Skip to content

Commit

Permalink
Fixed compiling warnings and Arduino sample
Browse files Browse the repository at this point in the history
Fixed all compiling warnings and added NurApiSetModuleSetup sample to Arduino.
  • Loading branch information
TuroRantanen committed Jun 13, 2018
1 parent 94507d2 commit cf4e801
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 35 deletions.
70 changes: 52 additions & 18 deletions arduino/NurMicroApi/examples/NurExample/NurExample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
/*
NurExample
Does tag inventory in loop every 1000ms.
This example code is in the public domain.
*/

// NUR serial port baud rate.
// NOTE: By default NUR module is configured to 115200 baudrate.
// NOTE: By default NUR module is configured to 115200 baudrate.
// If using something else baudrate (e.g. 38400) you'll need to reconfigure NUR for other baudrate using Nordic ID RFID Configurator app.
#define NUR_SERIAL_BAUDRATE (38400)

Expand All @@ -35,7 +35,7 @@ SoftwareSerial swSerial(10, 11); // RX, TX
static BYTE ApiRxBuffer[256];
static BYTE ApiTxBuffer[128];

// Ttue if NUR module detected in setup()
// True if NUR module detected in setup()
BOOL NurAvailable = FALSE;

// NurMicroApi handle
Expand All @@ -45,7 +45,7 @@ static struct NUR_API_HANDLE gApi =
NULL, // TransportReadDataFunction
NULL, // TransportWriteDataFunction
NULL, // UnsolEventHandler;

NULL, // BYTE *TxBuffer;
0, // DWORD TxBufferLen;

Expand Down Expand Up @@ -81,15 +81,15 @@ int nur_serial_read(struct NUR_API_HANDLE *hNurApi, BYTE *buffer, DWORD bufferLe

*bytesRead = dwRead;

return NUR_SUCCESS;
return NUR_SUCCESS;
}

// Write buffer to NUR serial
int nur_serial_write(struct NUR_API_HANDLE *hNurApi, BYTE *buffer, DWORD bufferLen, DWORD *bytesWritten)
{
DWORD dwWritten = 0;

while (dwWritten < bufferLen)
while (dwWritten < bufferLen)
{
NurSerial.write(buffer[dwWritten++]);
}
Expand Down Expand Up @@ -126,15 +126,15 @@ static void nur_print_versions()
PrintSerial.print(F("Versions, mode "));
PrintSerial.print((char)vr->mode);
PrintSerial.println("");

PrintSerial.print(F(" - primary : "));
PrintSerial.print(vr->vMajor, DEC);
PrintSerial.print(F("."));
PrintSerial.print(vr->vMinor, DEC);
PrintSerial.print(F("-"));
PrintSerial.print((char)vr->vBuild);
PrintSerial.println("");

PrintSerial.print(F(" - secondary : "));
PrintSerial.print(vr->otherMajor, DEC);
PrintSerial.print(F("."));
Expand All @@ -151,11 +151,46 @@ static void nur_print_versions()
#endif
}

// Configure NUR module
static void nur_configure_module()
{
int rc = NUR_SUCCESS;
struct NUR_CMD_LOADSETUP_PARAMS params;
// Flag settings that you want to chage
params.flags = NUR_SETUP_TXLEVEL | NUR_SETUP_ANTMASK | NUR_SETUP_SELECTEDANT;
// Set TxLevel to maximum (500mW/1000mW depending from the module)
params.txLevel = 0;
// Enable antenna 0.
// Use bit operation if you want to enable multiple
// antennas like antenna 0 and 1 (NUR_ANTENNAMASK_1 | NUR_ANTENNAMASK_2)
params.antennaMask = NUR_ANTENNAMASK_1;
// Set antenna selection to auto mode
params.selectedAntenna = NUR_ANTENNAID_AUTOSELECT;
#ifdef PrintSerial
PrintSerial.print(F("Configure NUR module"));
#endif
// Set new module setti
rc = NurApiSetModuleSetup(&gApi, &params);
if (rc == NUR_SUCCESS) {
#ifdef PrintSerial
PrintSerial.print(F("OK"));
#endif
}
else
{
#ifdef PrintSerial
PrintSerial.print(F("SetModuleSetup error. Code = "));
PrintSerial.print(rc, DEC);
PrintSerial.println("");
#endif
}
}

#ifdef PrintSerial
void print_hex(int val) {
char tmp[3];
sprintf(tmp, "%02X", val);
PrintSerial.print(tmp);
char tmp[3];
sprintf(tmp, "%02X", val);
PrintSerial.print(tmp);
}
#endif

