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_decode_binary(self): ctrl_unit = ControlUnit() # Controllo la lunghezza errata with self.assertRaises(ValueError): ctrl_unit.decode_binary( binascii.unhexlify( '300251898CC5DECD61040A692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8225000430EAA' ) ) with self.assertRaises(ValueError): ctrl_unit.decode_binary( binascii.unhexlify( '200251898CC5DECD61040A692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8225000430E' ) ) # Ora controllo la traduzione result = ctrl_unit.decode_binary( binascii.unhexlify( '32025EB13622B83F010061040A692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8226E00430E' ) ) self.assertEqual(result, True) self.assertEqual(ctrl_unit.imei, 351535057252702L) self.assertEqual(ctrl_unit.driver, 1121) self.assertEqual(ctrl_unit.event, 10) self.assertEqual(ctrl_unit.unixtime, 1447501929) self.assertEqual(ctrl_unit.sat, 11) self.assertAlmostEqual(ctrl_unit.lat, 41.694336, 6) self.assertAlmostEqual(ctrl_unit.lon, 12.599915, 6) self.assertEqual(ctrl_unit.speed, 11.2) self.assertEqual(ctrl_unit.gasoline_r, 200.1) self.assertEqual(ctrl_unit.gasoline_l, 300.2) self.assertEqual(ctrl_unit.gasoline_f, 400.3) self.assertEqual(ctrl_unit.vin, 25.8) self.assertEqual(ctrl_unit.vbatt, 4.26) self.assertEqual(ctrl_unit.input_gasoline_r, 500.2) self.assertEqual(ctrl_unit.input_gasoline_l, 600.3) self.assertEqual(ctrl_unit.input_gasoline_f, 700.4) self.assertEqual(ctrl_unit.input_gasoline_tot, 8888) self.assertEqual(ctrl_unit.cup_r, ControlUnit.CUP_FAIL) self.assertEqual(ctrl_unit.cup_l, ControlUnit.CUP_OPEN) self.assertEqual(ctrl_unit.cup_f, ControlUnit.CUP_CLOSE) self.assertEqual(ctrl_unit.engine, ControlUnit.ENGINE_ON) self.assertEqual(ctrl_unit.alarm, ControlUnit.ALARM_UNARMED) self.assertEqual(ctrl_unit.cup_lock, ControlUnit.CAPS_UNLOCKED) self.assertEqual(ctrl_unit.distance_travelled, 365.1) # Ora controllo la traduzione dell'evento 13 result = ctrl_unit.decode_binary( binascii.unhexlify( '33025EB13622B83F0100610413692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8226E00430E05' ) ) self.assertEqual(result, True) self.assertEqual(ctrl_unit.event, 0x13) self.assertEqual(ctrl_unit.gas_station, 5) # Ora controllo la traduzione dell'evento 14 result = ctrl_unit.decode_binary( binascii.unhexlify( 'B4025EB13622B83F0100610414692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8226E00430E' '436F6D65207661206C6120747261736D697373696F6E652062696E617269613F000000000000000000000000000000000000' '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' '000000000000000000000000000000000000000000000000000000000000' ) ) self.assertEqual(result, True) self.assertEqual(ctrl_unit.event, 0x14) self.assertEqual(ctrl_unit.text_message, "Come va la trasmissione binaria?") # Ora controllo la traduzione dell'evento 15 result = ctrl_unit.decode_binary( binascii.unhexlify( '46025EB13622B83F0100610415692047560B00C72642409949417000D107BA0BA30F0201AA018A1373175C1BB8226E00430E' '41423332344C5200000000000000000000000000' ) ) self.assertEqual(result, True) self.assertEqual(ctrl_unit.event, 0x15) self.assertEqual(ctrl_unit.plate, "AB324LR")