Example #1
0
    def test_encode_resp_version(self):
        """Test the process of encoding a version response."""
        sessionTime = int(round(time.time() * 1000))
        returnCode = Packet.RTN_E_RCV_FRAME
        ejecting = 0
        battery = 2
        printCount = 7
        resPacket = VersionCommand(Packet.MESSAGE_MODE_RESPONSE,
                                   unknown1=254,
                                   firmware=275,
                                   hardware=0)
        encodedResponse = resPacket.encodeResponse(sessionTime, returnCode,
                                                   ejecting, battery,
                                                   printCount)
        packetFactory = PacketFactory()
        decodedPacket = packetFactory.decode(encodedResponse)
        # decodedPacket.printDebug()
        postHeader = decodedPacket.header
        self.helper_verify_header(postHeader,
                                  Packet.MESSAGE_MODE_RESPONSE,
                                  Packet.MESSAGE_TYPE_PRINTER_VERSION,
                                  len(encodedResponse),
                                  resPacket.encodedSessionTime,
                                  returnCode=returnCode,
                                  ejecting=ejecting,
                                  battery=battery,
                                  printCount=printCount)

        # Verify Payload
        self.assertEqual(decodedPacket.payload['unknown1'], 254)
        self.assertEqual(decodedPacket.payload['firmware'], '01.13')
        self.assertEqual(decodedPacket.payload['hardware'], '00.00')
Example #2
0
    def test_encode_resp_send(self):
        """Test encoding a Send Image Response."""
        sessionTime = int(round(time.time() * 1000))
        returnCode = Packet.RTN_E_RCV_FRAME
        ejecting = 0
        battery = 2
        printCount = 7
        sequenceNumber = 5
        resPacket = SendImageCommand(Packet.MESSAGE_MODE_RESPONSE,
                                     sequenceNumber=sequenceNumber)
        encodedResponse = resPacket.encodeResponse(sessionTime, returnCode,
                                                   ejecting, battery,
                                                   printCount)
        packetFactory = PacketFactory()
        decodedPacket = packetFactory.decode(encodedResponse)
        # decodedPacket.printDebug()
        postHeader = decodedPacket.header
        self.helper_verify_header(postHeader,
                                  Packet.MESSAGE_MODE_RESPONSE,
                                  Packet.MESSAGE_TYPE_SEND_IMAGE,
                                  len(encodedResponse),
                                  resPacket.encodedSessionTime,
                                  returnCode=returnCode,
                                  ejecting=ejecting,
                                  battery=battery,
                                  printCount=printCount)

        # Verify Payload
        self.assertEqual(decodedPacket.payload['sequenceNumber'],
                         sequenceNumber)
