def __init__(self, dbc_name, signals, checks=[], bus=0): self.can_valid = True self.vl = defaultdict(dict) self.ts = defaultdict(dict) sig_names = dict( (name, ffi.new("char[]", name)) for name, _, _ in signals) signal_options_c = ffi.new( "SignalParseOptions[]", [{ 'address': sig_address, 'name': sig_names[sig_name], 'default_value': sig_default, } for sig_name, sig_address, sig_default in signals]) message_options = dict((address, 0) for _, address, _ in signals) message_options.update(dict(checks)) message_options_c = ffi.new( "MessageParseOptions[]", [{ 'address': address, 'check_frequency': freq, } for address, freq in message_options.iteritems()]) self.can = libdbc.can_init(bus, dbc_name, len(message_options_c), message_options_c, len(signal_options_c), signal_options_c) self.p_can_valid = ffi.new("bool*") value_count = libdbc.can_query(self.can, 0, self.p_can_valid, 0, ffi.NULL) self.can_values = ffi.new("SignalValue[%d]" % value_count) self.update_vl(0)
def __init__(self, dbc_name, signals, checks=None, bus=0, sendcan=False, tcp_addr="127.0.0.1"): if checks is None: checks = [] self.can_valid = True self.vl = defaultdict(dict) self.ts = defaultdict(dict) self.dbc_name = dbc_name self.dbc = libdbc.dbc_lookup(dbc_name) self.msg_name_to_addres = {} self.address_to_msg_name = {} num_msgs = self.dbc[0].num_msgs for i in range(num_msgs): msg = self.dbc[0].msgs[i] name = ffi.string(msg.name) address = msg.address self.msg_name_to_addres[name] = address self.address_to_msg_name[address] = name # Convert message names into addresses for i in range(len(signals)): s = signals[i] if not isinstance(s[1], numbers.Number): s = (s[0], self.msg_name_to_addres[s[1]], s[2]) signals[i] = s for i in range(len(checks)): c = checks[i] if not isinstance(c[0], numbers.Number): c = (self.msg_name_to_addres[c[0]], c[1]) checks[i] = c sig_names = dict( (name, ffi.new("char[]", name)) for name, _, _ in signals) signal_options_c = ffi.new( "SignalParseOptions[]", [{ 'address': sig_address, 'name': sig_names[sig_name], 'default_value': sig_default, } for sig_name, sig_address, sig_default in signals]) message_options = dict((address, 0) for _, address, _ in signals) message_options.update(dict(checks)) message_options_c = ffi.new( "MessageParseOptions[]", [{ 'address': msg_address, 'check_frequency': freq, } for msg_address, freq in message_options.items()]) self.can = libdbc.can_init(bus, dbc_name, len(message_options_c), message_options_c, len(signal_options_c), signal_options_c, sendcan, tcp_addr) self.p_can_valid = ffi.new("bool*") value_count = libdbc.can_query(self.can, 0, self.p_can_valid, 0, ffi.NULL) self.can_values = ffi.new("SignalValue[%d]" % value_count) self.update_vl(0)