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:
parent
7c5b01e967
commit
9b0b18310e
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <sstream>
|
||||
#include <forward_list>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#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;
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
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 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 wipe(){std::forward_list<tlv8_t, Mallocator<tlv8_t>>().swap(*this);}
|
||||
void wipe(){std::list<tlv8_t, Mallocator<tlv8_t>>().swap(*this);}
|
||||
|
||||
};
|
||||
|
|
|
|||
50
src/src.ino
50
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<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.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");
|
||||
|
||||
|
|
@ -57,8 +82,6 @@ void setup() {
|
|||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue