Added Linked Services logic
New SpanService method addLink(SpanService *svc), where svc is a pointer to the SpanService that is being specified as a Linked Service for the current Service. addLink() returns a pointer to "this" so may be chained
This commit is contained in:
parent
35c8f5b48c
commit
24cc2486e2
|
|
@ -831,20 +831,24 @@ void Span::processSerialCommand(const char *c){
|
|||
Serial.print("\n\n");
|
||||
|
||||
char d[]="------------------------------";
|
||||
char cBuf[256];
|
||||
sprintf(cBuf,"%-30s %s %10s %s %s %s %s\n","Service","Type","AID","IID","Update","Loop","Button");
|
||||
Serial.print(cBuf);
|
||||
sprintf(cBuf,"%.30s %.4s %.10s %.3s %.6s %.4s %.6s\n",d,d,d,d,d,d,d);
|
||||
Serial.print(cBuf);
|
||||
Serial.printf("%-30s %s %10s %s %s %s %s %s\n","Service","Type","AID","IID","Update","Loop","Button","Linked Services");
|
||||
Serial.printf("%.30s %.4s %.10s %.3s %.6s %.4s %.6s %.15s\n",d,d,d,d,d,d,d,d);
|
||||
for(int i=0;i<Accessories.size();i++){ // identify all services with over-ridden loop() methods
|
||||
for(int j=0;j<Accessories[i]->Services.size();j++){
|
||||
SpanService *s=Accessories[i]->Services[j];
|
||||
sprintf(cBuf,"%-30s %4s %10u %3d %6s %4s %6s\n",s->hapName,s->type,Accessories[i]->aid,s->iid,
|
||||
Serial.printf("%-30s %4s %10u %3d %6s %4s %6s ",s->hapName,s->type,Accessories[i]->aid,s->iid,
|
||||
(void(*)())(s->*(&SpanService::update))!=(void(*)())(&SpanService::update)?"YES":"NO",
|
||||
(void(*)())(s->*(&SpanService::loop))!=(void(*)())(&SpanService::loop)?"YES":"NO",
|
||||
(void(*)(int,boolean))(s->*(&SpanService::button))!=(void(*)(int,boolean))(&SpanService::button)?"YES":"NO"
|
||||
);
|
||||
Serial.print(cBuf);
|
||||
if(s->linkedServices.empty())
|
||||
Serial.print("-");
|
||||
for(int k=0;k<s->linkedServices.size();k++){
|
||||
Serial.print(s->linkedServices[k]->iid);
|
||||
if(k<s->linkedServices.size()-1)
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.print("\n");
|
||||
}
|
||||
}
|
||||
Serial.print("\n*** End Info ***\n");
|
||||
|
|
@ -1378,6 +1382,13 @@ SpanService *SpanService::setHidden(){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
SpanService *SpanService::addLink(SpanService *svc){
|
||||
linkedServices.push_back(svc);
|
||||
return(this);
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
int SpanService::sprintfAttributes(char *cBuf){
|
||||
int nBytes=0;
|
||||
|
||||
|
|
@ -1389,6 +1400,16 @@ int SpanService::sprintfAttributes(char *cBuf){
|
|||
if(primary)
|
||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,"\"primary\":true,");
|
||||
|
||||
if(!linkedServices.empty()){
|
||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,"\"linked\":[");
|
||||
for(int i=0;i<linkedServices.size();i++){
|
||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,"%d",linkedServices[i]->iid);
|
||||
if(i+1<linkedServices.size())
|
||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",");
|
||||
}
|
||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,"],");
|
||||
}
|
||||
|
||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,"\"characteristics\":[");
|
||||
|
||||
for(int i=0;i<Characteristics.size();i++){
|
||||
|
|
|
|||
|
|
@ -187,11 +187,13 @@ struct SpanService{
|
|||
vector<SpanCharacteristic *> Characteristics; // vector of pointers to all Characteristics in this Service
|
||||
vector<HapCharType *> req; // vector of pointers to all required HAP Characteristic Types for this Service
|
||||
vector<HapCharType *> opt; // vector of pointers to all optional HAP Characteristic Types for this Service
|
||||
vector<SpanService *> linkedServices; // vector of pointers to any optional linked Services
|
||||
|
||||
SpanService(const char *type, const char *hapName);
|
||||
|
||||
SpanService *setPrimary(); // sets the Service Type to be primary and returns pointer to self
|
||||
SpanService *setHidden(); // sets the Service Type to be hidden and returns pointer to self
|
||||
SpanService *addLink(SpanService *svc); // adds svc as a Linked Service
|
||||
|
||||
int sprintfAttributes(char *cBuf); // prints Service JSON records into buf; return number of characters printed, excluding null terminator
|
||||
void validate(); // error-checks Service
|
||||
|
|
|
|||
16
src/src.ino
16
src/src.ino
|
|
@ -20,10 +20,6 @@ void setup() {
|
|||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpanTest");
|
||||
|
||||
Serial.printf("\nFD_SETSIZE: %d\n",FD_SETSIZE);
|
||||
Serial.printf("CONFIG_LWIP_MAX_SOCKETS: %d\n",CONFIG_LWIP_MAX_SOCKETS);
|
||||
Serial.printf("LWIP_SOCKET_OFFSET: %d\n\n",LWIP_SOCKET_OFFSET);
|
||||
|
||||
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
|
||||
|
||||
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, which has 6 required Characteristics
|
||||
|
|
@ -37,8 +33,16 @@ void setup() {
|
|||
new Service::HAPProtocolInformation(); // Create the HAP Protcol Information Service
|
||||
new Characteristic::Version("1.1.0"); // Set the Version Characteristic to "1.1.0" as required by HAP
|
||||
|
||||
new Service::LightBulb(); // Create the Light Bulb Service
|
||||
new Characteristic::On(); // This Service requires the "On" Characteristic to turn the light on and off
|
||||
SpanService *v1=new Service::Valve();
|
||||
new Characteristic::Active();
|
||||
new Characteristic::InUse();
|
||||
new Characteristic::ValveType();
|
||||
SpanService *v2=new Service::Valve();
|
||||
new Characteristic::Active();
|
||||
new Characteristic::InUse();
|
||||
new Characteristic::ValveType();
|
||||
(new Service::Faucet())->addLink(v1)->addLink(v2);
|
||||
new Characteristic::Active();
|
||||
|
||||
} // end of setup()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue