Added enum and logic for TLV Characteristics

This commit is contained in:
Gregg 2024-03-17 19:54:48 -05:00
parent 41f755039f
commit 6bc45cf884
3 changed files with 9 additions and 5 deletions

View File

@ -49,7 +49,8 @@ enum FORMAT { // HAP Table 6-5
INT=5, INT=5,
FLOAT=6, FLOAT=6,
STRING=7, STRING=7,
DATA=8 DATA=8,
TLV_ENC=9
}; };
/////////////////////////////// ///////////////////////////////

View File

@ -529,6 +529,7 @@ class SpanCharacteristic{
return(String(c)); return(String(c));
case FORMAT::STRING: case FORMAT::STRING:
case FORMAT::DATA: case FORMAT::DATA:
case FORMAT::TLV_ENC:
sprintf(c,"\"%.64s\"",u.STRING); // Truncating string to 64 chars sprintf(c,"\"%.64s\"",u.STRING); // Truncating string to 64 chars
return(String(c)); return(String(c));
} // switch } // switch
@ -536,7 +537,7 @@ class SpanCharacteristic{
} }
void uvSet(UVal &dest, UVal &src){ void uvSet(UVal &dest, UVal &src){
if(format==FORMAT::STRING || format==FORMAT::DATA) if(format==FORMAT::STRING || format==FORMAT::DATA || format==FORMAT::TLV_ENC)
uvSet(dest,(const char *)src.STRING); uvSet(dest,(const char *)src.STRING);
else else
dest=src; dest=src;
@ -572,6 +573,7 @@ class SpanCharacteristic{
break; break;
case FORMAT::STRING: case FORMAT::STRING:
case FORMAT::DATA: case FORMAT::DATA:
case FORMAT::TLV_ENC:
break; break;
} // switch } // switch
} }
@ -595,6 +597,7 @@ class SpanCharacteristic{
return((T) u.FLOAT); return((T) u.FLOAT);
case FORMAT::STRING: case FORMAT::STRING:
case FORMAT::DATA: case FORMAT::DATA:
case FORMAT::TLV_ENC:
break; break;
} }
return((T)0); // included to prevent compiler warnings return((T)0); // included to prevent compiler warnings
@ -615,7 +618,7 @@ class SpanCharacteristic{
sprintf(nvsKey,"%04X%08X%03X",t,aid,iid&0xFFF); sprintf(nvsKey,"%04X%08X%03X",t,aid,iid&0xFFF);
size_t len; size_t len;
if(format!=FORMAT::STRING && format!=FORMAT::DATA){ if(format!=FORMAT::STRING && format!=FORMAT::DATA && format!=FORMAT::TLV_ENC){
if(nvs_get_u64(homeSpan.charNVS,nvsKey,&(value.UINT64))!=ESP_OK) { if(nvs_get_u64(homeSpan.charNVS,nvsKey,&(value.UINT64))!=ESP_OK) {
nvs_set_u64(homeSpan.charNVS,nvsKey,value.UINT64); // store data as uint64_t regardless of actual type (it will be read correctly when access through uvGet()) nvs_set_u64(homeSpan.charNVS,nvsKey,value.UINT64); // store data as uint64_t regardless of actual type (it will be read correctly when access through uvGet())
nvs_commit(homeSpan.charNVS); // commit to NVS nvs_commit(homeSpan.charNVS); // commit to NVS
@ -634,7 +637,7 @@ class SpanCharacteristic{
uvSet(newValue,value); uvSet(newValue,value);
if(format!=FORMAT::STRING && format!=FORMAT::DATA) { if(format!=FORMAT::STRING && format!=FORMAT::DATA && format!=FORMAT::TLV_ENC) {
uvSet(minValue,min); uvSet(minValue,min);
uvSet(maxValue,max); uvSet(maxValue,max);
uvSet(stepValue,0); uvSet(stepValue,0);

View File

@ -36,7 +36,7 @@
#define HS_MAJOR 1 #define HS_MAJOR 1
#define HS_MINOR 9 #define HS_MINOR 9
#define HS_PATCH 0 #define HS_PATCH 1
#define STRINGIFY(x) _STR(x) #define STRINGIFY(x) _STR(x)
#define _STR(x) #x #define _STR(x) #x