You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
For some crownstones, the accumulatedEnergy advertised in serviceData remains constant, even though the advertised realPowerUsage is high enough that the accumulatedEnergy should increase over time.
For example, I have a crownstone that consumes ~27 Watt as per the consumer app (see screenshot). Since the accumulatedEnergy field in the advertisement data contains energy in 64J units, the accumulatedEnergy value should increment every ~2 seconds or so. Instead, it remains constant for at least hours (see second screenshot).
To Reproduce onlinegdb simulation for reproducing the bug and the proposed solution.
The bug is not easily reproduced on a crownstone since it only occurs for specific (high enough) initial values of the _energyUsedmicroJoule variable in cs_PowerSampling.cpp. In my case it was 17694528000000 (it is an int64_t).
Cause and solution
Together with @vliedel I found the cause of the bug to stem from a bug in the incrementation of the energyUsedmicroJoule on line 1036 of cs_PowerSampling.cpp. This operation adds a float to an int64_t using float addition. For high values of the int64_t variable, it seems that the float addition fails (probably due to bad resolution for floats for high numbers). The solution is simple: cast to int64_t before performing the addition. @vliedel and I tested this in the onlinegdb simulation and it seems to work.
Screenshots
Binary (please complete the following information):
Firmware version: 5.6.4
Softdevice version: irrelevant
Bootloader version: irrelevant
The text was updated successfully, but these errors were encountered:
Describe the bug
For some crownstones, the accumulatedEnergy advertised in serviceData remains constant, even though the advertised realPowerUsage is high enough that the accumulatedEnergy should increase over time.
For example, I have a crownstone that consumes ~27 Watt as per the consumer app (see screenshot). Since the accumulatedEnergy field in the advertisement data contains energy in 64J units, the accumulatedEnergy value should increment every ~2 seconds or so. Instead, it remains constant for at least hours (see second screenshot).
To Reproduce
onlinegdb simulation for reproducing the bug and the proposed solution.
The bug is not easily reproduced on a crownstone since it only occurs for specific (high enough) initial values of the
_energyUsedmicroJoule
variable incs_PowerSampling.cpp
. In my case it was17694528000000
(it is anint64_t
).Cause and solution
Together with @vliedel I found the cause of the bug to stem from a bug in the incrementation of the
energyUsedmicroJoule
on line 1036 ofcs_PowerSampling.cpp
. This operation adds afloat
to anint64_t
usingfloat
addition. For high values of theint64_t
variable, it seems that thefloat
addition fails (probably due to bad resolution for floats for high numbers). The solution is simple: cast toint64_t
before performing the addition. @vliedel and I tested this in the onlinegdb simulation and it seems to work.Screenshots
Binary (please complete the following information):
The text was updated successfully, but these errors were encountered: