improve instance id

This commit is contained in:
hathach committed 2017-10-14 00:58:06 +07:00
1 parent 59c40a27f6
commit 3c0762fcf1
4 files changed
+13 -13

No files matched your search

+6 -4
View File
@@ -40,6 +40,8 @@
#define HOMEKIT_PROTOCOL_VERION 2
#define HOMEKIT_PROTOCOL_VERSION_STR "02.01.00"
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),
@@ -49,7 +51,7 @@ BLEHomekit::BLEHomekit()
}
err_t addServiceInstanceID(uint16_t id)
err_t addServiceInstanceID(void)
{
BLECharacteristic chr(HAP_UUID_CHR_SERVICE_ID);
chr.setTempMemory();
@@ -59,7 +61,7 @@ err_t addServiceInstanceID(uint16_t id)
chr.setFixedLen(2);
VERIFY_STATUS( chr.begin() );
chr.write( id );
chr.write( BLEHomekit::_gInstanceID++ );
return ERROR_NONE;
}
@@ -89,7 +91,7 @@ err_t BLEHomekit::begin()
/*------------- Pairing Service -------------*/
VERIFY_STATUS( _pairing.begin() );
{
addServiceInstanceID(3);
addServiceInstanceID();
// TODO read, write using auth
_pair_setup.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE);
@@ -117,7 +119,7 @@ err_t BLEHomekit::begin()
/*------------- LightBulb Service -------------*/
VERIFY_STATUS( _lightbulb.begin() ) ;
{
addServiceInstanceID(4);
addServiceInstanceID();
// Name chr
BLECharacteristic chr(HAP_UUID_CHR_VERSION);
+3
View File
@@ -65,10 +65,13 @@ enum
class BLEHomekit : public Advertisable
{
public:
static uint16_t _gInstanceID;
virtual bool setAdv(BLEAdvertisingData& adv);
BLEHomekit();
err_t begin();
HAPAccessoryInfo AccessoryInfo;
private:
+2 -5
View File
@@ -39,9 +39,6 @@
#include "BLEHomekit.h"
#include "HAPService.h"
// Starting from 1 for Accessory Info
uint16_t HAPService::_g_svc_id = 1;
err_t HAPService::begin(void)
{
VERIFY_STATUS( BLEService::begin() );
@@ -59,8 +56,8 @@ err_t HAPService::_addSvcID(void)
chr.setFixedLen(2);
VERIFY_STATUS( chr.begin() );
_sid = _g_svc_id++;
chr.write( _sid );
_svc_id = BLEHomekit::_gInstanceID++;
chr.write( _svc_id );
return ERROR_NONE;
}
+2 -4
View File
@@ -41,13 +41,11 @@
class HAPService : public BLEService
{
public:
static uint16_t _g_svc_id;
HAPService(BLEUuid bleuuid) : BLEService(bleuuid) {}
HAPService(BLEUuid bleuuid) : BLEService(bleuuid) { _svc_id = 0; }
virtual err_t begin(void);
private:
uint16_t _sid;
uint16_t _svc_id;
// Service Instance ID
err_t _addSvcID(void);