-
Notifications
You must be signed in to change notification settings - Fork 4
/
eucerttest_5_3_ethernet.py
377 lines (334 loc) · 9.66 KB
/
eucerttest_5_3_ethernet.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
##############################################################################
#
# Module: eucerttest_5_3_ethernet.py
#
# Description:
# Script to perform EU certification 5.3 test through ethernet
#
# Copyright notice:
# This file copyright (c) 2021 by
#
# MCCI Corporation
# 3520 Krums Corners Road
# Ithaca, NY 14850
#
# See accompanying LICENSE file for copyright and license information.
#
# Author:
# Sivaprakash Veluthambi, MCCI January, 2021
#
##############################################################################
import os, sys
import time
sys.path.insert(0, os.path.abspath('..'))
from rwclib.cRWC5020x import RWCTesterApi
def debug(msg):
'''
Display debug message
'''
print(msg, end='\n')
return True
def err(msg):
'''
Display error message
'''
print(msg, end='\n')
def fatal(msg):
'''
Exit on error
'''
err(msg)
print('\nTest Result: FAIL')
sys.exit(1)
def exec_link():
'''
To start link test
'''
result = ob.link_run()
if result:
if result == 'ACK':
debug('Link Status: Running\n')
else:
fatal('Link execution failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def clear_link():
'''
Clear existing link messages
'''
result = ob.link_clear()
if result:
if result == 'ACK':
debug('Old link messages cleared\n')
else:
fatal('Clear link message failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def set_dlslot(slot):
'''
Configure downlink slot
'''
result = ob.protocol_setdownlinkslot(slot)
if result:
if result == 'ACK':
debug('Protocol Downlink Slot: {}'.format(slot))
else:
fatal('Configuring downlink slot failed')
else:
fatal('Tester returns none and connection timed-out')
return True
def set_mactype():
'''
Configure MAC command type
'''
mactype = 'UNCONFIRMED'
result = ob.link_setmaccmdtype(mactype)
if result:
if result == 'ACK':
debug('Link MAC Command Type: {}'.format(mactype))
else:
fatal('Configuring MAC command type failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def set_maccmdfield():
'''
Configure MAC command field
'''
maccmdfield = 'PAYLOAD'
result = ob.link_setmaccmdfield(maccmdfield)
if result:
if result == 'ACK':
debug('Link MAC Command Field: {}'.format(maccmdfield))
else:
fatal('Configuring MAC command field failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def set_numofcmd():
'''
Configure number of MAC command
'''
num = 1
result = ob.link_setnumofmaccmd(num)
if result:
if result == 'ACK':
debug('Link Number of Command: {}'.format(num))
else:
fatal('Configuring no. of commands failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def instant_mac_cmd(num, maccmd):
'''
Configure instant MAC command
'''
result = ob.link_setinstantmaccmd(num, maccmd)
if result:
if result == 'ACK':
debug('Link Instant MAC Command: {}\n'.format(maccmd))
else:
fatal('Configuring instant MAC command failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def set_echolen(length):
'''
Configure payload length
'''
result = ob.link_setpayloadlength(1, length)
if result:
if result == 'ACK':
debug('Set Bytes: {}'.format(length))
else:
fatal('Configuring bytes length failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def set_droffset(val):
'''
Configure RX1 data rate offset
'''
result = ob.protocol_setrx1_dr_offset(val)
if result:
if result == 'ACK':
debug('Protocol RX1_DR_OFFSET value: {}'.format(val))
else:
fatal('Configuring RX1_DR_OFFSET failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def set_dr(val):
'''
Configure RX2 DR value
'''
result = ob.protocol_setrx2_dr(val)
if result:
if result == 'ACK':
debug('Protocol RX2_DR value: {}\n'.format(val))
else:
fatal('Configuring RX2_DR failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def link_status():
'''
To check the status of link test
'''
cnt = 0
while(cnt < 2):
result = ob.link_getactivationstatus()
if not result:
fatal('Tester returns none and connection timed-out\n')
if result == 'YES':
debug('Link status: Active\n')
return True
else:
if cnt == 0:
debug('Link status: In-active\n'
'Please make sure the link is active\nTrying again...\n')
time.sleep(15)
cnt = cnt + 1
status = True if cnt < 2 and result == 'YES' else None
if status:
return True
else:
fatal('Link status: In-active\n')
def config_param(slot, num, maccmd):
'''
Configure parameters for EU test
'''
set_dlslot(slot)
set_mactype()
set_maccmdfield()
set_numofcmd()
instant_mac_cmd(num, maccmd)
def link_msg():
'''
To read the link message
'''
msg = None
while (msg is None or msg == 'NA'):
msg = ob.link_readmsg()
time.sleep(3)
if msg and msg != 'NAK':
return msg
else:
fatal('READ:LINK:MSG? - {}\n'.format(msg))
def send_mac():
'''
To send a MAC command
'''
time.sleep(1)
result = ob.link_sendmac()
if result:
if result == 'ACK':
#debug('MAC Command Sent')
pass
else:
fatal('Send MAC command failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def link_reset():
'''
Reset the link message
'''
result = ob.link_msgreset()
if result:
if result == 'ACK':
#debug('Link message reset')
pass
else:
fatal('Link message reset failed\n')
else:
fatal('Tester returns none and connection timed-out\n')
return True
def link_test(num, req_cmd, resp_cmd):
'''
To perform link test
'''
cnt = 0
while (cnt < 2):
rcnt = 0
send_mac()
time.sleep(1)
link_reset()
while (rcnt < 2):
msg = link_msg()
msglist = msg.split('\t')
if req_cmd in msglist[num]:
print('MAC Request: {}'.format(msglist[num]), end='\n')
msg = link_msg()
msglist = msg.split('\t')
if resp_cmd in msglist[num]:
print('Response: {}'.format(msglist[num]), end='\n\n')
return True
else:
if rcnt < 1:
err('Invalid Response: {}\nTrying again...\n' \
.format(msglist[num]))
time.sleep(3)
rcnt += 1
else:
err('Invalid Response: {}\n'.format(msglist[num]))
return False
else:
#err('Invalid MAC Request : {} \n'.format(msglist[num]))
rcnt += 1
time.sleep(1)
cnt += 1
if __name__ == '__main__':
ob = RWCTesterApi('5001', '192.168.0.33') # For Ethernet communication
# Open port
ob.open_port()
# Clear if old link messages
clear_link()
# Run Link
exec_link()
debug('Start EU Certification(5.3) Test\n')
# Check link status
link_status()
# Send ACTIVATE_TM mac request
debug('ACTIVATE-TM MAC CMD REQUEST\n')
config_param('RX1', 1, 'ACTIVATE_TM')
result = link_test(17, 'ActivateTM', 'DlCounter')
if bool(result) is False:
fatal('ACTIVATE-TM MAC CMD REQUEST: Test Failed\n')
# Send TRIGGER_JOIN_REQ_TM mac request
debug('TRIGGER JOIN MAC CMD REQUEST\n')
set_droffset(2)
set_dr('DR2_SF10BW125')
config_param('RX1', 1, 'TRIGGER_JOIN_REQ_TM')
result = link_test(17, 'TriggerJoinReq', 'Join-request')
if bool(result) is False:
fatal('TRIGGER JOIN MAC CMD REQUEST: Test Failed\n')
# Check link status
link_status()
# Send ACTIVATE_TM mac request
debug('ACTIVATE-TM MAC CMD REQUEST\n')
config_param('RX1', 1, 'ACTIVATE_TM')
result = link_test(17, 'ActivateTM', 'DlCounter')
if bool(result) is False:
fatal('ACTIVATE-TM MAC CMD REQUEST: Test Failed\n')
# Send ECHO REQUEST mac command
byte_len = 2
debug('ECHO REQUEST MAC CMD REQUEST\n')
set_echolen(byte_len)
config_param('RX1', 1, 'ECHO_REQUEST_TM')
result = link_test(17, 'EchoRequest', 'EchoResponse')
if bool(result) is False:
fatal('ECHO REQUEST MAC CMD REQUEST (Bytes - {}): Test Failed\n' \
.format(byte_len))
# Send ECHO REQUEST mac command
debug('ECHO REQUEST MAC CMD REQUEST\n')
set_echolen(byte_len)
config_param('RX2', 1, 'ECHO_REQUEST_TM')
result = link_test(17, 'EchoRequest', 'EchoResponse')
if bool(result) is False:
fatal('ECHO REQUEST MAC CMD REQUEST (Bytes - {}): Test Failed\n' \
.format(byte_len))
debug('EU Certification(5.3) Test Finished\nTest Result: PASS')
ob.close_port()