Esempio n. 1
0
  def test_civic(self):

    dbc_file = "honda_civic_touring_2016_can_generated"

    signals = [
      ("STEER_TORQUE", "STEERING_CONTROL", 0),
      ("STEER_TORQUE_REQUEST", "STEERING_CONTROL", 0),
    ]
    checks = [("STEERING_CONTROL", 50)]

    parser = CANParser(dbc_file, signals, checks, 0)
    packer = CANPacker(dbc_file)

    idx = 0

    for steer in range(-256, 255):
      for active in [1, 0]:
        values = {
          "STEER_TORQUE": steer,
          "STEER_TORQUE_REQUEST": active,
        }

        msgs = packer.make_can_msg("STEERING_CONTROL", 0, values, idx)
        bts = can_list_to_can_capnp([msgs])

        parser.update_string(bts)

        self.assertAlmostEqual(parser.vl["STEERING_CONTROL"]["STEER_TORQUE"], steer)
        self.assertAlmostEqual(parser.vl["STEERING_CONTROL"]["STEER_TORQUE_REQUEST"], active)
        self.assertAlmostEqual(parser.vl["STEERING_CONTROL"]["COUNTER"], idx % 4)

        idx += 1
Esempio n. 2
0
    def test_parser_can_valid(self):
        signals = [
            ("COUNTER", "CAN_FD_MESSAGE"),
        ]
        checks = [
            ("CAN_FD_MESSAGE", 10),
        ]
        packer = CANPacker(TEST_DBC)
        parser = CANParser(TEST_DBC, signals, checks, 0)

        # shouldn't be valid initially
        self.assertFalse(parser.can_valid)

        # not valid until the message is seen
        for _ in range(100):
            dat = can_list_to_can_capnp([])
            parser.update_string(dat)
            self.assertFalse(parser.can_valid)

        # valid once seen
        for i in range(1, 100):
            t = int(0.01 * i * 1e9)
            msg = packer.make_can_msg("CAN_FD_MESSAGE", 0, {})
            dat = can_list_to_can_capnp([
                msg,
            ], logMonoTime=t)
            parser.update_string(dat)
            self.assertTrue(parser.can_valid)
Esempio n. 3
0
    def test_packer_parser(self):

        signals = [
            ("COUNTER", "STEERING_CONTROL"),
            ("CHECKSUM", "STEERING_CONTROL"),
            ("STEER_TORQUE", "STEERING_CONTROL"),
            ("STEER_TORQUE_REQUEST", "STEERING_CONTROL"),
            ("COUNTER", "CAN_FD_MESSAGE"),
            ("64_BIT_LE", "CAN_FD_MESSAGE"),
            ("64_BIT_BE", "CAN_FD_MESSAGE"),
            ("SIGNED", "CAN_FD_MESSAGE"),
        ]
        checks = [("STEERING_CONTROL", 0), ("CAN_FD_MESSAGE", 0)]

        packer = CANPacker(TEST_DBC)
        parser = CANParser(TEST_DBC, signals, checks, 0)

        for steer in range(-256, 255):
            for active in (1, 0):
                v1 = {
                    "STEER_TORQUE": steer,
                    "STEER_TORQUE_REQUEST": active,
                }
                m1 = packer.make_can_msg("STEERING_CONTROL", 0, v1)

                v2 = {
                    "SIGNED": steer,
                    "64_BIT_LE": random.randint(0, 100),
                    "64_BIT_BE": random.randint(0, 100),
                }
                m2 = packer.make_can_msg("CAN_FD_MESSAGE", 0, v2)

                bts = can_list_to_can_capnp([m1, m2])
                parser.update_string(bts)

                for key, val in v1.items():
                    self.assertAlmostEqual(parser.vl["STEERING_CONTROL"][key],
                                           val)

                for key, val in v2.items():
                    self.assertAlmostEqual(parser.vl["CAN_FD_MESSAGE"][key],
                                           val)

                # also check address
                for sig in ("STEER_TORQUE", "STEER_TORQUE_REQUEST", "COUNTER",
                            "CHECKSUM"):
                    self.assertEqual(parser.vl["STEERING_CONTROL"][sig],
                                     parser.vl[228][sig])
