mirror of https://github.com/ARMmbed/mbed-os.git
cpp refactored, refactor the python next
parent
c36f5406ae
commit
d285b5f23e
|
@ -35,35 +35,36 @@ using mbed::nfc::NFCEEPROMDriver;
|
|||
|
||||
#endif // MBED_CONF_NFCEEPROM
|
||||
|
||||
const char *errorcodes = // descriptions from nfc/stack/nfc_errors.h
|
||||
" 0 NFC_OK\r\n"
|
||||
" 1 NFC_ERR_UNKNOWN\r\n"
|
||||
" 2 NFC_ERR_LENGTH\r\n"
|
||||
" 3 NFC_ERR_NOT_FOUND\r\n"
|
||||
" 4 NFC_ERR_UNSUPPORTED\r\n"
|
||||
" 5 NFC_ERR_PARAMS\r\n"
|
||||
" 6 NFC_ERR_BUFFER_TOO_SMALL\r\n"
|
||||
" 7 NFC_ERR_TIMEOUT\r\n"
|
||||
" 8 NFC_ERR_CRC\r\n"
|
||||
" 9 NFC_ERR_NOPEER\r\n"
|
||||
"10 NFC_ERR_PARITY\r\n"
|
||||
"11 NFC_ERR_FIELD\r\n"
|
||||
"12 NFC_ERR_COLLISION\r\n"
|
||||
"13 NFC_ERR_WRONG_COMM\r\n"
|
||||
"14 NFC_ERR_PROTOCOL\r\n"
|
||||
"15 NFC_ERR_BUSY\r\n"
|
||||
"16 NFC_ERR_CONTROLLER\r\n"
|
||||
"17 NFC_ERR_HALTED\r\n"
|
||||
"18 NFC_ERR_MAC\r\n"
|
||||
"19 NFC_ERR_UNDERFLOW\r\n"
|
||||
"20 NFC_ERR_DISCONNECTED\r\n"
|
||||
"21 NFC_ERR_ABORTED\r\n";
|
||||
|
||||
|
||||
void wrap_printf(const char *f, va_list a)
|
||||
{
|
||||
vprintf(f, a);
|
||||
}
|
||||
|
||||
const char *errorcodes = // descriptions from nfc/stack/nfc_errors.h
|
||||
" 0 NFC_OK \n"
|
||||
" 1 NFC_ERR_UNKNOWN\n"
|
||||
" 2 NFC_ERR_LENGTH \n"
|
||||
" 3 NFC_ERR_NOT_FOUND\n"
|
||||
" 4 NFC_ERR_UNSUPPORTED\n"
|
||||
" 5 NFC_ERR_PARAMS \n"
|
||||
" 6 NFC_ERR_BUFFER_TOO_SMALL\n"
|
||||
" 7 NFC_ERR_TIMEOUT\n"
|
||||
" 8 NFC_ERR_CRC\n"
|
||||
" 9 NFC_ERR_NOPEER \n"
|
||||
"10 NFC_ERR_PARITY \n"
|
||||
"11 NFC_ERR_FIELD\n"
|
||||
"12 NFC_ERR_COLLISION\n"
|
||||
"13 NFC_ERR_WRONG_COMM \n"
|
||||
"14 NFC_ERR_PROTOCOL \n"
|
||||
"15 NFC_ERR_BUSY \n"
|
||||
"16 NFC_ERR_CONTROLLER \n"
|
||||
"17 NFC_ERR_HALTED \n"
|
||||
"18 NFC_ERR_MAC\n"
|
||||
"19 NFC_ERR_UNDERFLOW\n"
|
||||
"20 NFC_ERR_DISCONNECTED \n"
|
||||
"21 NFC_ERR_ABORTED\n";
|
||||
|
||||
/** Disables VT100 etc. for easy manual UI interaction */
|
||||
int seteasy(int argc, char *argv[])
|
||||
|
@ -75,6 +76,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
|
||||
|
@ -88,7 +90,7 @@ int seteasy(int argc, char *argv[])
|
|||
* If using an NFC EEPROM, an extra library is needed. Please see the documentation in the README.MD for instructions
|
||||
* on how to modify this test for new drivers/targets, and the steps to run this test suite.
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
int main()
|
||||
{
|
||||
cmd_init(&wrap_printf);
|
||||
cmd_add("getlastnfcerror", HandleTestCommand::cmd_get_last_nfc_error,
|
||||
|
@ -127,6 +129,8 @@ int main(int argc, char *argv[])
|
|||
"set rf protocols", "-p [t1t]/[t2t]/[t3t]/[isodep]/[nfcdep]/[t5t]");
|
||||
cmd_add("easy", seteasy, "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.");
|
||||
|
||||
#if MBED_CONF_NFCEEPROM
|
||||
cmd_printf("MBED NFC EEPROM defined\r\n");
|
||||
|
@ -135,16 +139,17 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
|
||||
#ifdef TARGET_M24SR
|
||||
cmd_printf("Using driver:M24SR\r\n");
|
||||
cmd_printf("Using driver: M24SR\r\n");
|
||||
#endif
|
||||
#ifdef TARGET_PN512
|
||||
cmd_printf("Using driver:PN512\r\n");
|
||||
cmd_printf("Using driver: PN512\r\n");
|
||||
#endif
|
||||
|
||||
int c;
|
||||
HandleTestCommand handleCommands; // starts handling nfc messages
|
||||
while ((c = getc(stdin)) != EOF) {
|
||||
cmd_char_input(c);
|
||||
{
|
||||
int c;
|
||||
HandleTestCommand handleCommands; // For handling test commands and set nfc message queue
|
||||
while ((c = getc(stdin)) != EOF) {
|
||||
cmd_char_input(c);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include "mbed_events.h"
|
||||
#include "mbed-client-cli/ns_cmdline.h"
|
||||
|
@ -29,33 +30,81 @@
|
|||
|
||||
using mbed::nfc::nfc_rf_protocols_bitmask_t;
|
||||
|
||||
events::EventQueue nfcQueue;
|
||||
rtos::Thread nfcThread;
|
||||
NFCTestShim *pNFC_Test_Shim = NULL;
|
||||
events::EventQueue HandleTestCommand::_nfcQueue;
|
||||
|
||||
NFCTestShim *new_testshim()
|
||||
rtos::Thread nfcThread;
|
||||
bool human_trace_enabled = true;
|
||||
|
||||
NFCTestShim *HandleTestCommand::new_testshim()
|
||||
{
|
||||
#if MBED_CONF_NFCEEPROM
|
||||
mbed::nfc::NFCEEPROMDriver &eeprom_driver = get_eeprom_driver(nfcQueue);
|
||||
mbed::nfc::NFCEEPROMDriver &eeprom_driver = get_eeprom_driver(_nfcQueue);
|
||||
|
||||
return ((NFCTestShim *)(new NFCProcessEEPROM(nfcQueue, eeprom_driver)));
|
||||
return ((NFCTestShim *)(new NFCProcessEEPROM(_nfcQueue, eeprom_driver)));
|
||||
#else
|
||||
return ((NFCTestShim *)(new NFCProcessController(nfcQueue)));
|
||||
return ((NFCTestShim *)(new NFCProcessController(_nfcQueue)));
|
||||
#endif // EEPROM
|
||||
|
||||
}
|
||||
|
||||
void nfcRoutine()
|
||||
void HandleTestCommand::nfc_routine()
|
||||
{
|
||||
nfcQueue.dispatch_forever();
|
||||
_nfcQueue.dispatch_forever();
|
||||
}
|
||||
|
||||
void trace_printf(const char *fmt, ...)
|
||||
{
|
||||
if (human_trace_enabled) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
cmd_vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
HandleTestCommand::HandleTestCommand()
|
||||
{
|
||||
osStatus status = nfcThread.start(mbed::callback(&nfcRoutine));
|
||||
osStatus status = nfcThread.start(mbed::callback(&HandleTestCommand::nfc_routine));
|
||||
MBED_ASSERT(status == osOK);
|
||||
}
|
||||
|
||||
int HandleTestCommand::cmd_get_last_nfc_error(int argc, char *argv[])
|
||||
{
|
||||
_nfcQueue.call(NFCTestShim::cmd_get_last_nfc_error);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
/** returns compile time flag if NFC EEPROM was compiled */
|
||||
int HandleTestCommand::cmd_get_conf_nfceeprom(int argc, char *argv[])
|
||||
{
|
||||
_nfcQueue.call(NFCTestShim::cmd_get_conf_nfceeprom);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int HandleTestCommand::cmd_set_trace(int argc, char *argv[])
|
||||
{
|
||||
human_trace_enabled = false;
|
||||
if (argc > 1) {
|
||||
static char buffer[7];
|
||||
char *p_buffer = buffer;
|
||||
strncpy(buffer, argv[1], sizeof(buffer) - 1);
|
||||
buffer[sizeof(buffer) - 1] = 0;
|
||||
while (*p_buffer) {
|
||||
*p_buffer = toupper(*p_buffer);
|
||||
p_buffer++;
|
||||
}
|
||||
cmd_printf(buffer);
|
||||
human_trace_enabled = (0 == strcmp(buffer, "TRUE")) || (0 == strcmp(buffer, "1")) || (0 == strcmp(buffer, "ON"));
|
||||
}
|
||||
cmd_printf("set trace '%s'", (human_trace_enabled ? "true" : "false"));
|
||||
return (CMDLINE_RETCODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int HandleTestCommand::cmd_set_last_nfc_error(int argc, char *argv[])
|
||||
{
|
||||
if (argc <= 1) {
|
||||
|
@ -63,7 +112,7 @@ int HandleTestCommand::cmd_set_last_nfc_error(int argc, char *argv[])
|
|||
return (CMDLINE_RETCODE_INVALID_PARAMETERS);
|
||||
} else {
|
||||
int value = strtol(argv[1], NULL, 10);
|
||||
nfcQueue.call(NFCTestShim::cmd_set_last_nfc_error, value);
|
||||
_nfcQueue.call(NFCTestShim::cmd_set_last_nfc_error, value);
|
||||
}
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
@ -72,7 +121,7 @@ int HandleTestCommand::cmd_set_last_nfc_error(int argc, char *argv[])
|
|||
int HandleTestCommand::cmd_get_max_ndef(int argc, char *argv[])
|
||||
{
|
||||
if (pNFC_Test_Shim) {
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_get_max_ndef);
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_get_max_ndef);
|
||||
return CMDLINE_RETCODE_EXCUTING_CONTINUE;
|
||||
}
|
||||
return CMDLINE_RETCODE_FAIL;
|
||||
|
@ -81,19 +130,18 @@ int HandleTestCommand::cmd_get_max_ndef(int argc, char *argv[])
|
|||
|
||||
int HandleTestCommand::cmd_init_nfc(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if (pNFC_Test_Shim) {
|
||||
cmd_printf("WARN init called again!\r\n"); // only legal here, if eeprom driver stops talking
|
||||
} else {
|
||||
pNFC_Test_Shim = new_testshim();
|
||||
}
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_init);
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_init);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
int HandleTestCommand::cmd_read_message(int argc, char *argv[])
|
||||
{
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_read_nfc_contents);
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_read_nfc_contents);
|
||||
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
@ -109,8 +157,8 @@ int HandleTestCommand::cmd_set_smartposter(int argc, char *argv[])
|
|||
char *uri = (char *) malloc(strlen(argv[1]) + 1);
|
||||
if (uri) {
|
||||
strcpy(uri, argv[1]);
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_set_smartposter,
|
||||
uri); // called thread must free
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_set_smartposter,
|
||||
uri); // called thread must free
|
||||
} else {
|
||||
cmd_printf("WARN out of memory!\r\n");
|
||||
return (CMDLINE_RETCODE_FAIL);
|
||||
|
@ -119,10 +167,9 @@ int HandleTestCommand::cmd_set_smartposter(int argc, char *argv[])
|
|||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
// todo: jira IOTPAN-295
|
||||
int HandleTestCommand::cmd_erase(int argc, char *argv[])
|
||||
{
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_erase);
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_erase);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
|
@ -169,31 +216,31 @@ int HandleTestCommand::cmd_write_long_ndef_message(int argc, char *argv[])
|
|||
data[length] = '\0';
|
||||
|
||||
// method must release buffer
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_write_long, data);
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_write_long, data);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
int HandleTestCommand::cmd_start_discovery(int argc, char *argv[])
|
||||
{
|
||||
if ((argc > 1) && (0 == strcmp(argv[1], "man"))) {
|
||||
cmd_printf("User must restart discovery manually()\r\n");
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_start_discovery, false);
|
||||
trace_printf("User must restart discovery manually()\r\n");
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_start_discovery, false);
|
||||
} else {
|
||||
cmd_printf("App will restart discovery loop on auto()\r\n");
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_start_discovery, true);
|
||||
trace_printf("App will restart discovery loop on auto()\r\n");
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_start_discovery, true);
|
||||
}
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
int HandleTestCommand::cmd_stop_discovery(int argc, char *argv[])
|
||||
{
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_stop_discovery);
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_stop_discovery);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
int HandleTestCommand::cmd_get_supported_rf_protocols(int argc, char *argv[])
|
||||
{
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_get_rf_protocols);
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_get_rf_protocols);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
|
@ -234,38 +281,8 @@ int HandleTestCommand::cmd_configure_rf_protocols(int argc, char *argv[])
|
|||
}
|
||||
argindex--;
|
||||
}
|
||||
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_configure_rf_protocols,
|
||||
protocols);
|
||||
_nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_configure_rf_protocols,
|
||||
protocols);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
|
||||
// todo: implement
|
||||
int cmd_start_stop_discovery_wait_tag(int argc, char *argv[])
|
||||
{
|
||||
|
||||
return (CMDLINE_RETCODE_COMMAND_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// boilerplate only
|
||||
|
||||
int cmd_is_iso7816_supported(int argc, char *argv[])
|
||||
{
|
||||
return (CMDLINE_RETCODE_COMMAND_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
int cmd_add_iso7816_application(int argc, char *argv[])
|
||||
{
|
||||
return (CMDLINE_RETCODE_COMMAND_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
int cmd_set_tagtype(int argc, char *argv[])
|
||||
{
|
||||
return (CMDLINE_RETCODE_COMMAND_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
int cmd_get_tagtype(int argc, char *argv[])
|
||||
{
|
||||
return (CMDLINE_RETCODE_COMMAND_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,41 +23,51 @@
|
|||
#include "nfcProcessCtrl.h"
|
||||
#endif
|
||||
|
||||
extern events::EventQueue nfcQueue;
|
||||
|
||||
// see https://support.microsoft.com/en-my/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer
|
||||
#define MAX_URL_LENGTH 2000
|
||||
|
||||
#ifndef MBED_CONF_NFCEEPROM
|
||||
#define MBED_CONF_NFCEEPROM false
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* \brief adds human-readable traces not needed by the framework, filter is via a switch set_trace_enable()
|
||||
* \param fmt standard printf formatter
|
||||
* \param varargs
|
||||
*/
|
||||
void trace_printf(const char *fmt, ...);
|
||||
|
||||
/**
|
||||
* \brief turns on human readable traces
|
||||
* \param enabled : set to false to disable the extra traces
|
||||
*/
|
||||
void set_trace_enable(bool enabled = true);
|
||||
|
||||
/**
|
||||
* HandleTestCommand turns all the typed-in/serial commands into function calls sent via a eventqueue to the driver
|
||||
* shim/wrapper class. Most application level code that is agnostic of EEPROM/controller drivers lives in this class.
|
||||
* shim/wrapper class.
|
||||
* Methods with cmd_ prefix map to the serial commands, and are building blocks for test cases and scenarios. The
|
||||
* first function a test must call is typically the initnfc command. Commands report back a test verdict, and a
|
||||
* NFC status code. The test verdict is always success unless the command is not allowed. Tests much check the
|
||||
* NFC error code for NFC_OK or zero; this pattern allows us to write negative tests which expect a specific NFC error.
|
||||
*
|
||||
* Handlers are statics because the test framework is not supporting C++
|
||||
*/
|
||||
class HandleTestCommand {
|
||||
public:
|
||||
HandleTestCommand();
|
||||
/** set corresponding mask bit on in referenced structure, return false if the supplied string cannot parse */
|
||||
static bool set_protocol_target(mbed::nfc::nfc_rf_protocols_bitmask_t &bitmask, const char *protocolName);
|
||||
|
||||
/** return and clear the last result code. Type "help getlastnfcerror" for a list of error codes */
|
||||
static int cmd_get_last_nfc_error(int argc, char *argv[])
|
||||
{
|
||||
nfcQueue.call(NFCTestShim::cmd_get_last_nfc_error);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
static int cmd_get_last_nfc_error(int argc, char *argv[]);
|
||||
|
||||
/** internal function to test getlastnfcerror */
|
||||
static int cmd_set_last_nfc_error(int argc, char *argv[]);
|
||||
|
||||
/** returns compile time flag if NFC EEPROM was compiled */
|
||||
static int cmd_get_conf_nfceeprom(int argc, char *argv[])
|
||||
{
|
||||
nfcQueue.call(NFCTestShim::cmd_get_conf_nfceeprom);
|
||||
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
|
||||
}
|
||||
static int cmd_get_conf_nfceeprom(int argc, char *argv[]);
|
||||
|
||||
static int cmd_set_trace(int argc, char *argv[]);
|
||||
|
||||
/** For EEPROM, returns the driver max_ndef value, else returns the app config MBED_CONF_APP_TEST_NDEF_MSG_MAX */
|
||||
static int cmd_get_max_ndef(int argc, char *argv[]);
|
||||
|
@ -83,6 +93,13 @@ public:
|
|||
/** write a text 'T' NDEF message to the target */
|
||||
static int cmd_write_long_ndef_message(int argc, char *argv[]);
|
||||
|
||||
private:
|
||||
/** set corresponding mask bit on in referenced structure, return false if the supplied string cannot parse */
|
||||
static bool set_protocol_target(mbed::nfc::nfc_rf_protocols_bitmask_t &bitmask, const char *protocolName);
|
||||
static NFCTestShim *new_testshim();
|
||||
static void nfc_routine();
|
||||
|
||||
static events::EventQueue _nfcQueue;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "nfc/ndef/common/util.h"
|
||||
|
||||
|
||||
#include "nfcCommands.h"
|
||||
#include "nfcProcessCtrl.h"
|
||||
#include "SmartPoster.h"
|
||||
|
||||
|
@ -65,13 +66,20 @@ NFCProcessController::NFCProcessController(events::EventQueue &queue) :
|
|||
*/
|
||||
nfc_err_t NFCProcessController::init()
|
||||
{
|
||||
cmd_printf("init()\r\n");
|
||||
trace_printf("init()\r\n");
|
||||
|
||||
// register callbacks
|
||||
_nfc_controller.set_delegate(this);
|
||||
return _nfc_controller.initialize();
|
||||
}
|
||||
|
||||
|
||||
void NFCProcessController::cmd_get_max_ndef()
|
||||
{
|
||||
cmd_printf("{{maxndef=%d}}\r\n", (int)MBED_CONF_APP_TEST_NDEF_MSG_MAX);
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the discovery of peers.
|
||||
*
|
||||
|
@ -80,7 +88,7 @@ nfc_err_t NFCProcessController::init()
|
|||
*/
|
||||
nfc_err_t NFCProcessController::start_discovery()
|
||||
{
|
||||
cmd_printf("start_discovery()\r\n");
|
||||
trace_printf("start_discovery()\r\n");
|
||||
|
||||
return _nfc_controller.start_discovery();
|
||||
}
|
||||
|
@ -93,20 +101,20 @@ nfc_err_t NFCProcessController::start_discovery()
|
|||
*/
|
||||
nfc_err_t NFCProcessController::stop_discovery()
|
||||
{
|
||||
cmd_printf("stop_discovery()\r\n");
|
||||
trace_printf("stop_discovery()\r\n");
|
||||
return _nfc_controller.cancel_discovery();
|
||||
}
|
||||
|
||||
nfc_rf_protocols_bitmask_t NFCProcessController::get_rf_protocols()
|
||||
{
|
||||
cmd_printf("get_supported_rf_protocols()\r\n");
|
||||
trace_printf("get_supported_rf_protocols()\r\n");
|
||||
return _nfc_controller.get_supported_rf_protocols();
|
||||
}
|
||||
|
||||
nfc_err_t NFCProcessController::set_rf_protocols(
|
||||
nfc_rf_protocols_bitmask_t protocols)
|
||||
{
|
||||
cmd_printf("configure_rf_protocols()\r\n");
|
||||
trace_printf("configure_rf_protocols()\r\n");
|
||||
|
||||
return _nfc_controller.configure_rf_protocols(protocols);
|
||||
}
|
||||
|
@ -138,18 +146,18 @@ void NFCProcessController::parse_ndef_message(
|
|||
size_t len = buffer.size();
|
||||
// copy remotely written message into our dummy buffer
|
||||
if (len <= sizeof(_ndef_write_buffer)) {
|
||||
cmd_printf("Store remote ndef message of size %d\r\n", len);
|
||||
trace_printf("Store remote ndef message of size %d\r\n", len);
|
||||
memcpy(_ndef_write_buffer, buffer.data(), len);
|
||||
_ndef_write_buffer_used = len;
|
||||
} else {
|
||||
cmd_printf("Remote ndef message of size %d too large!\r\n", len);
|
||||
trace_printf("Remote ndef message of size %d too large!\r\n", len);
|
||||
}
|
||||
}
|
||||
|
||||
size_t NFCProcessController::build_ndef_message(const Span<uint8_t> &buffer)
|
||||
{
|
||||
cmd_printf("Copying message %d bytes to query buffer\r\n",
|
||||
_ndef_write_buffer_used);
|
||||
trace_printf("Copying message %d bytes to query buffer\r\n",
|
||||
_ndef_write_buffer_used);
|
||||
memcpy(buffer.data(), _ndef_write_buffer, _ndef_write_buffer_used);
|
||||
for (size_t k = 0; k < _ndef_write_buffer_used; k++) {
|
||||
cmd_printf("%02x ", buffer[k]);
|
||||
|
@ -174,8 +182,8 @@ const char *NFCProcessController::str_discovery_terminated_reason(
|
|||
void NFCProcessController::on_discovery_terminated(
|
||||
nfc_discovery_terminated_reason_t reason)
|
||||
{
|
||||
cmd_printf("on_discovery_terminated(%s)\r\n",
|
||||
str_discovery_terminated_reason(reason));
|
||||
trace_printf("on_discovery_terminated(%s)\r\n",
|
||||
str_discovery_terminated_reason(reason));
|
||||
if (reason != nfc_discovery_terminated_completed
|
||||
&& this->_discovery_restart) {
|
||||
start_discovery();
|
||||
|
@ -185,7 +193,7 @@ void NFCProcessController::on_discovery_terminated(
|
|||
void NFCProcessController::on_nfc_initiator_discovered(
|
||||
const SharedPtr<mbed::nfc::NFCRemoteInitiator> &nfc_initiator)
|
||||
{
|
||||
cmd_printf("on_nfc_initiator_discovered()\r\n");
|
||||
trace_printf("on_nfc_initiator_discovered()\r\n");
|
||||
|
||||
// setup the local remote initiator
|
||||
_nfc_remote_initiator = nfc_initiator;
|
||||
|
|
|
@ -48,11 +48,7 @@ class NFCProcessController: NFCTestShim,
|
|||
public:
|
||||
NFCProcessController(events::EventQueue &queue);
|
||||
|
||||
void cmd_get_max_ndef()
|
||||
{
|
||||
cmd_printf("{{maxndef=%d}}\r\n", (int)MBED_CONF_APP_TEST_NDEF_MSG_MAX);
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
}
|
||||
void cmd_get_max_ndef();
|
||||
nfc_err_t init();
|
||||
nfc_err_t start_discovery();
|
||||
nfc_err_t stop_discovery();
|
||||
|
|
|
@ -81,20 +81,33 @@ char const *uri_prefix_string[] = { "",
|
|||
};
|
||||
|
||||
int last_nfc_error = 0;
|
||||
#if MBED_CONF_NFCEEPROM
|
||||
int using_eeprom = true;
|
||||
#else
|
||||
int using_eeprom = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
NFCTestShim *pNFC_Test_Shim = NULL;
|
||||
|
||||
NFCTestShim::NFCTestShim(events::EventQueue &queue) :
|
||||
_ndef_write_buffer_used(0), ndef_poster_message(_ndef_write_buffer),
|
||||
_ndef_write_buffer_used(0), _ndef_poster_message(_ndef_write_buffer),
|
||||
_discovery_restart(true), // on disconnect, will restart discovery
|
||||
_queue(queue)
|
||||
{
|
||||
}
|
||||
|
||||
void NFCTestShim::cmd_get_last_nfc_error()
|
||||
{
|
||||
get_last_nfc_error();
|
||||
}
|
||||
|
||||
void NFCTestShim::cmd_set_last_nfc_error(int err)
|
||||
{
|
||||
set_last_nfc_error(err);
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
}
|
||||
|
||||
void NFCTestShim::cmd_get_conf_nfceeprom()
|
||||
{
|
||||
get_conf_nfceeprom();
|
||||
}
|
||||
|
||||
/** \brief The last failed NFC API call status, gets cleared upon reading it.
|
||||
* \return void The NFC error is set asyncronously by sending text back over serial
|
||||
*/
|
||||
|
@ -118,7 +131,7 @@ void NFCTestShim::get_conf_nfceeprom()
|
|||
{
|
||||
set_last_nfc_error(NFC_OK);
|
||||
// return data as text to the plugin framework
|
||||
cmd_printf("{{iseeprom=%s}}\r\n", (::using_eeprom ? "true" : "false"));
|
||||
cmd_printf("{{iseeprom=%s}}\r\n", (MBED_CONF_NFCEEPROM ? "true" : "false"));
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
@ -237,31 +250,28 @@ void NFCTestShim::cmd_read_nfc_contents()
|
|||
{
|
||||
#if MBED_CONF_NFCEEPROM
|
||||
((NFCProcessEEPROM *)this)->queue_read_call();
|
||||
cmd_printf("NFCTestShim::cmd_read_nfc_contents() exit\r\n");
|
||||
trace_printf("NFCTestShim::cmd_read_nfc_contents() exit\r\n");
|
||||
|
||||
#else
|
||||
// returns last message "written", since we cannot read
|
||||
print_ndef_message(_ndef_write_buffer, _ndef_write_buffer_used);
|
||||
cmd_printf("Controller buffer data size=%d\r\n", _ndef_write_buffer_used);
|
||||
trace_printf("Controller buffer data size=%d\r\n", _ndef_write_buffer_used);
|
||||
set_last_nfc_error(NFC_OK);
|
||||
|
||||
cmd_printf("NFCTestShim::cmd_read_nfc_contents()\r\n");
|
||||
trace_printf("NFCTestShim::cmd_read_nfc_contents() exit\r\n");
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
#endif
|
||||
}
|
||||
|
||||
void NFCTestShim::cmd_erase()
|
||||
{
|
||||
|
||||
#if MBED_CONF_NFCEEPROM
|
||||
((NFCProcessEEPROM *)this)->queue_erase_call();
|
||||
|
||||
#else
|
||||
cmd_printf("erase %d bytes, last msg\r\n",
|
||||
sizeof(_ndef_write_buffer));
|
||||
trace_printf("Erase (reset) controller msg buffer\r\n");
|
||||
_ndef_write_buffer_used = 0;
|
||||
memset(_ndef_write_buffer, 0, sizeof(_ndef_write_buffer));
|
||||
set_last_nfc_error(NFC_OK); // effectively a no-op
|
||||
set_last_nfc_error(NFC_OK);
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
#endif
|
||||
}
|
||||
|
@ -273,14 +283,14 @@ void NFCTestShim::cmd_erase()
|
|||
*/
|
||||
void NFCTestShim::cmd_write_long(char *text_string)
|
||||
{
|
||||
MessageBuilder builder(ndef_poster_message);
|
||||
MessageBuilder builder(_ndef_poster_message);
|
||||
strcpy(::long_string, text_string); //max_ndef - header - overheads
|
||||
Text text(Text::UTF8, span_from_cstr("en-US"),
|
||||
span_from_cstr((const char *)(::long_string)));
|
||||
|
||||
text.append_as_record(builder, true);
|
||||
_ndef_write_buffer_used = builder.get_message().size();
|
||||
cmd_printf("Composed NDEF message %d bytes\r\n", _ndef_write_buffer_used);
|
||||
trace_printf("Composed NDEF message %d bytes\r\n", _ndef_write_buffer_used);
|
||||
|
||||
#if MBED_CONF_NFCEEPROM
|
||||
((NFCProcessEEPROM *)this)->queue_write_call();
|
||||
|
@ -289,7 +299,7 @@ void NFCTestShim::cmd_write_long(char *text_string)
|
|||
set_last_nfc_error(NFC_OK);
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
#endif
|
||||
cmd_printf("NFCTestShim::write_long() exit\r\n");
|
||||
trace_printf("NFCTestShim::write_long() exit\r\n");
|
||||
free(text_string);
|
||||
}
|
||||
|
||||
|
@ -299,7 +309,7 @@ void NFCTestShim::cmd_write_long(char *text_string)
|
|||
*/
|
||||
void NFCTestShim::cmd_set_smartposter(char *cmdUri)
|
||||
{
|
||||
MessageBuilder builder(ndef_poster_message);
|
||||
MessageBuilder builder(_ndef_poster_message);
|
||||
|
||||
uint8_t smart_poster_buffer[1024];
|
||||
MessageBuilder smart_poster_builder(smart_poster_buffer);
|
||||
|
@ -316,7 +326,7 @@ void NFCTestShim::cmd_set_smartposter(char *cmdUri)
|
|||
smart_poster_builder.get_message(), true);
|
||||
|
||||
_ndef_write_buffer_used = builder.get_message().size();
|
||||
cmd_printf("Composed NDEF message %d bytes\r\n", _ndef_write_buffer_used);
|
||||
trace_printf("Composed NDEF message %d bytes\r\n", _ndef_write_buffer_used);
|
||||
|
||||
#if MBED_CONF_NFCEEPROM
|
||||
((NFCProcessEEPROM *)this)->queue_write_call();
|
||||
|
@ -325,7 +335,7 @@ void NFCTestShim::cmd_set_smartposter(char *cmdUri)
|
|||
set_last_nfc_error(NFC_OK);
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
#endif
|
||||
cmd_printf("NFCTestShim::setsmartposter() exit\r\n");
|
||||
trace_printf("NFCTestShim::setsmartposter() exit\r\n");
|
||||
free(cmdUri);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,26 +29,22 @@
|
|||
#include "nfc/NFCDefinitions.h"
|
||||
|
||||
/**
|
||||
* Test app driver wrapper. This is a base class containing shared EEPROM and Controller test data + logic
|
||||
* Test app driver wrapper. This is a base class containing shared EEPROM and Controller test data + logic.
|
||||
* Variations for the 2 different kinds of driver supported are delegated to derived classes.
|
||||
*/
|
||||
class NFCTestShim {
|
||||
public:
|
||||
NFCTestShim(events::EventQueue &queue);
|
||||
|
||||
static void cmd_get_last_nfc_error()
|
||||
{
|
||||
get_last_nfc_error();
|
||||
};
|
||||
static void cmd_set_last_nfc_error(int err)
|
||||
{
|
||||
set_last_nfc_error(err);
|
||||
cmd_ready(CMDLINE_RETCODE_SUCCESS);
|
||||
};
|
||||
static void cmd_get_conf_nfceeprom()
|
||||
{
|
||||
get_conf_nfceeprom();
|
||||
};
|
||||
static void cmd_get_last_nfc_error();
|
||||
static void cmd_set_last_nfc_error(int err);
|
||||
static void cmd_get_conf_nfceeprom();
|
||||
/**
|
||||
* For an EEPROM, this queries and responds with the flash size,
|
||||
* For a Controller, responds with the config macro TEST_NDEF_MSG_MAX
|
||||
*/
|
||||
virtual void cmd_get_max_ndef() = 0;
|
||||
|
||||
static void get_last_nfc_error();
|
||||
static void set_last_nfc_error(int err);
|
||||
static void get_conf_nfceeprom();
|
||||
|
@ -58,7 +54,6 @@ public:
|
|||
static char const *get_ndef_record_type_prefix(mbed::nfc::ndef::common::URI::uri_identifier_code_t id);
|
||||
|
||||
void cmd_init();
|
||||
virtual nfc_err_t init() = 0;
|
||||
|
||||
void cmd_set_smartposter(char *cmdUri);
|
||||
void cmd_erase();
|
||||
|
@ -71,6 +66,7 @@ public:
|
|||
|
||||
protected:
|
||||
// implement/declare EEPROM and Controller model underlying common BH and delegate specializations
|
||||
virtual nfc_err_t init() = 0;
|
||||
virtual nfc_err_t set_rf_protocols(mbed::nfc::nfc_rf_protocols_bitmask_t protocols)
|
||||
{
|
||||
return NFC_ERR_UNSUPPORTED ;
|
||||
|
@ -99,7 +95,7 @@ protected:
|
|||
|
||||
protected:
|
||||
size_t _ndef_write_buffer_used;
|
||||
mbed::Span<uint8_t> ndef_poster_message; // message to build and send
|
||||
mbed::Span<uint8_t> _ndef_poster_message; // message to build and send
|
||||
uint8_t _ndef_write_buffer[MBED_CONF_APP_TEST_NDEF_MSG_MAX]; // if this buffer is smaller than the EEPROM, the driver may crash see IOTPAN-297
|
||||
uint8_t _ndef_buffer[MBED_CONF_APP_TEST_NDEF_MSG_MAX]; // driver I/O buffer
|
||||
bool _discovery_restart; // default true, restart discovery loop again on remote disconnect
|
||||
|
|
|
@ -39,8 +39,7 @@ def debug_nfc_data(key, value):
|
|||
logger.info(text)
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG) # read commandline value?
|
||||
logger = logging.getLogger()
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class NfcWrapper:
|
||||
|
|
|
@ -155,6 +155,7 @@ def test_nfce2e_reprogrammed(self):
|
|||
self.nfc_command("dev1", "erase")
|
||||
|
||||
# program a poster tag to target
|
||||
print("Write Smartposter MESSAGE wirelessly")
|
||||
self.clf.parse("connect")
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
|
@ -162,7 +163,7 @@ def test_nfce2e_reprogrammed(self):
|
|||
nfc_messages.program_remote_tag(smartposter, tag)
|
||||
self.logger.info("Remote programmed %d bytes Smartposter" % len(str(smartposter)))
|
||||
|
||||
# read device
|
||||
print("Write back Smartposter MESSAGE wirelessly")
|
||||
self.clf.parse("connect")
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not re-connect to any tag")
|
||||
|
@ -189,25 +190,30 @@ def test_nfce2e_read_stress(self):
|
|||
response = self.nfc_command("dev1", "iseeprom")
|
||||
eeprom = response.parsed['iseeprom']
|
||||
self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
|
||||
max_ndef = STRESS_BUFFLEN
|
||||
|
||||
self.nfc_command("dev1", "initnfc")
|
||||
if not eeprom:
|
||||
self.nfc_command("dev1", "start")
|
||||
textLength = STRESS_BUFFLEN
|
||||
else:
|
||||
max_ndef = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
|
||||
textLength = max_ndef / 2 # large values slow down test runs and may time out
|
||||
if (max_ndef > 800 ):
|
||||
textLength = 800 # large values slow down test runs and may time out
|
||||
else:
|
||||
textLength = max_ndef
|
||||
self.nfc_command("dev1", "erase")
|
||||
# calculate actual message to compare to using the library
|
||||
expected_text = nfc_messages.repeat_string_to_length(messageRep, textLength)
|
||||
|
||||
# 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")
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
|
||||
# assert that read the eeprom contents gives correct data and length
|
||||
print("Read tag MESSAGE wirelessly" )
|
||||
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "TextRecord", "expected TextRecord")
|
||||
self.assert_text_equal(tag.ndef.records[0].text, expected_text)
|
||||
|
||||
|
@ -223,20 +229,26 @@ def test_nfce2e_reprogrammed_stress(self):
|
|||
response = self.nfc_command("dev1", "iseeprom")
|
||||
eeprom = response.parsed['iseeprom']
|
||||
self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
|
||||
max_ndef = STRESS_BUFFLEN
|
||||
|
||||
self.nfc_command("dev1", "initnfc")
|
||||
if not eeprom:
|
||||
self.nfc_command("dev1", "start")
|
||||
textLength = STRESS_BUFFLEN
|
||||
else:
|
||||
max_ndef = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
|
||||
textLength = max_ndef / 2 # large values slow down test runs and may time out
|
||||
|
||||
if (max_ndef > 800 ):
|
||||
textLength = 800 # large values slow down test runs and may time out
|
||||
else:
|
||||
textLength = max_ndef
|
||||
self.nfc_command("dev1", "erase")
|
||||
|
||||
# calculate actual message to compare to using the library
|
||||
message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength))
|
||||
expected_message = str(message)
|
||||
self.nfc_command("dev1", "erase")
|
||||
|
||||
# program a large tag to target remotely
|
||||
print("Write tag MESSAGE wirelessly (%d) bytes" % len(str(message)))
|
||||
self.clf.parse("connect")
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not connect to any tag")
|
||||
|
@ -244,6 +256,7 @@ def test_nfce2e_reprogrammed_stress(self):
|
|||
self.logger.info("%d bytes chunk of data written to tag remotely" % len(str(message)))
|
||||
|
||||
# read device locally
|
||||
print("Read back tag MESSAGE wirelessly")
|
||||
self.clf.parse("connect")
|
||||
tag = self.clf.clf_response()
|
||||
asserts.assertNotNone(tag, "Could not re-connect to any tag")
|
||||
|
@ -268,8 +281,8 @@ def test_nfce2e_discovery_loop(self):
|
|||
|
||||
self.nfc_command("dev1", "initnfc") # this NOT automatically start discovery at the same time, the test command
|
||||
# "start" must be used on a controller. (Eeeproms always have the loop enabled.)
|
||||
# By default, the test app automatically starts discovery loop again after a reader disconnects from the controller.
|
||||
# Automatic resume after disconnect can be turned off by using command "start man" , the default is "start auto" .
|
||||
# By default, the test app automatically starts discovery loop again after a reader disconnects from the controller.
|
||||
# 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")
|
||||
|
|
|
@ -132,7 +132,7 @@ can be read back.
|
|||
@test_case(CreamSconeSelfTests)
|
||||
def test_nfc_write_long(self):
|
||||
messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
|
||||
textLength = STRESS_BUFFLEN # 2K < x < 4K
|
||||
textLength = STRESS_BUFFLEN / 2 # 2K < x < 4K
|
||||
# calculate actual message to compare to using the library
|
||||
message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength))
|
||||
expected_message = str(message)
|
||||
|
@ -176,6 +176,7 @@ def test_nfc_set_controller_protocols(self):
|
|||
response = self.nfc_command("dev1", "iseeprom")
|
||||
eeprom = response.parsed['iseeprom']
|
||||
if eeprom:
|
||||
# eeproms do not allow target control
|
||||
self.logger.info("Test ignore - target includes NFCEEPROM: %s" % eeprom)
|
||||
else:
|
||||
self.nfc_command("dev1", "setprotocols t1t")
|
||||
|
|
Loading…
Reference in New Issue