BLE Library with custom services for the tortuga bike
Fork of BLE_API by
ble/services/BikeService.h@1207:da7745688342, 2016-07-18 (annotated)
- Committer:
- ptuytsch
- Date:
- Mon Jul 18 09:25:32 2016 +0000
- Revision:
- 1207:da7745688342
- Parent:
- 1206:8afbec0520f5
make it working with tortuga itself
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ptuytsch | 1131:5cc818415e2b | 1 | #ifndef __BLE_BIKE_SERVICE_H__ |
ptuytsch | 1131:5cc818415e2b | 2 | #define __BLE_BIKE_SERVICE_H__ |
ptuytsch | 1204:c87f50212c84 | 3 | |
ptuytsch | 1204:c87f50212c84 | 4 | #include "BikeData.h" |
ptuytsch | 1205:86f0783a5420 | 5 | #include "ble/BLE.h" |
ptuytsch | 1131:5cc818415e2b | 6 | class BikeService { |
ptuytsch | 1131:5cc818415e2b | 7 | public: |
ptuytsch | 1204:c87f50212c84 | 8 | /* |
ptuytsch | 1204:c87f50212c84 | 9 | UUID LIST: |
ptuytsch | 1204:c87f50212c84 | 10 | 0x6969: SERVICE |
ptuytsch | 1204:c87f50212c84 | 11 | 0x696A: Trip Distance |
ptuytsch | 1204:c87f50212c84 | 12 | 0x696B: Trip Average |
ptuytsch | 1204:c87f50212c84 | 13 | 0x696C: Trip Time (in seconds) |
ptuytsch | 1204:c87f50212c84 | 14 | |
ptuytsch | 1204:c87f50212c84 | 15 | 0x696D: Overall Distance |
ptuytsch | 1204:c87f50212c84 | 16 | 0x696E: Overall Average |
ptuytsch | 1204:c87f50212c84 | 17 | 0x696F: Overall Time (in seconds) |
ptuytsch | 1204:c87f50212c84 | 18 | |
ptuytsch | 1204:c87f50212c84 | 19 | 0x6970: Since Battery Change Distance |
ptuytsch | 1204:c87f50212c84 | 20 | 0x6971: Since Battery Change Average |
ptuytsch | 1204:c87f50212c84 | 21 | 0x6972: Since Battery Change Time (in seconds) |
ptuytsch | 1204:c87f50212c84 | 22 | |
ptuytsch | 1204:c87f50212c84 | 23 | 0x6973: pulses in last second |
ptuytsch | 1204:c87f50212c84 | 24 | 0x6974: Speed |
ptuytsch | 1204:c87f50212c84 | 25 | 0x6975: Control |
ptuytsch | 1205:86f0783a5420 | 26 | 0x6976: Device Name |
ptuytsch | 1204:c87f50212c84 | 27 | */ |
ptuytsch | 1204:c87f50212c84 | 28 | |
ptuytsch | 1204:c87f50212c84 | 29 | |
ptuytsch | 1204:c87f50212c84 | 30 | /*defining the UUID's for the service and characters*/ |
ptuytsch | 1205:86f0783a5420 | 31 | const static uint16_t BIKE_SERVICE_UUID = 0x6969; |
ptuytsch | 1202:a31d51d9fba8 | 32 | |
ptuytsch | 1205:86f0783a5420 | 33 | const static uint16_t TRIP_DISTANCE_CHARACTERISTIC_UUID = 0x696A; |
ptuytsch | 1205:86f0783a5420 | 34 | const static uint16_t TRIP_AVERAGE_CHARACTERISTIC_UUID = 0x696B; |
ptuytsch | 1205:86f0783a5420 | 35 | const static uint16_t TRIP_TIME_CHARACTERISTIC_UUID = 0x696C; |
ptuytsch | 1204:c87f50212c84 | 36 | |
ptuytsch | 1205:86f0783a5420 | 37 | const static uint16_t OVERALL_DISTANCE_CHARACTERISTIC_UUID = 0x696D; |
ptuytsch | 1205:86f0783a5420 | 38 | const static uint16_t OVERALL_AVERAGE_CHARACTERISTIC_UUID = 0x696E; |
ptuytsch | 1205:86f0783a5420 | 39 | const static uint16_t OVERALL_TIME_CHARACTERISTIC_UUID = 0x696F; |
ptuytsch | 1204:c87f50212c84 | 40 | |
ptuytsch | 1205:86f0783a5420 | 41 | const static uint16_t BATCHANGE_DISTANCE_CHARACTERISTIC_UUID = 0x6970; |
ptuytsch | 1205:86f0783a5420 | 42 | const static uint16_t BATCHANGE_AVERAGE_CHARACTERISTIC_UUID = 0x6971; |
ptuytsch | 1205:86f0783a5420 | 43 | const static uint16_t BATCHANGE_TIME_CHARACTERISTIC_UUID = 0x6972; |
ptuytsch | 1204:c87f50212c84 | 44 | |
ptuytsch | 1205:86f0783a5420 | 45 | const static uint16_t PULSE_CHARACTERISTIC_UUID = 0x6973; |
ptuytsch | 1205:86f0783a5420 | 46 | const static uint16_t SPEED_CHARACTERISTIC_UUID = 0x6974; |
ptuytsch | 1205:86f0783a5420 | 47 | const static uint16_t CONTROL_CHARACTERISTIC_UUID = 0x6975; |
ptuytsch | 1205:86f0783a5420 | 48 | const static uint16_t DEVICE_NAME_CHARACTERISTIC_UUID = 0x6976; |
ptuytsch | 1202:a31d51d9fba8 | 49 | |
ptuytsch | 1202:a31d51d9fba8 | 50 | //CONSTRUCTOR |
ptuytsch | 1204:c87f50212c84 | 51 | BikeService(BLE &_ble, BikeData *bikeData) : |
ptuytsch | 1204:c87f50212c84 | 52 | /*define standard/initial value*/ |
ptuytsch | 1204:c87f50212c84 | 53 | ble(_ble), |
ptuytsch | 1204:c87f50212c84 | 54 | bd(bikeData), |
ptuytsch | 1204:c87f50212c84 | 55 | tripDistanceChar(TRIP_DISTANCE_CHARACTERISTIC_UUID,&tripDistance, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 56 | tripAverageChar(TRIP_AVERAGE_CHARACTERISTIC_UUID,&tripAverage, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 57 | tripTimeChar(TRIP_TIME_CHARACTERISTIC_UUID,&tripTime, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 58 | |
ptuytsch | 1204:c87f50212c84 | 59 | overallDistanceChar(OVERALL_DISTANCE_CHARACTERISTIC_UUID,&overallDistance, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 60 | overallAverageChar(OVERALL_AVERAGE_CHARACTERISTIC_UUID,&overallAverage, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 61 | overallTimeChar(OVERALL_TIME_CHARACTERISTIC_UUID,&overallTime, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 62 | |
ptuytsch | 1204:c87f50212c84 | 63 | batChangeDistanceChar(BATCHANGE_DISTANCE_CHARACTERISTIC_UUID,&batChangeDistance, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 64 | batChangeAverageChar(BATCHANGE_AVERAGE_CHARACTERISTIC_UUID,&batChangeAverage, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 65 | batChangeTimeChar(BATCHANGE_TIME_CHARACTERISTIC_UUID,&batChangeTime, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 66 | |
ptuytsch | 1204:c87f50212c84 | 67 | pulseChar(PULSE_CHARACTERISTIC_UUID,&pulse, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 68 | speedChar(SPEED_CHARACTERISTIC_UUID,&speed, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ptuytsch | 1204:c87f50212c84 | 69 | controlChar(CONTROL_CHARACTERISTIC_UUID,&control, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
ptuytsch | 1205:86f0783a5420 | 70 | /*deviceNameChar(DEVICE_NAME_CHARACTERISTIC_UUID, |
ptuytsch | 1205:86f0783a5420 | 71 | (uint8_t *)bd->getBikeName(), |
ptuytsch | 1205:86f0783a5420 | 72 | bd->getBikeNameSize(), |
ptuytsch | 1205:86f0783a5420 | 73 | bd->getBikeNameSize(), |
ptuytsch | 1205:86f0783a5420 | 74 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)*/ |
ptuytsch | 1131:5cc818415e2b | 75 | { |
ptuytsch | 1205:86f0783a5420 | 76 | static char devName[] = "tmp"; |
ptuytsch | 1205:86f0783a5420 | 77 | bd->getBikeName(devName); |
ptuytsch | 1205:86f0783a5420 | 78 | deviceNameChar = new GattCharacteristic(DEVICE_NAME_CHARACTERISTIC_UUID, |
ptuytsch | 1205:86f0783a5420 | 79 | (uint8_t *)devName, |
ptuytsch | 1205:86f0783a5420 | 80 | bd->getBikeNameSize(), |
ptuytsch | 1205:86f0783a5420 | 81 | bd->getBikeNameSize(), |
ptuytsch | 1205:86f0783a5420 | 82 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE); |
ptuytsch | 1205:86f0783a5420 | 83 | /*static char devName[] = "tmp"; |
ptuytsch | 1205:86f0783a5420 | 84 | bd->getBikeName(devName); |
ptuytsch | 1205:86f0783a5420 | 85 | ble.gattServer().write(deviceNameChar.getValueHandle(),(uint8_t *)devName,bd->getBikeNameSize());*/ |
ptuytsch | 1204:c87f50212c84 | 86 | //read al the values out of the BikeData object |
ptuytsch | 1204:c87f50212c84 | 87 | tripDistance = (bd->getDataSet(BikeData::TRIP))->getDistance() *100; |
ptuytsch | 1204:c87f50212c84 | 88 | tripAverage = (bd->getDataSet(BikeData::TRIP))->getAverage() *100; |
ptuytsch | 1204:c87f50212c84 | 89 | tripTime = (bd->getDataSet(BikeData::TRIP))->getTime(); |
ptuytsch | 1204:c87f50212c84 | 90 | |
ptuytsch | 1204:c87f50212c84 | 91 | overallDistance = (bd->getDataSet(BikeData::OVERALL))->getDistance()*100; |
ptuytsch | 1204:c87f50212c84 | 92 | overallAverage = (bd->getDataSet(BikeData::OVERALL))->getAverage()*100; |
ptuytsch | 1204:c87f50212c84 | 93 | overallTime = (bd->getDataSet(BikeData::OVERALL))->getTime(); |
ptuytsch | 1204:c87f50212c84 | 94 | |
ptuytsch | 1204:c87f50212c84 | 95 | batChangeDistance = (bd->getDataSet(BikeData::BATCHANGE))->getDistance() *100; |
ptuytsch | 1204:c87f50212c84 | 96 | batChangeAverage = (bd->getDataSet(BikeData::BATCHANGE))->getAverage() *100; |
ptuytsch | 1204:c87f50212c84 | 97 | batChangeTime = (bd->getDataSet(BikeData::BATCHANGE))->getTime(); |
ptuytsch | 1204:c87f50212c84 | 98 | |
ptuytsch | 1204:c87f50212c84 | 99 | pulse = bd->getLastCount(); |
ptuytsch | 1204:c87f50212c84 | 100 | speed = bd->getSpeed()*100; |
ptuytsch | 1204:c87f50212c84 | 101 | control = bd->isLogging()*5; |
ptuytsch | 1204:c87f50212c84 | 102 | |
ptuytsch | 1204:c87f50212c84 | 103 | //creating a pointer list of al the characteristics |
ptuytsch | 1204:c87f50212c84 | 104 | GattCharacteristic *charTable[] = {&tripDistanceChar, &tripAverageChar, &tripTimeChar, |
ptuytsch | 1204:c87f50212c84 | 105 | &overallDistanceChar, &overallAverageChar, &overallTimeChar, |
ptuytsch | 1204:c87f50212c84 | 106 | &batChangeDistanceChar, &batChangeAverageChar, &batChangeTimeChar, |
ptuytsch | 1205:86f0783a5420 | 107 | &pulseChar, &speedChar, &controlChar, deviceNameChar}; |
ptuytsch | 1204:c87f50212c84 | 108 | //creating the gattService |
ptuytsch | 1131:5cc818415e2b | 109 | GattService bikeService(BikeService::BIKE_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
ptuytsch | 1131:5cc818415e2b | 110 | ble.gattServer().addService(bikeService); |
ptuytsch | 1205:86f0783a5420 | 111 | //define the function to call when data is written to service |
ptuytsch | 1202:a31d51d9fba8 | 112 | ble.onDataWritten(this, &BikeService::onDataWrittenCallback); |
ptuytsch | 1202:a31d51d9fba8 | 113 | } |
ptuytsch | 1202:a31d51d9fba8 | 114 | |
ptuytsch | 1202:a31d51d9fba8 | 115 | void onDataWrittenCallback(const GattWriteCallbackParams *writeParams) { |
ptuytsch | 1204:c87f50212c84 | 116 | //when data is written in the controlCharacteristic |
ptuytsch | 1204:c87f50212c84 | 117 | if (writeParams->handle == controlChar.getValueHandle()) { |
ptuytsch | 1204:c87f50212c84 | 118 | //performing different actions according to the written value |
ptuytsch | 1204:c87f50212c84 | 119 | if (*(writeParams->data) == '1'){ |
ptuytsch | 1204:c87f50212c84 | 120 | bd->startTrip(); |
ptuytsch | 1204:c87f50212c84 | 121 | } |
ptuytsch | 1204:c87f50212c84 | 122 | else if (*(writeParams->data) == '2'){ |
ptuytsch | 1204:c87f50212c84 | 123 | bd->pauzeTrip(); |
ptuytsch | 1204:c87f50212c84 | 124 | } |
ptuytsch | 1204:c87f50212c84 | 125 | else if (*(writeParams->data) == '3'){ |
ptuytsch | 1204:c87f50212c84 | 126 | bd->stopTrip(); |
ptuytsch | 1204:c87f50212c84 | 127 | } |
ptuytsch | 1202:a31d51d9fba8 | 128 | } |
ptuytsch | 1205:86f0783a5420 | 129 | |
ptuytsch | 1205:86f0783a5420 | 130 | if (writeParams->handle == deviceNameChar->getValueHandle()) { |
ptuytsch | 1205:86f0783a5420 | 131 | printf("name changing, length: %i\n",(uint8_t)writeParams->len); |
ptuytsch | 1205:86f0783a5420 | 132 | //uint8_t *recievedName = writeParams->data; |
ptuytsch | 1205:86f0783a5420 | 133 | //writeParams->data->push_back(0x00); |
ptuytsch | 1205:86f0783a5420 | 134 | uint8_t recievedName[writeParams->len +1]; |
ptuytsch | 1205:86f0783a5420 | 135 | for (uint8_t i = 0 ; i < writeParams->len ; i++){ |
ptuytsch | 1205:86f0783a5420 | 136 | recievedName[i] = *(writeParams->data+i); |
ptuytsch | 1205:86f0783a5420 | 137 | } |
ptuytsch | 1205:86f0783a5420 | 138 | recievedName[writeParams->len] = 0x00; |
ptuytsch | 1205:86f0783a5420 | 139 | bd->setBikeName((char *)recievedName,((uint8_t)writeParams->len)+1); |
ptuytsch | 1205:86f0783a5420 | 140 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)recievedName, (writeParams->len)+1);//passing the device name |
ptuytsch | 1205:86f0783a5420 | 141 | |
ptuytsch | 1205:86f0783a5420 | 142 | printf("written length: %i\n", bd->getBikeNameSize()); |
ptuytsch | 1205:86f0783a5420 | 143 | static char devName[] = "tmp"; |
ptuytsch | 1205:86f0783a5420 | 144 | bd->getBikeName(devName); |
ptuytsch | 1205:86f0783a5420 | 145 | ble.gattServer().write(deviceNameChar->getValueHandle(),(uint8_t *)devName,bd->getBikeNameSize()); |
ptuytsch | 1205:86f0783a5420 | 146 | /*char name[] = "otherName"; |
ptuytsch | 1205:86f0783a5420 | 147 | bd->setBikeName(name,sizeof(name));*/ |
ptuytsch | 1205:86f0783a5420 | 148 | } |
ptuytsch | 1131:5cc818415e2b | 149 | } |
ptuytsch | 1131:5cc818415e2b | 150 | |
ptuytsch | 1131:5cc818415e2b | 151 | |
ptuytsch | 1204:c87f50212c84 | 152 | void update(){ |
ptuytsch | 1204:c87f50212c84 | 153 | /*updating the different characteristics when the value has changed*/ |
ptuytsch | 1204:c87f50212c84 | 154 | uint32_t tmp; |
ptuytsch | 1204:c87f50212c84 | 155 | //TripData |
ptuytsch | 1204:c87f50212c84 | 156 | tmp = ((bd->getDataSet(BikeData::TRIP))->getDistance()) * 100; |
ptuytsch | 1204:c87f50212c84 | 157 | if (tmp != tripDistance){ |
ptuytsch | 1204:c87f50212c84 | 158 | tripDistance = tmp; |
ptuytsch | 1204:c87f50212c84 | 159 | ble.gattServer().write(tripDistanceChar.getValueHandle(),(uint8_t *)&tripDistance,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 160 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1206:8afbec0520f5 | 161 | } |
ptuytsch | 1204:c87f50212c84 | 162 | tmp = ((bd->getDataSet(BikeData::TRIP))->getAverage()) * 100; |
ptuytsch | 1204:c87f50212c84 | 163 | if (tmp != tripAverage){ |
ptuytsch | 1204:c87f50212c84 | 164 | tripAverage = tmp; |
ptuytsch | 1204:c87f50212c84 | 165 | ble.gattServer().write(tripAverageChar.getValueHandle(),(uint8_t *)&tripAverage,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 166 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 167 | } |
ptuytsch | 1204:c87f50212c84 | 168 | tmp = ((bd->getDataSet(BikeData::TRIP))->getTime()); |
ptuytsch | 1204:c87f50212c84 | 169 | if (tmp != tripTime){ |
ptuytsch | 1204:c87f50212c84 | 170 | tripTime = tmp; |
ptuytsch | 1204:c87f50212c84 | 171 | ble.gattServer().write(tripTimeChar.getValueHandle(),(uint8_t *)&tripTime,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 172 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 173 | } |
ptuytsch | 1204:c87f50212c84 | 174 | //OverallData |
ptuytsch | 1204:c87f50212c84 | 175 | tmp = (bd->getDataSet(BikeData::OVERALL))->getDistance()*100; |
ptuytsch | 1204:c87f50212c84 | 176 | if (tmp != overallDistance){ |
ptuytsch | 1204:c87f50212c84 | 177 | overallDistance = tmp; |
ptuytsch | 1204:c87f50212c84 | 178 | ble.gattServer().write(overallDistanceChar.getValueHandle(),(uint8_t *)&overallDistance,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 179 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 180 | } |
ptuytsch | 1204:c87f50212c84 | 181 | tmp = (bd->getDataSet(BikeData::OVERALL))->getAverage()*100; |
ptuytsch | 1204:c87f50212c84 | 182 | if (tmp != overallAverage){ |
ptuytsch | 1204:c87f50212c84 | 183 | overallAverage = tmp; |
ptuytsch | 1204:c87f50212c84 | 184 | ble.gattServer().write(overallAverageChar.getValueHandle(),(uint8_t *)&overallAverage,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 185 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 186 | } |
ptuytsch | 1204:c87f50212c84 | 187 | tmp = (bd->getDataSet(BikeData::OVERALL))->getTime(); |
ptuytsch | 1204:c87f50212c84 | 188 | if (tmp != overallTime){ |
ptuytsch | 1204:c87f50212c84 | 189 | overallTime = tmp; |
ptuytsch | 1204:c87f50212c84 | 190 | ble.gattServer().write(overallTimeChar.getValueHandle(),(uint8_t *)&overallTime,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 191 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 192 | } |
ptuytsch | 1204:c87f50212c84 | 193 | //Since Battery Change |
ptuytsch | 1204:c87f50212c84 | 194 | tmp = (bd->getDataSet(BikeData::BATCHANGE))->getDistance() *100; |
ptuytsch | 1204:c87f50212c84 | 195 | if (tmp != batChangeDistance){ |
ptuytsch | 1204:c87f50212c84 | 196 | batChangeDistance = tmp; |
ptuytsch | 1204:c87f50212c84 | 197 | ble.gattServer().write(batChangeDistanceChar.getValueHandle(),(uint8_t *)&batChangeDistance,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 198 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 199 | } |
ptuytsch | 1204:c87f50212c84 | 200 | tmp = (bd->getDataSet(BikeData::BATCHANGE))->getAverage() *100; |
ptuytsch | 1204:c87f50212c84 | 201 | if (tmp != batChangeAverage){ |
ptuytsch | 1204:c87f50212c84 | 202 | batChangeAverage = tmp; |
ptuytsch | 1204:c87f50212c84 | 203 | ble.gattServer().write(batChangeAverageChar.getValueHandle(),(uint8_t *)&batChangeAverage,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 204 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 205 | } |
ptuytsch | 1204:c87f50212c84 | 206 | tmp = (bd->getDataSet(BikeData::BATCHANGE))->getTime(); |
ptuytsch | 1204:c87f50212c84 | 207 | if (tmp != batChangeTime){ |
ptuytsch | 1204:c87f50212c84 | 208 | batChangeTime = tmp; |
ptuytsch | 1204:c87f50212c84 | 209 | ble.gattServer().write(batChangeTimeChar.getValueHandle(),(uint8_t *)&batChangeTime,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 210 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 211 | } |
ptuytsch | 1204:c87f50212c84 | 212 | // Continious Data |
ptuytsch | 1204:c87f50212c84 | 213 | tmp = bd->getLastCount(); |
ptuytsch | 1204:c87f50212c84 | 214 | if (tmp != pulse){ |
ptuytsch | 1204:c87f50212c84 | 215 | pulse = tmp; |
ptuytsch | 1204:c87f50212c84 | 216 | ble.gattServer().write(pulseChar.getValueHandle(),&pulse,sizeof(uint8_t)); |
ptuytsch | 1207:da7745688342 | 217 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 218 | } |
ptuytsch | 1204:c87f50212c84 | 219 | tmp = bd->getSpeed()*100; |
ptuytsch | 1204:c87f50212c84 | 220 | if (tmp != speed){ |
ptuytsch | 1204:c87f50212c84 | 221 | speed = tmp; |
ptuytsch | 1204:c87f50212c84 | 222 | ble.gattServer().write(speedChar.getValueHandle(),(uint8_t *)&speed,sizeof(uint32_t)); |
ptuytsch | 1207:da7745688342 | 223 | for (uint64_t i = 0; i<0x2760; i++); |
ptuytsch | 1204:c87f50212c84 | 224 | } |
ptuytsch | 1204:c87f50212c84 | 225 | tmp = bd->isLogging()*'5'; |
ptuytsch | 1204:c87f50212c84 | 226 | if (tmp != control){ |
ptuytsch | 1204:c87f50212c84 | 227 | control = tmp; |
ptuytsch | 1204:c87f50212c84 | 228 | ble.gattServer().write(controlChar.getValueHandle(),&control,sizeof(uint8_t)); |
ptuytsch | 1204:c87f50212c84 | 229 | } |
ptuytsch | 1204:c87f50212c84 | 230 | } |
ptuytsch | 1204:c87f50212c84 | 231 | |
ptuytsch | 1204:c87f50212c84 | 232 | public: |
ptuytsch | 1204:c87f50212c84 | 233 | |
ptuytsch | 1204:c87f50212c84 | 234 | //different variables for the service |
ptuytsch | 1204:c87f50212c84 | 235 | BLE &ble; |
ptuytsch | 1204:c87f50212c84 | 236 | BikeData *bd; |
ptuytsch | 1204:c87f50212c84 | 237 | uint32_t tripDistance, tripAverage, tripTime, |
ptuytsch | 1204:c87f50212c84 | 238 | overallDistance, overallAverage, overallTime, |
ptuytsch | 1204:c87f50212c84 | 239 | batChangeDistance, batChangeAverage, batChangeTime, |
ptuytsch | 1204:c87f50212c84 | 240 | speed; |
ptuytsch | 1204:c87f50212c84 | 241 | uint8_t pulse, control; |
ptuytsch | 1204:c87f50212c84 | 242 | |
ptuytsch | 1204:c87f50212c84 | 243 | //the different characteristics created of an template |
ptuytsch | 1204:c87f50212c84 | 244 | ReadOnlyGattCharacteristic<uint32_t> tripDistanceChar; |
ptuytsch | 1204:c87f50212c84 | 245 | ReadOnlyGattCharacteristic<uint32_t> tripAverageChar; |
ptuytsch | 1204:c87f50212c84 | 246 | ReadOnlyGattCharacteristic<uint32_t> tripTimeChar; |
ptuytsch | 1131:5cc818415e2b | 247 | |
ptuytsch | 1204:c87f50212c84 | 248 | ReadOnlyGattCharacteristic<uint32_t> overallDistanceChar; |
ptuytsch | 1204:c87f50212c84 | 249 | ReadOnlyGattCharacteristic<uint32_t> overallAverageChar; |
ptuytsch | 1204:c87f50212c84 | 250 | ReadOnlyGattCharacteristic<uint32_t> overallTimeChar; |
ptuytsch | 1204:c87f50212c84 | 251 | |
ptuytsch | 1204:c87f50212c84 | 252 | ReadOnlyGattCharacteristic<uint32_t> batChangeDistanceChar; |
ptuytsch | 1204:c87f50212c84 | 253 | ReadOnlyGattCharacteristic<uint32_t> batChangeAverageChar; |
ptuytsch | 1204:c87f50212c84 | 254 | ReadOnlyGattCharacteristic<uint32_t> batChangeTimeChar; |
ptuytsch | 1204:c87f50212c84 | 255 | |
ptuytsch | 1204:c87f50212c84 | 256 | ReadOnlyGattCharacteristic<uint8_t> pulseChar; |
ptuytsch | 1204:c87f50212c84 | 257 | ReadOnlyGattCharacteristic<uint32_t> speedChar; |
ptuytsch | 1204:c87f50212c84 | 258 | ReadWriteGattCharacteristic<uint8_t> controlChar; |
ptuytsch | 1205:86f0783a5420 | 259 | |
ptuytsch | 1205:86f0783a5420 | 260 | |
ptuytsch | 1205:86f0783a5420 | 261 | GattCharacteristic *deviceNameChar; |
ptuytsch | 1131:5cc818415e2b | 262 | }; |
ptuytsch | 1131:5cc818415e2b | 263 | |
ptuytsch | 1202:a31d51d9fba8 | 264 | #endif |