created getDataGeneric() and getStringGeneric()
Though this simplifies the code, the code size is still the same - compiler must have already optimized these functions.
This commit is contained in:
parent
1892a0a5a2
commit
3d4b02e492
|
|
@ -661,19 +661,15 @@ class SpanCharacteristic{
|
||||||
return(uvGet<T>(newValue));
|
return(uvGet<T>(newValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getString(){
|
char *getStringGeneric(UVal &val){
|
||||||
if(format>=FORMAT::STRING)
|
if(format>=FORMAT::STRING)
|
||||||
return value.STRING;
|
return val.STRING;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getNewString(){
|
char *getString(){return(getStringGeneric(value));}
|
||||||
if(format>=FORMAT::STRING)
|
char *getNewString(){return(getStringGeneric(newValue));}
|
||||||
return newValue.STRING;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setString(const char *val, boolean notify=true){
|
void setString(const char *val, boolean notify=true){
|
||||||
|
|
||||||
|
|
@ -682,12 +678,12 @@ class SpanCharacteristic{
|
||||||
setValFinish(notify);
|
setValFinish(notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getData(uint8_t *data, size_t len){
|
size_t getDataGeneric(uint8_t *data, size_t len, UVal &val){
|
||||||
if(format<FORMAT::DATA)
|
if(format<FORMAT::DATA)
|
||||||
return(0);
|
return(0);
|
||||||
|
|
||||||
size_t olen;
|
size_t olen;
|
||||||
int ret=mbedtls_base64_decode(data,len,&olen,(uint8_t *)value.STRING,strlen(value.STRING));
|
int ret=mbedtls_base64_decode(data,len,&olen,(uint8_t *)val.STRING,strlen(val.STRING));
|
||||||
|
|
||||||
if(data==NULL)
|
if(data==NULL)
|
||||||
return(olen);
|
return(olen);
|
||||||
|
|
@ -700,23 +696,8 @@ class SpanCharacteristic{
|
||||||
return(olen);
|
return(olen);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getNewData(uint8_t *data, size_t len){
|
size_t getData(uint8_t *data, size_t len){return(getDataGeneric(data,len,value));}
|
||||||
if(format<FORMAT::DATA)
|
size_t getNewData(uint8_t *data, size_t len){return(getDataGeneric(data,len,newValue));}
|
||||||
return(0);
|
|
||||||
|
|
||||||
size_t olen;
|
|
||||||
int ret=mbedtls_base64_decode(data,len,&olen,(uint8_t *)newValue.STRING,strlen(newValue.STRING));
|
|
||||||
|
|
||||||
if(data==NULL)
|
|
||||||
return(olen);
|
|
||||||
|
|
||||||
if(ret==MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL)
|
|
||||||
LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Destination buffer is too small (%d out of %d bytes needed)!\n\n",hapName,len,olen);
|
|
||||||
else if(ret==MBEDTLS_ERR_BASE64_INVALID_CHARACTER)
|
|
||||||
LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Data is not in base-64 format!\n\n",hapName);
|
|
||||||
|
|
||||||
return(olen);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setData(uint8_t *data, size_t len, boolean notify=true){
|
void setData(uint8_t *data, size_t len, boolean notify=true){
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ struct HomeSpanTV : Service::Television {
|
||||||
static void setTVName(const char *buf, void *arg){
|
static void setTVName(const char *buf, void *arg){
|
||||||
HomeSpanTV *hsTV=(HomeSpanTV *)arg;
|
HomeSpanTV *hsTV=(HomeSpanTV *)arg;
|
||||||
hsTV->tvname->setString("New Name");
|
hsTV->tvname->setString("New Name");
|
||||||
|
Serial.printf("Reset TV Name to '%s'\n",hsTV->tvname->getString());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void changeOrder(const char *buf, void *arg){
|
static void changeOrder(const char *buf, void *arg){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue