DEVEUI handling improved (issue #5)

This commit is contained in:
Klaus K Wilting 2018-03-21 22:32:59 +01:00
parent ce5dadeffe
commit 903bbac73d
4 changed files with 23 additions and 9 deletions

View File

@ -10,9 +10,8 @@
/* /*
// Only define DEVEUI here if you don't want it to be derived from device's MAC address // Only define DEVEUI here if you don't want it to be derived from device's MAC address
// Use little endian format (lsb) // Use same format as in TTN console (cut & paste, for your convenience)
static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
//static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
// This EUI must be in little-endian format, so least-significant-byte // This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse // first. When copying an EUI from ttnctl output, this means to reverse

View File

@ -36,6 +36,16 @@ void gen_lora_deveui(uint8_t *pdeveui) {
} }
} }
// Function to do a byte swap in a byte array
void RevBytes(unsigned char* b, size_t c)
{
u1_t i;
for (i = 0; i < c / 2; i++)
{ unsigned char t = b[i];
b[i] = b[c - 1 - i];
b[c - 1 - i] = t; }
}
#ifdef VERBOSE #ifdef VERBOSE
// Display a key // Display a key

View File

@ -75,6 +75,8 @@ void loadConfig(void);
// defined in lorawan.cpp // defined in lorawan.cpp
void gen_lora_deveui(uint8_t * pdeveui); void gen_lora_deveui(uint8_t * pdeveui);
void RevBytes(unsigned char* b, size_t c);
#ifdef VERBOSE #ifdef VERBOSE
void printKeys(void); void printKeys(void);
#endif // VERBOSE #endif // VERBOSE
@ -82,11 +84,14 @@ void gen_lora_deveui(uint8_t * pdeveui);
// LMIC callback functions // LMIC callback functions
void os_getArtEui (u1_t *buf) { memcpy(buf, APPEUI, 8);} void os_getArtEui (u1_t *buf) { memcpy(buf, APPEUI, 8);}
void os_getDevKey (u1_t *buf) { memcpy(buf, APPKEY, 16);} void os_getDevKey (u1_t *buf) { memcpy(buf, APPKEY, 16);}
#ifdef DEVEUI // if DEVEUI defined in loraconf.h use that and hardwire it in code ... void os_getDevEui (u1_t* buf) {
void os_getDevEui (u1_t *buf) { memcpy(buf, DEVEUI, 8);} #ifdef DEVEUI
#else // ... otherwise generate DEVEUI at runtime from devices's MAC memcpy(buf, DEVEUI, 8);
void os_getDevEui (u1_t *buf) { gen_lora_deveui(buf);} RevBytes(buf, 8); // TTN requires it in LSB First order, so we swap bytes
#endif #else
gen_lora_deveui(buf);
#endif
}
// LMIC enhanced Pin mapping // LMIC enhanced Pin mapping
const lmic_pinmap lmic_pins = { const lmic_pinmap lmic_pins = {

View File

@ -1,5 +1,5 @@
// program version // program version
#define PROGVERSION "1.2.31" // use max 10 chars here! #define PROGVERSION "1.2.32" // use max 10 chars here!
#define PROGNAME "PAXCNT" #define PROGNAME "PAXCNT"
// Verbose enables serial output // Verbose enables serial output