prepare LMIC battlevel MAC request

This commit is contained in:
Klaus K Wilting 2020-04-10 23:26:29 +02:00
parent a6cbc2479e
commit 90a004ec79
4 changed files with 30 additions and 26 deletions

View File

@ -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);

View File

@ -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

View File

@ -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) {

View File

@ -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;
}