AKM Development Platform. This is the D7.014 version.
Dependencies: AK09970 AK099XX AK7401 AK7451 AK8963X AK9750 AK9752 AkmSensor BLE_API I2CNano MCP342x SerialNano SpiNano TCA9554A mbed nRF51822
Fork of AKDP by
Diff: main.cpp
- Revision:
- 10:a710e8c3311c
- Parent:
- 9:90a7650db802
- Child:
- 11:53e52f5f1051
--- a/main.cpp Thu May 26 21:57:18 2016 +0000 +++ b/main.cpp Sat Jun 11 00:18:38 2016 +0000 @@ -12,8 +12,8 @@ #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */ #define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */ -//#define TXRX_LEN UARTService::BLE_UART_SERVICE_MAX_DATA_LEN+1 -#define TXRX_LEN 50 // Temp +#define BLE_BUF_LEN UARTService::BLE_UART_SERVICE_MAX_DATA_LEN+1 +#define TXRX_LEN 50 #define CR '\r' #define LF '\n' @@ -28,80 +28,44 @@ AkmSensorManager* manager; -static char commandStr[TXRX_LEN]; -static uint16_t rx_len=0; - -/* void WrittenHandler(const GattWriteCallbackParams *Handler) { - uint8_t buf[TXRX_LEN]; + static char command[TXRX_LEN]=""; + static uint16_t len=0; + + uint8_t buf[BLE_BUF_LEN]; uint16_t bytesRead; + if (Handler->handle == uartService->getTXCharacteristicHandle()) { ble.gattServer().read(uartService->getTXCharacteristicHandle(), buf, &bytesRead); - int len = 0; - for(int i=0; i<bytesRead; i++){ - commandStr[len++] = buf[i]; - if(i>=TXRX_LEN || buf[i]==LF ) + + for(uint16_t i=0; i<bytesRead; i++){ + if(buf[i] == CR) + { + ; // ignore CR + } + else if(buf[i] == LF || len > TXRX_LEN) { - manager->commandReceived(commandStr); - return; + manager->commandReceived(command); + for(int j=0; j<TXRX_LEN; j++){ + command[j] = 0; + } + len = 0; + } + else + { + command[len++] = (char)buf[i]; } } } } -*/ -void WrittenHandler(const GattWriteCallbackParams *Handler) -{ - uint8_t buf[TXRX_LEN]; - uint16_t bytesRead; - - if (Handler->handle == uartService->getTXCharacteristicHandle()) - { - ble.gattServer().read(uartService->getTXCharacteristicHandle(), buf, &bytesRead); - char command[TXRX_LEN]; - int len = 0; - for(int i=0; i<bytesRead; i++){ - if(i>=TXRX_LEN || buf[i]==CR ) - { - break; - } - else - { - if(buf[i] != LF) - { - command[len++] = (char)buf[i]; - } - } - } - manager->commandReceived(command); - } -} - - -/* void usbUartCallback(void) { - if(serial.readable()) - { - uint8_t c = serial.getc(); - if(rx_len>=TXRX_LEN || c == CR ) - { - manager->commandReceived(commandStr); - rx_len = 0; - } - else{ - if(c != LF) - { - commandStr[rx_len++] = c; - } - } - } -} -*/ -void usbUartCallback(void) -{ + static char command[TXRX_LEN] = ""; + static uint16_t len=0; + if(serial.readable()) { uint8_t c = serial.getc(); @@ -109,11 +73,14 @@ // ignore CR if(c==CR) return; - commandStr[rx_len++] = c; - if(rx_len>=TXRX_LEN || c == LF) + command[len++] = c; + if(len>=TXRX_LEN || c == LF) { - manager->commandReceived(commandStr); - rx_len = 0; + manager->commandReceived(command); + for(int j=0; j<TXRX_LEN; j++){ + command[j] = 0; + } + len = 0; } } } @@ -121,13 +88,13 @@ void connectionCallback(const Gap::ConnectionCallbackParams_t *params) { manager->setEventConnected(); - MSG("#Connected\r\n"); + MSG("#Connected\n"); } void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { manager->setEventDisconnected(); - MSG("#Disconnected \r\n"); + MSG("#Disconnected\n"); ble.gap().startAdvertising(); }