adapted to latest changes in gwen, more work on data and nodes servers.

This commit is contained in:
Martin Preuss
2024-09-26 10:45:22 +02:00
parent be053b035f
commit b0b6efb1c3
88 changed files with 1745 additions and 445 deletions

View File

@@ -48,13 +48,11 @@
* ------------------------------------------------------------------------------------------------
*/
static void _processValue2Message(AQHOMED *aqh, const GWEN_MSG *nodeMsg);
static void _processValue3Message(AQHOMED *aqh, const GWEN_MSG *nodeMsg);
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, int valueId, const char *valuePath);
static void _publishInt(AQHOMED *aqh, uint32_t uid, const char *vPath, int vModality, const char *vUnits, int v);
static void _publishDouble(AQHOMED *aqh, uint32_t uid, const char *vPath, int vType, const char *vUnits, double v);
static void _setDeviceName(AQH_VALUE *value, uint32_t uid);
@@ -69,9 +67,6 @@ void AqHomed_ForwardTtyMsgToBroker(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
if (GWEN_MsgEndpoint_GetState(aqh->brokerEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
DBG_DEBUG(AQH_LOGDOMAIN, "Processing output message");
switch(AQH_NodeMsg_GetMsgType(nodeMsg)) {
case AQH_MSG_TYPE_VALUE2:
_processValue2Message(aqh, nodeMsg);
break;
case AQH_MSG_TYPE_VALUE_REPORT:
_processValue3Message(aqh, nodeMsg);
break;
@@ -89,26 +84,39 @@ void AqHomed_ForwardTtyMsgToBroker(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
void _processValue2Message(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
{
_publishDouble(aqh,
AQH_Value2Msg_GetUid(nodeMsg),
AQH_Value2Msg_GetValueId(nodeMsg),
AQH_Value2Msg_GetValueTypeUnits(nodeMsg),
AQH_Value2Msg_GetValueTypeName(nodeMsg),
AQH_Value2Msg_GetValue(nodeMsg));
}
void _processValue3Message(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
{
_publishDouble(aqh,
AQH_Value3Msg_GetUid(nodeMsg),
AQH_Value3Msg_GetValueId(nodeMsg),
AQH_Value3Msg_GetValueTypeUnits(nodeMsg),
AQH_Value3Msg_GetValueTypeName(nodeMsg),
AQH_Value3Msg_GetValue(nodeMsg));
uint32_t uid;
uint8_t valueId;
AQH_NODE_INFO *ni;
double v;
uid=AQH_Value3Msg_GetUid(nodeMsg);
valueId=AQH_Value3Msg_GetValueId(nodeMsg);
v=AQH_Value3Msg_GetValue(nodeMsg);
ni=AQH_NodeDb_GetNodeInfoByUid(aqh->nodeDb, uid);
if (ni) {
const char *devName;
devName=AQH_NodeInfo_GetDeviceId(ni);
if (devName) {
const AQHNODE_DEVICE *devInfo;
devInfo=AqHomed_GetDeviceDefByName(aqh, devName);
if (devInfo) {
const AQHNODE_VALUE *value;
value=AQHNODE_Value_List_GetById(AQHNODE_Device_GetValueList(devInfo), valueId);
if (value) {
const char *vname;
vname=AQHNODE_Value_GetName(value);
if (vname && *vname)
_publishDouble(aqh, uid, vname, AQHNODE_Value_GetModality(value), AQHNODE_Value_GetValueUnits(value), v);
}
}
}
}
}
@@ -119,12 +127,14 @@ void _processSendStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
packetsOutInt=AQH_SendStatsMsg_GetPacketsOut(nodeMsg);
if (packetsOutInt) {
uint32_t uid;
double packetsOut;
double collisions;
double busy;
double collisionsPercentage=0.0;
double busyPercentage=0.0;
uid=AQH_SendStatsMsg_GetUid(nodeMsg);
packetsOut=/*(double)*/ packetsOutInt;
collisions=/*(double)*/ AQH_SendStatsMsg_GetCollisions(nodeMsg);
busy=/*(double)*/ AQH_SendStatsMsg_GetBusyErrors(nodeMsg);
@@ -132,10 +142,10 @@ void _processSendStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
collisionsPercentage=collisions*100.0/packetsOut;
busyPercentage=busy*100.0/packetsOut;
_publishInt(aqh, AQH_SendStatsMsg_GetUid(nodeMsg), 0, NULL, "net/packetsOut", packetsOutInt);
_publishInt(aqh, AQH_SendStatsMsg_GetUid(nodeMsg), 0, NULL, "net/collisions", (int) AQH_SendStatsMsg_GetCollisions(nodeMsg));
_publishDouble(aqh, AQH_SendStatsMsg_GetUid(nodeMsg), 0, "%", "net/collisionsPercent", collisionsPercentage);
_publishDouble(aqh, AQH_SendStatsMsg_GetUid(nodeMsg), 0, "%", "net/busyPercent", busyPercentage);
_publishInt( aqh, uid, "net/packetsOut", 0, NULL, packetsOutInt);
_publishInt( aqh, uid, "net/collisions", 0, NULL, (int) AQH_SendStatsMsg_GetCollisions(nodeMsg));
_publishDouble(aqh, uid, "net/collisionsPercent", 0, "%", collisionsPercentage);
_publishDouble(aqh, uid, "net/busyPercent", 0, "%", busyPercentage);
}
}
@@ -147,12 +157,14 @@ void _processRecvStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
packetsInInt=AQH_RecvStatsMsg_GetPacketsIn(nodeMsg);
if (packetsInInt) {
uint32_t uid;
double packetsIn;
double crcErrors;
double ioErrors;
double crcErrorsPercentage=0.0;
double ioErrorsPercentage=0.0;
uid=AQH_SendStatsMsg_GetUid(nodeMsg);
packetsIn=/*(double)*/ packetsInInt;
crcErrors=/*(double)*/AQH_RecvStatsMsg_GetCrcErrors(nodeMsg);
ioErrors=/*(double)*/AQH_RecvStatsMsg_GetIoErrors(nodeMsg);
@@ -160,24 +172,24 @@ void _processRecvStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg)
crcErrorsPercentage=crcErrors*100.0/packetsIn;
ioErrorsPercentage=ioErrors*100.0/packetsIn;
_publishInt(aqh, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, NULL, "net/packetsIn", packetsInInt);
_publishInt(aqh, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, NULL, "net/crcerrors", (int) AQH_RecvStatsMsg_GetCrcErrors(nodeMsg));
_publishInt(aqh, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, NULL, "net/ioerrors", (int) AQH_RecvStatsMsg_GetIoErrors(nodeMsg));
_publishDouble(aqh, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "%", "net/crcerrorsPercent", crcErrorsPercentage);
_publishDouble(aqh, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "%", "net/ioerrorsPercent", ioErrorsPercentage);
_publishInt( aqh, uid, "net/packetsIn", 0, NULL, packetsInInt);
_publishInt( aqh, uid, "net/crcerrors", 0, NULL, (int) AQH_RecvStatsMsg_GetCrcErrors(nodeMsg));
_publishInt( aqh, uid, "net/ioerrors", 0, NULL, (int) AQH_RecvStatsMsg_GetIoErrors(nodeMsg));
_publishDouble(aqh, uid, "net/crcerrorsPercent", 0, "%", crcErrorsPercentage);
_publishDouble(aqh, uid, "net/ioerrorsPercent", 0, "%", ioErrorsPercentage);
}
}
void _publishInt(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUnits, const char *valuePath, int v)
void _publishInt(AQHOMED *aqh, uint32_t uid, const char *vPath, int vModality, const char *vUnits, int v)
{
_publishDouble(aqh, uid, valueId, valueUnits, valuePath, /*(double)*/ v);
_publishDouble(aqh, uid, vPath, vModality, vUnits, /*(double)*/ v);
}
void _publishDouble(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUnits, const char *valuePath, double v)
void _publishDouble(AQHOMED *aqh, uint32_t uid, const char *vPath, int vModality, const char *vUnits, double v)
{
GWEN_MSG *pubMsg;
union {double f; uint64_t i;} u;
@@ -189,12 +201,14 @@ void _publishDouble(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUn
arrayToSend[1]=u.i;
value=AQH_Value_new();
_setValueNameForDriver(value, valueId, valuePath);
AQH_Value_SetValueUnits(value, valueUnits);
AQH_Value_SetValueType(value, 0);
_setDeviceName(value, uid);
AQH_Value_SetName(value, vPath);
AQH_Value_SetValueUnits(value, vUnits);
AQH_Value_SetValueType(value, vModality);
pubMsg=AQH_MultiDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_UPDATEDATA, value, arrayToSend, 1);
pubMsg=AQH_MultiDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_UPDATEDATA,
GWEN_MsgEndpoint_GetNextMessageId(aqh->brokerEndpoint), 0,
value, arrayToSend, 1);
if (pubMsg) {
DBG_INFO(AQH_LOGDOMAIN, "BROKER PUBLISH %s: %f", AQH_Value_GetName(value), v);
GWEN_MsgEndpoint_AddSendMessage(aqh->brokerEndpoint, pubMsg);
@@ -204,21 +218,6 @@ void _publishDouble(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUn
void _setValueNameForDriver(AQH_VALUE *value, int valueId, const char *valuePath)
{
GWEN_BUFFER *buf;
buf=GWEN_Buffer_new(0, 64, 0, 1);
if (valueId>0)
GWEN_Buffer_AppendArgs(buf, "%d/%s", valueId, valuePath);
else
GWEN_Buffer_AppendArgs(buf, "%s", valuePath);
AQH_Value_SetName(value, GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
}
void _setDeviceName(AQH_VALUE *value, uint32_t uid)
{
GWEN_BUFFER *buf;