prepare LMIC battlevel MAC request
This commit is contained in:
parent
a6cbc2479e
commit
90a004ec79
@ -11,6 +11,10 @@
|
||||
#define DEFAULT_VREF 1100 // tbd: use adc2_vref_to_gpio() for better estimate
|
||||
#define NO_OF_SAMPLES 64 // we do some multisampling to get better values
|
||||
|
||||
#ifndef BAT_MAX_VOLTAGE
|
||||
#define BAT_MAX_VOLTAGE 4100 // millivolts
|
||||
#endif
|
||||
|
||||
uint16_t read_voltage(void);
|
||||
void calibrate_voltage(void);
|
||||
bool batt_sufficient(void);
|
||||
|
@ -104,3 +104,6 @@
|
||||
#define USE_IDEETRON_AES
|
||||
//
|
||||
//#define USE_MBEDTLS_AES
|
||||
|
||||
// Define this for devices with external power.
|
||||
//#define LMIC_MCMD_DEVS_BATT_DEFAULT MCMD_DEVS_EXT_POWER
|
@ -538,32 +538,6 @@ const char *getCrName(rps_t rps) {
|
||||
return t[getCr(rps)];
|
||||
}
|
||||
|
||||
/*
|
||||
u1_t os_getBattLevel() {
|
||||
|
||||
//return values:
|
||||
//MCMD_DEVS_EXT_POWER = 0x00, // external power supply
|
||||
//MCMD_DEVS_BATT_MIN = 0x01, // min battery value
|
||||
//MCMD_DEVS_BATT_MAX = 0xFE, // max battery value
|
||||
//MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level
|
||||
|
||||
#if (defined HAS_PMU || defined BAT_MEASURE_ADC)
|
||||
uint16_t voltage = read_voltage();
|
||||
|
||||
switch (voltage) {
|
||||
case 0:
|
||||
return MCMD_DEVS_BATT_NOINFO;
|
||||
case 0xffff:
|
||||
return MCMD_DEVS_EXT_POWER;
|
||||
default:
|
||||
return (voltage > OTA_MIN_BATT ? MCMD_DEVS_BATT_MAX : MCMD_DEVS_BATT_MIN);
|
||||
}
|
||||
#else // we don't have any info on battery level
|
||||
return MCMD_DEVS_BATT_NOINFO;
|
||||
#endif
|
||||
} // getBattLevel()
|
||||
*/
|
||||
|
||||
#if (VERBOSE)
|
||||
// decode LORAWAN MAC message
|
||||
void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, bool is_down) {
|
||||
|
@ -217,5 +217,28 @@ uint16_t read_voltage() {
|
||||
|
||||
#endif // HAS_PMU
|
||||
|
||||
/*
|
||||
// set battery level value for lmic stack
|
||||
#if (HAS_LORA)
|
||||
// Sets the battery level returned in MAC Command DevStatusAns.
|
||||
// Available defines in lorabase.h:
|
||||
// MCMD_DEVS_EXT_POWER = 0x00, // external power supply
|
||||
// MCMD_DEVS_BATT_MIN = 0x01, // min battery value
|
||||
// MCMD_DEVS_BATT_MAX = 0xFE, // max battery value
|
||||
// MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level
|
||||
// When setting the battery level calculate the applicable
|
||||
// value from MCMD_DEVS_BATT_MIN to MCMD_DEVS_BATT_MAX.
|
||||
|
||||
// external power
|
||||
if (voltage == 0xffff)
|
||||
LMIC_setBattLevel(MCMD_DEVS_EXT_POWER);
|
||||
// scale battery millivolts to lmic battlevel
|
||||
else
|
||||
LMIC_setBattLevel(voltage / BAT_MAX_VOLTAGE *
|
||||
(MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1));
|
||||
|
||||
#endif // (HAS_LORA)
|
||||
*/
|
||||
|
||||
return voltage;
|
||||
}
|
Loading…
Reference in New Issue
Block a user