![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BLEUART
Fork of 0925BLEonly by
Diff: main.cpp
- Revision:
- 3:837f3a27c2f7
- Parent:
- 2:0d84e066f294
- Child:
- 4:d1480d298d7f
--- a/main.cpp Fri Sep 29 07:31:44 2017 +0000 +++ b/main.cpp Fri Sep 29 08:19:19 2017 +0000 @@ -16,6 +16,9 @@ #include "mbed.h" #include "ble/BLE.h" +#include <stdio.h> +#include <string.h> + #include "ble/services/UARTService.h" @@ -40,7 +43,7 @@ uint8_t state; uint8_t open; - uint8_t longble[120]; + uint8_t longble[255]; uint8_t lb=0 ; UARTService *uartServicePtr; @@ -74,29 +77,46 @@ // uint16_t bytesRead = params->len; DEBUG("received %u bytes\n\r", bytesRead); ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, params->len);// uint16_t bytesRead = params->len; - uint8_t x=0; if(((*(params->data))=='<')&&((*(params->data+1))=='S')&&((*(params->data+2))=='>')){ // <S> lb=0; - memset(longble,'\0',60); - // x=3; - } + memset(longble,'\0',sizeof(longble)); + + } + if(((*(params->data))=='<')&&((*(params->data+1))=='E')&&((*(params->data+2))=='>')){ // <E> + char buf[255]; + char *ptr1,*ptr2; + int n,len1=3,len2=3; + + ptr1 = strstr(longble,"<S>") + len1; + ptr2 = strstr(ptr1,"<E>"); + n=strlen(longble)-len1-len2; + strncpy(buf,ptr1,n); + buf[n]='\0'; + pc.printf("%s\n",buf); + + +// uint8_t *a; +// a=longble; +// a+=3; + // longble=a; + pc.printf("%S\r\n",longble) ; + pc.printf("%d\r\n",(sizeof(longble))) ; + } uint8_t blein[params->len]; - for(uint8_t count=0 ; count<((params->len)+x) ; ++count){ //取得藍芽資料 + for(uint8_t count=0 ; count<((params->len)) ; ++count){ //取得藍芽資料 blein[count]= *((params->data)+count); - longble[count+lb]= *((params->data)+count+x); + longble[count+lb]= *((params->data)+count); } //x=0; lb+=(params->len); if(lb>110) lb=0; - // <<|>> - // >>|<< + // uint8_t *a; // uint8_t test[] = "OPEN"; // a = longble; //ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), a, 20); - if(((*(params->data))=='<')&&((*(params->data+1))=='E')&&((*(params->data+2))=='>')) // <E> - pc.printf("%S\r\n",longble) ; + //ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, params->len);// uint16_t bytesRead = params->len; //uint8_t test[] = "123456789012345678901";