DEVEUI handling improved (issue #5)
This commit is contained in:
		
							parent
							
								
									ce5dadeffe
								
							
						
					
					
						commit
						903bbac73d
					
				@ -10,9 +10,8 @@
 | 
			
		||||
/* 
 | 
			
		||||
 | 
			
		||||
// Only define DEVEUI here if you don't want it to be derived from device's MAC address
 | 
			
		||||
// Use little endian format (lsb)
 | 
			
		||||
 | 
			
		||||
//static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 | 
			
		||||
// 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 };
 | 
			
		||||
 | 
			
		||||
// This EUI must be in little-endian format, so least-significant-byte
 | 
			
		||||
// first. When copying an EUI from ttnctl output, this means to reverse
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
// Display a key
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/main.cpp
									
									
									
									
									
								
							@ -75,6 +75,8 @@ void loadConfig(void);
 | 
			
		||||
 | 
			
		||||
// defined in lorawan.cpp
 | 
			
		||||
void gen_lora_deveui(uint8_t * pdeveui);
 | 
			
		||||
void RevBytes(unsigned char* b, size_t c);
 | 
			
		||||
 | 
			
		||||
#ifdef VERBOSE
 | 
			
		||||
    void printKeys(void);
 | 
			
		||||
#endif // VERBOSE
 | 
			
		||||
@ -82,11 +84,14 @@ void gen_lora_deveui(uint8_t * pdeveui);
 | 
			
		||||
// LMIC callback functions
 | 
			
		||||
void os_getArtEui (u1_t *buf) { memcpy(buf, APPEUI, 8);}
 | 
			
		||||
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) { memcpy(buf, DEVEUI, 8);}
 | 
			
		||||
#else // ... otherwise generate DEVEUI at runtime from devices's MAC
 | 
			
		||||
    void os_getDevEui (u1_t *buf) { gen_lora_deveui(buf);} 
 | 
			
		||||
#endif
 | 
			
		||||
void os_getDevEui (u1_t* buf) {
 | 
			
		||||
    #ifdef DEVEUI
 | 
			
		||||
        memcpy(buf, DEVEUI, 8);
 | 
			
		||||
        RevBytes(buf, 8); // TTN requires it in LSB First order, so we swap bytes
 | 
			
		||||
    #else
 | 
			
		||||
        gen_lora_deveui(buf);
 | 
			
		||||
    #endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LMIC enhanced Pin mapping 
 | 
			
		||||
const lmic_pinmap lmic_pins = {
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
// 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"
 | 
			
		||||
 | 
			
		||||
// Verbose enables serial output
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user