Exemplo n.º 1
0
  def test_honda_checksum(self):
    """Test checksums for Honda standard and extended CAN ids"""
    dbc_file = "honda_accord_2018_can_generated"

    signals = [
      ("CHECKSUM", "LKAS_HUD"),
      ("CHECKSUM", "LKAS_HUD_A"),
    ]
    checks = [("LKAS_HUD", 0), ("LKAS_HUD_A", 0)]

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

    values = {
      'SET_ME_X41': 0x41,
      'STEERING_REQUIRED': 1,
      'SOLID_LANES': 1,
      'BEEP': 0,
    }

    # known correct checksums according to the above values
    checksum_std = [11, 10, 9, 8]
    checksum_ext = [4, 3, 2, 1]

    for std, ext in zip(checksum_std, checksum_ext):
      msgs = [
        packer.make_can_msg("LKAS_HUD", 0, values),
        packer.make_can_msg("LKAS_HUD_A", 0, values),
      ]
      can_strings = [can_list_to_can_capnp(msgs), ]
      parser.update_strings(can_strings)

      self.assertEqual(parser.vl['LKAS_HUD']['CHECKSUM'], std)
      self.assertEqual(parser.vl['LKAS_HUD_A']['CHECKSUM'], ext)
Exemplo n.º 2
0
    def test_updated(self):
        """Test updated value dict"""
        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)

        # Make sure nothing is updated
        self.assertEqual(len(parser.vl_all["VSA_STATUS"]["USER_BRAKE"]), 0)

        idx = 0
        for _ in range(10):
            # Ensure CANParser holds the values of any duplicate messages over multiple frames
            user_brake_vals = [
                random.randrange(100) for _ in range(random.randrange(5, 10))
            ]
            half_idx = len(user_brake_vals) // 2
            can_msgs = [[], []]
            for frame, brake_vals in enumerate(
                (user_brake_vals[:half_idx], user_brake_vals[half_idx:])):
                for user_brake in brake_vals:
                    values = {"USER_BRAKE": user_brake}
                    can_msgs[frame].append(
                        packer.make_can_msg("VSA_STATUS", 0, values))
                    idx += 1

            can_strings = [can_list_to_can_capnp(msgs) for msgs in can_msgs]
            parser.update_strings(can_strings)
            vl_all = parser.vl_all["VSA_STATUS"]["USER_BRAKE"]

            self.assertEqual(vl_all, user_brake_vals)
            if len(user_brake_vals):
                self.assertEqual(vl_all[-1],
                                 parser.vl["VSA_STATUS"]["USER_BRAKE"])
Exemplo n.º 3
0
def can_sync_thread():

    can_sock = messaging.sub_sock('can', conflate=True, timeout=100)
    can_pub = None

    os.environ["ZMQ"] = "1"
    pub_context = messaging_pyx.Context()
    can_pub = messaging_pyx.PubSocket()
    can_pub.connect(pub_context, 'testJoystick')
    del os.environ["ZMQ"]

    rk = Ratekeeper(100.0, print_delay_threshold=None)

    cc_main = 0
    cc_status = 0
    speed = 0.0

    dbc_file = "toyota_yaris"
    signals = [
        # sig_name, sig_address, default
        ("GEAR", "GEAR_PACKET", 0),
        ("BRAKE_PRESSED", "BRAKE_MODULE2", 0),
        ("GAS_PEDAL", "GAS_PEDAL", 0),
        ("SEATBELT_DRIVER_UNLATCHED", "SEATS_DOORS", 0),
        ("DOOR_OPEN_FL", "SEATS_DOORS", 0),
        ("DOOR_OPEN_FR", "SEATS_DOORS", 0),
        ("DOOR_OPEN_RL", "SEATS_DOORS", 0),
        ("DOOR_OPEN_RR", "SEATS_DOORS", 0),
        ("MAIN_ON", "PCM_CRUISE_SM", 0),
        ("CRUISE_CONTROL_STATE", "PCM_CRUISE_SM", 0),
        ("TURN_SIGNALS", "STEERING_LEVERS", 0),  # 3 is no blinkers
        ("ENGINE_RPM", "POWERTRAIN", 0),
        ("SPEED", "SPEED", 0),
        ("MAY_CONTAIN_LIGHTS", "BOOLS", 0),
        ("CHANGES_EACH_RIDE", "SLOW_VARIABLE_INFOS", 0),
        ("INCREASING_VALUE_FUEL", "SLOW_VARIABLE_INFOS", 0)
    ]
    checks = []
    parser = CANParser(dbc_file, signals, checks, 0)
    play_time = 0

    while True:
        try:
            can_strs = messaging.drain_sock_raw(can_sock, wait_for_one=True)
            parser.update_strings(can_strs)

            # print (parser.vl)

            cc_main = parser.vl['PCM_CRUISE_SM']['MAIN_ON']
            cc_status = parser.vl['PCM_CRUISE_SM']['CRUISE_CONTROL_STATE']
            speed = parser.vl['SPEED']['SPEED']

            doorOpen = any([
                parser.vl["SEATS_DOORS"]['DOOR_OPEN_FL'],
                parser.vl["SEATS_DOORS"]['DOOR_OPEN_FR'],
                parser.vl["SEATS_DOORS"]['DOOR_OPEN_RL'],
                parser.vl["SEATS_DOORS"]['DOOR_OPEN_RR']
            ])
            seatbeltUnlatched = parser.vl["SEATS_DOORS"][
                'SEATBELT_DRIVER_UNLATCHED'] != 0
            light = parser.vl["BOOLS"]["MAY_CONTAIN_LIGHTS"]
            a = parser.vl["SLOW_VARIABLE_INFOS"]["CHANGES_EACH_RIDE"]
            b = parser.vl["SLOW_VARIABLE_INFOS"]["INCREASING_VALUE_FUEL"]

            if doorOpen:
                play_time = play_sound(SOUND_PATH + 'door_open.wav', play_time,
                                       3)

            if seatbeltUnlatched:
                play_time = play_sound(SOUND_PATH + 'seatbelt.wav', play_time,
                                       3)

            if light != 0:
                play_time = play_sound(SOUND_PATH + 'turn_signal.wav',
                                       play_time, 3)

            cc_main_v = 0
            if cc_main:
                cc_main_v = 1

            can_dict = {
                'cc_main': cc_main_v,
                'cc_status': cc_status,
                'speed': speed,
                'light': light,
                'a': a,
                'b': b
            }

            json_str = json.dumps(can_dict)
            json_str = json_str.replace('\'', '"')
            can_pub.send(json_str)

        except messaging_pyx.MessagingError:
            print('MessagingError error happens')

    rk.keep_time()