Continuing with 'i' refactoring

Next up: Re-do optional/required Characteristics logic
This commit is contained in:
Gregg 2022-04-30 18:18:15 -05:00
parent 5f463b013e
commit 0e6f7d27f9
2 changed files with 18 additions and 37 deletions

View File

@ -926,16 +926,29 @@ void Span::processSerialCommand(const char *c){
Serial.print("\n*** HomeSpan Info ***\n\n"); Serial.print("\n*** HomeSpan Info ***\n\n");
std::set<uint32_t> aidValues;
for(auto acc=Accessories.begin(); acc!=Accessories.end(); acc++){ for(auto acc=Accessories.begin(); acc!=Accessories.end(); acc++){
Serial.printf("\u27a4 Accessory: AID=%d\n",(*acc)->aid); Serial.printf("\u27a4 Accessory: AID=%d\n",(*acc)->aid);
boolean foundInfo=false; boolean foundInfo=false;
if(acc==Accessories.begin() && (*acc)->aid!=1)
Serial.printf(" *** ERROR! AID of first Accessory must always be 1 ***\n");
if(aidValues.find((*acc)->aid)!=aidValues.end())
Serial.printf(" *** ERROR! AID already in use for another Accessory ***\n");
aidValues.insert((*acc)->aid);
for(auto svc=(*acc)->Services.begin(); svc!=(*acc)->Services.end(); svc++){ for(auto svc=(*acc)->Services.begin(); svc!=(*acc)->Services.end(); svc++){
Serial.printf(" \u279f Service %s: IID=%d, %sUUIS=\"%s\"",(*svc)->hapName,(*svc)->iid,(*svc)->isCustom?"Custom-":"",(*svc)->type); Serial.printf(" \u279f Service %s: IID=%d, %sUUIS=\"%s\"",(*svc)->hapName,(*svc)->iid,(*svc)->isCustom?"Custom-":"",(*svc)->type);
Serial.printf("\n"); Serial.printf("\n");
if(!strcmp((*svc)->type,"3E")) if(!strcmp((*svc)->type,"3E")){
foundInfo=true; foundInfo=true;
if((*svc)->iid!=1)
Serial.printf(" *** ERROR! The Accessory Information Service must be defined before any other Services in an Accessory ***\n");
}
else if((*acc)->aid==1) // this is an Accessory with aid=1, but it has more than just AccessoryInfo. So... else if((*acc)->aid==1) // this is an Accessory with aid=1, but it has more than just AccessoryInfo. So...
isBridge=false; // ...this is not a bridge device isBridge=false; // ...this is not a bridge device
@ -976,7 +989,7 @@ void Span::processSerialCommand(const char *c){
} // Services } // Services
if(!foundInfo) if(!foundInfo)
Serial.printf(" *** ERROR! Required Service::AccessoryInformation() not found ***\n"); Serial.printf(" *** ERROR! Required Accessory Information Service not found ***\n");
} // Accessories } // Accessories
@ -1459,23 +1472,6 @@ SpanAccessory::SpanAccessory(uint32_t aid){
this->aid=aid; this->aid=aid;
} }
homeSpan.configLog+="\u27a4 Accessory: AID=" + String(this->aid);
for(int i=0;i<homeSpan.Accessories.size()-1;i++){
if(this->aid==homeSpan.Accessories[i]->aid){
homeSpan.configLog+=" *** ERROR! ID already in use for another Accessory. ***";
homeSpan.nFatalErrors++;
break;
}
}
if(homeSpan.Accessories.size()==1 && this->aid!=1){
homeSpan.configLog+=" *** ERROR! ID of first Accessory must always be 1. ***";
homeSpan.nFatalErrors++;
}
homeSpan.configLog+="\n";
} }
/////////////////////////////// ///////////////////////////////
@ -1502,15 +1498,13 @@ int SpanAccessory::sprintfAttributes(char *cBuf){
SpanService::SpanService(const char *type, const char *hapName, boolean isCustom){ SpanService::SpanService(const char *type, const char *hapName, boolean isCustom){
if(!homeSpan.Accessories.empty() && !homeSpan.Accessories.back()->Services.empty()) // this is not the first Service to be defined for this Accessory // if(!homeSpan.Accessories.empty() && !homeSpan.Accessories.back()->Services.empty()) // this is not the first Service to be defined for this Accessory
homeSpan.Accessories.back()->Services.back()->validate(); // homeSpan.Accessories.back()->Services.back()->validate();
this->type=type; this->type=type;
this->hapName=hapName; this->hapName=hapName;
this->isCustom=isCustom; this->isCustom=isCustom;
homeSpan.configLog+=" \u279f Service " + String(hapName);
if(homeSpan.Accessories.empty()){ if(homeSpan.Accessories.empty()){
homeSpan.configLog+=" *** ERROR! Can't create new Service without a defined Accessory! ***\n"; homeSpan.configLog+=" *** ERROR! Can't create new Service without a defined Accessory! ***\n";
homeSpan.nFatalErrors++; homeSpan.nFatalErrors++;
@ -1520,20 +1514,6 @@ SpanService::SpanService(const char *type, const char *hapName, boolean isCustom
homeSpan.Accessories.back()->Services.push_back(this); homeSpan.Accessories.back()->Services.push_back(this);
iid=++(homeSpan.Accessories.back()->iidCount); iid=++(homeSpan.Accessories.back()->iidCount);
homeSpan.configLog+=": IID=" + String(iid) + ", " + (isCustom?"Custom-":"") + "UUID=\"" + String(type) + "\"";
if(Span::invalidUUID(type,isCustom)){
homeSpan.configLog+=" *** ERROR! Format of UUID is invalid. ***";
homeSpan.nFatalErrors++;
}
if(!strcmp(this->type,"3E") && iid!=1){
homeSpan.configLog+=" *** ERROR! The AccessoryInformation Service must be defined before any other Services in an Accessory. ***";
homeSpan.nFatalErrors++;
}
homeSpan.configLog+="\n";
} }
/////////////////////////////// ///////////////////////////////

View File

@ -36,6 +36,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <set>
#include <nvs.h> #include <nvs.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>