Skip to content

Commit c509af3

Browse files
committed
python removed extra plumbing
1 parent d285b5f commit c509af3

File tree

3 files changed

+30
-61
lines changed

3 files changed

+30
-61
lines changed

TEST_APPS/device/nfcapp/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void wrap_printf(const char *f, va_list a)
6767

6868

6969
/** Disables VT100 etc. for easy manual UI interaction */
70-
int seteasy(int argc, char *argv[])
70+
int set_easy_printer(int argc, char *argv[])
7171
{
7272
const char msg[][20] =
7373
{ "echo off", "set --retcode true", "set --vt100 off" };
@@ -77,6 +77,7 @@ int seteasy(int argc, char *argv[])
7777
return (CMDLINE_RETCODE_SUCCESS);
7878
}
7979

80+
8081
/**
8182
* This test app can be used standalone interactively with at 115200 baud terminal. It is designed to work with the
8283
* IceTea test framework https://os.mbed.com/docs/latest/tools/icetea-testing-applications.html . This app does
@@ -93,6 +94,8 @@ int seteasy(int argc, char *argv[])
9394
int main()
9495
{
9596
cmd_init(&wrap_printf);
97+
HandleTestCommand handleCommands; // For handling test commands and set nfc message queue
98+
9699
cmd_add("getlastnfcerror", HandleTestCommand::cmd_get_last_nfc_error,
97100
"last NFC error code", errorcodes);
98101
cmd_add("setlastnfcerror", HandleTestCommand::cmd_set_last_nfc_error,
@@ -127,7 +130,7 @@ int main()
127130
"get supported protocols", "returns CSV list, see setprotocols");
128131
cmd_add("setprotocols", HandleTestCommand::cmd_configure_rf_protocols,
129132
"set rf protocols", "-p [t1t]/[t2t]/[t3t]/[isodep]/[nfcdep]/[t5t]");
130-
cmd_add("easy", seteasy, "Use human readable terminal output",
133+
cmd_add("easy", set_easy_printer, "Use human readable terminal output",
131134
"echo off,vt100 off,return-codes visible");
132135
cmd_add("trace", HandleTestCommand::cmd_set_trace, "detailed tracing on/off, ",
133136
"Defaults to enabled; values like 'on','true','1' all turn it on, anything else turns off detailed tracing.");
@@ -146,7 +149,6 @@ int main()
146149
#endif
147150
{
148151
int c;
149-
HandleTestCommand handleCommands; // For handling test commands and set nfc message queue
150152
while ((c = getc(stdin)) != EOF) {
151153
cmd_char_input(c);
152154
}

TEST_APPS/testcases/nfc/nfc_clf_wrapper.py

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
from nfc.clf import RemoteTarget
2121
import logging
2222

23-
logprefixnfc = "NFCPY: "
24-
2523
"""
2624
Wrap calls to nfcpi testing module, handle loading the driver
2725
"""
2826

2927

30-
def command_is(string, command):
31-
return string.split(' ')[0] == command
28+
# def command_is(string, command):
29+
# return string.split(' ')[0] == command
3230

3331

3432
def debug_nfc_data(key, value):
@@ -60,52 +58,25 @@ def __init__(self):
6058
def clf_response(self):
6159
return self.clfResponse
6260

63-
def parse(self,line):
64-
logging.debug(line)
65-
parseok = False
66-
# find command and call the needed nfcWrapper method
67-
if command_is(line, "ping"):
68-
self.pong()
69-
parseok = True
70-
if command_is(line, "connect"):
71-
detectedTag = self.connect()
72-
debug_nfc_data("Connectedtag", detectedTag)
73-
parseok = True
74-
if command_is(line, "mute"):
75-
detectedTag = self.mute()
76-
parseok = True
77-
if command_is(line, "disconnect"):
78-
self.disconnect()
79-
parseok = True
80-
return parseok
81-
82-
"""return the detected tag, else timeout after interval"""
83-
def sense(self, target_options = ("106A","106B","212F")):
84-
logging.info(logprefixnfc + "detecting tags with options " + target_options)
85-
# todo filter using the target_options
86-
targets = self.clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F'))
87-
self.clfResponse = targets
88-
return targets
89-
9061
def connect(self, target_options = ("106A","106B","212F")):
91-
# todo: decide on tag types to allow/filter
62+
# note: only supporting type4
9263
after5s = lambda: time.time() - started > 5
9364
started = time.time()
9465
tag = self.clf.connect( rdwr={'on-connect': lambda tag: False},
9566
llcp={}, terminate = after5s)
9667
self.clfResponse = tag
9768
if tag: # None if timeout expires
98-
logging.info(logprefixnfc + str(tag))
69+
logging.info("NFCReader: connected " + str(tag))
9970
return tag
10071

10172
def mute(self):
10273
"""turn off the reader radio"""
10374
if self.clf.device:
104-
logging.info(logprefixnfc + "radio mute" + self.clf.device.product_name)
75+
logging.info("NFCReader: radio mute" + self.clf.device.product_name)
10576
self.clf.device.mute()
10677

10778
def disconnect(self):
108-
logging.info(logprefixnfc + "close frontend.")
79+
logging.info("NFCReader: close frontend.")
10980
self.clf.close()
11081

11182
"""
@@ -126,9 +97,5 @@ def __getattr__(self, name):
12697

12798
__nfc_wrapper = None
12899

129-
# plumbing, calls a static instance for the reader object.
130-
def parse(self, line):
131-
return self.nfc.parse(line)
132-
133100
def clf_response(self):
134101
return self.nfc.clf_response()

TEST_APPS/testcases/nfc/test_nfc.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def __init__(self, **kwargs):
5656
Bench.__init__(self, **testcase_args)
5757

5858
def setup(self):
59-
try:
59+
#try:
6060
self.clf = ContactlessCommandRunner()
61-
self.clf.parse("mute")
62-
except:
63-
raise asserts.TestStepFail("Could not find NFC reader")
61+
self.clf.nfc.mute()
62+
#except:
63+
# raise asserts.TestStepFail("Could not find NFC reader")
6464

6565
def teardown(self):
6666
self.logger.info("Test teardown: Reboot target...")
@@ -83,7 +83,7 @@ def test_nfce2e_target_found(self):
8383
if not eeprom:
8484
self.nfc_command("dev1", "start")
8585

86-
self.clf.parse("connect")
86+
self.clf.nfc.connect()
8787
tag = self.clf.clf_response()
8888
asserts.assertNotNone(tag, "Could not connect to any tag")
8989

@@ -103,7 +103,7 @@ def test_nfce2e_type4_found(self):
103103
if not eeprom:
104104
self.nfc_command("dev1", "start")
105105

106-
self.clf.parse("connect")
106+
self.clf.nfc.connect()
107107
tag = self.clf.clf_response()
108108
asserts.assertNotNone(tag, "Could not connect to any tag")
109109

@@ -129,7 +129,7 @@ def test_nfce2e_smartposter(self):
129129
# write poster tag to target
130130
self.command("dev1", "setsmartposter %s" % expectedURI)
131131

132-
self.clf.parse("connect")
132+
self.clf.nfc.connect()
133133
tag = self.clf.clf_response()
134134
asserts.assertNotNone(tag, "Could not connect to any tag")
135135
asserts.assertEqual(1, len(tag.ndef.records), "expected number NDEF records")
@@ -156,21 +156,21 @@ def test_nfce2e_reprogrammed(self):
156156

157157
# program a poster tag to target
158158
print("Write Smartposter MESSAGE wirelessly")
159-
self.clf.parse("connect")
159+
self.clf.nfc.connect()
160160
tag = self.clf.clf_response()
161161
asserts.assertNotNone(tag, "Could not connect to any tag")
162162
smartposter = nfc_messages.make_smartposter(expectedURI, ["en-US:Other search engines exist"])
163163
nfc_messages.program_remote_tag(smartposter, tag)
164164
self.logger.info("Remote programmed %d bytes Smartposter" % len(str(smartposter)))
165165

166166
print("Write back Smartposter MESSAGE wirelessly")
167-
self.clf.parse("connect")
167+
self.clf.nfc.connect()
168168
tag = self.clf.clf_response()
169169
asserts.assertNotNone(tag, "Could not re-connect to any tag")
170170

171171
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "SmartposterRecord", "expected SmartposterRecord")
172172
asserts.assertEqual(expectedURI, tag.ndef.records[0].uri_records[0].uri, "expected exact URI")
173-
self.clf.parse("mute") # disable radio, to allow a local session
173+
self.clf.nfc.mute() # disable radio, to allow a local session
174174

175175
# verify in target
176176
response = self.nfc_command("dev1", "readmessage")
@@ -208,7 +208,7 @@ def test_nfce2e_read_stress(self):
208208
# write a large message to the tag via API, then read it wirelessly
209209
print("Write/set tag MESSAGE (%d) bytes" % textLength)
210210
self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep))
211-
self.clf.parse("connect")
211+
self.clf.nfc.connect()
212212
tag = self.clf.clf_response()
213213
asserts.assertNotNone(tag, "Could not connect to any tag")
214214

@@ -249,18 +249,18 @@ def test_nfce2e_reprogrammed_stress(self):
249249

250250
# program a large tag to target remotely
251251
print("Write tag MESSAGE wirelessly (%d) bytes" % len(str(message)))
252-
self.clf.parse("connect")
252+
self.clf.nfc.connect()
253253
tag = self.clf.clf_response()
254254
asserts.assertNotNone(tag, "Could not connect to any tag")
255255
nfc_messages.program_remote_tag(message, tag)
256256
self.logger.info("%d bytes chunk of data written to tag remotely" % len(str(message)))
257257

258258
# read device locally
259259
print("Read back tag MESSAGE wirelessly")
260-
self.clf.parse("connect")
260+
self.clf.nfc.connect()
261261
tag = self.clf.clf_response()
262262
asserts.assertNotNone(tag, "Could not re-connect to any tag")
263-
self.clf.parse("mute") # disable the reader radio, to allow local access
263+
self.clf.nfc.mute() # disable the reader radio, to allow local access
264264

265265
# verify in target
266266
response = self.nfc_command("dev1", "readmessage")
@@ -285,26 +285,26 @@ def test_nfce2e_discovery_loop(self):
285285
# Automatic resume after disconnect can be turned off by using command "start man" , the default is "start auto" .
286286

287287
if not eeprom:
288-
self.clf.parse("connect")
288+
self.clf.nfc.connect()
289289
tag = self.clf.clf_response()
290290
asserts.assertNone(tag, "post-init: Tag discovery loop should be stopped!")
291291
self.nfc_command("dev1", "stop")
292292
time.sleep(1)
293293

294-
self.clf.parse("connect")
294+
self.clf.nfc.connect()
295295
tag = self.clf.clf_response()
296296
asserts.assertNone(tag, "post-stop: Tag discovery loop should be stopped!")
297297
self.nfc_command("dev1", "start")
298298
time.sleep(1)
299299

300-
self.clf.parse("connect")
300+
self.clf.nfc.connect()
301301
tag = self.clf.clf_response()
302302
asserts.assertNotNone(tag, "Could not connect to any tag")
303303

304-
self.clf.parse("mute")
304+
self.clf.nfc.mute()
305305
self.nfc_command("dev1", "stop")
306306
time.sleep(10)
307-
self.clf.parse("connect")
307+
self.clf.nfc.connect()
308308
tag = self.clf.clf_response()
309309
# test blocked by issue raised IOTPAN313 NFC Controller discovery can stop but cannot restart - PN512
310310
asserts.assertNone(tag, "post-restart: Tag discovery loop should be stopped!")

0 commit comments

Comments
 (0)