LEDをON(文字列'a'を送る)OFF(文字列'b'を送る)できるMSC

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleChat by RedBearLab

Revision:
5:35728098eeae
diff -r 41cf035db84a -r 35728098eeae Services/TxPower.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Services/TxPower.h	Thu Dec 08 10:57:15 2016 +0000
@@ -0,0 +1,60 @@
+#ifndef TX_POWER_H
+#define TX_POWER_H
+#include "ble/BLE.h"
+
+//#include "BLEDevice.h"
+
+/**
+* @class Tx power service
+* @brief Tx power Service. This service exposes a device’s current transmit power level when in a connection (-100dbm to +20).
+* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.tx_power.xml
+* Tx power Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.tx_power_level.xml
+*/
+class TxPowerService
+{
+
+public:
+    /**
+    * @param[ref] _ble
+    *             BLEDevice object for the underlying controller.
+    * @param[in] TxValue
+    *             signed 8bit Transmit power.
+    */
+    
+    //        TxPowerChar(GattCharacteristic::UUID_TX_POWER_LEVEL_CHAR, (uint8_t*)&TxPower, sizeof(TxPower), sizeof(TxPower),
+//                    GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) {
+    
+    TxPowerService(BLE &_ble, int8_t TxValue):
+        ble(_ble),
+        TxPower(TxValue),
+        TxPowerChar(GattCharacteristic::UUID_TX_POWER_LEVEL_CHAR, &TxPower, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) {
+        GattCharacteristic *charTable[] = {&TxPowerChar};
+        GattService         TxPowerService(GattService::UUID_TX_POWER_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
+
+        ble.addService(TxPowerService);
+    }
+
+    /**
+    * @brief Update the Tx power with a new value. with a valid range from -100dbm to +20dbm according to the service Char.
+    *
+    * @param newTxPower
+    *              update the Tx power with the new value.
+    */
+    void updateTxPower(int8_t newTxPower) {
+
+        if(newTxPower >= -100 && newTxPower <= 20) {
+
+            TxPower = newTxPower;
+            ble.updateCharacteristicValue (TxPowerChar.getValueAttribute().getHandle(), (uint8_t*)&TxPower, 1);
+            //ble.updateCharacteristicValue (TxPowerChar.getValueHandle(), (uint8_t*)&TxPower, 1);
+            //ble.gattServer().write(TxPowerChar.getValueHandle(), &TxPower, 1);
+        }
+    }
+
+private:
+    BLE &ble;
+    int8_t TxPower;
+    ReadOnlyGattCharacteristic<int8_t>  TxPowerChar;
+};
+
+#endif
\ No newline at end of file