receive_message

Receiving a CAN message from a bus
from pprint import pprint

get_argparser

 get_argparser ()

*summary get CAN bus, dbc config and the message to send

Returns: argparse.ArgumentParser: description*

db = cantools.database.load_file('../../res/motohawk_new.dbc')
db.messages
example_message: MessageTpl = db.get_message_by_name('ExampleMessage')
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
data_dict ={'Temperature': 250.1, 'AverageRadius': 3.2, 'Enable': 1}
data_json_bytes = json.dumps(data_dict).encode('utf-8')
data_json_bytes
json.loads(data_json_bytes.decode())

can_data = example_message.encode({'Temperature': 250.1, 'AverageRadius': 3.2, 'Enable': 1})
example_message.decode(can_data)
f = io.BytesIO(data_json_bytes)
bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
data = example_message.encode({'Temperature': 250.1, 'AverageRadius': 3.2, 'Enable': 1})
message_to_send = can.Message(arbitration_id=example_message.frame_id, data=data, is_extended_id=False)     
# can_bus.send(message)
manager = Manager()
message_proxy = manager.dict()

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