Continuing to refactor 'i' CLI command
This commit is contained in:
parent
88f2373a71
commit
5f463b013e
|
|
@ -184,11 +184,8 @@ void Span::pollTask() {
|
||||||
if(!homeSpan.Accessories.back()->Services.empty())
|
if(!homeSpan.Accessories.back()->Services.empty())
|
||||||
homeSpan.Accessories.back()->Services.back()->validate();
|
homeSpan.Accessories.back()->Services.back()->validate();
|
||||||
|
|
||||||
homeSpan.Accessories.back()->validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRanges();
|
|
||||||
|
|
||||||
if(nWarnings>0){
|
if(nWarnings>0){
|
||||||
configLog+="\n*** CAUTION: There " + String((nWarnings>1?"are ":"is ")) + String(nWarnings) + " WARNING" + (nWarnings>1?"S":"") + " associated with this configuration that may lead to the device becoming non-responsive, or operating in an unexpected manner. ***\n";
|
configLog+="\n*** CAUTION: There " + String((nWarnings>1?"are ":"is ")) + String(nWarnings) + " WARNING" + (nWarnings>1?"S":"") + " associated with this configuration that may lead to the device becoming non-responsive, or operating in an unexpected manner. ***\n";
|
||||||
}
|
}
|
||||||
|
|
@ -931,10 +928,16 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
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"))
|
||||||
|
foundInfo=true;
|
||||||
|
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
|
||||||
|
|
||||||
for(auto chr=(*svc)->Characteristics.begin(); chr!=(*svc)->Characteristics.end(); chr++){
|
for(auto chr=(*svc)->Characteristics.begin(); chr!=(*svc)->Characteristics.end(); chr++){
|
||||||
Serial.printf(" \u21e8 Characteristic %s(%s): IID=%d, %sUUID=\"%s\"",(*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type);
|
Serial.printf(" \u21e8 Characteristic %s(%s): IID=%d, %sUUID=\"%s\"",(*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type);
|
||||||
|
|
@ -951,31 +954,38 @@ void Span::processSerialCommand(const char *c){
|
||||||
Serial.printf("\n");
|
Serial.printf("\n");
|
||||||
|
|
||||||
if(!(*chr)->isSupported)
|
if(!(*chr)->isSupported)
|
||||||
Serial.printf(" *** WARNING! Service does not support this Characteristic. ***\n");
|
Serial.printf(" *** WARNING! Service does not support this Characteristic ***\n");
|
||||||
else
|
else
|
||||||
if(invalidUUID((*chr)->type,(*chr)->isCustom))
|
if(invalidUUID((*chr)->type,(*chr)->isCustom))
|
||||||
Serial.printf(" *** ERROR! Format of UUID is invalid. ***\n");
|
Serial.printf(" *** ERROR! Format of UUID is invalid ***\n");
|
||||||
else
|
else
|
||||||
if((*chr)->isRepeated)
|
if((*chr)->isRepeated)
|
||||||
Serial.printf(" *** ERROR! Characteristic already defined for this Service. ***\n");
|
Serial.printf(" *** ERROR! Characteristic already defined for this Service ***\n");
|
||||||
|
|
||||||
if((*chr)->setRangeError)
|
if((*chr)->setRangeError)
|
||||||
Serial.printf(" *** WARNING! Attempt to set Custom Range for this Characteristic ignored. ***\n");
|
Serial.printf(" *** WARNING! Attempt to set Custom Range for this Characteristic ignored ***\n");
|
||||||
|
|
||||||
|
if((*chr)->format!=STRING && ((*chr)->uvGet<double>((*chr)->value) < (*chr)->uvGet<double>((*chr)->minValue) || (*chr)->uvGet<double>((*chr)->value) > (*chr)->uvGet<double>((*chr)->maxValue)))
|
||||||
|
Serial.printf(" *** WARNING! Value of %llg is out of range [%llg,%llg] ***\n",(*chr)->uvGet<double>((*chr)->value),(*chr)->uvGet<double>((*chr)->minValue),(*chr)->uvGet<double>((*chr)->maxValue));
|
||||||
|
|
||||||
// 1. RANGE CHECK
|
|
||||||
// 2. MISSING REQUIRED CHARACTERISTICS
|
// 2. MISSING REQUIRED CHARACTERISTICS
|
||||||
// 3. AID CHECK
|
// 3. AID CHECK
|
||||||
|
|
||||||
}
|
} // Characteristics
|
||||||
}
|
|
||||||
}
|
} // Services
|
||||||
|
|
||||||
|
if(!foundInfo)
|
||||||
|
Serial.printf(" *** ERROR! Required Service::AccessoryInformation() not found ***\n");
|
||||||
|
|
||||||
|
} // Accessories
|
||||||
|
|
||||||
Serial.print("\n------------\n\n");
|
Serial.print("\n------------\n\n");
|
||||||
|
|
||||||
Serial.println(configLog);
|
Serial.println(configLog);
|
||||||
|
|
||||||
Serial.print("\nConfigured as Bridge: ");
|
Serial.print("\nConfigured as Bridge: ");
|
||||||
Serial.print(homeSpan.isBridge?"YES":"NO");
|
Serial.print(isBridge?"YES":"NO");
|
||||||
Serial.print("\n\n");
|
Serial.print("\n\n");
|
||||||
|
|
||||||
char d[]="------------------------------";
|
char d[]="------------------------------";
|
||||||
|
|
@ -1419,37 +1429,6 @@ int Span::sprintfAttributes(char **ids, int numIDs, int flags, char *cBuf){
|
||||||
return(nChars);
|
return(nChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
|
||||||
|
|
||||||
void Span::checkRanges(){
|
|
||||||
|
|
||||||
boolean okay=true;
|
|
||||||
homeSpan.configLog+="\nRange Check:";
|
|
||||||
|
|
||||||
for(int i=0;i<Accessories.size();i++){
|
|
||||||
for(int j=0;j<Accessories[i]->Services.size();j++){
|
|
||||||
for(int k=0;k<Accessories[i]->Services[j]->Characteristics.size();k++){
|
|
||||||
SpanCharacteristic *chr=Accessories[i]->Services[j]->Characteristics[k];
|
|
||||||
|
|
||||||
if(chr->format!=STRING && (chr->uvGet<double>(chr->value) < chr->uvGet<double>(chr->minValue) || chr->uvGet<double>(chr->value) > chr->uvGet<double>(chr->maxValue))){
|
|
||||||
char c[256];
|
|
||||||
sprintf(c,"\n \u2718 Characteristic %s with AID=%d, IID=%d: Initial value of %lg is out of range [%llg,%llg]",
|
|
||||||
chr->hapName,chr->aid,chr->iid,chr->uvGet<double>(chr->value),chr->uvGet<double>(chr->minValue),chr->uvGet<double>(chr->maxValue));
|
|
||||||
if(okay)
|
|
||||||
homeSpan.configLog+="\n";
|
|
||||||
homeSpan.configLog+=c;
|
|
||||||
homeSpan.nWarnings++;
|
|
||||||
okay=false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(okay)
|
|
||||||
homeSpan.configLog+=" No Warnings";
|
|
||||||
homeSpan.configLog+="\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
// SpanAccessory //
|
// SpanAccessory //
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -1469,8 +1448,7 @@ SpanAccessory::SpanAccessory(uint32_t aid){
|
||||||
|
|
||||||
if(!homeSpan.Accessories.back()->Services.empty())
|
if(!homeSpan.Accessories.back()->Services.empty())
|
||||||
homeSpan.Accessories.back()->Services.back()->validate();
|
homeSpan.Accessories.back()->Services.back()->validate();
|
||||||
|
|
||||||
homeSpan.Accessories.back()->validate();
|
|
||||||
} else {
|
} else {
|
||||||
this->aid=1;
|
this->aid=1;
|
||||||
}
|
}
|
||||||
|
|
@ -1502,27 +1480,6 @@ SpanAccessory::SpanAccessory(uint32_t aid){
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
void SpanAccessory::validate(){
|
|
||||||
|
|
||||||
boolean foundInfo=false;
|
|
||||||
|
|
||||||
for(int i=0;i<Services.size();i++){
|
|
||||||
if(!strcmp(Services[i]->type,"3E"))
|
|
||||||
foundInfo=true;
|
|
||||||
else if(aid==1) // this is an Accessory with aid=1, but it has more than just AccessoryInfo. So...
|
|
||||||
homeSpan.isBridge=false; // ...this is not a bridge device
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!foundInfo){
|
|
||||||
homeSpan.configLog+=" \u2718 Service AccessoryInformation";
|
|
||||||
homeSpan.configLog+=" *** ERROR! Required Service for this Accessory not found. ***\n";
|
|
||||||
homeSpan.nFatalErrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////
|
|
||||||
|
|
||||||
int SpanAccessory::sprintfAttributes(char *cBuf){
|
int SpanAccessory::sprintfAttributes(char *cBuf){
|
||||||
int nBytes=0;
|
int nBytes=0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,6 @@ struct Span{
|
||||||
void checkConnect(); // check WiFi connection; connect if needed
|
void checkConnect(); // check WiFi connection; connect if needed
|
||||||
void commandMode(); // allows user to control and reset HomeSpan settings with the control button
|
void commandMode(); // allows user to control and reset HomeSpan settings with the control button
|
||||||
void processSerialCommand(const char *c); // process command 'c' (typically from readSerial, though can be called with any 'c')
|
void processSerialCommand(const char *c); // process command 'c' (typically from readSerial, though can be called with any 'c')
|
||||||
void checkRanges(); // checks values of all Characteristics to ensure they are each within range
|
|
||||||
|
|
||||||
int sprintfAttributes(char *cBuf); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
int sprintfAttributes(char *cBuf); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||||
void prettyPrint(char *buf, int nsp=2); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces
|
void prettyPrint(char *buf, int nsp=2); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces
|
||||||
|
|
@ -285,7 +284,6 @@ struct SpanAccessory{
|
||||||
SpanAccessory(uint32_t aid=0);
|
SpanAccessory(uint32_t aid=0);
|
||||||
|
|
||||||
int sprintfAttributes(char *cBuf); // prints Accessory JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
int sprintfAttributes(char *cBuf); // prints Accessory JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||||
void validate(); // error-checks Accessory
|
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue