Index: Miscellaneous/DG_Firmware_Simulator.py =================================================================== diff -u -rabd93c1d800178a5ee618b9bba83532b853e3c96 -reeded10f89bd0722474d326a6423c755a11cc988 --- Miscellaneous/DG_Firmware_Simulator.py (.../DG_Firmware_Simulator.py) (revision abd93c1d800178a5ee618b9bba83532b853e3c96) +++ Miscellaneous/DG_Firmware_Simulator.py (.../DG_Firmware_Simulator.py) (revision eeded10f89bd0722474d326a6423c755a11cc988) @@ -1,69 +1,39 @@ -import serial -import random +from DialityCoreCanProtocol import * from time import sleep -START_BYTE = b'\xA5' +dialin_messenger = DialinCanMessenger() - -def calculate_crc(message): - return sum(message[0:-1]) % 256 - - -def build_message(message): - message_out = bytearray(message) - message_out[-1] = calculate_crc(message_out) - return message_out - - -serial_port = serial.Serial(port='/dev/ttyUSB1', baudrate=115200) - # Building response message -response_message = build_message(START_BYTE + b'\x00\x03' + b'\x01' + b'\x00' + b'\x00') -# Building Async response message -async_message = build_message(START_BYTE + b'\x00\x02' + b'\x02' + b'\x01\x02' + b'\x00') +response_msg = DialinMessage.buildMessage(channel_id=DialinChannels.dg_to_hd_ch_id, + message_id=1000, + payload=[1]) -# Building Sync response message -sync_message = build_message(START_BYTE + b'\x00\x05' + b'\x02' + b'\x05\x06' + b'\x00') +# Building Publication message +publication_msg = DialinMessage.buildMessage(channel_id=DialinChannels.dg_sync_broadcast_ch_id, + message_id=0x7100, + payload=[1, 2, 3, 4, 5]) -counter = 0 - print("") -print("o -> response") -print(". -> Sync") -print("x -> Async") +print("o -> response to fill command") +print(". -> publication message") print("") -while True: +def respondToCommand(message): + dialin_messenger.send(response_msg) + print("o", end='', flush=True) - bytes_in_serial_port = serial_port.in_waiting; - if bytes_in_serial_port != 0: - # This is what we received - serial_port.read(bytes_in_serial_port) +# Register response command for the DG +dialin_messenger.registerReceivingPublicationFunction(channel_id=DialinChannels.ui_to_hd_ch_id, + message_id=1000, + function=respondToCommand) - # Answer immediately - serial_port.write(response_message) +dialin_messenger.start() - # Show on the screen - print("o", end='', flush=True) - - - sleep(0.05) - - counter += 1 - - if counter == 20: - counter = 0 - - # Send Sync Values - serial_port.write(sync_message) - - print(".", end='', flush=True) - - if random.randint(1, 100) == 69: - # Send Async message - serial_port.write(async_message) - - print("x", end='', flush=True) +# This is the main loop +while True: + dialin_messenger.send(publication_msg) + print(".", end='', flush=True) + sleep(1)