Example #3
0
 def test_premade_resp_prep(self):
     """Test Decoding a Prep Response."""
     msg = bytearray.fromhex('2451 001c 9b60 d511 0457'
                             ' 0000 1000 0015 f900 0000'
                             '  0000 0000 fc14 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #4
0
    def test_encode_resp_prep(self):
        """Test encoding a Prep Image Response."""
        sessionTime = int(round(time.time() * 1000))
        returnCode = Packet.RTN_E_RCV_FRAME
        ejecting = 0
        battery = 2
        printCount = 7
        maxLen = 60000
        resPacket = PrepImageCommand(Packet.MESSAGE_MODE_RESPONSE,
                                     maxLen=maxLen)
        encodedResponse = resPacket.encodeResponse(sessionTime, returnCode,
                                                   ejecting, battery,
                                                   printCount)
        packetFactory = PacketFactory()
        decodedPacket = packetFactory.decode(encodedResponse)
        # decodedPacket.printDebug()
        postHeader = decodedPacket.header
        self.helper_verify_header(postHeader,
                                  Packet.MESSAGE_MODE_RESPONSE,
                                  Packet.MESSAGE_TYPE_PREP_IMAGE,
                                  len(encodedResponse),
                                  resPacket.encodedSessionTime,
                                  returnCode=returnCode,
                                  ejecting=ejecting,
                                  battery=battery,
                                  printCount=printCount)

        # Verify Payload
        self.assertEqual(decodedPacket.payload['maxLen'], maxLen)
Example #5
0
    def test_encode_resp_prePrint(self):
        """Test the process of encoding a pre print response."""
        sessionTime = int(round(time.time() * 1000))
        returnCode = Packet.RTN_E_RCV_FRAME
        ejecting = 0
        battery = 2
        printCount = 7
        cmdNumber = 8
        respNumber = 1
        resPacket = PrePrintCommand(Packet.MESSAGE_MODE_RESPONSE,
                                    cmdNumber=cmdNumber,
                                    respNumber=respNumber)
        encodedResponse = resPacket.encodeResponse(sessionTime, returnCode,
                                                   ejecting, battery,
                                                   printCount)
        packetFactory = PacketFactory()
        decodedPacket = packetFactory.decode(encodedResponse)
        # decodedPacket.printDebug()
        postHeader = decodedPacket.header
        self.helper_verify_header(postHeader,
                                  Packet.MESSAGE_MODE_RESPONSE,
                                  Packet.MESSAGE_TYPE_PRE_PRINT,
                                  len(encodedResponse),
                                  resPacket.encodedSessionTime,
                                  returnCode=returnCode,
                                  ejecting=ejecting,
                                  battery=battery,
                                  printCount=printCount)

        # Verify Payload
        self.assertEqual(decodedPacket.payload['cmdNumber'], cmdNumber)
        self.assertEqual(decodedPacket.payload['respNumber'], respNumber)
Example #6
0
 def test_encode_cmd_prep(self):
     """Test encoding a Prep Image Command."""
     sessionTime = int(round(time.time() * 1000))
     pinCode = 1111
     format = 16
     options = 128
     imgLength = 1440000
     cmdPacket = PrepImageCommand(Packet.MESSAGE_MODE_COMMAND,
                                  format=format,
                                  options=options,
                                  imgLength=imgLength)
     encodedCommand = cmdPacket.encodeCommand(sessionTime, pinCode)
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedCommand)
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_COMMAND,
                               Packet.MESSAGE_TYPE_PREP_IMAGE,
                               len(encodedCommand),
                               cmdPacket.encodedSessionTime,
                               pinCode)
     # Verify Payload
     self.assertEqual(decodedPacket.payload['format'], format)
     self.assertEqual(decodedPacket.payload['options'], options)
     self.assertEqual(decodedPacket.payload['imgLength'], imgLength)
Example #7
0
    def test_encode_resp_modelName(self):
        """Test the process of encoding a model name response."""
        sessionTime = int(round(time.time() * 1000))
        returnCode = Packet.RTN_E_RCV_FRAME
        ejecting = 0
        battery = 2
        printCount = 7
        modelName = 'SP-2'
        resPacket = ModelNameCommand(Packet.MESSAGE_MODE_RESPONSE,
                                     modelName=modelName)
        encodedResponse = resPacket.encodeResponse(sessionTime, returnCode,
                                                   ejecting, battery,
                                                   printCount)
        packetFactory = PacketFactory()
        decodedPacket = packetFactory.decode(encodedResponse)
        # decodedPacket.printDebug()
        postHeader = decodedPacket.header
        self.helper_verify_header(postHeader,
                                  Packet.MESSAGE_MODE_RESPONSE,
                                  Packet.MESSAGE_TYPE_MODEL_NAME,
                                  len(encodedResponse),
                                  resPacket.encodedSessionTime,
                                  returnCode=returnCode,
                                  ejecting=ejecting,
                                  battery=battery,
                                  printCount=printCount)

        # Verify Payload
        self.assertEqual(decodedPacket.payload['modelName'], modelName)
Example #8
0
 def test_encode_resp_lock_state(self):
     """Test encoding a lock state Response."""
     sessionTime = int(round(time.time() * 1000))
     returnCode = Packet.RTN_E_RCV_FRAME
     ejecting = 0
     battery = 2
     printCount = 7
     unknownFourByteInt = 100
     resPacket = LockStateCommand(Packet.MESSAGE_MODE_RESPONSE,
                                  unknownFourByteInt=unknownFourByteInt)
     encodedResponse = resPacket.encodeResponse(sessionTime, returnCode,
                                                ejecting, battery,
                                                printCount)
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedResponse)
     # decodedPacket.printDebug()
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_RESPONSE,
                               Packet.MESSAGE_TYPE_SET_LOCK_STATE,
                               len(encodedResponse),
                               resPacket.encodedSessionTime,
                               returnCode=returnCode,
                               ejecting=ejecting,
                               battery=battery,
                               printCount=printCount)
     # Verify Payload
     self.assertEqual(decodedPacket.payload['unknownFourByteInt'],
                      unknownFourByteInt)
