add more HAP services: HAPPairing, HAPLightBulb
This commit is contained in:
1 parent
fe02b18f82
commit
e81d315f28
7 files changed
+258
-43
No files matched your search
@@ -43,10 +43,8 @@
|
||||
uint16_t BLEHomekit::_gInstanceID = 1;
|
||||
|
||||
BLEHomekit::BLEHomekit()
|
||||
: _protocol_info(HAP_UUID_SVC_PROTOCOL_INFO), AccessoryInfo(),
|
||||
_pairing(HAP_UUID_SVC_PAIRING), _pair_setup(HAP_UUID_CHR_PAIR_SETUP), _pair_verify(HAP_UUID_CHR_PAIR_VERIFY),
|
||||
_pair_features(HAP_UUID_SVC_PAIR_FEATURE), _pair_pairing(HAP_UUID_SVC_PAIR_PAIRING),
|
||||
_lightbulb(HAP_UUID_SVC_LIGHT_BULB), _on(HAP_UUID_CHR_ON)
|
||||
: _protocol_info(HAP_UUID_SVC_PROTOCOL_INFO), AccessoryInfo(), _pairing(),
|
||||
_lightbulb()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -74,7 +72,7 @@ err_t BLEHomekit::begin()
|
||||
/*------------- Protocol Info Service -------------*/
|
||||
VERIFY_STATUS( _protocol_info.begin() );
|
||||
{
|
||||
HAPCharacteristic chr(HAP_UUID_CHR_VERSION);
|
||||
HAPCharacteristic chr(HAP_UUID_CHR_VERSION, BLE_GATT_CPF_FORMAT_UTF8S);
|
||||
|
||||
chr.setTempMemory(); // ready-only, not included in Gatt list
|
||||
chr.setProperties(CHR_PROPS_READ);
|
||||
@@ -86,41 +84,10 @@ err_t BLEHomekit::begin()
|
||||
}
|
||||
|
||||
/*------------- Pairing Service -------------*/
|
||||
VERIFY_STATUS( _pairing.begin() );
|
||||
{
|
||||
// TODO read, write using auth
|
||||
_pair_setup.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
|
||||
_pair_setup.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
_pair_setup.setMaxLen(100);
|
||||
VERIFY_STATUS( _pair_setup.begin() );
|
||||
|
||||
_pair_verify.setProperties(CHR_PROPS_READ);
|
||||
_pair_verify.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_pair_verify.setMaxLen(100);
|
||||
VERIFY_STATUS( _pair_verify.begin() );
|
||||
|
||||
_pair_features.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
|
||||
_pair_features.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_pair_features.setFixedLen(1);
|
||||
VERIFY_STATUS( _pair_features.begin() );
|
||||
_pair_features.write( (uint8_t) 0x01); // support HAP pairing
|
||||
|
||||
_pair_pairing.setProperties(CHR_PROPS_READ);
|
||||
_pair_pairing.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
_pair_pairing.setMaxLen(100);
|
||||
VERIFY_STATUS( _pair_pairing.begin() );
|
||||
}
|
||||
VERIFY_STATUS ( _pairing.begin() );
|
||||
|
||||
/*------------- LightBulb Service -------------*/
|
||||
VERIFY_STATUS( _lightbulb.begin() ) ;
|
||||
{
|
||||
// ON char
|
||||
_on.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE | CHR_PROPS_INDICATE );
|
||||
_on.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
_on.setFixedLen(1);
|
||||
VERIFY_STATUS( _on.begin() );
|
||||
_on.write( (uint8_t) 0x00 );
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "HAPService.h"
|
||||
|
||||
#include "service/HAPAccessoryInfo.h"
|
||||
#include "service/HAPPairing.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -74,18 +75,14 @@ class BLEHomekit : public Advertisable
|
||||
BLEHomekit();
|
||||
err_t begin();
|
||||
|
||||
|
||||
HAPAccessoryInfo AccessoryInfo;
|
||||
|
||||
private:
|
||||
// Mandatory services
|
||||
HAPService _protocol_info;
|
||||
|
||||
HAPService _pairing;
|
||||
HAPCharacteristic _pair_setup, _pair_verify, _pair_features, _pair_pairing;
|
||||
HAPPairing _pairing;
|
||||
|
||||
HAPService _lightbulb;
|
||||
HAPCharacteristic _on;
|
||||
};
|
||||
|
||||
#endif /* BLEHOMEKIT_H_ */
|
||||
@@ -43,7 +43,7 @@ class HAPCharacteristic : public BLECharacteristic
|
||||
public:
|
||||
static BLEUuid _g_uuid_cid;
|
||||
|
||||
HAPCharacteristic(BLEUuid bleuuid, uint8_t format, uint16_t unit);
|
||||
HAPCharacteristic(BLEUuid bleuuid, uint8_t format, uint16_t unit = UUID16_UNIT_UNITLESS);
|
||||
virtual err_t begin(void);
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file HAPLightBulb.cpp
|
||||
@author hathach
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2017, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include <bluefruit.h>
|
||||
#include "HAPUuid.h"
|
||||
#include "HAPLightBulb.h"
|
||||
|
||||
HAPLightBulb::HAPLightBulb(void)
|
||||
: HAPService(HAP_UUID_SVC_LIGHT_BULB), _on(HAP_UUID_CHR_ON)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t HAPLightBulb::begin(void)
|
||||
{
|
||||
VERIFY_STATUS( HAPService::begin() ); // Invoke base class begin()
|
||||
|
||||
// ON char
|
||||
_on.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE | CHR_PROPS_INDICATE );
|
||||
_on.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
_on.setFixedLen(1);
|
||||
VERIFY_STATUS( _on.begin() );
|
||||
_on.write( (uint8_t) 0x00 );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file HAPLightBulb.h
|
||||
@author hathach
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2017, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#ifndef HAPLIGHTBULB_H_
|
||||
#define HAPLIGHTBULB_H_
|
||||
|
||||
#include "HAPCharacteristic.h"
|
||||
#include "HAPService.h"
|
||||
|
||||
class HAPLightBulb : public HAPService
|
||||
{
|
||||
public:
|
||||
HAPLightBulb(void);
|
||||
|
||||
virtual err_t begin(void);
|
||||
|
||||
private:
|
||||
HAPCharacteristic _on;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* HAPLIGHTBULB_H_ */
|
||||
@@ -0,0 +1,78 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file HAPPairing.cpp
|
||||
@author hathach
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2017, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include <bluefruit.h>
|
||||
#include "HAPUuid.h"
|
||||
#include "HAPPairing.h"
|
||||
|
||||
HAPPairing::HAPPairing(void)
|
||||
: HAPService(HAP_UUID_SVC_PAIRING),
|
||||
_setup (HAP_UUID_CHR_PAIR_SETUP , BLE_GATT_CPF_FORMAT_STRUCT),
|
||||
_verify (HAP_UUID_CHR_PAIR_VERIFY , BLE_GATT_CPF_FORMAT_STRUCT),
|
||||
_features (HAP_UUID_SVC_PAIR_FEATURE , BLE_GATT_CPF_FORMAT_STRUCT),
|
||||
_pairing (HAP_UUID_SVC_PAIR_PAIRING , BLE_GATT_CPF_FORMAT_STRUCT)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t HAPPairing::begin(void)
|
||||
{
|
||||
VERIFY_STATUS( HAPService::begin() ); // Invoke base class begin()
|
||||
|
||||
// TODO read, write using auth
|
||||
_setup.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
|
||||
_setup.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
_setup.setMaxLen(100);
|
||||
VERIFY_STATUS( _setup.begin() );
|
||||
|
||||
_verify.setProperties(CHR_PROPS_READ);
|
||||
_verify.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_verify.setMaxLen(100);
|
||||
VERIFY_STATUS( _verify.begin() );
|
||||
|
||||
_features.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
|
||||
_features.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
_features.setFixedLen(1);
|
||||
VERIFY_STATUS( _features.begin() );
|
||||
_features.write( (uint8_t) 0x01); // support HAP pairing
|
||||
|
||||
_pairing.setProperties(CHR_PROPS_READ);
|
||||
_pairing.setPermission(SECMODE_OPEN, SECMODE_OPEN);
|
||||
_pairing.setMaxLen(100);
|
||||
VERIFY_STATUS( _pairing.begin() );
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file HAPPairing.h
|
||||
@author hathach
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2017, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#ifndef HAPPAIRING_H_
|
||||
#define HAPPAIRING_H_
|
||||
|
||||
#include "HAPCharacteristic.h"
|
||||
#include "HAPService.h"
|
||||
|
||||
class HAPPairing : public HAPService
|
||||
{
|
||||
public:
|
||||
HAPPairing(void);
|
||||
|
||||
virtual err_t begin(void);
|
||||
|
||||
private:
|
||||
HAPCharacteristic _setup;
|
||||
HAPCharacteristic _verify;
|
||||
HAPCharacteristic _features;
|
||||
HAPCharacteristic _pairing;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* HAPPAIRING_H_ */
|
||||
Reference in new issue
Block a user