Expand All @@ -172,7 +207,7 @@ int nur_fetch_tags_function(struct NUR_API_HANDLE *hNurApi, struct NUR_IDBUFFER_
PrintSerial.print(tag->scaledRssi, DEC);
PrintSerial.print(F("%) EPC: "));

for (n=0; n<tag->epcLen; n++) {
for (n = 0; n < tag->epcLen; n++) {
print_hex(tag->epcData[n]);
}
PrintSerial.println("");
Expand All @@ -195,16 +230,16 @@ void nur_tag_inventory()

// Clear tag buffer
rc = NurApiClearTags(&gApi);
if (rc == NUR_SUCCESS)
if (rc == NUR_SUCCESS)
{
// Perform tag inventory
rc = NurApiInventory(&gApi, NULL); // Pass NULL as params, uses default inventory settings from module setup
if (rc == NUR_SUCCESS)
if (rc == NUR_SUCCESS)
{
// Fetch tags one by one
int tagCount, n;
tagCount = gApi.resp->inventory.numTagsMem;
for (n=0; n<tagCount; n++)
for (n = 0; n < tagCount; n++)
{
rc = NurApiFetchTagAt(&gApi, TRUE, n, nur_fetch_tags_function);
if (rc != NUR_SUCCESS) {
Expand Down Expand Up @@ -240,7 +275,7 @@ void setup() {

#ifdef PrintSerial
// Open the print serial port
PrintSerial.begin(PRINT_SERIAL_BAUDRATE);
PrintSerial.begin(PRINT_SERIAL_BAUDRATE);
PrintSerial.println(F("Start"));
#endif

Expand All @@ -260,7 +295,7 @@ void setup() {
PrintSerial.println(F("NUR DETECTED"));
#endif
nur_print_versions();
}
}
else {
// No response or invalid response
#ifdef PrintSerial
Expand Down Expand Up @@ -289,4 +324,3 @@ void loop() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a 1000ms
}

2 changes: 1 addition & 1 deletion arduino/NurMicroApi/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=NurMicroApi
version=1.0.2
version=1.0.3
author=NordicID
maintainer=NordicID <support@nordicid.com>
sentence=Allows an Arduino board with UART capabilites to use Nordic ID NUR module based UHF RFID readers.
Expand Down
2 changes: 1 addition & 1 deletion arduino/NurMicroApi/src/NurMicroApi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ int NURAPICONV NurApiProgramBuffer(struct NUR_API_HANDLE *hNurApi, pProgramProgr
if (pageSize > NUR_FLASH_PAGE_SIZE)
pageSize = NUR_FLASH_PAGE_SIZE;

memcpy(pagewriteParams->data, &buffer[writePos], pageSize);
nurMemcpy(pagewriteParams->data, &buffer[writePos], pageSize);

if (pageSize < NUR_FLASH_PAGE_SIZE) {
// Pad with 0xFF
Expand Down
14 changes: 7 additions & 7 deletions arduino/NurMicroApi/src/NurMicroApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ enum NUR_MODULESETUP_FLAGS
NUR_SETUP_AUTOPERIOD = (1L<<22), /**< stixPeriod field in struct NUR_MODULESETUP is valid */
NUR_SETUP_PERANTPOWER = (1L<<23), /**< antPower field in struct NUR_MODULESETUP is valid */
NUR_SETUP_PERANTOFFSET = (1L<<24), /**< powerOffset field in struct NUR_MODULESETUP is valid */
NUR_SETUP_ANTMASKEX = (1<<25), /**< antennaMaskEx field in struct NUR_MODULESETUP is valid */
NUR_SETUP_AUTOTUNE = (1<<26), /**< autotune field in struct NUR_MODULESETUP is valid */
NUR_SETUP_PERANTPOWER_EX = (1<<27), /**< antPowerEx field in struct NUR_MODULESETUP is valid */
NUR_SETUP_RXSENS = (1<<28), /**< rxSensitivity field in struct NUR_MODULESETUP is valid */
NUR_SETUP_ANTMASKEX = (1L<<25), /**< antennaMaskEx field in struct NUR_MODULESETUP is valid */
NUR_SETUP_AUTOTUNE = (1L<<26), /**< autotune field in struct NUR_MODULESETUP is valid */
NUR_SETUP_PERANTPOWER_EX = (1L<<27), /**< antPowerEx field in struct NUR_MODULESETUP is valid */
NUR_SETUP_RXSENS = (1L<<28), /**< rxSensitivity field in struct NUR_MODULESETUP is valid */

NUR_SETUP_ALL = ((1 << 29) - 1) /**< All setup flags in the structure. */
NUR_SETUP_ALL = ((1L << 29) - 1) /**< All setup flags in the structure. */
};

/** Possible inventory targets.
Expand Down Expand Up @@ -853,7 +853,7 @@ NUR_API int NURAPICONV NurApiInventoryEx(struct NUR_API_HANDLE *hNurApi,

NUR_API int NURAPICONV NurApiGetInventoryReadConfig(struct NUR_API_HANDLE *hNurApi);
NUR_API int NURAPICONV NurApiSetInventoryReadConfig(struct NUR_API_HANDLE *hNurApi,
struct NUR_CMD_CONFIGIR_PARAMS *params);
struct NUR_CMD_IRCONFIG_PARAMS *params);

NUR_API int NURAPICONV NurApiFetchTags(struct NUR_API_HANDLE *hNurApi, BOOL includeMeta, BOOL clearModuleTags, int *tagsReceived, pFetchTagsFunction tagFunc);
NUR_API int NURAPICONV NurApiFetchTagAt(struct NUR_API_HANDLE *hNurApi, BOOL includeMeta, int tagNum, pFetchTagsFunction tagFunc);
Expand Down Expand Up @@ -884,7 +884,7 @@ int NURAPICONV NurApiGetMode(struct NUR_API_HANDLE *hNurApi, char *mode);
int NURAPICONV NurApiModuleRestart(struct NUR_API_HANDLE *hNurApi);
int NURAPICONV NurApiEnterBoot(struct NUR_API_HANDLE *hNurApi);

#define NUR_APP_FIRST_PAGE ((64 * 1024) / NUR_FLASH_PAGE_SIZE)
#define NUR_APP_FIRST_PAGE ((64L * 1024L) / NUR_FLASH_PAGE_SIZE)
#define NUR_BL_FIRST_PAGE (0)

struct NUR_PRGPROGRESS_DATA
Expand Down
Binary file modified arduino/NurMicroApi_arduino.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion source/NurMicroApi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ int NURAPICONV NurApiProgramBuffer(struct NUR_API_HANDLE *hNurApi, pProgramProgr
if (pageSize > NUR_FLASH_PAGE_SIZE)
pageSize = NUR_FLASH_PAGE_SIZE;

memcpy(pagewriteParams->data, &buffer[writePos], pageSize);
nurMemcpy(pagewriteParams->data, &buffer[writePos], pageSize);

if (pageSize < NUR_FLASH_PAGE_SIZE) {
// Pad with 0xFF
Expand Down
14 changes: 7 additions & 7 deletions source/NurMicroApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ enum NUR_MODULESETUP_FLAGS
NUR_SETUP_AUTOPERIOD = (1L<<22), /**< stixPeriod field in struct NUR_MODULESETUP is valid */
NUR_SETUP_PERANTPOWER = (1L<<23), /**< antPower field in struct NUR_MODULESETUP is valid */
NUR_SETUP_PERANTOFFSET = (1L<<24), /**< powerOffset field in struct NUR_MODULESETUP is valid */
NUR_SETUP_ANTMASKEX = (1<<25), /**< antennaMaskEx field in struct NUR_MODULESETUP is valid */
NUR_SETUP_AUTOTUNE = (1<<26), /**< autotune field in struct NUR_MODULESETUP is valid */
NUR_SETUP_PERANTPOWER_EX = (1<<27), /**< antPowerEx field in struct NUR_MODULESETUP is valid */
NUR_SETUP_RXSENS = (1<<28), /**< rxSensitivity field in struct NUR_MODULESETUP is valid */
NUR_SETUP_ANTMASKEX = (1L<<25), /**< antennaMaskEx field in struct NUR_MODULESETUP is valid */
NUR_SETUP_AUTOTUNE = (1L<<26), /**< autotune field in struct NUR_MODULESETUP is valid */
NUR_SETUP_PERANTPOWER_EX = (1L<<27), /**< antPowerEx field in struct NUR_MODULESETUP is valid */
NUR_SETUP_RXSENS = (1L<<28), /**< rxSensitivity field in struct NUR_MODULESETUP is valid */

NUR_SETUP_ALL = ((1 << 29) - 1) /**< All setup flags in the structure. */
NUR_SETUP_ALL = ((1L << 29) - 1) /**< All setup flags in the structure. */
};

/** Possible inventory targets.
Expand Down Expand Up @@ -853,7 +853,7 @@ NUR_API int NURAPICONV NurApiInventoryEx(struct NUR_API_HANDLE *hNurApi,

NUR_API int NURAPICONV NurApiGetInventoryReadConfig(struct NUR_API_HANDLE *hNurApi);
NUR_API int NURAPICONV NurApiSetInventoryReadConfig(struct NUR_API_HANDLE *hNurApi,
struct NUR_CMD_CONFIGIR_PARAMS *params);
struct NUR_CMD_IRCONFIG_PARAMS *params);

NUR_API int NURAPICONV NurApiFetchTags(struct NUR_API_HANDLE *hNurApi, BOOL includeMeta, BOOL clearModuleTags, int *tagsReceived, pFetchTagsFunction tagFunc);
NUR_API int NURAPICONV NurApiFetchTagAt(struct NUR_API_HANDLE *hNurApi, BOOL includeMeta, int tagNum, pFetchTagsFunction tagFunc);
Expand Down Expand Up @@ -884,7 +884,7 @@ int NURAPICONV NurApiGetMode(struct NUR_API_HANDLE *hNurApi, char *mode);
int NURAPICONV NurApiModuleRestart(struct NUR_API_HANDLE *hNurApi);
int NURAPICONV NurApiEnterBoot(struct NUR_API_HANDLE *hNurApi);

#define NUR_APP_FIRST_PAGE ((64 * 1024) / NUR_FLASH_PAGE_SIZE)
#define NUR_APP_FIRST_PAGE ((64L * 1024L) / NUR_FLASH_PAGE_SIZE)
#define NUR_BL_FIRST_PAGE (0)

struct NUR_PRGPROGRESS_DATA
Expand Down

0 comments on commit cf4e801

Please sign in to comment.