Skip to content

Commit 95cb89d

Browse files
committed
Fix #576: add DevStatusAns battery APIs; v4.1.0-pre1
1 parent 5e5a597 commit 95cb89d

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ function uflt12f(rawUflt12)
12481248
- Warn about Feather pin wiring requirements ([#755](https://github.com/mcci-catena/arduino-lmic/issues/755), thanks to [@d-a-v](https://github.com/d-a-v)).
12491249
- Fix typos in this document ([#780](https://github.com/mcci-catena/arduino-lmic/issues/780), thanks [@PeeJay](https://github.com/PeeJay)).
12501250
- Fix additional warnings on non-ARM platforms ([#791](https://github.com/mcci-catena/arduino-lmic/issues/791), thanks [@d-a-v](https://github.com/d-a-v)).
1251+
- Allow application to set the value to be used in `DeviceStatusAns` MAC messages ([#576](https://github.com/mcci-catena/arduino-lmic/issues/576) and [#560](https://github.com/mcci-catena/arduino-lmic/issues/560), thanks to [@altishchenko](https://github.com/altishchenko)).
12511252

12521253
- v4.0 is a major release; changes are significant enough to be "likely breaking". It includes the following changes.
12531254

src/lmic/lmic.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void os_wmsbf4 (xref2u1_t buf, u4_t v) {
119119

120120
#if !defined(os_getBattLevel)
121121
u1_t os_getBattLevel (void) {
122-
return MCMD_DEVS_BATT_NOINFO;
122+
return LMIC.client.devStatusAns_battery;
123123
}
124124
#endif
125125

@@ -2815,6 +2815,7 @@ void LMIC_reset (void) {
28152815

28162816
void LMIC_init (void) {
28172817
LMIC.opmode = OP_SHUTDOWN;
2818+
LMIC.client.devStatusAns_battery = MCMD_DEVS_BATT_NOINFO;
28182819
LMICbandplan_init();
28192820
}
28202821

@@ -3102,3 +3103,47 @@ int LMIC_getNetworkTimeReference(lmic_time_reference_t *pReference) {
31023103
#endif // LMIC_ENABLE_DeviceTimeReq
31033104
return 0;
31043105
}
3106+
3107+
///
3108+
/// \brief set battery level to be returned by `DevStatusAns`.
3109+
///
3110+
/// \param uBattLevel is the 8-bit value to be returned. Per LoRaWAN 1.0.3 line 769,
3111+
/// this is \c MCMD_DEVS_EXT_POWER (0) if on external power,
3112+
/// \c MCMD_DEVS_NOINFO (255) if not able to measure battery level,
3113+
/// or a value in [ \c MCMD_DEVS_BATT_MIN, \c MCMD_DEVS_BATT_MAX ], numerically
3114+
/// [1, 254], to represent the charge state of the battery. Note that
3115+
/// this is not millivolts.
3116+
///
3117+
/// \returns
3118+
/// This function returns the previous value of the battery level.
3119+
///
3120+
/// \details
3121+
/// The LMIC maintains an idea of the current battery state, initially set to
3122+
/// \c MCMD_DEVS_NOINFO after the call to LMIC_init(). The appplication then calls
3123+
/// this function from time to time to update the battery level.
3124+
///
3125+
/// It is possible (in non-Arduino environments) to supply a local implementation
3126+
/// of os_getBatteryLevel(). In that case, it's up to the implementation to decide
3127+
/// whether to use the value supplied by this API.
3128+
///
3129+
/// This implementation was chosen to minimize the risk of a battery measurement
3130+
/// introducting breaking delays into the LMIC.
3131+
///
3132+
u1_t LMIC_setBatteryLevel(u1_t uBattLevel) {
3133+
const u1_t result = LMIC.client.devStatusAns_battery;
3134+
3135+
LMIC.client.devStatusAns_battery = uBattLevel;
3136+
return result;
3137+
}
3138+
3139+
///
3140+
/// \brief get battery level that is to be returned by `DevStatusAns`.
3141+
///
3142+
/// \returns
3143+
/// This function returns the saved value of the battery level.
3144+
///
3145+
/// \see LMIC_setBatteryLevel()
3146+
///
3147+
u1_t LMIC_getBatteryLevel(void) {
3148+
return LMIC.client.devStatusAns_battery;
3149+
}

src/lmic/lmic.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ extern "C"{
106106
((((major)*UINT32_C(1)) << 24) | (((minor)*UINT32_C(1)) << 16) | (((patch)*UINT32_C(1)) << 8) | (((local)*UINT32_C(1)) << 0))
107107

108108
#define ARDUINO_LMIC_VERSION \
109-
ARDUINO_LMIC_VERSION_CALC(4, 0, 1, 1) /* 4.0.1-pre1 */
109+
ARDUINO_LMIC_VERSION_CALC(4, 1, 0, 1) /* 4.1.0-pre1 */
110110

111111
#define ARDUINO_LMIC_VERSION_GET_MAJOR(v) \
112112
((((v)*UINT32_C(1)) >> 24u) & 0xFFu)
@@ -459,7 +459,7 @@ struct lmic_client_data_s {
459459
u2_t clockError; //! Inaccuracy in the clock. CLOCK_ERROR_MAX represents +/-100% error
460460

461461
/* finally, things that are (u)int8_t */
462-
/* none at the moment */
462+
u1_t devStatusAns_battery; //!< value to report in MCMD_DevStatusAns message.
463463
};
464464

465465
/*
@@ -740,6 +740,9 @@ int LMIC_registerEventCb(lmic_event_cb_t *pEventCb, void *pUserData);
740740

741741
int LMIC_findNextChannel(uint16_t *, const uint16_t *, uint16_t, int);
742742

743+
u1_t LMIC_getBatteryLevel(void);
744+
u1_t LMIC_setBatteryLevel(u1_t /* uBattLevel */);
745+
743746
// APIs for client half of compliance.
744747
typedef u1_t lmic_compliance_rx_action_t;
745748

0 commit comments

Comments
 (0)