void rs_ble_process(void) { while (ble_available()) { byte cmd; cmd = ble_read(); Serial.write(cmd); // Parse data here switch (cmd) { case 'V': // query protocol version { byte buf[] = {'V', PROTOCOL_MAJOR, PROTOCOL_MINOR, PROTOCOL_BUGFIX}; ble_write_string(buf, 4); } break; // send out any outstanding data ble_do_events(); buf_len = 0; return; // only do this task in this loop } // process text data if (Serial.available()) { byte d = 'Z'; ble_write(d); delay(5); while (Serial.available()) { d = Serial.read(); ble_write(d); } ble_do_events(); buf_len = 0; return; } ble_do_events(); buf_len = 0; } }
void ble_write_string(byte *bytes, uint8_t len) { int j; if (buf_len + len > 20) { for (j = 0; j < 15000; j++) ble_do_events(); buf_len = 0; } for (j = 0; j < len; j++) { ble_write(bytes[j]); buf_len++; } if (buf_len == 20) { for (j = 0; j < 15000; j++) ble_do_events(); buf_len = 0; } }
void beaconSendData(){ int carrier; char sendCharArray[14]; if (Serial.available()){ delay(5); while (Serial.available()){ carrier = Serial.read(); ble_write ( carrier ); } } ble_do_events(); }
void ble_write_bytes(unsigned char *data, uint8_t len) { for (int i = 0; i < len; i++) ble_write(data[i]); }