code sanitizations
This commit is contained in:
		
							parent
							
								
									337fc64602
								
							
						
					
					
						commit
						fa11eba85c
					
				| @ -11,11 +11,11 @@ | |||||||
| 
 | 
 | ||||||
| ; ---> SELECT TARGET PLATFORM HERE! <--- | ; ---> SELECT TARGET PLATFORM HERE! <--- | ||||||
| [platformio] | [platformio] | ||||||
| ;env_default = generic | env_default = generic | ||||||
| ;env_default = heltec | ;env_default = heltec | ||||||
| ;env_default = ttgov1 | ;env_default = ttgov1 | ||||||
| ;env_default = ttgov2 | ;env_default = ttgov2 | ||||||
| env_default = ttgov21 | ;env_default = ttgov21 | ||||||
| ;env_default = ttgobeam | ;env_default = ttgobeam | ||||||
| ;env_default = lopy | ;env_default = lopy | ||||||
| ;env_default = lopy4 | ;env_default = lopy4 | ||||||
| @ -44,7 +44,7 @@ build_flags = | |||||||
| ; otherwise device may crash in dense environments due to serial buffer overflow | ; otherwise device may crash in dense environments due to serial buffer overflow | ||||||
| ; | ; | ||||||
| ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE | ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE | ||||||
| ;-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO |  -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO | ||||||
| ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG | ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG | ||||||
| ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE | ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE | ||||||
| ; | ; | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| #ifdef HAS_BUTTON | #ifdef HAS_BUTTON | ||||||
| 
 | 
 | ||||||
| #include "globals.h" | #include "globals.h" | ||||||
|  | #include "senddata.h" | ||||||
| 
 | 
 | ||||||
| // Local logging tag
 | // Local logging tag
 | ||||||