Esempio n. 4
0
    def test_subaru(self):
        # Subuaru is little endian

        dbc_file = "subaru_global_2017_generated"

        signals = [
            ("Counter", "ES_LKAS", 0),
            ("LKAS_Output", "ES_LKAS", 0),
            ("LKAS_Request", "ES_LKAS", 0),
            ("SET_1", "ES_LKAS", 0),
        ]

        checks = []

        parser = CANParser(dbc_file, signals, checks, 0)
        packer = CANPacker(dbc_file)

        idx = 0

        for steer in range(-256, 255):
            for active in [1, 0]:
                values = {
                    "Counter": idx,
                    "LKAS_Output": steer,
                    "LKAS_Request": active,
                    "SET_1": 1
                }

                msgs = packer.make_can_msg("ES_LKAS", 0, values)
                bts = can_list_to_can_capnp([msgs])
                parser.update_string(bts)

                self.assertAlmostEqual(parser.vl["ES_LKAS"]["LKAS_Output"],
                                       steer)
                self.assertAlmostEqual(parser.vl["ES_LKAS"]["LKAS_Request"],
                                       active)
                self.assertAlmostEqual(parser.vl["ES_LKAS"]["SET_1"], 1)
                self.assertAlmostEqual(parser.vl["ES_LKAS"]["Counter"],
                                       idx % 16)

                idx += 1
Esempio n. 5
0
    def test_scale_offset(self):
        """Test that both scale and offset are correctly preserved"""
        dbc_file = "honda_civic_touring_2016_can_generated"

        signals = [
            ("USER_BRAKE", "VSA_STATUS"),
        ]
        checks = [("VSA_STATUS", 50)]

        parser = CANParser(dbc_file, signals, checks, 0)
        packer = CANPacker(dbc_file)

        for brake in range(0, 100):
            values = {"USER_BRAKE": brake}
            msgs = packer.make_can_msg("VSA_STATUS", 0, values)
            bts = can_list_to_can_capnp([msgs])

            parser.update_string(bts)

            self.assertAlmostEqual(parser.vl["VSA_STATUS"]["USER_BRAKE"],
                                   brake)
Esempio n. 6
0
    def test_packer_counter(self):
        signals = [
            ("COUNTER", "CAN_FD_MESSAGE"),
        ]
        checks = [
            ("CAN_FD_MESSAGE", 0),
        ]
        packer = CANPacker(TEST_DBC)
        parser = CANParser(TEST_DBC, signals, checks, 0)

        # packer should increment the counter
        for i in range(1000):
            msg = packer.make_can_msg("CAN_FD_MESSAGE", 0, {})
            dat = can_list_to_can_capnp([
                msg,
            ])
            parser.update_string(dat)
            self.assertEqual(parser.vl["CAN_FD_MESSAGE"]["COUNTER"], i % 256)

        # setting COUNTER should override
        for _ in range(100):
            cnt = random.randint(0, 255)
            msg = packer.make_can_msg("CAN_FD_MESSAGE", 0, {
                "COUNTER": cnt,
            })
            dat = can_list_to_can_capnp([
                msg,
            ])
            parser.update_string(dat)
            self.assertEqual(parser.vl["CAN_FD_MESSAGE"]["COUNTER"], cnt)

        # then, should resume counting from the override value
        cnt = parser.vl["CAN_FD_MESSAGE"]["COUNTER"]
        for i in range(100):
            msg = packer.make_can_msg("CAN_FD_MESSAGE", 0, {})
            dat = can_list_to_can_capnp([
                msg,
            ])
            parser.update_string(dat)
            self.assertEqual(parser.vl["CAN_FD_MESSAGE"]["COUNTER"],
                             (cnt + i) % 256)