I'm looking to develop a program that writes CAN data to an asc file (using the CAN protocol). The file is supposed to contain all data 10 seconds before and 10 seconds after there is a change with the error variable on the bus. To do this, I have created a log that rotates every 10 seconds. If an error is detected, 10 seconds of additional data are written to the file. When this data has been written, the file will be saved and the name of the rotating log file whill change. I'm having a variety of issues implementing my program (and I've been unsure of how to develop a more specific question because of the lack of resources for CAN protocol on the internet). Any help would be appreciated.
import can
import time
Bus = Bus
time_log = 0
time_log_calculator()
While time_log < 11
time.sleep(1)
time_log += 1
Else
do_rollover(data.msg)
time_log = 0
trigger_count = 0
variable_file_name = ("%s.asc", trigger_count)
Logger = can.io.BaseRotatingLogger( namer = variable_file_name, mode = open())
rotation_filename("%i.asc" rollover_count)
time_calculator_first()
def should_rollver(data.msg)
If data.msg != None
Return true
notifier = Notifier(bus = bus, listeners = [logger])
time = 0
time_calculator
time.sleep(1)
time = +1
return time
For msg in bus
If error_data_old = None
error_data_old = data.msg.dm1
error_data_new = data.msg.dm1
If error_data_new != error_data_old
# then we know that there has been a change in the variable value
Time_calculator()
While time < 10
printer = can.printer(variable_file_name, write_to_file = true, append = true)
on_message_received(msg)
Else
Trigger_count += 1
error_data_old = data.msg.dm1