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.
This commit is contained in:
Gregg 2024-03-24 22:03:23 -05:00
parent 7c5b01e967
commit 9b0b18310e
4 changed files with 37 additions and 29 deletions

View File

@ -537,7 +537,7 @@ class SpanCharacteristic{
} }
void uvSet(UVal &dest, UVal &src){ 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); uvSet(dest,(const char *)src.STRING);
else else
dest=src; dest=src;

View File

@ -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){ TLV8_it TLV8::add(uint8_t tag, size_t len, const uint8_t* val){
if(!empty() && front().tag==tag) if(!empty() && back().tag==tag)
front().update(len,val); back().update(len,val);
else else
emplace_front(tag,len,val); emplace_back(tag,len,val);
return(begin()); return(begin());
} }

View File

@ -29,7 +29,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <sstream> #include <sstream>
#include <forward_list> #include <list>
#include <memory> #include <memory>
#include "PSRAM.h" #include "PSRAM.h"
@ -51,12 +51,12 @@ struct tlv8_t {
///////////////////////////////////// /////////////////////////////////////
typedef std::forward_list<tlv8_t, Mallocator<tlv8_t>>::iterator TLV8_it; typedef std::list<tlv8_t, Mallocator<tlv8_t>>::iterator TLV8_it;
typedef struct { const uint8_t tag; const char *name; } TLV8_names; typedef struct { const uint8_t tag; const char *name; } TLV8_names;
///////////////////////////////////// /////////////////////////////////////
class TLV8 : public std::forward_list<tlv8_t, Mallocator<tlv8_t>> { class TLV8 : public std::list<tlv8_t, Mallocator<tlv8_t>> {
TLV8_it currentPackIt; TLV8_it currentPackIt;
TLV8_it endPackIt; TLV8_it endPackIt;
@ -109,6 +109,6 @@ class TLV8 : public std::forward_list<tlv8_t, Mallocator<tlv8_t>> {
void unpack(uint8_t *buf, size_t bufSize); void unpack(uint8_t *buf, size_t bufSize);
void wipe(){std::forward_list<tlv8_t, Mallocator<tlv8_t>>().swap(*this);} void wipe(){std::list<tlv8_t, Mallocator<tlv8_t>>().swap(*this);}
}; };

View File

@ -26,18 +26,43 @@
********************************************************************************/ ********************************************************************************/
#include "HomeSpan.h" #include "HomeSpan.h"
#include "TLV8.h"
#define MAX_LIGHTS 1 #define MAX_LIGHTS 1
void setup() { void setup() {
Serial.begin(115200); 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<nMax;i++)
c[i]=0x22;
tlv.add(5);
tlv.add(6);
tlv.add(7,44);
tlv.add(255);
tlv.add(7,33);
tlv.add(7,34);
tlv.add(15,nMax,c);
tlv.print();
Serial.printf("\nSize=%d\n\n",tlv.pack_size());
uint8_t bOut[tlv.pack_size()];
tlv.pack(bOut);
tlv2.unpack(bOut,tlv.pack_size());
tlv2.print();
while(1);
homeSpan.setLogLevel(2); homeSpan.setLogLevel(2);
homeSpan.enableWebLog(50,"pool.ntp.org","UTC",NULL);
// homeSpan.setPairingCode("12345670");
// homeSpan.enableWebLog(50,"pool.ntp.org","UTC","myStatus");
// homeSpan.enableWebLog(50,NULL,NULL,NULL);
homeSpan.begin(Category::Lighting,"HomeSpan Max"); homeSpan.begin(Category::Lighting,"HomeSpan Max");
@ -57,8 +82,6 @@ void setup() {
WEBLOG("Configuring %s",c); WEBLOG("Configuring %s",c);
} }
new SpanUserCommand('w', " - get web log test",webLogTest); // simulate getting an HTTPS request for weblog
} }
////////////////////////////////////// //////////////////////////////////////
@ -70,18 +93,3 @@ void loop(){
} }
////////////////////////////////////// //////////////////////////////////////
void webLogTest(const char *dummy){
Serial.printf("\n*** In Web Log Test. Starting Custom Web Log Handler\n"); // here is where you would perform any HTTPS initializations
homeSpan.getWebLog(webLogHandler,NULL); // this starts the normal weblog with output redirected to the specified handler (below)
}
void webLogHandler(const char *buf, void *args){
if(buf!=NULL){
Serial.printf("--------\n");
Serial.printf("%s",buf); // here is where you would transmit data to the HTTPS connection
Serial.printf("********\n");
}
else
Serial.print("*** DONE!\n\n"); // here is where you would close the HTTPS connection
}