Example #1
0
def index(req):
    postData = req.form
    jsonList = []

    for key in keyStrNames:
        if key in postData:
            tp = postData[key].value
            bytes = unhexlify(tp)
            data = tinypacks.unpack(bytes)
            jsonList.append(json.dumps(data))

    return jsonList
Example #2
0
def index(req):
 	postData = req.form
 	jsonList = []

	for key in keyStrNames:
		if key in postData:
			tp = postData[key].value
			bytes = unhexlify(tp)
			data = tinypacks.unpack(bytes)
			jsonList.append(json.dumps(data))

	return jsonList
Example #3
0
    def receive(self):
        frame = ""
        byte = ""
        try:
            while (byte != "\x7E" or frame == ""):
                byte = self.fd.read(1)
                if not byte:
                    raise PostmanError("Frame receiving timed out.")
                if byte == "\x7D":
                    frame += chr(ord(self.fd.read(1)) | 32)
                elif byte != "\x7E":
                    frame += byte
        except PostmanError:
            raise
        except IOError as err:
            raise PostmanError("Frame receiving failed: %s" % err)

        if self.debug:
            print "RX:",
            for c in frame:
                print "%X" % ord(c),
            print "[%i]" % len(frame)

        if len(frame) >= 4 and crc16.crc16str(frame[:-2]) == struct.unpack(
                ">H", frame[-2:])[0]:
            frame = frame[:-2]
            response, frame = tinypacks.unpack(frame)
            if frame:
                token, frame = tinypacks.unpack(frame)
                if frame:
                    payload, frame = tinypacks.unpack(frame)
                    return [response, token, payload]
                else:
                    return [response, token]
            else:
                return [response]
        else:
            raise PostmanError("Frame receiving failed, bad CRC %s != %s " %
                               (hex(crc16.crc16str(frame[:-2])),
                                hex(struct.unpack(">H", frame[-2:])[0])))
Example #4
0
    def receive(self):
        frame = ""
        byte = ""
        try:
            while (byte != "\x7E" or frame == ""):
                byte = self.fd.read(1)
                if not byte:
                    raise PostmanError("Frame receiving timed out.")
                if byte == "\x7D":
                    frame += chr(ord(self.fd.read(1))|32)
                elif byte != "\x7E":
                    frame += byte
        except PostmanError:
            raise
        except  IOError as err:
            raise PostmanError("Frame receiving failed: %s" % err)

        if self.debug:
            print "RX:",
            for c in frame:
                print "%X" % ord(c),
            print "[%i]" % len(frame)

        if len(frame) >= 4 and crc16.crc16str(frame[:-2]) == struct.unpack(">H", frame[-2:])[0]:
            frame = frame[:-2]
            response, frame = tinypacks.unpack(frame)
            if frame:
                token, frame = tinypacks.unpack(frame)
                if frame:
                    payload, frame = tinypacks.unpack(frame)
                    return [response, token, payload]
                else:
                    return [response, token]
            else:
                return [response]
        else:
            raise PostmanError("Frame receiving failed, bad CRC %s != %s " % (hex(crc16.crc16str(frame[:-2])), hex(struct.unpack(">H", frame[-2:])[0])))
Example #5
0
#!/usr/bin/python
#
# TinyPacks pack/unpack example
#

import tinypacks

data = {"text": "Hello world!", "status": True, "count": 123}
print("Data: " +  repr(data))

packed_data = tinypacks.pack(data)
print("Packed: " + repr(packed_data))

(unpacked_data, remaining_data) = tinypacks.unpack(packed_data)
print("Unpacked: " + repr(unpacked_data))
Example #6
0
#  and/or sell copies of the Software, and to permit persons to whom the
#  Software is furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#  DEALINGS IN THE SOFTWARE.

import sys
import json
import tinypacks

if len(sys.argv) < 3:
    print("\nUsage: %s <TinyPacks file> <JSON file>\n" % sys.argv[0])
    sys.exit()

source_file = open(sys.argv[1], "r")
destination_file = open(sys.argv[2], "w")

parsed_tinypacks = tinypacks.unpack(source_file.read())
encoded_json = json.dump(parsed_tinypacks, destination_file)

source_file.close()
destination_file.close()
Example #7
0
#  Software is furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
# 
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#  DEALINGS IN THE SOFTWARE.

import sys
import json
import tinypacks

if len(sys.argv) < 3:
    print("\nUsage: %s <TinyPacks file> <JSON file>\n" % sys.argv[0])
    sys.exit()

source_file = open(sys.argv[1], "r")
destination_file = open(sys.argv[2], "w")

parsed_tinypacks = tinypacks.unpack(source_file.read())
encoded_json = json.dump(parsed_tinypacks, destination_file)

source_file.close()
destination_file.close()