From a47cf1517a41100cf817fdf3cb11f95046e2ab24 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 12 Jun 2018 12:52:48 +0200 Subject: [PATCH] v1.3.81 --- src/lorawan.cpp | 315 +++++++++++++++++++++++++----------------------- src/main.h | 6 - 2 files changed, 164 insertions(+), 157 deletions(-) diff --git a/src/lorawan.cpp b/src/lorawan.cpp index b35532ac..05661981 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -7,7 +7,7 @@ #include #ifdef MCP_24AA02E64_I2C_ADDRESS - #include // Needed for 24AA02E64, does not hurt anything if included and not used +#include // Needed for 24AA02E64, does not hurt anything if included and not used #endif // Local logging Tag @@ -19,88 +19,88 @@ void switch_lora(uint8_t sf, uint8_t tx); // DevEUI generator using devices's MAC address void gen_lora_deveui(uint8_t *pdeveui) { - uint8_t *p = pdeveui, dmac[6]; - int i = 0; - esp_efuse_mac_get_default(dmac); - // deveui is LSB, we reverse it so TTN DEVEUI display - // will remain the same as MAC address - // MAC is 6 bytes, devEUI 8, set first 2 ones - // with an arbitrary value - *p++ = 0xFF; - *p++ = 0xFE; - // Then next 6 bytes are mac address reversed - for ( i=0; i<6 ; i++) { - *p++ = dmac[5-i]; - } + uint8_t *p = pdeveui, dmac[6]; + int i = 0; + esp_efuse_mac_get_default(dmac); + // deveui is LSB, we reverse it so TTN DEVEUI display + // will remain the same as MAC address + // MAC is 6 bytes, devEUI 8, set first 2 ones + // with an arbitrary value + *p++ = 0xFF; + *p++ = 0xFE; + // Then next 6 bytes are mac address reversed + for (i = 0; i < 6; i++) { + *p++ = dmac[5 - i]; + } } // 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; - for (i = 0; i < c / 2; i++) - { unsigned char t = b[i]; + for (i = 0; i < c / 2; i++) { + unsigned char t = b[i]; b[i] = b[c - 1 - i]; - b[c - 1 - i] = t; } + b[c - 1 - i] = t; + } } void get_hard_deveui(uint8_t *pdeveui) { - // read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present + // read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present #ifdef MCP_24AA02E64_I2C_ADDRESS - uint8_t i2c_ret; - // Init this just in case, no more to 100KHz - Wire.begin(OLED_SDA, OLED_SCL, 100000); + uint8_t i2c_ret; + // Init this just in case, no more to 100KHz + Wire.begin(OLED_SDA, OLED_SCL, 100000); + Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS); + Wire.write(MCP_24AA02E64_MAC_ADDRESS); + i2c_ret = Wire.endTransmission(); + // check if device seen on i2c bus + if (i2c_ret == 0) { + char deveui[32] = ""; + uint8_t data; Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS); - Wire.write(MCP_24AA02E64_MAC_ADDRESS); - i2c_ret = Wire.endTransmission(); - // check if device seen on i2c bus - if (i2c_ret == 0) { - char deveui[32]=""; - uint8_t data; - Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS); - Wire.write(MCP_24AA02E64_MAC_ADDRESS); - Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8); - while (Wire.available()) { - data = Wire.read(); - sprintf(deveui+strlen(deveui), "%02X ", data); - *pdeveui++ = data; - } - i2c_ret = Wire.endTransmission(); - ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 found, read DEVEUI %s", deveui); - } else { - ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 not found ret=%d", i2c_ret); + Wire.write(MCP_24AA02E64_MAC_ADDRESS); + Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8); + while (Wire.available()) { + data = Wire.read(); + sprintf(deveui + strlen(deveui), "%02X ", data); + *pdeveui++ = data; } - // Set back to 400KHz to speed up OLED - Wire.setClock(400000); -#endif // MCP 24AA02E64 + i2c_ret = Wire.endTransmission(); + ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 found, read DEVEUI %s", deveui); + } else { + ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 not found ret=%d", i2c_ret); + } + // Set back to 400KHz to speed up OLED + Wire.setClock(400000); +#endif // MCP 24AA02E64 } #ifdef VERBOSE // Display a key -void printKey(const char * name, const uint8_t * key, uint8_t len, bool lsb) { - const uint8_t * p ; - char keystring[len+1] = "", keybyte[3]; - for (uint8_t i=0; i>>>>>> master