Tryout for on demand switching between BLE and Wifi counting in libpax
This commit is contained in:
		
							parent
							
								
									3f3027aa69
								
							
						
					
					
						commit
						93dcace8bd
					
				
							
								
								
									
										10
									
								
								include/libpax_helpers.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								include/libpax_helpers.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					#ifndef _LIBPAX_HELPERS_H
 | 
				
			||||||
 | 
					#define _LIBPAX_HELPERS_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "globals.h"
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <libpax_api.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void init_libpax();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										18
									
								
								src/libpax_helpers.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/libpax_helpers.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					#include "libpax_helpers.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// libpax payload
 | 
				
			||||||
 | 
					#ifdef LIBPAX
 | 
				
			||||||
 | 
					struct count_payload_t count_from_libpax;
 | 
				
			||||||
 | 
					uint16_t volatile libpax_macs_ble, libpax_macs_wifi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void process_count(void) {
 | 
				
			||||||
 | 
					  printf("pax: %d; %d; %d;\n", count_from_libpax.pax, count_from_libpax.wifi_count, count_from_libpax.ble_count);
 | 
				
			||||||
 | 
					  libpax_macs_ble = count_from_libpax.ble_count;
 | 
				
			||||||
 | 
					  libpax_macs_wifi = count_from_libpax.wifi_count;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void init_libpax() {
 | 
				
			||||||
 | 
					      libpax_counter_init(process_count, &count_from_libpax, 60*1000, 1); 
 | 
				
			||||||
 | 
					      libpax_counter_start();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										16
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/main.cpp
									
									
									
									
									
								
							@ -86,6 +86,7 @@ triggers pps 1 sec impulse
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Basic Config
 | 
					// Basic Config
 | 
				
			||||||
#include "main.h"
 | 
					#include "main.h"
 | 
				
			||||||
 | 
					#include "libpax_helpers.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
configData_t cfg; // struct holds current device configuration
 | 
					configData_t cfg; // struct holds current device configuration
 | 
				
			||||||
char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message
 | 
					char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message
 | 
				
			||||||
@ -96,8 +97,6 @@ uint8_t volatile channel = WIFI_CHANNEL_MIN;   // channel rotation counter
 | 
				
			|||||||
uint8_t volatile rf_load = 0;                  // RF traffic indicator
 | 
					uint8_t volatile rf_load = 0;                  // RF traffic indicator
 | 
				
			||||||
#ifndef LIBPAX
 | 
					#ifndef LIBPAX
 | 
				
			||||||
uint16_t volatile macs_wifi = 0, macs_ble = 0; // globals for display
 | 
					uint16_t volatile macs_wifi = 0, macs_ble = 0; // globals for display
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
uint16_t volatile libpax_macs_ble, libpax_macs_wifi;
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL;
 | 
					hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL;
 | 
				
			||||||
@ -119,16 +118,6 @@ TimeChangeRule myDST = DAYLIGHT_TIME;
 | 
				
			|||||||
TimeChangeRule mySTD = STANDARD_TIME;
 | 
					TimeChangeRule mySTD = STANDARD_TIME;
 | 
				
			||||||
Timezone myTZ(myDST, mySTD);
 | 
					Timezone myTZ(myDST, mySTD);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// libpax payload
 | 
					 | 
				
			||||||
#ifdef LIBPAX
 | 
					 | 
				
			||||||
struct count_payload_t count_from_libpax;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void process_count(void) {
 | 
					 | 
				
			||||||
  printf("pax: %d; %d; %d;\n", count_from_libpax.pax, count_from_libpax.wifi_count, count_from_libpax.ble_count);
 | 
					 | 
				
			||||||
  libpax_macs_ble = count_from_libpax.ble_count;
 | 
					 | 
				
			||||||
  libpax_macs_wifi = count_from_libpax.wifi_count;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// local Tag for logging
 | 
					// local Tag for logging
 | 
				
			||||||
static const char TAG[] = __FILE__;
 | 
					static const char TAG[] = __FILE__;
 | 
				
			||||||
@ -340,8 +329,7 @@ ESP_LOGI(TAG, "Starting libpax...");
 | 
				
			|||||||
    if(config_update != 0) {
 | 
					    if(config_update != 0) {
 | 
				
			||||||
      ESP_LOGE(TAG, "Error in libpax configuration.");
 | 
					      ESP_LOGE(TAG, "Error in libpax configuration.");
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      libpax_counter_init(process_count, &count_from_libpax, 60*1000, 1); 
 | 
					      init_libpax();
 | 
				
			||||||
      libpax_counter_start();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    ESP_LOGE(TAG, "Error in libpax configuration: Wifi and BLE are not supported at the same time!");
 | 
					    ESP_LOGE(TAG, "Error in libpax configuration: Wifi and BLE are not supported at the same time!");
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
// Basic Config
 | 
					// Basic Config
 | 
				
			||||||
#include "globals.h"
 | 
					#include "globals.h"
 | 
				
			||||||
#include "rcommand.h"
 | 
					#include "rcommand.h"
 | 
				
			||||||
 | 
					#include "libpax_helpers.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Local logging tag
 | 
					// Local logging tag
 | 
				
			||||||
static const char TAG[] = __FILE__;
 | 
					static const char TAG[] = __FILE__;
 | 
				
			||||||
@ -248,27 +249,47 @@ void set_loraadr(uint8_t val[]) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void set_blescan(uint8_t val[]) {
 | 
					void set_blescan(uint8_t val[]) {
 | 
				
			||||||
  ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off");
 | 
					  ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off");
 | 
				
			||||||
 | 
					  cfg.blescan = val[0] ? 1 : 0;
 | 
				
			||||||
  #ifndef LIBPAX
 | 
					  #ifndef LIBPAX
 | 
				
			||||||
  macs_ble = 0; // clear BLE counter
 | 
					  macs_ble = 0; // clear BLE counter
 | 
				
			||||||
  cfg.blescan = val[0] ? 1 : 0;
 | 
					 | 
				
			||||||
  if (cfg.blescan)
 | 
					  if (cfg.blescan)
 | 
				
			||||||
    start_BLEscan();
 | 
					    start_BLEscan();
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    stop_BLEscan();
 | 
					    stop_BLEscan();
 | 
				
			||||||
  #else
 | 
					  #else
 | 
				
			||||||
  // TODO update libpax configuration
 | 
					  if(cfg.blescan) {
 | 
				
			||||||
 | 
					    cfg.wifiscan = 0;
 | 
				
			||||||
 | 
					    // Restart of libpax while switching scannings does not work atm
 | 
				
			||||||
 | 
					    // libpax_counter_stop();
 | 
				
			||||||
 | 
					    // libpax_config_t current_config;
 | 
				
			||||||
 | 
					    // libpax_get_current_config(¤t_config);
 | 
				
			||||||
 | 
					    // current_config.wificounter = 0;
 | 
				
			||||||
 | 
					    // current_config.blecounter = 1;
 | 
				
			||||||
 | 
					    // libpax_update_config(¤t_config);
 | 
				
			||||||
 | 
					    // init_libpax();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  #endif 
 | 
					  #endif 
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void set_wifiscan(uint8_t val[]) {
 | 
					void set_wifiscan(uint8_t val[]) {
 | 
				
			||||||
  ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s",
 | 
					  ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s",
 | 
				
			||||||
           val[0] ? "on" : "off");
 | 
					           val[0] ? "on" : "off");
 | 
				
			||||||
 | 
					  cfg.wifiscan = val[0] ? 1 : 0;
 | 
				
			||||||
  #ifndef LIBPAX
 | 
					  #ifndef LIBPAX
 | 
				
			||||||
  macs_wifi = 0; // clear WIFI counter
 | 
					  macs_wifi = 0; // clear WIFI counter
 | 
				
			||||||
  cfg.wifiscan = val[0] ? 1 : 0;
 | 
					 | 
				
			||||||
  switch_wifi_sniffer(cfg.wifiscan);
 | 
					  switch_wifi_sniffer(cfg.wifiscan);
 | 
				
			||||||
  #else
 | 
					  #else
 | 
				
			||||||
  // TODO update libpax configuration
 | 
					  if(cfg.wifiscan) {
 | 
				
			||||||
 | 
					    cfg.blescan = 0;
 | 
				
			||||||
 | 
					    // Restart of libpax while switching scannings does not work atm
 | 
				
			||||||
 | 
					    // libpax_counter_stop();
 | 
				
			||||||
 | 
					    // libpax_config_t current_config;
 | 
				
			||||||
 | 
					    // libpax_get_current_config(¤t_config);
 | 
				
			||||||
 | 
					    // current_config.wificounter = 1;
 | 
				
			||||||
 | 
					    // current_config.blecounter = 0;
 | 
				
			||||||
 | 
					    // libpax_update_config(¤t_config);
 | 
				
			||||||
 | 
					    // init_libpax();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  #endif 
 | 
					  #endif 
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user