TeleViLibに対応するMSC
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleChat_LED_kai by
Diff: main.cpp
- Revision:
- 8:0d98c9aca74c
- Parent:
- 7:fbaa5e70a60e
- Child:
- 9:37c7b2a4b0a5
--- a/main.cpp Fri Jan 06 07:24:16 2017 +0000 +++ b/main.cpp Wed Jan 18 05:33:13 2017 +0000 @@ -31,16 +31,16 @@ #include "TxPower.h" //#include "DFUService.h" +LocalFileSystem local("local"); // マウントポイントを定義(ディレクトリパスになる) + + #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. */ -#define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */ +#define BLE_UUID_TX_CHARACTERISTIC 0x0003 /**< The UUID of the TX Characteristic. */ +#define BLE_UUIDS_RX_CHARACTERISTIC 0x0002 /**< The UUID of the RX Characteristic. */ #define TXRX_BUF_LEN 20 -#define DIGITAL_OUT_PIN P0_17 //D7 - -//構成情報 -const static char CONFIG_INFO[] = "OL"; // change this - +//#define DIGITAL_OUT_PIN P0_17 //nRF51, 51822 +#define DIGITAL_OUT_PIN P0_5 //Nano // TX POWER用 #include "ble_gap.h" #define TX_POWER 0 @@ -83,14 +83,14 @@ 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 +GattCharacteristic mscCharacteristic (msc_uuid, mscPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); //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受信用 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; //Feature UUID @@ -98,7 +98,7 @@ 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 +GattCharacteristic featureCharacteristic (feature_uuid, featurePayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); //tx power characteristic // Tx Power Service @@ -122,7 +122,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 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 *)); @@ -221,7 +221,7 @@ //ここから------------- char bufbuf_c[20]; uint8_t bufbuf[40]; - sprintf(bufbuf_c, "%s", "Out.Led"); + sprintf(bufbuf_c, "%s", "Mn.Out.Led"); int a; for(a=0; bufbuf_c[a] != '\0'; a++) { bufbuf[a] = bufbuf_c[a]; @@ -232,11 +232,6 @@ } -void initChara() { - initMsc(); - initFeature(); -} - void txStep() { //ここから------------- //sd_ble_gap_tx_power_set(TX_POWER); @@ -248,7 +243,12 @@ bufbuf[a] = bufbuf_c[a]; } ble.updateCharacteristicValue(txPowerCharacteristic.getValueAttribute().getHandle(), bufbuf, a); - initChara(); +} + +void initChara() { + initMsc(); + initFeature(); + txStep(); } //------------------- @@ -287,6 +287,20 @@ pc.attach( uartCB , pc.RxIrq); + + FILE *fp; + FILE *fpr; + char ch[40]; + + fp = fopen("/local/out.txt", "w"); // ファイルを書き込みモードで開く + fprintf(fp, "Hello World!"); + fclose(fp); + + fpr = fopen("/local/out.txt", "r"); + fscanf(fp, "%s", ch); + pc.printf("%s\r\n",ch); + + //txPowerService = new TxPowerService(ble, -40); //txPowerService->updateTxPower(TX_POWER); @@ -318,8 +332,8 @@ ble.startAdvertising(); pc.printf("Advertising Start \r\n"); - //TX POWER用 - txSteper.attach(&txStep, 2.0); + //init用 + //txSteper.attach(&initChara, 1.0); txPowerUpdate(TX_POWER); initChara();