created getTLV(TLV8 &tlv)

Works, but is memory-inefficient since it decodes entire string before unpacking.  Need to add new functionality to TLV8 so that unpacking can be done in chunks similar to how pack() works.

Also need to create getNewTLV() OR make all get/getNew generic to reduce code size.
This commit is contained in:
Gregg 2024-03-31 09:23:23 -05:00
parent cbe26c7c41
commit eb821f002f
2 changed files with 28 additions and 3 deletions

View File

@ -736,6 +736,25 @@ class SpanCharacteristic{
}
size_t getTLV(TLV8 &tlv){
if(format<FORMAT::TLV_ENC)
return(0);
size_t olen;
mbedtls_base64_decode(NULL,0,&olen,(uint8_t *)value.STRING,strlen(value.STRING)); // get length of buffer needed to decode
TempBuffer<uint8_t> tBuf(olen); // create temporary buffer
int ret=mbedtls_base64_decode(tBuf,olen,&olen,(uint8_t *)value.STRING,strlen(value.STRING));
if(ret==MBEDTLS_ERR_BASE64_INVALID_CHARACTER){
LOG0("\n*** WARNING: Can't decode Characteristic::%s with getTLV(). Data is not in base-64 format\n\n",hapName);
return(0);
}
tlv.unpack(tBuf,olen);
return(tlv.pack_size());
}
void setTLV(TLV8 &tlv, boolean notify=true){
setValCheck();
@ -793,9 +812,8 @@ class SpanCharacteristic{
template <typename T> void setVal(T val, boolean notify=true){
if(updateFlag==1)
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal() within update() while it is being updated by Home App. This may cause device to become non-responsive!\n\n",hapName);
setValCheck();
if(!((val >= uvGet<T>(minValue)) && (val <= uvGet<T>(maxValue)))){
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal(%g) is out of range [%g,%g]. This may cause device to become non-responsive!\n\n",
hapName,(double)val,uvGet<double>(minValue),uvGet<double>(maxValue));

View File

@ -122,6 +122,12 @@ struct HomeSpanTV : Service::Television {
HomeSpanTV *hsTV=(HomeSpanTV *)arg;
TLV8 orderTLV;
Serial.printf("BEFORE:\n");
hsTV->displayOrder->getTLV(orderTLV);
orderTLV.print();
orderTLV.wipe();
uint32_t order[]={12,10,6,2,1,9,11,3,18,5};
for(int i=0;i<sizeof(order)/sizeof(uint32_t);i++){
@ -130,6 +136,7 @@ struct HomeSpanTV : Service::Television {
orderTLV.add(1,sizeof(uint32_t),(uint8_t*)(order+i));
}
Serial.printf("AFTER:\n");
orderTLV.print();
size_t n=orderTLV.pack_size();
Serial.printf("Size=%d\n",n);