From 9b0b18310ec31ee9b12214944a7861e98aac2bda Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 24 Mar 2024 22:03:23 -0500 Subject: [PATCH] changed TLV8 from std::forward_list to std::list Though this increases space requirement for TLV8 (just a little), using std::list allows adding elements directly to end, which ensure the order is maintained when packing and unpacking. Will avoid potential confusion when TLV8 is used for Characteristics. --- src/HomeSpan.h | 2 +- src/TLV8.cpp | 6 +++--- src/TLV8.h | 8 ++++---- src/src.ino | 50 +++++++++++++++++++++++++++++--------------------- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 983289c..99865a7 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -537,7 +537,7 @@ class SpanCharacteristic{ } void uvSet(UVal &dest, UVal &src){ - if(format==FORMAT::STRING || format==FORMAT::DATA || format==FORMAT::TLV_ENC) + if(format>=FORMAT::STRING) uvSet(dest,(const char *)src.STRING); else dest=src; diff --git a/src/TLV8.cpp b/src/TLV8.cpp index 9fd6e16..2f19730 100644 --- a/src/TLV8.cpp +++ b/src/TLV8.cpp @@ -70,10 +70,10 @@ void tlv8_t::osprint(std::ostream& os){ TLV8_it TLV8::add(uint8_t tag, size_t len, const uint8_t* val){ - if(!empty() && front().tag==tag) - front().update(len,val); + if(!empty() && back().tag==tag) + back().update(len,val); else - emplace_front(tag,len,val); + emplace_back(tag,len,val); return(begin()); } diff --git a/src/TLV8.h b/src/TLV8.h index 4a83cc2..af752e8 100644 --- a/src/TLV8.h +++ b/src/TLV8.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include "PSRAM.h" @@ -51,12 +51,12 @@ struct tlv8_t { ///////////////////////////////////// -typedef std::forward_list>::iterator TLV8_it; +typedef std::list>::iterator TLV8_it; typedef struct { const uint8_t tag; const char *name; } TLV8_names; ///////////////////////////////////// -class TLV8 : public std::forward_list> { +class TLV8 : public std::list> { TLV8_it currentPackIt; TLV8_it endPackIt; @@ -109,6 +109,6 @@ class TLV8 : public std::forward_list> { void unpack(uint8_t *buf, size_t bufSize); - void wipe(){std::forward_list>().swap(*this);} + void wipe(){std::list>().swap(*this);} }; diff --git a/src/src.ino b/src/src.ino index ea87240..7fda69a 100644 --- a/src/src.ino +++ b/src/src.ino @@ -26,18 +26,43 @@ ********************************************************************************/ #include "HomeSpan.h" +#include "TLV8.h" #define MAX_LIGHTS 1 void setup() { Serial.begin(115200); + delay(1000); + Serial.printf("\n\nREADY\n\n"); + + TLV8 tlv, tlv2; + + const size_t nMax=257; + uint8_t c[nMax]; + for(int i=0;i