Simplified IPC code to use less different IPC messages. Share more code. More qork on MQTT code.
This commit is contained in:
@@ -52,6 +52,8 @@ static void _processSendStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg);
|
||||
static void _processRecvStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg);
|
||||
static void _publishInt(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUnits, const char *valuePath, int v);
|
||||
static void _publishDouble(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUnits, const char *valuePath, double v);
|
||||
static void _setValueNameForDriver(AQH_VALUE *value, uint32_t uid, int valueId, const char *valuePath);
|
||||
static void _setDeviceName(AQH_VALUE *value, uint32_t uid);
|
||||
|
||||
|
||||
|
||||
@@ -162,29 +164,58 @@ void _publishInt(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUnits
|
||||
|
||||
void _publishDouble(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUnits, const char *valuePath, double v)
|
||||
{
|
||||
GWEN_BUFFER *bufTopic;
|
||||
GWEN_MSG *pubMsg;
|
||||
union {double f; uint64_t i;} u;
|
||||
uint64_t arrayToSend[2];
|
||||
AQH_VALUE *value;
|
||||
|
||||
u.f=v;
|
||||
arrayToSend[0]=(uint64_t) time(NULL);
|
||||
arrayToSend[1]=u.i;
|
||||
|
||||
bufTopic=GWEN_Buffer_new(0, 64, 0, 1);
|
||||
if (valueId>0)
|
||||
GWEN_Buffer_AppendArgs(bufTopic, "%08x/%d/%s", uid, valueId, valuePath);
|
||||
else
|
||||
GWEN_Buffer_AppendArgs(bufTopic, "%08x/%s", uid, valuePath);
|
||||
value=AQH_Value_new();
|
||||
_setValueNameForDriver(value, uid, valueId, valuePath);
|
||||
AQH_Value_SetValueUnits(value, valueUnits);
|
||||
AQH_Value_SetValueType(value, 0);
|
||||
_setDeviceName(value, uid);
|
||||
|
||||
pubMsg=AQH_MultiDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_UPDATEDATA, GWEN_Buffer_GetStart(bufTopic), valueUnits, 0, arrayToSend, 1);
|
||||
pubMsg=AQH_MultiDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_UPDATEDATA, value, arrayToSend, 1);
|
||||
if (pubMsg) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "BROKER PUBLISH %s: %f", GWEN_Buffer_GetStart(bufTopic), v);
|
||||
DBG_INFO(AQH_LOGDOMAIN, "BROKER PUBLISH %s: %f", AQH_Value_GetNameForDriver(value), v);
|
||||
GWEN_MsgEndpoint_AddSendMessage(aqh->brokerEndpoint, pubMsg);
|
||||
}
|
||||
GWEN_Buffer_free(bufTopic);
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _setValueNameForDriver(AQH_VALUE *value, uint32_t uid, int valueId, const char *valuePath)
|
||||
{
|
||||
GWEN_BUFFER *buf;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 64, 0, 1);
|
||||
if (valueId>0)
|
||||
GWEN_Buffer_AppendArgs(buf, "%08x/%d/%s", uid, valueId, valuePath);
|
||||
else
|
||||
GWEN_Buffer_AppendArgs(buf, "%08x/%s", uid, valuePath);
|
||||
AQH_Value_SetNameForDriver(value, GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _setDeviceName(AQH_VALUE *value, uint32_t uid)
|
||||
{
|
||||
GWEN_BUFFER *buf;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 64, 0, 1);
|
||||
GWEN_Buffer_AppendArgs(buf, "%08x", uid);
|
||||
AQH_Value_SetDeviceNameForDriver(value, GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user