Example #9
0
 def test_premade_resp_printCount(self):
     """Test Decoding a Print Count Response with an existing payload."""
     msg = bytearray.fromhex('2ac1 0024 e759 eede 0000'
                             ' 0000 0000 0027 0000 0003'
                             ' 00f3 c048 0000 1645 001e'
                             ' 0000 f946 0d0a')
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(msg)
     self.assertEqual(decodedPacket.payload['printHistory'], 3)
Example #10
0
 def test_premade_resp_version(self):
     """Test Decoding a Version Response with an existing payload."""
     msg = bytearray.fromhex('2ac0 001c e759 eede 0000'
                             ' 0000 0000 0027 0101 0113'
                             ' 0000 0000 fbb0 0d0a')
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(msg)
     self.assertEqual(decodedPacket.payload['unknown1'], 257)
     self.assertEqual(decodedPacket.payload['firmware'], '01.13')
     self.assertEqual(decodedPacket.payload['hardware'], '00.00')
Example #11
0
 def test_premade_resp_specifications(self):
     """Test Decoding a Specifications Response with an existing payload."""
     msg = bytearray.fromhex('2a4f 0030 e759 eede 0000 0000 0000 0027 0258'
                             ' 0320 0100 000a 0000 0000 ea60 1000 0000 0000'
                             ' 0000 0000 0000 0000 fa41 0d0a')
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(msg)
     self.assertEqual(decodedPacket.payload['maxHeight'], 800)
     self.assertEqual(decodedPacket.payload['maxWidth'], 600)
     self.assertEqual(decodedPacket.payload['maxColours'], 256)
     self.assertEqual(decodedPacket.payload['unknown1'], 10)
     self.assertEqual(decodedPacket.payload['maxMsgSize'], 60000)
     self.assertEqual(decodedPacket.payload['unknown2'], 16)
     self.assertEqual(decodedPacket.payload['unknown3'], 0)
Example #12
0
 def test_encode_cmd_195(self):
     """Test encoding a Type 195 Command."""
     sessionTime = int(round(time.time() * 1000))
     pinCode = 1111
     cmdPacket = Type195Command(Packet.MESSAGE_MODE_COMMAND)
     encodedCommand = cmdPacket.encodeCommand(sessionTime, pinCode)
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedCommand)
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_COMMAND,
                               Packet.MESSAGE_TYPE_195,
                               len(encodedCommand),
                               cmdPacket.encodedSessionTime,
                               pinCode)
Example #13
0
 def test_encode_cmd_lock_state(self):
     """Test encoding a lock state Command."""
     sessionTime = int(round(time.time() * 1000))
     pinCode = 1111
     cmdPacket = LockStateCommand(Packet.MESSAGE_MODE_COMMAND)
     encodedCommand = cmdPacket.encodeCommand(sessionTime, pinCode)
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedCommand)
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_COMMAND,
                               Packet.MESSAGE_TYPE_SET_LOCK_STATE,
                               len(encodedCommand),
                               cmdPacket.encodedSessionTime,
                               pinCode)
Example #14
0
 def test_encode_cmd_modelName(self):
     """Test the process of encoding a model name command."""
     # Create Model Name Command Packet
     sessionTime = int(round(time.time() * 1000))
     pinCode = 1111
     cmdPacket = ModelNameCommand(Packet.MESSAGE_MODE_COMMAND)
     # Encodde the command to raw byte array
     encodedCommand = cmdPacket.encodeCommand(sessionTime, pinCode)
     # Decode the command back into a packet object
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedCommand)
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_COMMAND,
                               Packet.MESSAGE_TYPE_MODEL_NAME,
                               len(encodedCommand),
                               cmdPacket.encodedSessionTime,
                               pinCode)
Example #15
0
 def test_encode_cmd_specifications(self):
     """Test the process of encoding a spcecifications command."""
     # Create Specifications Command Packet
     sessionTime = int(round(time.time() * 1000))
     pinCode = 1111
     cmdPacket = SpecificationsCommand(Packet.MESSAGE_MODE_COMMAND)
     # Encode the command to raw byte array
     encodedCommand = cmdPacket.encodeCommand(sessionTime, pinCode)
     # Decode the command back into a packet object
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedCommand)
     # decodedPacket.printDebug()
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_COMMAND,
                               Packet.MESSAGE_TYPE_SPECIFICATIONS,
                               len(encodedCommand),
                               cmdPacket.encodedSessionTime,
                               pinCode)
