CdsLibに対応したMSC
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleChat by
Revision 6:92a65bca83cd, committed 2017-02-12
- Comitter:
- ke_ix1
- Date:
- Sun Feb 12 10:35:07 2017 +0000
- Parent:
- 5:29b82cc045b6
- Commit message:
- Cds init;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 29b82cc045b6 -r 92a65bca83cd main.cpp --- a/main.cpp Thu Dec 08 13:53:36 2016 +0000 +++ b/main.cpp Sun Feb 12 10:35:07 2017 +0000 @@ -30,7 +30,22 @@ // TX POWER用 #include "ble_gap.h" -#define TX_POWER -40 +#define TX_POWER -16 +//機器設定 +//#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 + + +#define TX_POWER_CALI -8 +const static char DEVICE_NAME[] = "MN9"; // change this + #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. */ @@ -43,7 +58,7 @@ Serial pc(USBTX, USBRX); Ticker steper; DigitalOut ledori1(LED1); - +AnalogIn cdsIn(P0_1); // 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}; @@ -52,10 +67,12 @@ //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_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}; +//static const uint8_t uart_base_uuid_rev[] = {0x7C, 0xCD, 0xD4, 0x16, 0x66, 0xFB, 0xFC, 0xB6, 0x02, 0x48, 0x11, 0x8D, 0x38, 0xF5, 0xF3, 0x53}; +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_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71}; // TX POWER用 @@ -63,9 +80,26 @@ uint8_t powerPayload[TXRX_BUF_LEN] = {0,}; static uint8_t power_buf[TXRX_BUF_LEN]; static uint8_t power_len=0; -GattCharacteristic txPowerCharacteristic (power_level_uuid, powerPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); //tx power characteristic +GattCharacteristic txPowerCharacteristic (power_level_uuid, powerPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); //tx power characteristic Ticker txSteper; + +// 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 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); //tx power characteristic + + +//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 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); //tx power characteristic + + uint8_t txPayload[TXRX_BUF_LEN] = {0,}; uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; @@ -80,11 +114,46 @@ 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 rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); + +GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic, &txPowerCharacteristic, &mscCharacteristic, &featureCharacteristic}; +GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); + -GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic, &txPowerCharacteristic}; +// MSC UUID +void initMsc() { + //ここから------------- + char bufbuf_c[20]; + uint8_t bufbuf[40]; + //MSCのUUIDをセット + sprintf(bufbuf_c, "%s", "00000006"); + //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(mscCharacteristic.getValueAttribute().getHandle(), bufbuf, a); + //ここまで------------- + //をこぴればデータを送信可能 +} -GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); + +// Feature +void initFeature() { + //ここから------------- + char bufbuf_c[20]; + uint8_t bufbuf[40]; + sprintf(bufbuf_c, "%s", "In.Sensor.CdS"); + int a; + for(a=0; bufbuf_c[a] != '\0'; a++) { + bufbuf[a] = bufbuf_c[a]; + } + ble.updateCharacteristicValue(featureCharacteristic.getValueAttribute().getHandle(), bufbuf, a); + //ここまで------------- + //をこぴればデータを送信可能 +} + + // TX POWER用 void txPowerUpdate(int newTxPower) { @@ -92,7 +161,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]; @@ -106,15 +175,24 @@ //ここから------------- char bufbuf_c[20]; uint8_t bufbuf[40]; - sprintf(bufbuf_c, "%d", TX_POWER); + 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); + ble.updateCharacteristicValue(txPowerCharacteristic.getValueAttribute().getHandle(), bufbuf, a); } //------------------- + +void initChara() { + initMsc(); + initFeature(); + txStep(); +} + + + void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { pc.printf("Disconnected \r\n"); @@ -172,7 +250,7 @@ pc.printf("Data: "); for(index=0; index<bytesRead; index++) { - pc.putc(txPayload[index]); + pc.putc(txPayload[index]); } pc.printf("\r\n"); } @@ -199,11 +277,12 @@ // 1++していく void step() { - ++st; + + float cds = cdsIn; //ここから------------- char bufbuf_c[20]; uint8_t bufbuf[40]; - sprintf(bufbuf_c, "%d", st); + sprintf(bufbuf_c, "%f", cds); int a; for(a=0; bufbuf_c[a] != '\0'; a++) { @@ -215,13 +294,11 @@ //ここまで------------- //をこぴればデータを送信可能 - pc.printf("%d", st); - pc.printf("step! \r\n"); + pc.printf("%f", cds); + pc.printf(" cds! \r\n"); } - - int main(void) { ledori1 = 0; @@ -237,7 +314,7 @@ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, - (const uint8_t *)"KEI_SEND", sizeof("KEI_SEND") - 1); + (const uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME) - 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. @@ -258,7 +335,9 @@ //TX POWER用 txPowerUpdate(TX_POWER); - txSteper.attach(&txStep, 2.0); + //txSteper.attach(&initChara, 1.0); + initChara(); + while(1) {