From eb821f002f1fad8b1a78cf991d7f99271a4a0f86 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 31 Mar 2024 09:23:23 -0500 Subject: [PATCH] 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. --- src/HomeSpan.h | 24 +++++++++++++++++++++--- src/src.ino | 7 +++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 919a213..97a102e 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -736,6 +736,25 @@ class SpanCharacteristic{ } + size_t getTLV(TLV8 &tlv){ + if(format 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 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(minValue)) && (val <= uvGet(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(minValue),uvGet(maxValue)); diff --git a/src/src.ino b/src/src.ino index ef3f4b1..d6ce93f 100644 --- a/src/src.ino +++ b/src/src.ino @@ -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