BLE Library with custom services for the tortuga bike
Fork of BLE_API by
ble/services/BikeService.h@1205:86f0783a5420, 2016-07-12 (annotated)
- Committer:
- ptuytsch
- Date:
- Tue Jul 12 11:55:13 2016 +0000
- Revision:
- 1205:86f0783a5420
- Parent:
- 1204:c87f50212c84
- Child:
- 1206:8afbec0520f5
finetuning bikeservice and adding name change characteristic
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 | 1205:86f0783a5420 | 117 | printf("data\n"); |
ptuytsch | 1204:c87f50212c84 | 118 | if (writeParams->handle == controlChar.getValueHandle()) { |
ptuytsch | 1204:c87f50212c84 | 119 | //performing different actions according to the written value |
ptuytsch | 1204:c87f50212c84 | 120 | if (*(writeParams->data) == '1'){ |
ptuytsch | 1204:c87f50212c84 | 121 | bd->startTrip(); |
ptuytsch | 1204:c87f50212c84 | 122 | } |
ptuytsch | 1204:c87f50212c84 | 123 | else if (*(writeParams->data) == '2'){ |
ptuytsch | 1204:c87f50212c84 | 124 | bd->pauzeTrip(); |
ptuytsch | 1204:c87f50212c84 | 125 | } |
ptuytsch | 1204:c87f50212c84 | 126 | else if (*(writeParams->data) == '3'){ |
ptuytsch | 1204:c87f50212c84 | 127 | bd->stopTrip(); |
ptuytsch | 1204:c87f50212c84 | 128 | } |
ptuytsch | 1202:a31d51d9fba8 | 129 | } |
ptuytsch | 1205:86f0783a5420 | 130 | |
ptuytsch | 1205:86f0783a5420 | 131 | if (writeParams->handle == deviceNameChar->getValueHandle()) { |
ptuytsch | 1205:86f0783a5420 | 132 | printf("name changing, length: %i\n",(uint8_t)writeParams->len); |
ptuytsch | 1205:86f0783a5420 | 133 | //uint8_t *recievedName = writeParams->data; |
ptuytsch | 1205:86f0783a5420 | 134 | //writeParams->data->push_back(0x00); |
ptuytsch | 1205:86f0783a5420 | 135 | uint8_t recievedName[writeParams->len +1]; |
ptuytsch | 1205:86f0783a5420 | 136 | for (uint8_t i = 0 ; i < writeParams->len ; i++){ |
ptuytsch | 1205:86f0783a5420 | 137 | recievedName[i] = *(writeParams->data+i); |
ptuytsch | 1205:86f0783a5420 | 138 | } |
ptuytsch | 1205:86f0783a5420 | 139 | recievedName[writeParams->len] = 0x00; |
ptuytsch | 1205:86f0783a5420 | 140 | bd->setBikeName((char *)recievedName,((uint8_t)writeParams->len)+1); |
ptuytsch | 1205:86f0783a5420 | 141 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)recievedName, (writeParams->len)+1);//passing the device name |
ptuytsch | 1205:86f0783a5420 | 142 | |
ptuytsch | 1205:86f0783a5420 | 143 | printf("written length: %i\n", bd->getBikeNameSize()); |
ptuytsch | 1205:86f0783a5420 | 144 | static char devName[] = "tmp"; |
ptuytsch | 1205:86f0783a5420 | 145 | bd->getBikeName(devName); |
ptuytsch | 1205:86f0783a5420 | 146 | ble.gattServer().write(deviceNameChar->getValueHandle(),(uint8_t *)devName,bd->getBikeNameSize()); |
ptuytsch | 1205:86f0783a5420 | 147 | /*char name[] = "otherName"; |
ptuytsch | 1205:86f0783a5420 | 148 | bd->setBikeName(name,sizeof(name));*/ |
ptuytsch | 1205:86f0783a5420 | 149 | } |
ptuytsch | 1131:5cc818415e2b | 150 | } |
ptuytsch | 1131:5cc818415e2b | 151 | |
ptuytsch | 1131:5cc818415e2b | 152 | |
ptuytsch | 1204:c87f50212c84 | 153 | void update(){ |
ptuytsch | 1204:c87f50212c84 | 154 | /*updating the different characteristics when the value has changed*/ |
ptuytsch | 1204:c87f50212c84 | 155 | |
ptuytsch | 1204:c87f50212c84 | 156 | uint32_t tmp; |
ptuytsch | 1204:c87f50212c84 | 157 | //TripData |
ptuytsch | 1204:c87f50212c84 | 158 | tmp = ((bd->getDataSet(BikeData::TRIP))->getDistance()) * 100; |
ptuytsch | 1204:c87f50212c84 | 159 | if (tmp != tripDistance){ |
ptuytsch | 1204:c87f50212c84 | 160 | tripDistance = tmp; |
ptuytsch | 1204:c87f50212c84 | 161 | ble.gattServer().write(tripDistanceChar.getValueHandle(),(uint8_t *)&tripDistance,sizeof(uint32_t)); |
ptuytsch | 1204:c87f50212c84 | 162 | } |
ptuytsch | 1204:c87f50212c84 | 163 | tmp = ((bd->getDataSet(BikeData::TRIP))->getAverage()) * 100; |
ptuytsch | 1204:c87f50212c84 | 164 | if (tmp != tripAverage){ |
ptuytsch | 1204:c87f50212c84 | 165 | tripAverage = tmp; |
ptuytsch | 1204:c87f50212c84 | 166 | ble.gattServer().write(tripAverageChar.getValueHandle(),(uint8_t *)&tripAverage,sizeof(uint32_t)); |
ptuytsch | 1204:c87f50212c84 | 167 | } |
ptuytsch | 1204:c87f50212c84 | 168 | |
ptuytsch | 1204:c87f50212c84 | 169 | tmp = ((bd->getDataSet(BikeData::TRIP))->getTime()); |
ptuytsch | 1204:c87f50212c84 | 170 | if (tmp != tripTime){ |
ptuytsch | 1204:c87f50212c84 | 171 | tripTime = tmp; |
ptuytsch | 1204:c87f50212c84 | 172 | ble.gattServer().write(tripTimeChar.getValueHandle(),(uint8_t *)&tripTime,sizeof(uint32_t)); |
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 | 1204:c87f50212c84 | 179 | } |
ptuytsch | 1204:c87f50212c84 | 180 | tmp = (bd->getDataSet(BikeData::OVERALL))->getAverage()*100; |
ptuytsch | 1204:c87f50212c84 | 181 | if (tmp != overallAverage){ |
ptuytsch | 1204:c87f50212c84 | 182 | overallAverage = tmp; |
ptuytsch | 1204:c87f50212c84 | 183 | ble.gattServer().write(overallAverageChar.getValueHandle(),(uint8_t *)&overallAverage,sizeof(uint32_t)); |
ptuytsch | 1204:c87f50212c84 | 184 | } |
ptuytsch | 1204:c87f50212c84 | 185 | tmp = (bd->getDataSet(BikeData::OVERALL))->getTime(); |
ptuytsch | 1204:c87f50212c84 | 186 | if (tmp != overallTime){ |
ptuytsch | 1204:c87f50212c84 | 187 | overallTime = tmp; |
ptuytsch | 1204:c87f50212c84 | 188 | ble.gattServer().write(overallTimeChar.getValueHandle(),(uint8_t *)&overallTime,sizeof(uint32_t)); |
ptuytsch | 1204:c87f50212c84 | 189 | } |
ptuytsch | 1204:c87f50212c84 | 190 | //Since Battery Change |
ptuytsch | 1204:c87f50212c84 | 191 | tmp = (bd->getDataSet(BikeData::BATCHANGE))->getDistance() *100; |
ptuytsch | 1204:c87f50212c84 | 192 | if (tmp != batChangeDistance){ |
ptuytsch | 1204:c87f50212c84 | 193 | batChangeDistance = tmp; |
ptuytsch | 1204:c87f50212c84 | 194 | ble.gattServer().write(batChangeDistanceChar.getValueHandle(),(uint8_t *)&batChangeDistance,sizeof(uint32_t)); |
ptuytsch | 1204:c87f50212c84 | 195 | } |
ptuytsch | 1204:c87f50212c84 | 196 | tmp = (bd->getDataSet(BikeData::BATCHANGE))->getAverage() *100; |
ptuytsch | 1204:c87f50212c84 | 197 | if (tmp != batChangeAverage){ |
ptuytsch | 1204:c87f50212c84 | 198 | batChangeAverage = tmp; |
ptuytsch | 1204:c87f50212c84 | 199 | ble.gattServer().write(batChangeAverageChar.getValueHandle(),(uint8_t *)&batChangeAverage,sizeof(uint32_t)); |
ptuytsch | 1204:c87f50212c84 | 200 | } |
ptuytsch | 1204:c87f50212c84 | 201 | tmp = (bd->getDataSet(BikeData::BATCHANGE))->getTime(); |
ptuytsch | 1204:c87f50212c84 | 202 | if (tmp != batChangeTime){ |
ptuytsch | 1204:c87f50212c84 | 203 | batChangeTime = tmp; |
ptuytsch | 1204:c87f50212c84 | 204 | ble.gattServer().write(batChangeTimeChar.getValueHandle(),(uint8_t *)&batChangeTime,sizeof(uint32_t)); |
ptuytsch | 1204:c87f50212c84 | 205 | } |
ptuytsch | 1204:c87f50212c84 | 206 | // Continious Data |
ptuytsch | 1204:c87f50212c84 | 207 | tmp = bd->getLastCount(); |
ptuytsch | 1204:c87f50212c84 | 208 | if (tmp != pulse){ |
ptuytsch | 1204:c87f50212c84 | 209 | pulse = tmp; |
ptuytsch | 1204:c87f50212c84 | 210 | ble.gattServer().write(pulseChar.getValueHandle(),&pulse,sizeof(uint8_t)); |
ptuytsch | 1204:c87f50212c84 | 211 | } |
ptuytsch | 1204:c87f50212c84 | 212 | tmp = bd->getSpeed()*100; |
ptuytsch | 1204:c87f50212c84 | 213 | if (tmp != speed){ |
ptuytsch | 1204:c87f50212c84 | 214 | speed = tmp; |
ptuytsch | 1204:c87f50212c84 | 215 | ble.gattServer().write(speedChar.getValueHandle(),(uint8_t *)&speed,sizeof(uint32_t)); |
ptuytsch | 1204:c87f50212c84 | 216 | } |
ptuytsch | 1204:c87f50212c84 | 217 | tmp = bd->isLogging()*'5'; |
ptuytsch | 1204:c87f50212c84 | 218 | if (tmp != control){ |
ptuytsch | 1204:c87f50212c84 | 219 | control = tmp; |
ptuytsch | 1204:c87f50212c84 | 220 | ble.gattServer().write(controlChar.getValueHandle(),&control,sizeof(uint8_t)); |
ptuytsch | 1204:c87f50212c84 | 221 | } |
ptuytsch | 1204:c87f50212c84 | 222 | } |
ptuytsch | 1204:c87f50212c84 | 223 | |
ptuytsch | 1204:c87f50212c84 | 224 | public: |
ptuytsch | 1204:c87f50212c84 | 225 | |
ptuytsch | 1204:c87f50212c84 | 226 | //different variables for the service |
ptuytsch | 1204:c87f50212c84 | 227 | BLE &ble; |
ptuytsch | 1204:c87f50212c84 | 228 | BikeData *bd; |
ptuytsch | 1204:c87f50212c84 | 229 | uint32_t tripDistance, tripAverage, tripTime, |
ptuytsch | 1204:c87f50212c84 | 230 | overallDistance, overallAverage, overallTime, |
ptuytsch | 1204:c87f50212c84 | 231 | batChangeDistance, batChangeAverage, batChangeTime, |
ptuytsch | 1204:c87f50212c84 | 232 | speed; |
ptuytsch | 1204:c87f50212c84 | 233 | uint8_t pulse, control; |
ptuytsch | 1204:c87f50212c84 | 234 | |
ptuytsch | 1204:c87f50212c84 | 235 | //the different characteristics created of an template |
ptuytsch | 1204:c87f50212c84 | 236 | ReadOnlyGattCharacteristic<uint32_t> tripDistanceChar; |
ptuytsch | 1204:c87f50212c84 | 237 | ReadOnlyGattCharacteristic<uint32_t> tripAverageChar; |
ptuytsch | 1204:c87f50212c84 | 238 | ReadOnlyGattCharacteristic<uint32_t> tripTimeChar; |
ptuytsch | 1131:5cc818415e2b | 239 | |
ptuytsch | 1204:c87f50212c84 | 240 | ReadOnlyGattCharacteristic<uint32_t> overallDistanceChar; |
ptuytsch | 1204:c87f50212c84 | 241 | ReadOnlyGattCharacteristic<uint32_t> overallAverageChar; |
ptuytsch | 1204:c87f50212c84 | 242 | ReadOnlyGattCharacteristic<uint32_t> overallTimeChar; |
ptuytsch | 1204:c87f50212c84 | 243 | |
ptuytsch | 1204:c87f50212c84 | 244 | ReadOnlyGattCharacteristic<uint32_t> batChangeDistanceChar; |
ptuytsch | 1204:c87f50212c84 | 245 | ReadOnlyGattCharacteristic<uint32_t> batChangeAverageChar; |
ptuytsch | 1204:c87f50212c84 | 246 | ReadOnlyGattCharacteristic<uint32_t> batChangeTimeChar; |
ptuytsch | 1204:c87f50212c84 | 247 | |
ptuytsch | 1204:c87f50212c84 | 248 | ReadOnlyGattCharacteristic<uint8_t> pulseChar; |
ptuytsch | 1204:c87f50212c84 | 249 | ReadOnlyGattCharacteristic<uint32_t> speedChar; |
ptuytsch | 1204:c87f50212c84 | 250 | ReadWriteGattCharacteristic<uint8_t> controlChar; |
ptuytsch | 1205:86f0783a5420 | 251 | |
ptuytsch | 1205:86f0783a5420 | 252 | |
ptuytsch | 1205:86f0783a5420 | 253 | GattCharacteristic *deviceNameChar; |
ptuytsch | 1131:5cc818415e2b | 254 | }; |
ptuytsch | 1131:5cc818415e2b | 255 | |
ptuytsch | 1202:a31d51d9fba8 | 256 | #endif |