def test_direct_loop(self): ctrl_unit = ControlUnit() input_mex = "A57901351535057249088454500201512011056360000000000N000000000E0000008200920096111419" \ "00000000000000000FF1UUUU10UUUUUU00000" ctrl_unit.decode_ascii(input_mex) ctrl_unit.encode_binary() ctrl_unit.decode_binary(ctrl_unit.output_packet) ctrl_unit.encode_ascii() self.assertEqual(input_mex, ctrl_unit.output_packet)
def test_wrong_packets(self): ctrl_unit = ControlUnit() input_mex = "A57901351535057249088000050201512160653500000000000N000000000E0000605647080419055409" \ "0000000000000000FFFF1UUU00UUUUUU00000" ctrl_unit.decode_ascii(input_mex) input_mex = "32025891f8333b440100000001f3cd7256000000000000000000000010000e001d008100a3010000000000000000ec000000" ctrl_unit.decode_binary(binascii.unhexlify(input_mex)) # !linea 696 elif self.cup_lock == ControlUnit.CAPS_UNLOCKED: senza el!!!! input_mex = "A57901351535057248759000016201005082359590000000000N000000000E00000042003200322423170000000000000000FFF1FUUU11UUUUUU00000" ctrl_unit.decode_ascii(input_mex) ctrl_unit.check_values() ctrl_unit.encode_binary() input_mex = "A57901351535057209884000001201512201500090841426506N012350963E00000001000000001754170000000000000000F0FFFUUU00UUUUUU00000" ctrl_unit.decode_ascii(input_mex) ctrl_unit.check_values() ctrl_unit.encode_binary()
def test_encode_binary(self): ctrl_unit = ControlUnit() ctrl_unit.imei = 351535057252702L ctrl_unit.driver = 1121 ctrl_unit.event = 10 ctrl_unit.unixtime = 1447501929 ctrl_unit.sat = 11 ctrl_unit.lat = 41.694336 ctrl_unit.lon = 12.599915 ctrl_unit.speed = 11.2 ctrl_unit.gasoline_r = 200.1 ctrl_unit.gasoline_l = 300.2 ctrl_unit.gasoline_f = 400.3 ctrl_unit.vin = 25.8 ctrl_unit.vbatt = 4.26 ctrl_unit.input_gasoline_r = 500.2 ctrl_unit.input_gasoline_l = 600.3 ctrl_unit.input_gasoline_f = 700.4 ctrl_unit.input_gasoline_tot = 8888 ctrl_unit.cup_r = ControlUnit.CUP_FAIL ctrl_unit.cup_l = ControlUnit.CUP_OPEN ctrl_unit.cup_f = ControlUnit.CUP_CLOSE ctrl_unit.engine = ControlUnit.ENGINE_ON ctrl_unit.alarm = ControlUnit.ALARM_UNARMED ctrl_unit.cup_lock = ControlUnit.CAPS_UNLOCKED ctrl_unit.distance_travelled = 365.1 ctrl_unit.gas_station = 5 ctrl_unit.text_message = "Come va la trasmissione binaria?" ctrl_unit.plate = "AB324LR" # Evento di base result = ctrl_unit.encode_binary() self.assertEqual(result, True) self.assertEqual( ctrl_unit.output_packet, binascii.unhexlify( '32025EB13622B83F010061040A692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8226E00430E' ) ) # Rifornimento ctrl_unit.event = 0x13 result = ctrl_unit.encode_binary() self.assertEqual(result, True) self.assertEqual( ctrl_unit.output_packet, binascii.unhexlify( '33025EB13622B83F0100610413692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8226E00430E05' ) ) # Messaggio di testo ctrl_unit.event = 0x14 result = ctrl_unit.encode_binary() self.assertEqual(result, True) self.assertEqual( ctrl_unit.output_packet, binascii.unhexlify( 'B4025EB13622B83F0100610414692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8226E00430E' '436F6D65207661206C6120747261736D697373696F6E652062696E617269613F000000000000000000000000000000000000' '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' '000000000000000000000000000000000000000000000000000000000000' ) ) # Messaggio di rifornimento da cisterna ctrl_unit.event = 0x15 result = ctrl_unit.encode_binary() self.assertEqual(result, True) self.assertEqual( ctrl_unit.output_packet, binascii.unhexlify( '46025EB13622B83F0100610415692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8226E00430E' '41423332344C5200000000000000000000000000' ) )