Example #16
0
 def test_encode_cmd_lock(self):
     """Test encoding a Lock Printer Command."""
     sessionTime = int(round(time.time() * 1000))
     pinCode = 1111
     lockState = 1
     cmdPacket = PrinterLockCommand(Packet.MESSAGE_MODE_COMMAND,
                                    lockState=lockState)
     encodedCommand = cmdPacket.encodeCommand(sessionTime, pinCode)
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedCommand)
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_COMMAND,
                               Packet.MESSAGE_TYPE_LOCK_DEVICE,
                               len(encodedCommand),
                               cmdPacket.encodedSessionTime,
                               pinCode)
     # Verify Payload
     self.assertEqual(decodedPacket.payload['lockState'], lockState)
Example #17
0
    def test_process_log(self):
        """Import a json log and replay the messages."""
        filename = "priming.json"
        json_data = open(filename)
        data = json.load(json_data)
        json_data.close()
        print()
        decodedPacketList = []
        for packet in data:
            readBytes = bytearray.fromhex(packet['bytes'])
            packetFactory = PacketFactory()
            decodedPacket = packetFactory.decode(readBytes)
            # decodedPacket.printDebug()
            packetObj = decodedPacket.getPacketObject()
            decodedPacketList.append(packetObj)

        pprint(decodedPacketList)
        with open('log2.json', 'w') as outfile:
            json.dump(decodedPacketList, outfile, indent=4)
Example #18
0
    def test_encode_resp_specifications(self):
        """Test the process of encoding a specifications response."""
        sessionTime = int(round(time.time() * 1000))
        returnCode = Packet.RTN_E_RCV_FRAME
        ejecting = 0
        battery = 2
        printCount = 7
        resPacket = SpecificationsCommand(Packet.MESSAGE_MODE_RESPONSE,
                                          maxHeight=800,
                                          maxWidth=600,
                                          maxColours=256,
                                          unknown1=10,
                                          maxMsgSize=60000,
                                          unknown2=16,
                                          unknown3=0)
        encodedResponse = resPacket.encodeResponse(sessionTime, returnCode,
                                                   ejecting, battery,
                                                   printCount)
        packetFactory = PacketFactory()
        decodedPacket = packetFactory.decode(encodedResponse)
        # decodedPacket.printDebug()
        postHeader = decodedPacket.header
        self.helper_verify_header(postHeader,
                                  Packet.MESSAGE_MODE_RESPONSE,
                                  Packet.MESSAGE_TYPE_SPECIFICATIONS,
                                  len(encodedResponse),
                                  resPacket.encodedSessionTime,
                                  returnCode=returnCode,
                                  ejecting=ejecting,
                                  battery=battery,
                                  printCount=printCount)

        # Verify Payload
        # print(decodedPacket.payload)
        self.assertEqual(decodedPacket.payload['maxHeight'], 800)
        self.assertEqual(decodedPacket.payload['maxWidth'], 600)
        self.assertEqual(decodedPacket.payload['maxColours'], 256)
        self.assertEqual(decodedPacket.payload['unknown1'], 10)
        self.assertEqual(decodedPacket.payload['maxMsgSize'], 60000)
        self.assertEqual(decodedPacket.payload['unknown2'], 16)
        self.assertEqual(decodedPacket.payload['unknown3'], 0)
Example #19
0
 def test_encode_cmd_prePrint(self):
     """Test the process of encoding a prePrint command."""
     # Create Model Name Command Packet
     sessionTime = int(round(time.time() * 1000))
     pinCode = 1111
     cmdNumber = 8
     cmdPacket = PrePrintCommand(Packet.MESSAGE_MODE_COMMAND,
                                 cmdNumber=cmdNumber)
     # Encodde the command to raw byte array
     encodedCommand = cmdPacket.encodeCommand(sessionTime, pinCode)
     # Decodee the command back into a packet object
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedCommand)
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_COMMAND,
                               Packet.MESSAGE_TYPE_PRE_PRINT,
                               len(encodedCommand),
                               cmdPacket.encodedSessionTime,
                               pinCode)
     # Verify Payload
     self.assertEqual(decodedPacket.payload['cmdNumber'], cmdNumber)
