More TLV updates
This commit is contained in:
parent
a11eab4b37
commit
1b74564baf
|
|
@ -896,7 +896,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
LOG0("%s%s",(foundPerms++)?"+":"",pNames[i]);
|
LOG0("%s%s",(foundPerms++)?"+":"",pNames[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((*chr)->format!=FORMAT::STRING && (*chr)->format!=FORMAT::BOOL && (*chr)->format!=FORMAT::DATA){
|
if((*chr)->format<FORMAT::STRING && (*chr)->format!=FORMAT::BOOL){
|
||||||
if((*chr)->validValues)
|
if((*chr)->validValues)
|
||||||
LOG0(", Valid Values=%s",(*chr)->validValues);
|
LOG0(", Valid Values=%s",(*chr)->validValues);
|
||||||
else if((*chr)->uvGet<double>((*chr)->stepValue)>0)
|
else if((*chr)->uvGet<double>((*chr)->stepValue)>0)
|
||||||
|
|
@ -937,7 +937,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
if((*chr)->setValidValuesError)
|
if((*chr)->setValidValuesError)
|
||||||
LOG0(" *** WARNING #%d! Attempt to set Custom Valid Values for this Characteristic ignored ***\n",++nWarnings);
|
LOG0(" *** WARNING #%d! Attempt to set Custom Valid Values for this Characteristic ignored ***\n",++nWarnings);
|
||||||
|
|
||||||
if((*chr)->format!=STRING && (!(((*chr)->uvGet<double>((*chr)->value) >= (*chr)->uvGet<double>((*chr)->minValue)) && ((*chr)->uvGet<double>((*chr)->value) <= (*chr)->uvGet<double>((*chr)->maxValue)))))
|
if((*chr)->format<STRING && (!(((*chr)->uvGet<double>((*chr)->value) >= (*chr)->uvGet<double>((*chr)->minValue)) && ((*chr)->uvGet<double>((*chr)->value) <= (*chr)->uvGet<double>((*chr)->maxValue)))))
|
||||||
LOG0(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet<double>((*chr)->value),(*chr)->uvGet<double>((*chr)->minValue),(*chr)->uvGet<double>((*chr)->maxValue));
|
LOG0(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet<double>((*chr)->value),(*chr)->uvGet<double>((*chr)->minValue),(*chr)->uvGet<double>((*chr)->maxValue));
|
||||||
|
|
||||||
} // Characteristics
|
} // Characteristics
|
||||||
|
|
@ -1457,7 +1457,7 @@ int Span::updateCharacteristics(char *buf, SpanBuf *pObj){
|
||||||
if(status==StatusCode::OK){ // if status is okay
|
if(status==StatusCode::OK){ // if status is okay
|
||||||
pObj[j].characteristic->uvSet(pObj[j].characteristic->value,pObj[j].characteristic->newValue); // update characteristic value with new value
|
pObj[j].characteristic->uvSet(pObj[j].characteristic->value,pObj[j].characteristic->newValue); // update characteristic value with new value
|
||||||
if(pObj[j].characteristic->nvsKey){ // if storage key found
|
if(pObj[j].characteristic->nvsKey){ // if storage key found
|
||||||
if(pObj[j].characteristic->format!=FORMAT::STRING && pObj[j].characteristic->format!=FORMAT::DATA)
|
if(pObj[j].characteristic->format<FORMAT::STRING)
|
||||||
nvs_set_u64(charNVS,pObj[j].characteristic->nvsKey,pObj[j].characteristic->value.UINT64); // store data as uint64_t regardless of actual type (it will be read correctly when access through uvGet())
|
nvs_set_u64(charNVS,pObj[j].characteristic->nvsKey,pObj[j].characteristic->value.UINT64); // store data as uint64_t regardless of actual type (it will be read correctly when access through uvGet())
|
||||||
else
|
else
|
||||||
nvs_set_str(charNVS,pObj[j].characteristic->nvsKey,pObj[j].characteristic->value.STRING); // store data
|
nvs_set_str(charNVS,pObj[j].characteristic->nvsKey,pObj[j].characteristic->value.STRING); // store data
|
||||||
|
|
@ -1833,7 +1833,7 @@ SpanCharacteristic::~SpanCharacteristic(){
|
||||||
free(validValues);
|
free(validValues);
|
||||||
free(nvsKey);
|
free(nvsKey);
|
||||||
|
|
||||||
if(format==FORMAT::STRING || format==FORMAT::DATA){
|
if(format>=FORMAT::STRING){
|
||||||
free(value.STRING);
|
free(value.STRING);
|
||||||
free(newValue.STRING);
|
free(newValue.STRING);
|
||||||
}
|
}
|
||||||
|
|
@ -2005,6 +2005,8 @@ StatusCode SpanCharacteristic::loadUpdate(char *val, char *ev, boolean wr){
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STRING:
|
case STRING:
|
||||||
|
case DATA:
|
||||||
|
case TLV_ENC:
|
||||||
uvSet(newValue,(const char *)val);
|
uvSet(newValue,(const char *)val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -675,12 +675,12 @@ class SpanCharacteristic{
|
||||||
void setString(const char *val, boolean notify=true){
|
void setString(const char *val, boolean notify=true){
|
||||||
|
|
||||||
if(!((perms&EV) || (updateFlag==2))){
|
if(!((perms&EV) || (updateFlag==2))){
|
||||||
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. No EVENT NOTIFICATION (EV) permission on this characteristic\n\n",hapName);
|
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setString() ignored. No EVENT NOTIFICATION (EV) permission on this characteristic\n\n",hapName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(updateFlag==1)
|
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);
|
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setString() within update() while it is being updated by Home App. This may cause device to become non-responsive!\n\n",hapName);
|
||||||
|
|
||||||
uvSet(value,val);
|
uvSet(value,val);
|
||||||
uvSet(newValue,value);
|
uvSet(newValue,value);
|
||||||
|
|
@ -763,7 +763,7 @@ class SpanCharacteristic{
|
||||||
template <typename T> void setVal(T val, boolean notify=true){
|
template <typename T> void setVal(T val, boolean notify=true){
|
||||||
|
|
||||||
if(!((perms&EV) || (updateFlag==2))){
|
if(!((perms&EV) || (updateFlag==2))){
|
||||||
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. No EVENT NOTIFICATION (EV) permission on this characteristic\n\n",hapName);
|
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal() ignored. No EVENT NOTIFICATION (EV) permission on this characteristic\n\n",hapName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
37
src/src.ino
37
src/src.ino
|
|
@ -30,41 +30,11 @@
|
||||||
|
|
||||||
#define MAX_LIGHTS 1
|
#define MAX_LIGHTS 1
|
||||||
|
|
||||||
|
CUSTOM_CHAR_DATA(UserData, AAAAAAAA-BBBB-AAAA-AAAA-AAAAAAAAAAAA, PR+PW+EV);
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
tlv.print(--tlv.end(),tlv.end());
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
@ -78,6 +48,8 @@ void setup() {
|
||||||
new SpanAccessory();
|
new SpanAccessory();
|
||||||
new Service::AccessoryInformation();
|
new Service::AccessoryInformation();
|
||||||
new Characteristic::Identify();
|
new Characteristic::Identify();
|
||||||
|
uint8_t x[]={1,2,3,4,5};
|
||||||
|
(new Characteristic::UserData("AAAA"))->setDescription("Custom Data")->setData(x,5);
|
||||||
char c[30];
|
char c[30];
|
||||||
sprintf(c,"Light-%d",i);
|
sprintf(c,"Light-%d",i);
|
||||||
new Characteristic::Name(c);
|
new Characteristic::Name(c);
|
||||||
|
|
@ -93,6 +65,7 @@ void setup() {
|
||||||
void loop(){
|
void loop(){
|
||||||
|
|
||||||
homeSpan.poll();
|
homeSpan.poll();
|
||||||
|
delay(100000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue