Skip to content

Commit c36f540

Browse files
committed
Merged buffer size in config
1 parent 7095b82 commit c36f540

File tree

15 files changed

+220
-104
lines changed

15 files changed

+220
-104
lines changed

TEST_APPS/device/nfcapp/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const char *errorcodes = // descriptions from nfc/stack/nfc_errors.h
6565
"20 NFC_ERR_DISCONNECTED \n"
6666
"21 NFC_ERR_ABORTED\n";
6767

68-
// for easy manual UI interaction
68+
/** Disables VT100 etc. for easy manual UI interaction */
6969
int seteasy(int argc, char *argv[])
7070
{
7171
const char msg[][20] =
@@ -95,15 +95,17 @@ int main(int argc, char *argv[])
9595
"last NFC error code", errorcodes);
9696
cmd_add("setlastnfcerror", HandleTestCommand::cmd_set_last_nfc_error,
9797
"self-test", "for self-test only");
98+
cmd_add("iseeprom", HandleTestCommand::cmd_get_conf_nfceeprom,
99+
"get NFC configEEPROM present",
100+
"true if config exists, else false");
98101
cmd_add("initnfc", HandleTestCommand::cmd_init_nfc, "init NFC driver",
99102
"call first");
103+
cmd_add("getmaxndef", HandleTestCommand::cmd_get_max_ndef, "get max NDEF record target supports",
104+
"returns the eeprom size, or max buffer if a controller");
100105
cmd_add("init", HandleTestCommand::cmd_init_nfc, "alias initnfc",
101106
"call first");
102107
cmd_add("setsmartposter", HandleTestCommand::cmd_set_smartposter,
103108
"send smartposter NDEF", "<uri>");
104-
cmd_add("iseeprom", HandleTestCommand::cmd_get_conf_nfceeprom,
105-
"get NFC configEEPROM present",
106-
"true if config exists, else false");
107109
cmd_add("readmessage", HandleTestCommand::cmd_read_message,
108110
"read EEPROM else return last message", "returns hex dump");
109111
cmd_add("read", HandleTestCommand::cmd_read_message, "alias readmessage",

TEST_APPS/device/nfcapp/mbed_app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"config": {
3-
"TEST_NDEF_MSG_MAX" : 8192
3+
"TEST_NDEF_MSG_MAX" : 1024
44
},
55
"target_overrides": {
66
"DISCO_L475VG_IOT01A": {

TEST_APPS/device/nfcapp/nfccommands.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ int HandleTestCommand::cmd_set_last_nfc_error(int argc, char *argv[])
6868
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
6969
}
7070

71+
72+
int HandleTestCommand::cmd_get_max_ndef(int argc, char *argv[])
73+
{
74+
if (pNFC_Test_Shim) {
75+
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_get_max_ndef);
76+
return CMDLINE_RETCODE_EXCUTING_CONTINUE;
77+
}
78+
return CMDLINE_RETCODE_FAIL;
79+
}
80+
81+
7182
int HandleTestCommand::cmd_init_nfc(int argc, char *argv[])
7283
{
7384

@@ -82,7 +93,7 @@ int HandleTestCommand::cmd_init_nfc(int argc, char *argv[])
8293

8394
int HandleTestCommand::cmd_read_message(int argc, char *argv[])
8495
{
85-
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_read_nfceeprom);
96+
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_read_nfc_contents);
8697

8798
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
8899
}
@@ -133,6 +144,12 @@ int HandleTestCommand::cmd_write_long_ndef_message(int argc, char *argv[])
133144
cmd_printf("Cannot convert value to int\r\n");
134145
return (CMDLINE_RETCODE_INVALID_PARAMETERS);
135146
}
147+
// check that it would not overflow
148+
if (length > MBED_CONF_APP_TEST_NDEF_MSG_MAX) {
149+
cmd_printf("Buffer length may not exceed %d !\r\n", (int)MBED_CONF_APP_TEST_NDEF_MSG_MAX);
150+
return (CMDLINE_RETCODE_FAIL);
151+
}
152+
136153
data = (char *) malloc(length + 1);
137154
if (!data) {
138155
cmd_printf("WARN out of memory!\r\n");

TEST_APPS/device/nfcapp/nfccommands.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,49 @@ extern events::EventQueue nfcQueue;
3838
*/
3939
class HandleTestCommand {
4040
public:
41-
// start thread and handle queue
4241
HandleTestCommand();
43-
/* set corresponding mask bit on, return false if the supplied string cannot parse */
42+
/** set corresponding mask bit on in referenced structure, return false if the supplied string cannot parse */
4443
static bool set_protocol_target(mbed::nfc::nfc_rf_protocols_bitmask_t &bitmask, const char *protocolName);
4544

46-
/* return and clear the last result code. Type "help getlastnfcerror" for a list of error codes */
45+
/** return and clear the last result code. Type "help getlastnfcerror" for a list of error codes */
4746
static int cmd_get_last_nfc_error(int argc, char *argv[])
4847
{
4948
nfcQueue.call(NFCTestShim::cmd_get_last_nfc_error);
5049
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
5150
}
5251

53-
/* internal function to test getlastnfcerror */
52+
/** internal function to test getlastnfcerror */
5453
static int cmd_set_last_nfc_error(int argc, char *argv[]);
5554

56-
/* compile time flag */
55+
/** returns compile time flag if NFC EEPROM was compiled */
5756
static int cmd_get_conf_nfceeprom(int argc, char *argv[])
5857
{
5958
nfcQueue.call(NFCTestShim::cmd_get_conf_nfceeprom);
6059
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
6160
}
6261

63-
/* must be called before invoking any other calls */
62+
/** For EEPROM, returns the driver max_ndef value, else returns the app config MBED_CONF_APP_TEST_NDEF_MSG_MAX */
63+
static int cmd_get_max_ndef(int argc, char *argv[]);
64+
65+
/** Init must be called before invoking any other calls, obtains a driver reference and initializes driver */
6466
static int cmd_init_nfc(int argc, char *argv[]);
65-
/* write a smartposter url, 'Sp' NDEF to the target */
67+
/** write a smartposter url, 'Sp' NDEF to the target */
6668
static int cmd_set_smartposter(int argc, char *argv[]);
67-
/* erase EEPROM */
69+
/** erases the EEPROM if present */
6870
static int cmd_erase(int argc, char *argv[]);
6971

70-
// controller driver methods:
72+
/** Returns a CSV list of protocols supported */
7173
static int cmd_get_supported_rf_protocols(int argc, char *argv[]);
74+
/** Sets the protocols supported (unimplemented) */
7275
static int cmd_configure_rf_protocols(int argc, char *argv[]);
76+
/** starts the NFC discovery loop if controller, has no effect on EEPROM */
7377
static int cmd_start_discovery(int argc, char *argv[]);
78+
/** stops the NFC discovery loop if controller */
7479
static int cmd_stop_discovery(int argc, char *argv[]);
7580

76-
/* read raw EEPROM contents */
81+
/** read raw EEPROM contents, reads a buffer if a controller is used */
7782
static int cmd_read_message(int argc, char *argv[]);
78-
/* write a text 'T' NDEF message to the target */
83+
/** write a text 'T' NDEF message to the target */
7984
static int cmd_write_long_ndef_message(int argc, char *argv[]);
8085

8186
};

TEST_APPS/device/nfcapp/nfcprocessCtrl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class NFCProcessController: NFCTestShim,
4848
public:
4949
NFCProcessController(events::EventQueue &queue);
5050

51+
void cmd_get_max_ndef()
52+
{
53+
cmd_printf("{{maxndef=%d}}\r\n", (int)MBED_CONF_APP_TEST_NDEF_MSG_MAX);
54+
cmd_ready(CMDLINE_RETCODE_SUCCESS);
55+
}
5156
nfc_err_t init();
5257
nfc_err_t start_discovery();
5358
nfc_err_t stop_discovery();

TEST_APPS/device/nfcapp/nfcprocessEeprom.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using mbed::nfc::NFCEEPROMDriver;
4747

4848
// implements : mbed::nfc::NFCEEPROM::Delegate
4949
NFCProcessEEPROM::NFCProcessEEPROM(events::EventQueue &queue, NFCEEPROMDriver &eeprom_driver) :
50-
NFCTestShim(queue), _eeprom(&eeprom_driver, &queue, _ndef_buffer)
50+
NFCTestShim(queue), _eeprom(&eeprom_driver, &queue, _ndef_buffer), _ptr_eeprom_driver(&eeprom_driver)
5151
{}
5252

5353
nfc_err_t NFCProcessEEPROM::init()
@@ -63,6 +63,13 @@ nfc_err_t NFCProcessEEPROM::init()
6363
return (err);
6464
}
6565

