Cleaned up compiler warnings

* Changed ~SpanService to virtual function to ensure any user-defined destructor is also called

* Found/corrected bug in error message related to defining a Characteristic without any Service

* Added warning/error ID numbers to warning/error messages

* Other misc changes to clean up compiler warnings
This commit is contained in:
Gregg 2022-12-02 17:49:54 -06:00
parent cc443f8f08
commit 484f1c4f2e
4 changed files with 35 additions and 33 deletions

View File

@ -705,7 +705,7 @@ int HAPClient::postPairVerifyURL(){
memcpy(iosCurveKey,tlv8.buf(kTLVType_PublicKey),32); // save iosCurveKey (will persist until end of verification process)
int _x = crypto_scalarmult_curve25519(sharedCurveKey,secretCurveKey,iosCurveKey); // generate (and persist) Pair Verify SharedSecret CurveKey from Accessory's Curve25519 secret key and Controller's Curve25519 public key (32 bytes)
crypto_scalarmult_curve25519(sharedCurveKey,secretCurveKey,iosCurveKey); // generate (and persist) Pair Verify SharedSecret CurveKey from Accessory's Curve25519 secret key and Controller's Curve25519 public key (32 bytes)
uint8_t *accessoryPairingID = accessory.ID; // set accessoryPairingID
size_t accessoryPairingIDLen = 17;
@ -1235,7 +1235,7 @@ int HAPClient::getStatusURL(){
sprintf(clocktime,"Unknown");
}
char uptime[16];
char uptime[32];
int seconds=esp_timer_get_time()/1e6;
int secs=seconds%60;
int mins=(seconds/=60)%60;

View File

@ -40,7 +40,7 @@
#include "HomeSpan.h"
#include "HAP.h"
const __attribute__((section(".rodata_custom_desc"))) SpanPartition spanPartition = {HOMESPAN_MAGIC_COOKIE};
const __attribute__((section(".rodata_custom_desc"))) SpanPartition spanPartition = {HOMESPAN_MAGIC_COOKIE,0};
using namespace Utils;
@ -903,10 +903,10 @@ void Span::processSerialCommand(const char *c){
boolean foundInfo=false;
if(acc==Accessories.begin() && (*acc)->aid!=1)
Serial.printf(" *** ERROR! AID of first Accessory must always be 1 ***\n",nErrors++);
Serial.printf(" *** ERROR #%d! AID of first Accessory must always be 1 ***\n",++nErrors);
if(aidValues.find((*acc)->aid)!=aidValues.end())
Serial.printf(" *** ERROR! AID already in use for another Accessory ***\n",nErrors++);
Serial.printf(" *** ERROR #%d! AID already in use for another Accessory ***\n",++nErrors);
aidValues.insert((*acc)->aid);
@ -917,7 +917,7 @@ void Span::processSerialCommand(const char *c){
if(!strcmp((*svc)->type,"3E")){
foundInfo=true;
if((*svc)->iid!=1)
Serial.printf(" *** ERROR! The Accessory Information Service must be defined before any other Services in an Accessory ***\n",nErrors++);
Serial.printf(" *** ERROR #%d! The Accessory Information Service must be defined 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...
isBridge=false; // ...this is not a bridge device
@ -948,22 +948,22 @@ void Span::processSerialCommand(const char *c){
Serial.printf("\n");
if(!(*chr)->isCustom && !(*svc)->isCustom && (*svc)->req.find((*chr)->hapChar)==(*svc)->req.end() && (*svc)->opt.find((*chr)->hapChar)==(*svc)->opt.end())
Serial.printf(" *** WARNING! Service does not support this Characteristic ***\n",nWarnings++);
Serial.printf(" *** WARNING #%d! Service does not support this Characteristic ***\n",++nWarnings);
else
if(invalidUUID((*chr)->type,(*chr)->isCustom))
Serial.printf(" *** ERROR! Format of UUID is invalid ***\n",nErrors++);
Serial.printf(" *** ERROR #%d! Format of UUID is invalid ***\n",++nErrors);
else
if(hapChar.find((*chr)->hapChar)!=hapChar.end())
Serial.printf(" *** ERROR! Characteristic already defined for this Service ***\n",nErrors++);
Serial.printf(" *** ERROR #%d! Characteristic already defined for this Service ***\n",++nErrors);
if((*chr)->setRangeError)
Serial.printf(" *** WARNING! Attempt to set Custom Range for this Characteristic ignored ***\n",nWarnings++);
Serial.printf(" *** WARNING #%d! Attempt to set Custom Range for this Characteristic ignored ***\n",++nWarnings);
if((*chr)->setValidValuesError)
Serial.printf(" *** WARNING! Attempt to set Custom Valid Values for this Characteristic ignored ***\n",nWarnings++);
Serial.printf(" *** WARNING #%d! Attempt to set Custom Valid Values for this Characteristic ignored ***\n",++nWarnings);
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),nWarnings++);
Serial.printf(" *** 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));
hapChar.insert((*chr)->hapChar);
@ -971,7 +971,7 @@ void Span::processSerialCommand(const char *c){
for(auto req=(*svc)->req.begin(); req!=(*svc)->req.end(); req++){
if(hapChar.find(*req)==hapChar.end())
Serial.printf(" *** WARNING! Required '%s' Characteristic for this Service not found ***\n",(*req)->hapName,nWarnings++);
Serial.printf(" *** WARNING #%d! Required '%s' Characteristic for this Service not found ***\n",++nWarnings,(*req)->hapName);
}
for(auto button=PushButtons.begin(); button!=PushButtons.end(); button++){
@ -990,14 +990,14 @@ void Span::processSerialCommand(const char *c){
Serial.printf("USER-DEFINED\n");
if((void(*)(int,int))((*svc)->*(&SpanService::button))==(void(*)(int,int))(&SpanService::button))
Serial.printf(" *** WARNING! No button() method defined in this Service ***\n",nWarnings++);
Serial.printf(" *** WARNING #%d! No button() method defined in this Service ***\n",++nWarnings);
}
}
} // Services
if(!foundInfo)
Serial.printf(" *** ERROR! Required 'AccessoryInformation' Service not found ***\n",nErrors++);
Serial.printf(" *** ERROR #%d! Required 'AccessoryInformation' Service not found ***\n",++nErrors);
} // Accessories
@ -1077,9 +1077,13 @@ void Span::processSerialCommand(const char *c){
uCom->second->userFunction1(c+1);
else
uCom->second->userFunction2(c+1,uCom->second->userArg);
break;
} else {
Serial.print("*** Undefined user command: '");
Serial.print(c);
Serial.print("'. Type '?' for list of commands.\n");
}
}
break;
default:
Serial.print("*** Unknown command: '");
@ -1730,12 +1734,6 @@ int SpanService::sprintfAttributes(char *cBuf, int flags){
SpanCharacteristic::SpanCharacteristic(HapChar *hapChar, boolean isCustom){
if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){
Serial.printf("\nFATAL ERROR! Can't create new Characteristic '%s' without a defined Service ***\n",hapName);
Serial.printf("\n=== PROGRAM HALTED ===");
while(1);
}
type=hapChar->type;
perms=hapChar->perms;
hapName=hapChar->hapName;
@ -1744,6 +1742,12 @@ SpanCharacteristic::SpanCharacteristic(HapChar *hapChar, boolean isCustom){
this->isCustom=isCustom;
this->hapChar=hapChar;
if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){
Serial.printf("\nFATAL ERROR! Can't create new Characteristic '%s' without a defined Service ***\n",hapName);
Serial.printf("\n=== PROGRAM HALTED ===");
while(1);
}
homeSpan.Accessories.back()->Services.back()->Characteristics.push_back(this);
iid=++(homeSpan.Accessories.back()->iidCount);
service=homeSpan.Accessories.back()->Services.back();

View File

@ -32,6 +32,7 @@
#endif
#pragma GCC diagnostic ignored "-Wpmf-conversions" // eliminates warning messages from use of pointers to member functions to detect whether update() and loop() are overridden by user
#pragma GCC diagnostic ignored "-Wunused-result" // eliminates warning message regarded unused result from call to crypto_scalarmult_curve25519()
#include <Arduino.h>
#include <unordered_map>
@ -390,7 +391,7 @@ class SpanService{
protected:
~SpanService(); // destructor
virtual ~SpanService(); // destructor
unordered_set<HapChar *> req; // unordered set of pointers to all required HAP Characteristic Types for this Service
unordered_set<HapChar *> opt; // unordered set of pointers to all optional HAP Characteristic Types for this Service
@ -472,7 +473,7 @@ class SpanCharacteristic{
sprintf(c,"%llu",u.UINT64);
return(String(c));
case FORMAT::FLOAT:
sprintf(c,"%llg",u.FLOAT);
sprintf(c,"%g",u.FLOAT);
return(String(c));
case FORMAT::STRING:
sprintf(c,"\"%s\"",u.STRING);
@ -516,6 +517,8 @@ class SpanCharacteristic{
case FORMAT::FLOAT:
u.FLOAT=(double)val;
break;
case FORMAT::STRING:
break;
} // switch
}
@ -536,6 +539,8 @@ class SpanCharacteristic{
return((T) u.UINT64);
case FORMAT::FLOAT:
return((T) u.FLOAT);
case FORMAT::STRING:
break;
}
return(0); // included to prevent compiler warnings
}
@ -546,37 +551,32 @@ class SpanCharacteristic{
template <typename T, typename A=boolean, typename B=boolean> void init(T val, boolean nvsStore, A min=0, B max=1){
int nvsFlag=0;
uvSet(value,val);
if(nvsStore){
nvsKey=(char *)malloc(16);
uint16_t t;
sscanf(type,"%x",&t);
sscanf(type,"%hx",&t);
sprintf(nvsKey,"%04X%08X%03X",t,aid,iid&0xFFF);
size_t len;
if(format != FORMAT::STRING){
if(!nvs_get_blob(homeSpan.charNVS,nvsKey,NULL,&len)){
nvs_get_blob(homeSpan.charNVS,nvsKey,&value,&len);
nvsFlag=2;
}
else {
nvs_set_blob(homeSpan.charNVS,nvsKey,&value,sizeof(UVal)); // store data
nvs_commit(homeSpan.charNVS); // commit to NVS
nvsFlag=1;
}
} else {
if(!nvs_get_str(homeSpan.charNVS,nvsKey,NULL,&len)){
char c[len];
nvs_get_str(homeSpan.charNVS,nvsKey,c,&len);
uvSet(value,(const char *)c);
nvsFlag=2;
}
else {
nvs_set_str(homeSpan.charNVS,nvsKey,value.STRING); // store string data
nvs_commit(homeSpan.charNVS); // commit to NVS
nvsFlag=1;
}
}
}

View File

@ -65,8 +65,6 @@ void setup() {
homeSpan.begin(Category::Lighting,"HomeSpan Lamp Server","homespan");
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
@ -92,7 +90,7 @@ void setup() {
new Service::LightBulb();
new Characteristic::On(0,true);
(new Characteristic::Brightness(50,false))->setRange(10,100,5);
(new Characteristic::Brightness())->setRange(10,100,5);
new Characteristic::Name("Light 2");
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments