aqhome-nodes: re-implemented setdata request received via broker.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user