aqhome-nodes: re-implemented setdata request received via broker.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#endif
|
||||
|
||||
#include <aqhome/ipc/msg_ipc_result.h>
|
||||
#include <aqhome/ipc/data/ipc_data.h>
|
||||
|
||||
#include <gwenhywfar/msg.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user