-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackground_generator.py
executable file
·64 lines (45 loc) · 1.71 KB
/
background_generator.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
#!/usr/bin/env python3.10
'''
This uses the CAN link layer to generate
a continuous stream of low-priority messages
to provide a background of frames trying to arbitrate
Usage e.g.:
python3.10 background_generator.py -d /dev/cu.usbmodemCC570001B1
The -h option will display a full list of options.
To get the lowest possible CAN priority, this sends
an end-datagram frame from the 0xFFF alias to the 0xFFE alias.
This does _not_ handle collisions should either of
those aliases already exist on the CAN network.
'''
import sys
import time
from openlcb.nodeid import NodeID
def check():
# get and process options
import configure
trace = configure.trace # just to be shorter
# configure the physical link
if configure.hostname is not None :
from openlcb.canbus.tcpsocket import TcpSocket
s = TcpSocket()
s.connect(configure.hostname, configure.portnumber)
else :
from openlcb.canbus.seriallink import SerialLink
s = SerialLink()
s.connect(configure.devicename)
if trace >= 20 :
print("RM, SM are message level receive and send; RL, SL are link (frame) interface; RR, SR are raw socket interface")
def sendToSocket(string) :
if trace >= 40 : print(" SR: "+string.strip())
s.send(string)
# Predefined frames
amdFrameOwn = ":X10701FFEN03000000FEED;"
amdFrameODest = ":X10701FFFN03000000BEEF;"
dataFrame = ":X1DFFFFFEN00;" # from FFF to FFE, end segment of datagram
# establish aliases for our traffic
sendToSocket(amdFrameOwn)
sendToSocket(amdFrameODest)
while True :
sendToSocket(dataFrame)
if __name__ == "__main__":
sys.exit(check())