diff --git a/apps/aqhome-nodes/loop.c b/apps/aqhome-nodes/loop.c index 369f0ad..5558184 100644 --- a/apps/aqhome-nodes/loop.c +++ b/apps/aqhome-nodes/loop.c @@ -18,6 +18,7 @@ #include "./aqhomed_p.h" #include "./tty_log.h" #include "./db.h" +#include "./requests.h" #include "aqhome/msg/endpoint_tty.h" #include "aqhome/msg/msg_node.h" @@ -64,6 +65,9 @@ void AqHomed_Loop(AQHOMED *aqh, int timeoutInMsecs) AqHomed_ReadAndHandleIpcMessages(aqh); AqHomed_ReadAndHandleBrokerMessages(aqh); + AqHomeNodes_Requests_CheckTimeouts(aqh); + AqHomeNodes_Requests_Cleanup(aqh); + #if 0 DBG_ERROR(NULL, "Messages in TTY queue: %d in, %d out", GWEN_Msg_List_GetCount(GWEN_MsgEndpoint_GetReceivedMessageList(aqh->ttyEndpoint)), diff --git a/apps/aqhome-nodes/loop_broker.c b/apps/aqhome-nodes/loop_broker.c index f777b3b..6aa58e3 100644 --- a/apps/aqhome-nodes/loop_broker.c +++ b/apps/aqhome-nodes/loop_broker.c @@ -16,6 +16,8 @@ #include "./b_setdata.h" #include "./tty_log.h" #include "./db.h" +#include "./requests.h" +#include "./r_setdata.h" #include "aqhome/msg/endpoint_tty.h" #include "aqhome/msg/msg_node.h" @@ -67,7 +69,8 @@ void AqHomed_ReadAndHandleBrokerMessages(AQHOMED *aqh) code=GWEN_IpcMsg_GetCode(msg); DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC packet %d (%x)", (int) code, code); - _handleIpcMsg(aqh, epTcp, msg); + if (AqHomeNodes_Requests_HandleIpcMsg(aqh, epTcp, msg)!=GWEN_MSG_REQUEST_RESULT_HANDLED) + _handleIpcMsg(aqh, epTcp, msg); GWEN_Msg_free(msg); } } @@ -83,7 +86,7 @@ void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg) code=GWEN_IpcMsg_GetCode(msg); DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC packet"); switch(code) { -// case AQH_MSGTYPE_IPC_DATA_SETDATA: AqHomeNodes_HandleBrokerSetData(aqh, ep, msg); break; + case AQH_MSGTYPE_IPC_DATA_SETDATA: AqHomeNodes_HandleSetData(aqh, ep, msg); break; default: break; } } diff --git a/apps/aqhome-nodes/loop_ipc.c b/apps/aqhome-nodes/loop_ipc.c index 5278953..caf1a09 100644 --- a/apps/aqhome-nodes/loop_ipc.c +++ b/apps/aqhome-nodes/loop_ipc.c @@ -15,6 +15,8 @@ #include "./aqhomed_p.h" #include "./tty_log.h" #include "./db.h" +#include "./requests.h" +#include "./r_setdata.h" #include "aqhome/msg/endpoint_tty.h" #include "aqhome/msg/msg_node.h" @@ -62,9 +64,6 @@ 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); @@ -94,7 +93,8 @@ void _handleIpcEndpoint(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep) GWEN_MSG *msg; while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) { - _handleIpcMsg(aqh, ep, msg); + if (AqHomeNodes_Requests_HandleIpcMsg(aqh, ep, msg)!=GWEN_MSG_REQUEST_RESULT_HANDLED) + _handleIpcMsg(aqh, ep, msg); GWEN_Msg_free(msg); } } @@ -113,7 +113,7 @@ void _handleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg) 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; +// case AQH_MSGTYPE_IPC_DATA_SETDATA: AqHomeNodes_HandleNodeSetData(aqh, ep, msg); break; default: break; } } @@ -195,103 +195,3 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_ -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; -} - - - - - - diff --git a/apps/aqhome-nodes/loop_tty.c b/apps/aqhome-nodes/loop_tty.c index 2897091..aa48728 100644 --- a/apps/aqhome-nodes/loop_tty.c +++ b/apps/aqhome-nodes/loop_tty.c @@ -17,6 +17,7 @@ #include "./aqhomed_p.h" #include "./tty_log.h" #include "./db.h" +#include "./requests.h" #include "aqhome/msg/endpoint_tty.h" #include "aqhome/msg/msg_node.h" @@ -63,6 +64,7 @@ void AqHomed_ReadAndHandleTtyMessages(AQHOMED *aqh) while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(aqh->ttyEndpoint)) ) { _handleTtyMsg(aqh, msg); + AqHomeNodes_Requests_HandleTtyMsg(aqh, aqh->ttyEndpoint, msg); GWEN_Msg_free(msg); } } diff --git a/apps/aqhome-nodes/n_setdata.c b/apps/aqhome-nodes/n_setdata.c deleted file mode 100644 index 01e5286..0000000 --- a/apps/aqhome-nodes/n_setdata.c +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2024 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 -#endif - - -#include "./n_setdata.h" -#include "./aqhomed_p.h" -#include "./r_setdata.h" - -#include "aqhome/data/value.h" -#include "aqhome/ipc/data/msg_data_set.h" -#include "aqhome/ipc/data/ipc_data.h" -#include "aqhome/ipc/msg_ipc_result.h" -#include "aqhome/ipc/endpoint_ipc.h" - -#include - - - -/* ------------------------------------------------------------------------------------------------ - * defines - * ------------------------------------------------------------------------------------------------ - */ - - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static int _readDataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom); -static AQH_NODE_INFO *_getNodeInfoFromValue(AQHOMED *aqh, const AQH_VALUE *value); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - -void AqHomeNodes_HandleNodeSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *recvdMsg) -{ - uint32_t msgId; - - DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC SetDataRequest message"); - msgId=GWEN_IpcMsg_GetMsgId(recvdMsg); - - if (aqh->ttyEndpoint && GWEN_MsgEndpoint_GetState(aqh->ttyEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) { - AQH_VALUE *value; - - AQH_SetDataIpcMsg_Parse(recvdMsg, 0); - value=AQH_SetDataIpcMsg_ReadValue(recvdMsg); - if (value) { - char *data; - - data=AQH_SetDataIpcMsg_ReadData(recvdMsg); - 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_REQUEST *rq; - int destAddr; - - destAddr=AQH_NodeInfo_GetBusAddress(nodeInfo); - - rq=AqHomeNodes_MkRequest_SetData(aqh, ep, msgId, destAddr, valueId, dataVal, dataDenom); - AqHomed_AddRequestToTree(aqh, rq); - /* done */ - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid value id \"%s\"", s); - AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_INVALID); - } - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "No matching node found"); - AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_NOTFOUND); - } - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Bad data \"%s\"", data); - AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_BADDATA); - } - free(data); - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "No data"); - AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_NODATA); - } - AQH_Value_free(value); - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Could not read value from message"); - } - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "TTY endpoint not connected"); - AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_IO); - } -} - - - -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; -} - - diff --git a/apps/aqhome-nodes/n_setdata.h b/apps/aqhome-nodes/n_setdata.h deleted file mode 100644 index e705750..0000000 --- a/apps/aqhome-nodes/n_setdata.h +++ /dev/null @@ -1,26 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2024 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_N_SETDATA_H -#define AQHOMED_N_SETDATA_H - - -#include "./aqhomed.h" - -#include - - - -void AqHomeNodes_HandleNodeSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *recvdMsg); - - - - -#endif - - diff --git a/apps/aqhome-nodes/r_setdata.c b/apps/aqhome-nodes/r_setdata.c index a721ae7..d5c8fd1 100644 --- a/apps/aqhome-nodes/r_setdata.c +++ b/apps/aqhome-nodes/r_setdata.c @@ -14,6 +14,7 @@ #include "./r_setdata.h" #include "./aqhomed_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" @@ -39,6 +40,12 @@ * ------------------------------------------------------------------------------------------------ */ +static AQH_NODE_INFO *_getNodeInfoFromValue(AQHOMED *aqh, 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 void _rqSubRequestFinished(GWEN_MSG_REQUEST *rq, GWEN_MSG_REQUEST *subRq, int reason); static void _rqAbort(GWEN_MSG_REQUEST *rq); @@ -53,9 +60,115 @@ static void _subRqAbort(GWEN_MSG_REQUEST *rq); * ------------------------------------------------------------------------------------------------ */ -GWEN_MSG_REQUEST *AqHomeNodes_MkRequest_SetData(AQHOMED *aqh, - GWEN_MSG_ENDPOINT *ep, uint32_t requestMsgId, - int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom) + +void AqHomeNodes_HandleSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *recvdMsg) +{ + uint32_t msgId; + + DBG_ERROR(AQH_LOGDOMAIN, "Received IPC SetDataRequest message"); + msgId=GWEN_IpcMsg_GetMsgId(recvdMsg); + + if (aqh->ttyEndpoint && GWEN_MsgEndpoint_GetState(aqh->ttyEndpoint)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) { + AQH_VALUE *value; + + AQH_SetDataIpcMsg_Parse(recvdMsg, 0); + value=AQH_SetDataIpcMsg_ReadValue(recvdMsg); + if (value) { + const char *varName; + + varName=AQH_Value_GetName(value); + if (varName) { + char *data; + + data=AQH_SetDataIpcMsg_ReadData(recvdMsg); + if (data) { + AQH_NODE_INFO *nodeInfo; + + nodeInfo=_getNodeInfoFromValue(aqh, value); + if (nodeInfo) { + const char *devName; + + devName=AQH_NodeInfo_GetDeviceId(nodeInfo); + if (devName) { + const AQHNODE_DEVICE *devInfo; + + devInfo=AqHomed_GetDeviceDefByName(aqh, 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; + + if (AQH_ReadDataFromString(AQHNODE_Value_GetDataType(devValue), data, &dataVal, &dataDenom)==0) { + GWEN_MSG_REQUEST *rq; + int destAddr; + + destAddr=AQH_NodeInfo_GetBusAddress(nodeInfo); + DBG_ERROR(NULL, "Creating SETDATA request"); + + rq=_mkRequest_SetData(aqh, ep, msgId, destAddr, AQHNODE_Value_GetId(devValue), dataVal, dataDenom); + AqHomed_AddRequestToTree(aqh, rq); + /* done */ + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "Bad data \"%s\"", data); + AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_BADDATA); + } + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "Invalid value name \"%s\"", varName); + AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_INVALID); + } + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "Unknown node \"%s\"", devName); + AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_INVALID); + } + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "Node not yet fully identified, come back later"); + AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_TRYAGAIN); + } + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "No matching nodeinfo"); + AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_INVALID); + } + free(data); + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "No data"); + AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_NODATA); + } + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "No var name"); + AQH_IpcEndpoint_SendResponseResult(ep, msgId, AQH_MSGTYPE_IPC_DATA_RESULT, AQH_MSG_IPC_ERROR_NODATA); + } + AQH_Value_free(value); + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "Could not read value from message"); + } + } + else { + DBG_ERROR(AQH_LOGDOMAIN, "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) { GWEN_MSG_REQUEST *rq; GWEN_MSG_REQUEST *subRq; @@ -82,7 +195,7 @@ void _rqSubRequestFinished(GWEN_MSG_REQUEST *rq, GWEN_MSG_REQUEST *subRq, int re uint32_t refMsgId; int result; - DBG_INFO(NULL, "SubRequest finished"); + DBG_ERROR(NULL, "SubRequest finished (reason: %d)", reason); refMsgId=GWEN_MsgRequest_GetRequestMsgId(rq); ep=GWEN_MsgRequest_GetEndpoint(rq); result=GWEN_MsgRequest_GetResult(subRq); @@ -120,6 +233,9 @@ void _rqAbort(GWEN_MSG_REQUEST *rq) +/* ------------------------------------------------------------------------------------------------ + * TTY Request SETDATA + */ GWEN_MSG_REQUEST *_mkSubRequest_SetData(AQHOMED *aqh, int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom) @@ -152,7 +268,7 @@ int _subRqHandleResponse(GWEN_MSG_REQUEST *rq, GWEN_MSG *msg) AQHOMED *aqh; uint8_t destAddr; - DBG_DEBUG(NULL, "Checking message from %02x", AQH_NodeMsg_GetSourceAddress(msg)); + DBG_ERROR(NULL, "Checking message from %02x", AQH_NodeMsg_GetSourceAddress(msg)); aqh=(AQHOMED*)GWEN_MsgRequest_GetPrivateData(rq); destAddr=AQH_NodeMsg_GetDestAddress(msg); @@ -167,9 +283,9 @@ int _subRqHandleResponse(GWEN_MSG_REQUEST *rq, GWEN_MSG *msg) if (msgId==GWEN_MsgRequest_GetRequestMsgId(rq)) { GWEN_MSG_REQUEST *rqParent; - DBG_INFO(NULL, - "Received response (%02x) for msg id %04x from %02x", - msgCode, msgId, AQH_NodeMsg_GetSourceAddress(msg)); + DBG_ERROR(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); @@ -178,11 +294,11 @@ int _subRqHandleResponse(GWEN_MSG_REQUEST *rq, GWEN_MSG *msg) return GWEN_MSG_REQUEST_RESULT_HANDLED; } else { - DBG_DEBUG(NULL, " Non-matching message id"); + DBG_ERROR(NULL, " Non-matching message id"); } } else { - DBG_DEBUG(NULL, " Non-matching message code"); + DBG_ERROR(NULL, " Non-matching message code"); } } return GWEN_MSG_REQUEST_RESULT_NOT_HANDLED; @@ -194,7 +310,7 @@ void _subRqAbort(GWEN_MSG_REQUEST *rq) { GWEN_MSG_REQUEST *rqParent; - DBG_INFO(NULL, "Aborting request"); + DBG_ERROR(NULL, "Aborting request"); GWEN_MsgRequest_SetResult(rq, AQH_MSG_IPC_ERROR_GENERIC); GWEN_MsgRequest_SetState(rq, GWEN_MSG_REQUEST_STATE_DONE); @@ -206,4 +322,23 @@ void _subRqAbort(GWEN_MSG_REQUEST *rq) +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; +} + diff --git a/apps/aqhome-nodes/r_setdata.h b/apps/aqhome-nodes/r_setdata.h index e829f9c..26f6cf5 100644 --- a/apps/aqhome-nodes/r_setdata.h +++ b/apps/aqhome-nodes/r_setdata.h @@ -16,9 +16,8 @@ -GWEN_MSG_REQUEST *AqHomeNodes_MkRequest_SetData(AQHOMED *aqh, - GWEN_MSG_ENDPOINT *ep, uint32_t requestMsgId, - int destAddr, int valueId, uint16_t dataVal, uint16_t dataDenom); +void AqHomeNodes_HandleSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *recvdMsg); + diff --git a/apps/aqhome-nodes/requests.c b/apps/aqhome-nodes/requests.c index 6cf6d4b..bdbd00c 100644 --- a/apps/aqhome-nodes/requests.c +++ b/apps/aqhome-nodes/requests.c @@ -131,8 +131,10 @@ void _freeFinishedRequests(GWEN_MSG_REQUEST *rq) subRq=nextSubRq; } - if (GWEN_MsgRequest_GetState(rq)==GWEN_MSG_REQUEST_STATE_DONE) + if (GWEN_MsgRequest_GetState(rq)==GWEN_MSG_REQUEST_STATE_DONE) { + DBG_ERROR(NULL, "Deleting request"); GWEN_MsgRequest_free(rq); + } } diff --git a/aqhome/aqhome.c b/aqhome/aqhome.c index 32eed16..7679d84 100644 --- a/aqhome/aqhome.c +++ b/aqhome/aqhome.c @@ -43,6 +43,9 @@ static void _definePath(const char *pathName, const char *pathValue); static GWEN_STRINGLIST *_getListOfMatchingFiles(const char *pathName, const char *subFolder, const char *mask); static GWEN_BUFFER *_getRuntimeFilePath(const char *pathName, const char *sFilename); static GWEN_BUFFER *_findFileinPath(const char *pathName, const char *sFilename); +static int _readUint8DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom); +static int _readUint16DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom); +static int _readUint32DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom); @@ -213,9 +216,15 @@ int AQH_ValueDataType_fromString(const char *s) if (strcasecmp(s, "int")==0) return AQH_ValueDataType_Int; else if (strcasecmp(s, "dword")==0) - return AQH_ValueDataType_Dword; + return AQH_ValueDataType_Uint32; else if (strcasecmp(s, "rational")==0) return AQH_ValueDataType_Rational; + else if (strcasecmp(s, "AQH_ValueDataType_Uint8")==0) + return AQH_ValueDataType_Uint8; + else if (strcasecmp(s, "AQH_ValueDataType_Uint16")==0) + return AQH_ValueDataType_Uint16; + else if (strcasecmp(s, "AQH_ValueDataType_Uint32")==0) + return AQH_ValueDataType_Uint32; } return AQH_ValueDataType_Unknown; } @@ -226,8 +235,10 @@ const char *AQH_ValueDataType_toString(int i) { switch(i) { case AQH_ValueDataType_Int: return "int"; - case AQH_ValueDataType_Dword: return "dword"; case AQH_ValueDataType_Rational: return "rational"; + case AQH_ValueDataType_Uint8: return "uint8"; + case AQH_ValueDataType_Uint16: return "uint16"; + case AQH_ValueDataType_Uint32: return "uint32"; case AQH_ValueDataType_Unknown: default: return "unknown"; } @@ -437,3 +448,65 @@ GWEN_BUFFER *_findFileinPath(const char *pathName, const char *sFilename) +int AQH_ReadDataFromString(int dataType, const char *s, uint16_t *pDataVal, uint16_t *pDataDenom) +{ + if (s && *s) { + switch(dataType) { + case AQH_ValueDataType_Int: + + case AQH_ValueDataType_Uint8: return _readUint8DataFromString(s, pDataVal, pDataDenom); + case AQH_ValueDataType_Uint16: return _readUint16DataFromString(s, pDataVal, pDataDenom); + case AQH_ValueDataType_Uint32: return _readUint32DataFromString(s, pDataVal, pDataDenom); + case AQH_ValueDataType_Rational: break; + default: break; + } + } + + return GWEN_ERROR_INVALID; +} + + + +int _readUint8DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom) +{ + unsigned int v=0; + + if (1==sscanf(s, "%i", &v)) { + *pDataVal=v & 0xff; + *pDataDenom=1; + return 0; + } + return GWEN_ERROR_INVALID; +} + + + +int _readUint16DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom) +{ + unsigned int v=0; + + if (1==sscanf(s, "%i", &v)) { + *pDataVal=v & 0xffff; + *pDataDenom=1; + return 0; + } + return GWEN_ERROR_INVALID; +} + + + +int _readUint32DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom) +{ + unsigned long int v=0; + + if (1==sscanf(s, "%li", &v)) { + *pDataVal=(v>>16) & 0xffff; + *pDataDenom=v & 0xffff; + return 0; + } + return GWEN_ERROR_INVALID; +} + + + + diff --git a/aqhome/aqhome.h b/aqhome/aqhome.h index ccf49ca..9c49f83 100644 --- a/aqhome/aqhome.h +++ b/aqhome/aqhome.h @@ -27,8 +27,11 @@ enum { enum { AQH_ValueDataType_Unknown=0, AQH_ValueDataType_Int, - AQH_ValueDataType_Dword, - AQH_ValueDataType_Rational + AQH_ValueDataType_Rational, + AQH_ValueDataType_Uint8, + AQH_ValueDataType_Uint16, + AQH_ValueDataType_Uint32 + }; @@ -73,6 +76,7 @@ AQHOME_API const char *AQH_ValueDataType_toString(int i); AQHOME_API int AQH_ValueModality_fromString(const char *s); AQHOME_API const char *AQH_ValueModality_toString(int i); +AQHOME_API int AQH_ReadDataFromString(int dataType, const char *s, uint16_t *pDataVal, uint16_t *pDataDenom); #endif diff --git a/aqhome/ipc/endpoint_ipc.c b/aqhome/ipc/endpoint_ipc.c index 486d225..94ecf65 100644 --- a/aqhome/ipc/endpoint_ipc.c +++ b/aqhome/ipc/endpoint_ipc.c @@ -264,12 +264,14 @@ GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, void AQH_IpcEndpoint_SendResponseResult(GWEN_MSG_ENDPOINT *ep, uint32_t refMsgId, uint16_t code, uint32_t resultCode) { - GWEN_MSG *msgOut; - uint32_t msgId; + if (ep) { + GWEN_MSG *msgOut; + uint32_t msgId; - msgId=GWEN_MsgEndpoint_GetNextMessageId(ep); - msgOut=AQH_ResultIpcMsg_new(code, msgId, refMsgId, resultCode); - GWEN_MsgEndpoint_AddSendMessage(ep, msgOut); + msgId=GWEN_MsgEndpoint_GetNextMessageId(ep); + msgOut=AQH_ResultIpcMsg_new(code, msgId, refMsgId, resultCode); + GWEN_MsgEndpoint_AddSendMessage(ep, msgOut); + } } diff --git a/aqhome/ipc/msg_ipc_result.c b/aqhome/ipc/msg_ipc_result.c index beacc8c..87299d9 100644 --- a/aqhome/ipc/msg_ipc_result.c +++ b/aqhome/ipc/msg_ipc_result.c @@ -11,6 +11,7 @@ #endif #include +#include #include #include @@ -35,9 +36,8 @@ GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t resultCode) { GWEN_MSG *msg; - uint8_t *ptr; - msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_RESULT_ID, AQH_IPC_PROTOCOL_RESULT_VERSION, code, + msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, AQH_MSGIPC_RESULT_PAYLOADSIZE, NULL); GWEN_Msg_AddUint32(msg, resultCode); @@ -59,7 +59,8 @@ void AQH_ResultIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const { if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_RESULT_MINSIZE) { GWEN_Buffer_AppendArgs(dbuf, - "ERROR (code=%d, proto=%d, proto version=%d, error=%d, msgId=%d, refMsgId=%d)\n", + "ERROR %s (code=%d, proto=%d, proto version=%d, error=%d, msgId=%d, refMsgId=%d)\n", + sText?sText:"", GWEN_IpcMsg_GetCode(msg), GWEN_IpcMsg_GetProtoId(msg), GWEN_IpcMsg_GetProtoVersion(msg), diff --git a/aqhome/ipc/msg_ipc_result.h b/aqhome/ipc/msg_ipc_result.h index 9d54b6f..9fa685c 100644 --- a/aqhome/ipc/msg_ipc_result.h +++ b/aqhome/ipc/msg_ipc_result.h @@ -31,6 +31,7 @@ #define AQH_MSG_IPC_ERROR_PERMS 6 #define AQH_MSG_IPC_ERROR_NOTFOUND 7 #define AQH_MSG_IPC_ERROR_IO 8 +#define AQH_MSG_IPC_ERROR_TRYAGAIN 9 AQHOME_API GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t resultCode);