aqhome-nodes: re-implemented setdata request received via broker.
This commit is contained in:
@@ -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)),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <config.h>
|
||||
#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 <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <gwenhywfar/request.h>
|
||||
|
||||
|
||||
|
||||
void AqHomeNodes_HandleNodeSetData(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *recvdMsg);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user