Hsieh JenYun
/
test
BLEUART
Fork of 0925BLEonly by
Diff: main.cpp
- Revision:
- 1:5d6887b45ff6
- Parent:
- 0:f6f2880bef7f
- Child:
- 2:0d84e066f294
--- a/main.cpp Tue Sep 26 02:19:35 2017 +0000 +++ b/main.cpp Fri Sep 29 06:57:49 2017 +0000 @@ -39,6 +39,9 @@ InterruptIn button1(P0_11); uint8_t state; uint8_t open; + + uint8_t longble[120]; + uint8_t lb=0 ; UARTService *uartServicePtr; @@ -70,42 +73,41 @@ if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) { // 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 blein[params->len]; - for(uint8_t count=0 ; count<(params->len) ; ++count){ //取得藍芽資料 + 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; + } + uint8_t blein[params->len]; + for(uint8_t count=0 ; count<((params->len)-x) ; ++count){ //取得藍芽資料 blein[count]= *((params->data)+count); + longble[count+lb]= *((params->data)+count+x); } - uint8_t *a; - if((blein[0]=='A') && (state==0)){ - uint8_t test[] = "OPEN"; - a = test; - ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), a, 4); - state=1; - open=1; - // led2=0; - //opendoor(); - } - else if((blein[0]=='B') && (state==1)){ - uint8_t test[] = "TAKE"; - a = test; - ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), a, 4); - state=0; - open=1; - // led2=1; - //opendoor(); - } - else{ - ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, params->len);// uint16_t bytesRead = params->len; - } + 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"; // uint8_t *a; //a = test; - // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), a, params->len); + // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), a, params->len); } } void button1_pressed() -{ +{ + } void periodicCallback(void)