コード例 #1
0
    def test_deprecation_warning(self):

        ctrl_unit = ControlUnit()

        input_mex = "A57901356496042398040000000201512021722030000000000N000000000E0000002400180034128386" \
                    "00000000000000000101FUUU00UUUUUU00000"

        ctrl_unit.decode_ascii(input_mex)
コード例 #2
0
    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)
コード例 #3
0
    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()
コード例 #4
0
    def test_decode_ascii(self):

        ctrl_unit = ControlUnit()

        # Evento di base
        packet = "A5790135153505725270211210A201511141152091141416602N012359949E01122001300240032584265002600370048888"
        packet += "0101UUUU00UUUUUU03651"

        # Test del controllo del campo HDR, diverso da A5
        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii("B5" + packet[2:])

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:2] + "89" + packet[4:])  # Test del campo LEN != len(str)

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:4] + "02" + packet[6:])  # Test del campo VER != 1

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:6] + "351A35057252702" + packet[21:])  # Test del campo IMEI, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:6] + "3515a5057252702" + packet[21:])  # Test del campo IMEI, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:6] + "35153s057252702" + packet[21:])  # Test del campo IMEI, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:21] + "A121" + packet[25:])  # Test del campo DRVN, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:21] + "1a21" + packet[25:])  # Test del campo DRVN, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:21] + "11s1" + packet[25:])  # Test del campo DRVN, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:25] + "0a" + packet[27:])  # Test del campo EVTN, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:25] + "s1" + packet[27:])  # Test del campo EVTN, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:27] + "20151314" + packet[35:])  # Test del campo DATE, wrong

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:27] + "201511s4" + packet[35:])  # Test del campo DATE, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:35] + "117209" + packet[41:])  # Test del campo TIME, wrong

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:35] + "115t09" + packet[41:])  # Test del campo TIME, wrong

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:41] + "1A" + packet[43:])  # Test del campo GSAT, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:43] + "41416602E" + packet[52:])  # Test del campo LAT, wrong

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:43] + "4s416602N" + packet[52:])  # Test del campo LAT, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:52] + "012759949N" + packet[62:])  # Test del campo LONG, wrong

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:52] + "012k59949E" + packet[62:])  # Test del campo LONG, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:52] + "012k59949E" + packet[62:])  # Test del campo LONG, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:62] + "0A12" + packet[66:])  # Test del campo SPD, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:62] + "01a2" + packet[66:])  # Test del campo SPD, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:62] + "011s" + packet[66:])  # Test del campo SPD, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:66] + "A001" + packet[70:])  # Test del campo FTR, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:66] + "2a01" + packet[70:])  # Test del campo FTR, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:66] + "20h1" + packet[70:])  # Test del campo FTR, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:70] + "A002" + packet[74:])  # Test del campo FTL, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:70] + "3a02" + packet[74:])  # Test del campo FTL, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:70] + "30h2" + packet[74:])  # Test del campo FTL, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:74] + "A003" + packet[78:])  # Test del campo FTF, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:74] + "4a03" + packet[78:])  # Test del  campo FTF, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:74] + "40h3" + packet[78:])  # Test del campo FTF, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:78] + "A58" + packet[81:])  # Test del campo MBAT, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:78] + "2a8" + packet[81:])  # Test del campo MBAT, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:78] + "25n" + packet[81:])  # Test del campo MBAT, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:81] + "A58" + packet[84:])  # Test del campo BBAT, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:81] + "2a8" + packet[84:])  # Test del campo BBAT, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:81] + "25n" + packet[84:])  # Test del campo BBAT, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:84] + "B002" + packet[88:])  # Test del campo FCRM, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:84] + "5b02" + packet[88:])  # Test del campo FCRM, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:84] + "50m2" + packet[88:])  # Test del campo FCRM, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:88] + "C003" + packet[92:])  # Test del campo FCLM, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:88] + "6c03" + packet[92:])  # Test del campo FCLM, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:88] + "60l3" + packet[92:])  # Test del campo FCLM, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:92] + "C003" + packet[96:])  # Test del campo FCFM, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:92] + "6c03" + packet[96:])  # Test del campo FCFM, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:92] + "60l3" + packet[96:])  # Test del campo FCFM, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:96] + "D888" + packet[100:])  # Test del campo FCDL, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:96] + "8d88" + packet[100:])  # Test del campo FCDL, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:96] + "88u8" + packet[100:])  # Test del campo FCDL, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:100] + "a" + packet[101:])  # Test del campo FCRS, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:101] + "a" + packet[102:])  # Test del campo FCLS, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:102] + "a" + packet[103:])  # Test del campo FCFS, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:103] + "a" + packet[104:])  # Test del campo IGSS, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:108] + "a" + packet[109:])  # Test del campo ALRM, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:109] + "a" + packet[110:])  # Test del campo FCRL, string

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:116] + "A3651")  # Test del campo HSZZ, HEX

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:116] + "0a651")  # Test del campo HSZZ, hex

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:116] + "03s51")  # Test del campo HSZZ, HEX

        # Ora provo la conversione di tutti i parametri corretti
        result = ctrl_unit.decode_ascii(packet)

        self.assertEqual(result, True)
        self.assertEqual(ctrl_unit.ascii_header, "A5")
        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.694337, 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_CLOSE)
        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.unused_inputs, "UUUU")
        self.assertEqual(ctrl_unit.alarm, ControlUnit.ALARM_UNARMED)
        self.assertEqual(ctrl_unit.cup_lock, ControlUnit.CAPS_UNLOCKED)
        self.assertEqual(ctrl_unit.unused_outputs, "UUUUUU")
        self.assertEqual(ctrl_unit.distance_travelled, 365.1)

        # Rifornimento
        packet = "A57B01351535057252702112113201511141152091141416602N012359949E01122001300240032584265002600370048888"
        packet += "0101UUUU00UUUUUU0365105"

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:121] + "0D")  # Test del campo DIST, NUM

        # Ora provo la conversione di tutti i parametri ed analizzo l'ultimo introdotto
        result = ctrl_unit.decode_ascii(packet)
        self.assertEqual(result, True)
        self.assertEqual(ctrl_unit.gas_station, 5)

        # Messaggio di testo
        packet = "A59901351535057252702112114201511141152091141416602N012359949E01122001300240032584265002600370048888"
        packet += "0101UUUU00UUUUUU03651Questo e' un messaggio di testo$"

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:121] + "Questo è un messaggio di testo")  # Test del campo CHAT, STR

        # Ora provo la conversione di tutti i parametri ed analizzo l'ultimo introdotto
        result = ctrl_unit.decode_ascii(packet)
        self.assertEqual(result, True)
        self.assertEqual(ctrl_unit.text_message, "Questo e' un messaggio di testo")

        # Messaggio di rifornimento da cisterna
        packet = "A58101351535057252702112115201511141152091141416602N012359949E01122001300240032584265002600370048888"
        packet += "0101UUUU00UUUUUU03651AB123CD$"

        with self.assertRaises(ValueError):
            ctrl_unit.decode_ascii(packet[0:121] + "AB123CD")  # Test del campo TARG, STR

        # Ora provo la conversione di tutti i parametri ed analizzo l'ultimo introdotto
        result = ctrl_unit.decode_ascii(packet)
        self.assertEqual(result, True)
        self.assertEqual(ctrl_unit.plate, "AB123CD")