diff --git a/src/NimBLEEddystoneTLM.cpp b/src/NimBLEEddystoneTLM.cpp index 8ee405b5..4cfd7498 100644 --- a/src/NimBLEEddystoneTLM.cpp +++ b/src/NimBLEEddystoneTLM.cpp @@ -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(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"; @@ -188,7 +190,7 @@ 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 /** @@ -196,7 +198,7 @@ void NimBLEEddystoneTLM::setVolt(uint16_t volt) { * @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 /** @@ -204,7 +206,7 @@ void NimBLEEddystoneTLM::setTemp(int16_t temp) { * @param [in] advCount The advertisement number. */ void NimBLEEddystoneTLM::setCount(uint32_t advCount) { - m_eddystoneData.advCount = advCount; + m_eddystoneData.advCount = ENDIAN_CHANGE_U32(advCount); } // setCount /** @@ -212,7 +214,7 @@ void NimBLEEddystoneTLM::setCount(uint32_t advCount) { * @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) diff --git a/src/NimBLEEddystoneTLM.h b/src/NimBLEEddystoneTLM.h index f48cf94c..fdfcb841 100644 --- a/src/NimBLEEddystoneTLM.h +++ b/src/NimBLEEddystoneTLM.h @@ -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. uint32_t advCount{0}; uint32_t tmil{0}; } __attribute__((packed));