-
Notifications
You must be signed in to change notification settings - Fork 3
/
j1708_com_replay_log.py
75 lines (58 loc) · 1.91 KB
/
j1708_com_replay_log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import serial, time, signal, sys, csv, re
from j1708 import Message
from j1708 import to_dec
from settings import *
def signal_handler(signal, handler):
if 'com' in globals():
if com.is_open:
com.close()
print('Script interrupted!\n')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def load_from_csv(filename):
messages = []
input_file = open(filename,'r')
reader = csv.reader(input_file,delimiter=';')
for row in reader:
content_list = row[4]
content_list = content_list[1:-1]
print(content_list)
#content_list = [int(i) for i in content_list.split(',')]
#print(content_list)
message = Message(
int(row[0]),
content_list,
int(row[3]),
int(row[1]),
int(row[2])
)
messages.append(message)
input_file.close()
return messages
def message_send(message):
if com.is_open:
print(f"MID: {message.mid} LEN: {message.length} CRC: {message.checksum} CONTENT: {message.content}")
#print(type(message.content))
com.write(bytes(message.content,'utf-8'))
#com.write(b'\r')
if __name__ == "__main__":
com = serial.Serial()
com.port = CONF_SERIAL_TX_NAME
com.baudrate = CONF_SERIAL_BAUDRATE
if ~com.is_open:
com.open()
messages = load_from_csv('messages_dump.txt')
test = messages[0].content
total_messages = len(messages)
print(f"{total_messages} messages loaded.")
print(f"Starting transmission on {com.port}...")
#count = 0
for ind, msg in enumerate(messages):
print(f"Transmitting {ind+1}/{total_messages}...")
print(list(msg.content.split(',')))
message_send(msg)
#count += 1
time.sleep(0.2)
print(f"All mesages has been transmitted.\rExiting...")
#print(count)
com.close()