![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CAN to BLE translator - and back
Dependencies: BLE_API CANnucleo X_NUCLEO_IDB0XA1 mbed
main.cpp@3:5bce2e8d2797, 2016-04-08 (annotated)
- Committer:
- filippomontano
- Date:
- Fri Apr 08 12:21:07 2016 +0000
- Revision:
- 3:5bce2e8d2797
- Parent:
- 2:bfe8810290ac
- Child:
- 4:8c2cd88d2545
CAN to BLE Now is working!!! - missing disconnection callback
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
filippomontano | 0:345c72cbcd60 | 1 | #include "mbed.h" |
filippomontano | 0:345c72cbcd60 | 2 | #include "ble/BLE.h" |
filippomontano | 0:345c72cbcd60 | 3 | #include "CAN.h" |
filippomontano | 0:345c72cbcd60 | 4 | |
filippomontano | 3:5bce2e8d2797 | 5 | #define TARGET_NUCLEO_F072RB 1 |
filippomontano | 0:345c72cbcd60 | 6 | #define LED_PIN PA_5 |
filippomontano | 0:345c72cbcd60 | 7 | |
filippomontano | 3:5bce2e8d2797 | 8 | #define BLE_GATT_CHAR_PROPERTIES_NOTIFY 0x10 |
filippomontano | 3:5bce2e8d2797 | 9 | |
filippomontano | 0:345c72cbcd60 | 10 | uint8_t CANId2BLESlot(unsigned int id); |
filippomontano | 0:345c72cbcd60 | 11 | unsigned int BLESlot2CANId(uint8_t id); |
filippomontano | 0:345c72cbcd60 | 12 | void onMsgReceived(void); |
filippomontano | 0:345c72cbcd60 | 13 | void initCAN(void); |
filippomontano | 0:345c72cbcd60 | 14 | |
filippomontano | 3:5bce2e8d2797 | 15 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params); |
filippomontano | 3:5bce2e8d2797 | 16 | void writeCharCallback(const GattWriteCallbackParams *params); |
filippomontano | 3:5bce2e8d2797 | 17 | void bleInitComplete(BLE::InitializationCompleteCallbackContext *params); |
filippomontano | 3:5bce2e8d2797 | 18 | void onBleInitError(BLE &ble, ble_error_t error); |
filippomontano | 3:5bce2e8d2797 | 19 | void initBLE(void); |
filippomontano | 0:345c72cbcd60 | 20 | |
filippomontano | 0:345c72cbcd60 | 21 | |
filippomontano | 3:5bce2e8d2797 | 22 | DigitalOut led(LED_PIN),CAN_show(PC_12); |
filippomontano | 3:5bce2e8d2797 | 23 | |
filippomontano | 3:5bce2e8d2797 | 24 | |
filippomontano | 3:5bce2e8d2797 | 25 | const static char DEVICE_NAME[] = "STNucleo - RGM - FM"; |
filippomontano | 3:5bce2e8d2797 | 26 | static const uint16_t uuid16_list[] = {0xFFFF}; |
filippomontano | 3:5bce2e8d2797 | 27 | |
filippomontano | 0:345c72cbcd60 | 28 | //const unsigned int RX_ID = 0x10; |
filippomontano | 0:345c72cbcd60 | 29 | //const unsigned int TX_ID = 0x11; |
filippomontano | 0:345c72cbcd60 | 30 | |
filippomontano | 0:345c72cbcd60 | 31 | char shareddata[64][8]= { }; |
filippomontano | 0:345c72cbcd60 | 32 | |
filippomontano | 0:345c72cbcd60 | 33 | uint8_t canWrPointer= 255; |
filippomontano | 0:345c72cbcd60 | 34 | uint8_t canRdPointer= 255; |
filippomontano | 0:345c72cbcd60 | 35 | uint8_t bleWrPointerA= 255; |
filippomontano | 0:345c72cbcd60 | 36 | uint8_t bleRdPointerA= 255; |
filippomontano | 0:345c72cbcd60 | 37 | uint8_t bleWrPointerB= 255; |
filippomontano | 0:345c72cbcd60 | 38 | uint8_t bleRdPointerB= 255; |
filippomontano | 0:345c72cbcd60 | 39 | |
filippomontano | 3:5bce2e8d2797 | 40 | const uint8_t firstBleRdPointer=1; |
filippomontano | 3:5bce2e8d2797 | 41 | const uint8_t lastBleRdPointer=14; |
filippomontano | 3:5bce2e8d2797 | 42 | |
filippomontano | 3:5bce2e8d2797 | 43 | const uint8_t firstCanRdPointer=62; |
filippomontano | 3:5bce2e8d2797 | 44 | const uint8_t lastCanRdPointer=63; |
filippomontano | 3:5bce2e8d2797 | 45 | |
filippomontano | 3:5bce2e8d2797 | 46 | uint8_t canRdLastPointer= 255; // puntatore per sapere che cosa ho mandato per ultimo. a runtime devo andare a modificarlo per sapere al ciclo dopo cosa ho già mandato |
filippomontano | 3:5bce2e8d2797 | 47 | uint8_t bleRdLastPointer= 255; // puntatore per sapere che cosa ho mandato per ultimo. a runtime devo andare a modificarlo per sapere al ciclo dopo cosa ho già mandato |
filippomontano | 3:5bce2e8d2797 | 48 | |
filippomontano | 3:5bce2e8d2797 | 49 | Timer timerA; //questo contatoro serve solo per dire: appena è passato un po' di tempo -> esegui |
filippomontano | 0:345c72cbcd60 | 50 | |
filippomontano | 2:bfe8810290ac | 51 | //CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name |
filippomontano | 0:345c72cbcd60 | 52 | CANMessage rxMsg; |
filippomontano | 0:345c72cbcd60 | 53 | CANMessage txMsg; |
filippomontano | 0:345c72cbcd60 | 54 | |
filippomontano | 3:5bce2e8d2797 | 55 | BLE ble; |
filippomontano | 3:5bce2e8d2797 | 56 | |
filippomontano | 3:5bce2e8d2797 | 57 | uint16_t customServiceUUID = 0xA000; // service UUID |
filippomontano | 3:5bce2e8d2797 | 58 | uint16_t readCharUUID = 0xA001; // read characteristic UUID |
filippomontano | 3:5bce2e8d2797 | 59 | uint16_t writeCharUUID = 0xA002; // write characteristic UUID |
filippomontano | 3:5bce2e8d2797 | 60 | |
filippomontano | 3:5bce2e8d2797 | 61 | static uint8_t readValue[128] = {0}; |
filippomontano | 3:5bce2e8d2797 | 62 | |
filippomontano | 3:5bce2e8d2797 | 63 | //static uint8_t readValue[6]="HELLO"; |
filippomontano | 3:5bce2e8d2797 | 64 | |
filippomontano | 3:5bce2e8d2797 | 65 | |
filippomontano | 3:5bce2e8d2797 | 66 | ReadOnlyArrayGattCharacteristic<uint8_t, sizeof(readValue)> readChar(readCharUUID, readValue, BLE_GATT_CHAR_PROPERTIES_NOTIFY , NULL,0); //aggiunto il BLE_GATT_CHAR_PROPERTIES_NOTIFY => appena arriva lo rimanda |
filippomontano | 3:5bce2e8d2797 | 67 | |
filippomontano | 3:5bce2e8d2797 | 68 | static uint8_t writeValue[128] = {0}; |
filippomontano | 3:5bce2e8d2797 | 69 | WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(writeValue)> writeChar(writeCharUUID, writeValue); |
filippomontano | 3:5bce2e8d2797 | 70 | |
filippomontano | 3:5bce2e8d2797 | 71 | GattCharacteristic *characteristics[] = {&readChar, &writeChar}; |
filippomontano | 3:5bce2e8d2797 | 72 | GattService customService(customServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *)); |
filippomontano | 3:5bce2e8d2797 | 73 | uint8_t retry=1; |
filippomontano | 3:5bce2e8d2797 | 74 | uint8_t readdata[20]= {}; |
filippomontano | 3:5bce2e8d2797 | 75 | char symbol=' '; |
filippomontano | 0:345c72cbcd60 | 76 | volatile bool CANmsgAvailable = false; |
filippomontano | 3:5bce2e8d2797 | 77 | volatile bool BLExmit = false; |
filippomontano | 3:5bce2e8d2797 | 78 | float stopTimer=2.0; |
filippomontano | 0:345c72cbcd60 | 79 | |
filippomontano | 0:345c72cbcd60 | 80 | int main() |
filippomontano | 0:345c72cbcd60 | 81 | { |
filippomontano | 3:5bce2e8d2797 | 82 | uint8_t j=0,k=firstBleRdPointer; |
filippomontano | 3:5bce2e8d2797 | 83 | // printf("\r\nBoard started\r\n"); |
filippomontano | 0:345c72cbcd60 | 84 | led = 1; // turn LED on |
filippomontano | 3:5bce2e8d2797 | 85 | CAN_show=1; |
filippomontano | 3:5bce2e8d2797 | 86 | |
filippomontano | 3:5bce2e8d2797 | 87 | bleRdLastPointer=lastBleRdPointer; |
filippomontano | 3:5bce2e8d2797 | 88 | BLE::Instance().init(bleInitComplete); |
filippomontano | 3:5bce2e8d2797 | 89 | CAN can(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name |
filippomontano | 3:5bce2e8d2797 | 90 | CAN_show=0; |
filippomontano | 3:5bce2e8d2797 | 91 | |
filippomontano | 3:5bce2e8d2797 | 92 | //canRdLastPointer=lastCanRdPointer; |
filippomontano | 3:5bce2e8d2797 | 93 | can.frequency(500000); // set bit rate to 500kbps as S018 |
filippomontano | 3:5bce2e8d2797 | 94 | printf("\r\nCAN started at 500kbps\r\n"); |
filippomontano | 0:345c72cbcd60 | 95 | timerA.start(); |
filippomontano | 3:5bce2e8d2797 | 96 | can.attach(&onMsgReceived, CAN::RxIrq); // attach 'CAN receive-complete' interrupt handler |
filippomontano | 3:5bce2e8d2797 | 97 | |
filippomontano | 3:5bce2e8d2797 | 98 | while(true) { |
filippomontano | 3:5bce2e8d2797 | 99 | if(ble.getGapState().connected) { |
filippomontano | 3:5bce2e8d2797 | 100 | stopTimer=0.2; |
filippomontano | 3:5bce2e8d2797 | 101 | symbol='!'; |
filippomontano | 3:5bce2e8d2797 | 102 | |
filippomontano | 3:5bce2e8d2797 | 103 | |
filippomontano | 3:5bce2e8d2797 | 104 | } else { |
filippomontano | 3:5bce2e8d2797 | 105 | stopTimer=3; |
filippomontano | 3:5bce2e8d2797 | 106 | ble.waitForEvent(); |
filippomontano | 3:5bce2e8d2797 | 107 | symbol='.'; |
filippomontano | 3:5bce2e8d2797 | 108 | } |
filippomontano | 3:5bce2e8d2797 | 109 | |
filippomontano | 3:5bce2e8d2797 | 110 | if(timerA.read()>=stopTimer) { |
filippomontano | 3:5bce2e8d2797 | 111 | BLExmit=ble.getGapState().connected; |
filippomontano | 0:345c72cbcd60 | 112 | timerA.stop(); |
filippomontano | 0:345c72cbcd60 | 113 | timerA.reset(); |
filippomontano | 0:345c72cbcd60 | 114 | led=!led.read(); |
filippomontano | 3:5bce2e8d2797 | 115 | printf("%c\r\n",symbol); |
filippomontano | 0:345c72cbcd60 | 116 | timerA.start(); |
filippomontano | 3:5bce2e8d2797 | 117 | |
filippomontano | 0:345c72cbcd60 | 118 | } |
filippomontano | 0:345c72cbcd60 | 119 | if(CANmsgAvailable) { |
filippomontano | 0:345c72cbcd60 | 120 | CANmsgAvailable = false; // reset flag for next use |
filippomontano | 0:345c72cbcd60 | 121 | can.read(rxMsg); // read message into Rx message storage |
filippomontano | 0:345c72cbcd60 | 122 | j=CANId2BLESlot(rxMsg.id); |
filippomontano | 0:345c72cbcd60 | 123 | if(j!=bleRdPointerA && j!=bleRdPointerB) { |
filippomontano | 3:5bce2e8d2797 | 124 | |
filippomontano | 0:345c72cbcd60 | 125 | for(int i = 0; i < rxMsg.len; i++) { |
filippomontano | 0:345c72cbcd60 | 126 | shareddata[j][i]=rxMsg.data[i]; |
filippomontano | 3:5bce2e8d2797 | 127 | // printf(" %x", rxMsg.data[i]); |
filippomontano | 0:345c72cbcd60 | 128 | } |
filippomontano | 3:5bce2e8d2797 | 129 | // printf("#"); |
filippomontano | 3:5bce2e8d2797 | 130 | |
filippomontano | 0:345c72cbcd60 | 131 | } |
filippomontano | 3:5bce2e8d2797 | 132 | } |
filippomontano | 3:5bce2e8d2797 | 133 | if(BLExmit) { |
filippomontano | 3:5bce2e8d2797 | 134 | BLExmit=false; |
filippomontano | 3:5bce2e8d2797 | 135 | retry++; |
filippomontano | 3:5bce2e8d2797 | 136 | if(retry==0xff) ble.gap().startAdvertising(); |
filippomontano | 3:5bce2e8d2797 | 137 | printf ("%x ",retry); |
filippomontano | 3:5bce2e8d2797 | 138 | printf("@"); |
filippomontano | 3:5bce2e8d2797 | 139 | k++; |
filippomontano | 3:5bce2e8d2797 | 140 | if(k>lastBleRdPointer) |
filippomontano | 3:5bce2e8d2797 | 141 | k=firstBleRdPointer; |
filippomontano | 3:5bce2e8d2797 | 142 | readValue[0]=k; |
filippomontano | 3:5bce2e8d2797 | 143 | for(int i=1; i<8; i++) { |
filippomontano | 3:5bce2e8d2797 | 144 | readValue[i]=shareddata[k][i]; |
filippomontano | 0:345c72cbcd60 | 145 | } |
filippomontano | 3:5bce2e8d2797 | 146 | for(int i=0; i<8; i++) { |
filippomontano | 3:5bce2e8d2797 | 147 | printf ("%x",readValue[i]); |
filippomontano | 3:5bce2e8d2797 | 148 | } |
filippomontano | 3:5bce2e8d2797 | 149 | ble.updateCharacteristicValue(readChar.getValueHandle(), readValue,9); |
filippomontano | 3:5bce2e8d2797 | 150 | |
filippomontano | 3:5bce2e8d2797 | 151 | |
filippomontano | 0:345c72cbcd60 | 152 | } |
filippomontano | 0:345c72cbcd60 | 153 | } |
filippomontano | 0:345c72cbcd60 | 154 | } |
filippomontano | 3:5bce2e8d2797 | 155 | |
filippomontano | 3:5bce2e8d2797 | 156 | void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) |
filippomontano | 0:345c72cbcd60 | 157 | { |
filippomontano | 3:5bce2e8d2797 | 158 | BLE& ble = params->ble; |
filippomontano | 3:5bce2e8d2797 | 159 | ble_error_t error = params->error; |
filippomontano | 3:5bce2e8d2797 | 160 | |
filippomontano | 3:5bce2e8d2797 | 161 | if (error != BLE_ERROR_NONE) { |
filippomontano | 3:5bce2e8d2797 | 162 | onBleInitError(ble, error); |
filippomontano | 3:5bce2e8d2797 | 163 | return; |
filippomontano | 3:5bce2e8d2797 | 164 | } |
filippomontano | 3:5bce2e8d2797 | 165 | |
filippomontano | 3:5bce2e8d2797 | 166 | if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { |
filippomontano | 3:5bce2e8d2797 | 167 | return; |
filippomontano | 3:5bce2e8d2797 | 168 | } |
filippomontano | 3:5bce2e8d2797 | 169 | |
filippomontano | 3:5bce2e8d2797 | 170 | ble.gap().onDisconnection(disconnectionCallback); |
filippomontano | 3:5bce2e8d2797 | 171 | |
filippomontano | 3:5bce2e8d2797 | 172 | /* Setup primary service. */ |
filippomontano | 3:5bce2e8d2797 | 173 | |
filippomontano | 3:5bce2e8d2797 | 174 | /* Setup advertising. */ |
filippomontano | 3:5bce2e8d2797 | 175 | printf("Setup of Advertising\r\n"); |
filippomontano | 3:5bce2e8d2797 | 176 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
filippomontano | 3:5bce2e8d2797 | 177 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); |
filippomontano | 3:5bce2e8d2797 | 178 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); |
filippomontano | 3:5bce2e8d2797 | 179 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
filippomontano | 3:5bce2e8d2797 | 180 | ble.gap().setAdvertisingInterval(1000);// 1000ms |
filippomontano | 3:5bce2e8d2797 | 181 | ble.gap().startAdvertising(); |
filippomontano | 3:5bce2e8d2797 | 182 | ble.onDataWritten(writeCharCallback); |
filippomontano | 3:5bce2e8d2797 | 183 | ble.addService(customService); |
filippomontano | 3:5bce2e8d2797 | 184 | |
filippomontano | 3:5bce2e8d2797 | 185 | printf("Starting Loop\r\n"); |
filippomontano | 3:5bce2e8d2797 | 186 | |
filippomontano | 3:5bce2e8d2797 | 187 | |
filippomontano | 3:5bce2e8d2797 | 188 | } |
filippomontano | 3:5bce2e8d2797 | 189 | void onBleInitError(BLE &ble, ble_error_t error) |
filippomontano | 3:5bce2e8d2797 | 190 | { |
filippomontano | 3:5bce2e8d2797 | 191 | (void)ble; |
filippomontano | 3:5bce2e8d2797 | 192 | (void)error; |
filippomontano | 3:5bce2e8d2797 | 193 | printf(" ### BLE init error ###\r\n"); |
filippomontano | 3:5bce2e8d2797 | 194 | |
filippomontano | 3:5bce2e8d2797 | 195 | |
filippomontano | 3:5bce2e8d2797 | 196 | /* Initialization error handling should go here */ |
filippomontano | 0:345c72cbcd60 | 197 | } |
filippomontano | 0:345c72cbcd60 | 198 | void onMsgReceived(void) |
filippomontano | 0:345c72cbcd60 | 199 | { |
filippomontano | 0:345c72cbcd60 | 200 | CANmsgAvailable = true; |
filippomontano | 0:345c72cbcd60 | 201 | } |
filippomontano | 0:345c72cbcd60 | 202 | uint8_t CANId2BLESlot(unsigned int id) |
filippomontano | 0:345c72cbcd60 | 203 | { |
filippomontano | 0:345c72cbcd60 | 204 | uint8_t retval=0; |
filippomontano | 0:345c72cbcd60 | 205 | switch(id) { |
filippomontano | 0:345c72cbcd60 | 206 | case 0x313: |
filippomontano | 0:345c72cbcd60 | 207 | retval=1; |
filippomontano | 0:345c72cbcd60 | 208 | break; |
filippomontano | 0:345c72cbcd60 | 209 | case 0x314: |
filippomontano | 0:345c72cbcd60 | 210 | retval=2; |
filippomontano | 0:345c72cbcd60 | 211 | break; |
filippomontano | 0:345c72cbcd60 | 212 | case 0x310: |
filippomontano | 0:345c72cbcd60 | 213 | retval=3; |
filippomontano | 0:345c72cbcd60 | 214 | break; |
filippomontano | 0:345c72cbcd60 | 215 | case 0x315: |
filippomontano | 0:345c72cbcd60 | 216 | retval=4; |
filippomontano | 0:345c72cbcd60 | 217 | break; |
filippomontano | 0:345c72cbcd60 | 218 | case 0x111: |
filippomontano | 0:345c72cbcd60 | 219 | retval=5; |
filippomontano | 0:345c72cbcd60 | 220 | break; |
filippomontano | 0:345c72cbcd60 | 221 | case 0x112: |
filippomontano | 0:345c72cbcd60 | 222 | retval=6; |
filippomontano | 0:345c72cbcd60 | 223 | break; |
filippomontano | 0:345c72cbcd60 | 224 | case 0x400: |
filippomontano | 0:345c72cbcd60 | 225 | retval=7; |
filippomontano | 0:345c72cbcd60 | 226 | break; |
filippomontano | 0:345c72cbcd60 | 227 | case 0x450: |
filippomontano | 0:345c72cbcd60 | 228 | retval=8; |
filippomontano | 0:345c72cbcd60 | 229 | break; |
filippomontano | 0:345c72cbcd60 | 230 | case 0x451: |
filippomontano | 0:345c72cbcd60 | 231 | retval=9; |
filippomontano | 0:345c72cbcd60 | 232 | break; |
filippomontano | 0:345c72cbcd60 | 233 | case 0x452: |
filippomontano | 0:345c72cbcd60 | 234 | retval=10; |
filippomontano | 0:345c72cbcd60 | 235 | break; |
filippomontano | 0:345c72cbcd60 | 236 | case 0x453: |
filippomontano | 0:345c72cbcd60 | 237 | retval=11; |
filippomontano | 0:345c72cbcd60 | 238 | break; |
filippomontano | 0:345c72cbcd60 | 239 | case 0x454: |
filippomontano | 0:345c72cbcd60 | 240 | retval=12; |
filippomontano | 0:345c72cbcd60 | 241 | break; |
filippomontano | 0:345c72cbcd60 | 242 | case 0x455: |
filippomontano | 0:345c72cbcd60 | 243 | retval=13; |
filippomontano | 0:345c72cbcd60 | 244 | break; |
filippomontano | 0:345c72cbcd60 | 245 | default: |
filippomontano | 0:345c72cbcd60 | 246 | retval=0; |
filippomontano | 0:345c72cbcd60 | 247 | break; |
filippomontano | 0:345c72cbcd60 | 248 | } |
filippomontano | 0:345c72cbcd60 | 249 | return retval; |
filippomontano | 0:345c72cbcd60 | 250 | } |
filippomontano | 0:345c72cbcd60 | 251 | unsigned int BLESlot2CANId(uint8_t id) |
filippomontano | 0:345c72cbcd60 | 252 | { |
filippomontano | 0:345c72cbcd60 | 253 | unsigned int retval=0; |
filippomontano | 0:345c72cbcd60 | 254 | switch(id) { |
filippomontano | 0:345c72cbcd60 | 255 | case 63: |
filippomontano | 0:345c72cbcd60 | 256 | retval=0x303; |
filippomontano | 0:345c72cbcd60 | 257 | break; |
filippomontano | 0:345c72cbcd60 | 258 | case 62: |
filippomontano | 0:345c72cbcd60 | 259 | retval=0x304; |
filippomontano | 0:345c72cbcd60 | 260 | break; |
filippomontano | 0:345c72cbcd60 | 261 | default: |
filippomontano | 0:345c72cbcd60 | 262 | retval=0x0; |
filippomontano | 0:345c72cbcd60 | 263 | break; |
filippomontano | 0:345c72cbcd60 | 264 | } |
filippomontano | 0:345c72cbcd60 | 265 | return retval; |
filippomontano | 3:5bce2e8d2797 | 266 | } |
filippomontano | 3:5bce2e8d2797 | 267 | |
filippomontano | 3:5bce2e8d2797 | 268 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) |
filippomontano | 3:5bce2e8d2797 | 269 | { |
filippomontano | 3:5bce2e8d2797 | 270 | (void)params; |
filippomontano | 3:5bce2e8d2797 | 271 | printf("\r\nTarget loss... wait for reconnection \r\n"); |
filippomontano | 3:5bce2e8d2797 | 272 | |
filippomontano | 3:5bce2e8d2797 | 273 | BLE::Instance().gap().startAdvertising(); // restart advertising |
filippomontano | 3:5bce2e8d2797 | 274 | } |
filippomontano | 3:5bce2e8d2797 | 275 | |
filippomontano | 3:5bce2e8d2797 | 276 | void writeCharCallback(const GattWriteCallbackParams *params) |
filippomontano | 3:5bce2e8d2797 | 277 | { |
filippomontano | 3:5bce2e8d2797 | 278 | |
filippomontano | 3:5bce2e8d2797 | 279 | uint8_t j=0; |
filippomontano | 3:5bce2e8d2797 | 280 | |
filippomontano | 3:5bce2e8d2797 | 281 | // check to see what characteristic was written, by handle |
filippomontano | 3:5bce2e8d2797 | 282 | if(params->handle == writeChar.getValueHandle()) { |
filippomontano | 3:5bce2e8d2797 | 283 | BLESlot2CANId(params->data[0]); |
filippomontano | 3:5bce2e8d2797 | 284 | printf("\n\r Data received: length = %d, data = ",params->len); |
filippomontano | 3:5bce2e8d2797 | 285 | if(canRdPointer != j && canRdPointer != j+1) { |
filippomontano | 3:5bce2e8d2797 | 286 | bleWrPointerA=j; |
filippomontano | 3:5bce2e8d2797 | 287 | bleWrPointerB=j+1; |
filippomontano | 3:5bce2e8d2797 | 288 | for(int x=0; x < 9; x++) { |
filippomontano | 3:5bce2e8d2797 | 289 | printf("%c",params->data[x]); |
filippomontano | 3:5bce2e8d2797 | 290 | shareddata[j][x]=params->data[x]; |
filippomontano | 3:5bce2e8d2797 | 291 | } |
filippomontano | 3:5bce2e8d2797 | 292 | for(int x=9; x < 18; x++) { |
filippomontano | 3:5bce2e8d2797 | 293 | printf("%c",params->data[x]); |
filippomontano | 3:5bce2e8d2797 | 294 | shareddata[j+1][x-9]=params->data[x]; |
filippomontano | 3:5bce2e8d2797 | 295 | } |
filippomontano | 3:5bce2e8d2797 | 296 | bleWrPointerA=255; |
filippomontano | 3:5bce2e8d2797 | 297 | bleWrPointerB=255; |
filippomontano | 3:5bce2e8d2797 | 298 | } |
filippomontano | 3:5bce2e8d2797 | 299 | } |
filippomontano | 3:5bce2e8d2797 | 300 | } |