testing for double to float
Dependencies: ADXL345_nRF51 BLE_API advertiser_data mbed nRF51822
Fork of BLE_GAP_Acceleration_Observer_2_Advertisers by
Diff: main.cpp
- Revision:
- 16:7593fe102c55
- Parent:
- 14:3bde71241a53
- Child:
- 17:d0e05234fd95
--- a/main.cpp Mon Jul 27 18:50:30 2015 +0000 +++ b/main.cpp Wed Jul 29 17:14:40 2015 +0000 @@ -79,6 +79,54 @@ //pc.printf("Found device...\n\r"); #endif if (params->peerAddr[5] == 0xe5 && params->peerAddr[4] == 0x4f) { + pc.printf("ADVERTISER 1\n\r"); +#ifdef DEBUG + for (unsigned index = 0; index < params->advertisingDataLen; index++) { + pc.printf("%02x ", params->advertisingData[index]); + } + pc.printf("\n\r"); +#endif + /* Using only the 3rd part of address for indexing the stored data for now */ + advertiser_data *pdata = get_advertiser_data(params->peerAddr[3]); + if (!pdata) { +#ifdef DEBUG + pc.printf("Too many advertisers!\n\r"); +#endif + return; + } + + /* Always update the rssi */ + uint8_t passdat = (uint8_t)(abs(params->rssi)); + advertiser_data_update_rssi(pdata, passdat); + + /* Find the manufacturers data */ + const uint8_t *manData = NULL; + uint8_t manDataLen = 0; + get_manufacturer_data(params->advertisingData, params->advertisingDataLen, manData, manDataLen); + + /* If the data is empty, skip the counter check */ + if (!advertiser_data_is_empty(pdata)) { + uint8_t diff = advertiser_data_counter_difference(pdata, manData, manDataLen); + if (diff == 0) { + /* Quit early if we've seen this packet */ + return; + } else if (diff > 1) { +#ifdef DEBUG + pc.printf("resetting: diff is %d\n\r", diff); +#endif + /* Reset the data if we missed a packet (likely lost signal for a while) */ + advertiser_data_reset(pdata); + advertiser_data_update_rssi(pdata, passdat); + } + } + + /* Update everything from the manufacturer data */ + advertiser_data_update(pdata, manData, manDataLen); + + // TODO: implement the rest of the algorithms + advertiser_data_print(pdata); + }else if(params->peerAddr[5] == 0xe6 && params->peerAddr[4] == 0x4f) { + pc.printf("ADVERTISER 2\n\r"); #ifdef DEBUG for (unsigned index = 0; index < params->advertisingDataLen; index++) { pc.printf("%02x ", params->advertisingData[index]);