Code optimization

This commit is contained in:
Charles 2018-04-05 14:34:39 +02:00
parent 114651d8c0
commit a37a567ab2

View File

@ -10,8 +10,6 @@
#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
uint8_t mydata[] = "0000";
// Local logging Tag // Local logging Tag
static const char *TAG = "lorawan"; static const char *TAG = "lorawan";
@ -113,6 +111,7 @@ void printKeys(void) {
#endif // VERBOSE #endif // VERBOSE
void do_send(osjob_t* j){ void do_send(osjob_t* j){
uint8_t mydata[4];
uint16_t data; uint16_t data;
// Total BLE+WIFI unique MACs seen // Total BLE+WIFI unique MACs seen
data = (uint16_t) macs.size(); data = (uint16_t) macs.size();
@ -131,52 +130,40 @@ void do_send(osjob_t* j){
//mydata[5] = data & 0xff; //mydata[5] = data & 0xff;
// Check if there is not a current TX/RX job running // Check if there is not a current TX/RX job running
u8x8.clearLine(7);
if (LMIC.opmode & OP_TXRXPEND) { if (LMIC.opmode & OP_TXRXPEND) {
ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); ESP_LOGI(TAG, "OP_TXRXPEND, not sending");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "LORA BUSY"); u8x8.drawString(0, 7, "LORA BUSY");
} else { } else {
// Prepare upstream data transmission at the next possible time. // Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, (cfg.countermode & 0x02)); LMIC_setTxData2(1, mydata, sizeof(mydata), (cfg.countermode & 0x02));
ESP_LOGI(TAG, "Packet queued"); ESP_LOGI(TAG, "Packet queued");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "PACKET QUEUED"); u8x8.drawString(0, 7, "PACKET QUEUED");
} }
// Next TX is scheduled after TX_COMPLETE event. // Next TX is scheduled after TX_COMPLETE event.
} }
void onEvent (ev_t ev) { void onEvent (ev_t ev) {
char buff[24]="";
switch(ev) { switch(ev) {
case EV_SCAN_TIMEOUT: case EV_SCAN_TIMEOUT: strcpy_P(buff, PSTR("SCAN TIMEOUT")); break;
ESP_LOGI(TAG, "EV_SCAN_TIMEOUT"); case EV_BEACON_FOUND: strcpy_P(buff, PSTR("BEACON FOUND")); break;
u8x8.clearLine(7); case EV_BEACON_MISSED: strcpy_P(buff, PSTR( "BEACON MISSED")); break;
u8x8.drawString(0, 7, "SCAN TIMEOUT"); case EV_BEACON_TRACKED: strcpy_P(buff, PSTR("BEACON TRACKED")); break;
break; case EV_JOINING: strcpy_P(buff, PSTR("JOINING")); break;
case EV_BEACON_FOUND: case EV_LOST_TSYNC: strcpy_P(buff, PSTR("LOST TSYNC")); break;
ESP_LOGI(TAG, "EV_BEACON_FOUND"); case EV_RESET: strcpy_P(buff, PSTR("RESET")); break;
u8x8.clearLine(7); case EV_RXCOMPLETE: strcpy_P(buff, PSTR("RX COMPLETE")); break;
u8x8.drawString(0, 7, "BEACON FOUND"); 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_MISSED: case EV_RFU1: strcpy_P(buff, PSTR("RFUI")); break;
ESP_LOGI(TAG, "EV_BEACON_MISSED"); case EV_JOIN_FAILED: strcpy_P(buff, PSTR("JOIN FAILED")); break;
u8x8.clearLine(7); case EV_REJOIN_FAILED: strcpy_P(buff, PSTR("REJOIN FAILED")); break;
u8x8.drawString(0, 7, "BEACON MISSED");
break;
case EV_BEACON_TRACKED:
ESP_LOGI(TAG, "EV_BEACON_TRACKED");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "BEACON TRACKED");
break;
case EV_JOINING:
ESP_LOGI(TAG, "EV_JOINING");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "JOINING");
break;
case EV_JOINED: case EV_JOINED:
ESP_LOGI(TAG, "EV_JOINED"); strcpy_P(buff, PSTR("JOINED"));
u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp
u8x8.clearLine(7);
u8x8.drawString(0, 7, "JOINED");
// Disable link check validation (automatically enabled // Disable link check validation (automatically enabled
// during join, but not supported by TTN at this time). // during join, but not supported by TTN at this time).
LMIC_setLinkCheckMode(0); LMIC_setLinkCheckMode(0);
@ -188,35 +175,20 @@ void onEvent (ev_t ev) {
// show effective LoRa parameters after join // show effective LoRa parameters after join
ESP_LOGI(TAG, "ADR=%i, SF=%i, TXPOWER=%i", cfg.adrmode, cfg.lorasf, cfg.txpower); ESP_LOGI(TAG, "ADR=%i, SF=%i, TXPOWER=%i", cfg.adrmode, cfg.lorasf, cfg.txpower);
break; break;
case EV_RFU1:
ESP_LOGI(TAG, "EV_RFU1");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "RFUI");
break;
case EV_JOIN_FAILED:
ESP_LOGI(TAG, "EV_JOIN_FAILED");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "JOIN FAILED");
break;
case EV_REJOIN_FAILED:
ESP_LOGI(TAG, "EV_REJOIN_FAILED");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "REJOIN FAILED");
break;
case EV_TXCOMPLETE: case EV_TXCOMPLETE:
ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)"); ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)");
u8x8.clearLine(7); u8x8.clearLine(7);
u8x8.drawString(0, 7, "TX COMPLETE");
if (LMIC.txrxFlags & TXRX_ACK) { if (LMIC.txrxFlags & TXRX_ACK) {
ESP_LOGI(TAG, "Received ack"); ESP_LOGI(TAG, "Received ack");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "RECEIVED ACK"); u8x8.drawString(0, 7, "RECEIVED ACK");
} } else {
u8x8.drawString(0, 7, "TX COMPLETE");
}
if (LMIC.dataLen) { if (LMIC.dataLen) {
ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen); ESP_LOGI(TAG, "Received %d bytes of payload", LMIC.dataLen);
u8x8.clearLine(6); u8x8.clearLine(6);
u8x8.setCursor(0, 6); u8x8.setCursor(0, 6);
u8x8.printf("Rcvd %i bytes", LMIC.dataLen); u8x8.printf("Rcvd %d bytes", LMIC.dataLen);
u8x8.clearLine(7); u8x8.clearLine(7);
u8x8.setCursor(0, 7); u8x8.setCursor(0, 7);
// LMIC.snr = SNR twos compliment [dB] * 4 // LMIC.snr = SNR twos compliment [dB] * 4
@ -234,38 +206,16 @@ void onEvent (ev_t ev) {
} }
} }
break; break;
case EV_LOST_TSYNC: default: sprintf_P(buff, PSTR("UNKNOWN EVENT %d"), ev); break;
ESP_LOGI(TAG, "EV_LOST_TSYNC");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "LOST TSYNC");
break;
case EV_RESET:
ESP_LOGI(TAG, "EV_RESET");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "RESET");
break;
case EV_RXCOMPLETE:
// data received in ping slot
ESP_LOGI(TAG, "EV_RXCOMPLETE");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "RX COMPLETE");
break;
case EV_LINK_DEAD:
ESP_LOGI(TAG, "EV_LINK_DEAD");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "LINK DEAD");
break;
case EV_LINK_ALIVE:
ESP_LOGI(TAG, "EV_LINK_ALIVE");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "LINK ALIVE");
break;
default:
ESP_LOGI(TAG, "Unknown event");
u8x8.clearLine(7);
u8x8.setCursor(0, 7);
u8x8.printf("UNKNOWN EVENT %d", ev);
break;
} }
// Log & Display if asked
if (*buff) {
ESP_LOGI(TAG, "EV_%s", buff);
u8x8.clearLine(7);
u8x8.drawString(0, 7, buff);
}
} }