AirConLibに対応したMSC
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleChat_LED_kai by
Diff: main.cpp
- Revision:
- 7:fbaa5e70a60e
- Parent:
- 6:b15d219371da
- Child:
- 8:8962bcb7ddc4
diff -r b15d219371da -r fbaa5e70a60e main.cpp --- a/main.cpp Thu Dec 08 13:52:38 2016 +0000 +++ b/main.cpp Fri Jan 06 07:24:16 2017 +0000 @@ -27,9 +27,9 @@ #include "mbed.h" #include "ble/BLE.h" -// TX POWER用 -#include "ble_gap.h" -#define TX_POWER 0 + +#include "TxPower.h" +//#include "DFUService.h" #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */ #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */ @@ -38,6 +38,25 @@ #define TXRX_BUF_LEN 20 #define DIGITAL_OUT_PIN P0_17 //D7 +//構成情報 +const static char CONFIG_INFO[] = "OL"; // change this + +// TX POWER用 +#include "ble_gap.h" +#define TX_POWER 0 +//機器設定 +//#define TX_ZERO +//#define TX_POWER_CALI -10 +//const static char DEVICE_NAME[] = "nRF51DK"; // change this + +#define TX_POWER_CALI -7 +const static char DEVICE_NAME[] = "51822"; // change this + +//#define TX_POWER_CALI -15 +//const static char DEVICE_NAME[] = "Nano"; // change this + +//反映してない 二箇所設定変更する場所ある +//static int tx_power = TX_POWER + TX_POWER_CALI; BLE ble; @@ -45,18 +64,26 @@ Ticker steper; DigitalOut led1(DIGITAL_OUT_PIN); DigitalOut ledori1(LED1); +//DFUService dfu(ble); // 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}; // The Service -static const uint8_t uart_base_uuid[] = {0x02, 0xF3, 0xF5, 0x38, 0x8D, 0x11, 0x48, 0x02, 0xB6, 0xFC, 0xFB, 0x66, 0x16, 0xD4, 0xCD, 0x70}; //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[] = {0x70, 0xCD, 0xD4, 0x16, 0x66, 0xFB, 0xFC, 0xB6, 0x02, 0x48, 0x11, 0x8D, 0x38, 0xF5, 0xF3, 0x02}; +//static const uint8_t uart_base_uuid[] = {0x02, 0xF3, 0xF5, 0x38, 0x8D, 0x11, 0x48, 0x02, 0xB6, 0xFC, 0xFB, 0x66, 0x16, 0xD4, 0xCD, 0x70}; //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[] = {0x70, 0xCD, 0xD4, 0x16, 0x66, 0xFB, 0xFC, 0xB6, 0x02, 0x48, 0x11, 0x8D, 0x38, 0xF5, 0xF3, 0x02}; + +// MSC UUID +static const uint8_t msc_uuid[] = {0x71, 0x3D, 0, 6, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_TxPower受信用 +uint8_t mscPayload[TXRX_BUF_LEN] = {0,}; +static uint8_t msc_buf[TXRX_BUF_LEN]; +static uint8_t msc_len=0; +GattCharacteristic mscCharacteristic (msc_uuid, mscPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); //tx power characteristic // TX POWER用 static const uint8_t power_level_uuid[] = {0x71, 0x3D, 0, 4, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_TxPower受信用 @@ -66,6 +93,12 @@ GattCharacteristic txPowerCharacteristic (power_level_uuid, powerPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); //tx power characteristic Ticker txSteper; +//Feature UUID +static const uint8_t feature_uuid[] = {0x71, 0x3D, 0, 5, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_TxPower受信用 +uint8_t featurePayload[TXRX_BUF_LEN] = {0,}; +static uint8_t feature_buf[TXRX_BUF_LEN]; +static uint8_t feature_len=0; +GattCharacteristic featureCharacteristic (feature_uuid, featurePayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); //tx power characteristic // Tx Power Service @@ -79,7 +112,7 @@ */ //02f3f538-8d11-4802-b6fc-fb6616d4cd70 -const static char DEVICE_NAME[] = "KEI_LED2"; // change this + uint8_t txPayload[TXRX_BUF_LEN] = {0,}; uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; @@ -90,7 +123,7 @@ //Uart Service associated GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); -GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic, &txPowerCharacteristic}; +GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic, &txPowerCharacteristic, &mscCharacteristic, &featureCharacteristic}; GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); //TxPowerService *txPowerService = NULL; @@ -155,7 +188,7 @@ //ここから------------- char bufbuf_c[20]; uint8_t bufbuf[40]; - sprintf(bufbuf_c, "%d", newTxPower); + sprintf(bufbuf_c, "%d", newTxPower + TX_POWER_CALI); int a; for(a=0; bufbuf_c[a] != '\0'; a++) { bufbuf[a] = bufbuf_c[a]; @@ -165,19 +198,61 @@ //をこぴればデータを送信可能 } -void txStep() { + +// MSC UUID +void initMsc() { //ここから------------- char bufbuf_c[20]; uint8_t bufbuf[40]; - sprintf(bufbuf_c, "%d", TX_POWER); + sprintf(bufbuf_c, "%s", "00000001"); + //sprintf(bufbuf_c, "%d", "02f3f538-8d11-4802-b6fc-fb6616d4cd70"); int a; for(a=0; bufbuf_c[a] != '\0'; a++) { bufbuf[a] = bufbuf_c[a]; } - ble.updateCharacteristicValue(txPowerCharacteristic.getValueAttribute().getHandle(), bufbuf, a); + ble.updateCharacteristicValue(mscCharacteristic.getValueAttribute().getHandle(), bufbuf, a); + //ここまで------------- + //をこぴればデータを送信可能 +} + + +// Feature +void initFeature() { + //ここから------------- + char bufbuf_c[20]; + uint8_t bufbuf[40]; + sprintf(bufbuf_c, "%s", "Out.Led"); + int a; + for(a=0; bufbuf_c[a] != '\0'; a++) { + bufbuf[a] = bufbuf_c[a]; + } + ble.updateCharacteristicValue(featureCharacteristic.getValueAttribute().getHandle(), bufbuf, a); + //ここまで------------- + //をこぴればデータを送信可能 +} + + +void initChara() { + initMsc(); + initFeature(); +} + +void txStep() { + //ここから------------- + //sd_ble_gap_tx_power_set(TX_POWER); + char bufbuf_c[20]; + uint8_t bufbuf[40]; + sprintf(bufbuf_c, "%d", TX_POWER + TX_POWER_CALI); + int a; + for(a=0; bufbuf_c[a] != '\0'; a++) { + bufbuf[a] = bufbuf_c[a]; + } + ble.updateCharacteristicValue(txPowerCharacteristic.getValueAttribute().getHandle(), bufbuf, a); + initChara(); } //------------------- + void uartCB(void) { while(pc.readable()) @@ -212,8 +287,8 @@ pc.attach( uartCB , pc.RxIrq); -// txPowerService = new TxPowerService(ble, -40); -// txPowerService->updateTxPower(TX_POWER); + //txPowerService = new TxPowerService(ble, -40); + //txPowerService->updateTxPower(TX_POWER); //TxPowerService tx(ble, -40); // setting up the service and assigning an initial value @@ -230,6 +305,7 @@ 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. ble.setAdvertisingInterval(50); @@ -246,9 +322,12 @@ txSteper.attach(&txStep, 2.0); txPowerUpdate(TX_POWER); + initChara(); + while(1) { ble.waitForEvent(); } } +