Added error-checking for homeSpan.resetIID()

HomeSpan will throw a Warning when 'i' CLI command finds a duplicate IID within the same Accessory.
This commit is contained in:
Gregg 2024-04-16 21:56:07 -05:00
parent fe3269e9ef
commit b9efa873dc
1 changed files with 17 additions and 8 deletions

View File

@ -874,6 +874,7 @@ void Span::processSerialCommand(const char *c){
LOG0(" *** ERROR #%d! AID already in use for another Accessory ***\n",++nErrors); LOG0(" *** ERROR #%d! AID already in use for another Accessory ***\n",++nErrors);
aidValues.push_back((*acc)->aid); aidValues.push_back((*acc)->aid);
vector<uint32_t, Mallocator<uint32_t>> iidValues;
for(auto svc=(*acc)->Services.begin(); svc!=(*acc)->Services.end(); svc++){ for(auto svc=(*acc)->Services.begin(); svc!=(*acc)->Services.end(); svc++){
LOG0(" \u279f Service %s: IID=%d, %sUUID=\"%s\"\n",(*svc)->hapName,(*svc)->iid,(*svc)->isCustom?"Custom-":"",(*svc)->type); LOG0(" \u279f Service %s: IID=%d, %sUUID=\"%s\"\n",(*svc)->hapName,(*svc)->iid,(*svc)->isCustom?"Custom-":"",(*svc)->type);
@ -881,11 +882,16 @@ void Span::processSerialCommand(const char *c){
if(!strcmp((*svc)->type,"3E")){ if(!strcmp((*svc)->type,"3E")){
foundInfo=true; foundInfo=true;
if((*svc)->iid!=1) if((*svc)->iid!=1)
LOG0(" *** ERROR #%d! The Accessory Information Service must be defined before any other Services in an Accessory ***\n",++nErrors); LOG0(" *** ERROR #%d! The Accessory Information Service must be defined with IID=1 (i.e. before any other Services in an Accessory) ***\n",++nErrors);
} }
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
if(std::find(iidValues.begin(),iidValues.end(),(*svc)->iid)!=iidValues.end())
LOG0(" *** ERROR #%d! IID already in use for another Service or Characteristic within this Accessory ***\n",++nErrors);
iidValues.push_back((*svc)->iid);
for(auto chr=(*svc)->Characteristics.begin(); chr!=(*svc)->Characteristics.end(); chr++){ for(auto chr=(*svc)->Characteristics.begin(); chr!=(*svc)->Characteristics.end(); chr++){
LOG0(" \u21e8 Characteristic %s(%.33s%s): IID=%d, %sUUID=\"%s\", %sPerms=", LOG0(" \u21e8 Characteristic %s(%.33s%s): IID=%d, %sUUID=\"%s\", %sPerms=",
(*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),strlen((*chr)->uvPrint((*chr)->value).c_str())>33?"...\"":"",(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type,(*chr)->perms!=(*chr)->hapChar->perms?"Custom-":""); (*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),strlen((*chr)->uvPrint((*chr)->value).c_str())>33?"...\"":"",(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type,(*chr)->perms!=(*chr)->hapChar->perms?"Custom-":"");
@ -940,6 +946,11 @@ void Span::processSerialCommand(const char *c){
if((*chr)->format<STRING && (!(((*chr)->uvGet<double>((*chr)->value) >= (*chr)->uvGet<double>((*chr)->minValue)) && ((*chr)->uvGet<double>((*chr)->value) <= (*chr)->uvGet<double>((*chr)->maxValue))))) if((*chr)->format<STRING && (!(((*chr)->uvGet<double>((*chr)->value) >= (*chr)->uvGet<double>((*chr)->minValue)) && ((*chr)->uvGet<double>((*chr)->value) <= (*chr)->uvGet<double>((*chr)->maxValue)))))
LOG0(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet<double>((*chr)->value),(*chr)->uvGet<double>((*chr)->minValue),(*chr)->uvGet<double>((*chr)->maxValue)); LOG0(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet<double>((*chr)->value),(*chr)->uvGet<double>((*chr)->minValue),(*chr)->uvGet<double>((*chr)->maxValue));
if(std::find(iidValues.begin(),iidValues.end(),(*chr)->iid)!=iidValues.end())
LOG0(" *** ERROR #%d! IID already in use for another Service or Characteristic within this Accessory ***\n",++nErrors);
iidValues.push_back((*chr)->iid);
} // Characteristics } // Characteristics
for(auto req=(*svc)->req.begin(); req!=(*svc)->req.end(); req++){ for(auto req=(*svc)->req.begin(); req!=(*svc)->req.end(); req++){
@ -1594,15 +1605,13 @@ Span& Span::resetIID(int newIID){
while(1); while(1);
} }
newIID--; if(newIID<1){
LOG0("\nFATAL ERROR! Request to reset the Accessory IID count to 0 not allowed (IID must be 1 or greater) ***\n");
if(newIID<Accessories.back()->iidCount){
LOG0("\nFATAL ERROR! Can't reset the Accessory IID count to a value less than already used ***\n");
LOG0("\n=== PROGRAM HALTED ==="); LOG0("\n=== PROGRAM HALTED ===");
while(1); while(1);
} }
Accessories.back()->iidCount=newIID; Accessories.back()->iidCount=newIID-1;
return(*this); return(*this);
} }