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_encode_ascii(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_CLOSE
        ctrl_unit.cup_l = ControlUnit.CUP_OPEN
        ctrl_unit.cup_f = ControlUnit.CUP_FAIL
        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 = "Questo e' un messaggio di testo"
        ctrl_unit.plate = "AB324LR"

        # Evento di base
        result = ctrl_unit.encode_ascii()

        self.assertEqual(result, True)
        self.assertEqual(
            ctrl_unit.output_packet,
            "A5790135153505725270211210A201511141152091141416602N012359949E0112200130024003258426500260037004888801F1"
            "UUUU00UUUUUU03651"
        )

        # Rifornimento
        ctrl_unit.event = 0x13
        result = ctrl_unit.encode_ascii()

        self.assertEqual(result, True)
        self.assertEqual(
            ctrl_unit.output_packet,
            "A57B01351535057252702112113201511141152091141416602N012359949E0112200130024003258426500260037004888801F1"
            "UUUU00UUUUUU0365105"
        )

        # Messaggio di testo
        ctrl_unit.event = 0x14
        result = ctrl_unit.encode_ascii()

        self.assertEqual(result, True)
        self.assertEqual(
            ctrl_unit.output_packet,
            "A59901351535057252702112114201511141152091141416602N012359949E0112200130024003258426500260037004888801F1"
            "UUUU00UUUUUU03651Questo e' un messaggio di testo$"
        )

        # Messaggio di rifornimento da cisterna
        ctrl_unit.event = 0x15
        result = ctrl_unit.encode_ascii()

        self.assertEqual(result, True)
        self.assertEqual(
            ctrl_unit.output_packet,
            "A58101351535057252702112115201511141152091141416602N012359949E0112200130024003258426500260037004888801F1"
            "UUUU00UUUUUU03651AB324LR$"
        )