-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathverifyNodeGlobalTcp.py
executable file
·105 lines (91 loc) · 3.5 KB
/
verifyNodeGlobalTcp.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
'''
Handle OpenLCB verifyNodeGlobal
@author: Bob Jacobsen
'''
import connection as connection
import tcpolcbutils
def makeMessage(sourceNodeID, destNodeID) :
body = [0x04,0x90]+sourceNodeID
if destNodeID != None :
body += destNodeID
return tcpolcbutils.makemessagestring(sourceNodeID, None, body)
def usage() :
print ""
print "Called standalone, will send TCP VerifyNode (Global) message."
print "By default, this carries no Node ID information in the body, "
print "but if you supply the -n or --node option, it will be included."
print ""
print "Expect a single VerifiedNode reply in return"
print "containing destination NodeID"
print ""
print "Default connection detail taken from connection.py"
print ""
print "-n --node dest nodeID (default None, format 01.02.03.04.05.06)"
print "-v verbose"
print "-V Very verbose"
import getopt, sys
def main():
# argument processing
sourceNodeID = [0x11,0x12,0x13,0x14,0x15,0x16]
destNodeID = [1,2,3,4,5,6]
alias = connection.thisNodeAlias
identifynode = False
verbose = False
try:
opts, remainder = getopt.getopt(sys.argv[1:], "tn:a:vV", ["alias=", "node="])
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 ("-n", "--node"):
destNodeID = tcpolcbutils.splitSequence(arg)
else:
assert False, "unhandled option"
# now execute
retval = test(sourceNodeID, destNodeID, connection, verbose)
connection.network.close()
exit(retval)
def test(sourceNodeID, destNodeID, connection, verbose):
if verbose :
print "First message sent: "+tcpolcbutils.format(makeMessage(sourceNodeID, destNodeID))
# first, send with dest node's nodeID in data
connection.network.send(makeMessage(sourceNodeID, destNodeID))
reply = connection.network.receive()
if (reply == None ) :
print "Global verify with matching node ID did not receive expected reply"
return 2
[transmitter, message] = reply
[mti, source, dest, body] = tcpolcbutils.parseMessage(message)
if not mti == 0x0170 :
print "Global verify with matching node ID received wrong reply message", tcpolcbutils.formatMessage(message)
return 4
# send without nodeID in data
connection.network.send(makeMessage(sourceNodeID, None))
reply = connection.network.receive()
if (reply == None ) :
print "Global verify without node ID did not receive expected reply"
return 12
[transmitter, message] = reply
[mti, source, dest, body] = tcpolcbutils.parseMessage(message)
if not mti == 0x0170 :
print "Global verify without node ID received wrong reply message ", tcpolcbutils.formatMessage(message)
return 14
# send with wrong node ID in data
connection.network.send(makeMessage(sourceNodeID, [0,0,0,0,0,1]))
reply = connection.network.receive()
if (reply == None ) :
return 0
else :
[transmitter, message] = reply
print "Global verify with wrong node ID should not receive reply but did: ", tcpolcbutils.formatMessage(message)
return 24
if __name__ == '__main__':
main()