Bluetooth Low Energy for Smart Plug
Dependencies: BLE_API mbed nRF51822
Services/SmartPlugService.h@0:25ad6eba7916, 2015-07-07 (annotated)
- Committer:
- Slepnir
- Date:
- Tue Jul 07 04:02:14 2015 +0000
- Revision:
- 0:25ad6eba7916
- Child:
- 1:e036e77762fa
V1:; - Successfully advertise and connect ; - Update fail; - Can read only 4 bit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Slepnir | 0:25ad6eba7916 | 1 | #ifndef SP_SERVICE_H |
Slepnir | 0:25ad6eba7916 | 2 | #define SP_SERVICE_H |
Slepnir | 0:25ad6eba7916 | 3 | |
Slepnir | 0:25ad6eba7916 | 4 | #include "ble/BLE.h" |
Slepnir | 0:25ad6eba7916 | 5 | #include "MVC.h" |
Slepnir | 0:25ad6eba7916 | 6 | #include "mbed.h" |
Slepnir | 0:25ad6eba7916 | 7 | #include "SmartPlugBLE.h" |
Slepnir | 0:25ad6eba7916 | 8 | |
Slepnir | 0:25ad6eba7916 | 9 | |
Slepnir | 0:25ad6eba7916 | 10 | #define FULL_UUID(uuid_16) { \ |
Slepnir | 0:25ad6eba7916 | 11 | 0x9B,0x3F,uuid_16>>16,uuid_16&0xFF,0x65,0x80,0x47,0x51, \ |
Slepnir | 0:25ad6eba7916 | 12 | 0xB0,0x2F,0xA7,0xB5,0x19,0x4C,0x7F,0x23 \ |
Slepnir | 0:25ad6eba7916 | 13 | } |
Slepnir | 0:25ad6eba7916 | 14 | |
Slepnir | 0:25ad6eba7916 | 15 | static const uint16_t SPS_UUID_SERVICE = 0x1522; |
Slepnir | 0:25ad6eba7916 | 16 | static const uint16_t SPS_UUID_VOLTAGE_CHAR = 0x1523; |
Slepnir | 0:25ad6eba7916 | 17 | static const uint16_t SPS_UUID_CURERNT_CHAR = 0x1524; |
Slepnir | 0:25ad6eba7916 | 18 | static const uint16_t SPS_UUID_POWER_CHAR = 0x1525; |
Slepnir | 0:25ad6eba7916 | 19 | static const uint16_t SPS_UUID_POWER_FACTOR_CHAR = 0x1526; |
Slepnir | 0:25ad6eba7916 | 20 | static const uint16_t SPS_UUID_ENERGY_CHAR = 0x1527; |
Slepnir | 0:25ad6eba7916 | 21 | static const uint16_t SPS_UUID_RELAY_CHAR = 0x1528; |
Slepnir | 0:25ad6eba7916 | 22 | static const uint16_t SPS_UUID_UPDATE_CHAR = 0x1529; |
Slepnir | 0:25ad6eba7916 | 23 | |
Slepnir | 0:25ad6eba7916 | 24 | static const uint8_t SPS_UUID_SERVICE_FULL[] = FULL_UUID(SPS_UUID_SERVICE); |
Slepnir | 0:25ad6eba7916 | 25 | static const uint8_t SPS_UUID_VOLTAGE_CHAR_FULL[] = FULL_UUID(SPS_UUID_VOLTAGE_CHAR); |
Slepnir | 0:25ad6eba7916 | 26 | static const uint8_t SPS_UUID_CURERNT_CHAR_FULL[] = FULL_UUID(SPS_UUID_CURERNT_CHAR); |
Slepnir | 0:25ad6eba7916 | 27 | static const uint8_t SPS_UUID_POWER_CHAR_FULL[] = FULL_UUID(SPS_UUID_POWER_CHAR); |
Slepnir | 0:25ad6eba7916 | 28 | static const uint8_t SPS_UUID_POWER_FACTOR_CHAR_FULL[] = FULL_UUID(SPS_UUID_POWER_FACTOR_CHAR); |
Slepnir | 0:25ad6eba7916 | 29 | static const uint8_t SPS_UUID_ENERGY_CHAR_FULL[] = FULL_UUID(SPS_UUID_ENERGY_CHAR); |
Slepnir | 0:25ad6eba7916 | 30 | static const uint8_t SPS_UUID_RELAY_CHAR_FULL[] = FULL_UUID(SPS_UUID_RELAY_CHAR); |
Slepnir | 0:25ad6eba7916 | 31 | static const uint8_t SPS_UUID_UPDATE_CHAR_FULL[] = FULL_UUID(SPS_UUID_UPDATE_CHAR); |
Slepnir | 0:25ad6eba7916 | 32 | |
Slepnir | 0:25ad6eba7916 | 33 | |
Slepnir | 0:25ad6eba7916 | 34 | class SmartPlugService: public Observer |
Slepnir | 0:25ad6eba7916 | 35 | { |
Slepnir | 0:25ad6eba7916 | 36 | public: |
Slepnir | 0:25ad6eba7916 | 37 | SmartPlugService(BLE &_ble, SmartPlugBLE &sys); |
Slepnir | 0:25ad6eba7916 | 38 | |
Slepnir | 0:25ad6eba7916 | 39 | void updateVoltage(unsigned long value); |
Slepnir | 0:25ad6eba7916 | 40 | void updateCurrent(unsigned long value); |
Slepnir | 0:25ad6eba7916 | 41 | void updatePower(unsigned long value); |
Slepnir | 0:25ad6eba7916 | 42 | void updatePowerFactor(unsigned long value); |
Slepnir | 0:25ad6eba7916 | 43 | void onDataWritten(const GattWriteCallbackParams *params); |
Slepnir | 0:25ad6eba7916 | 44 | void update(void* data); |
Slepnir | 0:25ad6eba7916 | 45 | void updateData(SmartPlug* data); |
Slepnir | 0:25ad6eba7916 | 46 | void setupService(void); |
Slepnir | 0:25ad6eba7916 | 47 | private: |
Slepnir | 0:25ad6eba7916 | 48 | BLE ble; |
Slepnir | 0:25ad6eba7916 | 49 | |
Slepnir | 0:25ad6eba7916 | 50 | uint8_t voltage[4]; |
Slepnir | 0:25ad6eba7916 | 51 | uint8_t current[4]; |
Slepnir | 0:25ad6eba7916 | 52 | uint8_t power[4]; |
Slepnir | 0:25ad6eba7916 | 53 | uint8_t powerFactor[4]; |
Slepnir | 0:25ad6eba7916 | 54 | uint8_t energy[4]; |
Slepnir | 0:25ad6eba7916 | 55 | uint8_t relayValue[3]; |
Slepnir | 0:25ad6eba7916 | 56 | //uint8_t updateValue; |
Slepnir | 0:25ad6eba7916 | 57 | SmartPlugBLE& system; |
Slepnir | 0:25ad6eba7916 | 58 | |
Slepnir | 0:25ad6eba7916 | 59 | ReadOnlyGattCharacteristic<uint8_t> voltageChar; |
Slepnir | 0:25ad6eba7916 | 60 | ReadOnlyGattCharacteristic<uint8_t> currentChar; |
Slepnir | 0:25ad6eba7916 | 61 | ReadOnlyGattCharacteristic<uint8_t> powerChar; |
Slepnir | 0:25ad6eba7916 | 62 | ReadOnlyGattCharacteristic<uint8_t> powerFactorChar; |
Slepnir | 0:25ad6eba7916 | 63 | ReadOnlyGattCharacteristic<uint8_t> energyChar; |
Slepnir | 0:25ad6eba7916 | 64 | ReadWriteGattCharacteristic<uint8_t> relayChar; |
Slepnir | 0:25ad6eba7916 | 65 | WriteOnlyGattCharacteristic<uint8_t> updateChar; |
Slepnir | 0:25ad6eba7916 | 66 | }; |
Slepnir | 0:25ad6eba7916 | 67 | |
Slepnir | 0:25ad6eba7916 | 68 | #endif |