-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_cd30_acdi.py
executable file
·301 lines (238 loc) · 10.9 KB
/
check_cd30_acdi.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/usr/bin/env python3.10
'''
This uses a CAN link layer to check ACDI consistency
Usage:
python3.10 check_cd30_acdi.py
The -h option will display a full list of options.
'''
import sys
import logging
from openlcb.nodeid import NodeID
from openlcb.message import Message
from openlcb.mti import MTI
from openlcb.pip import PIP
from openlcb.snip import SNIP
import xmlschema
from queue import Empty
import olcbchecker.setup
def getReplyDatagram(destination) :
'''
Invoked after a datagram has been sent, this waits
for first the datagram reply message, then a
datagram message that contains a reply. It
replies with a datagram OK, then returns the reply datagram message.
Raises Exception if something went wrong.
'''
# first, wait for the reply
while True :
try :
received = olcbchecker.getMessage() # timeout if no entries
# is this a datagram reply, OK or not?
if not (received.mti == MTI.Datagram_Received_OK or received.mti == MTI.Datagram_Rejected) :
continue # wait for next
if destination != received.source : # check source in message header
continue
if NodeID(olcbchecker.ownnodeid()) != received.destination : # check destination in message header
continue
if received.mti == MTI.Datagram_Received_OK :
# OK, proceed
break
else : # must be datagram rejected
# can't proceed
raise Exception("Failure - Original Datagram rejected")
except Empty:
raise Exception("Failure - no reply to read request")
# now wait for the reply datagram
while True :
try :
received = olcbchecker.getMessage() # timeout if no entries
# is this a datagram reply, OK or not?
if not (received.mti == MTI.Datagram) :
continue # wait for next
if destination != received.source : # check source in message header
continue
if NodeID(olcbchecker.ownnodeid()) != received.destination : # check destination in message header
continue
# here we've received the reply datagram
# send the reply
message = Message(MTI.Datagram_Received_OK, NodeID(olcbchecker.ownnodeid()), destination, [0])
olcbchecker.sendMessage(message)
return received
except Empty:
raise Exception("Failure - no reply datagram received")
# get a string from a certain place in memory
def read_memory(destination, address, length, space) :
ad1 = (address >> 24) & 0xFF
ad2 = (address >> 16) & 0xFF
ad3 = (address >> 8) & 0xFF
ad4 = address & 0xFF
memory_read_command = [0x20, 0x40, ad1, ad2, ad3, ad4, space, length]
datagram = Message(MTI.Datagram, NodeID(olcbchecker.ownnodeid()), destination, memory_read_command)
olcbchecker.sendMessage(datagram)
content = getReplyDatagram(destination).data[7:]
# if we just asked for one byte, return that as an int
if length == 1 : return content[0]
# convert to string for convenience
result = ""
for one in content:
if one == 0 : break
result = result+chr(one)
return result
def check():
# set up the infrastructure
logger = logging.getLogger("CDI")
# pull any early received messages
olcbchecker.purgeMessages()
# get configured DUT node ID - this uses Verify Global in some cases, but not all
destination = olcbchecker.getTargetID()
###############################
# checking sequence starts here
###############################
pipSet = olcbchecker.gatherPIP(destination, always = True)
memory_config_present = (pipSet is None) or (PIP.MEMORY_CONFIGURATION_PROTOCOL in pipSet)
snip_in_pip = (pipSet is None) or (PIP.SIMPLE_NODE_IDENTIFICATION_PROTOCOL in pipSet)
acdi_in_pip = (pipSet is None) or (PIP.ADCDI_PROTOCOL in pipSet)
#####
# ACDI bit set and Memory Configuration bit not set
#####
if acdi_in_pip and not memory_config_present :
logger.warning ("Failure - ACDI is in PIP but Memory Configuration is not")
return 3
#####
# ACDI bit and Memory Configuration bit set
#####
manufacturerName = ""
modelName = ""
hardwareVersion = ""
softwareVersion = ""
userProvidedNodeName = ""
userProvidedDescription = ""
if acdi_in_pip and memory_config_present :
# check 251 and 252 spaces show present
memory_address_space_cmd = [0x20, 0x84, 251]
datagram = Message(MTI.Datagram, NodeID(olcbchecker.ownnodeid()), destination, memory_address_space_cmd)
olcbchecker.sendMessage(datagram)
try :
content = getReplyDatagram(destination).data
if content[1] != 0x87 :
logger.warning ("Failure - space 251 marked as not present")
return 3
except Exception as e :
logger.warning (str(e))
return (3)
memory_address_space_cmd = [0x20, 0x84, 252]
datagram = Message(MTI.Datagram, NodeID(olcbchecker.ownnodeid()), destination, memory_address_space_cmd)
olcbchecker.sendMessage(datagram)
try :
content = getReplyDatagram(destination).data
if content[1] != 0x87 :
logger.warning ("Failure - space 252 marked as not present")
return 3
# check version numbers in 251 and 252 spaces
v2 = read_memory(destination, 0, 1, 252)
if v2 != 0 and v2 != 4 :
logger.warning("Failure - Space 252 version number not match")
return (3)
v1 = read_memory(destination, 0, 1, 251)
if v1 != 0 and v1 != 2 :
logger.warning("Failure - Space 251 version number not match")
return (3)
# load the six strings
manufacturerName = read_memory(destination, 1, 41, 252)
modelName = read_memory(destination, 42, 41, 252)
hardwareVersion = read_memory(destination, 83, 21, 252)
softwareVersion = read_memory(destination, 104, 21, 252)
userProvidedNodeName = read_memory(destination, 1, 64, 251)
userProvidedDescription = read_memory(destination, 64, 64, 251)
except Exception as e :
logger.warning (str(e))
return (3)
#####
# SNIP bit, ACDI bit and Memory Configuration bit set
#####
if snip_in_pip and acdi_in_pip and memory_config_present :
# send a SNIP request message to provoke response
message = Message(MTI.Simple_Node_Ident_Info_Request, NodeID(olcbchecker.ownnodeid()), destination)
olcbchecker.sendMessage(message)
results = []
while True :
try :
received = olcbchecker.getMessage() # timeout if no entries
# is this a snip reply?
if not received.mti == MTI.Simple_Node_Ident_Info_Reply : continue # wait for next
if destination != received.source : # check source in message header
logger.warning ("Failure - Unexpected source of reply message: {} {}".format(received, received.source))
return(3)
if NodeID(olcbchecker.ownnodeid()) != received.destination : # check destination in message header
logger.warning ("Failure - Unexpected destination of reply message: {} {}".format(received, received.destination))
return(3)
# accumulate the data
results.extend(received.data)
except Empty:
break # finished receiving the reply
# load into SNIP for convenient retrieval
snip = SNIP()
snip.addData(results)
# now check the results against previously acquired data
if not manufacturerName == snip.manufacturerName :
logger.warning("Failure - SNIP ["+snip.manufacturerName+"] and ACDI manufacturer name ["+manufacturerName+"] did not match")
return (3)
if not modelName == snip.modelName :
logger.warning("Failure - SNIP ["+snip.modelName+"] and ACDI model name ["+modelName+"] did not match")
return (3)
if not hardwareVersion == snip.hardwareVersion :
logger.warning("Failure - SNIP ["+snip.hardwareVersion+"] and ACDI hardware version ["+hardwareVersion+"] did not match")
return (3)
if not softwareVersion == snip.softwareVersion :
logger.warning("Failure - SNIP ["+snip.softwareVersion+"] and ACDI software version ["+softwareVersion+"] did not match")
return (3)
if not userProvidedNodeName == snip.userProvidedNodeName :
logger.warning("Failure - SNIP ["+snip.userProvidedNodeName+"] and ACDI user node name ["+userProvidedNodeName+"] did not match")
return (3)
if not userProvidedDescription == snip.userProvidedDescription :
logger.warning("Failure - SNIP ["+snip.userProvidedDescription+"] and ACDI user description ["+userProvidedDescription+"] did not match")
return (3)
#####
# Memory Configuration bit and CDI bit set
#####
if memory_config_present and acdi_in_pip :
# read CDI to check for ACDI
address = 0
LENGTH = 64
content = []
while not 0x00 in content and address < 820 :
ad1 = (address >> 24) & 0xFF
ad2 = (address >> 16) & 0xFF
ad3 = (address >> 8) & 0xFF
ad4 = address & 0xFF
# send an read datagran
request = [0x20, 0x43, ad1,ad2,ad3,ad4, LENGTH]
message = Message(MTI.Datagram, NodeID(olcbchecker.ownnodeid()), destination, request)
olcbchecker.sendMessage(message)
try :
reply = getReplyDatagram(destination)
except Exception as e:
logger.warning (str(e))
return (3)
content.extend(reply.data[6:])
address = address+LENGTH
# here have front of CDI
# convert to string for convenience
result = ""
for one in content:
if one == 0 : break
result = result+chr(one)
acdi_in_cdi = "<acdi" in result # could be <acdi/> or <acdi></acdi>
if acdi_in_cdi and not acdi_in_pip :
logger.warning ("Failure - ACDI in CDI but not in PIP")
return 3
if not acdi_in_cdi and acdi_in_pip :
logger.warning ("Failure - ACDI in PIP but not in CDI")
return 3
logger.info("Passed")
return 0
if __name__ == "__main__":
result = check()
import olcbchecker
olcbchecker.setup.interface.close()
sys.exit(result)