aqhome: improved "write" module.
- write window status as string translated from value - reduced code duplication
This commit is contained in:
@@ -44,7 +44,6 @@ static void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
|
|||||||
static void _processValue2Message(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
|
static void _processValue2Message(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
|
||||||
static void _processSendStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
|
static void _processSendStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
|
||||||
static void _processRecvStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
|
static void _processRecvStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
|
||||||
static const char *_valueTypeToString(int t);
|
|
||||||
static void _writeDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v);
|
static void _writeDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v);
|
||||||
static void _writeInt(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, int v);
|
static void _writeInt(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, int v);
|
||||||
static void _writeString(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, const char *v);
|
static void _writeString(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, const char *v);
|
||||||
@@ -109,13 +108,21 @@ void _processValue2Message(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
|
|||||||
{
|
{
|
||||||
const char *sType;
|
const char *sType;
|
||||||
|
|
||||||
sType=_valueTypeToString(AQH_Value2Msg_GetValueId(nodeMsg));
|
sType=AQH_Value2Msg_GetValueTypeName(nodeMsg);
|
||||||
if (sType && *sType)
|
if (sType && *sType) {
|
||||||
_writeDouble(ep,
|
if (AQH_Value2Msg_GetValueType(nodeMsg)==AQH_MSG_VALUE2_TYPE_DOOR)
|
||||||
AQH_Value2Msg_GetUid(nodeMsg),
|
_writeString(ep,
|
||||||
AQH_Value2Msg_GetValueId(nodeMsg),
|
AQH_Value2Msg_GetUid(nodeMsg),
|
||||||
sType,
|
AQH_Value2Msg_GetValueId(nodeMsg),
|
||||||
AQH_Value2Msg_GetValue(nodeMsg));
|
sType,
|
||||||
|
AQH_Value2Msg_GetValueAsWindowStateString(nodeMsg));
|
||||||
|
else
|
||||||
|
_writeDouble(ep,
|
||||||
|
AQH_Value2Msg_GetUid(nodeMsg),
|
||||||
|
AQH_Value2Msg_GetValueId(nodeMsg),
|
||||||
|
sType,
|
||||||
|
AQH_Value2Msg_GetValue(nodeMsg));
|
||||||
|
}
|
||||||
_writeDouble(ep,
|
_writeDouble(ep,
|
||||||
AQH_Value2Msg_GetUid(nodeMsg),
|
AQH_Value2Msg_GetUid(nodeMsg),
|
||||||
AQH_Value2Msg_GetValueId(nodeMsg),
|
AQH_Value2Msg_GetValueId(nodeMsg),
|
||||||
@@ -182,18 +189,6 @@ void _processRecvStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char *_valueTypeToString(int t)
|
|
||||||
{
|
|
||||||
switch(t) {
|
|
||||||
case AQH_MSG_VALUE2_TYPE_TEMP: return "temperature";
|
|
||||||
case AQH_MSG_VALUE2_TYPE_HUMIDITY: return "humidity";
|
|
||||||
case AQH_MSG_VALUE2_TYPE_DOOR: return "door_window";
|
|
||||||
default: return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _writeDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v)
|
void _writeDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v)
|
||||||
{
|
{
|
||||||
char numBuf[16];
|
char numBuf[16];
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ const char *AQH_Value2Msg_GetValueTypeName(const GWEN_MSG *msg)
|
|||||||
switch(t) {
|
switch(t) {
|
||||||
case AQH_MSG_VALUE2_TYPE_TEMP: return "temperature";
|
case AQH_MSG_VALUE2_TYPE_TEMP: return "temperature";
|
||||||
case AQH_MSG_VALUE2_TYPE_HUMIDITY: return "humidity";
|
case AQH_MSG_VALUE2_TYPE_HUMIDITY: return "humidity";
|
||||||
case AQH_MSG_VALUE2_TYPE_DOOR: return "door/window";
|
case AQH_MSG_VALUE2_TYPE_DOOR: return "door_window";
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ AQHOME_API int16_t AQH_Value2Msg_GetValueDenom(const GWEN_MSG *msg);
|
|||||||
AQHOME_API double AQH_Value2Msg_GetValue(const GWEN_MSG *msg);
|
AQHOME_API double AQH_Value2Msg_GetValue(const GWEN_MSG *msg);
|
||||||
|
|
||||||
AQHOME_API const char *AQH_Value2Msg_GetValueAsWindowStateString(const GWEN_MSG *msg);
|
AQHOME_API const char *AQH_Value2Msg_GetValueAsWindowStateString(const GWEN_MSG *msg);
|
||||||
|
AQHOME_API const char *AQH_Value2Msg_GetValueTypeName(const GWEN_MSG *msg);
|
||||||
|
|
||||||
AQHOME_API void AQH_Value2Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
AQHOME_API void AQH_Value2Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user