aqhome: finished transformation of aqhome-data and aqhome-tool.
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
devicesread.h
|
||||
devicesdump.h
|
||||
r_setdata.h
|
||||
r_connect.h
|
||||
</headers>
|
||||
|
||||
<sources>
|
||||
@@ -49,6 +50,7 @@
|
||||
devicesread.c
|
||||
devicesdump.c
|
||||
r_setdata.c
|
||||
r_connect.c
|
||||
main.c
|
||||
</sources>
|
||||
|
||||
|
||||
82
apps/aqhome-nodes/r_connect.c
Normal file
82
apps/aqhome-nodes/r_connect.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
* 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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "./r_connect.h"
|
||||
#include "./server_p.h"
|
||||
#include "aqhome/ipc2/endpoint.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_connect.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* code
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void AQH_NodeServer_HandleConnect(GWEN_UNUSED AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg)
|
||||
{
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
AQH_MESSAGE *outMsg;
|
||||
int resultCode=AQH_MSGDATA_RESULT_SUCCESS;
|
||||
char *clientId=NULL;
|
||||
char *userId=NULL;
|
||||
char *passw=NULL;
|
||||
uint32_t flags;
|
||||
|
||||
tagList=AQH_IpcMessageTag16_ParsePayload(msg, 0);
|
||||
clientId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_CLIENTID, NULL);
|
||||
userId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_USERID, NULL);
|
||||
flags=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSG_CONNECT_TAGS_FLAGS, 0);
|
||||
passw=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_PASSWORD, NULL);
|
||||
|
||||
if (clientId)
|
||||
AQH_Endpoint_SetServiceName(ep, clientId);
|
||||
if (userId)
|
||||
AQH_Endpoint_SetUserName(ep, userId);
|
||||
|
||||
if (flags & AQH_MSG_CONNECT_FLAGS_WANTUPDATES)
|
||||
AQH_Endpoint_AddFlags(ep, AQH_ENDPOINT_FLAGS_WANTUPDATES);
|
||||
|
||||
/* TODO: add user management, for now we allow all */
|
||||
AQH_Endpoint_SetPermissions(ep,
|
||||
AQH_ENDPOINT_PERMS_LISTVALUES |
|
||||
AQH_ENDPOINT_PERMS_READVALUE |
|
||||
AQH_ENDPOINT_PERMS_ADDVALUE |
|
||||
AQH_ENDPOINT_PERMS_LISTDATA |
|
||||
AQH_ENDPOINT_PERMS_READDATA |
|
||||
AQH_ENDPOINT_PERMS_ADDDATA |
|
||||
AQH_ENDPOINT_PERMS_LISTDEVICES |
|
||||
AQH_ENDPOINT_PERMS_READDEVICE |
|
||||
AQH_ENDPOINT_PERMS_ADDDEVICE |
|
||||
AQH_ENDPOINT_PERMS_MODDEVICE);
|
||||
free(passw);
|
||||
free(userId);
|
||||
free(clientId);
|
||||
|
||||
outMsg=AQH_IpcMessageResult_new(AQH_IPC_PROTOCOL_NODES_ID,
|
||||
AQH_IPC_PROTOCOL_NODES_VERSION,
|
||||
AQH_MSGTYPE_IPC_NODES_RESULT,
|
||||
AQH_Endpoint_GetNextMessageId(ep),
|
||||
AQH_IpcMessage_GetMsgId(msg),
|
||||
resultCode, NULL);
|
||||
AQH_Endpoint_AddMsgOut(ep, outMsg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
27
apps/aqhome-nodes/r_connect.h
Normal file
27
apps/aqhome-nodes/r_connect.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/****************************************************************************
|
||||
* 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 AQHOMED_R_CONNECT_H
|
||||
#define AQHOMED_R_CONNECT_H
|
||||
|
||||
|
||||
#include "./server.h"
|
||||
|
||||
#include <gwenhywfar/request.h>
|
||||
|
||||
|
||||
|
||||
void AQH_NodeServer_HandleConnect(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *recvdMsg);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "./db.h"
|
||||
#include "./devicesread.h"
|
||||
#include "./r_setdata.h"
|
||||
#include "./r_connect.h"
|
||||
|
||||
#include <aqhome/aqhome.h>
|
||||
#include <aqhome/ipc2/ipc_endpoint.h>
|
||||
@@ -27,8 +28,11 @@
|
||||
#include <aqhome/ipc2/ipc_server.h>
|
||||
#include <aqhome/msg/ipc/m_ipc.h>
|
||||
#include <aqhome/msg/ipc/m_ipc_result.h>
|
||||
#include <aqhome/msg/ipc/m_ipc_connect.h>
|
||||
#include <aqhome/msg/ipc/data/m_ipcd.h>
|
||||
#include <aqhome/msg/ipc/data/m_ipcd_multidata.h>
|
||||
#include <aqhome/msg/ipc/nodes/m_ipcn.h>
|
||||
#include <aqhome/msg/ipc/nodes/m_ipcn_forward.h>
|
||||
#include <aqhome/msg/node/m_node.h>
|
||||
#include <aqhome/msg/node/m_value.h>
|
||||
#include <aqhome/msg/node/m_recvstats.h>
|
||||
@@ -94,6 +98,7 @@ static int readIntConfigWithAlt(GWEN_DB_NODE *dbArgs, const char *varName, const
|
||||
static int _startIpc(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
||||
static int _startTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
||||
static int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
||||
static int _exchangeConnect(AQH_OBJECT *o, AQH_NODE_SERVER *xo, uint32_t flags);
|
||||
static void _setupDb(AQH_NODE_SERVER *xo);
|
||||
static int _loadDeviceList(AQH_NODE_SERVER *xo);
|
||||
|
||||
@@ -109,9 +114,10 @@ static void _handleMsgFromClient(AQH_OBJECT *o, AQH_NODE_SERVER *xo, AQH_OBJECT
|
||||
static void _handleMsgFromTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _writeTtyMsgToLogFile(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _forwardTtyMsgToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _forwardValueMessage(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _forwardDataFromSendStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _forwardDataFromRecvStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _forwardValueMessageToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _forwardDataFromSendStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _forwardDataFromRecvStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _forwardTtyMsgToClients(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||
static void _publishInt(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, int v);
|
||||
static void _publishDouble(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, double v);
|
||||
static void _setDeviceName(AQH_VALUE *value, uint32_t uid);
|
||||
@@ -562,14 +568,7 @@ int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo)
|
||||
AQH_Object_AddLink(ep, AQH_ENDPOINT_SIGNAL_CLOSED, AQH_NODE_SERVER_SLOT_BROKERCLOSED, o);
|
||||
AQH_Object_Enable(ep);
|
||||
|
||||
rv=AQH_IpcEndpoint_ExchangeConnectMsg(ep,
|
||||
AQH_MSGTYPE_IPC_DATA_CONNECT_REQ,
|
||||
AQH_MSGTYPE_IPC_DATA_RESULT,
|
||||
xo->brokerClientId,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
xo->timeoutInSeconds);
|
||||
rv=_exchangeConnect(o, xo, 0);
|
||||
if (rv!=0) {
|
||||
DBG_ERROR(NULL, "Error connecting to broker: %d", rv);
|
||||
return (rv<0)?rv:GWEN_ERROR_PERMISSIONS;
|
||||
@@ -588,6 +587,24 @@ int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo)
|
||||
|
||||
|
||||
|
||||
int _exchangeConnect(AQH_OBJECT *o, AQH_NODE_SERVER *xo, uint32_t flags)
|
||||
{
|
||||
AQH_MESSAGE *msgOut;
|
||||
uint32_t msgId;
|
||||
|
||||
msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint);
|
||||
msgOut=AQH_IpcMessageConnect_new(xo->protoId, xo->protoVer,
|
||||
AQH_MSGTYPE_IPC_CONNECT_REQ,
|
||||
msgId, 0,
|
||||
xo->brokerClientId, NULL, NULL, flags);
|
||||
AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut);
|
||||
return AQH_IpcEndpoint_WaitForResultMsg(xo->ipcEndpoint,
|
||||
xo->protoId, xo->protoVer, AQH_MSGTYPE_IPC_RESULT,
|
||||
msgId, xo->timeoutInSeconds);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _setupDb(AQH_NODE_SERVER *xo)
|
||||
{
|
||||
if (xo->dbFile) {
|
||||
@@ -700,6 +717,7 @@ void _handleMsgFromClient(GWEN_UNUSED AQH_OBJECT *o, GWEN_UNUSED AQH_NODE_SERVER
|
||||
if (protoId==AQH_IPC_PROTOCOL_DATA_ID) {
|
||||
DBG_ERROR(NULL, "Received IPC packet %d (%x)", (int) code, code);
|
||||
switch(code) {
|
||||
case AQH_MSGTYPE_IPC_DATA_CONNECT_REQ: AQH_NodeServer_HandleConnect(o, ep, msg); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -745,6 +763,7 @@ void _handleMsgFromTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *ms
|
||||
AQH_NodeServer_NodeMsgToDb(o, msg);
|
||||
_writeTtyMsgToLogFile(xo, msg);
|
||||
_forwardTtyMsgToBroker(o, xo, msg);
|
||||
_forwardTtyMsgToClients(o, xo, msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -755,16 +774,44 @@ void _forwardTtyMsgToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAG
|
||||
|
||||
code=AQH_NodeMessage_GetMsgType(msg);
|
||||
switch(code) {
|
||||
case AQH_MSG_TYPE_VALUE_REPORT: _forwardValueMessage(o, xo, msg); break;
|
||||
case AQH_MSG_TYPE_COMSENDSTATS: _forwardDataFromSendStatsMessage(xo, msg); break;
|
||||
case AQH_MSG_TYPE_COMRECVSTATS: _forwardDataFromRecvStatsMessage(xo, msg); break;
|
||||
case AQH_MSG_TYPE_VALUE_REPORT: _forwardValueMessageToBroker(o, xo, msg); break;
|
||||
case AQH_MSG_TYPE_COMSENDSTATS: _forwardDataFromSendStatsMsgToBroker(xo, msg); break;
|
||||
case AQH_MSG_TYPE_COMRECVSTATS: _forwardDataFromRecvStatsMsgToBroker(xo, msg); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _forwardValueMessage(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
void _forwardTtyMsgToClients(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
uint8_t code;
|
||||
uint32_t msgGroup;
|
||||
|
||||
code=AQH_NodeMessage_GetMsgType(msg);
|
||||
msgGroup=AQH_NodeMessage_GetMsgGroup(code);
|
||||
if (msgGroup) {
|
||||
AQH_OBJECT *ep;
|
||||
|
||||
ep=AQH_Object_List_First(xo->ipcClientList);
|
||||
while(ep) {
|
||||
if (AQH_Endpoint_GetAcceptedMsgGroups(ep) & msgGroup) {
|
||||
AQH_MESSAGE *outMsg;
|
||||
|
||||
outMsg=AQH_IpcnMessageForward_new(AQH_MSGTYPE_IPC_NODES_FORWARD,
|
||||
AQH_Endpoint_GetNextMessageId(ep), 0,
|
||||
AQH_Message_GetMsgPointer(msg), AQH_Message_GetUsedSize(msg));
|
||||
AQH_Endpoint_AddMsgOut(ep, outMsg);
|
||||
}
|
||||
ep=AQH_Object_List_Next(ep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void _forwardValueMessageToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
uint8_t valueId;
|
||||
double v;
|
||||
@@ -790,7 +837,7 @@ void _forwardValueMessage(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE
|
||||
|
||||
|
||||
|
||||
void _forwardDataFromSendStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
void _forwardDataFromSendStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
uint16_t packetsOutInt;
|
||||
|
||||
@@ -820,7 +867,7 @@ void _forwardDataFromSendStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *ms
|
||||
|
||||
|
||||
|
||||
void _forwardDataFromRecvStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
void _forwardDataFromRecvStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||
{
|
||||
uint16_t packetsInInt;
|
||||
|
||||
|
||||
@@ -18,6 +18,22 @@
|
||||
|
||||
|
||||
|
||||
#define AQH_ENDPOINT_PERMS_LISTVALUES 0x0001
|
||||
#define AQH_ENDPOINT_PERMS_READVALUE 0x0002
|
||||
#define AQH_ENDPOINT_PERMS_ADDVALUE 0x0004
|
||||
|
||||
#define AQH_ENDPOINT_PERMS_LISTDATA 0x0010
|
||||
#define AQH_ENDPOINT_PERMS_READDATA 0x0020
|
||||
#define AQH_ENDPOINT_PERMS_ADDDATA 0x0040
|
||||
#define AQH_ENDPOINT_PERMS_SETDATA 0x0080
|
||||
|
||||
#define AQH_ENDPOINT_PERMS_LISTDEVICES 0x0100
|
||||
#define AQH_ENDPOINT_PERMS_READDEVICE 0x0200
|
||||
#define AQH_ENDPOINT_PERMS_ADDDEVICE 0x0400
|
||||
#define AQH_ENDPOINT_PERMS_MODDEVICE 0x0800
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT *AQH_NodeServer_new(AQH_EVENT_LOOP *eventLoop);
|
||||
int AQH_NodeServer_Init(AQH_OBJECT *o, int argc, char **argv);
|
||||
|
||||
|
||||
@@ -66,6 +66,10 @@ struct AQH_NODE_SERVER {
|
||||
struct termios initialTermiosState;
|
||||
|
||||
int timeoutInSeconds;
|
||||
|
||||
uint8_t protoId;
|
||||
uint8_t protoVer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user