adapted to latest changes in gwen, more work on data and nodes servers.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "aqhome/msg/endpoint_tty.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
#include "aqhome/msg/msg_value2.h"
|
||||
#include "aqhome/msg/msg_value3.h"
|
||||
#include "aqhome/msg/msg_ping.h"
|
||||
#include "aqhome/ipc/endpoint_ipc.h"
|
||||
#include "aqhome/ipc/nodes/ipc_nodes.h"
|
||||
@@ -27,6 +28,8 @@
|
||||
#include "aqhome/ipc/nodes/msg_ipc_ping.h"
|
||||
#include "aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h"
|
||||
#include "aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/ipc/data/msg_data_set.h"
|
||||
#include "aqhome/ipc/msg_ipc_result.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
@@ -34,6 +37,8 @@
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endpoint_tcpd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -52,11 +57,14 @@
|
||||
*/
|
||||
|
||||
static void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep);
|
||||
static void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
|
||||
static void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
|
||||
void _handleIpcMsgPing(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
|
||||
void _handleIpcMsgSetAccMsgGrps(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
|
||||
void _handleIpcMsgForward(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
|
||||
void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
|
||||
void _handleIpcMsgSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
|
||||
static int _readDataFromString(const char *s, uint16_t *pDataVal, uint16_t *pValDenom);
|
||||
static AQH_NODE_INFO *_getNodeInfoFromValue(AQHOMED *aqh, const AQH_VALUE *value);
|
||||
|
||||
|
||||
|
||||
@@ -93,18 +101,19 @@ void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep)
|
||||
|
||||
|
||||
|
||||
void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
|
||||
void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg)
|
||||
{
|
||||
uint16_t code;
|
||||
|
||||
/* exec IPC message */
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC packet");
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Received IPC packet (%d, %04x)", code, code);
|
||||
switch(code) {
|
||||
case AQH_MSGTYPE_IPC_NODES_PING: _handleIpcMsgPing(aqh, ep, msg); break;
|
||||
case AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS: _handleIpcMsgSetAccMsgGrps(aqh, ep, msg); break;
|
||||
case AQH_MSGTYPE_IPC_NODES_FORWARD: _handleIpcMsgForward(aqh, ep, msg); break;
|
||||
case AQH_MSGTYPE_IPC_NODES_GETDEVICES_REQ: _handleIpcMsgGetDevicesReq(aqh, ep, msg); break;
|
||||
case AQH_MSGTYPE_IPC_DATA_SETDATA: _handleIpcMsgSetData(aqh, ep, msg); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -128,7 +137,7 @@ void _handleIpcMsgSetAccMsgGrps(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_
|
||||
{
|
||||
uint32_t groups;
|
||||
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC SET_ACCEPTED_MSG_GROUPS message");
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Received IPC SET_ACCEPTED_MSG_GROUPS message");
|
||||
groups=AQH_SetAcceptedMsgGroupsIpcMsg_GetMsgGroups(msg);
|
||||
AQH_IpcEndpoint_SetAcceptedMsgGroups(ep, groups);
|
||||
// TODO: send response?
|
||||
@@ -154,7 +163,7 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_
|
||||
{
|
||||
AQH_NODE_INFO_LIST *nodeInfoList;
|
||||
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC GetDevicesRequest message");
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Received IPC GetDevicesRequest message");
|
||||
nodeInfoList=AQH_NodeDb_GetAllNodeInfos(aqh->nodeDb);
|
||||
if (nodeInfoList && AQH_NodeInfo_List_GetCount(nodeInfoList)) {
|
||||
const AQH_NODE_INFO *ni;
|
||||
@@ -166,7 +175,9 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_
|
||||
|
||||
niNext=AQH_NodeInfo_List_Next(ni);
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Sending response for node %02x (%08x)", AQH_NodeInfo_GetBusAddress(ni), AQH_NodeInfo_GetUid(ni));
|
||||
msgOut=AQH_GetDevicesResponseIpcMsg_new(AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP, niNext?0:AQH_MSGIPC_GETDEVICES_RSP_FLAGS_LAST, ni);
|
||||
msgOut=AQH_GetDevicesResponseIpcMsg_new(AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP,
|
||||
GWEN_MsgEndpoint_GetNextMessageId(ep), GWEN_IpcMsg_GetMsgId(msg),
|
||||
niNext?0:AQH_MSGIPC_GETDEVICES_RSP_FLAGS_LAST, ni);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, msgOut);
|
||||
ni=niNext;
|
||||
}
|
||||
@@ -175,13 +186,112 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "No nodes");
|
||||
msgOut=AQH_ResultIpcMsg_new(AQH_MSGTYPE_IPC_NODES_RESULT, AQH_MSG_IPC_ERROR_NODATA);
|
||||
msgOut=AQH_ResultIpcMsg_new(AQH_MSGTYPE_IPC_NODES_RESULT,
|
||||
GWEN_MsgEndpoint_GetNextMessageId(ep), GWEN_IpcMsg_GetMsgId(msg),
|
||||
AQH_MSG_IPC_ERROR_NODATA);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, msgOut);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleIpcMsgSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg)
|
||||
{
|
||||
if (aqh->ttyEndpoint && GWEN_MsgEndpoint_GetState(aqh->ttyEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
|
||||
AQH_VALUE *value;
|
||||
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC SetDataRequest message");
|
||||
AQH_SetDataIpcMsg_Parse(msg, 0);
|
||||
value=AQH_SetDataIpcMsg_ReadValue(msg);
|
||||
if (value) {
|
||||
char *data;
|
||||
|
||||
data=AQH_SetDataIpcMsg_ReadData(msg);
|
||||
if (data) {
|
||||
uint16_t dataVal=0;
|
||||
uint16_t dataDenom=0;
|
||||
|
||||
if (_readDataFromString(data, &dataVal, &dataDenom)==0) {
|
||||
AQH_NODE_INFO *nodeInfo;
|
||||
|
||||
nodeInfo=_getNodeInfoFromValue(aqh, value);
|
||||
if (nodeInfo) {
|
||||
int valueId=0;
|
||||
const char *s;
|
||||
|
||||
s=AQH_Value_GetName(value);
|
||||
if (s && *s && 1==sscanf(s, "%d", &valueId)) {
|
||||
GWEN_MSG *msgOut;
|
||||
int destAddr;
|
||||
|
||||
destAddr=AQH_NodeInfo_GetBusAddress(nodeInfo);
|
||||
msgOut=AQH_Value3Msg_new(aqh->nodeAddress, destAddr, AQH_MSG_TYPE_VALUE_SET, 0 /* msgid*/, valueId, dataVal, dataDenom);
|
||||
GWEN_MsgEndpoint_AddSendMessage(aqh->ttyEndpoint, msgOut);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Invalid value id \"%s\"", s);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "No matching node found");
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
}
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Could not read value from message");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _readDataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom)
|
||||
{
|
||||
if (s && *s) {
|
||||
if (*s=='&') {
|
||||
unsigned long int v=0;
|
||||
|
||||
s++;
|
||||
if (1==sscanf(s, "%lx", &v)) {
|
||||
*pDataVal=(v>>16) & 0xffff;
|
||||
*pDataDenom=v & 0xffff;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Bad hex value \"%s\"", s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_NODE_INFO *_getNodeInfoFromValue(AQHOMED *aqh, const AQH_VALUE *value)
|
||||
{
|
||||
const char *s;
|
||||
unsigned long int uid;
|
||||
|
||||
s=AQH_Value_GetDeviceName(value);
|
||||
if (s && *s && 1==sscanf(s, "%lx", &uid)) {
|
||||
AQH_NODE_INFO *ni;
|
||||
|
||||
ni=AQH_NodeDb_GetNodeInfoByUid(aqh->nodeDb, uid);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Node \"%08lx\" not found", uid);
|
||||
return NULL;
|
||||
}
|
||||
return ni;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user