Example #20
0
 def test_encode_cmd_send(self):
     """Test encoding a Send Image Command."""
     sessionTime = int(round(time.time() * 1000))
     pinCode = 1111
     sequenceNumber = 5
     payloadBytes = bytearray(10)
     cmdPacket = SendImageCommand(Packet.MESSAGE_MODE_COMMAND,
                                  sequenceNumber=sequenceNumber,
                                  payloadBytes=payloadBytes)
     encodedCommand = cmdPacket.encodeCommand(sessionTime, pinCode)
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedCommand)
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_COMMAND,
                               Packet.MESSAGE_TYPE_SEND_IMAGE,
                               len(encodedCommand),
                               cmdPacket.encodedSessionTime,
                               pinCode)
     # Verify Payload
     self.assertEqual(decodedPacket.payload['sequenceNumber'],
                      sequenceNumber)
     self.assertEqual(decodedPacket.payload['payloadBytes'], payloadBytes)
Example #21
0
 def test_encode_resp_195(self):
     """Test encoding a Type 195 Response."""
     sessionTime = int(round(time.time() * 1000))
     returnCode = Packet.RTN_E_RCV_FRAME
     ejecting = 0
     battery = 2
     printCount = 7
     resPacket = Type195Command(Packet.MESSAGE_MODE_RESPONSE)
     encodedResponse = resPacket.encodeResponse(sessionTime, returnCode,
                                                ejecting, battery,
                                                printCount)
     packetFactory = PacketFactory()
     decodedPacket = packetFactory.decode(encodedResponse)
     # decodedPacket.printDebug()
     postHeader = decodedPacket.header
     self.helper_verify_header(postHeader,
                               Packet.MESSAGE_MODE_RESPONSE,
                               Packet.MESSAGE_TYPE_195,
                               len(encodedResponse),
                               resPacket.encodedSessionTime,
                               returnCode=returnCode,
                               ejecting=ejecting,
                               battery=battery,
                               printCount=printCount)
Example #22
0
 def test_premade_resp_lock(self):
     """Test Decoding a Lock Response."""
     msg = bytearray.fromhex('2ab3 0014 75b8 bd8e 0000'
                             ' 0000 0000 003a fc5c 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #23
0
 def test_premade_cmd_lock(self):
     """Test Decoding a Lock Command."""
     msg = bytearray.fromhex('24b3 0014 9619 02df 0457'
                             ' 0000 0100 0000 fd28 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #24
0
 def test_premade_cmd_prePrint(self):
     """Test Decoding a Pre Print Command."""
     msg = bytearray.fromhex('24c4 0014 4e40 684c 0457'
                             ' 0000 0000 0008 fd5e 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #25
0
 def test_premade_cmd_modelName(self):
     """Test Decoding a Model Name Command."""
     msg = bytearray.fromhex('24c2 0010 0b8d c2b4 0457 0000 fca0 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #26
0
 def test_premade_resp_195_last(self):
     """Test decoding a 195 last response."""
     msg = bytearray.fromhex('2ac3 0014 f130 d7cc 0000 0000'
                             ' 0000 0035 fc05 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #27
0
 def test_premade_resp_195_first(self):
     """Test decoding a 195 first response."""
     msg = bytearray.fromhex('2ac3 0014 f130 d7cc 0000 0000'
                             ' 7f00 0436 fb81 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #28
0
 def test_premade_cmd_195(self):
     """Test decoding a 195 command."""
     msg = bytearray.fromhex('24c3 0010 f130 d7cc 0457 0000 fbe9 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #29
0
 def test_premade_resp_lock_state(self):
     """Test decoding a Lock state response."""
     msg = bytearray.fromhex('2ab0 0018 f130 d7cc 0000 0000'
                             ' 0000 0036 0000 0064 fbaf 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)
Example #30
0
 def test_premade_cmd_lock_state(self):
     """Test decoding a Lock state command."""
     msg = bytearray.fromhex('24b0 0010 f776 ecbe 0457 0000 fba9 0d0a')
     packetFactory = PacketFactory()
     packetFactory.decode(msg)