66+
67+
void NFCProcessEEPROM::cmd_get_max_ndef()
68+
{
69+
cmd_printf("{{maxndef=%d}}\r\n", (int)_ptr_eeprom_driver->read_max_size());
70+
cmd_ready(CMDLINE_RETCODE_SUCCESS);
71+
}
72+
6673
void NFCProcessEEPROM::queue_write_call()
6774
{
6875
cmd_printf("NFCProcessEEPROM::queue_write_call() entry\r\n");
@@ -83,7 +90,6 @@ void NFCProcessEEPROM::queue_erase_call()
8390

8491
void NFCProcessEEPROM::on_ndef_message_written(nfc_err_t result)
8592
{
86-
// todo: de-duplicate this code
8793
set_last_nfc_error(result);
8894
if (result == NFC_OK) {
8995
cmd_printf("message written successfully\r\n");
@@ -108,7 +114,6 @@ void NFCProcessEEPROM::on_ndef_message_read(nfc_err_t result)
108114

109115
void NFCProcessEEPROM::on_ndef_message_erased(nfc_err_t result)
110116
{
111-
// todo : de-duplicate/template this callback handler
112117
set_last_nfc_error(result);
113118
if (result == NFC_OK) {
114119
cmd_printf("message erased successfully\r\n");

TEST_APPS/device/nfcapp/nfcprocessEeprom.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class NFCProcessEEPROM : NFCTestShim, mbed::nfc::NFCEEPROM::Delegate {
4343
void queue_write_long_call();
4444
void queue_read_call();
4545
void queue_erase_call();
46+
void cmd_get_max_ndef();
47+
4648

4749
private:
4850
virtual void on_ndef_message_written(nfc_err_t result);
@@ -52,6 +54,7 @@ class NFCProcessEEPROM : NFCTestShim, mbed::nfc::NFCEEPROM::Delegate {
5254
virtual void on_ndef_message_erased(nfc_err_t result);
5355
private:
5456
mbed::nfc::NFCEEPROM _eeprom;
57+
mbed::nfc::NFCEEPROMDriver *_ptr_eeprom_driver;
5558
};
5659

5760
#endif // eeprom

TEST_APPS/device/nfcapp/nfctestshim.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ using mbed::nfc::nfc_rf_protocols_bitmask_t;
4242
// statics
4343
namespace {
4444
char long_string[MBED_CONF_APP_TEST_NDEF_MSG_MAX];
45-
4645
char const *uri_prefix_string[] = { "",
4746
"http://www.",
4847
"https://www.",
@@ -234,18 +233,19 @@ void NFCTestShim::cmd_configure_rf_protocols(
234233
* the framework
235234
* \return void An ICETEA error code and NFC error is set asyncronously
236235
*/
237-
void NFCTestShim::cmd_read_nfceeprom()
236+
void NFCTestShim::cmd_read_nfc_contents()
238237
{
239238
#if MBED_CONF_NFCEEPROM
240239
((NFCProcessEEPROM *)this)->queue_read_call();
241-
cmd_printf("NFCTestShim::read_nfceeprom() exit\r\n");
240+
cmd_printf("NFCTestShim::cmd_read_nfc_contents() exit\r\n");
242241

243242
#else
244243
// returns last message "written", since we cannot read
245244
print_ndef_message(_ndef_write_buffer, _ndef_write_buffer_used);
245+
cmd_printf("Controller buffer data size=%d\r\n", _ndef_write_buffer_used);
246246
set_last_nfc_error(NFC_OK);
247247

248-
cmd_printf("NFCTestShim::read_nfceeprom()\r\n");
248+
cmd_printf("NFCTestShim::cmd_read_nfc_contents()\r\n");
249249
cmd_ready(CMDLINE_RETCODE_SUCCESS);
250250
#endif
251251
}
@@ -271,11 +271,10 @@ void NFCTestShim::cmd_erase()
271271
* \param uri This method must free the passed in pointer
272272
* \return void An ICETEA error code and NFC error is set asyncronously
273273
*/
274-
void NFCTestShim::cmd_write_long(char *data)
274+
void NFCTestShim::cmd_write_long(char *text_string)
275275
{
276276
MessageBuilder builder(ndef_poster_message);
277-
278-
strcpy(::long_string, data); //max_ndef - header - overheads
277+
strcpy(::long_string, text_string); //max_ndef - header - overheads
279278
Text text(Text::UTF8, span_from_cstr("en-US"),
280279
span_from_cstr((const char *)(::long_string)));
281280

@@ -290,9 +289,8 @@ void NFCTestShim::cmd_write_long(char *data)
290289
set_last_nfc_error(NFC_OK);
291290
cmd_ready(CMDLINE_RETCODE_SUCCESS);
292291
#endif
293-
294292
cmd_printf("NFCTestShim::write_long() exit\r\n");
295-
free(data);
293+
free(text_string);
296294
}
297295

298296
/** \brief Write a URI Use case would be to prompt to install an app from the appstore using the tag

TEST_APPS/device/nfcapp/nfctestshim.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
#include "nfc/ndef/common/util.h"
2929
#include "nfc/NFCDefinitions.h"
3030

31-
31+
/**
32+
* Test app driver wrapper. This is a base class containing shared EEPROM and Controller test data + logic
33+
*/
3234
class NFCTestShim {
3335
public:
3436
NFCTestShim(events::EventQueue &queue);
@@ -46,6 +48,7 @@ class NFCTestShim {
4648
{
4749
get_conf_nfceeprom();
4850
};
51+
virtual void cmd_get_max_ndef() = 0;
4952
static void get_last_nfc_error();
5053
static void set_last_nfc_error(int err);
5154
static void get_conf_nfceeprom();
@@ -59,8 +62,8 @@ class NFCTestShim {
5962

6063
void cmd_set_smartposter(char *cmdUri);
6164
void cmd_erase();
62-
void cmd_write_long(char *data);
63-
void cmd_read_nfceeprom();
65+
void cmd_write_long(char *text_string);
66+
void cmd_read_nfc_contents();
6467
void cmd_start_discovery(bool manual = false);
6568
void cmd_stop_discovery();
6669
void cmd_configure_rf_protocols(mbed::nfc::nfc_rf_protocols_bitmask_t protocols);
@@ -101,7 +104,6 @@ class NFCTestShim {
101104
uint8_t _ndef_buffer[MBED_CONF_APP_TEST_NDEF_MSG_MAX]; // driver I/O buffer
102105
bool _discovery_restart; // default true, restart discovery loop again on remote disconnect
103106
events::EventQueue &_queue;
104-
105107
};
106108

107109
// forward declare single instance

0 commit comments

Comments
 (0)