-
Notifications
You must be signed in to change notification settings - Fork 3
/
identifyConsumers.py
executable file
·74 lines (64 loc) · 2.07 KB
/
identifyConsumers.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
#!/usr/bin/env python
'''
Send identifyConsumers message
@author: Bob Jacobsen
'''
import connection as connection
import canolcbutils
import defaults
def makeframe(alias, eventID) :
return canolcbutils.makeframestring(0x198F4000+alias,eventID)
def usage() :
print ""
print "Called standalone, will send one CAN IdentifyConsumers message"
print " and display response"
print ""
print "Expect zero or more ConsumerIdentified reply in return"
print "e.g. [194C4sss] nn nn nn nn nn nn"
print "containing dest alias and EventID"
print ""
print "Default connection detail taken from connection.py"
print ""
print "-a --alias source alias (default 0x"+hex(connection.thisNodeAlias).upper()+")"
print "-e --event eventID as 1.2.3.4.5.6.7.8 form"
print "-v verbose"
print "-V Very verbose"
import getopt, sys
def main():
alias = connection.thisNodeAlias
event = defaults.testEventID
verbose = False
# argument processing
try:
opts, remainder = getopt.getopt(sys.argv[1:], "e:a:vV", ["alias=", "event="])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
for opt, arg in opts:
if opt == "-v":
verbose = True
elif opt == "-V":
verbose = True
connection.network.verbose = True
elif opt in ("-a", "--alias"):
alias = int(arg) # needs hex decode
elif opt in ("-e", "--event"):
event = canolcbutils.splitSequence(arg)
else:
usage()
return
retval = test(alias,event,connection,verbose)
connection.network.close()
exit(retval)
def test(alias,event,connection,verbose) :
connection.network.send(makeframe(alias,event))
count = 0
while (True) :
if (connection.network.receive() == None ) : break
count = count + 1
if verbose : print " Found",count,"nodes"
return 0
if __name__ == '__main__':
main()