Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/NimBLEEddystoneTLM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ std::string NimBLEEddystoneTLM::toString() {
out += val;
out += " mV\n";

out += "Temperature ";
uint8_t intTemp = m_eddystoneData.temp / 256;
uint8_t frac = m_eddystoneData.temp % 256 * 100 / 256;
snprintf(val, sizeof(val), "%d.%d", intTemp, frac);
out += "Temperature ";
int16_t temp = ENDIAN_CHANGE_U16(m_eddystoneData.temp);
uint32_t absTemp = temp < 0 ? -static_cast<int32_t>(temp) : temp;
uint8_t intTemp = absTemp / 256;
uint8_t frac = absTemp % 256 * 100 / 256;
snprintf(val, sizeof(val), "%s%d.%02d", (temp < 0 ? "-" : ""), intTemp, frac);
out += val;
out += " C\n";

Expand Down Expand Up @@ -188,31 +190,31 @@ void NimBLEEddystoneTLM::setVersion(uint8_t version) {
* @param [in] volt The voltage in millivolts.
*/
void NimBLEEddystoneTLM::setVolt(uint16_t volt) {
m_eddystoneData.volt = volt;
m_eddystoneData.volt = ENDIAN_CHANGE_U16(volt);
} // setVolt

/**
* @brief Set the temperature to advertise.
* @param [in] temp The temperature value in 8.8 fixed point format.
*/
void NimBLEEddystoneTLM::setTemp(int16_t temp) {
m_eddystoneData.temp = temp;
m_eddystoneData.temp = ENDIAN_CHANGE_U16(temp);
} // setTemp

/**
* @brief Set the advertisement count.
* @param [in] advCount The advertisement number.
*/
void NimBLEEddystoneTLM::setCount(uint32_t advCount) {
m_eddystoneData.advCount = advCount;
m_eddystoneData.advCount = ENDIAN_CHANGE_U32(advCount);
} // setCount

/**
* @brief Set the advertisement time.
* @param [in] tmil The advertisement time in milliseconds.
*/
void NimBLEEddystoneTLM::setTime(uint32_t tmil) {
m_eddystoneData.tmil = tmil;
m_eddystoneData.tmil = ENDIAN_CHANGE_U32(tmil);
} // setTime

#endif // CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER)
4 changes: 2 additions & 2 deletions src/NimBLEEddystoneTLM.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class NimBLEEddystoneTLM {
struct BeaconData {
uint8_t frameType{EDDYSTONE_TLM_FRAME_TYPE};
uint8_t version{0};
uint16_t volt{3300};
uint16_t temp{23 * 256};
uint16_t volt{0xE40C}; // Big-endian (wire format) encoding of 3300 mV; getVolt() swaps back to host order.
uint16_t temp{0x0017}; // Big-endian (wire format) encoding of 23.0C (23 * 256); getTemp() swaps back to host order.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
uint32_t advCount{0};
uint32_t tmil{0};
} __attribute__((packed));
Expand Down