TeleViLibに対応するMSC
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleChat_LED_kai by
main.cpp@6:b15d219371da, 2016-12-08 (annotated)
- Committer:
- ke_ix1
- Date:
- Thu Dec 08 13:52:38 2016 +0000
- Revision:
- 6:b15d219371da
- Parent:
- 5:35728098eeae
- Child:
- 7:fbaa5e70a60e
???????TxPower????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RedBearLab | 1:1c058e553423 | 1 | /* |
RedBearLab | 0:cffe8ac1bdf0 | 2 | |
RedBearLab | 1:1c058e553423 | 3 | Copyright (c) 2012-2014 RedBearLab |
RedBearLab | 1:1c058e553423 | 4 | |
RedBearLab | 1:1c058e553423 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
RedBearLab | 1:1c058e553423 | 6 | and associated documentation files (the "Software"), to deal in the Software without restriction, |
RedBearLab | 1:1c058e553423 | 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
RedBearLab | 1:1c058e553423 | 8 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, |
RedBearLab | 1:1c058e553423 | 9 | subject to the following conditions: |
RedBearLab | 1:1c058e553423 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
RedBearLab | 1:1c058e553423 | 11 | |
RedBearLab | 1:1c058e553423 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
RedBearLab | 1:1c058e553423 | 13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
RedBearLab | 1:1c058e553423 | 14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
RedBearLab | 1:1c058e553423 | 15 | FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
RedBearLab | 1:1c058e553423 | 16 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
RedBearLab | 1:1c058e553423 | 17 | |
RedBearLab | 1:1c058e553423 | 18 | */ |
RedBearLab | 1:1c058e553423 | 19 | |
RedBearLab | 1:1c058e553423 | 20 | /* |
RedBearLab | 1:1c058e553423 | 21 | * The application works with the BLEController iOS/Android App. |
RedBearLab | 1:1c058e553423 | 22 | * Type something from the Terminal to send |
RedBearLab | 1:1c058e553423 | 23 | * to the BLEController App or vice verse. |
RedBearLab | 1:1c058e553423 | 24 | * Characteristics received from App will print on Terminal. |
RedBearLab | 1:1c058e553423 | 25 | */ |
RedBearLab | 1:1c058e553423 | 26 | |
RedBearLab | 0:cffe8ac1bdf0 | 27 | #include "mbed.h" |
RedBearLab | 2:4b66b69c7ecb | 28 | #include "ble/BLE.h" |
ke_ix1 | 6:b15d219371da | 29 | |
ke_ix1 | 6:b15d219371da | 30 | // TX POWER用 |
ke_ix1 | 5:35728098eeae | 31 | #include "ble_gap.h" |
ke_ix1 | 6:b15d219371da | 32 | #define TX_POWER 0 |
RedBearLab | 0:cffe8ac1bdf0 | 33 | |
RedBearLab | 0:cffe8ac1bdf0 | 34 | #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */ |
RedBearLab | 0:cffe8ac1bdf0 | 35 | #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */ |
RedBearLab | 0:cffe8ac1bdf0 | 36 | #define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */ |
RedBearLab | 0:cffe8ac1bdf0 | 37 | |
RedBearLab | 0:cffe8ac1bdf0 | 38 | #define TXRX_BUF_LEN 20 |
ke_ix1 | 4:41cf035db84a | 39 | #define DIGITAL_OUT_PIN P0_17 //D7 |
ke_ix1 | 4:41cf035db84a | 40 | |
RedBearLab | 0:cffe8ac1bdf0 | 41 | |
RedBearLab | 2:4b66b69c7ecb | 42 | BLE ble; |
RedBearLab | 0:cffe8ac1bdf0 | 43 | |
RedBearLab | 0:cffe8ac1bdf0 | 44 | Serial pc(USBTX, USBRX); |
ke_ix1 | 5:35728098eeae | 45 | Ticker steper; |
ke_ix1 | 4:41cf035db84a | 46 | DigitalOut led1(DIGITAL_OUT_PIN); |
ke_ix1 | 4:41cf035db84a | 47 | DigitalOut ledori1(LED1); |
RedBearLab | 0:cffe8ac1bdf0 | 48 | |
RedBearLab | 0:cffe8ac1bdf0 | 49 | // The Nordic UART Service |
ke_ix1 | 4:41cf035db84a | 50 | //static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
ke_ix1 | 4:41cf035db84a | 51 | //static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
ke_ix1 | 4:41cf035db84a | 52 | //static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
ke_ix1 | 4:41cf035db84a | 53 | //static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71}; |
RedBearLab | 0:cffe8ac1bdf0 | 54 | |
ke_ix1 | 4:41cf035db84a | 55 | // The Service |
ke_ix1 | 4:41cf035db84a | 56 | static const uint8_t uart_base_uuid[] = {0x02, 0xF3, 0xF5, 0x38, 0x8D, 0x11, 0x48, 0x02, 0xB6, 0xFC, 0xFB, 0x66, 0x16, 0xD4, 0xCD, 0x70}; //Service |
ke_ix1 | 4:41cf035db84a | 57 | static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_送信用 |
ke_ix1 | 4:41cf035db84a | 58 | static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_受信用 |
ke_ix1 | 6:b15d219371da | 59 | static const uint8_t uart_base_uuid_rev[] = {0x70, 0xCD, 0xD4, 0x16, 0x66, 0xFB, 0xFC, 0xB6, 0x02, 0x48, 0x11, 0x8D, 0x38, 0xF5, 0xF3, 0x02}; |
ke_ix1 | 6:b15d219371da | 60 | |
ke_ix1 | 6:b15d219371da | 61 | // TX POWER用 |
ke_ix1 | 5:35728098eeae | 62 | 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受信用 |
ke_ix1 | 6:b15d219371da | 63 | uint8_t powerPayload[TXRX_BUF_LEN] = {0,}; |
ke_ix1 | 6:b15d219371da | 64 | static uint8_t power_buf[TXRX_BUF_LEN]; |
ke_ix1 | 6:b15d219371da | 65 | static uint8_t power_len=0; |
ke_ix1 | 6:b15d219371da | 66 | GattCharacteristic txPowerCharacteristic (power_level_uuid, powerPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); //tx power characteristic |
ke_ix1 | 6:b15d219371da | 67 | Ticker txSteper; |
ke_ix1 | 6:b15d219371da | 68 | |
ke_ix1 | 6:b15d219371da | 69 | |
ke_ix1 | 4:41cf035db84a | 70 | |
ke_ix1 | 5:35728098eeae | 71 | // Tx Power Service |
ke_ix1 | 5:35728098eeae | 72 | //static const uint8_t power_base_uuid[] = {0x03, 0xF3, 0xF5, 0x38, 0x8D, 0x11, 0x48, 0x02, 0xB6, 0xFC, 0xFB, 0x66, 0x16, 0xD4, 0xCD, 0x70}; //Service |
ke_ix1 | 5:35728098eeae | 73 | //static const uint8_t power_base_uuid_rev[] = {0x70, 0xCD, 0xD4, 0x16, 0x66, 0xFB, 0xFC, 0xB6, 0x02, 0x48, 0x11, 0x8D, 0x38, 0xF5, 0xF3, 0x03}; |
ke_ix1 | 5:35728098eeae | 74 | //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受信用 |
ke_ix1 | 5:35728098eeae | 75 | |
ke_ix1 | 5:35728098eeae | 76 | /* |
ke_ix1 | 5:35728098eeae | 77 | static const uint16_t txpower_base_uuid[] = {0x18, 0x04}; |
ke_ix1 | 5:35728098eeae | 78 | static const uint16_t txpower_base_uuid_rev[] = {0x04, 0x18}; |
ke_ix1 | 5:35728098eeae | 79 | */ |
ke_ix1 | 4:41cf035db84a | 80 | //02f3f538-8d11-4802-b6fc-fb6616d4cd70 |
ke_ix1 | 4:41cf035db84a | 81 | |
ke_ix1 | 5:35728098eeae | 82 | const static char DEVICE_NAME[] = "KEI_LED2"; // change this |
RedBearLab | 0:cffe8ac1bdf0 | 83 | |
RedBearLab | 0:cffe8ac1bdf0 | 84 | uint8_t txPayload[TXRX_BUF_LEN] = {0,}; |
RedBearLab | 0:cffe8ac1bdf0 | 85 | uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; |
RedBearLab | 0:cffe8ac1bdf0 | 86 | |
RedBearLab | 0:cffe8ac1bdf0 | 87 | static uint8_t rx_buf[TXRX_BUF_LEN]; |
RedBearLab | 0:cffe8ac1bdf0 | 88 | static uint8_t rx_len=0; |
RedBearLab | 0:cffe8ac1bdf0 | 89 | |
ke_ix1 | 5:35728098eeae | 90 | //Uart Service associated |
RedBearLab | 0:cffe8ac1bdf0 | 91 | GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); |
RedBearLab | 0:cffe8ac1bdf0 | 92 | GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); |
ke_ix1 | 5:35728098eeae | 93 | GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic, &txPowerCharacteristic}; |
RedBearLab | 0:cffe8ac1bdf0 | 94 | GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); |
RedBearLab | 0:cffe8ac1bdf0 | 95 | |
ke_ix1 | 5:35728098eeae | 96 | //TxPowerService *txPowerService = NULL; |
ke_ix1 | 5:35728098eeae | 97 | //BatteryService *batteryService = NULL; |
ke_ix1 | 5:35728098eeae | 98 | //uint8_t batteryLevel = 50; |
RedBearLab | 0:cffe8ac1bdf0 | 99 | |
RedBearLab | 3:b3f6c612b603 | 100 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) |
RedBearLab | 0:cffe8ac1bdf0 | 101 | { |
RedBearLab | 0:cffe8ac1bdf0 | 102 | pc.printf("Disconnected \r\n"); |
RedBearLab | 0:cffe8ac1bdf0 | 103 | pc.printf("Restart advertising \r\n"); |
RedBearLab | 0:cffe8ac1bdf0 | 104 | ble.startAdvertising(); |
RedBearLab | 0:cffe8ac1bdf0 | 105 | } |
RedBearLab | 0:cffe8ac1bdf0 | 106 | |
ke_ix1 | 4:41cf035db84a | 107 | void ConnectionCallback(const Gap::ConnectionCallbackParams_t *params) |
ke_ix1 | 4:41cf035db84a | 108 | { |
ke_ix1 | 4:41cf035db84a | 109 | pc.printf("Disconnected \r\n"); |
ke_ix1 | 4:41cf035db84a | 110 | pc.printf("Restart advertising \r\n"); |
ke_ix1 | 4:41cf035db84a | 111 | ble.startAdvertising(); |
ke_ix1 | 4:41cf035db84a | 112 | } |
ke_ix1 | 4:41cf035db84a | 113 | |
RedBearLab | 2:4b66b69c7ecb | 114 | void WrittenHandler(const GattWriteCallbackParams *Handler) |
RedBearLab | 0:cffe8ac1bdf0 | 115 | { |
RedBearLab | 0:cffe8ac1bdf0 | 116 | uint8_t buf[TXRX_BUF_LEN]; |
RedBearLab | 0:cffe8ac1bdf0 | 117 | uint16_t bytesRead, index; |
RedBearLab | 0:cffe8ac1bdf0 | 118 | |
ke_ix1 | 5:35728098eeae | 119 | if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) |
RedBearLab | 0:cffe8ac1bdf0 | 120 | { |
RedBearLab | 0:cffe8ac1bdf0 | 121 | ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead); |
RedBearLab | 0:cffe8ac1bdf0 | 122 | memset(txPayload, 0, TXRX_BUF_LEN); |
ke_ix1 | 5:35728098eeae | 123 | memcpy(txPayload, buf, TXRX_BUF_LEN); |
RedBearLab | 0:cffe8ac1bdf0 | 124 | pc.printf("WriteHandler \r\n"); |
RedBearLab | 0:cffe8ac1bdf0 | 125 | pc.printf("Length: "); |
ke_ix1 | 4:41cf035db84a | 126 | pc.putc(bytesRead); //受け取った文字の先頭アドレス? |
ke_ix1 | 4:41cf035db84a | 127 | pc.printf("\r\n"); |
ke_ix1 | 4:41cf035db84a | 128 | pc.printf("[0]: "); |
ke_ix1 | 4:41cf035db84a | 129 | pc.putc(txPayload[1]); //1文字目を表示 |
ke_ix1 | 4:41cf035db84a | 130 | if(txPayload[1]=='a') { |
ke_ix1 | 4:41cf035db84a | 131 | pc.printf("yeahhhhhh!!!!!!!!"); |
ke_ix1 | 4:41cf035db84a | 132 | // if(led1 == 0) { |
ke_ix1 | 4:41cf035db84a | 133 | led1 = 1; |
ke_ix1 | 5:35728098eeae | 134 | ledori1 = 0; |
ke_ix1 | 4:41cf035db84a | 135 | // } else { |
ke_ix1 | 4:41cf035db84a | 136 | // led1 = 0; |
ke_ix1 | 4:41cf035db84a | 137 | // } |
ke_ix1 | 4:41cf035db84a | 138 | } else if(txPayload[1]=='b') { |
ke_ix1 | 4:41cf035db84a | 139 | led1 = 0; |
ke_ix1 | 5:35728098eeae | 140 | ledori1 = 1; |
ke_ix1 | 4:41cf035db84a | 141 | } |
RedBearLab | 0:cffe8ac1bdf0 | 142 | pc.printf("\r\n"); |
RedBearLab | 0:cffe8ac1bdf0 | 143 | pc.printf("Data: "); |
RedBearLab | 0:cffe8ac1bdf0 | 144 | for(index=0; index<bytesRead; index++) |
RedBearLab | 0:cffe8ac1bdf0 | 145 | { |
ke_ix1 | 4:41cf035db84a | 146 | pc.putc(txPayload[index]); |
RedBearLab | 0:cffe8ac1bdf0 | 147 | } |
RedBearLab | 0:cffe8ac1bdf0 | 148 | pc.printf("\r\n"); |
RedBearLab | 0:cffe8ac1bdf0 | 149 | } |
RedBearLab | 0:cffe8ac1bdf0 | 150 | } |
RedBearLab | 0:cffe8ac1bdf0 | 151 | |
ke_ix1 | 6:b15d219371da | 152 | // TX POWER用 |
ke_ix1 | 5:35728098eeae | 153 | void txPowerUpdate(int newTxPower) { |
ke_ix1 | 6:b15d219371da | 154 | sd_ble_gap_tx_power_set(newTxPower); |
ke_ix1 | 5:35728098eeae | 155 | //ここから------------- |
ke_ix1 | 5:35728098eeae | 156 | char bufbuf_c[20]; |
ke_ix1 | 5:35728098eeae | 157 | uint8_t bufbuf[40]; |
ke_ix1 | 5:35728098eeae | 158 | sprintf(bufbuf_c, "%d", newTxPower); |
ke_ix1 | 5:35728098eeae | 159 | int a; |
ke_ix1 | 5:35728098eeae | 160 | for(a=0; bufbuf_c[a] != '\0'; a++) { |
ke_ix1 | 5:35728098eeae | 161 | bufbuf[a] = bufbuf_c[a]; |
ke_ix1 | 5:35728098eeae | 162 | } |
ke_ix1 | 5:35728098eeae | 163 | ble.updateCharacteristicValue(txPowerCharacteristic.getValueAttribute().getHandle(), bufbuf, a); |
ke_ix1 | 5:35728098eeae | 164 | //ここまで------------- |
ke_ix1 | 5:35728098eeae | 165 | //をこぴればデータを送信可能 |
ke_ix1 | 5:35728098eeae | 166 | } |
ke_ix1 | 5:35728098eeae | 167 | |
ke_ix1 | 6:b15d219371da | 168 | void txStep() { |
ke_ix1 | 6:b15d219371da | 169 | //ここから------------- |
ke_ix1 | 6:b15d219371da | 170 | char bufbuf_c[20]; |
ke_ix1 | 6:b15d219371da | 171 | uint8_t bufbuf[40]; |
ke_ix1 | 6:b15d219371da | 172 | sprintf(bufbuf_c, "%d", TX_POWER); |
ke_ix1 | 6:b15d219371da | 173 | int a; |
ke_ix1 | 6:b15d219371da | 174 | for(a=0; bufbuf_c[a] != '\0'; a++) { |
ke_ix1 | 6:b15d219371da | 175 | bufbuf[a] = bufbuf_c[a]; |
ke_ix1 | 6:b15d219371da | 176 | } |
ke_ix1 | 6:b15d219371da | 177 | ble.updateCharacteristicValue(txPowerCharacteristic.getValueAttribute().getHandle(), bufbuf, a); |
ke_ix1 | 6:b15d219371da | 178 | } |
ke_ix1 | 6:b15d219371da | 179 | //------------------- |
ke_ix1 | 6:b15d219371da | 180 | |
RedBearLab | 0:cffe8ac1bdf0 | 181 | void uartCB(void) |
RedBearLab | 0:cffe8ac1bdf0 | 182 | { |
RedBearLab | 0:cffe8ac1bdf0 | 183 | while(pc.readable()) |
RedBearLab | 0:cffe8ac1bdf0 | 184 | { |
RedBearLab | 0:cffe8ac1bdf0 | 185 | rx_buf[rx_len++] = pc.getc(); |
RedBearLab | 0:cffe8ac1bdf0 | 186 | if(rx_len>=20 || rx_buf[rx_len-1]=='\0' || rx_buf[rx_len-1]=='\n') |
RedBearLab | 0:cffe8ac1bdf0 | 187 | { |
ke_ix1 | 5:35728098eeae | 188 | txPowerUpdate(TX_POWER); |
ke_ix1 | 5:35728098eeae | 189 | |
RedBearLab | 0:cffe8ac1bdf0 | 190 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf, rx_len); |
RedBearLab | 0:cffe8ac1bdf0 | 191 | pc.printf("RecHandler \r\n"); |
RedBearLab | 0:cffe8ac1bdf0 | 192 | pc.printf("Length: "); |
RedBearLab | 0:cffe8ac1bdf0 | 193 | pc.putc(rx_len); |
RedBearLab | 0:cffe8ac1bdf0 | 194 | pc.printf("\r\n"); |
RedBearLab | 0:cffe8ac1bdf0 | 195 | rx_len = 0; |
RedBearLab | 0:cffe8ac1bdf0 | 196 | break; |
RedBearLab | 0:cffe8ac1bdf0 | 197 | } |
RedBearLab | 0:cffe8ac1bdf0 | 198 | } |
RedBearLab | 0:cffe8ac1bdf0 | 199 | } |
RedBearLab | 0:cffe8ac1bdf0 | 200 | |
RedBearLab | 0:cffe8ac1bdf0 | 201 | int main(void) |
RedBearLab | 0:cffe8ac1bdf0 | 202 | { |
ke_ix1 | 4:41cf035db84a | 203 | led1 = 0; |
ke_ix1 | 4:41cf035db84a | 204 | ledori1 = 0; |
RedBearLab | 0:cffe8ac1bdf0 | 205 | ble.init(); |
RedBearLab | 0:cffe8ac1bdf0 | 206 | ble.onDisconnection(disconnectionCallback); |
ke_ix1 | 4:41cf035db84a | 207 | ble.onDataWritten(WrittenHandler); |
ke_ix1 | 4:41cf035db84a | 208 | ble.onConnection(ConnectionCallback); |
RedBearLab | 0:cffe8ac1bdf0 | 209 | |
RedBearLab | 0:cffe8ac1bdf0 | 210 | pc.baud(9600); |
RedBearLab | 0:cffe8ac1bdf0 | 211 | pc.printf("SimpleChat Init \r\n"); |
RedBearLab | 0:cffe8ac1bdf0 | 212 | |
RedBearLab | 0:cffe8ac1bdf0 | 213 | pc.attach( uartCB , pc.RxIrq); |
ke_ix1 | 5:35728098eeae | 214 | |
ke_ix1 | 5:35728098eeae | 215 | // txPowerService = new TxPowerService(ble, -40); |
ke_ix1 | 5:35728098eeae | 216 | // txPowerService->updateTxPower(TX_POWER); |
ke_ix1 | 5:35728098eeae | 217 | |
ke_ix1 | 5:35728098eeae | 218 | |
ke_ix1 | 5:35728098eeae | 219 | //TxPowerService tx(ble, -40); // setting up the service and assigning an initial value |
ke_ix1 | 5:35728098eeae | 220 | //tx.updateTxPower(TX_POWER); //changing the initial value just for testing .... |
ke_ix1 | 5:35728098eeae | 221 | |
RedBearLab | 0:cffe8ac1bdf0 | 222 | // setup advertising |
ke_ix1 | 5:35728098eeae | 223 | // ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); |
ke_ix1 | 5:35728098eeae | 224 | // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)txpower_base_uuid_rev, sizeof(txpower_base_uuid_rev)); |
ke_ix1 | 5:35728098eeae | 225 | |
RedBearLab | 0:cffe8ac1bdf0 | 226 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
RedBearLab | 0:cffe8ac1bdf0 | 227 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
RedBearLab | 0:cffe8ac1bdf0 | 228 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
ke_ix1 | 4:41cf035db84a | 229 | (const uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME) - 1); |
RedBearLab | 0:cffe8ac1bdf0 | 230 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
RedBearLab | 0:cffe8ac1bdf0 | 231 | (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); |
ke_ix1 | 5:35728098eeae | 232 | |
RedBearLab | 0:cffe8ac1bdf0 | 233 | // 100ms; in multiples of 0.625ms. |
ke_ix1 | 4:41cf035db84a | 234 | ble.setAdvertisingInterval(50); |
RedBearLab | 0:cffe8ac1bdf0 | 235 | |
RedBearLab | 0:cffe8ac1bdf0 | 236 | ble.addService(uartService); |
RedBearLab | 0:cffe8ac1bdf0 | 237 | |
ke_ix1 | 5:35728098eeae | 238 | ble.setScanParams(GapScanningParams::SCAN_INTERVAL_MIN, |
ke_ix1 | 5:35728098eeae | 239 | GapScanningParams::SCAN_WINDOW_MIN, |
ke_ix1 | 5:35728098eeae | 240 | 0); |
ke_ix1 | 5:35728098eeae | 241 | |
RedBearLab | 0:cffe8ac1bdf0 | 242 | ble.startAdvertising(); |
RedBearLab | 0:cffe8ac1bdf0 | 243 | pc.printf("Advertising Start \r\n"); |
ke_ix1 | 6:b15d219371da | 244 | |
ke_ix1 | 6:b15d219371da | 245 | //TX POWER用 |
ke_ix1 | 6:b15d219371da | 246 | txSteper.attach(&txStep, 2.0); |
ke_ix1 | 6:b15d219371da | 247 | txPowerUpdate(TX_POWER); |
ke_ix1 | 5:35728098eeae | 248 | |
RedBearLab | 0:cffe8ac1bdf0 | 249 | while(1) |
RedBearLab | 0:cffe8ac1bdf0 | 250 | { |
RedBearLab | 0:cffe8ac1bdf0 | 251 | ble.waitForEvent(); |
RedBearLab | 0:cffe8ac1bdf0 | 252 | } |
RedBearLab | 0:cffe8ac1bdf0 | 253 | } |
ke_ix1 | 6:b15d219371da | 254 |