| static const char TAG[] = "main"; | static const char TAG[] = "main"; | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| #ifndef _BUTTON_H | #ifndef _BUTTON_H | ||||||
| #define _BUTTON_H | #define _BUTTON_H | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| void IRAM_ATTR ButtonIRQ(void); | void IRAM_ATTR ButtonIRQ(void); | ||||||
| void readButton(void); | void readButton(void); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -52,4 +52,28 @@ void IRAM_ATTR homeCycleIRQ() { | |||||||
|   portENTER_CRITICAL(&timerMux); |   portENTER_CRITICAL(&timerMux); | ||||||
|   HomeCycleIRQ++; |   HomeCycleIRQ++; | ||||||
|   portEXIT_CRITICAL(&timerMux); |   portEXIT_CRITICAL(&timerMux); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // uptime counter 64bit to prevent millis() rollover after 49 days
 | ||||||
|  | uint64_t uptime() { | ||||||
|  |   static uint32_t low32, high32; | ||||||
|  |   uint32_t new_low32 = millis(); | ||||||
|  |   if (new_low32 < low32) | ||||||
|  |     high32++; | ||||||
|  |   low32 = new_low32; | ||||||
|  |   return (uint64_t)high32 << 32 | low32; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void reset_counters() { | ||||||
|  |   macs.clear();   // clear all macs container
 | ||||||
|  |   macs_total = 0; // reset all counters
 | ||||||
|  |   macs_wifi = 0; | ||||||
|  |   macs_ble = 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #ifndef VERBOSE | ||||||
|  | int redirect_log(const char *fmt, va_list args) { | ||||||
|  |   // do nothing
 | ||||||
|  |   return 0; | ||||||
|  | } | ||||||
|  | #endif | ||||||
|  | |||||||
| @ -4,5 +4,8 @@ | |||||||
| void doHomework(void); | void doHomework(void); | ||||||
| void checkHousekeeping(void); | void checkHousekeeping(void); | ||||||
| void homeCycleIRQ(void); | void homeCycleIRQ(void); | ||||||
|  | uint64_t uptime(void); | ||||||
|  | void reset_counters(void); | ||||||
|  | int redirect_log(const char *fmt, va_list args); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
| @ -11,6 +11,15 @@ | |||||||
| // Local logging Tag
 | // Local logging Tag
 | ||||||
| static const char TAG[] = "lora"; | static const char TAG[] = "lora"; | ||||||
| 
 | 
 | ||||||
|  | // LMIC enhanced Pin mapping
 | ||||||
|  | const lmic_pinmap lmic_pins = {.mosi = PIN_SPI_MOSI, | ||||||
|  |                                .miso = PIN_SPI_MISO, | ||||||
|  |                                .sck = PIN_SPI_SCK, | ||||||
|  |                                .nss = PIN_SPI_SS, | ||||||
|  |                                .rxtx = LMIC_UNUSED_PIN, | ||||||
|  |                                .rst = RST, | ||||||
|  |                                .dio = {DIO0, DIO1, DIO2}}; | ||||||
|  | 
 | ||||||
| // DevEUI generator using devices's MAC address
 | // DevEUI generator using devices's MAC address
 | ||||||
| void gen_lora_deveui(uint8_t *pdeveui) { | void gen_lora_deveui(uint8_t *pdeveui) { | ||||||
|   uint8_t *p = pdeveui, dmac[6]; |   uint8_t *p = pdeveui, dmac[6]; | ||||||
| @ -231,4 +240,16 @@ void onEvent(ev_t ev) { | |||||||
| 
 | 
 | ||||||
| } // onEvent()
 | } // onEvent()
 | ||||||
| 
 | 
 | ||||||
|  | // LMIC FreeRTos Task
 | ||||||
|  | void lorawan_loop(void *pvParameters) { | ||||||
|  | 
 | ||||||
|  |   configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
 | ||||||
|  | 
 | ||||||
|  |   while (1) { | ||||||
|  |     os_runloop_once();                  // execute LMIC jobs
 | ||||||
|  |     vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
 | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| #endif // HAS_LORA
 | #endif // HAS_LORA
 | ||||||
| @ -14,5 +14,6 @@ void os_getDevKey(u1_t *buf); | |||||||
| void os_getArtEui(u1_t *buf); | void os_getArtEui(u1_t *buf); | ||||||
| void os_getDevEui(u1_t *buf); | void os_getDevEui(u1_t *buf); | ||||||
| void printKeys(void); | void printKeys(void); | ||||||
|  | void lorawan_loop(void *pvParameters); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
| @ -145,3 +145,25 @@ void IRAM_ATTR ChannelSwitchIRQ() { | |||||||
|   ChannelTimerIRQ++; |   ChannelTimerIRQ++; | ||||||
|   portEXIT_CRITICAL(&timerMux); |   portEXIT_CRITICAL(&timerMux); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // Wifi channel rotation task
 | ||||||
|  | void wifi_channel_loop(void *pvParameters) { | ||||||
|  | 
 | ||||||
|  |   configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
 | ||||||
|  | 
 | ||||||
|  |   while (1) { | ||||||
|  | 
 | ||||||
|  |     if (ChannelTimerIRQ) { | ||||||
|  |       portENTER_CRITICAL(&timerMux); | ||||||
|  |       ChannelTimerIRQ = 0; | ||||||
|  |       portEXIT_CRITICAL(&timerMux); | ||||||
|  |       // rotates variable channel 1..WIFI_CHANNEL_MAX
 | ||||||
|  |       channel = (channel % WIFI_CHANNEL_MAX) + 1; | ||||||
|  |       wifi_sniffer_set_channel(channel); | ||||||
|  |       ESP_LOGD(TAG, "Wifi set channel %d", channel); | ||||||
|  | 
 | ||||||
|  |       vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |   } // end of infinite wifi channel rotation loop
 | ||||||
|  | } | ||||||
| @ -32,5 +32,6 @@ void wifi_sniffer_set_channel(uint8_t channel); | |||||||
| void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); | void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); | ||||||
| bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); | bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); | ||||||
| void ChannelSwitchIRQ(void); | void ChannelSwitchIRQ(void); | ||||||
|  | void wifi_channel_loop(void *pvParameters); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
							
								
								
									
										99
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										99
									
								
								src/main.cpp
									
									
									
									
									
								
							| @ -54,82 +54,6 @@ PayloadConvert payload(PAYLOAD_BUFFER_SIZE); | |||||||
| // local Tag for logging
 | // local Tag for logging
 | ||||||
| static const char TAG[] = "main"; | static const char TAG[] = "main"; | ||||||
| 
 | 
 | ||||||
| #ifndef VERBOSE |  | ||||||
| int redirect_log(const char *fmt, va_list args) { |  | ||||||
|   // do nothing
 |  | ||||||
|   return 0; |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| void reset_counters() { |  | ||||||
|   macs.clear();   // clear all macs container
 |  | ||||||
|   macs_total = 0; // reset all counters
 |  | ||||||
|   macs_wifi = 0; |  | ||||||
|   macs_ble = 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #ifdef HAS_LORA |  | ||||||
| 
 |  | ||||||
| // LMIC enhanced Pin mapping
 |  | ||||||
| const lmic_pinmap lmic_pins = {.mosi = PIN_SPI_MOSI, |  | ||||||
|                                .miso = PIN_SPI_MISO, |  | ||||||
|                                .sck = PIN_SPI_SCK, |  | ||||||
|                                .nss = PIN_SPI_SS, |  | ||||||
|                                .rxtx = LMIC_UNUSED_PIN, |  | ||||||
|                                .rst = RST, |  | ||||||
|                                .dio = {DIO0, DIO1, DIO2}}; |  | ||||||
| 
 |  | ||||||
| // Get MCP 24AA02E64 hardware DEVEUI (override default settings if found)
 |  | ||||||
| #ifdef MCP_24AA02E64_I2C_ADDRESS |  | ||||||
| get_hard_deveui(buf); |  | ||||||
| RevBytes(buf, 8); // swap bytes to LSB format
 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| // LMIC FreeRTos Task
 |  | ||||||
| void lorawan_loop(void *pvParameters) { |  | ||||||
| 
 |  | ||||||
|   configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
 |  | ||||||
| 
 |  | ||||||
|   while (1) { |  | ||||||
|     os_runloop_once();                  // execute LMIC jobs
 |  | ||||||
|     vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
 |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #endif // HAS_LORA
 |  | ||||||
| 
 |  | ||||||
| // Wifi channel rotation task
 |  | ||||||
| void wifi_channel_loop(void *pvParameters) { |  | ||||||
| 
 |  | ||||||
|   configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
 |  | ||||||
| 
 |  | ||||||
|   while (1) { |  | ||||||
| 
 |  | ||||||
|     if (ChannelTimerIRQ) { |  | ||||||
|       portENTER_CRITICAL(&timerMux); |  | ||||||
|       ChannelTimerIRQ = 0; |  | ||||||
|       portEXIT_CRITICAL(&timerMux); |  | ||||||
|       // rotates variable channel 1..WIFI_CHANNEL_MAX
 |  | ||||||
|       channel = (channel % WIFI_CHANNEL_MAX) + 1; |  | ||||||
|       wifi_sniffer_set_channel(channel); |  | ||||||
|       ESP_LOGD(TAG, "Wifi set channel %d", channel); |  | ||||||
| 
 |  | ||||||
|       vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
 |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|   } // end of infinite wifi channel rotation loop
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // uptime counter 64bit to prevent millis() rollover after 49 days
 |  | ||||||
| uint64_t uptime() { |  | ||||||
|   static uint32_t low32, high32; |  | ||||||
|   uint32_t new_low32 = millis(); |  | ||||||
|   if (new_low32 < low32) |  | ||||||
|     high32++; |  | ||||||
|   low32 = new_low32; |  | ||||||
|   return (uint64_t)high32 << 32 | low32; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /* begin Aruino SETUP
 | /* begin Aruino SETUP
 | ||||||
|  * ------------------------------------------------------------ */ |  * ------------------------------------------------------------ */ | ||||||
| 
 | 
 | ||||||
| @ -183,7 +107,12 @@ void setup() { | |||||||
|   // read settings from NVRAM
 |   // read settings from NVRAM
 | ||||||
|   loadConfig(); // includes initialize if necessary
 |   loadConfig(); // includes initialize if necessary
 | ||||||
| 
 | 
 | ||||||
|   // initialize led if needed
 | // initialize LoRa
 | ||||||
|  | #if HAS_LORA | ||||||
|  |   strcat_P(features, "LORA"); | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |   // initialize led
 | ||||||
| #if (HAS_LED != NOT_A_PIN) | #if (HAS_LED != NOT_A_PIN) | ||||||
|   pinMode(HAS_LED, OUTPUT); |   pinMode(HAS_LED, OUTPUT); | ||||||
|   strcat_P(features, " LED"); |   strcat_P(features, " LED"); | ||||||
| @ -194,7 +123,7 @@ void setup() { | |||||||
|   strcat_P(features, " RGB"); |   strcat_P(features, " RGB"); | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|   // initialize button handling if needed
 |   // initialize button
 | ||||||
| #ifdef HAS_BUTTON | #ifdef HAS_BUTTON | ||||||
|   strcat_P(features, " BTN_"); |   strcat_P(features, " BTN_"); | ||||||
| #ifdef BUTTON_PULLUP | #ifdef BUTTON_PULLUP | ||||||
| @ -210,7 +139,7 @@ void setup() { | |||||||
| #endif // BUTTON_PULLUP
 | #endif // BUTTON_PULLUP
 | ||||||
| #endif // HAS_BUTTON
 | #endif // HAS_BUTTON
 | ||||||
| 
 | 
 | ||||||
|   // initialize wifi antenna if needed
 |   // initialize wifi antenna
 | ||||||
| #ifdef HAS_ANTENNA_SWITCH | #ifdef HAS_ANTENNA_SWITCH | ||||||
|   strcat_P(features, " ANT"); |   strcat_P(features, " ANT"); | ||||||
|   antenna_init(); |   antenna_init(); | ||||||
| @ -224,19 +153,19 @@ void setup() { | |||||||
|   bool btstop = btStop(); |   bool btstop = btStop(); | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| // initialize gps if present
 | // initialize gps
 | ||||||
| #ifdef HAS_GPS | #ifdef HAS_GPS | ||||||
|   strcat_P(features, " GPS"); |   strcat_P(features, " GPS"); | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| // initialize battery status if present
 | // initialize battery status
 | ||||||
| #ifdef HAS_BATTERY_PROBE | #ifdef HAS_BATTERY_PROBE | ||||||
|   strcat_P(features, " BATT"); |   strcat_P(features, " BATT"); | ||||||
|   calibrate_voltage(); |   calibrate_voltage(); | ||||||
|   batt_voltage = read_voltage(); |   batt_voltage = read_voltage(); | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| // initialize display if present
 | // initialize display
 | ||||||
| #ifdef HAS_DISPLAY | #ifdef HAS_DISPLAY | ||||||
|   strcat_P(features, " OLED"); |   strcat_P(features, " OLED"); | ||||||
|   DisplayState = cfg.screenon; |   DisplayState = cfg.screenon; | ||||||
| @ -288,7 +217,6 @@ void setup() { | |||||||
|   ESP_LOGI(TAG, "Features: %s", features); |   ESP_LOGI(TAG, "Features: %s", features); | ||||||
| 
 | 
 | ||||||
| #ifdef HAS_LORA | #ifdef HAS_LORA | ||||||
| 
 |  | ||||||
|   // output LoRaWAN keys to console
 |   // output LoRaWAN keys to console
 | ||||||
| #ifdef VERBOSE | #ifdef VERBOSE | ||||||
|   printKeys(); |   printKeys(); | ||||||
| @ -351,8 +279,7 @@ void setup() { | |||||||
| void loop() { | void loop() { | ||||||
| 
 | 
 | ||||||
|   while (1) { |   while (1) { | ||||||
| 
 |     // state machine for switching display, LED, button, housekeeping, senddata
 | ||||||
|     // state machine for uptime, display, LED, button, lowmemory, senddata
 |  | ||||||
| 
 | 
 | ||||||
| #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED) | #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED) | ||||||
|     led_loop(); |     led_loop(); | ||||||
| @ -368,10 +295,8 @@ void loop() { | |||||||
| 
 | 
 | ||||||
|     // check housekeeping cycle and to homework if expired
 |     // check housekeeping cycle and to homework if expired
 | ||||||
|     checkHousekeeping(); |     checkHousekeeping(); | ||||||
| 
 |  | ||||||
|     // check send cycle and send payload if cycle is expired
 |     // check send cycle and send payload if cycle is expired
 | ||||||
|     sendPayload(); |     sendPayload(); | ||||||
| 
 |  | ||||||
|     vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
 |     vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
 | ||||||
| 
 | 
 | ||||||
|   } // end of infinite main loop
 |   } // end of infinite main loop
 | ||||||
|  | |||||||
| @ -12,9 +12,4 @@ | |||||||
| 
 | 
 | ||||||
| #include <TimeLib.h> | #include <TimeLib.h> | ||||||
| 
 | 
 | ||||||
| void reset_counters(void); |  | ||||||
| void blink_LED(uint16_t set_color, uint16_t set_blinkduration); |  | ||||||
| void led_loop(void); |  | ||||||
| uint64_t uptime(); |  | ||||||
| 
 |  | ||||||
| #endif | #endif | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user