aqhome/mqtt: added messages regarding subscription.

This commit is contained in:
Martin Preuss
2023-05-14 22:24:55 +02:00
parent 3e85dc9bd5
commit 1751170940
10 changed files with 444 additions and 89 deletions

View File

@@ -168,6 +168,40 @@ void _flagsToDb(uint8_t flags, GWEN_DB_NODE *dbDest, const char *varNameFlags, c
/* helper functions */
void AQH_MqttMsg_AppendStringWithLen(GWEN_BUFFER *buf, const char *s)
{
unsigned int len;
len=strlen(s);
GWEN_Buffer_AppendByte(buf, (len>>8) & 0xff);
GWEN_Buffer_AppendByte(buf, len & 0xff);
if (s && *s)
GWEN_Buffer_AppendString(buf, s);
}
int AQH_MqttMsg_DumpString(const uint8_t *ptr, uint32_t len, GWEN_BUFFER *buf)
{
if (len>1) {
int slen;
slen=(ptr[0]<<8)+ptr[1];
if (slen) {
if (slen>(len-2)) {
DBG_ERROR(AQH_LOGDOMAIN, "Invalid string length (%lu, remaining %lu)",
(unsigned long int) slen, (unsigned long int) len);
return GWEN_ERROR_BAD_DATA;
}
GWEN_Buffer_AppendBytes(buf, (const char*) ptr+2, slen);
}
return slen+2;
}
return GWEN_ERROR_BAD_DATA;
}