from pprint import pprint
receive_message
Receiving a CAN message from a bus
get_argparser
get_argparser ()
*summary get CAN bus, dbc config and the message to send
Returns: argparse.ArgumentParser: description*
= cantools.database.load_file('../../res/motohawk_new.dbc')
db
db.messages= db.get_message_by_name('ExampleMessage')
example_message: MessageTpl
pprint(example_message.signals)# pprint(example_message.__dict__)
example_message.frame_id
!gpg -d -q ~/.sshpasswd.gpg | sshpass -v sudo modprobe vcan
!gpg -d -q ~/.sshpasswd.gpg | sshpass -v sudo ip link add dev vcan0 type vcan
# sshpass -v -p asdf sudo ip link add dev vcan0 type vcan
!ip link show vcan0
# !gpg -d -q ~/.sshpasswd.gpg | sshpass -v sudo ip link set vcan0 type vcan bitrate 500000 # vcan Does not SUPPORT set bitrate on command line!
# !sshpass -p asdf sudo ip link add dev vcan0 type vcan
!gpg -d -q ~/.sshpasswd.gpg | sshpass -v sudo ip link set up vcan0
# !sshpass -v -p asdf sudo ip link set up vcan0
={'Temperature': 250.1, 'AverageRadius': 3.2, 'Enable': 1}
data_dict = json.dumps(data_dict).encode('utf-8')
data_json_bytes
data_json_bytes
json.loads(data_json_bytes.decode())
= example_message.encode({'Temperature': 250.1, 'AverageRadius': 3.2, 'Enable': 1})
can_data example_message.decode(can_data)
= io.BytesIO(data_json_bytes) f
= can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
bus = example_message.encode({'Temperature': 250.1, 'AverageRadius': 3.2, 'Enable': 1})
data = can.Message(arbitration_id=example_message.frame_id, data=data, is_extended_id=False)
message_to_send # can_bus.send(message)
= Manager()
manager = manager.dict() message_proxy
receive_msg
receive_msg (db:cantools.database.can.database.Database, message:str, channel:str, bitrate:int, bus_type:str)
receive_message
receive_message (message_proxy:multiprocessing.managers.DictProxy, bus:<function Bus>)
os.getcwd()
# proc = subprocess.Popen(['python', 'message_send.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
# print(f'PARENT: {proc.pid} before signaling child')
# sys.stdout.flush()
# time.sleep(1)
# receive_message(message_proxy, bus)
# print(f'PARENT: {proc.pid} signaling child')
# sys.stdout.flush()
# os.kill(proc.pid, signal.SIGUSR1)
# stdout_value = proc.communicate()[0].decode('utf-8')
# print(f'stdout: {repr(stdout_value)}')
# datetime.fromtimestamp(message_proxy['timestamp']),db.decode_message(message_proxy['arbitration_id'],message_proxy['data'])
# close and remove vcan0
# !sshpass -v -p asdf sudo ip link delete vcan0
!gpg -d -q ~/.sshpasswd.gpg | sshpass -v sudo ip link set down vcan0
!gpg -d -q ~/.sshpasswd.gpg | sshpass -v sudo ip link delete vcan0