aqhome-nodes: transformed app to use new event2 interface.
This commit is contained in:
@@ -35,16 +35,6 @@
|
||||
</setVar>
|
||||
|
||||
<headers dist="true" >
|
||||
aqhomed.h
|
||||
aqhomed_p.h
|
||||
init.h
|
||||
fini.h
|
||||
loop.h
|
||||
loop_broker.h
|
||||
loop_tty.h
|
||||
loop_tty_ipc.h
|
||||
loop_tty_broker.h
|
||||
loop_ipc.h
|
||||
db.h
|
||||
tty_log.h
|
||||
devicesread.h
|
||||
@@ -54,21 +44,12 @@
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
main.c
|
||||
aqhomed.c
|
||||
init.c
|
||||
fini.c
|
||||
loop.c
|
||||
loop_broker.c
|
||||
loop_tty.c
|
||||
loop_tty_ipc.c
|
||||
loop_tty_broker.c
|
||||
loop_ipc.c
|
||||
server.c
|
||||
db.c
|
||||
tty_log.c
|
||||
devicesread.c
|
||||
devicesdump.c
|
||||
r_setdata.c
|
||||
main.c
|
||||
</sources>
|
||||
|
||||
<useTargets>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
@@ -12,28 +12,25 @@
|
||||
|
||||
|
||||
#include "./db.h"
|
||||
#include "./aqhomed_p.h"
|
||||
#include "./server_p.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
#include "aqhome/msg/msg_sendstats.h"
|
||||
#include "aqhome/msg/msg_recvstats.h"
|
||||
#include "aqhome/msg/msg_value2.h"
|
||||
#include "aqhome/msg/msg_value3.h"
|
||||
#include "aqhome/msg/msg_needaddr.h"
|
||||
#include "aqhome/msg/msg_claimaddr.h"
|
||||
#include "aqhome/msg/msg_haveaddr.h"
|
||||
#include "aqhome/msg/msg_device.h"
|
||||
#include "aqhome/msg/msg_flashready.h"
|
||||
#include "aqhome/msg/node/m_node.h"
|
||||
#include "aqhome/msg/node/m_sendstats.h"
|
||||
#include "aqhome/msg/node/m_recvstats.h"
|
||||
#include "aqhome/msg/node/m_value.h"
|
||||
#include "aqhome/msg/node/m_addr.h"
|
||||
#include "aqhome/msg/node/m_device.h"
|
||||
#include "aqhome/msg/node/m_flashready.h"
|
||||
|
||||
#include "aqhome/data/value.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/ipc/data/msg_data_values.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd_values.h"
|
||||
#include "aqhome/ipc2/endpoint.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/args.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endpoint_tcpd.h>
|
||||
#include <gwenhywfar/timestamp.h>
|
||||
|
||||
|
||||
@@ -43,23 +40,20 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _handleMsgValue2(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgValue3(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgNeedAddress(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgClaimAddress(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgHaveAddress(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgComSendStat(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgComRecvStat(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgDevice(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgFlashReady(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
static void _handleMsgValue(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _handleAddressMsg(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _handleMsgComSendStat(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _handleMsgComRecvStat(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _handleMsgDevice(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _handleMsgFlashReady(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
|
||||
static AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(AQHOMED *aqh, const GWEN_MSG *msg, uint32_t uid);
|
||||
static AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg, uint32_t uid);
|
||||
static void _updateTimestampLastChange(AQH_NODE_INFO *ni);
|
||||
static void _assignDeviceId(AQHOMED *aqh, AQH_NODE_INFO *ni, uint32_t uid);
|
||||
static void _assignDeviceId(AQH_OBJECT *o, AQH_NODE_INFO *ni, uint32_t uid);
|
||||
|
||||
static void _announceNodeValues(AQHOMED *aqh, const AQH_NODE_INFO *ni);
|
||||
static void _announceNodeValues(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_NODE_INFO *ni);
|
||||
static void _setDeviceName(AQH_VALUE *value, uint32_t uid);
|
||||
static void _announceValue(AQHOMED *aqh, uint32_t uid, const AQHNODE_VALUE *v);
|
||||
static void _announceValue(AQH_NODE_SERVER *xo, uint32_t uid, const AQHNODE_VALUE *v);
|
||||
|
||||
|
||||
|
||||
@@ -69,61 +63,57 @@ static void _announceValue(AQHOMED *aqh, uint32_t uid, const AQHNODE_VALUE *v);
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void AqHomed_NodeMsgToDb(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
void AQH_NodeServer_NodeMsgToDb(AQH_OBJECT *o, const AQH_MESSAGE *msg)
|
||||
{
|
||||
int msgIsValid;
|
||||
uint8_t msgType;
|
||||
AQH_NODE_SERVER *xo;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN,
|
||||
" - msg %d (%s) from %d to %d",
|
||||
AQH_NodeMsg_GetMsgType(msg),
|
||||
AQH_NodeMsg_MsgTypeToChar(AQH_NodeMsg_GetMsgType(msg)),
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg));
|
||||
xo=AQH_NodeServer_GetServerData(o);
|
||||
if (xo) {
|
||||
uint8_t msgType;
|
||||
|
||||
msgIsValid=(AQH_NodeMsg_IsChecksumValid(msg) && AQH_NodeMsg_IsMsgComplete(msg));
|
||||
msgType=AQH_NodeMsg_GetMsgType(msg);
|
||||
msgType=AQH_NodeMessage_GetMsgType(msg);
|
||||
|
||||
if (msgIsValid) {
|
||||
switch(msgType) {
|
||||
case AQH_MSG_TYPE_COMSENDSTATS: _handleMsgComSendStat(aqh, msg); break;
|
||||
case AQH_MSG_TYPE_COMRECVSTATS: _handleMsgComRecvStat(aqh, msg); break;
|
||||
case AQH_MSG_TYPE_VALUE2: _handleMsgValue2(aqh, msg); break;
|
||||
case AQH_MSG_TYPE_VALUE_REPORT: _handleMsgValue3(aqh, msg); break;
|
||||
case AQH_MSG_TYPE_NEED_ADDRESS: _handleMsgNeedAddress(aqh, msg); break;
|
||||
case AQH_MSG_TYPE_CLAIM_ADDRESS: _handleMsgClaimAddress(aqh, msg); break;
|
||||
case AQH_MSG_TYPE_HAVE_ADDRESS: _handleMsgHaveAddress(aqh, msg); break;
|
||||
case AQH_MSG_TYPE_DEVICE: _handleMsgDevice(aqh, msg); break;
|
||||
case AQH_MSG_TYPE_FLASH_READY: _handleMsgFlashReady(aqh, msg); break;
|
||||
default: break;
|
||||
case AQH_MSG_TYPE_COMSENDSTATS: _handleMsgComSendStat(xo, msg); break;
|
||||
case AQH_MSG_TYPE_COMRECVSTATS: _handleMsgComRecvStat(xo, msg); break;
|
||||
case AQH_MSG_TYPE_VALUE_REPORT: _handleMsgValue(xo, msg); break;
|
||||
case AQH_MSG_TYPE_NEED_ADDRESS: _handleAddressMsg(xo, msg); break;
|
||||
case AQH_MSG_TYPE_CLAIM_ADDRESS: _handleAddressMsg(xo, msg); break;
|
||||
case AQH_MSG_TYPE_HAVE_ADDRESS: _handleAddressMsg(xo, msg); break;
|
||||
case AQH_MSG_TYPE_DEVICE: _handleMsgDevice(o, xo, msg); break;
|
||||
case AQH_MSG_TYPE_FLASH_READY: _handleMsgFlashReady(o, xo, msg); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AqHomed_WriteNodeDb(AQHOMED *aqh)
|
||||
void AQH_NodeServer_WriteNodeDb(AQH_OBJECT *o)
|
||||
{
|
||||
if (aqh->dbFile) {
|
||||
AQH_NODE_SERVER *xo;
|
||||
|
||||
xo=AQH_NodeServer_GetServerData(o);
|
||||
if (xo && xo->dbFile) {
|
||||
GWEN_DB_NODE *dbNodeDb;
|
||||
|
||||
AQH_NodeDb_ClearModified(aqh->nodeDb);
|
||||
AQH_NodeDb_ClearModified(xo->nodeDb);
|
||||
dbNodeDb=GWEN_DB_Group_new("nodeDb");
|
||||
AQH_NodeDb_toDb(aqh->nodeDb, dbNodeDb);
|
||||
GWEN_DB_WriteFile(dbNodeDb, aqh->dbFile, GWEN_DB_FLAGS_DEFAULT);
|
||||
AQH_NodeDb_toDb(xo->nodeDb, dbNodeDb);
|
||||
GWEN_DB_WriteFile(dbNodeDb, xo->dbFile, GWEN_DB_FLAGS_DEFAULT);
|
||||
GWEN_DB_Group_free(dbNodeDb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleMsgValue2(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
void _handleMsgValue(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_Value2Msg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
uid=AQH_ValueMessage_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(xo, msg, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
}
|
||||
@@ -131,13 +121,13 @@ void _handleMsgValue2(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
|
||||
|
||||
|
||||
void _handleMsgValue3(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
void _handleAddressMsg(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_Value3Msg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
uid=AQH_AddrMessage_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(xo, msg, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
}
|
||||
@@ -145,111 +135,69 @@ void _handleMsgValue3(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
|
||||
|
||||
|
||||
void _handleMsgNeedAddress(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
void _handleMsgComSendStat(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_NeedAddrMsg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
uid=AQH_SendStatsMessage_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(xo, msg, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleMsgClaimAddress(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_ClaimAddrMsg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleMsgHaveAddress(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_HaveAddrMsg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleMsgComSendStat(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_SendStatsMsg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
}
|
||||
AQH_NodeInfo_SetStatsPacketsOut(ni, AQH_SendStatsMsg_GetPacketsOut(msg));
|
||||
AQH_NodeInfo_SetStatsCollisions(ni, AQH_SendStatsMsg_GetCollisions(msg));
|
||||
AQH_NodeInfo_SetStatsBusy(ni, AQH_SendStatsMsg_GetBusyErrors(msg));
|
||||
AQH_NodeDb_SetModified(aqh->nodeDb);
|
||||
AQH_NodeInfo_SetStatsPacketsOut(ni, AQH_SendStatsMessage_GetPacketsOut(msg));
|
||||
AQH_NodeInfo_SetStatsCollisions(ni, AQH_SendStatsMessage_GetCollisions(msg));
|
||||
AQH_NodeInfo_SetStatsBusy(ni, AQH_SendStatsMessage_GetBusyErrors(msg));
|
||||
AQH_NodeDb_SetModified(xo->nodeDb);
|
||||
_updateTimestampLastChange(ni);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleMsgComRecvStat(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
void _handleMsgComRecvStat(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_RecvStatsMsg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
uid=AQH_RecvStatsMessage_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(xo, msg, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
}
|
||||
AQH_NodeInfo_SetStatsPacketsIn(ni, AQH_RecvStatsMsg_GetPacketsIn(msg));
|
||||
AQH_NodeInfo_SetStatsCrcErrors(ni, AQH_RecvStatsMsg_GetCrcErrors(msg));
|
||||
AQH_NodeInfo_SetStatsIoErrors(ni, AQH_RecvStatsMsg_GetIoErrors(msg));
|
||||
AQH_NodeDb_SetModified(aqh->nodeDb);
|
||||
AQH_NodeInfo_SetStatsPacketsIn(ni, AQH_RecvStatsMessage_GetPacketsIn(msg));
|
||||
AQH_NodeInfo_SetStatsCrcErrors(ni, AQH_RecvStatsMessage_GetCrcErrors(msg));
|
||||
AQH_NodeInfo_SetStatsIoErrors(ni, AQH_RecvStatsMessage_GetIoErrors(msg));
|
||||
AQH_NodeDb_SetModified(xo->nodeDb);
|
||||
_updateTimestampLastChange(ni);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleMsgDevice(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
void _handleMsgDevice(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_DeviceMsg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
uid=AQH_DeviceMessage_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(xo, msg, uid);
|
||||
if (ni) {
|
||||
const char *s;
|
||||
|
||||
AQH_NodeInfo_SetManufacturer(ni, AQH_DeviceMsg_GetManufacturer(msg));
|
||||
AQH_NodeInfo_SetDeviceType(ni, AQH_DeviceMsg_GetDeviceType(msg));
|
||||
AQH_NodeInfo_SetDeviceVersion(ni, (AQH_DeviceMsg_GetDeviceVersion(msg)<<8)+AQH_DeviceMsg_GetDeviceRevision(msg));
|
||||
AQH_NodeInfo_SetManufacturer(ni, AQH_DeviceMessage_GetManufacturer(msg));
|
||||
AQH_NodeInfo_SetDeviceType(ni, AQH_DeviceMessage_GetDeviceType(msg));
|
||||
AQH_NodeInfo_SetDeviceVersion(ni, (AQH_DeviceMessage_GetDeviceVersion(msg)<<8)+AQH_DeviceMessage_GetDeviceRevision(msg));
|
||||
AQH_NodeInfo_SetFirmwareVersion(ni,
|
||||
(AQH_DeviceMsg_GetFirmwareVariant(msg)<<24) |
|
||||
(AQH_DeviceMsg_GetFirmwareVersionMajor(msg)<<16) |
|
||||
(AQH_DeviceMsg_GetFirmwareVersionMinor(msg)<<8) |
|
||||
AQH_DeviceMsg_GetFirmwareVersionPatchlevel(msg));
|
||||
(AQH_DeviceMessage_GetFirmwareVariant(msg)<<24) |
|
||||
(AQH_DeviceMessage_GetFirmwareVersionMajor(msg)<<16) |
|
||||
(AQH_DeviceMessage_GetFirmwareVersionMinor(msg)<<8) |
|
||||
AQH_DeviceMessage_GetFirmwareVersionPatchlevel(msg));
|
||||
s=AQH_NodeInfo_GetDeviceId(ni);
|
||||
if (!(s && *s))
|
||||
_assignDeviceId(aqh, ni, uid);
|
||||
_assignDeviceId(o, ni, uid);
|
||||
_updateTimestampLastChange(ni);
|
||||
AQH_NodeDb_SetModified(aqh->nodeDb);
|
||||
AQH_NodeDb_SetModified(xo->nodeDb);
|
||||
if (uid!=0x00000000L && uid!=0xffffffff)
|
||||
_announceNodeValues(aqh, ni);
|
||||
_announceNodeValues(o, xo, ni);
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
@@ -258,7 +206,7 @@ void _handleMsgDevice(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
|
||||
|
||||
|
||||
void _announceNodeValues(AQHOMED *aqh, const AQH_NODE_INFO *ni)
|
||||
void _announceNodeValues(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_NODE_INFO *ni)
|
||||
{
|
||||
const char *devName;
|
||||
|
||||
@@ -266,7 +214,7 @@ void _announceNodeValues(AQHOMED *aqh, const AQH_NODE_INFO *ni)
|
||||
if (devName) {
|
||||
const AQHNODE_DEVICE *devInfo;
|
||||
|
||||
devInfo=AqHomed_GetDeviceDefByName(aqh, devName);
|
||||
devInfo=AQH_NodeServer_GetDeviceDefByName(o, devName);
|
||||
if (devInfo) {
|
||||
const AQHNODE_VALUE_LIST *valueList;
|
||||
|
||||
@@ -280,7 +228,7 @@ void _announceNodeValues(AQHOMED *aqh, const AQH_NODE_INFO *ni)
|
||||
AQH_NodeInfo_GetUid(ni), AQHNODE_Value_GetName(v),
|
||||
AQHNODE_Value_GetModality(v),
|
||||
AQH_ValueModality_toString(AQHNODE_Value_GetModality(v)));
|
||||
_announceValue(aqh, AQH_NodeInfo_GetUid(ni), v);
|
||||
_announceValue(xo, AQH_NodeInfo_GetUid(ni), v);
|
||||
v=AQHNODE_Value_List_Next(v);
|
||||
}
|
||||
}
|
||||
@@ -308,10 +256,10 @@ void _setDeviceName(AQH_VALUE *value, uint32_t uid)
|
||||
|
||||
|
||||
|
||||
void _announceValue(AQHOMED *aqh, uint32_t uid, const AQHNODE_VALUE *v)
|
||||
void _announceValue(AQH_NODE_SERVER *xo, uint32_t uid, const AQHNODE_VALUE *v)
|
||||
{
|
||||
AQH_VALUE *value;
|
||||
GWEN_MSG *msg;
|
||||
AQH_MESSAGE *msg;
|
||||
|
||||
value=AQH_Value_new();
|
||||
_setDeviceName(value, uid);
|
||||
@@ -320,41 +268,41 @@ void _announceValue(AQHOMED *aqh, uint32_t uid, const AQHNODE_VALUE *v)
|
||||
AQH_Value_SetValueUnits(value, AQHNODE_Value_GetValueUnits(v));
|
||||
AQH_Value_SetValueType(value, AQHNODE_Value_GetValueType(v));
|
||||
AQH_Value_SetModality(value, AQHNODE_Value_GetModality(v));
|
||||
|
||||
msg=AQH_ValuesDataIpcMsg_newForOneValue(AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE,
|
||||
GWEN_MsgEndpoint_GetNextMessageId(aqh->brokerEndpoint), 0,
|
||||
0, value);
|
||||
GWEN_MsgEndpoint_AddSendMessage(aqh->brokerEndpoint, msg);
|
||||
|
||||
msg=AQH_IpcdMessageValues_newForOne(AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE,
|
||||
AQH_Endpoint_GetNextMessageId(xo->brokerEndpoint), 0,
|
||||
0, value);
|
||||
AQH_Endpoint_AddMsgOut(xo->brokerEndpoint, msg);
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleMsgFlashReady(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
void _handleMsgFlashReady(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint32_t uid;
|
||||
|
||||
uid=AQH_FlashReadyMsg_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
|
||||
uid=AQH_FlashReadyMessage_GetUid(msg);
|
||||
ni=_getOrCreateNodeAndUpdateUidAddr(xo, msg, uid);
|
||||
if (ni) {
|
||||
const char *s;
|
||||
|
||||
AQH_NodeInfo_SetManufacturer(ni, AQH_FlashReadyMsg_GetManufacturer(msg));
|
||||
AQH_NodeInfo_SetDeviceType(ni, AQH_FlashReadyMsg_GetDeviceType(msg));
|
||||
AQH_NodeInfo_SetDeviceVersion(ni, (AQH_FlashReadyMsg_GetDeviceVersion(msg)<<8)+AQH_FlashReadyMsg_GetDeviceRevision(msg));
|
||||
AQH_NodeInfo_SetManufacturer(ni, AQH_FlashReadyMessage_GetManufacturer(msg));
|
||||
AQH_NodeInfo_SetDeviceType(ni, AQH_FlashReadyMessage_GetDeviceType(msg));
|
||||
AQH_NodeInfo_SetDeviceVersion(ni, (AQH_FlashReadyMessage_GetDeviceVersion(msg)<<8)+AQH_FlashReadyMessage_GetDeviceRevision(msg));
|
||||
AQH_NodeInfo_SetFirmwareVersion(ni,
|
||||
(AQH_FlashReadyMsg_GetFirmwareVariant(msg)<<24) |
|
||||
(AQH_FlashReadyMsg_GetFirmwareVersionMajor(msg)<<16) |
|
||||
(AQH_FlashReadyMsg_GetFirmwareVersionMinor(msg)<<8) |
|
||||
AQH_FlashReadyMsg_GetFirmwareVersionPatchlevel(msg));
|
||||
(AQH_FlashReadyMessage_GetFirmwareVariant(msg)<<24) |
|
||||
(AQH_FlashReadyMessage_GetFirmwareVersionMajor(msg)<<16) |
|
||||
(AQH_FlashReadyMessage_GetFirmwareVersionMinor(msg)<<8) |
|
||||
AQH_FlashReadyMessage_GetFirmwareVersionPatchlevel(msg));
|
||||
s=AQH_NodeInfo_GetDeviceId(ni);
|
||||
if (!(s && *s))
|
||||
_assignDeviceId(aqh, ni, uid);
|
||||
_assignDeviceId(o, ni, uid);
|
||||
_updateTimestampLastChange(ni);
|
||||
AQH_NodeDb_SetModified(aqh->nodeDb);
|
||||
AQH_NodeDb_SetModified(xo->nodeDb);
|
||||
if (uid!=0x00000000L && uid!=0xffffffff)
|
||||
_announceNodeValues(aqh, ni);
|
||||
_announceNodeValues(o, xo, ni);
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
|
||||
@@ -363,13 +311,13 @@ void _handleMsgFlashReady(AQHOMED *aqh, const GWEN_MSG *msg)
|
||||
|
||||
|
||||
|
||||
AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(AQHOMED *aqh, const GWEN_MSG *msg, uint32_t uid)
|
||||
AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg, uint32_t uid)
|
||||
{
|
||||
uint8_t busAddr;
|
||||
AQH_NODE_INFO *ni;
|
||||
|
||||
busAddr=AQH_NodeMsg_GetSourceAddress(msg);
|
||||
ni=AQH_NodeDb_GetNodeInfoByUid(aqh->nodeDb, uid);
|
||||
busAddr=AQH_NodeMessage_GetSourceAddress(msg);
|
||||
ni=AQH_NodeDb_GetNodeInfoByUid(xo->nodeDb, uid);
|
||||
if (ni) {
|
||||
uint8_t storedBusAddr;
|
||||
|
||||
@@ -378,7 +326,7 @@ AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(AQHOMED *aqh, const GWEN_MSG *ms
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Changed busaddr for %08x from %02x to %02x", uid, storedBusAddr, busAddr);
|
||||
AQH_NodeInfo_SetBusAddress(ni, busAddr);
|
||||
_updateTimestampLastChange(ni);
|
||||
AQH_NodeDb_SetModified(aqh->nodeDb);
|
||||
AQH_NodeDb_SetModified(xo->nodeDb);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -388,7 +336,7 @@ AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(AQHOMED *aqh, const GWEN_MSG *ms
|
||||
AQH_NodeInfo_SetBusAddress(ni, busAddr);
|
||||
AQH_NodeInfo_SetUid(ni, uid);
|
||||
_updateTimestampLastChange(ni);
|
||||
rv=AQH_NodeDb_AddNodeInfo(aqh->nodeDb, ni);
|
||||
rv=AQH_NodeDb_AddNodeInfo(xo->nodeDb, ni);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
AQH_NodeInfo_free(ni);
|
||||
@@ -403,14 +351,14 @@ AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(AQHOMED *aqh, const GWEN_MSG *ms
|
||||
|
||||
|
||||
|
||||
void _assignDeviceId(AQHOMED *aqh, AQH_NODE_INFO *ni, uint32_t uid)
|
||||
void _assignDeviceId(AQH_OBJECT *o, AQH_NODE_INFO *ni, uint32_t uid)
|
||||
{
|
||||
const AQHNODE_DEVICE *dev;
|
||||
|
||||
dev=AqHomed_FindDeviceDef(aqh,
|
||||
AQH_NodeInfo_GetManufacturer(ni),
|
||||
AQH_NodeInfo_GetDeviceType(ni),
|
||||
AQH_NodeInfo_GetDeviceVersion(ni));
|
||||
dev=AQH_NodeServer_FindDeviceDef(o,
|
||||
AQH_NodeInfo_GetManufacturer(ni),
|
||||
AQH_NodeInfo_GetDeviceType(ni),
|
||||
AQH_NodeInfo_GetDeviceVersion(ni));
|
||||
if (dev==NULL) {
|
||||
DBG_ERROR(NULL,
|
||||
"Unknown NODE device encountered (%08x, %04x, %04x)",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
@@ -10,13 +10,15 @@
|
||||
#define AQHOMED_DB_H
|
||||
|
||||
|
||||
#include "./aqhomed.h"
|
||||
#include "./server.h"
|
||||
|
||||
#include "aqhome/events2/object.h"
|
||||
#include "aqhome/ipc2/message.h"
|
||||
|
||||
|
||||
void AQH_NodeServer_NodeMsgToDb(AQH_OBJECT *o, const AQH_MESSAGE *msg);
|
||||
|
||||
void AqHomed_NodeMsgToDb(AQHOMED *aqh, const GWEN_MSG *msg);
|
||||
|
||||
void AqHomed_WriteNodeDb(AQHOMED *aqh);
|
||||
void AQH_NodeServer_WriteNodeDb(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ static void _dumpValue(const AQHNODE_VALUE *value, GWEN_BUFFER *dbuf, int indent
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void AqHomeNodes_DumpDevices(const AQHNODE_DEVICE_LIST *devList, GWEN_BUFFER *dbuf)
|
||||
void AQH_NodeServer_DumpDevices(const AQHNODE_DEVICE_LIST *devList, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
|
||||
if (devList && AQHNODE_Device_List_GetCount(devList)) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
|
||||
void AqHomeNodes_DumpDevices(const AQHNODE_DEVICE_LIST *devList, GWEN_BUFFER *dbuf);
|
||||
void AQH_NodeServer_DumpDevices(const AQHNODE_DEVICE_LIST *devList, GWEN_BUFFER *dbuf);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ static int _readDeviceVersion(AQHNODE_DEVICE *device, GWEN_XMLNODE *deviceNode);
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQHNODE_DEVICE_LIST *AqHomeNodes_ReadDeviceFile(const char *sFilename)
|
||||
AQHNODE_DEVICE_LIST *AQH_NodeServer_ReadDeviceFile(const char *sFilename)
|
||||
{
|
||||
int rv;
|
||||
|
||||
@@ -81,7 +81,7 @@ AQHNODE_DEVICE_LIST *AqHomeNodes_ReadDeviceFile(const char *sFilename)
|
||||
|
||||
|
||||
|
||||
AQHNODE_DEVICE_LIST *AqHomeNodes_ReadDataDeviceFiles()
|
||||
AQHNODE_DEVICE_LIST *AQH_NodeServer_ReadDataDeviceFiles()
|
||||
{
|
||||
GWEN_STRINGLIST *sl;
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
|
||||
|
||||
AQHNODE_DEVICE_LIST *AqHomeNodes_ReadDeviceFile(const char *sFilename);
|
||||
AQHNODE_DEVICE_LIST *AqHomeNodes_ReadDataDeviceFiles(void);
|
||||
AQHNODE_DEVICE_LIST *AQH_NodeServer_ReadDeviceFile(const char *sFilename);
|
||||
AQHNODE_DEVICE_LIST *AQH_NodeServer_ReadDataDeviceFiles(void);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,10 +13,7 @@
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/aqhome.h>
|
||||
|
||||
#include "./aqhomed.h"
|
||||
#include "./init.h"
|
||||
#include "./fini.h"
|
||||
#include "./loop.h"
|
||||
#include "./server.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/logger.h>
|
||||
@@ -37,6 +34,9 @@
|
||||
#define I18N(msg) msg
|
||||
#define I18S(msg) msg
|
||||
|
||||
#define CONNCLEAN_INTERVAL_IN_SECS 2
|
||||
#define CONNCHECK_INTERVAL_IN_SECS 10
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -44,12 +44,13 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _runService(AQHOMED *aqh);
|
||||
static void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop);
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
static int _setSignalHandlers(void);
|
||||
static int _setupSigAction(struct sigaction *sa, int sig);
|
||||
static void _signalHandler(int s);
|
||||
#endif
|
||||
static int _diffInSeconds(time_t t1, time_t t0);
|
||||
|
||||
|
||||
|
||||
@@ -74,7 +75,8 @@ static int stopService=0;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rv;
|
||||
AQHOMED *aqh;
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
AQH_OBJECT *aqh;
|
||||
GWEN_GUI *gui;
|
||||
|
||||
rv=GWEN_Init();
|
||||
@@ -83,7 +85,7 @@ int main(int argc, char **argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
GWEN_Logger_Open(0, "aqhomed", 0, GWEN_LoggerType_Console, GWEN_LoggerFacility_User);
|
||||
GWEN_Logger_Open(0, "aqhome-nodes", 0, GWEN_LoggerType_Console, GWEN_LoggerFacility_User);
|
||||
GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Warning);
|
||||
|
||||
rv=_setSignalHandlers();
|
||||
@@ -101,17 +103,18 @@ int main(int argc, char **argv)
|
||||
gui=GWEN_Gui_CGui_new();
|
||||
GWEN_Gui_SetGui(gui);
|
||||
|
||||
aqh=AqHomed_new();
|
||||
rv=AqHomed_Init(aqh, argc, argv);
|
||||
eventLoop=AQH_EventLoop_new();
|
||||
aqh=AQH_NodeServer_new(eventLoop);
|
||||
rv=AQH_NodeServer_Init(aqh, argc, argv);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
|
||||
_runService(aqh);
|
||||
_runService(aqh, eventLoop);
|
||||
|
||||
AqHomed_Fini(aqh);
|
||||
AqHomed_free(aqh);
|
||||
//AQH_NodeServer_Fini(aqh);
|
||||
AQH_Object_free(aqh);
|
||||
|
||||
GWEN_Gui_SetGui(NULL);
|
||||
GWEN_Gui_free(gui);
|
||||
@@ -121,24 +124,44 @@ int main(int argc, char **argv)
|
||||
|
||||
|
||||
|
||||
void _runService(AQHOMED *aqh)
|
||||
void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop)
|
||||
{
|
||||
time_t timeStart;
|
||||
int timeout;
|
||||
time_t timeLastConnectionCleanup;
|
||||
time_t timeLastConnCheck;
|
||||
|
||||
timeout=AqHomed_GetTimeout(aqh);
|
||||
timeout=AQH_NodeServer_GetTimeout(aqh);
|
||||
timeStart=time(NULL);
|
||||
timeLastConnectionCleanup=time(NULL);
|
||||
timeLastConnCheck=time(NULL);
|
||||
|
||||
while(!stopService) {
|
||||
AqHomed_Loop(aqh, 2000);
|
||||
if (timeout) {
|
||||
time_t now;
|
||||
time_t now;
|
||||
|
||||
now=time(NULL);
|
||||
if (timeout && ((int)difftime(now, timeStart))>timeout) {
|
||||
DBG_INFO(NULL, "Timeout");
|
||||
break;
|
||||
}
|
||||
AQH_EventLoop_Run(eventLoop, 2000);
|
||||
AQH_NodeServer_HandleTtyMsgs(aqh);
|
||||
AQH_NodeServer_HandleClientMsgs(aqh);
|
||||
AQH_NodeServer_HandleBrokerMsgs(aqh);
|
||||
|
||||
now=time(NULL);
|
||||
|
||||
if (_diffInSeconds(now, timeLastConnectionCleanup)>CONNCLEAN_INTERVAL_IN_SECS) {
|
||||
DBG_ERROR(NULL, "Cleanup connections");
|
||||
AQH_NodeServer_CleanupClients(aqh);
|
||||
timeLastConnectionCleanup=now;
|
||||
}
|
||||
|
||||
if (_diffInSeconds(now, timeLastConnCheck)>CONNCHECK_INTERVAL_IN_SECS) {
|
||||
DBG_ERROR(NULL, "Write time");
|
||||
AQH_NodeServer_CheckBrokerConnection(aqh);
|
||||
AQH_NodeServer_CheckTtyConnection(aqh);
|
||||
timeLastConnCheck=now;
|
||||
}
|
||||
|
||||
if (timeout && (_diffInSeconds(now, timeStart)>timeout)) {
|
||||
DBG_INFO(NULL, "Timeout");
|
||||
break;
|
||||
}
|
||||
} /* while */
|
||||
}
|
||||
@@ -210,3 +233,10 @@ void _signalHandler(int s)
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _diffInSeconds(time_t t1, time_t t0)
|
||||
{
|
||||
return t1-t0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
@@ -12,14 +12,18 @@
|
||||
|
||||
|
||||
#include "./r_setdata.h"
|
||||
#include "./aqhomed_p.h"
|
||||
#include "./server_p.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
#include "aqhome/ipc/endpoint_ipc.h"
|
||||
#include "aqhome/ipc/msg_ipc_result.h"
|
||||
#include "aqhome/ipc/data/msg_data_set.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/msg/msg_value3.h"
|
||||
#include "aqhome/data/value.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd_setdata.h"
|
||||
#include "aqhome/msg/node/m_node.h"
|
||||
#include "aqhome/msg/node/m_value.h"
|
||||
#include "aqhome/ipc2/endpoint.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
@@ -40,18 +44,20 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static AQH_NODE_INFO *_getNodeInfoFromValue(AQHOMED *aqh, const AQH_VALUE *value);
|
||||
static AQH_NODE_INFO *_getNodeInfoFromValue(AQH_NODE_SERVER *xo, const AQH_VALUE *value);
|
||||
|
||||
static GWEN_MSG_REQUEST *_mkRequest_SetData(AQHOMED *aqh,
|
||||
GWEN_MSG_ENDPOINT *ep, uint32_t requestMsgId,
|
||||
int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom);
|
||||
static AQH_MSG_REQUEST *_mkRequest_SetData(AQH_OBJECT *o, AQH_NODE_SERVER *xo,
|
||||
AQH_OBJECT *ep, uint32_t requestMsgId,
|
||||
int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom);
|
||||
|
||||
static void _rqSubRequestFinished(GWEN_MSG_REQUEST *rq, GWEN_MSG_REQUEST *subRq, int reason);
|
||||
static void _rqAbort(GWEN_MSG_REQUEST *rq, int reason);
|
||||
static void _rqSubRequestFinished(AQH_MSG_REQUEST *rq, AQH_MSG_REQUEST *subRq, int reason);
|
||||
static void _rqAbort(AQH_MSG_REQUEST *rq, int reason);
|
||||
|
||||
static GWEN_MSG_REQUEST *_mkSubRequest_SetData(AQHOMED *aqh, int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom);
|
||||
static int _subRqHandleResponse(GWEN_MSG_REQUEST *rq, GWEN_MSG *msg);
|
||||
static void _subRqAbort(GWEN_MSG_REQUEST *rq, int reason);
|
||||
static AQH_MSG_REQUEST *_mkSubRequest_SetData(AQH_OBJECT *o, AQH_NODE_SERVER *xo,
|
||||
int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom);
|
||||
static int _subRqHandleResponse(AQH_MSG_REQUEST *rq, const AQH_MESSAGE *msg);
|
||||
static void _subRqAbort(AQH_MSG_REQUEST *rq, int reason);
|
||||
static void _sendResponseResultToBroker(AQH_OBJECT *ep, uint32_t refMsgId, int result);
|
||||
|
||||
|
||||
|
||||
@@ -61,171 +67,182 @@ static void _subRqAbort(GWEN_MSG_REQUEST *rq, int reason);
|
||||
*/
|
||||
|
||||
|
||||
void AqHomeNodes_HandleSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *recvdMsg)
|
||||
void AQH_NodeServer_HandleSetData(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *recvdMsg)
|
||||
{
|
||||
uint32_t msgId;
|
||||
if (o) {
|
||||
AQH_NODE_SERVER *xo;
|
||||
|
||||
DBG_INFO(NULL, "Received IPC SetDataRequest message");
|
||||
msgId=GWEN_IpcMsg_GetMsgId(recvdMsg);
|
||||
xo=AQH_NodeServer_GetServerData(o);
|
||||
if (xo) {
|
||||
uint32_t msgId;
|
||||
|
||||
if (aqh->ttyEndpoint && GWEN_MsgEndpoint_GetState(aqh->ttyEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
|
||||
AQH_VALUE *value;
|
||||
DBG_INFO(NULL, "Received IPC SetDataRequest message");
|
||||
msgId=AQH_IpcMessage_GetMsgId(recvdMsg);
|
||||
|
||||
if (xo->ttyEndpoint) {
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
|
||||
AQH_SetDataIpcMsg_Parse(recvdMsg, 0);
|
||||
value=AQH_SetDataIpcMsg_ReadValue(recvdMsg);
|
||||
if (value) {
|
||||
const char *varName;
|
||||
tagList=AQH_IpcMessageTag16_ParsePayload(recvdMsg, 0);
|
||||
if (tagList) {
|
||||
AQH_VALUE *value;
|
||||
|
||||
value=AQH_IpcdMessageSetData_ReadValue(tagList);
|
||||
if (value) {
|
||||
const char *varName;
|
||||
|
||||
varName=AQH_Value_GetName(value);
|
||||
if (varName) {
|
||||
char *data;
|
||||
varName=AQH_Value_GetName(value);
|
||||
if (varName) {
|
||||
char *data;
|
||||
|
||||
data=AQH_SetDataIpcMsg_ReadData(recvdMsg);
|
||||
if (data) {
|
||||
AQH_NODE_INFO *nodeInfo;
|
||||
data=AQH_IpcdMessageSetData_ReadData(tagList);
|
||||
if (data) {
|
||||
AQH_NODE_INFO *nodeInfo;
|
||||
|
||||
nodeInfo=_getNodeInfoFromValue(aqh, value);
|
||||
if (nodeInfo) {
|
||||
const char *devName;
|
||||
nodeInfo=_getNodeInfoFromValue(xo, value);
|
||||
if (nodeInfo) {
|
||||
const char *devName;
|
||||
|
||||
devName=AQH_NodeInfo_GetDeviceId(nodeInfo);
|
||||
if (devName) {
|
||||
const AQHNODE_DEVICE *devInfo;
|
||||
devName=AQH_NodeInfo_GetDeviceId(nodeInfo);
|
||||
if (devName) {
|
||||
const AQHNODE_DEVICE *devInfo;
|
||||
|
||||
devInfo=AqHomed_GetDeviceDefByName(aqh, devName);
|
||||
if (devInfo) {
|
||||
const AQHNODE_VALUE *devValue;
|
||||
devInfo=AQH_NodeServer_GetDeviceDefByName(o, devName);
|
||||
if (devInfo) {
|
||||
const AQHNODE_VALUE *devValue;
|
||||
|
||||
devValue=AQHNODE_Value_List_GetByName(AQHNODE_Device_GetValueList(devInfo), varName);
|
||||
if (devValue) {
|
||||
uint16_t dataVal=0;
|
||||
uint16_t dataDenom=0;
|
||||
devValue=AQHNODE_Value_List_GetByName(AQHNODE_Device_GetValueList(devInfo), varName);
|
||||
if (devValue) {
|
||||
uint16_t dataVal=0;
|
||||
uint16_t dataDenom=0;
|
||||
|
||||
if (AQH_ReadDataFromString(AQHNODE_Value_GetDataType(devValue), data, &dataVal, &dataDenom)==0) {
|
||||
GWEN_MSG_REQUEST *rq;
|
||||
int destAddr;
|
||||
if (AQH_ReadDataFromString(AQHNODE_Value_GetDataType(devValue), data, &dataVal, &dataDenom)==0) {
|
||||
AQH_MSG_REQUEST *rq;
|
||||
int destAddr;
|
||||
|
||||
destAddr=AQH_NodeInfo_GetBusAddress(nodeInfo);
|
||||
DBG_DEBUG(NULL, "Creating SETDATA request");
|
||||
destAddr=AQH_NodeInfo_GetBusAddress(nodeInfo);
|
||||
DBG_DEBUG(NULL, "Creating SETDATA request");
|
||||
|
||||
rq=_mkRequest_SetData(aqh, ep, msgId, destAddr, AQHNODE_Value_GetId(devValue), dataVal, dataDenom);
|
||||
AqHomed_AddRequestToTree(aqh, rq);
|
||||
/* done */
|
||||
rq=_mkRequest_SetData(o, xo, ep, msgId, destAddr, AQHNODE_Value_GetId(devValue), dataVal, dataDenom);
|
||||
AQH_NodeServer_AddRequestToTree(o, rq);
|
||||
/* done */
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Bad data \"%s\"", data);
|
||||
_sendResponseResultToBroker(ep, msgId, AQH_MSGDATA_RESULT_ERROR_BADDATA);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Invalid value name \"%s\"", varName);
|
||||
_sendResponseResultToBroker(ep, msgId, AQH_MSGDATA_RESULT_ERROR_INVALID);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Unknown node \"%s\"", devName);
|
||||
_sendResponseResultToBroker(ep, msgId, AQH_MSGDATA_RESULT_ERROR_INVALID);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Bad data \"%s\"", data);
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_BADDATA);
|
||||
DBG_ERROR(NULL, "Node not yet fully identified, come back later");
|
||||
_sendResponseResultToBroker(ep, msgId, AQH_MSGDATA_RESULT_ERROR_TRYAGAIN);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Invalid value name \"%s\"", varName);
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_INVALID);
|
||||
DBG_ERROR(NULL, "No matching nodeinfo");
|
||||
_sendResponseResultToBroker(ep, msgId, AQH_MSGDATA_RESULT_ERROR_INVALID);
|
||||
}
|
||||
free(data);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Unknown node \"%s\"", devName);
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_INVALID);
|
||||
DBG_ERROR(NULL, "No data");
|
||||
_sendResponseResultToBroker(ep, msgId, AQH_MSGDATA_RESULT_ERROR_NODATA);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Node not yet fully identified, come back later");
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_TRYAGAIN);
|
||||
DBG_ERROR(NULL, "No var name");
|
||||
_sendResponseResultToBroker(ep, msgId, AQH_MSGDATA_RESULT_ERROR_NODATA);
|
||||
}
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "No matching nodeinfo");
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_INVALID);
|
||||
DBG_ERROR(NULL, "Could not read value from message");
|
||||
}
|
||||
free(data);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "No data");
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_NODATA);
|
||||
GWEN_Tag16_List_free(tagList);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "No var name");
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_NODATA);
|
||||
DBG_ERROR(NULL, "TTY endpoint not connected");
|
||||
_sendResponseResultToBroker(ep, msgId, AQH_MSGDATA_RESULT_ERROR_IO);
|
||||
}
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Could not read value from message");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "TTY endpoint not connected");
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_IO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* IPC Request SETDATA
|
||||
*/
|
||||
|
||||
GWEN_MSG_REQUEST *_mkRequest_SetData(AQHOMED *aqh,
|
||||
GWEN_MSG_ENDPOINT *ep, uint32_t requestMsgId,
|
||||
int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom)
|
||||
AQH_MSG_REQUEST *_mkRequest_SetData(AQH_OBJECT *o, AQH_NODE_SERVER *xo,
|
||||
AQH_OBJECT *ep, uint32_t requestMsgId,
|
||||
int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom)
|
||||
{
|
||||
GWEN_MSG_REQUEST *rq;
|
||||
GWEN_MSG_REQUEST *subRq;
|
||||
AQH_MSG_REQUEST *rq;
|
||||
AQH_MSG_REQUEST *subRq;
|
||||
|
||||
rq=GWEN_MsgRequest_new();
|
||||
GWEN_MsgRequest_SetPrivateData(rq, aqh);
|
||||
GWEN_MsgRequest_SetEndpoint(rq, ep);
|
||||
GWEN_MsgRequest_SetRequestMsgId(rq, requestMsgId);
|
||||
GWEN_MsgRequest_SetSubRequestFinishedFn(rq, _rqSubRequestFinished);
|
||||
GWEN_MsgRequest_SetAbortFn(rq, _rqAbort);
|
||||
GWEN_MsgRequest_SetTimestamps(rq, R_SETDATA_REQUEST_EXPIRE_SECS);
|
||||
rq=AQH_MsgRequest_new();
|
||||
AQH_MsgRequest_SetPrivateData(rq, o);
|
||||
AQH_MsgRequest_SetEndpoint(rq, ep);
|
||||
AQH_MsgRequest_SetRequestMsgId(rq, requestMsgId);
|
||||
AQH_MsgRequest_SetSubRequestFinishedFn(rq, _rqSubRequestFinished);
|
||||
AQH_MsgRequest_SetAbortFn(rq, _rqAbort);
|
||||
AQH_MsgRequest_SetTimestamps(rq, R_SETDATA_REQUEST_EXPIRE_SECS);
|
||||
|
||||
subRq=_mkSubRequest_SetData(aqh, destAddr, valueId, dataVal, dataDenom);
|
||||
GWEN_MsgRequest_Tree2_AddChild(rq, subRq);
|
||||
subRq=_mkSubRequest_SetData(o, xo, destAddr, valueId, dataVal, dataDenom);
|
||||
AQH_MsgRequest_Tree2_AddChild(rq, subRq);
|
||||
|
||||
return rq;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _rqSubRequestFinished(GWEN_MSG_REQUEST *rq, GWEN_MSG_REQUEST *subRq, int reason)
|
||||
void _rqSubRequestFinished(AQH_MSG_REQUEST *rq, AQH_MSG_REQUEST *subRq, int reason)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
AQH_OBJECT *ep;
|
||||
uint32_t refMsgId;
|
||||
int result;
|
||||
|
||||
DBG_INFO(NULL, "SubRequest finished (reason: %d)", reason);
|
||||
refMsgId=GWEN_MsgRequest_GetRequestMsgId(rq);
|
||||
ep=GWEN_MsgRequest_GetEndpoint(rq);
|
||||
result=GWEN_MsgRequest_GetResult(subRq);
|
||||
refMsgId=AQH_MsgRequest_GetRequestMsgId(rq);
|
||||
ep=AQH_MsgRequest_GetEndpoint(rq);
|
||||
result=AQH_MsgRequest_GetResult(subRq);
|
||||
|
||||
if (reason==GWEN_MSG_REQUEST_REASON_ABORTED)
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, refMsgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_GENERIC);
|
||||
if (reason==AQH_MSG_REQUEST_REASON_ABORTED)
|
||||
_sendResponseResultToBroker(ep, refMsgId, AQH_MSGDATA_RESULT_ERROR_GENERIC);
|
||||
else
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, refMsgId, AQH_MSGTYPE_IPC_DATA_RESULT, result);
|
||||
_sendResponseResultToBroker(ep, refMsgId, result);
|
||||
|
||||
GWEN_MsgRequest_SetResult(rq, result);
|
||||
GWEN_MsgRequest_SetState(rq, GWEN_MSG_REQUEST_STATE_DONE);
|
||||
AQH_MsgRequest_SetResult(rq, result);
|
||||
AQH_MsgRequest_SetState(rq, AQH_MSG_REQUEST_STATE_DONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _rqAbort(GWEN_MSG_REQUEST *rq, int reason)
|
||||
void _rqAbort(AQH_MSG_REQUEST *rq, int reason)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
AQH_OBJECT *ep;
|
||||
uint32_t refMsgId;
|
||||
GWEN_MSG_REQUEST *rqParent;
|
||||
AQH_MSG_REQUEST *rqParent;
|
||||
|
||||
DBG_INFO(NULL, "Aborting request");
|
||||
refMsgId=GWEN_MsgRequest_GetRequestMsgId(rq);
|
||||
ep=GWEN_MsgRequest_GetEndpoint(rq);
|
||||
AQH_IpcEndpoint_SendResponseResult(ep, refMsgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_GENERIC);
|
||||
GWEN_MsgRequest_SetState(rq, GWEN_MSG_REQUEST_STATE_DONE);
|
||||
refMsgId=AQH_MsgRequest_GetRequestMsgId(rq);
|
||||
ep=AQH_MsgRequest_GetEndpoint(rq);
|
||||
_sendResponseResultToBroker(ep, refMsgId, AQH_MSGDATA_RESULT_ERROR_GENERIC);
|
||||
AQH_MsgRequest_SetState(rq, AQH_MSG_REQUEST_STATE_DONE);
|
||||
|
||||
rqParent=GWEN_MsgRequest_Tree2_GetParent(rq);
|
||||
rqParent=AQH_MsgRequest_Tree2_GetParent(rq);
|
||||
if (rqParent)
|
||||
GWEN_MsgRequest_SubRequestFinished(rqParent, rq, reason);
|
||||
AQH_MsgRequest_SubRequestFinished(rqParent, rq, reason);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,91 +255,100 @@ void _rqAbort(GWEN_MSG_REQUEST *rq, int reason)
|
||||
*/
|
||||
|
||||
|
||||
GWEN_MSG_REQUEST *_mkSubRequest_SetData(AQHOMED *aqh, int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom)
|
||||
AQH_MSG_REQUEST *_mkSubRequest_SetData(AQH_OBJECT *o, AQH_NODE_SERVER *xo,
|
||||
int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom)
|
||||
{
|
||||
GWEN_MSG_REQUEST *rq;
|
||||
AQH_MSG_REQUEST *rq;
|
||||
uint16_t msgId;
|
||||
GWEN_MSG *msgOut;
|
||||
AQH_MESSAGE *msgOut;
|
||||
|
||||
rq=GWEN_MsgRequest_new();
|
||||
GWEN_MsgRequest_SetPrivateData(rq, aqh);
|
||||
GWEN_MsgRequest_SetEndpoint(rq, aqh->ttyEndpoint);
|
||||
rq=AQH_MsgRequest_new();
|
||||
AQH_MsgRequest_SetPrivateData(rq, o);
|
||||
AQH_MsgRequest_SetEndpoint(rq, xo->ttyEndpoint);
|
||||
|
||||
GWEN_MsgRequest_SetHandleResponseFn(rq, _subRqHandleResponse);
|
||||
GWEN_MsgRequest_SetAbortFn(rq, _subRqAbort);
|
||||
AQH_MsgRequest_SetHandleResponseFn(rq, _subRqHandleResponse);
|
||||
AQH_MsgRequest_SetAbortFn(rq, _subRqAbort);
|
||||
|
||||
msgId=GWEN_MsgEndpoint_GetNextMessageId(aqh->ttyEndpoint) & 0xffff;
|
||||
GWEN_MsgRequest_SetRequestMsgId(rq, msgId);
|
||||
GWEN_MsgRequest_SetTimestamps(rq, R_SETDATA_SUBREQUEST_EXPIRE_SECS);
|
||||
msgId=AQH_Endpoint_GetNextMessageId(xo->ttyEndpoint) & 0xffff;
|
||||
AQH_MsgRequest_SetRequestMsgId(rq, msgId);
|
||||
AQH_MsgRequest_SetTimestamps(rq, R_SETDATA_SUBREQUEST_EXPIRE_SECS);
|
||||
|
||||
msgOut=AQH_Value3Msg_new(aqh->nodeAddress, destAddr, AQH_MSG_TYPE_VALUE_SET, msgId, valueId, dataVal, dataDenom);
|
||||
GWEN_MsgEndpoint_AddSendMessage(aqh->ttyEndpoint, msgOut);
|
||||
msgOut=AQH_ValueMessage_new(xo->nodeAddress, destAddr, AQH_MSG_TYPE_VALUE_SET, msgId, valueId, dataVal, dataDenom);
|
||||
AQH_Endpoint_AddMsgOut(xo->ttyEndpoint, msgOut);
|
||||
|
||||
return rq;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _subRqHandleResponse(GWEN_MSG_REQUEST *rq, GWEN_MSG *msg)
|
||||
int _subRqHandleResponse(AQH_MSG_REQUEST *rq, const AQH_MESSAGE *msg)
|
||||
{
|
||||
AQHOMED *aqh;
|
||||
uint8_t destAddr;
|
||||
AQH_OBJECT *o;
|
||||
|
||||
DBG_DEBUG(NULL, "Checking message from %02x", AQH_NodeMsg_GetSourceAddress(msg));
|
||||
aqh=(AQHOMED*)GWEN_MsgRequest_GetPrivateData(rq);
|
||||
DBG_DEBUG(NULL, "Checking message from %02x", AQH_NodeMessage_GetSourceAddress(msg));
|
||||
o=(AQH_OBJECT*)AQH_MsgRequest_GetPrivateData(rq);
|
||||
if (o) {
|
||||
AQH_NODE_SERVER *xo;
|
||||
|
||||
destAddr=AQH_NodeMsg_GetDestAddress(msg);
|
||||
if (destAddr==0xff || destAddr==aqh->nodeAddress) {
|
||||
uint8_t msgCode;
|
||||
xo=AQH_NodeServer_GetServerData(o);
|
||||
if (xo) {
|
||||
uint8_t destAddr;
|
||||
|
||||
msgCode=AQH_NodeMsg_GetMsgType(msg);
|
||||
if (msgCode==AQH_MSG_TYPE_VALUE_SET_ACK || msgCode==AQH_MSG_TYPE_VALUE_SET_NACK) {
|
||||
uint16_t msgId;
|
||||
destAddr=AQH_NodeMessage_GetDestAddress(msg);
|
||||
if (destAddr==0xff || destAddr==xo->nodeAddress) {
|
||||
uint8_t msgCode;
|
||||
|
||||
msgId=AQH_Value3Msg_GetMsgId(msg);
|
||||
if (msgId==GWEN_MsgRequest_GetRequestMsgId(rq)) {
|
||||
GWEN_MSG_REQUEST *rqParent;
|
||||
msgCode=AQH_NodeMessage_GetMsgType(msg);
|
||||
if (msgCode==AQH_MSG_TYPE_VALUE_SET_ACK || msgCode==AQH_MSG_TYPE_VALUE_SET_NACK) {
|
||||
uint16_t msgId;
|
||||
|
||||
DBG_INFO(NULL,
|
||||
"Received response (%02x) for msg id %04x from %02x",
|
||||
msgCode, msgId, AQH_NodeMsg_GetSourceAddress(msg));
|
||||
GWEN_MsgRequest_SetResult(rq, (msgCode==AQH_MSG_TYPE_VALUE_SET_ACK)?AQH_MSG_IPC_SUCCESS:AQH_MSG_IPC_ERROR_GENERIC);
|
||||
GWEN_MsgRequest_SetState(rq, GWEN_MSG_REQUEST_STATE_DONE);
|
||||
rqParent=GWEN_MsgRequest_Tree2_GetParent(rq);
|
||||
if (rqParent)
|
||||
GWEN_MsgRequest_SubRequestFinished(rqParent, rq, GWEN_MSG_REQUEST_REASON_DONE);
|
||||
return GWEN_MSG_REQUEST_RESULT_HANDLED;
|
||||
msgId=AQH_ValueMessage_GetMsgId(msg);
|
||||
if (msgId==AQH_MsgRequest_GetRequestMsgId(rq)) {
|
||||
AQH_MSG_REQUEST *rqParent;
|
||||
|
||||
DBG_INFO(NULL,
|
||||
"Received response (%02x) for msg id %04x from %02x",
|
||||
msgCode, msgId, AQH_NodeMessage_GetSourceAddress(msg));
|
||||
AQH_MsgRequest_SetResult(rq,
|
||||
(msgCode==AQH_MSG_TYPE_VALUE_SET_ACK)?AQH_MSGDATA_RESULT_SUCCESS:AQH_MSGDATA_RESULT_ERROR_GENERIC);
|
||||
AQH_MsgRequest_SetState(rq, AQH_MSG_REQUEST_STATE_DONE);
|
||||
rqParent=AQH_MsgRequest_Tree2_GetParent(rq);
|
||||
if (rqParent)
|
||||
AQH_MsgRequest_SubRequestFinished(rqParent, rq, AQH_MSG_REQUEST_REASON_DONE);
|
||||
return AQH_MSG_REQUEST_RESULT_HANDLED;
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, " Non-matching message id");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, " Non-matching message code");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, " Non-matching message id");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, " Non-matching message code");
|
||||
}
|
||||
}
|
||||
return GWEN_MSG_REQUEST_RESULT_NOT_HANDLED;
|
||||
return AQH_MSG_REQUEST_RESULT_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _subRqAbort(GWEN_MSG_REQUEST *rq, int reason)
|
||||
void _subRqAbort(AQH_MSG_REQUEST *rq, int reason)
|
||||
{
|
||||
GWEN_MSG_REQUEST *rqParent;
|
||||
AQH_MSG_REQUEST *rqParent;
|
||||
|
||||
DBG_INFO(NULL, "Aborting request");
|
||||
|
||||
GWEN_MsgRequest_SetResult(rq, AQH_MSG_IPC_ERROR_GENERIC);
|
||||
GWEN_MsgRequest_SetState(rq, GWEN_MSG_REQUEST_STATE_DONE);
|
||||
AQH_MsgRequest_SetResult(rq, AQH_MSGDATA_RESULT_ERROR_GENERIC);
|
||||
AQH_MsgRequest_SetState(rq, AQH_MSG_REQUEST_STATE_DONE);
|
||||
|
||||
rqParent=GWEN_MsgRequest_Tree2_GetParent(rq);
|
||||
rqParent=AQH_MsgRequest_Tree2_GetParent(rq);
|
||||
if (rqParent)
|
||||
GWEN_MsgRequest_SubRequestFinished(rqParent, rq, reason);
|
||||
AQH_MsgRequest_SubRequestFinished(rqParent, rq, reason);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_NODE_INFO *_getNodeInfoFromValue(AQHOMED *aqh, const AQH_VALUE *value)
|
||||
AQH_NODE_INFO *_getNodeInfoFromValue(AQH_NODE_SERVER *xo, const AQH_VALUE *value)
|
||||
{
|
||||
const char *s;
|
||||
unsigned long int uid;
|
||||
@@ -331,7 +357,7 @@ AQH_NODE_INFO *_getNodeInfoFromValue(AQHOMED *aqh, const AQH_VALUE *value)
|
||||
if (s && *s && 1==sscanf(s, "%lx", &uid)) {
|
||||
AQH_NODE_INFO *ni;
|
||||
|
||||
ni=AQH_NodeDb_GetNodeInfoByUid(aqh->nodeDb, uid);
|
||||
ni=AQH_NodeDb_GetNodeInfoByUid(xo->nodeDb, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_ERROR(NULL, "Node \"%08lx\" not found", uid);
|
||||
return NULL;
|
||||
@@ -342,3 +368,15 @@ AQH_NODE_INFO *_getNodeInfoFromValue(AQHOMED *aqh, const AQH_VALUE *value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _sendResponseResultToBroker(AQH_OBJECT *ep, uint32_t refMsgId, int result)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
|
||||
msg=AQH_IpcMessageResult_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, AQH_MSGTYPE_IPC_DATA_RESULT,
|
||||
AQH_Endpoint_GetNextMessageId(ep), refMsgId, result, NULL);
|
||||
AQH_Endpoint_AddMsgOut(ep, msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
#define AQHOMED_R_SETDATA_H
|
||||
|
||||
|
||||
#include "./aqhomed.h"
|
||||
#include "./server.h"
|
||||
|
||||
#include <gwenhywfar/request.h>
|
||||
|
||||
|
||||
|
||||
void AqHomeNodes_HandleSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *recvdMsg);
|
||||
void AQH_NodeServer_HandleSetData(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *recvdMsg);
|
||||
|
||||
|
||||
|
||||
|
||||
1300
apps/aqhome-nodes/server.c
Normal file
1300
apps/aqhome-nodes/server.c
Normal file
File diff suppressed because it is too large
Load Diff
65
apps/aqhome-nodes/server.h
Normal file
65
apps/aqhome-nodes/server.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
|
||||
|
||||
|
||||
#include "aqhome-nodes/types/device.h"
|
||||
|
||||
#include "aqhome/events2/object.h"
|
||||
#include <aqhome/ipc2/msgrequest.h>
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT *AQH_NodeServer_new(AQH_EVENT_LOOP *eventLoop);
|
||||
int AQH_NodeServer_Init(AQH_OBJECT *o, int argc, char **argv);
|
||||
|
||||
/* loop functions */
|
||||
void AQH_NodeServer_CleanupClients(AQH_OBJECT *o);
|
||||
void AQH_NodeServer_HandleTtyMsgs(AQH_OBJECT *o);
|
||||
void AQH_NodeServer_HandleClientMsgs(AQH_OBJECT *o);
|
||||
void AQH_NodeServer_HandleBrokerMsgs(AQH_OBJECT *o);
|
||||
void AQH_NodeServer_CheckBrokerConnection(AQH_OBJECT *o);
|
||||
void AQH_NodeServer_CheckTtyConnection(AQH_OBJECT *o);
|
||||
|
||||
|
||||
/* getters and setters */
|
||||
int AQH_NodeServer_GetTimeout(const AQH_OBJECT *o);
|
||||
void AQH_NodeServer_SetLogFile(AQH_OBJECT *o, const char *s);
|
||||
void AQH_NodeServer_SetDbFile(AQH_OBJECT *o, const char *s);
|
||||
void AQH_NodeServer_SetPidFile(AQH_OBJECT *o, const char *s);
|
||||
|
||||
void AQH_NodeServer_SetDevicePath(AQH_OBJECT *o, const char *s);
|
||||
void AQH_NodeServer_SetTpcAddress(AQH_OBJECT *o, const char *s);
|
||||
void AQH_NodeServer_SetTcpPort(AQH_OBJECT *o, int i);
|
||||
void AQH_NodeServer_SetBrokerAddress(AQH_OBJECT *o, const char *s);
|
||||
void AQH_NodeServer_SetBrokerPort(AQH_OBJECT *o, int i);
|
||||
void AQH_NodeServer_SetBrokerClientId(AQH_OBJECT *o, const char *s);
|
||||
|
||||
|
||||
/* device management */
|
||||
const AQHNODE_DEVICE_LIST *AQH_NodeServer_GetDeviceDefList(const AQH_OBJECT *o);
|
||||
const AQHNODE_DEVICE *AQH_NodeServer_FindDeviceDef(const AQH_OBJECT *o,
|
||||
uint32_t manufacturer,
|
||||
uint16_t deviceType, uint16_t deviceVersion);
|
||||
const AQHNODE_DEVICE *AQH_NodeServer_GetDeviceDefByName(const AQH_OBJECT *o, const char *name);
|
||||
|
||||
|
||||
/* request management */
|
||||
AQH_MSG_REQUEST *AQH_NodeServer_GetRequestTree(const AQH_OBJECT *o);
|
||||
void AQH_NodeServer_AddRequestToTree(AQH_OBJECT *o, AQH_MSG_REQUEST *rq);
|
||||
void AQH_NodeServer_CleanupRequests(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
76
apps/aqhome-nodes/server_p.h
Normal file
76
apps/aqhome-nodes/server_p.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef SERVER_P_H
|
||||
#define SERVER_P_H
|
||||
|
||||
|
||||
#include "./server.h"
|
||||
#include "aqhome-nodes/types/device.h"
|
||||
|
||||
#include "aqhome/nodes/nodedb.h"
|
||||
#include "aqhome/ipc2/msgrequest.h"
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
|
||||
/* default values */
|
||||
#define AQHOMED_DEFAULT_NODEADDR 240
|
||||
#define AQHOMED_DEFAULT_PIDFILE "/var/run/aqhomed-node.pid"
|
||||
#define AQHOMED_DEFAULT_DEVICE "/dev/ttyUSB0"
|
||||
#define AQHOMED_DEFAULT_IPC_PORT 45454
|
||||
#define AQHOMED_DEFAULT_BROKER_PORT 1899
|
||||
#define AQHOMED_DEFAULT_BROKER_CLIENTID "nodes"
|
||||
|
||||
|
||||
|
||||
typedef struct AQH_NODE_SERVER AQH_NODE_SERVER;
|
||||
struct AQH_NODE_SERVER {
|
||||
AQH_OBJECT *ttyEndpoint;
|
||||
AQH_OBJECT *brokerEndpoint;
|
||||
|
||||
AQH_OBJECT *ipcEndpoint;
|
||||
AQH_OBJECT_LIST *ipcClientList;
|
||||
|
||||
AQH_NODE_DB *nodeDb;
|
||||
AQHNODE_DEVICE_LIST *deviceDefList;
|
||||
|
||||
AQH_MSG_REQUEST *requestTree;
|
||||
|
||||
GWEN_DB_NODE *dbArgs;
|
||||
|
||||
char *dbFile;
|
||||
char *logFile;
|
||||
char *pidFile;
|
||||
|
||||
int timeout; /* timeout for run e.g. inside valgrind */
|
||||
char *devicePath;
|
||||
|
||||
char *tcpAddress;
|
||||
int tcpPort;
|
||||
|
||||
char *brokerAddress;
|
||||
int brokerPort;
|
||||
char *brokerClientId;
|
||||
|
||||
time_t timestampTtyDown;
|
||||
time_t timestampBrokerDown;
|
||||
|
||||
int nodeAddress;
|
||||
|
||||
struct termios initialTermiosState;
|
||||
|
||||
int timeoutInSeconds;
|
||||
};
|
||||
|
||||
|
||||
AQH_NODE_SERVER *AQH_NodeServer_GetServerData(const AQH_OBJECT *o);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user