Merge pull request #95 from cyberman54/master
sync master & dev to v1.3.81
This commit is contained in:
commit
cc2a349f29
171
src/lorawan.cpp
171
src/lorawan.cpp
@ -7,7 +7,7 @@
|
|||||||
#include <hal/hal.h>
|
#include <hal/hal.h>
|
||||||
|
|
||||||
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
#include <Wire.h> // Needed for 24AA02E64, does not hurt anything if included and not used
|
#include <Wire.h> // Needed for 24AA02E64, does not hurt anything if included and not used
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Local logging Tag
|
// Local logging Tag
|
||||||
@ -29,19 +29,19 @@ void gen_lora_deveui(uint8_t *pdeveui) {
|
|||||||
*p++ = 0xFF;
|
*p++ = 0xFF;
|
||||||
*p++ = 0xFE;
|
*p++ = 0xFE;
|
||||||
// Then next 6 bytes are mac address reversed
|
// Then next 6 bytes are mac address reversed
|
||||||
for ( i=0; i<6 ; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
*p++ = dmac[5-i];
|
*p++ = dmac[5 - i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to do a byte swap in a byte array
|
// Function to do a byte swap in a byte array
|
||||||
void RevBytes(unsigned char* b, size_t c)
|
void RevBytes(unsigned char *b, size_t c) {
|
||||||
{
|
|
||||||
u1_t i;
|
u1_t i;
|
||||||
for (i = 0; i < c / 2; i++)
|
for (i = 0; i < c / 2; i++) {
|
||||||
{ unsigned char t = b[i];
|
unsigned char t = b[i];
|
||||||
b[i] = b[c - 1 - i];
|
b[i] = b[c - 1 - i];
|
||||||
b[c - 1 - i] = t; }
|
b[c - 1 - i] = t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_hard_deveui(uint8_t *pdeveui) {
|
void get_hard_deveui(uint8_t *pdeveui) {
|
||||||
@ -55,14 +55,14 @@ void get_hard_deveui(uint8_t *pdeveui) {
|
|||||||
i2c_ret = Wire.endTransmission();
|
i2c_ret = Wire.endTransmission();
|
||||||
// check if device seen on i2c bus
|
// check if device seen on i2c bus
|
||||||
if (i2c_ret == 0) {
|
if (i2c_ret == 0) {
|
||||||
char deveui[32]="";
|
char deveui[32] = "";
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
||||||
Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8);
|
Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8);
|
||||||
while (Wire.available()) {
|
while (Wire.available()) {
|
||||||
data = Wire.read();
|
data = Wire.read();
|
||||||
sprintf(deveui+strlen(deveui), "%02X ", data);
|
sprintf(deveui + strlen(deveui), "%02X ", data);
|
||||||
*pdeveui++ = data;
|
*pdeveui++ = data;
|
||||||
}
|
}
|
||||||
i2c_ret = Wire.endTransmission();
|
i2c_ret = Wire.endTransmission();
|
||||||
@ -78,12 +78,12 @@ void get_hard_deveui(uint8_t *pdeveui) {
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
|
|
||||||
// Display a key
|
// Display a key
|
||||||
void printKey(const char * name, const uint8_t * key, uint8_t len, bool lsb) {
|
void printKey(const char *name, const uint8_t *key, uint8_t len, bool lsb) {
|
||||||
const uint8_t * p ;
|
const uint8_t *p;
|
||||||
char keystring[len+1] = "", keybyte[3];
|
char keystring[len + 1] = "", keybyte[3];
|
||||||
for (uint8_t i=0; i<len ; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
p = lsb ? key+len-i-1 : key+i;
|
p = lsb ? key + len - i - 1 : key + i;
|
||||||
sprintf(keybyte, "%02X", * p);
|
sprintf(keybyte, "%02X", *p);
|
||||||
strncat(keystring, keybyte, 2);
|
strncat(keystring, keybyte, 2);
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "%s: %s", name, keystring);
|
ESP_LOGI(TAG, "%s: %s", name, keystring);
|
||||||
@ -95,11 +95,11 @@ void printKeys(void) {
|
|||||||
// all EUI buffer so we do it here to a temp
|
// all EUI buffer so we do it here to a temp
|
||||||
// buffer to be able to display them
|
// buffer to be able to display them
|
||||||
uint8_t buf[32];
|
uint8_t buf[32];
|
||||||
os_getDevEui((u1_t*) buf);
|
os_getDevEui((u1_t *)buf);
|
||||||
printKey("DevEUI", buf, 8, true);
|
printKey("DevEUI", buf, 8, true);
|
||||||
os_getArtEui((u1_t*) buf);
|
os_getArtEui((u1_t *)buf);
|
||||||
printKey("AppEUI", buf, 8, true);
|
printKey("AppEUI", buf, 8, true);
|
||||||
os_getDevKey((u1_t*) buf);
|
os_getDevKey((u1_t *)buf);
|
||||||
printKey("AppKey", buf, 16, false);
|
printKey("AppKey", buf, 16, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,31 +155,6 @@ void do_send(osjob_t *j) {
|
|||||||
#endif
|
#endif
|
||||||
sprintf(display_lmic, "PACKET QUEUED");
|
sprintf(display_lmic, "PACKET QUEUED");
|
||||||
|
|
||||||
#ifdef HAS_GPS
|
|
||||||
static uint8_t gpsdata[18];
|
|
||||||
if (cfg.gpsmode && gps.location.isValid()) {
|
|
||||||
gps_read();
|
|
||||||
memcpy (gpsdata, mydata, 4);
|
|
||||||
memcpy (gpsdata+4, &gps_status, sizeof(gps_status));
|
|
||||||
ESP_LOGI(TAG, "lat=%.6f / lon=%.6f | %u Sats | HDOP=%.1f | Altitude=%u m", \
|
|
||||||
gps_status.latitude / (float) 1000000, \
|
|
||||||
gps_status.longitude / (float) 1000000, \
|
|
||||||
gps_status.satellites, \
|
|
||||||
gps_status.hdop / (float) 100, \
|
|
||||||
gps_status.altitude);
|
|
||||||
LMIC_setTxData2(COUNTERPORT, gpsdata, sizeof(gpsdata), (cfg.countermode & 0x02));
|
|
||||||
ESP_LOGI(TAG, "%d bytes queued to send", sizeof(gpsdata));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
#endif
|
|
||||||
LMIC_setTxData2(COUNTERPORT, mydata, sizeof(mydata), (cfg.countermode & 0x02));
|
|
||||||
ESP_LOGI(TAG, "%d bytes queued to send", sizeof(mydata));
|
|
||||||
sprintf(display_lmic, "PACKET QUEUED");
|
|
||||||
|
|
||||||
#ifdef HAS_GPS
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// clear counter if not in cumulative counter mode
|
// clear counter if not in cumulative counter mode
|
||||||
if (cfg.countermode != 1) {
|
if (cfg.countermode != 1) {
|
||||||
reset_counters(); // clear macs container and reset all counters
|
reset_counters(); // clear macs container and reset all counters
|
||||||
@ -189,64 +164,103 @@ void do_send(osjob_t *j) {
|
|||||||
|
|
||||||
} // do_send()
|
} // do_send()
|
||||||
|
|
||||||
void onEvent (ev_t ev) {
|
void onEvent(ev_t ev) {
|
||||||
char buff[24]="";
|
char buff[24] = "";
|
||||||
|
|
||||||
switch(ev) {
|
switch (ev) {
|
||||||
case EV_SCAN_TIMEOUT: strcpy_P(buff, PSTR("SCAN TIMEOUT")); break;
|
case EV_SCAN_TIMEOUT:
|
||||||
case EV_BEACON_FOUND: strcpy_P(buff, PSTR("BEACON FOUND")); break;
|
strcpy_P(buff, PSTR("SCAN TIMEOUT"));
|
||||||
case EV_BEACON_MISSED: strcpy_P(buff, PSTR("BEACON MISSED")); break;
|
break;
|
||||||
case EV_BEACON_TRACKED: strcpy_P(buff, PSTR("BEACON TRACKED")); break;
|
case EV_BEACON_FOUND:
|
||||||
case EV_JOINING: strcpy_P(buff, PSTR("JOINING")); break;
|
strcpy_P(buff, PSTR("BEACON FOUND"));
|
||||||
case EV_LOST_TSYNC: strcpy_P(buff, PSTR("LOST TSYNC")); break;
|
break;
|
||||||
case EV_RESET: strcpy_P(buff, PSTR("RESET")); break;
|
case EV_BEACON_MISSED:
|
||||||
case EV_RXCOMPLETE: strcpy_P(buff, PSTR("RX COMPLETE")); break;
|
strcpy_P(buff, PSTR("BEACON MISSED"));
|
||||||
case EV_LINK_DEAD: strcpy_P(buff, PSTR("LINK DEAD")); break;
|
break;
|
||||||
case EV_LINK_ALIVE: strcpy_P(buff, PSTR("LINK ALIVE")); break;
|
case EV_BEACON_TRACKED:
|
||||||
case EV_RFU1: strcpy_P(buff, PSTR("RFUI")); break;
|
strcpy_P(buff, PSTR("BEACON TRACKED"));
|
||||||
case EV_JOIN_FAILED: strcpy_P(buff, PSTR("JOIN FAILED")); break;
|
break;
|
||||||
case EV_REJOIN_FAILED: strcpy_P(buff, PSTR("REJOIN FAILED")); break;
|
case EV_JOINING:
|
||||||
|
strcpy_P(buff, PSTR("JOINING"));
|
||||||
|
break;
|
||||||
|
case EV_LOST_TSYNC:
|
||||||
|
strcpy_P(buff, PSTR("LOST TSYNC"));
|
||||||
|
break;
|
||||||
|
case EV_RESET:
|
||||||
|
strcpy_P(buff, PSTR("RESET"));
|
||||||
|
break;
|
||||||
|
case EV_RXCOMPLETE:
|
||||||
|
strcpy_P(buff, PSTR("RX COMPLETE"));
|
||||||
|
break;
|
||||||
|
case EV_LINK_DEAD:
|
||||||
|
strcpy_P(buff, PSTR("LINK DEAD"));
|
||||||
|
break;
|
||||||
|
case EV_LINK_ALIVE:
|
||||||
|
strcpy_P(buff, PSTR("LINK ALIVE"));
|
||||||
|
break;
|
||||||
|
case EV_RFU1:
|
||||||
|
strcpy_P(buff, PSTR("RFUI"));
|
||||||
|
break;
|
||||||
|
case EV_JOIN_FAILED:
|
||||||
|
strcpy_P(buff, PSTR("JOIN FAILED"));
|
||||||
|
break;
|
||||||
|
case EV_REJOIN_FAILED:
|
||||||
|
strcpy_P(buff, PSTR("REJOIN FAILED"));
|
||||||
|
break;
|
||||||
|
|
||||||
case EV_JOINED:
|
case EV_JOINED:
|
||||||
|
|
||||||
strcpy_P(buff, PSTR("JOINED"));
|
strcpy_P(buff, PSTR("JOINED"));
|
||||||
sprintf(display_lora, " "); // clear previous lmic status message from display
|
sprintf(display_lora,
|
||||||
|
" "); // clear previous lmic status message from display
|
||||||
|
|
||||||
// set data rate adaptation
|
// set data rate adaptation
|
||||||
LMIC_setAdrMode(cfg.adrmode);
|
LMIC_setAdrMode(cfg.adrmode);
|
||||||
// Set data rate and transmit power (note: txpower seems to be ignored by the library)
|
// Set data rate and transmit power (note: txpower seems to be ignored by
|
||||||
switch_lora(cfg.lorasf,cfg.txpower);
|
// the library)
|
||||||
|
switch_lora(cfg.lorasf, cfg.txpower);
|
||||||
|
|
||||||
// show effective LoRa parameters after join
|
// show effective LoRa parameters after join
|
||||||
ESP_LOGI(TAG, "ADR=%d, SF=%d, TXPOWER=%d", cfg.adrmode, cfg.lorasf, cfg.txpower);
|
ESP_LOGI(TAG, "ADR=%d, SF=%d, TXPOWER=%d", cfg.adrmode, cfg.lorasf,
|
||||||
|
cfg.txpower);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EV_TXCOMPLETE:
|
case EV_TXCOMPLETE:
|
||||||
|
|
||||||
strcpy_P(buff, (LMIC.txrxFlags & TXRX_ACK) ? PSTR("RECEIVED ACK") : PSTR("TX COMPLETE"));
|
strcpy_P(buff, (LMIC.txrxFlags & TXRX_ACK) ? PSTR("RECEIVED ACK")
|
||||||
sprintf(display_lora, " "); // clear previous lmic status message from display
|
: PSTR("TX COMPLETE"));
|
||||||
|
sprintf(display_lora,
|
||||||
|
" "); // clear previous lmic status message from display
|
||||||
|
|
||||||
if (LMIC.dataLen) {
|
if (LMIC.dataLen) {
|
||||||
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d", LMIC.dataLen, LMIC.rssi, (signed char)LMIC.snr / 4);
|
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d",
|
||||||
|
LMIC.dataLen, LMIC.rssi, (signed char)LMIC.snr / 4);
|
||||||
// LMIC.snr = SNR twos compliment [dB] * 4
|
// LMIC.snr = SNR twos compliment [dB] * 4
|
||||||
// LMIC.rssi = RSSI [dBm] (-196...+63)
|
// LMIC.rssi = RSSI [dBm] (-196...+63)
|
||||||
sprintf(display_lora, "RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4 );
|
sprintf(display_lora, "RSSI %d SNR %d", LMIC.rssi,
|
||||||
|
(signed char)LMIC.snr / 4);
|
||||||
|
|
||||||
// check if payload received on command port, then call remote command interpreter
|
// check if payload received on command port, then call remote command
|
||||||
if ( (LMIC.txrxFlags & TXRX_PORT) && (LMIC.frame[LMIC.dataBeg-1] == RCMDPORT ) ) {
|
// interpreter
|
||||||
// caution: buffering LMIC values here because rcommand() can modify LMIC.frame
|
if ((LMIC.txrxFlags & TXRX_PORT) &&
|
||||||
unsigned char* buffer = new unsigned char[MAX_LEN_FRAME];
|
(LMIC.frame[LMIC.dataBeg - 1] == RCMDPORT)) {
|
||||||
memcpy(buffer, LMIC.frame, MAX_LEN_FRAME); //Copy data from cfg to char*
|
// caution: buffering LMIC values here because rcommand() can modify
|
||||||
int i, k = LMIC.dataBeg, l = LMIC.dataBeg+LMIC.dataLen-2;
|
// LMIC.frame
|
||||||
for (i=k; i<=l; i+=2) {
|
unsigned char *buffer = new unsigned char[MAX_LEN_FRAME];
|
||||||
rcommand(buffer[i], buffer[i+1]);
|
memcpy(buffer, LMIC.frame, MAX_LEN_FRAME); // Copy data from cfg to
|
||||||
|
// char*
|
||||||
|
int i, k = LMIC.dataBeg, l = LMIC.dataBeg + LMIC.dataLen - 2;
|
||||||
|
for (i = k; i <= l; i += 2) {
|
||||||
|
rcommand(buffer[i], buffer[i + 1]);
|
||||||
}
|
}
|
||||||
delete[] buffer; //free memory
|
delete[] buffer; // free memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: sprintf_P(buff, PSTR("UNKNOWN EVENT %d"), ev); break;
|
default:
|
||||||
|
sprintf_P(buff, PSTR("UNKNOWN EVENT %d"), ev);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log & Display if asked
|
// Log & Display if asked
|
||||||
@ -256,4 +270,3 @@ void onEvent (ev_t ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // onEvent()
|
} // onEvent()
|
||||||
|
|
||||||
|
@ -37,12 +37,6 @@ void led_loop(void);
|
|||||||
|
|
||||||
//defined in gpsread.cpp
|
//defined in gpsread.cpp
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
<<<<<<< HEAD
|
|
||||||
void gps_read(void);
|
void gps_read(void);
|
||||||
void gps_loop(void *pvParameters);
|
void gps_loop(void *pvParameters);
|
||||||
#endif
|
#endif
|
||||||
=======
|
|
||||||
void gps_read(void);
|
|
||||||
void gps_loop(void * pvParameters);
|
|
||||||
#endif
|
|
||||||
>>>>>>> master
|
|
||||||
|
Loading…
Reference in New Issue
Block a user