-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgetUnderTestAlias.py
More file actions
executable file
·75 lines (65 loc) · 2.28 KB
/
getUnderTestAlias.py
File metadata and controls
executable file
·75 lines (65 loc) · 2.28 KB
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
75
#!/usr/bin/env python
'''
Assuming one under-test node present, get its alias
@author: Bob Jacobsen
'''
import connection as connection
import verifyNodeGlobal
import canolcbutils
'''
Returns list of alias, nodeID
It obtains these by sending a globally-visible "verify nodes" message,
so it expects to have only one node on the network so that replies are unique.
'''
def get(alias, nodeID, verbose) :
connection.network.send(verifyNodeGlobal.makeframe(alias, nodeID))
while (True) :
reply = connection.network.receive()
if (reply == None ) : return None,None
if (reply.startswith(":X19170")) :
alias,nodeID = int(reply[7:10],16),canolcbutils.bodyArray(reply)
if verbose : print "Found alias "+str(alias)+" ("+hex(alias)+") for node ID ",nodeID
return alias,nodeID
def usage() :
print ""
print " Assumoing one under-test node present, uses "
print " one CAN VerifyNode (Global) message"
print " to get that node's alias "
print ""
print "Default connection detail taken from connection.py"
print ""
print "-a --alias source alias (default 123)"
print "-n --node dest nodeID (default None)"
print "-v verbose"
import getopt, sys
def main():
# argument processing
nodeID = None
alias = connection.thisNodeAlias
verbose = False
try:
opts, remainder = getopt.getopt(sys.argv[1:], "h:p:n:a:vV", ["alias=", "node=", "host=", "port="])
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" or opt == "-V":
connection.network.verbose = True
verbose = True
elif opt in ("-h", "--host"):
connection.network.host = arg
elif opt in ("-p", "--port"):
connection.network.port = int(arg)
elif opt in ("-a", "--alias"):
alias = int(arg)
elif opt in ("-n", "--node"):
nodeID = canolcbutils.splitSequence(arg)
else:
assert False, "unhandled option"
# now execute
alias,nodeID = get(alias, nodeID, verbose)
connection.network.close()
if __name__ == '__main__':
main()