mirror of https://github.com/ARMmbed/mbed-os.git
python removed extra plumbing
parent
d285b5f23e
commit
c509af32ce
|
@ -67,7 +67,7 @@ void wrap_printf(const char *f, va_list a)
|
|||
|
||||
|
||||
/** Disables VT100 etc. for easy manual UI interaction */
|
||||
int seteasy(int argc, char *argv[])
|
||||
int set_easy_printer(int argc, char *argv[])
|
||||
{
|
||||
const char msg[][20] =
|
||||
{ "echo off", "set --retcode true", "set --vt100 off" };
|
||||
|
@ -77,6 +77,7 @@ int seteasy(int argc, char *argv[])
|
|||
return (CMDLINE_RETCODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This test app can be used standalone interactively with at 115200 baud terminal. It is designed to work with the
|
||||
* 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[])
|
|||
int main()
|
||||
{
|
||||
cmd_init(&wrap_printf);
|
||||
HandleTestCommand handleCommands; // For handling test commands and set nfc message queue
|
||||
|
||||
cmd_add("getlastnfcerror", HandleTestCommand::cmd_get_last_nfc_error,
|
||||
"last NFC error code", errorcodes);
|
||||
cmd_add("setlastnfcerror", HandleTestCommand::cmd_set_last_nfc_error,
|
||||
|
@ -127,7 +130,7 @@ int main()
|
|||
"get supported protocols", "returns CSV list, see setprotocols");
|
||||
cmd_add("setprotocols", HandleTestCommand::cmd_configure_rf_protocols,
|
||||
"set rf protocols", "-p [t1t]/[t2t]/[t3t]/[isodep]/[nfcdep]/[t5t]");
|
||||
cmd_add("easy", seteasy, "Use human readable terminal output",
|
||||
cmd_add("easy", set_easy_printer, "Use human readable terminal output",
|
||||
"echo off,vt100 off,return-codes visible");
|
||||
cmd_add("trace", HandleTestCommand::cmd_set_trace, "detailed tracing on/off, ",
|
||||
"Defaults to enabled; values like 'on','true','1' all turn it on, anything else turns off detailed tracing.");
|
||||
|
@ -146,7 +149,6 @@ int main()
|
|||
#endif
|
||||
{
|
||||
int c;
|
||||
HandleTestCommand handleCommands; // For handling test commands and set nfc message queue
|
||||
while ((c = getc(stdin)) != EOF) {
|
||||
cmd_char_input(c);
|
||||
}
|
||||
|
|
|
@ -20,15 +20,13 @@ import nfc
|
|||
from nfc.clf import RemoteTarget
|
||||
import logging
|
||||
|
||||
logprefixnfc = "NFCPY: "
|
||||
|
||||
"""
|
||||
Wrap calls to nfcpi testing module, handle loading the driver
|
||||
"""
|
||||
|
||||
|
||||
def command_is(string, command):
|
||||
return string.split(' ')[0] == command
|
||||
# def command_is(string, command):
|
||||
# return string.split(' ')[0] == command
|
||||
|
||||
|
||||
def debug_nfc_data(key, value):
|
||||
|
@ -60,52 +58,25 @@ class NfcWrapper:
|
|||
def clf_response(self):
|
||||
return self.clfResponse
|
||||
|
||||
def parse(self,line):
|
||||
logging.debug(line)
|
||||
parseok = False
|
||||
# find command and call the needed nfcWrapper method
|
||||
if command_is(line, "ping"):
|
||||
self.pong()
|
||||
parseok = True
|
||||
if command_is(line, "connect"):
|
||||
detectedTag = self.connect()
|
||||
debug_nfc_data("Connectedtag", detectedTag)
|
||||
parseok = True
|
||||
if command_is(line, "mute"):
|
||||
detectedTag = self.mute()
|
||||
parseok = True
|
||||
if command_is(line, "disconnect"):
|
||||
self.disconnect()
|
||||
parseok = True
|
||||
return parseok
|
||||
|
||||
"""return the detected tag, else timeout after interval"""
|
||||
def sense(self, target_options = ("106A","106B","212F")):
|
||||
logging.info(logprefixnfc + "detecting tags with options " + target_options)
|
||||
# todo filter using the target_options
|
||||
targets = self.clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F'))
|
||||
self.clfResponse = targets
|
||||
return targets
|
||||
|
||||
def connect(self, target_options = ("106A","106B","212F")):
|
||||
# todo: decide on tag types to allow/filter
|
||||
# note: only supporting type4
|
||||
after5s = lambda: time.time() - started > 5
|
||||
started = time.time()
|
||||
tag = self.clf.connect( rdwr={'on-connect': lambda tag: False},
|
||||
llcp={}, terminate = after5s)
|
||||
self.clfResponse = tag
|
||||
if tag: # None if timeout expires
|
||||
logging.info(logprefixnfc + str(tag))
|
||||
logging.info("NFCReader: connected " + str(tag))
|
||||
return tag
|
||||
|
||||
def mute(self):
|
||||
"""turn off the reader radio"""
|
||||
if self.clf.device:
|
||||
logging.info(logprefixnfc + "radio mute" + self.clf.device.product_name)
|
||||
logging.info("NFCReader: radio mute" + self.clf.device.product_name)
|
||||
self.clf.device.mute()
|
||||
|
||||
def disconnect(self):
|
||||
logging.info(logprefixnfc + "close frontend.")
|
||||
logging.info("NFCReader: close frontend.")
|
||||
self.clf.close()
|
||||
|
||||
"""
|
||||
|
@ -126,9 +97,5 @@ class ContactlessCommandRunner():
|
|||
|
||||
__nfc_wrapper = None
|
||||
|
||||
# plumbing, calls a static instance for the reader object.
|
||||
def parse(self, line):
|
||||
return self.nfc.parse(line)
|
||||
|
||||
def clf_response(self):
|
||||
return self.nfc.clf_response()
|
||||
|
|
|
@ -56,11 +56,11 @@ class CreamSconeTests(Bench, CliHelper):
|
|||
Bench.__init__(self, **testcase_args)
|
||||
|
||||
def setup(self):
|
||||
try:
|
||||
#try:
|
||||
self.clf = ContactlessCommandRunner()
|
||||
self.clf.parse("mute")
|
||||
except:
|
||||
raise asserts.TestStepFail("Could not find NFC reader")
|
||||
self.clf.nfc.mute()
|
||||
#except:
|
||||
# raise asserts.TestStepFail("Could not find NFC reader")
|
||||
|
||||
def teardown(self):
|
||||
self.logger.info("Test teardown: Reboot target...")
|
||||
|
@ -83,7 +83,7 @@ def test_nfce2e_target_found(self):
|
|||
if not eeprom:
|
||||
self.nfc_command("dev1", "start")
|
||||
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
|
||||
|
@ -103,7 +103,7 @@ def test_nfce2e_type4_found(self):
|
|||
if not eeprom:
|
||||
self.nfc_command("dev1", "start")
|
||||
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
|
||||
|
@ -129,7 +129,7 @@ def test_nfce2e_smartposter(self):
|
|||
# write poster tag to target
|
||||
self.command("dev1", "setsmartposter %s" % expectedURI)
|
||||
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
asserts.assertEqual(1, len(tag.ndef.records), "expected number NDEF records")
|
||||
|
@ -156,7 +156,7 @@ def test_nfce2e_reprogrammed(self):
|
|||
|
||||
# program a poster tag to target
|
||||
print("Write Smartposter MESSAGE wirelessly")
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
smartposter = nfc_messages.make_smartposter(expectedURI, ["en-US:Other search engines exist"])
|
||||
|
@ -164,13 +164,13 @@ def test_nfce2e_reprogrammed(self):
|
|||
self.logger.info("Remote programmed %d bytes Smartposter" % len(str(smartposter)))
|
||||
|
||||
print("Write back Smartposter MESSAGE wirelessly")
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not re-connect to any tag")
|
||||
|
||||
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "SmartposterRecord", "expected SmartposterRecord")
|
||||
asserts.assertEqual(expectedURI, tag.ndef.records[0].uri_records[0].uri, "expected exact URI")
|
||||
self.clf.parse("mute") # disable radio, to allow a local session
|
||||
self.clf.nfc.mute() # disable radio, to allow a local session
|
||||
|
||||
# verify in target
|
||||
response = self.nfc_command("dev1", "readmessage")
|
||||
|
@ -208,7 +208,7 @@ def test_nfce2e_read_stress(self):
|
|||
# write a large message to the tag via API, then read it wirelessly
|
||||
print("Write/set tag MESSAGE (%d) bytes" % textLength)
|
||||
self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep))
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
|
||||
|
@ -249,7 +249,7 @@ def test_nfce2e_reprogrammed_stress(self):
|
|||
|
||||
# program a large tag to target remotely
|
||||
print("Write tag MESSAGE wirelessly (%d) bytes" % len(str(message)))
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
nfc_messages.program_remote_tag(message, tag)
|
||||
|
@ -257,10 +257,10 @@ def test_nfce2e_reprogrammed_stress(self):
|
|||
|
||||
# read device locally
|
||||
print("Read back tag MESSAGE wirelessly")
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not re-connect to any tag")
|
||||
self.clf.parse("mute") # disable the reader radio, to allow local access
|
||||
self.clf.nfc.mute() # disable the reader radio, to allow local access
|
||||
|
||||
# verify in target
|
||||
response = self.nfc_command("dev1", "readmessage")
|
||||
|
@ -285,26 +285,26 @@ def test_nfce2e_discovery_loop(self):
|
|||
# Automatic resume after disconnect can be turned off by using command "start man" , the default is "start auto" .
|
||||
|
||||
if not eeprom:
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNone(tag, "post-init: Tag discovery loop should be stopped!")
|
||||
self.nfc_command("dev1", "stop")
|
||||
time.sleep(1)
|
||||
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNone(tag, "post-stop: Tag discovery loop should be stopped!")
|
||||
self.nfc_command("dev1", "start")
|
||||
time.sleep(1)
|
||||
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
|
||||
self.clf.parse("mute")
|
||||
self.clf.nfc.mute()
|
||||
self.nfc_command("dev1", "stop")
|
||||
time.sleep(10)
|
||||
self.clf.parse("connect")
|
||||
self.clf.nfc.connect()
|
||||
tag = self.clf.clf_response()
|
||||
# test blocked by issue raised IOTPAN313 NFC Controller discovery can stop but cannot restart - PN512
|
||||
asserts.assertNone(tag, "post-restart: Tag discovery loop should be stopped!")
|
||||
|
|
Loading…
Reference in New Issue