CdsLibに対応したMSC
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleChat by
Diff: main.cpp
- Revision:
- 4:ddf414d64ea9
- Parent:
- 3:175ba3a059cb
- Child:
- 5:29b82cc045b6
--- a/main.cpp Mon Feb 29 07:05:55 2016 +0000 +++ b/main.cpp Sat Dec 03 03:22:17 2016 +0000 @@ -27,6 +27,7 @@ #include "mbed.h" #include "ble/BLE.h" #include <string.h> + //#include <stdio.h> @@ -44,11 +45,18 @@ // The Nordic UART Service -static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; -static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; -static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; -static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71}; +//static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; +//static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; +//static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; +//static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71}; +// Send One CLK Service +static const uint8_t uart_base_uuid[] = {0x53, 0xF3, 0xF5, 0x38, 0x8D, 0x11, 0x48, 0x02, 0xB6, 0xFC, 0xFB, 0x66, 0x16, 0xD4, 0xCD, 0x7C}; //Service +static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_送信用 +static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_受信用 +static const uint8_t uart_base_uuid_rev[] = {0x7C, 0xCD, 0xD4, 0x16, 0x66, 0xFB, 0xFC, 0xB6, 0x02, 0x48, 0x11, 0x8D, 0x38, 0xF5, 0xF3, 0x53}; + +//aaaaaaaaaaaaaaa uint8_t txPayload[TXRX_BUF_LEN] = {0,}; uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; @@ -56,7 +64,11 @@ static uint8_t rx_buf[TXRX_BUF_LEN]; static uint8_t rx_len=0; static uint8_t rx_buf_st[20]; -//static int st = 0; + +int8_t buf_before[40]; + +static int st = 0; + GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); @@ -76,49 +88,13 @@ void onScanCallback(const Gap::AdvertisementCallbackParams_t *params) { - - -//#if NEED_CONSOLE_OUTPUT -// DEBUG("onScan() "); -// DEBUG("RSSI:%d ",params->rssi); -// DEBUG("Addr:%d ",params->peerAddr); -// DEBUG("Len:%d ",params->advertisingDataLen); -// DEBUG("Data:"); -// for (int i=0; i< params->advertisingDataLen; i++){ -// DEBUG("%02x,",params->advertisingData[i]); -// } - //rx_buf_st[0] = params->rssi; - uint8_t bufbuf[40]; - char bufbuf_c[20]; - char bufbuf_addr[20]; - sprintf(bufbuf_c, "%d", params->rssi); + //printf("onScanNau\n"); + +// printf("adv peerAddr[%d %d %d %d %d %d] rssi %d, isScanResponse %u, AdvertisementType %u\r\n", - //strcat(bufbuf_c, '¥0'); - int a; - for(a=0; bufbuf_c[a] != '\0'; a++) { - bufbuf[a] = bufbuf_c[a]; - } - bufbuf[a] = ','; - a++; - int b; -// for(b=5; b >= 0; b--) { -// sprintf(bufbuf_addr,"%02x",params->peerAddr[b]); -// bufbuf[a] = bufbuf_addr[b]; -// memset(bufbuf_addr,NULL,sizeof(bufbuf_addr)); -// bufbuf[a++] = ','; -// a++; -// } - for(b=5; b >= 0; b--) { - // sprintf(bufbuf_addr,"%02x",params->peerAddr[b]); - bufbuf[a] = params->peerAddr[b];//bufbuf_addr[b]; - // memset(bufbuf_addr,'\0',sizeof(bufbuf_addr)); - a++; - } - - ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), bufbuf, a); - +//だいじ +/* printf("adv peerAddr[%02x %02x %02x %02x %02x %02x] rssi %d, isScanResponse %u, AdvertisementType %u\r\n", -// printf("adv peerAddr[%d %d %d %d %d %d] rssi %d, isScanResponse %u, AdvertisementType %u\r\n", params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0], params->rssi, params->isScanResponse, params->type); printf("\n"); @@ -127,6 +103,8 @@ for (int i=0; i< params->advertisingDataLen; i++){ printf("%02x,",params->advertisingData[i]); } + */ + // for (int i=0; i<params->advertisingDataLen; i++){ // printf("%02x,",params->advertisingData[i]); // } @@ -135,8 +113,8 @@ // DEBUG(" \n\r"); //#endif - - + + } @@ -184,12 +162,24 @@ // 1++していく void step() { - //++st; - //rx_buf_st[0] = st; - //ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf, rx_len); - //ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf_st, sizeof(rx_buf_st)); - //pc.printf("%d", st); - //pc.printf("step! \r\n"); + ++st; + //ここから------------- + char bufbuf_c[20]; + uint8_t bufbuf[40]; + sprintf(bufbuf_c, "%d", st); + + int a; + for(a=0; bufbuf_c[a] != '\0'; a++) { + bufbuf[a] = bufbuf_c[a]; + } + +// ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf, rx_len); + ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), bufbuf, a); + //ここまで------------- + //をこぴればデータを送信可能 + + pc.printf("%d", st); + pc.printf("step! \r\n"); } @@ -208,7 +198,7 @@ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, - (const uint8_t *)"keiichi", sizeof("keiichi") - 1); + (const uint8_t *)"KEI_SEND", sizeof("KEI_SEND") - 1); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); // 100ms; in multiples of 0.625ms. @@ -229,7 +219,7 @@ while(1) { - ble.waitForEvent(); + ble.waitForEvent(); } }