Commit 368dff9
Fix NimBLEEddystoneTLM byte-order mismatch between getters and setters (#431)
* Fix NimBLEEddystoneTLM byte-order mismatch between getters and setters
m_eddystoneData must always hold Eddystone-TLM wire-format (big-endian)
bytes, since getData() returns it directly for the caller to memcpy
straight into the BLE advertisement payload (see the
BLE_EddystoneTLM_Beacon example), and setData()/getData() already treat
it as raw wire bytes.
The getters (getVolt/getTemp) correctly un-swap on read, but the
setters (setVolt/setTemp/setCount/setTime) stored their host-order
input directly with no swap, and the BeaconData default member
initializers were host-order values instead of pre-swapped wire-format
values. This breaks the setter/getter round trip for any value set
locally (as opposed to arriving over the air via setData()), and means
a freshly constructed object reports a garbage battery voltage.
toString() also failed to un-swap the temperature field at all, and
used unsigned division/modulo on a signed 8.8 fixed-point value,
producing garbage output for negative temperatures.
This mirrors the existing, correct pattern already used by the sibling
NimBLEBeacon class, which swaps in its setters (setMajor/setMinor/
setManufacturerId).
Fix:
- setVolt/setTemp/setCount/setTime now apply ENDIAN_CHANGE_U16/U32 to
their input before storing, matching what the getters already
assume.
- BeaconData's default volt/temp member initializers are now the
wire-format (byte-swapped) encoding of the intended defaults (3300
mV, 23.0C), so a freshly constructed object reports correct values
without calling a setter first.
- toString() now swaps the temperature field the same way it already
swaps voltage, and computes the displayed magnitude from a signed
value with explicit sign handling instead of unsigned arithmetic on
the raw field.1 parent 9bc4b9f commit 368dff9
2 files changed
Lines changed: 12 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| |||
188 | 190 | | |
189 | 191 | | |
190 | 192 | | |
191 | | - | |
| 193 | + | |
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
199 | | - | |
| 201 | + | |
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
204 | 206 | | |
205 | 207 | | |
206 | 208 | | |
207 | | - | |
| 209 | + | |
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
214 | 216 | | |
215 | | - | |
| 217 | + | |
216 | 218 | | |
217 | 219 | | |
218 | 220 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
0 commit comments