Compare commits
119 Commits
mp-2023_08
...
mp-2025_01
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bebc4c1b0d | ||
|
|
8968f14122 | ||
|
|
f63079af11 | ||
|
|
cf8edbbd5f | ||
|
|
f1f24168e5 | ||
|
|
d5d6217c5e | ||
|
|
b60de3994c | ||
|
|
6e25647c0a | ||
|
|
a7990db831 | ||
|
|
bf61be029e | ||
|
|
c5ab06b6d0 | ||
|
|
bcc7194254 | ||
|
|
2a776ca895 | ||
|
|
35f2c2bd7e | ||
|
|
393d4b4f56 | ||
|
|
4339a8e80b | ||
|
|
351ab57d62 | ||
|
|
0790ac0dea | ||
|
|
358ceaaa7d | ||
|
|
50ba9ee3a1 | ||
|
|
703f8042f9 | ||
|
|
601559ca6e | ||
|
|
a36639ed8c | ||
|
|
224a5f336a | ||
|
|
9719063a21 | ||
|
|
dbe23f7e73 | ||
|
|
702acb3304 | ||
|
|
cc8dd6e22f | ||
|
|
bb73225b86 | ||
|
|
31ca7ae529 | ||
|
|
64e781f82f | ||
|
|
2d259ae9be | ||
|
|
b38d864612 | ||
|
|
52bbfcfb15 | ||
|
|
a96bd7fc07 | ||
|
|
7962ff6213 | ||
|
|
e840bfd9e6 | ||
|
|
779b37f195 | ||
|
|
dfbc10149c | ||
|
|
22a5402141 | ||
|
|
19af9daea7 | ||
|
|
0a10d136d5 | ||
|
|
0d7aca0060 | ||
|
|
7d33e451cd | ||
|
|
d631c5465f | ||
|
|
ecb2d85ea2 | ||
|
|
c390b1059c | ||
|
|
ba279ae2bb | ||
|
|
30a2743f19 | ||
|
|
46d939fa31 | ||
|
|
f2aff6c235 | ||
|
|
e97a5c0720 | ||
|
|
6dd9a3ba8f | ||
|
|
1775fb7785 | ||
|
|
a639316cdf | ||
|
|
87706e1265 | ||
|
|
fff64ae41e | ||
|
|
3633bb03fc | ||
|
|
172998a5c4 | ||
|
|
acbe4505b9 | ||
|
|
b2193afa46 | ||
|
|
28b130ecd4 | ||
|
|
2ac1182879 | ||
|
|
f2d18fceee | ||
|
|
43c23d754c | ||
|
|
8eee81c682 | ||
|
|
34d395bb0b | ||
|
|
277af02f68 | ||
|
|
68ef24ea9b | ||
|
|
a3d5b33105 | ||
|
|
a7adf15bf6 | ||
|
|
a435b995a8 | ||
|
|
9d71ff27a7 | ||
|
|
090e178ed1 | ||
|
|
a78e354c28 | ||
|
|
9c87c3e5f3 | ||
|
|
01133cc35b | ||
|
|
4dc6031d03 | ||
|
|
c3fd458769 | ||
|
|
433720525d | ||
|
|
375ab592ff | ||
|
|
d2694df67c | ||
|
|
2270163837 | ||
|
|
9282ac3bb2 | ||
|
|
6f858e3909 | ||
|
|
cf26a01bb8 | ||
|
|
2e3705946e | ||
|
|
42f76f9d09 | ||
|
|
bc7a549513 | ||
|
|
f002587aee | ||
|
|
a520b37089 | ||
|
|
4f628a16c6 | ||
|
|
630dc2cecb | ||
|
|
51a585740d | ||
|
|
dab4980a7a | ||
|
|
e847130f0c | ||
|
|
4c88c15874 | ||
|
|
132ec3ce95 | ||
|
|
9178a6fca5 | ||
|
|
eb68e66746 | ||
|
|
b72d474a7f | ||
|
|
2b68bfd3af | ||
|
|
e4a0e8557a | ||
|
|
57bbefdf38 | ||
|
|
7707cb0a82 | ||
|
|
dfad168875 | ||
|
|
7fde61f849 | ||
|
|
8904d33789 | ||
|
|
d28e20b179 | ||
|
|
c5915b5583 | ||
|
|
2626c4365c | ||
|
|
9c35e7a006 | ||
|
|
061438b7c8 | ||
|
|
88035efdf9 | ||
|
|
3546c93d23 | ||
|
|
e232b4adbf | ||
|
|
89019f1e60 | ||
|
|
efc91241d9 | ||
|
|
c90c33ec11 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -18,3 +18,8 @@ aqhome-mqtt.pid
|
||||
aqhome-mqtt.devices
|
||||
|
||||
core.*
|
||||
core
|
||||
aqhome.geany
|
||||
aqhome-nodes.db
|
||||
aqhome-nodes.db.*
|
||||
|
||||
|
||||
@@ -268,6 +268,9 @@ int _setupMqtt(AQHOME_MQTT *aqh, GWEN_DB_NODE *dbArgs)
|
||||
mqttPort=GWEN_DB_GetIntValue(dbArgs, "ConfigFile/mqttPort", 0, 1883);
|
||||
|
||||
mqttClientId=GWEN_DB_GetCharValue(dbArgs, "mqttClientId", 0, "aqhome-mqttlog");
|
||||
if (!(mqttClientId && *mqttClientId))
|
||||
mqttClientId=GWEN_DB_GetCharValue(dbArgs, "ConfigFile/mqttClientId", 0, "aqhome-mqttlog");
|
||||
|
||||
mqttKeepAlive=GWEN_DB_GetIntValue(dbArgs, "mqttKeepAlive", 0, 600);
|
||||
|
||||
if (mqttAddress && *mqttAddress && mqttPort) {
|
||||
|
||||
@@ -68,7 +68,7 @@ static int _sendFlashRecord(GWEN_MSG_ENDPOINT *epTcp,
|
||||
const AQH_FLASHRECORD *flashRecord,
|
||||
uint16_t pageSize,
|
||||
int timeoutInSeconds);
|
||||
static int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason);
|
||||
static int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason, int timeoutInSeconds);
|
||||
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ int _performFlashProcedure(GWEN_MSG_ENDPOINT *epTcp,
|
||||
flashRecord=AQH_FlashRecord_List_Next(flashRecord);
|
||||
}
|
||||
|
||||
rv=_sendFlashEnd(epTcp, 0);
|
||||
rv=_sendFlashEnd(epTcp, 0, timeoutInSeconds);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return rv;
|
||||
@@ -502,22 +502,44 @@ int _sendFlashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
|
||||
|
||||
|
||||
|
||||
int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason)
|
||||
int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason, int timeoutInSeconds)
|
||||
{
|
||||
GWEN_MSG *msgNode;
|
||||
GWEN_MSG *msgOut;
|
||||
int i;
|
||||
|
||||
msgNode=AQH_FlashEndMsg_new(0, 0xc1, AQH_MSG_TYPE_FLASH_END, reason);
|
||||
if (msgNode==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
for (i=0;i<FLASH_TOOL_MAX_REPEAT;i++) {
|
||||
GWEN_MSG *msgNode;
|
||||
GWEN_MSG *msgOut;
|
||||
int rv;
|
||||
|
||||
fprintf(stdout, "Sending end\n");
|
||||
|
||||
usleep(100000);
|
||||
|
||||
msgNode=AQH_FlashEndMsg_new(0, 0xc1, AQH_MSG_TYPE_FLASH_END, reason);
|
||||
if (msgNode==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_NODES_FORWARD,
|
||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
||||
GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_Msg_free(msgNode);
|
||||
|
||||
rv=_waitForFlashResponseMessage(epTcp, timeoutInSeconds);
|
||||
if (rv==0) {
|
||||
fprintf(stdout, "-> ACK received.\n");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Negative response to flash end message (%d)", rv);
|
||||
}
|
||||
} /* for */
|
||||
if (i>=FLASH_TOOL_MAX_REPEAT) {
|
||||
DBG_ERROR(NULL, "Too many errors (tried %d times), giving up", i);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_NODES_FORWARD,
|
||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
||||
GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_Msg_free(msgNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -555,6 +577,8 @@ int _sendFlashRecord(GWEN_MSG_ENDPOINT *epTcp,
|
||||
else
|
||||
fprintf(stdout, "Send data: dest addr=%04x, len=%d bytes\n", address, sendLen);
|
||||
|
||||
usleep(100000);
|
||||
|
||||
msgNode=AQH_FlashDataMsg_new(0, 0xc1, AQH_MSG_TYPE_FLASH_DATA, address, ptr, sendLen);
|
||||
if (msgNode==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
@@ -568,8 +592,10 @@ int _sendFlashRecord(GWEN_MSG_ENDPOINT *epTcp,
|
||||
GWEN_Msg_free(msgNode);
|
||||
|
||||
rv=_waitForFlashResponseMessage(epTcp, timeoutInSeconds);
|
||||
if (rv==0)
|
||||
break;
|
||||
if (rv==0) {
|
||||
fprintf(stdout, "-> ACK received.\n");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Negative response to flash data message (%d)", rv);
|
||||
}
|
||||
|
||||
@@ -65,11 +65,13 @@
|
||||
<subdirs>
|
||||
msg
|
||||
ipc
|
||||
ipc2
|
||||
nodes
|
||||
mqtt
|
||||
hexfile
|
||||
data
|
||||
events
|
||||
events2
|
||||
client
|
||||
</subdirs>
|
||||
|
||||
@@ -77,11 +79,13 @@
|
||||
<useTargets>
|
||||
aqhmsg
|
||||
aqhipc
|
||||
aqhipc2
|
||||
aqhnodes
|
||||
aqhmqtt
|
||||
aqhhexfile
|
||||
aqhdata
|
||||
aqhevents
|
||||
aqhevents2
|
||||
aqhclient
|
||||
</useTargets>
|
||||
|
||||
|
||||
@@ -219,11 +219,11 @@ int AQH_ValueDataType_fromString(const char *s)
|
||||
return AQH_ValueDataType_Uint32;
|
||||
else if (strcasecmp(s, "rational")==0)
|
||||
return AQH_ValueDataType_Rational;
|
||||
else if (strcasecmp(s, "AQH_ValueDataType_Uint8")==0)
|
||||
else if (strcasecmp(s, "uint8")==0)
|
||||
return AQH_ValueDataType_Uint8;
|
||||
else if (strcasecmp(s, "AQH_ValueDataType_Uint16")==0)
|
||||
else if (strcasecmp(s, "uint16")==0)
|
||||
return AQH_ValueDataType_Uint16;
|
||||
else if (strcasecmp(s, "AQH_ValueDataType_Uint32")==0)
|
||||
else if (strcasecmp(s, "uint32")==0)
|
||||
return AQH_ValueDataType_Uint32;
|
||||
}
|
||||
return AQH_ValueDataType_Unknown;
|
||||
@@ -259,6 +259,8 @@ int AQH_ValueModality_fromString(const char *s)
|
||||
return AQH_ValueModality_RGB;
|
||||
else if (strcasecmp(s, "rgbw")==0)
|
||||
return AQH_ValueModality_RGBW;
|
||||
else if (strcasecmp(s, "motion")==0)
|
||||
return AQH_ValueModality_Motion;
|
||||
}
|
||||
return AQH_ValueModality_Unknown;
|
||||
}
|
||||
@@ -273,6 +275,7 @@ const char *AQH_ValueModality_toString(int i)
|
||||
case AQH_ValueModality_Door: return "door";
|
||||
case AQH_ValueModality_RGB: return "rgb";
|
||||
case AQH_ValueModality_RGBW: return "rgbw";
|
||||
case AQH_ValueModality_Motion: return "motion";
|
||||
case AQH_ValueModality_Unknown:
|
||||
default: return "unknown";
|
||||
}
|
||||
@@ -451,10 +454,10 @@ 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) {
|
||||
//DBG_ERROR(NULL, "Reading \"%s\" as datatype %d (%s)", s?s:"<NULL>", dataType, AQH_ValueDataType_toString(dataType));
|
||||
switch(dataType) {
|
||||
case AQH_ValueDataType_Int:
|
||||
|
||||
case AQH_ValueDataType_Uint8: return _readUint8DataFromString(s, pDataVal, pDataDenom);
|
||||
case AQH_ValueDataType_Int:
|
||||
case AQH_ValueDataType_Uint16: return _readUint16DataFromString(s, pDataVal, pDataDenom);
|
||||
case AQH_ValueDataType_Uint32: return _readUint32DataFromString(s, pDataVal, pDataDenom);
|
||||
case AQH_ValueDataType_Rational: break;
|
||||
@@ -469,7 +472,7 @@ int AQH_ReadDataFromString(int dataType, const char *s, uint16_t *pDataVal, uint
|
||||
|
||||
int _readUint8DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom)
|
||||
{
|
||||
unsigned int v=0;
|
||||
int v=0;
|
||||
|
||||
if (1==sscanf(s, "%i", &v)) {
|
||||
*pDataVal=v & 0xff;
|
||||
@@ -483,7 +486,7 @@ int _readUint8DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataD
|
||||
|
||||
int _readUint16DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom)
|
||||
{
|
||||
unsigned int v=0;
|
||||
int v=0;
|
||||
|
||||
if (1==sscanf(s, "%i", &v)) {
|
||||
*pDataVal=v & 0xffff;
|
||||
@@ -497,7 +500,7 @@ int _readUint16DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pData
|
||||
|
||||
int _readUint32DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom)
|
||||
{
|
||||
unsigned long int v=0;
|
||||
long int v=0;
|
||||
|
||||
if (1==sscanf(s, "%li", &v)) {
|
||||
*pDataVal=(v>>16) & 0xffff;
|
||||
|
||||
@@ -41,7 +41,8 @@ enum {
|
||||
AQH_ValueModality_Humidity,
|
||||
AQH_ValueModality_Door,
|
||||
AQH_ValueModality_RGB,
|
||||
AQH_ValueModality_RGBW
|
||||
AQH_ValueModality_RGBW,
|
||||
AQH_ValueModality_Motion
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
|
||||
<headers dist="true" >
|
||||
df_direct.h
|
||||
df_direct_p.h
|
||||
</headers>
|
||||
|
||||
|
||||
|
||||
88
aqhome/events2/0BUILD
Normal file
88
aqhome/events2/0BUILD
Normal file
@@ -0,0 +1,88 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<target type="ConvenienceLibrary" name="aqhevents2" >
|
||||
|
||||
<includes type="c" >
|
||||
$(gwenhywfar_cflags)
|
||||
$(aqdatabase_cflags)
|
||||
-I$(topsrcdir)
|
||||
-I$(topbuilddir)
|
||||
</includes>
|
||||
|
||||
<includes type="tm2" >
|
||||
--include=$(builddir)
|
||||
--include=$(srcdir)
|
||||
--include=$(aqdatabase_AQDATABASE_TYPEMAKERDIR)/c
|
||||
</includes>
|
||||
|
||||
|
||||
<define name="BUILDING_AQHOME" />
|
||||
|
||||
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
||||
|
||||
|
||||
<setVar name="tm2flags" >
|
||||
--api=AQHOME_API
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/typefiles" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_sources" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_headers_pub">
|
||||
</setVar>
|
||||
|
||||
|
||||
<setVar name="local/built_headers_priv" >
|
||||
</setVar>
|
||||
|
||||
|
||||
<headers dist="false" install="$(pkgincludedir)/data" >
|
||||
$(local/built_headers_pub)
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/data" >
|
||||
eventloop.h
|
||||
object.h
|
||||
fdobject.h
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
eventloop_p.h
|
||||
object_p.h
|
||||
fdobject_p.h
|
||||
</headers>
|
||||
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
|
||||
eventloop.c
|
||||
eventloop_select.c
|
||||
object.c
|
||||
fdobject.c
|
||||
</sources>
|
||||
|
||||
|
||||
<extradist>
|
||||
</extradist>
|
||||
|
||||
|
||||
<useTargets>
|
||||
</useTargets>
|
||||
|
||||
<subdirs>
|
||||
</subdirs>
|
||||
|
||||
|
||||
|
||||
|
||||
</target>
|
||||
|
||||
</gwbuild>
|
||||
79
aqhome/events2/eventloop.c
Normal file
79
aqhome/events2/eventloop.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./eventloop_p.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
|
||||
AQH_EVENT_LOOP *AQH_EventLoop_new(void)
|
||||
{
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_EVENT_LOOP, eventLoop);
|
||||
eventLoop->fdObjectList=AQH_Object_List2_new();
|
||||
eventLoop->timerObjectList=AQH_Object_List2_new();
|
||||
|
||||
return eventLoop;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_EventLoop_free(AQH_EVENT_LOOP *eventLoop)
|
||||
{
|
||||
if (eventLoop) {
|
||||
AQH_Object_List2_free(eventLoop->timerObjectList);
|
||||
AQH_Object_List2_free(eventLoop->fdObjectList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_EventLoop_AddFdObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o)
|
||||
{
|
||||
if (eventLoop && o && NULL==AQH_Object_List2_Contains(eventLoop->fdObjectList, o)) {
|
||||
AQH_Object_List2_PushBack(eventLoop->fdObjectList, o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_EventLoop_DelFdObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o)
|
||||
{
|
||||
if (eventLoop && o)
|
||||
AQH_Object_List2_Remove(eventLoop->fdObjectList, o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_EventLoop_AddTimerObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o)
|
||||
{
|
||||
if (eventLoop && o && NULL==AQH_Object_List2_Contains(eventLoop->timerObjectList, o)) {
|
||||
AQH_Object_List2_PushBack(eventLoop->timerObjectList, o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_EventLoop_DelTimerObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o)
|
||||
{
|
||||
if (eventLoop && o)
|
||||
AQH_Object_List2_Remove(eventLoop->timerObjectList, o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
32
aqhome/events2/eventloop.h
Normal file
32
aqhome/events2/eventloop.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_EVENTLOOP_H
|
||||
#define AQH_EVENTLOOP_H
|
||||
|
||||
typedef struct AQH_EVENT_LOOP AQH_EVENT_LOOP;
|
||||
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_EVENT_LOOP *AQH_EventLoop_new(void);
|
||||
AQHOME_API void AQH_EventLoop_free(AQH_EVENT_LOOP *eventLoop);
|
||||
|
||||
AQHOME_API void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop);
|
||||
|
||||
AQHOME_API void AQH_EventLoop_AddFdObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_EventLoop_DelFdObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o);
|
||||
|
||||
AQHOME_API void AQH_EventLoop_AddTimerObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_EventLoop_DelTimerObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
25
aqhome/events2/eventloop_p.h
Normal file
25
aqhome/events2/eventloop_p.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_EVENTLOOP_P_H
|
||||
#define AQH_EVENTLOOP_P_H
|
||||
|
||||
#include "./eventloop.h"
|
||||
|
||||
|
||||
|
||||
struct AQH_EVENT_LOOP
|
||||
{
|
||||
AQH_OBJECT_LIST2 *fdObjectList;
|
||||
AQH_OBJECT_LIST2 *timerObjectList;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
173
aqhome/events2/eventloop_select.c
Normal file
173
aqhome/events2/eventloop_select.c
Normal file
@@ -0,0 +1,173 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./eventloop_p.h"
|
||||
#include "./fdobject.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/select.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static int _sampleFdsIntoSet(AQH_OBJECT_LIST2 *ol, fd_set *fds, int mode);
|
||||
static void _markReadyFdObjects(AQH_OBJECT_LIST2 *ol, fd_set *fds, int mode);
|
||||
static void _signalReadyFdObjects(AQH_OBJECT_LIST2 *ol);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* code
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop)
|
||||
{
|
||||
fd_set fdRead;
|
||||
fd_set fdWrite;
|
||||
int highestFd=-1;
|
||||
int rv;
|
||||
|
||||
FD_ZERO(&fdRead);
|
||||
FD_ZERO(&fdWrite);
|
||||
|
||||
highestFd=_sampleFdsIntoSet(eventLoop->fdObjectList, &fdRead, AQH_FDOBJECT_FDMODE_READ);
|
||||
rv=_sampleFdsIntoSet(eventLoop->fdObjectList, &fdWrite, AQH_FDOBJECT_FDMODE_WRITE);
|
||||
highestFd=(rv>highestFd)?rv:highestFd;
|
||||
|
||||
if (highestFd>-1) {
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec=0;
|
||||
tv.tv_usec=200000;
|
||||
rv=select(highestFd+1, &fdRead, &fdWrite, NULL, &tv);
|
||||
if (rv>0) {
|
||||
/* some fds became active */
|
||||
_markReadyFdObjects(eventLoop->fdObjectList, &fdRead, AQH_FDOBJECT_FDMODE_READ);
|
||||
_markReadyFdObjects(eventLoop->fdObjectList, &fdWrite, AQH_FDOBJECT_FDMODE_WRITE);
|
||||
_signalReadyFdObjects(eventLoop->fdObjectList);
|
||||
}
|
||||
else if (rv<0) {
|
||||
if (errno!=EINTR) {
|
||||
/* error */
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on SELECT: %d (%s)", errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* no fd became active (TODO: maybe signal deep idle objects?) */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _sampleFdsIntoSet(AQH_OBJECT_LIST2 *ol, fd_set *fds, int mode)
|
||||
{
|
||||
AQH_OBJECT_LIST2_ITERATOR *it;
|
||||
int highestFd=-1;
|
||||
|
||||
it=AQH_Object_List2_First(ol);
|
||||
if (it) {
|
||||
AQH_OBJECT *o;
|
||||
|
||||
o=AQH_Object_List2Iterator_Data(it);
|
||||
while(o) {
|
||||
int m;
|
||||
|
||||
m=AQH_FdObject_GetFdMode(o);
|
||||
if (m==mode) {
|
||||
int fd;
|
||||
|
||||
fd=AQH_FdObject_GetFd(o);
|
||||
if (fd>-1) {
|
||||
highestFd=(fd>highestFd)?fd:highestFd;
|
||||
FD_SET(fd, fds);
|
||||
}
|
||||
}
|
||||
o=AQH_Object_List2Iterator_Next(it);
|
||||
}
|
||||
AQH_Object_List2Iterator_free(it);
|
||||
}
|
||||
|
||||
return highestFd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _markReadyFdObjects(AQH_OBJECT_LIST2 *ol, fd_set *fds, int mode)
|
||||
{
|
||||
AQH_OBJECT_LIST2_ITERATOR *it;
|
||||
|
||||
it=AQH_Object_List2_First(ol);
|
||||
if (it) {
|
||||
AQH_OBJECT *o;
|
||||
|
||||
o=AQH_Object_List2Iterator_Data(it);
|
||||
while(o) {
|
||||
int m;
|
||||
|
||||
m=AQH_FdObject_GetFdMode(o);
|
||||
if (m==mode) {
|
||||
int fd;
|
||||
|
||||
fd=AQH_FdObject_GetFd(o);
|
||||
if (FD_ISSET(fd, fds))
|
||||
AQH_Object_AddFlags(o, AQH_OBJECT_FLAGS_FIRE);
|
||||
}
|
||||
o=AQH_Object_List2Iterator_Next(it);
|
||||
}
|
||||
|
||||
AQH_Object_List2Iterator_free(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _signalReadyFdObjects(AQH_OBJECT_LIST2 *ol)
|
||||
{
|
||||
AQH_OBJECT_LIST2_ITERATOR *it;
|
||||
|
||||
it=AQH_Object_List2_First(ol);
|
||||
if (it) {
|
||||
AQH_OBJECT *o;
|
||||
|
||||
o=AQH_Object_List2Iterator_Data(it);
|
||||
while(o) {
|
||||
if (AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_FIRE) {
|
||||
AQH_Object_SubFlags(o, AQH_OBJECT_FLAGS_FIRE);
|
||||
AQH_Object_EmitSignal(o, AQH_FDOBJECT_SIGNAL_ISREADY, 0, NULL);
|
||||
}
|
||||
o=AQH_Object_List2Iterator_Next(it);
|
||||
}
|
||||
|
||||
AQH_Object_List2Iterator_free(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
342
aqhome/events2/fdobject.c
Normal file
342
aqhome/events2/fdobject.c
Normal file
@@ -0,0 +1,342 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./fdobject_p.h"
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
//#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
GWEN_INHERIT(AQH_OBJECT, AQH_FDOBJECT)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static void _cbEnable(AQH_OBJECT *o);
|
||||
static void _cbDisable(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_FdObject_new(AQH_EVENT_LOOP *eventLoop, int fd, int mode)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
o=AQH_Object_new(eventLoop);
|
||||
GWEN_NEW_OBJECT(AQH_FDOBJECT, xo);
|
||||
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_FDOBJECT, o, xo, _freeData);
|
||||
xo->fd=fd;
|
||||
xo->fdMode=mode;
|
||||
|
||||
AQH_Object_SetEnableFn(o, _cbEnable);
|
||||
AQH_Object_SetDisableFn(o, _cbDisable);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=(AQH_FDOBJECT*)p;
|
||||
if (xo->fd>=0)
|
||||
close(xo->fd);
|
||||
xo->fd=-1;
|
||||
GWEN_FREE_OBJECT(xo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_FDOBJECT_STARTMSG_FN AQH_FdObject_SetStartMsgFn(AQH_OBJECT *o, AQH_FDOBJECT_STARTMSG_FN f)
|
||||
{
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo) {
|
||||
AQH_FDOBJECT_STARTMSG_FN oldFn;
|
||||
|
||||
oldFn=xo->startMsgFn;
|
||||
xo->startMsgFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_FDOBJECT_ENDMSG_FN AQH_FdObject_SetEndMsgFn(AQH_OBJECT *o, AQH_FDOBJECT_ENDMSG_FN f)
|
||||
{
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo) {
|
||||
AQH_FDOBJECT_ENDMSG_FN oldFn;
|
||||
|
||||
oldFn=xo->endMsgFn;
|
||||
xo->endMsgFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_FdObject_GetFdMode(const AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo)
|
||||
return xo->fdMode;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_FdObject_SetFdMode(AQH_OBJECT *o, int i)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo)
|
||||
xo->fdMode=i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_FdObject_GetFd(const AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo)
|
||||
return xo->fd;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_FdObject_Read(AQH_OBJECT *o, uint8_t *ptrBuffer, uint32_t lenBuffer)
|
||||
{
|
||||
if (o && ptrBuffer && lenBuffer) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo) {
|
||||
if (xo->fd!=-1) {
|
||||
ssize_t rv;
|
||||
|
||||
rv=read(xo->fd, ptrBuffer, lenBuffer);
|
||||
if (rv==0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "EOF met");
|
||||
return 0;
|
||||
}
|
||||
else if (rv>0) {
|
||||
/* data received */
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Received %d bytes", (int) rv);
|
||||
return (int) rv;
|
||||
}
|
||||
else {
|
||||
if (errno==EINTR || errno==EWOULDBLOCK || errno==EAGAIN) {
|
||||
/* temporarily no data, try again */
|
||||
return GWEN_ERROR_TRY_AGAIN;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on read: %s (%d)", strerror(errno), errno);
|
||||
close(xo->fd);
|
||||
xo->fd=-1;
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Previous error, not reading.");
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_FdObject_FlushInput(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo) {
|
||||
if (xo->fd!=-1) {
|
||||
ssize_t rv;
|
||||
ssize_t bytesRead=0;
|
||||
uint8_t tbuf[16];
|
||||
|
||||
do {
|
||||
rv=read(xo->fd, tbuf, sizeof(tbuf));
|
||||
if (rv>0)
|
||||
bytesRead+=rv;
|
||||
} while(rv>=0);
|
||||
|
||||
if (rv==0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "EOF met");
|
||||
return GWEN_ERROR_EOF;
|
||||
}
|
||||
else if (rv<0) {
|
||||
if (errno!=EINTR && errno!=EWOULDBLOCK && errno!=EAGAIN) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on read: %s (%d)", strerror(errno), errno);
|
||||
close(xo->fd);
|
||||
xo->fd=-1;
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
}
|
||||
return (bytesRead>0)?1:0;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Previous error, not reading.");
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_FdObject_Write(AQH_OBJECT *o, const uint8_t *ptrBuffer, uint32_t lenBuffer)
|
||||
{
|
||||
if (o && ptrBuffer && lenBuffer) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo) {
|
||||
if (xo->fd!=-1) {
|
||||
ssize_t rv;
|
||||
|
||||
rv=write(xo->fd, ptrBuffer, lenBuffer);
|
||||
if (rv<0) {
|
||||
if (errno==EINTR || errno==EWOULDBLOCK || errno==EAGAIN) {
|
||||
/* temporarily no data, try again */
|
||||
return GWEN_ERROR_TRY_AGAIN;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on write: %s (%d)", strerror(errno), errno);
|
||||
close(xo->fd);
|
||||
xo->fd=-1;
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* data received */
|
||||
return (int) rv;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Previous error, not writing.");
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_FdObject_StartMsg(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo && xo->startMsgFn)
|
||||
return xo->startMsgFn(o);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_FdObject_EndMsg(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_FDOBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
|
||||
if (xo && xo->endMsgFn)
|
||||
xo->endMsgFn(o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbEnable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o && !(AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_ENABLED)) {
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
|
||||
eventLoop=AQH_Object_GetEventLoop(o);
|
||||
if (eventLoop) {
|
||||
AQH_EventLoop_AddFdObject(eventLoop, o);
|
||||
AQH_Object_AddFlags(o, AQH_OBJECT_FLAGS_ENABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbDisable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o && (AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_ENABLED)) {
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
|
||||
eventLoop=AQH_Object_GetEventLoop(o);
|
||||
if (eventLoop) {
|
||||
AQH_EventLoop_DelFdObject(eventLoop, o);
|
||||
AQH_Object_SubFlags(o, AQH_OBJECT_FLAGS_ENABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
53
aqhome/events2/fdobject.h
Normal file
53
aqhome/events2/fdobject.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_FDOBJECT_H
|
||||
#define AQH_FDOBJECT_H
|
||||
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
|
||||
enum {
|
||||
AQH_FDOBJECT_FDMODE_READ=1,
|
||||
AQH_FDOBJECT_FDMODE_WRITE
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
AQH_FDOBJECT_SIGNAL_ISREADY=AQH_OBJECT_SIGNAL_LAST
|
||||
};
|
||||
|
||||
|
||||
typedef int (*AQH_FDOBJECT_STARTMSG_FN)(AQH_OBJECT *o);
|
||||
typedef void (*AQH_FDOBJECT_ENDMSG_FN)(AQH_OBJECT *o);
|
||||
|
||||
|
||||
/**
|
||||
* Create object for given file descriptor (takes over ownership of the given file descriptor, use dup() if
|
||||
* fd used in another object).
|
||||
*/
|
||||
AQHOME_API AQH_OBJECT *AQH_FdObject_new(AQH_EVENT_LOOP *eventLoop, int fd, int mode);
|
||||
|
||||
AQHOME_API int AQH_FdObject_GetFdMode(const AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_FdObject_SetFdMode(AQH_OBJECT *o, int i);
|
||||
|
||||
AQHOME_API int AQH_FdObject_GetFd(const AQH_OBJECT *o);
|
||||
|
||||
AQHOME_API int AQH_FdObject_Read(AQH_OBJECT *o, uint8_t *ptrBuffer, uint32_t lenBuffer);
|
||||
AQHOME_API int AQH_FdObject_Write(AQH_OBJECT *o, const uint8_t *ptrBuffer, uint32_t lenBuffer);
|
||||
AQHOME_API int AQH_FdObject_FlushInput(AQH_OBJECT *o);
|
||||
|
||||
AQHOME_API int AQH_FdObject_StartMsg(AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_FdObject_EndMsg(AQH_OBJECT *o);
|
||||
|
||||
AQHOME_API AQH_FDOBJECT_STARTMSG_FN AQH_FdObject_SetStartMsgFn(AQH_OBJECT *o, AQH_FDOBJECT_STARTMSG_FN f);
|
||||
AQHOME_API AQH_FDOBJECT_ENDMSG_FN AQH_FdObject_SetEndMsgFn(AQH_OBJECT *o, AQH_FDOBJECT_ENDMSG_FN f);
|
||||
|
||||
|
||||
#endif
|
||||
26
aqhome/events2/fdobject_p.h
Normal file
26
aqhome/events2/fdobject_p.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project Gwenhywfar.
|
||||
* Gwenhywfar (c) by 2023 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 AQH_FDOBJECT_P_H
|
||||
#define AQH_FDOBJECT_P_H
|
||||
|
||||
|
||||
#include "./fdobject.h"
|
||||
|
||||
|
||||
typedef struct AQH_FDOBJECT AQH_FDOBJECT;
|
||||
struct AQH_FDOBJECT {
|
||||
int fdMode;
|
||||
int fd;
|
||||
|
||||
AQH_FDOBJECT_STARTMSG_FN startMsgFn;
|
||||
AQH_FDOBJECT_ENDMSG_FN endMsgFn;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
287
aqhome/events2/object.c
Normal file
287
aqhome/events2/object.c
Normal file
@@ -0,0 +1,287 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./object_p.h"
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static AQH_LINK *AQH_Link_new();
|
||||
static void AQH_Link_free(AQH_LINK *ln);
|
||||
|
||||
static AQH_LINK *_findLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* list, inherit
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
GWEN_LIST_FUNCTIONS(AQH_LINK, AQH_Link)
|
||||
|
||||
GWEN_INHERIT_FUNCTIONS(AQH_OBJECT)
|
||||
GWEN_LIST_FUNCTIONS(AQH_OBJECT, AQH_Object)
|
||||
GWEN_LIST2_FUNCTIONS(AQH_OBJECT, AQH_Object)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* code
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_Object_new(AQH_EVENT_LOOP *eventLoop)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_OBJECT, o);
|
||||
o->refCount=1;
|
||||
GWEN_INHERIT_INIT(AQH_OBJECT, o);
|
||||
GWEN_LIST_INIT(AQH_OBJECT, o);
|
||||
o->eventLoop=eventLoop;
|
||||
o->linkList=AQH_Link_List_new();
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_IncRefCount(AQH_OBJECT *o)
|
||||
{
|
||||
if (o && o->refCount>0)
|
||||
o->refCount++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_free(AQH_OBJECT *o)
|
||||
{
|
||||
if (o && o->refCount>0) {
|
||||
if (--(o->refCount)==0) {
|
||||
GWEN_INHERIT_FINI(AQH_OBJECT, o);
|
||||
GWEN_LIST_FINI(AQH_OBJECT, o);
|
||||
|
||||
AQH_Link_List_free(o->linkList);
|
||||
|
||||
GWEN_FREE_OBJECT(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Object_GetFlags(const AQH_OBJECT *o)
|
||||
{
|
||||
return (o && o->refCount)?o->flags:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_SetFlags(AQH_OBJECT *o, uint32_t i)
|
||||
{
|
||||
if (o && o->refCount)
|
||||
o->flags=i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_AddFlags(AQH_OBJECT *o, uint32_t i)
|
||||
{
|
||||
if (o && o->refCount)
|
||||
o->flags|=i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_SubFlags(AQH_OBJECT *o, uint32_t i)
|
||||
{
|
||||
if (o && o->refCount)
|
||||
o->flags&=~i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_EVENT_LOOP *AQH_Object_GetEventLoop(const AQH_OBJECT *o)
|
||||
{
|
||||
return (o && o->refCount)?o->eventLoop:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_LINK *_findLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject)
|
||||
{
|
||||
if (o && o->refCount) {
|
||||
AQH_LINK *ln;
|
||||
|
||||
ln=AQH_Link_List_First(o->linkList);
|
||||
while(ln) {
|
||||
if (ln->signalIdForSender==signalId &&
|
||||
ln->signalIdForTarget==slotId &&
|
||||
ln->targetObject==targetObject)
|
||||
return ln;
|
||||
ln=AQH_Link_List_Next(ln);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_AddLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject)
|
||||
{
|
||||
AQH_LINK *ln;
|
||||
|
||||
ln=_findLink(o, signalId, slotId, targetObject);
|
||||
if (ln==NULL) {
|
||||
ln=AQH_Link_new();
|
||||
ln->signalIdForSender=signalId;
|
||||
ln->signalIdForTarget=slotId;
|
||||
ln->targetObject=targetObject;
|
||||
AQH_Link_List_Add(ln, o->linkList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_DelLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject)
|
||||
{
|
||||
AQH_LINK *ln;
|
||||
|
||||
ln=_findLink(o, signalId, slotId, targetObject);
|
||||
if (ln) {
|
||||
AQH_Link_List_Del(ln);
|
||||
AQH_Link_free(ln);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Object_EmitSignal(AQH_OBJECT *o, uint32_t signalId, int param1, void *param2)
|
||||
{
|
||||
int signalWasHandled=0;
|
||||
|
||||
if (o && o->refCount) {
|
||||
AQH_LINK *ln;
|
||||
|
||||
ln=AQH_Link_List_First(o->linkList);
|
||||
while(ln) {
|
||||
if (ln->signalIdForSender==signalId && ln->targetObject) {
|
||||
if (AQH_Object_HandleSignal(ln->targetObject, ln->signalIdForTarget, o, param1, param2))
|
||||
signalWasHandled=1;
|
||||
}
|
||||
ln=AQH_Link_List_Next(ln);
|
||||
}
|
||||
}
|
||||
return signalWasHandled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Object_HandleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2)
|
||||
{
|
||||
if (o && o->refCount && o->signalHandlerFn)
|
||||
return o->signalHandlerFn(o, slotId, senderObject, param1, param2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_Enable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o && o->refCount && o->enableFn)
|
||||
o->enableFn(o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Object_Disable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o && o->refCount && o->disableFn)
|
||||
o->disableFn(o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT_SIGNALHANDLER_FN AQH_Object_SetSignalHandlerFn(AQH_OBJECT *o, AQH_OBJECT_SIGNALHANDLER_FN f)
|
||||
{
|
||||
if (o && o->refCount) {
|
||||
AQH_OBJECT_SIGNALHANDLER_FN oldFn;
|
||||
|
||||
oldFn=o->signalHandlerFn;
|
||||
o->signalHandlerFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT_ENABLE_FN AQH_Object_SetEnableFn(AQH_OBJECT *o, AQH_OBJECT_ENABLE_FN f)
|
||||
{
|
||||
if (o && o->refCount) {
|
||||
AQH_OBJECT_ENABLE_FN oldFn;
|
||||
|
||||
oldFn=o->enableFn;
|
||||
o->enableFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT_DISABLE_FN AQH_Object_SetDisableFn(AQH_OBJECT *o, AQH_OBJECT_DISABLE_FN f)
|
||||
{
|
||||
if (o && o->refCount) {
|
||||
AQH_OBJECT_DISABLE_FN oldFn;
|
||||
|
||||
oldFn=o->disableFn;
|
||||
o->disableFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AQH_LINK *AQH_Link_new()
|
||||
{
|
||||
AQH_LINK *ln;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_LINK, ln);
|
||||
GWEN_LIST_INIT(AQH_LINK, ln);
|
||||
|
||||
return ln;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Link_free(AQH_LINK *ln)
|
||||
{
|
||||
if (ln) {
|
||||
GWEN_LIST_FINI(AQH_LINK, ln);
|
||||
GWEN_FREE_OBJECT(ln);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
123
aqhome/events2/object.h
Normal file
123
aqhome/events2/object.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_OBJECT_H
|
||||
#define AQH_OBJECT_H
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/list2.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_OBJECT_FLAGS_ENABLED 0x80000000L
|
||||
#define AQH_OBJECT_FLAGS_FIRE 0x40000000L
|
||||
|
||||
|
||||
enum {
|
||||
AQH_OBJECT_SIGNAL_LAST=10 /* reserve signal ids 0-9 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* @name Type Definition
|
||||
*/
|
||||
/*@{*/
|
||||
typedef struct AQH_OBJECT AQH_OBJECT;
|
||||
GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_OBJECT, AQHOME_API)
|
||||
GWEN_LIST_FUNCTION_LIB_DEFS(AQH_OBJECT, AQH_Object, AQHOME_API)
|
||||
GWEN_LIST2_FUNCTION_LIB_DEFS(AQH_OBJECT, AQH_Object, AQHOME_API)
|
||||
/*@}*/
|
||||
|
||||
|
||||
#include <aqhome/events2/eventloop.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* @name Virtual Function Declarations
|
||||
*/
|
||||
/*@{*/
|
||||
typedef int (*AQH_OBJECT_SIGNALHANDLER_FN)(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
|
||||
typedef void (*AQH_OBJECT_ENABLE_FN)(AQH_OBJECT *o);
|
||||
typedef void (*AQH_OBJECT_DISABLE_FN)(AQH_OBJECT *o);
|
||||
/*@}*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* @name Construction, Destruction
|
||||
*/
|
||||
/*@{*/
|
||||
AQHOME_API AQH_OBJECT *AQH_Object_new(AQH_EVENT_LOOP *eventLoop);
|
||||
AQHOME_API void AQH_Object_IncRefCount(AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_Object_free(AQH_OBJECT *o);
|
||||
/*@}*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* @name Manipulate Flags
|
||||
*/
|
||||
/*@{*/
|
||||
AQHOME_API uint32_t AQH_Object_GetFlags(const AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_Object_SetFlags(AQH_OBJECT *o, uint32_t i);
|
||||
AQHOME_API void AQH_Object_AddFlags(AQH_OBJECT *o, uint32_t i);
|
||||
AQHOME_API void AQH_Object_SubFlags(AQH_OBJECT *o, uint32_t i);
|
||||
/*@}*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* @name Getters, Setters
|
||||
*/
|
||||
/*@{*/
|
||||
AQHOME_API AQH_EVENT_LOOP *AQH_Object_GetEventLoop(const AQH_OBJECT *o);
|
||||
/*@}*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* @name Link Handling
|
||||
*/
|
||||
/*@{*/
|
||||
AQHOME_API void AQH_Object_AddLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject);
|
||||
AQHOME_API void AQH_Object_DelLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject);
|
||||
/*@}*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* @name Virtual Function Declarations
|
||||
*/
|
||||
/*@{*/
|
||||
AQHOME_API int AQH_Object_EmitSignal(AQH_OBJECT *o, uint32_t signalId, int param1, void *param2);
|
||||
AQHOME_API int AQH_Object_HandleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
|
||||
AQHOME_API void AQH_Object_Enable(AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_Object_Disable(AQH_OBJECT *o);
|
||||
/*@}*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* @name Setter for Virtual Functions
|
||||
*/
|
||||
/*@{*/
|
||||
AQHOME_API AQH_OBJECT_SIGNALHANDLER_FN AQH_Object_SetSignalHandlerFn(AQH_OBJECT *o, AQH_OBJECT_SIGNALHANDLER_FN f);
|
||||
AQHOME_API AQH_OBJECT_ENABLE_FN AQH_Object_SetEnableFn(AQH_OBJECT *o, AQH_OBJECT_ENABLE_FN f);
|
||||
AQHOME_API AQH_OBJECT_DISABLE_FN AQH_Object_SetDisableFn(AQH_OBJECT *o, AQH_OBJECT_DISABLE_FN f);
|
||||
/*@}*/
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
48
aqhome/events2/object_p.h
Normal file
48
aqhome/events2/object_p.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project Gwenhywfar.
|
||||
* Gwenhywfar (c) by 2023 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 AQH_OBJECT_P_H
|
||||
#define AQH_OBJECT_P_H
|
||||
|
||||
|
||||
#include "./object.h"
|
||||
|
||||
|
||||
typedef struct AQH_LINK AQH_LINK;
|
||||
GWEN_LIST_FUNCTION_DEFS(AQH_LINK, AQH_Link)
|
||||
|
||||
|
||||
|
||||
struct AQH_LINK {
|
||||
GWEN_LIST_ELEMENT(AQH_LINK)
|
||||
|
||||
uint32_t signalIdForSender;
|
||||
uint32_t signalIdForTarget;
|
||||
AQH_OBJECT *targetObject;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct AQH_OBJECT {
|
||||
GWEN_INHERIT_ELEMENT(AQH_OBJECT)
|
||||
GWEN_LIST_ELEMENT(AQH_OBJECT)
|
||||
|
||||
uint32_t flags;
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
|
||||
AQH_LINK_LIST *linkList;
|
||||
|
||||
AQH_OBJECT_SIGNALHANDLER_FN signalHandlerFn;
|
||||
AQH_OBJECT_ENABLE_FN enableFn;
|
||||
AQH_OBJECT_DISABLE_FN disableFn;
|
||||
|
||||
int refCount;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -70,7 +70,8 @@ void AQH_ConnectDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf,
|
||||
flags=AQH_Tag16IpcMsg_GetTagDataAsUint32(msg, AQH_MSGDATA_CONNECT_TAGS_FLAGS, 0);
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"CONNECT (code=%d, proto=%d, proto version=%d, clientId=%s, userId=%s, flags=%08x)\n",
|
||||
"CONNECT %s (code=%d, proto=%d, proto version=%d, clientId=%s, userId=%s, flags=%08x)\n",
|
||||
sText?sText:"",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg),
|
||||
|
||||
@@ -137,7 +137,8 @@ void AQH_DevicesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf,
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_DEVICES_MINSIZE) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"DEVICES (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
|
||||
"DEVICES %s (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
|
||||
sText?sText:"",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg),
|
||||
|
||||
@@ -68,7 +68,8 @@ void AQH_GetDataDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf,
|
||||
tsEnd=AQH_Tag16IpcMsg_GetTagDataAsUint64(msg, AQH_MSGDATA_GETDATA_TAGS_END, 0);
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"GETDATA (code=%d, proto=%d, proto version=%d, name=%s, tsBegin=%lu, tsEnd=%lu)\n",
|
||||
"GETDATA %s (code=%d, proto=%d, proto version=%d, name=%s, tsBegin=%lu, tsEnd=%lu)\n",
|
||||
sText?sText:"",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg),
|
||||
|
||||
@@ -139,7 +139,8 @@ void AQH_MultiDataDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf
|
||||
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"MULTIDATA (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d, datapoints=%u)\n",
|
||||
"MULTIDATA %s (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d, datapoints=%u)\n",
|
||||
sText?sText:"",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg),
|
||||
|
||||
@@ -92,7 +92,8 @@ void AQH_SetDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, cons
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_SET_MINSIZE) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"SET (code=%d, proto=%d, proto version=%d)\n",
|
||||
"SET %s (code=%d, proto=%d, proto version=%d)\n",
|
||||
sText?sText:"",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg));
|
||||
|
||||
@@ -139,7 +139,8 @@ void AQH_ValuesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, c
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_VALUES_MINSIZE) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"VALUES (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
|
||||
"VALUES %s (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
|
||||
sText?sText:"",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg),
|
||||
|
||||
@@ -37,7 +37,6 @@ GWEN_MSG *AQH_QwordsIpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
|
||||
uint32_t flags, const uint64_t *i64Ptr, int count)
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
uint8_t *ptr;
|
||||
int payloadSize;
|
||||
int i;
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ void AQH_Tag16IpcMsg_Extend(GWEN_MSG *msg)
|
||||
|
||||
|
||||
|
||||
void _freeData(void *bp, void *p)
|
||||
void _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQH_MSG_IPC_TAG16 *xmsg;
|
||||
|
||||
@@ -239,7 +239,8 @@ void AQH_Tag16IpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=GWEN_MSGIPC_OFFS_PAYLOAD) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"Tag16 (code=%d, proto=%d, proto version=%d)\n",
|
||||
"Tag16 %s (code=%d, proto=%d, proto version=%d)\n",
|
||||
sText?sText:"",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg));
|
||||
|
||||
105
aqhome/ipc2/0BUILD
Normal file
105
aqhome/ipc2/0BUILD
Normal file
@@ -0,0 +1,105 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<target type="ConvenienceLibrary" name="aqhipc2" >
|
||||
|
||||
<includes type="c" >
|
||||
$(gwenhywfar_cflags)
|
||||
-I$(topsrcdir)
|
||||
-I$(topbuilddir)
|
||||
</includes>
|
||||
|
||||
<includes type="tm2" >
|
||||
--include=$(builddir)
|
||||
--include=$(srcdir)
|
||||
</includes>
|
||||
|
||||
|
||||
<define name="BUILDING_AQHOME" />
|
||||
|
||||
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
||||
|
||||
|
||||
<setVar name="tm2flags" >
|
||||
--api=AQHOME_API
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/typefiles" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_sources" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_headers_pub">
|
||||
</setVar>
|
||||
|
||||
|
||||
<setVar name="local/built_headers_priv" >
|
||||
</setVar>
|
||||
|
||||
|
||||
<headers dist="false" install="$(pkgincludedir)/ipc" >
|
||||
$(local/built_headers_pub)
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/ipc" >
|
||||
msgreader.h
|
||||
msgwriter.h
|
||||
ipcmsgreader.h
|
||||
nodemsgreader.h
|
||||
ttyobject.h
|
||||
tcpd_object.h
|
||||
endpoint.h
|
||||
message.h
|
||||
msgrequest.h
|
||||
ipc_server.h
|
||||
tty_endpoint.h
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
msgreader_p.h
|
||||
msgwriter_p.h
|
||||
tcpd_object_p.h
|
||||
endpoint_p.h
|
||||
message_p.h
|
||||
msgrequest_p.h
|
||||
ipc_server_p.h
|
||||
</headers>
|
||||
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
|
||||
msgreader.c
|
||||
msgwriter.c
|
||||
ipcmsgreader.c
|
||||
nodemsgreader.c
|
||||
ttyobject.c
|
||||
tcpd_object.c
|
||||
endpoint.c
|
||||
message.c
|
||||
msgrequest.c
|
||||
ipc_server.c
|
||||
tty_endpoint.c
|
||||
</sources>
|
||||
|
||||
|
||||
<extradist>
|
||||
</extradist>
|
||||
|
||||
|
||||
<useTargets>
|
||||
</useTargets>
|
||||
|
||||
<subdirs>
|
||||
</subdirs>
|
||||
|
||||
|
||||
|
||||
|
||||
</target>
|
||||
|
||||
</gwbuild>
|
||||
305
aqhome/ipc2/endpoint.c
Normal file
305
aqhome/ipc2/endpoint.c
Normal file
@@ -0,0 +1,305 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./endpoint_p.h"
|
||||
#include "aqhome/ipc2/msgreader.h"
|
||||
#include "aqhome/ipc2/msgwriter.h"
|
||||
#include "aqhome/msg/node/m_node.h"
|
||||
|
||||
#include "aqhome/msg/node/m_device.h"
|
||||
#include "aqhome/msg/node/m_recvstats.h"
|
||||
#include "aqhome/msg/node/m_sendstats.h"
|
||||
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defs and enums
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
enum {
|
||||
AQH_ENDPOINT_SLOT_MSG_RECVD=1,
|
||||
AQH_ENDPOINT_SLOT_MSG_SENT
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* global vars
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
GWEN_INHERIT(AQH_OBJECT, AQH_ENDPOINT)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
|
||||
static int _handleMsgRecvd(AQH_OBJECT *o, int msgLen, const uint8_t *msgPtr);
|
||||
static int _handleMsgSent(AQH_OBJECT *o, int msgLen, const uint8_t *msgPtr);
|
||||
static void _dumpMsg(const AQH_MESSAGE *msg, const char *sText);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_Endpoint_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *msgReader, AQH_OBJECT *msgWriter)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
o=AQH_Object_new(eventLoop);
|
||||
GWEN_NEW_OBJECT(AQH_ENDPOINT, xo);
|
||||
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_ENDPOINT, o, xo, _freeData);
|
||||
|
||||
xo->msgOutList=AQH_Message_List_new();
|
||||
xo->msgInList=AQH_Message_List_new();
|
||||
|
||||
AQH_Object_SetSignalHandlerFn(o, _handleSignal);
|
||||
|
||||
if (msgReader) {
|
||||
xo->msgReader=msgReader;
|
||||
AQH_Object_AddLink(msgReader, AQH_MSG_READER_SIGNAL_MSGRECVD, AQH_ENDPOINT_SLOT_MSG_RECVD, o);
|
||||
}
|
||||
|
||||
if (msgWriter) {
|
||||
xo->msgWriter=msgWriter;
|
||||
AQH_Object_AddLink(msgWriter, AQH_MSG_WRITER_SIGNAL_MSGSENT, AQH_ENDPOINT_SLOT_MSG_SENT, o);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=(AQH_ENDPOINT*) p;
|
||||
AQH_Message_List_free(xo->msgOutList);
|
||||
AQH_Message_List_free(xo->msgInList);
|
||||
AQH_Object_free(xo->msgWriter);
|
||||
AQH_Object_free(xo->msgReader);
|
||||
GWEN_FREE_OBJECT(xo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgOutList(const AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo)
|
||||
return xo->msgOutList;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_Endpoint_GetNextMsgOut(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo)
|
||||
return AQH_Message_List_First(xo->msgOutList);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Endpoint_AddMsgOut(AQH_OBJECT *o, AQH_MESSAGE *msg)
|
||||
{
|
||||
if (o && msg) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo) {
|
||||
AQH_Message_List_Add(msg, xo->msgOutList);
|
||||
if (xo->msgWriter && AQH_Message_List_GetCount(xo->msgOutList)==1) {
|
||||
AQH_MsgWriter_SendMsg(xo->msgWriter, AQH_Message_GetMsgPointer(msg), AQH_Message_GetUsedSize(msg));
|
||||
AQH_Object_Enable(xo->msgWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgInList(const AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo)
|
||||
return xo->msgInList;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_Endpoint_GetNextMsgIn(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo)
|
||||
return AQH_Message_List_First(xo->msgInList);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Endpoint_AddMsgIn(AQH_OBJECT *o, AQH_MESSAGE *msg)
|
||||
{
|
||||
if (o && msg) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo) {
|
||||
AQH_Message_List_Add(msg, xo->msgInList);
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "now %d msgs in list", AQH_Message_List_GetCount(xo->msgInList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Endpoint_GetLastMessageId(const AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo)
|
||||
return xo->lastMsgId;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Endpoint_GetNextMessageId(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo)
|
||||
return ++(xo->lastMsgId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleSignal(AQH_OBJECT *o, uint32_t slotId, GWEN_UNUSED AQH_OBJECT *senderObject, int param1, void *param2)
|
||||
{
|
||||
switch(slotId) {
|
||||
case AQH_ENDPOINT_SLOT_MSG_RECVD: return _handleMsgRecvd(o, param1, param2);
|
||||
case AQH_ENDPOINT_SLOT_MSG_SENT: return _handleMsgSent(o, param1, param2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0; /* not handled */
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleMsgRecvd(AQH_OBJECT *o, int msgLen, const uint8_t *msgPtr)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Msg received:");
|
||||
msg=AQH_NodeMessage_fromBuffer(msgPtr, msgLen);
|
||||
_dumpMsg(msg, "Received");
|
||||
AQH_Endpoint_AddMsgIn(o, msg);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleMsgSent(AQH_OBJECT *o, int msgLen, const uint8_t *msgPtr)
|
||||
{
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Msg sent:");
|
||||
GWEN_Text_LogString((const char*) msgPtr, msgLen, AQH_LOGDOMAIN, GWEN_LoggerLevel_Error);
|
||||
|
||||
if (o) {
|
||||
AQH_ENDPOINT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||
if (xo) {
|
||||
AQH_MESSAGE *msg;
|
||||
|
||||
msg=AQH_Message_List_First(xo->msgOutList);
|
||||
if (msg) {
|
||||
/* remove sent message from list */
|
||||
AQH_Message_List_Del(msg);
|
||||
AQH_Message_free(msg);
|
||||
|
||||
/* get next message in list */
|
||||
msg=AQH_Message_List_First(xo->msgOutList);
|
||||
if (msg) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Sending next message");
|
||||
AQH_MsgWriter_SendMsg(xo->msgWriter, AQH_Message_GetMsgPointer(msg), AQH_Message_GetUsedSize(msg));
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Last message sent, disabling writer");
|
||||
AQH_Object_Disable(xo->msgWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _dumpMsg(const AQH_MESSAGE *msg, const char *sText)
|
||||
{
|
||||
if (msg) {
|
||||
GWEN_BUFFER *mbuf;
|
||||
|
||||
mbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
AQH_NodeMessage_DumpSpecificToBuffer(msg, mbuf, sText);
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "%s", GWEN_Buffer_GetStart(mbuf));
|
||||
GWEN_Buffer_free(mbuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
44
aqhome/ipc2/endpoint.h
Normal file
44
aqhome/ipc2/endpoint.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_ENDPOINT_H
|
||||
#define AQH_ENDPOINT_H
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Takes over ownership of msgReader and msgWriter, links signal AQH_MSG_READER_SIGNAL_MSGRECVD of msgReader
|
||||
* and signal AQH_MSG_WRITER_SIGNAL_MSGSENT of msgWriter to the newly created endpoint object.
|
||||
*
|
||||
* @param eventLoop pointer to event loop
|
||||
* @param msgReader pointer to message reader object (takes over ownership)
|
||||
* @param msgWriter pointer to message writer object (takes over ownership)
|
||||
*/
|
||||
AQHOME_API AQH_OBJECT *AQH_Endpoint_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *msgReader, AQH_OBJECT *msgWriter);
|
||||
|
||||
AQHOME_API AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgOutList(const AQH_OBJECT *o);
|
||||
AQHOME_API AQH_MESSAGE *AQH_Endpoint_GetNextMsgOut(AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_Endpoint_AddMsgOut(AQH_OBJECT *o, AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgInList(const AQH_OBJECT *o);
|
||||
AQHOME_API AQH_MESSAGE *AQH_Endpoint_GetNextMsgIn(AQH_OBJECT *o);
|
||||
AQHOME_API void AQH_Endpoint_AddMsgIn(AQH_OBJECT *o, AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API uint32_t AQH_Endpoint_GetLastMessageId(const AQH_OBJECT *o);
|
||||
AQHOME_API uint32_t AQH_Endpoint_GetNextMessageId(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
29
aqhome/ipc2/endpoint_p.h
Normal file
29
aqhome/ipc2/endpoint_p.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_ENDPOINT_P_H
|
||||
#define AQH_ENDPOINT_P_H
|
||||
|
||||
|
||||
#include "./endpoint.h"
|
||||
|
||||
typedef struct AQH_ENDPOINT AQH_ENDPOINT;
|
||||
|
||||
struct AQH_ENDPOINT {
|
||||
AQH_MESSAGE_LIST *msgOutList;
|
||||
AQH_MESSAGE_LIST *msgInList;
|
||||
AQH_OBJECT *msgWriter;
|
||||
AQH_OBJECT *msgReader;
|
||||
|
||||
uint32_t lastMsgId;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
146
aqhome/ipc2/ipc_server.c
Normal file
146
aqhome/ipc2/ipc_server.c
Normal file
@@ -0,0 +1,146 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./ipc_server_p.h"
|
||||
|
||||
#include <aqhome/ipc2/tcpd_object.h>
|
||||
#include <aqhome/ipc2/ipcmsgreader.h>
|
||||
#include <aqhome/ipc2/msgwriter.h>
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defs and enums
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
enum {
|
||||
AQH_IPCD_OBJECT_SLOT_NEWCONN=1
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* global vars
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
GWEN_INHERIT(AQH_OBJECT, AQH_IPC_SERVER)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
|
||||
static int _handleNewConn(AQH_OBJECT *o, int newFd);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_IpcServerObject_new(AQH_EVENT_LOOP *eventLoop, int fd)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
AQH_IPC_SERVER *xo;
|
||||
|
||||
o=AQH_Object_new(eventLoop);
|
||||
GWEN_NEW_OBJECT(AQH_IPC_SERVER, xo);
|
||||
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_IPC_SERVER, o, xo, _freeData);
|
||||
|
||||
AQH_Object_SetSignalHandlerFn(o, _handleSignal);
|
||||
|
||||
xo->tcpdObject=AQH_TcpdObject_new(eventLoop, fd);
|
||||
AQH_Object_AddLink(xo->tcpdObject, AQH_TCPD_OBJECT_SIGNAL_NEWCONN, AQH_IPCD_OBJECT_SLOT_NEWCONN, o);
|
||||
AQH_Object_Enable(xo->tcpdObject);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQH_IPC_SERVER *xo;
|
||||
|
||||
xo=(AQH_IPC_SERVER*) p;
|
||||
if (xo->tcpdObject) {
|
||||
AQH_Object_Disable(xo->tcpdObject);
|
||||
AQH_Object_free(xo->tcpdObject);
|
||||
xo->tcpdObject=NULL;
|
||||
}
|
||||
GWEN_FREE_OBJECT(xo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleSignal(AQH_OBJECT *o,
|
||||
uint32_t slotId,
|
||||
GWEN_UNUSED AQH_OBJECT *senderObject,
|
||||
int param1,
|
||||
GWEN_UNUSED void *param2)
|
||||
{
|
||||
switch(slotId) {
|
||||
case AQH_TCPD_OBJECT_SIGNAL_NEWCONN: return _handleNewConn(o, param1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0; /* not handled */
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleNewConn(AQH_OBJECT *o, int newFd)
|
||||
{
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
int fdCopy;
|
||||
AQH_OBJECT *fdReader;
|
||||
AQH_OBJECT *fdWriter;
|
||||
AQH_OBJECT *msgReader;
|
||||
AQH_OBJECT *msgWriter;
|
||||
AQH_OBJECT *endpoint;
|
||||
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Incoming connection");
|
||||
eventLoop=AQH_Object_GetEventLoop(o);
|
||||
fdCopy=dup(newFd);
|
||||
|
||||
fdReader=AQH_FdObject_new(eventLoop, newFd, AQH_FDOBJECT_FDMODE_READ);
|
||||
msgReader=AQH_IpcMsgReader_new(eventLoop, fdReader);
|
||||
|
||||
fdWriter=AQH_FdObject_new(eventLoop, fdCopy, AQH_FDOBJECT_FDMODE_WRITE);
|
||||
msgWriter=AQH_MsgWriter_new(eventLoop, fdWriter);
|
||||
|
||||
endpoint=AQH_Endpoint_new(eventLoop, msgReader, msgWriter);
|
||||
if (0==AQH_Object_EmitSignal(o, AQH_TCPD_OBJECT_SIGNAL_NEWCONN, 0, (void*) endpoint)) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "New connection not handled");
|
||||
AQH_Object_free(endpoint);
|
||||
}
|
||||
|
||||
return 1; /* msg handled */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
35
aqhome/ipc2/ipc_server.h
Normal file
35
aqhome/ipc2/ipc_server.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_IPC_SERVER_H
|
||||
#define AQH_IPC_SERVER_H
|
||||
|
||||
|
||||
#include <aqhome/ipc2/endpoint.h>
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
/** param2=pointer to endpoint object (see @ref AQH_Endpoint_new) */
|
||||
AQH_IPC_SERVER_SIGNAL_NEWCLIENT=AQH_OBJECT_SIGNAL_LAST
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param eventLoop pointer to eventLoop
|
||||
* @param fd socket to listen on (see @ref AQH_TcpdObject_new).
|
||||
*/
|
||||
AQHOME_API AQH_OBJECT *AQH_IpcServerObject_new(AQH_EVENT_LOOP *eventLoop, int fd);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
26
aqhome/ipc2/ipc_server_p.h
Normal file
26
aqhome/ipc2/ipc_server_p.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_IPC_SERVER_P_H
|
||||
#define AQH_IPC_SERVER_P_H
|
||||
|
||||
|
||||
#include "./ipc_server.h"
|
||||
|
||||
|
||||
|
||||
typedef struct AQH_IPC_SERVER AQH_IPC_SERVER;
|
||||
struct AQH_IPC_SERVER {
|
||||
AQH_OBJECT *tcpdObject;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
149
aqhome/ipc2/ipcmsgreader.c
Normal file
149
aqhome/ipc2/ipcmsgreader.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./ipcmsgreader.h"
|
||||
#include "./msgreader_p.h"
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endianfns.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
#define AQH_MSG_READER_HEADER_SIZE 4
|
||||
#define AQH_MSG_READER_MINMSGSIZE 12
|
||||
#define AQH_MSG_READER_MAXMSGSIZE 10240
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static int _readMsg(AQH_OBJECT *o);
|
||||
static int _readHeaderFromRingbuffer(AQH_MSG_READER *xo);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_IpcMsgReader_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *fdObject)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
|
||||
o=AQH_MsgReader_new(eventLoop, fdObject);
|
||||
AQH_MsgReader_SetReadMsgFn(o, _readMsg);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _readMsg(AQH_OBJECT *o)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=AQH_MsgReader_GetData(o);
|
||||
if (xo) {
|
||||
int rv;
|
||||
|
||||
if (xo->bytesReceived<AQH_MSG_READER_HEADER_SIZE) {
|
||||
rv=_readHeaderFromRingbuffer(xo);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (xo->bytesReceived>=AQH_MSG_READER_HEADER_SIZE) {
|
||||
/* reading remainder of msg directly into allocated buffer */
|
||||
rv=AQH_MsgReader_ReadRemainderFromRingbuffer(o);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
else if (rv==1) {
|
||||
int msgLen;
|
||||
uint8_t *msgPtr;
|
||||
|
||||
msgLen=xo->bytesReceived;
|
||||
msgPtr=xo->currentMsgBuf;
|
||||
|
||||
xo->bytesReceived=0;
|
||||
xo->bytesLeft=0;
|
||||
xo->currentMsgBuf=NULL;
|
||||
|
||||
rv=AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_MSGRECVD, msgLen, (void*) msgPtr);
|
||||
if (rv==0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Received message ignored");
|
||||
}
|
||||
free(msgPtr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _readHeaderFromRingbuffer(AQH_MSG_READER *xo)
|
||||
{
|
||||
uint32_t remaining;
|
||||
int rv;
|
||||
uint32_t xferSize;
|
||||
uint32_t bytesInBuffer;
|
||||
|
||||
bytesInBuffer=GWEN_RingBuffer_GetUsedBytes(xo->ringBuffer);
|
||||
|
||||
/* still reading header */
|
||||
remaining=AQH_MSG_READER_HEADER_SIZE-xo->bytesReceived;
|
||||
if (bytesInBuffer<remaining)
|
||||
remaining=bytesInBuffer;
|
||||
xferSize=remaining;
|
||||
rv=GWEN_RingBuffer_ReadBytes(xo->ringBuffer, (char*) (xo->headerBuffer+xo->bytesReceived), &xferSize);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Ringbuffer empty");
|
||||
return 0;
|
||||
}
|
||||
if (xferSize<remaining) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Read fewer bytes than available?");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
xo->bytesReceived+=xferSize;
|
||||
if (xo->bytesReceived==AQH_MSG_READER_HEADER_SIZE) {
|
||||
uint32_t msgLen;
|
||||
|
||||
/* full size received, parse msg size, allocate buffer */
|
||||
msgLen=GWEN_ENDIAN_LE32TOH(*((const uint32_t*)(xo->headerBuffer)));
|
||||
if (msgLen<AQH_MSG_READER_MINMSGSIZE || msgLen>AQH_MSG_READER_MAXMSGSIZE) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Bad message size(%lu)", (unsigned long int) msgLen);
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
xo->currentMsgBuf=(uint8_t*) malloc(msgLen+4); /* +4 because of msg len (4 bytes) */
|
||||
memmove(xo->currentMsgBuf, xo->headerBuffer, xo->bytesReceived);
|
||||
xo->bytesLeft=(msgLen+4)-xo->bytesReceived;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
20
aqhome/ipc2/ipcmsgreader.h
Normal file
20
aqhome/ipc2/ipcmsgreader.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_IPCMSGREADER_H
|
||||
#define AQH_IPCMSGREADER_H
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
|
||||
AQH_OBJECT *AQH_IpcMsgReader_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *fdObject);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
314
aqhome/ipc2/message.c
Normal file
314
aqhome/ipc2/message.c
Normal file
@@ -0,0 +1,314 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./message_p.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endianfns.h>
|
||||
|
||||
|
||||
|
||||
GWEN_LIST_FUNCTIONS(AQH_MESSAGE, AQH_Message)
|
||||
GWEN_INHERIT_FUNCTIONS(AQH_MESSAGE)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _ensureSize(AQH_MESSAGE *msg, uint32_t neededSize);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_Message_new(void)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_MESSAGE, msg);
|
||||
GWEN_INHERIT_INIT(AQH_MESSAGE, msg);
|
||||
GWEN_LIST_INIT(AQH_MESSAGE, msg);
|
||||
msg->refCount=1;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_IncRef(AQH_MESSAGE *msg)
|
||||
{
|
||||
if (msg && msg->refCount)
|
||||
msg->refCount++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_free(AQH_MESSAGE *msg)
|
||||
{
|
||||
if (msg && msg->refCount>0) {
|
||||
if (msg->refCount==1) {
|
||||
msg->refCount=0;
|
||||
GWEN_LIST_FINI(AQH_MESSAGE, msg);
|
||||
GWEN_INHERIT_FINI(AQH_MESSAGE, msg);
|
||||
free(msg->msgPointer);
|
||||
GWEN_FREE_OBJECT(msg);
|
||||
}
|
||||
else
|
||||
msg->refCount--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT *AQH_Message_GetObject(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return (msg && msg->refCount)?msg->object:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_SetObject(AQH_MESSAGE *msg, AQH_OBJECT *o)
|
||||
{
|
||||
if (msg && msg->refCount)
|
||||
msg->object=o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t *AQH_Message_GetMsgPointer(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return (msg && msg->refCount)?msg->msgPointer:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Message_GetMsgSize(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return (msg && msg->refCount)?msg->msgSize:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_SetData(AQH_MESSAGE *msg, const uint8_t *msgPtr, uint32_t msgSize)
|
||||
{
|
||||
if (msg && msg->refCount) {
|
||||
free(msg->msgPointer);
|
||||
msg->msgPointer=NULL;
|
||||
msg->msgSize=0;
|
||||
if (msgSize) {
|
||||
msg->msgPointer=(uint8_t*) malloc(msgSize);
|
||||
if (msg->msgPointer) {
|
||||
if (msgPtr)
|
||||
memmove(msg->msgPointer, msgPtr, msgSize);
|
||||
else
|
||||
memset(msg->msgPointer, 0, msgSize);
|
||||
msg->msgSize=msgSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Message_GetUsedSize(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return msg?msg->usedSize:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_SetUsedSize(AQH_MESSAGE *msg, uint32_t i)
|
||||
{
|
||||
if (msg) {
|
||||
_ensureSize(msg, i);
|
||||
msg->usedSize=i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_IncUsedSize(AQH_MESSAGE *msg, uint32_t i)
|
||||
{
|
||||
if (msg) {
|
||||
_ensureSize(msg, msg->usedSize+i);
|
||||
msg->usedSize+=i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void AQH_Message_WriteUint8At(AQH_MESSAGE *msg, uint32_t pos, uint8_t d)
|
||||
{
|
||||
if (msg) {
|
||||
_ensureSize(msg, pos+1);
|
||||
msg->msgPointer[pos]=d;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_Message_ReadUint8At(const AQH_MESSAGE *msg, uint32_t pos, uint8_t defaultValue)
|
||||
{
|
||||
if (msg && msg->msgPointer && msg->msgSize>=pos+1)
|
||||
return msg->msgPointer[pos];
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_WriteUint16At(AQH_MESSAGE *msg, uint32_t pos, uint16_t d)
|
||||
{
|
||||
if (msg) {
|
||||
_ensureSize(msg, pos+2);
|
||||
*( (uint16_t*) (msg->msgPointer+pos) )=GWEN_ENDIAN_HTOLE16(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_Message_ReadUint16At(const AQH_MESSAGE *msg, uint32_t pos, uint16_t defaultValue)
|
||||
{
|
||||
if (msg && msg->msgPointer && msg->msgSize>=pos+2)
|
||||
return GWEN_ENDIAN_LE16TOH(*( (uint16_t*) (msg->msgPointer+pos) ));
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_WriteUint32At(AQH_MESSAGE *msg, uint32_t pos, uint32_t d)
|
||||
{
|
||||
if (msg) {
|
||||
_ensureSize(msg, pos+4);
|
||||
*( (uint32_t*) (msg->msgPointer+pos) )=GWEN_ENDIAN_HTOLE32(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Message_ReadUint32At(const AQH_MESSAGE *msg, uint32_t pos, uint32_t defaultValue)
|
||||
{
|
||||
if (msg && msg->msgPointer && msg->msgSize>=pos+4)
|
||||
return GWEN_ENDIAN_LE32TOH(*( (uint32_t*) (msg->msgPointer+pos) ));
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_WriteUint64At(AQH_MESSAGE *msg, uint32_t pos, uint64_t d)
|
||||
{
|
||||
if (msg) {
|
||||
_ensureSize(msg, pos+8);
|
||||
*( (uint64_t*) (msg->msgPointer+pos) )=GWEN_ENDIAN_HTOLE64(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t AQH_Message_ReadUint64At(const AQH_MESSAGE *msg, uint32_t pos, uint64_t defaultValue)
|
||||
{
|
||||
if (msg && msg->msgPointer && msg->msgSize>=pos+8)
|
||||
return GWEN_ENDIAN_LE64TOH(*( (uint64_t*) (msg->msgPointer+pos) ));
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Message_WriteBytesAt(AQH_MESSAGE *msg, uint32_t pos, const uint8_t *bufferPtr, uint32_t bufferLen)
|
||||
{
|
||||
if (msg && bufferPtr && bufferLen) {
|
||||
_ensureSize(msg, pos+bufferLen);
|
||||
memmove(msg->msgPointer+pos, bufferPtr, bufferLen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Message_WriteStringAt(AQH_MESSAGE *msg, uint32_t pos, uint32_t maxSize, int filler, const char *s)
|
||||
{
|
||||
if (msg && maxSize) {
|
||||
uint32_t slen=0;
|
||||
|
||||
if (s) {
|
||||
slen=strlen(s);
|
||||
if (slen>maxSize) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "String too long (%d > %d)", slen, maxSize);
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
}
|
||||
_ensureSize(msg, pos+maxSize);
|
||||
if (s)
|
||||
memmove(msg->msgPointer+pos, s, slen);
|
||||
if (slen<maxSize)
|
||||
memset(msg->msgPointer+pos+slen, filler, maxSize-slen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Message_WriteStringWithTrailingNullAt(AQH_MESSAGE *msg, uint32_t pos, uint32_t maxSize, int filler, const char *s)
|
||||
{
|
||||
if (msg && maxSize) {
|
||||
uint32_t slen=1;
|
||||
|
||||
if (s) {
|
||||
slen=strlen(s)+1;
|
||||
if (slen>maxSize) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "String too long (%d > %d)", slen, maxSize);
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
}
|
||||
_ensureSize(msg, pos+maxSize);
|
||||
if (s)
|
||||
memmove(msg->msgPointer+pos, s, slen);
|
||||
if (slen<maxSize)
|
||||
memset(msg->msgPointer+pos+slen, filler, maxSize-slen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _ensureSize(AQH_MESSAGE *msg, uint32_t neededSize)
|
||||
{
|
||||
if (msg && neededSize) {
|
||||
if (msg->msgPointer==0 || msg->msgSize==0) {
|
||||
msg->msgPointer=(uint8_t*) malloc(neededSize);
|
||||
assert(msg->msgPointer);
|
||||
}
|
||||
else {
|
||||
if (neededSize>msg->msgSize) {
|
||||
uint8_t *ptr;
|
||||
|
||||
ptr=realloc(msg->msgPointer, neededSize);
|
||||
assert(ptr);
|
||||
if (ptr) {
|
||||
msg->msgPointer=ptr;
|
||||
msg->msgSize=neededSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
63
aqhome/ipc2/message.h
Normal file
63
aqhome/ipc2/message.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_MESSAGE_H
|
||||
#define AQH_MESSAGE_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/inherit.h>
|
||||
|
||||
|
||||
|
||||
typedef struct AQH_MESSAGE AQH_MESSAGE;
|
||||
GWEN_LIST_FUNCTION_LIB_DEFS(AQH_MESSAGE, AQH_Message, AQHOME_API)
|
||||
GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_MESSAGE, AQHOME_API)
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_Message_new(void);
|
||||
AQHOME_API void AQH_Message_IncRef(AQH_MESSAGE *msg);
|
||||
AQHOME_API void AQH_Message_free(AQH_MESSAGE *msg);
|
||||
|
||||
|
||||
/* unparsed data */
|
||||
AQHOME_API uint8_t *AQH_Message_GetMsgPointer(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint32_t AQH_Message_GetMsgSize(const AQH_MESSAGE *msg);
|
||||
AQHOME_API void AQH_Message_SetData(AQH_MESSAGE *msg, const uint8_t *msgPtr, uint32_t msgSize);
|
||||
|
||||
AQHOME_API uint32_t AQH_Message_GetUsedSize(const AQH_MESSAGE *msg);
|
||||
AQHOME_API void AQH_Message_SetUsedSize(AQH_MESSAGE *msg, uint32_t i);
|
||||
AQHOME_API void AQH_Message_IncUsedSize(AQH_MESSAGE *msg, uint32_t i);
|
||||
|
||||
/* helper functions for parsing */
|
||||
AQHOME_API void AQH_Message_WriteUint8At(AQH_MESSAGE *msg, uint32_t pos, uint8_t d);
|
||||
AQHOME_API uint8_t AQH_Message_ReadUint8At(const AQH_MESSAGE *msg, uint32_t pos, uint8_t defaultValue);
|
||||
|
||||
AQHOME_API void AQH_Message_WriteUint16At(AQH_MESSAGE *msg, uint32_t pos, uint16_t d);
|
||||
AQHOME_API uint16_t AQH_Message_ReadUint16At(const AQH_MESSAGE *msg, uint32_t pos, uint16_t defaultValue);
|
||||
|
||||
AQHOME_API void AQH_Message_WriteUint32At(AQH_MESSAGE *msg, uint32_t pos, uint32_t d);
|
||||
AQHOME_API uint32_t AQH_Message_ReadUint32At(const AQH_MESSAGE *msg, uint32_t pos, uint32_t defaultValue);
|
||||
|
||||
AQHOME_API void AQH_Message_WriteUint64At(AQH_MESSAGE *msg, uint32_t pos, uint64_t d);
|
||||
AQHOME_API uint64_t AQH_Message_ReadUint64At(const AQH_MESSAGE *msg, uint32_t pos, uint64_t defaultValue);
|
||||
|
||||
AQHOME_API void AQH_Message_WriteBytesAt(AQH_MESSAGE *msg, uint32_t pos, const uint8_t *bufferPtr, uint32_t bufferLen);
|
||||
AQHOME_API int AQH_Message_WriteStringAt(AQH_MESSAGE *msg, uint32_t pos, uint32_t maxSize, int filler, const char *s);
|
||||
AQHOME_API int AQH_Message_WriteStringWithTrailingNullAt(AQH_MESSAGE *msg, uint32_t pos, uint32_t maxSize, int filler, const char *s);
|
||||
|
||||
AQHOME_API AQH_OBJECT *AQH_Message_GetObject(const AQH_MESSAGE *msg);
|
||||
AQHOME_API void AQH_Message_SetObject(AQH_MESSAGE *msg, AQH_OBJECT *o);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
33
aqhome/ipc2/message_p.h
Normal file
33
aqhome/ipc2/message_p.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_MESSAGE_P_H
|
||||
#define AQH_MESSAGE_P_H
|
||||
|
||||
#include "./message.h"
|
||||
|
||||
|
||||
|
||||
struct AQH_MESSAGE {
|
||||
GWEN_INHERIT_ELEMENT(AQH_MESSAGE)
|
||||
GWEN_LIST_ELEMENT(AQH_MESSAGE)
|
||||
|
||||
int refCount;
|
||||
|
||||
/* unparsed data */
|
||||
uint8_t *msgPointer;
|
||||
uint32_t msgSize;
|
||||
uint32_t usedSize;
|
||||
|
||||
AQH_OBJECT *object;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
427
aqhome/ipc2/msgreader.c
Normal file
427
aqhome/ipc2/msgreader.c
Normal file
@@ -0,0 +1,427 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./msgreader_p.h"
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endianfns.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#define AQH_MSGREADER_SKIPTIME_IN_MS 20
|
||||
|
||||
#define AQH_MSGREADER_FLAGS_SKIP 0x0001
|
||||
|
||||
|
||||
|
||||
GWEN_INHERIT(AQH_OBJECT, AQH_MSG_READER)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
|
||||
static int _handleSocketReady(AQH_OBJECT *o, AQH_OBJECT *fdObject);
|
||||
static int _fillRingbuffer(AQH_OBJECT *o, AQH_MSG_READER *xo, AQH_OBJECT *fdObject);
|
||||
static void _handleSkipping(AQH_OBJECT *o, AQH_OBJECT *fdObject);
|
||||
static int _isStillSkipTime(AQH_MSG_READER *xo);
|
||||
static uint64_t _getTimeInMilliSeconds(void);
|
||||
static void _resetBuffers(AQH_MSG_READER *xo);
|
||||
static void _cbEnable(AQH_OBJECT *o);
|
||||
static void _cbDisable(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_MsgReader_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *fdObject)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
o=AQH_Object_new(eventLoop);
|
||||
GWEN_NEW_OBJECT(AQH_MSG_READER, xo);
|
||||
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_MSG_READER, o, xo, _freeData);
|
||||
xo->ringBuffer=GWEN_RingBuffer_new(AQH_MSG_READER_RINGBUFFER_SIZE);
|
||||
|
||||
AQH_Object_SetSignalHandlerFn(o, _handleSignal);
|
||||
AQH_Object_SetEnableFn(o, _cbEnable);
|
||||
AQH_Object_SetDisableFn(o, _cbDisable);
|
||||
|
||||
if (fdObject) {
|
||||
xo->fdObject=fdObject;
|
||||
AQH_Object_AddLink(xo->fdObject, AQH_FDOBJECT_SIGNAL_ISREADY, AQH_MSGREADER_SLOT_SOCKETREADY, o);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=(AQH_MSG_READER*) p;
|
||||
free(xo->currentMsgBuf);
|
||||
if (xo->fdObject) {
|
||||
AQH_Object_Disable(xo->fdObject);
|
||||
AQH_Object_free(xo->fdObject);
|
||||
xo->fdObject=NULL;
|
||||
}
|
||||
GWEN_FREE_OBJECT(xo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_MsgReader_GetFlags(const AQH_OBJECT *o)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
return xo?xo->flags:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgReader_SetFlags(AQH_OBJECT *o, uint32_t f)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo)
|
||||
xo->flags=f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgReader_AddFlags(AQH_OBJECT *o, uint32_t f)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo)
|
||||
xo->flags|=f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgReader_SubFlags(AQH_OBJECT *o, uint32_t f)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo)
|
||||
xo->flags&=~f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MSG_READER *AQH_MsgReader_GetData(const AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
return xo;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int _handleSignal(AQH_OBJECT *o,
|
||||
uint32_t slotId,
|
||||
AQH_OBJECT *senderObject,
|
||||
GWEN_UNUSED int param1,
|
||||
GWEN_UNUSED void *param2)
|
||||
{
|
||||
switch(slotId) {
|
||||
case AQH_MSGREADER_SLOT_SOCKETREADY: return _handleSocketReady(o, senderObject);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0; /* not handled */
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_MsgReader_ReadMsg(AQH_OBJECT *o)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo)
|
||||
return xo->readMsgFn(o);
|
||||
return GWEN_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MSG_READER_READMSG_FN AQH_MsgReader_SetReadMsgFn(AQH_OBJECT *o, AQH_MSG_READER_READMSG_FN f)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo) {
|
||||
AQH_MSG_READER_READMSG_FN oldFn;
|
||||
|
||||
oldFn=xo->readMsgFn;
|
||||
xo->readMsgFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleSocketReady(AQH_OBJECT *o, AQH_OBJECT *fdObject)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo) {
|
||||
int rv;
|
||||
|
||||
if (xo->flags & AQH_MSGREADER_FLAGS_SKIP) {
|
||||
if (_isStillSkipTime(xo)) {
|
||||
_handleSkipping(o, fdObject);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* read available data into ringbuffer */
|
||||
rv=_fillRingbuffer(o, xo, fdObject);
|
||||
if (rv<0) {
|
||||
if (rv!=GWEN_ERROR_TRY_AGAIN) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_ERROR, rv, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* read messages from ring buffer until buffer empty */
|
||||
do {
|
||||
rv=AQH_MsgReader_ReadMsg(o);
|
||||
} while (rv==1);
|
||||
if (rv<0) {
|
||||
AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_ERROR, rv, NULL);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgReader_StartSkipping(AQH_OBJECT *o)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Enter skip mode");
|
||||
GWEN_RingBuffer_Reset(xo->ringBuffer);
|
||||
_resetBuffers(xo);
|
||||
xo->flags|=AQH_MSGREADER_FLAGS_SKIP;
|
||||
xo->timestamp=_getTimeInMilliSeconds();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleSkipping(AQH_OBJECT *o, AQH_OBJECT *fdObject)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo) {
|
||||
int rv;
|
||||
|
||||
rv=AQH_FdObject_FlushInput(fdObject);
|
||||
if (rv<0) {
|
||||
AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_ERROR, rv, NULL);
|
||||
}
|
||||
else if (rv>0)
|
||||
xo->timestamp=_getTimeInMilliSeconds();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _isStillSkipTime(AQH_MSG_READER *xo)
|
||||
{
|
||||
uint64_t currentTime;
|
||||
uint64_t diffTime;
|
||||
|
||||
currentTime=_getTimeInMilliSeconds();
|
||||
diffTime=currentTime-xo->timestamp;
|
||||
if (diffTime>=AQH_MSGREADER_SKIPTIME_IN_MS) {
|
||||
xo->flags&=~AQH_MSGREADER_FLAGS_SKIP;
|
||||
GWEN_RingBuffer_Reset(xo->ringBuffer);
|
||||
_resetBuffers(xo);
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Leaving skip mode");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
xo->timestamp=currentTime;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _fillRingbuffer(AQH_OBJECT *o, AQH_MSG_READER *xo, AQH_OBJECT *fdObject)
|
||||
{
|
||||
while (1) {
|
||||
uint32_t len;
|
||||
|
||||
/* read data into ringbuffer */
|
||||
len=GWEN_RingBuffer_GetMaxUnsegmentedWrite(xo->ringBuffer);
|
||||
if (len>0) {
|
||||
int rv;
|
||||
|
||||
rv=AQH_FdObject_Read(fdObject, (uint8_t*) GWEN_RingBuffer_GetWritePointer(xo->ringBuffer), len);
|
||||
if (rv<0) {
|
||||
if (rv!=GWEN_ERROR_TRY_AGAIN) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
else if (rv==0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "EOF met");
|
||||
AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_CLOSED, 0, NULL);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
/* bytes received */
|
||||
GWEN_RingBuffer_SkipBytesWrite(xo->ringBuffer, rv);
|
||||
//return rv;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Ringbuffer full");
|
||||
/*return GWEN_ERROR_BUFFER_OVERFLOW;*/
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_MsgReader_ReadRemainderFromRingbuffer(AQH_OBJECT *o)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo) {
|
||||
uint32_t bytesInRingBuffer;
|
||||
uint32_t bytesToRead;
|
||||
int rv;
|
||||
|
||||
bytesInRingBuffer=GWEN_RingBuffer_GetUsedBytes(xo->ringBuffer);
|
||||
|
||||
/* still reading header */
|
||||
bytesToRead=xo->bytesLeft;
|
||||
if (bytesInRingBuffer<bytesToRead)
|
||||
bytesToRead=bytesInRingBuffer;
|
||||
if (bytesToRead) {
|
||||
uint32_t xferSize;
|
||||
|
||||
xferSize=bytesToRead;
|
||||
rv=GWEN_RingBuffer_ReadBytes(xo->ringBuffer, (char*) (xo->currentMsgBuf+xo->bytesReceived), &xferSize);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Ringbuffer empty");
|
||||
return 0;
|
||||
}
|
||||
if (xferSize<bytesToRead) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Read fewer bytes than available?");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
xo->bytesReceived+=xferSize;
|
||||
xo->bytesLeft-=xferSize;
|
||||
if (xo->bytesLeft==0) {
|
||||
/* msg finished */
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Message complete");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Not a MSGREADER object");
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t _getTimeInMilliSeconds(void)
|
||||
{
|
||||
struct timespec t ;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &t);
|
||||
return t.tv_sec*1000+(t.tv_nsec+500000)/1000000 ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _resetBuffers(AQH_MSG_READER *xo)
|
||||
{
|
||||
free(xo->currentMsgBuf);
|
||||
xo->currentMsgBuf=NULL;
|
||||
xo->bytesReceived=0;
|
||||
xo->bytesLeft=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbEnable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o && !(AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_ENABLED)) {
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo && xo->fdObject)
|
||||
AQH_Object_Enable(xo->fdObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbDisable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o && (AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_ENABLED)) {
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
|
||||
if (xo && xo->fdObject)
|
||||
AQH_Object_Disable(xo->fdObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
33
aqhome/ipc2/msgreader.h
Normal file
33
aqhome/ipc2/msgreader.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_MSGREADER_H
|
||||
#define AQH_MSGREADER_H
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
|
||||
enum {
|
||||
/** param1=msgSize, param2=msgPointer */
|
||||
AQH_MSG_READER_SIGNAL_MSGRECVD=AQH_OBJECT_SIGNAL_LAST,
|
||||
/** param1: error code */
|
||||
AQH_MSG_READER_SIGNAL_ERROR,
|
||||
AQH_MSG_READER_SIGNAL_CLOSED
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
AQH_MSGREADER_SLOT_SOCKETREADY=1
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
70
aqhome/ipc2/msgreader_p.h
Normal file
70
aqhome/ipc2/msgreader_p.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_MSGREADER_P_H
|
||||
#define AQH_MSGREADER_P_H
|
||||
|
||||
|
||||
#include "./msgreader.h"
|
||||
|
||||
#include <gwenhywfar/ringbuffer.h>
|
||||
|
||||
#define AQH_MSG_READER_RINGBUFFER_SIZE 1024
|
||||
#define AQH_MSG_READER_HEADERBUFFER_SIZE 32
|
||||
|
||||
|
||||
typedef struct AQH_MSG_READER AQH_MSG_READER;
|
||||
|
||||
/**
|
||||
* Read data for a message from the internal ring buffer.
|
||||
*
|
||||
* @return 1 if something has been done, 0 if not, negative on error
|
||||
* @param o object (THIS)
|
||||
*/
|
||||
typedef int (*AQH_MSG_READER_READMSG_FN)(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
struct AQH_MSG_READER {
|
||||
GWEN_RINGBUFFER *ringBuffer;
|
||||
|
||||
int bytesReceived;
|
||||
int bytesLeft;
|
||||
uint8_t headerBuffer[AQH_MSG_READER_HEADERBUFFER_SIZE];
|
||||
uint8_t *currentMsgBuf;
|
||||
|
||||
uint32_t flags;
|
||||
uint64_t timestamp;
|
||||
|
||||
AQH_OBJECT *fdObject;
|
||||
|
||||
AQH_MSG_READER_READMSG_FN readMsgFn;
|
||||
};
|
||||
|
||||
|
||||
AQH_OBJECT *AQH_MsgReader_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *fdObject);
|
||||
|
||||
AQH_MSG_READER *AQH_MsgReader_GetData(const AQH_OBJECT *o);
|
||||
int AQH_MsgReader_ReadRemainderFromRingbuffer(AQH_OBJECT *o);
|
||||
|
||||
int AQH_MsgReader_ReadMsg(AQH_OBJECT *o);
|
||||
AQH_MSG_READER_READMSG_FN AQH_MsgReader_SetReadMsgFn(AQH_OBJECT *o, AQH_MSG_READER_READMSG_FN f);
|
||||
|
||||
|
||||
uint32_t AQH_MsgReader_GetFlags(const AQH_OBJECT *o);
|
||||
void AQH_MsgReader_SetFlags(AQH_OBJECT *o, uint32_t f);
|
||||
void AQH_MsgReader_AddFlags(AQH_OBJECT *o, uint32_t f);
|
||||
void AQH_MsgReader_SubFlags(AQH_OBJECT *o, uint32_t f);
|
||||
|
||||
void AQH_MsgReader_StartSkipping(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
473
aqhome/ipc2/msgrequest.c
Normal file
473
aqhome/ipc2/msgrequest.c
Normal file
@@ -0,0 +1,473 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./msgrequest_p.h"
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
#include <aqhome/msg/ipc/m_ipc.h>
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
GWEN_INHERIT_FUNCTIONS(AQH_MSG_REQUEST)
|
||||
GWEN_TREE2_FUNCTIONS(AQH_MSG_REQUEST, AQH_MsgRequest)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _freeFinishedRequests(AQH_MSG_REQUEST *rq);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* code
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MSG_REQUEST *AQH_MsgRequest_new()
|
||||
{
|
||||
AQH_MSG_REQUEST *rq;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_MSG_REQUEST, rq);
|
||||
GWEN_INHERIT_INIT(AQH_MSG_REQUEST, rq);
|
||||
GWEN_TREE2_INIT(AQH_MSG_REQUEST, rq, AQH_MsgRequest);
|
||||
|
||||
return rq;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_free(AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
if (rq) {
|
||||
GWEN_TREE2_FINI(AQH_MSG_REQUEST, rq, AQH_MsgRequest);
|
||||
GWEN_INHERIT_FINI(AQH_MSG_REQUEST, rq);
|
||||
|
||||
GWEN_Timestamp_free(rq->expiresAt);
|
||||
GWEN_Timestamp_free(rq->createdAt);
|
||||
AQH_Message_free(rq->requestMsg);
|
||||
AQH_Message_List_free(rq->msgList);
|
||||
AQH_Object_free(rq->endpoint);
|
||||
|
||||
GWEN_FREE_OBJECT(rq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_MsgRequest_GetRequestType(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->requestType:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetRequestType(AQH_MSG_REQUEST *rq, int t)
|
||||
{
|
||||
if (rq)
|
||||
rq->requestType=t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_MsgRequest_GetRequestMsg(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->requestMsg:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetRequestMsg(AQH_MSG_REQUEST *rq, AQH_MESSAGE *msg)
|
||||
{
|
||||
if (rq) {
|
||||
AQH_Message_free(rq->requestMsg);
|
||||
rq->requestMsg=msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT *AQH_MsgRequest_GetEndpoint(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->endpoint:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetEndpoint(AQH_MSG_REQUEST *rq, AQH_OBJECT *ep)
|
||||
{
|
||||
if (rq) {
|
||||
if (ep)
|
||||
AQH_Object_IncRefCount(ep);
|
||||
if (rq->endpoint)
|
||||
AQH_Object_free(ep);
|
||||
rq->endpoint=ep;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_MsgRequest_GetRequestMsgId(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->requestMsgId:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetRequestMsgId(AQH_MSG_REQUEST *rq, uint32_t id)
|
||||
{
|
||||
if (rq)
|
||||
rq->requestMsgId=id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE_LIST *AQH_MsgRequest_GetMsgList(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->msgList:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_MsgRequest_GetFirstMsgFromList(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return (rq && rq->msgList)?AQH_Message_List_First(rq->msgList):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_AddMsgToList(AQH_MSG_REQUEST *rq, AQH_MESSAGE *msg)
|
||||
{
|
||||
if (rq && msg) {
|
||||
if (rq->msgList==NULL)
|
||||
rq->msgList=AQH_Message_List_new();
|
||||
AQH_Message_List_Add(msg, rq->msgList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const GWEN_TIMESTAMP *AQH_MsgRequest_GetCreatedAt(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->createdAt:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetCreatedAt(AQH_MSG_REQUEST *rq, GWEN_TIMESTAMP *ts)
|
||||
{
|
||||
if (rq) {
|
||||
GWEN_Timestamp_free(rq->createdAt);
|
||||
rq->createdAt=ts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const GWEN_TIMESTAMP *AQH_MsgRequest_GetExpiresAt(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->expiresAt:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetExpiresAt(AQH_MSG_REQUEST *rq, GWEN_TIMESTAMP *ts)
|
||||
{
|
||||
if (rq) {
|
||||
GWEN_Timestamp_free(rq->expiresAt);
|
||||
rq->expiresAt=ts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetTimestamps(AQH_MSG_REQUEST *rq, int expiresInSecs)
|
||||
{
|
||||
if (rq) {
|
||||
GWEN_TIMESTAMP *ts;
|
||||
|
||||
ts=GWEN_Timestamp_NowInLocalTime();
|
||||
GWEN_Timestamp_free(rq->createdAt);
|
||||
rq->createdAt=GWEN_Timestamp_dup(ts);
|
||||
GWEN_Timestamp_AddSeconds(ts, expiresInSecs);
|
||||
GWEN_Timestamp_free(rq->expiresAt);
|
||||
rq->expiresAt=ts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_MsgRequest_HandleResponse(AQH_MSG_REQUEST *rq, AQH_MESSAGE *msg)
|
||||
{
|
||||
if (rq && rq->handleResponseFn)
|
||||
return (rq->handleResponseFn)(rq, msg);
|
||||
return AQH_MSG_REQUEST_RESULT_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SubRequestFinished(AQH_MSG_REQUEST *rq, AQH_MSG_REQUEST *subRq, int reason)
|
||||
{
|
||||
if (rq && rq->subRequestFinishedFn)
|
||||
rq->subRequestFinishedFn(rq, subRq, reason);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_Abort(AQH_MSG_REQUEST *rq, int reason)
|
||||
{
|
||||
if (rq && rq->abortFn) {
|
||||
rq->abortFn(rq, reason);
|
||||
AQH_MsgRequest_SetState(rq, AQH_MSG_REQUEST_STATE_DONE);
|
||||
}
|
||||
else {
|
||||
AQH_MSG_REQUEST *rqParent;
|
||||
|
||||
AQH_MsgRequest_SetState(rq, AQH_MSG_REQUEST_STATE_DONE);
|
||||
rqParent=AQH_MsgRequest_Tree2_GetParent(rq);
|
||||
if (rqParent)
|
||||
AQH_MsgRequest_SubRequestFinished(rqParent, rq, AQH_MSG_REQUEST_REASON_ABORTED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MSG_REQUEST_HANDLERESPONSE_FN AQH_MsgRequest_SetHandleResponseFn(AQH_MSG_REQUEST *rq,
|
||||
AQH_MSG_REQUEST_HANDLERESPONSE_FN f)
|
||||
{
|
||||
if (rq) {
|
||||
AQH_MSG_REQUEST_HANDLERESPONSE_FN oldFn;
|
||||
|
||||
oldFn=rq->handleResponseFn;
|
||||
rq->handleResponseFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MSG_REQUEST_SUBREQUESTFINISHED_FN AQH_MsgRequest_SetSubRequestFinishedFn(AQH_MSG_REQUEST *rq,
|
||||
AQH_MSG_REQUEST_SUBREQUESTFINISHED_FN f)
|
||||
{
|
||||
if (rq) {
|
||||
AQH_MSG_REQUEST_SUBREQUESTFINISHED_FN oldFn;
|
||||
|
||||
oldFn=rq->subRequestFinishedFn;
|
||||
rq->subRequestFinishedFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MSG_REQUEST_ABORT_FN AQH_MsgRequest_SetAbortFn(AQH_MSG_REQUEST *rq, AQH_MSG_REQUEST_ABORT_FN f)
|
||||
{
|
||||
if (rq) {
|
||||
AQH_MSG_REQUEST_ABORT_FN oldFn;
|
||||
|
||||
oldFn=rq->abortFn;
|
||||
rq->abortFn=f;
|
||||
return oldFn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void *AQH_MsgRequest_GetPrivateData(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->privateData:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetPrivateData(AQH_MSG_REQUEST *rq, void *p)
|
||||
{
|
||||
if (rq)
|
||||
rq->privateData=p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_MsgRequest_GetResult(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->result:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetResult(AQH_MSG_REQUEST *rq, int result)
|
||||
{
|
||||
if (rq)
|
||||
rq->result=result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_MsgRequest_GetState(const AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
return rq?rq->state:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgRequest_SetState(AQH_MSG_REQUEST *rq, int i)
|
||||
{
|
||||
if (rq)
|
||||
rq->state=i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AQH_MSG_REQUEST *AQH_MsgRequest_Tree2_FindByEndpointAndMsgId(AQH_MSG_REQUEST *rootRq, AQH_OBJECT *ep, uint32_t refMsgId)
|
||||
{
|
||||
if (rootRq) {
|
||||
AQH_MSG_REQUEST *rq;
|
||||
|
||||
rq=AQH_MsgRequest_Tree2_GetFirstChild(rootRq);
|
||||
while(rq) {
|
||||
if (rq->endpoint==ep && rq->requestMsgId==refMsgId)
|
||||
return rq;
|
||||
rq=AQH_MsgRequest_Tree2_GetBelow(rq);
|
||||
} /* while */
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Request_Tree2_CheckTimeouts(AQH_MSG_REQUEST *rootRq)
|
||||
{
|
||||
if (rootRq) {
|
||||
AQH_MSG_REQUEST *rq;
|
||||
GWEN_TIMESTAMP *now;
|
||||
|
||||
now=GWEN_Timestamp_NowInLocalTime();
|
||||
rq=AQH_MsgRequest_Tree2_GetFirstChild(rootRq);
|
||||
while(rq) {
|
||||
const GWEN_TIMESTAMP *ts;
|
||||
|
||||
ts=AQH_MsgRequest_GetExpiresAt(rq);
|
||||
if (GWEN_Timestamp_Compare(now, ts)>=0) {
|
||||
/* timeout */
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Request timed out, aborting");
|
||||
AQH_MsgRequest_Abort(rq, AQH_MSG_REQUEST_REASON_TIMEOUT);
|
||||
}
|
||||
rq=AQH_MsgRequest_Tree2_GetBelow(rq);
|
||||
}
|
||||
GWEN_Timestamp_free(now);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Request_Tree2_Cleanup(AQH_MSG_REQUEST *rootRq)
|
||||
{
|
||||
if (rootRq) {
|
||||
AQH_MSG_REQUEST *rq;
|
||||
|
||||
rq=AQH_MsgRequest_Tree2_GetFirstChild(rootRq);
|
||||
while(rq) {
|
||||
AQH_MSG_REQUEST *nextSubRq;
|
||||
|
||||
nextSubRq=AQH_MsgRequest_Tree2_GetNext(rq);
|
||||
_freeFinishedRequests(rq);
|
||||
rq=nextSubRq;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Request_Tree2_HandleIpcMsg(AQH_MSG_REQUEST *rootRq, AQH_OBJECT *srcEp, AQH_MESSAGE *recvdMsg)
|
||||
{
|
||||
if (rootRq) {
|
||||
uint32_t refMsgId;
|
||||
|
||||
refMsgId=AQH_IpcMessage_GetRefMsgId(recvdMsg);
|
||||
if (refMsgId) {
|
||||
AQH_MSG_REQUEST *rq;
|
||||
|
||||
rq=AQH_MsgRequest_Tree2_GetFirstChild(rootRq);
|
||||
while(rq) {
|
||||
if (srcEp==AQH_MsgRequest_GetEndpoint(rq) && refMsgId==AQH_MsgRequest_GetRequestMsgId(rq)) {
|
||||
if (AQH_MsgRequest_HandleResponse(rq, recvdMsg)==AQH_MSG_REQUEST_RESULT_HANDLED)
|
||||
return AQH_MSG_REQUEST_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
rq=AQH_MsgRequest_Tree2_GetBelow(rq);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Message has no reference msg id, not a response");
|
||||
}
|
||||
}
|
||||
return AQH_MSG_REQUEST_RESULT_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Request_Tree2_HandleTtyMsg(AQH_MSG_REQUEST *rootRq, AQH_OBJECT *srcEp, AQH_MESSAGE *recvdMsg)
|
||||
{
|
||||
if (rootRq) {
|
||||
AQH_MSG_REQUEST *rq;
|
||||
|
||||
rq=AQH_MsgRequest_Tree2_GetFirstChild(rootRq);
|
||||
while(rq) {
|
||||
if (srcEp==AQH_MsgRequest_GetEndpoint(rq)) {
|
||||
if (AQH_MsgRequest_HandleResponse(rq, recvdMsg)==AQH_MSG_REQUEST_RESULT_HANDLED)
|
||||
return AQH_MSG_REQUEST_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
rq=AQH_MsgRequest_Tree2_GetBelow(rq);
|
||||
}
|
||||
}
|
||||
return AQH_MSG_REQUEST_RESULT_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _freeFinishedRequests(AQH_MSG_REQUEST *rq)
|
||||
{
|
||||
AQH_MSG_REQUEST *subRq;
|
||||
|
||||
subRq=AQH_MsgRequest_Tree2_GetFirstChild(rq);
|
||||
while(subRq) {
|
||||
AQH_MSG_REQUEST *nextSubRq;
|
||||
|
||||
nextSubRq=AQH_MsgRequest_Tree2_GetNext(subRq);
|
||||
_freeFinishedRequests(subRq);
|
||||
subRq=nextSubRq;
|
||||
}
|
||||
|
||||
if (AQH_MsgRequest_GetState(rq)==AQH_MSG_REQUEST_STATE_DONE) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Deleting request");
|
||||
AQH_MsgRequest_free(rq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
104
aqhome/ipc2/msgrequest.h
Normal file
104
aqhome/ipc2/msgrequest.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project Gwenhywfar.
|
||||
* Gwenhywfar (c) by 2023 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 AQH_MSGREQUEST_H
|
||||
#define AQH_MSGREQUEST_H
|
||||
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/tree2.h>
|
||||
#include <gwenhywfar/timestamp.h>
|
||||
|
||||
|
||||
#define AQH_MSG_REQUEST_RESULT_NOT_HANDLED 0
|
||||
#define AQH_MSG_REQUEST_RESULT_HANDLED 1
|
||||
|
||||
#define AQH_MSG_REQUEST_REASON_DONE 0
|
||||
#define AQH_MSG_REQUEST_REASON_ABORTED 1
|
||||
#define AQH_MSG_REQUEST_REASON_TIMEOUT 2
|
||||
#define AQH_MSG_REQUEST_REASON_DISCONNECT 3
|
||||
|
||||
#define AQH_MSG_REQUEST_STATE_OPEN 0
|
||||
#define AQH_MSG_REQUEST_STATE_DONE 1
|
||||
|
||||
|
||||
|
||||
typedef struct AQH_MSG_REQUEST AQH_MSG_REQUEST;
|
||||
|
||||
GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_MSG_REQUEST, AQHOME_API)
|
||||
GWEN_TREE2_FUNCTION_LIB_DEFS(AQH_MSG_REQUEST, AQH_MsgRequest, AQHOME_API)
|
||||
|
||||
typedef int (*AQH_MSG_REQUEST_HANDLERESPONSE_FN)(AQH_MSG_REQUEST *rq, AQH_MESSAGE *msg);
|
||||
typedef void (*AQH_MSG_REQUEST_SUBREQUESTFINISHED_FN)(AQH_MSG_REQUEST *rq, AQH_MSG_REQUEST *subRq, int reason);
|
||||
typedef void (*AQH_MSG_REQUEST_ABORT_FN)(AQH_MSG_REQUEST *rq, int reason);
|
||||
|
||||
|
||||
AQHOME_API AQH_MSG_REQUEST *AQH_MsgRequest_new();
|
||||
AQHOME_API void AQH_MsgRequest_free(AQH_MSG_REQUEST *rq);
|
||||
|
||||
AQHOME_API int AQH_MsgRequest_GetRequestType(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetRequestType(AQH_MSG_REQUEST *rq, int t);
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_MsgRequest_GetRequestMsg(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetRequestMsg(AQH_MSG_REQUEST *rq, AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API AQH_OBJECT *AQH_MsgRequest_GetEndpoint(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetEndpoint(AQH_MSG_REQUEST *rq, AQH_OBJECT *ep);
|
||||
|
||||
AQHOME_API uint32_t AQH_MsgRequest_GetRequestMsgId(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetRequestMsgId(AQH_MSG_REQUEST *rq, uint32_t id);
|
||||
|
||||
AQHOME_API AQH_MESSAGE_LIST *AQH_MsgRequest_GetMsgList(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API AQH_MESSAGE *AQH_MsgRequest_GetFirstMsgFromList(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_AddMsgToList(AQH_MSG_REQUEST *rq, AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API const GWEN_TIMESTAMP *AQH_MsgRequest_GetCreatedAt(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetCreatedAt(AQH_MSG_REQUEST *rq, GWEN_TIMESTAMP *ts);
|
||||
|
||||
AQHOME_API const GWEN_TIMESTAMP *AQH_MsgRequest_GetExpiresAt(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetExpiresAt(AQH_MSG_REQUEST *rq, GWEN_TIMESTAMP *ts);
|
||||
|
||||
AQHOME_API void AQH_MsgRequest_SetTimestamps(AQH_MSG_REQUEST *rq, int expiresInSecs);
|
||||
|
||||
AQHOME_API int AQH_MsgRequest_GetResult(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetResult(AQH_MSG_REQUEST *rq, int result);
|
||||
|
||||
AQHOME_API int AQH_MsgRequest_GetState(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetState(AQH_MSG_REQUEST *rq, int i);
|
||||
|
||||
|
||||
AQHOME_API int AQH_MsgRequest_HandleResponse(AQH_MSG_REQUEST *rq, AQH_MESSAGE *msg);
|
||||
AQHOME_API void AQH_MsgRequest_SubRequestFinished(AQH_MSG_REQUEST *rq, AQH_MSG_REQUEST *subRq, int reason);
|
||||
AQHOME_API void AQH_MsgRequest_Abort(AQH_MSG_REQUEST *rq, int reason);
|
||||
|
||||
|
||||
|
||||
AQHOME_API void *AQH_MsgRequest_GetPrivateData(const AQH_MSG_REQUEST *rq);
|
||||
AQHOME_API void AQH_MsgRequest_SetPrivateData(AQH_MSG_REQUEST *rq, void *p);
|
||||
|
||||
AQHOME_API AQH_MSG_REQUEST_HANDLERESPONSE_FN AQH_MsgRequest_SetHandleResponseFn(AQH_MSG_REQUEST *rq,
|
||||
AQH_MSG_REQUEST_HANDLERESPONSE_FN fn);
|
||||
|
||||
AQHOME_API AQH_MSG_REQUEST_SUBREQUESTFINISHED_FN AQH_MsgRequest_SetSubRequestFinishedFn(AQH_MSG_REQUEST *rq,
|
||||
AQH_MSG_REQUEST_SUBREQUESTFINISHED_FN f);
|
||||
AQHOME_API AQH_MSG_REQUEST_ABORT_FN AQH_MsgRequest_SetAbortFn(AQH_MSG_REQUEST *rq, AQH_MSG_REQUEST_ABORT_FN f);
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MSG_REQUEST *AQH_MsgRequest_Tree2_FindByEndpointAndMsgId(AQH_MSG_REQUEST *rootRq, AQH_OBJECT *ep, uint32_t refMsgId);
|
||||
AQHOME_API void AQH_Request_Tree2_CheckTimeouts(AQH_MSG_REQUEST *rootRq);
|
||||
AQHOME_API void AQH_Request_Tree2_Cleanup(AQH_MSG_REQUEST *rootRq);
|
||||
AQHOME_API int AQH_Request_Tree2_HandleIpcMsg(AQH_MSG_REQUEST *rootRq, AQH_OBJECT *srcEp, AQH_MESSAGE *recvdMsg);
|
||||
AQHOME_API int AQH_Request_Tree2_HandleTtyMsg(AQH_MSG_REQUEST *rootRq, AQH_OBJECT *srcEp, AQH_MESSAGE *recvdMsg);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
45
aqhome/ipc2/msgrequest_p.h
Normal file
45
aqhome/ipc2/msgrequest_p.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project Gwenhywfar.
|
||||
* Gwenhywfar (c) by 2023 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 AQH_MSGREQUEST_P_H
|
||||
#define AQH_MSGREQUEST_P_H
|
||||
|
||||
#include "./msgrequest.h"
|
||||
|
||||
|
||||
|
||||
struct AQH_MSG_REQUEST {
|
||||
GWEN_INHERIT_ELEMENT(AQH_MSG_REQUEST)
|
||||
GWEN_TREE2_ELEMENT(AQH_MSG_REQUEST)
|
||||
|
||||
int requestType;
|
||||
AQH_MESSAGE *requestMsg; /* msg this request is based on */
|
||||
AQH_OBJECT *endpoint; /* source/dest endpoint for this request */
|
||||
uint32_t requestMsgId;
|
||||
|
||||
AQH_MESSAGE_LIST *msgList;
|
||||
|
||||
GWEN_TIMESTAMP *createdAt;
|
||||
GWEN_TIMESTAMP *expiresAt;
|
||||
|
||||
AQH_MSG_REQUEST_HANDLERESPONSE_FN handleResponseFn;
|
||||
AQH_MSG_REQUEST_SUBREQUESTFINISHED_FN subRequestFinishedFn;
|
||||
AQH_MSG_REQUEST_ABORT_FN abortFn;
|
||||
|
||||
void *privateData;
|
||||
|
||||
int state;
|
||||
int result;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
245
aqhome/ipc2/msgwriter.c
Normal file
245
aqhome/ipc2/msgwriter.c
Normal file
@@ -0,0 +1,245 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./msgwriter_p.h"
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endianfns.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
#define AQH_MSGWRITER_FLAGS_MSGSTARTED 0x0001
|
||||
|
||||
|
||||
|
||||
GWEN_INHERIT(AQH_OBJECT, AQH_MSG_WRITER)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
|
||||
static int _handleSocketReady(AQH_OBJECT *o, AQH_OBJECT *fdObject);
|
||||
static int _startMsg(AQH_MSG_WRITER *xo, AQH_OBJECT *fdObject);
|
||||
static void _endMsg(AQH_MSG_WRITER *xo, AQH_OBJECT *fdObject);
|
||||
static void _resetBuffer(AQH_OBJECT *o);
|
||||
static void _cbEnable(AQH_OBJECT *o);
|
||||
static void _cbDisable(AQH_OBJECT *o);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_MsgWriter_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *fdObject)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
AQH_MSG_WRITER *xo;
|
||||
|
||||
o=AQH_Object_new(eventLoop);
|
||||
GWEN_NEW_OBJECT(AQH_MSG_WRITER, xo);
|
||||
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_MSG_WRITER, o, xo, _freeData);
|
||||
|
||||
AQH_Object_SetSignalHandlerFn(o, _handleSignal);
|
||||
AQH_Object_SetEnableFn(o, _cbEnable);
|
||||
AQH_Object_SetDisableFn(o, _cbDisable);
|
||||
|
||||
if (fdObject) {
|
||||
xo->fdObject=fdObject;
|
||||
AQH_Object_AddLink(xo->fdObject, AQH_FDOBJECT_SIGNAL_ISREADY, AQH_MSGWRITER_SLOT_SOCKETREADY, o);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQH_MSG_WRITER *xo;
|
||||
|
||||
xo=(AQH_MSG_WRITER*) p;
|
||||
if (xo->fdObject) {
|
||||
AQH_Object_Disable(xo->fdObject);
|
||||
AQH_Object_free(xo->fdObject);
|
||||
xo->fdObject=NULL;
|
||||
}
|
||||
GWEN_FREE_OBJECT(xo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgWriter_SendMsg(AQH_OBJECT *o, const uint8_t *ptr, int len)
|
||||
{
|
||||
if (o) {
|
||||
AQH_MSG_WRITER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_WRITER, o);
|
||||
if (xo) {
|
||||
_resetBuffer(o);
|
||||
if (ptr && len) {
|
||||
xo->msgBufPtr=ptr;
|
||||
xo->msgBufLen=len;
|
||||
}
|
||||
xo->bytesLeft=xo->msgBufLen;
|
||||
xo->currentPtr=xo->msgBufPtr;
|
||||
xo->flags&=~AQH_MSGWRITER_FLAGS_MSGSTARTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleSignal(AQH_OBJECT *o,
|
||||
uint32_t slotId,
|
||||
GWEN_UNUSED AQH_OBJECT *senderObject,
|
||||
GWEN_UNUSED int param1,
|
||||
GWEN_UNUSED void *param2)
|
||||
{
|
||||
switch(slotId) {
|
||||
case AQH_MSGWRITER_SLOT_SOCKETREADY: return _handleSocketReady(o, senderObject);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0; /* not handled */
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleSocketReady(AQH_OBJECT *o, AQH_OBJECT *fdObject)
|
||||
{
|
||||
AQH_MSG_WRITER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_WRITER, o);
|
||||
if (xo) {
|
||||
if (xo->bytesLeft) {
|
||||
int rv;
|
||||
|
||||
if (!(xo->flags & AQH_MSGWRITER_FLAGS_MSGSTARTED)) {
|
||||
rv=_startMsg(xo, fdObject);
|
||||
if (rv<0) {
|
||||
if (rv==GWEN_ERROR_TRY_AGAIN) {
|
||||
/* line is busy */
|
||||
}
|
||||
else {
|
||||
_endMsg(xo, fdObject);
|
||||
AQH_Object_EmitSignal(o, AQH_MSG_WRITER_SIGNAL_ERROR, rv, NULL);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
rv=AQH_FdObject_Write(fdObject, xo->currentPtr, xo->bytesLeft);
|
||||
if (rv>0) {
|
||||
xo->currentPtr+=rv;
|
||||
xo->bytesLeft-=rv;
|
||||
}
|
||||
} while (rv>0 && xo->bytesLeft>0);
|
||||
if (rv<0 && rv!=GWEN_ERROR_TRY_AGAIN) {
|
||||
_endMsg(xo, fdObject);
|
||||
AQH_Object_EmitSignal(o, AQH_MSG_WRITER_SIGNAL_ERROR, rv, NULL);
|
||||
}
|
||||
else {
|
||||
if (xo->bytesLeft==0) {
|
||||
_endMsg(xo, fdObject);
|
||||
rv=AQH_Object_EmitSignal(o, AQH_MSG_WRITER_SIGNAL_MSGSENT, xo->msgBufLen, (void*) (xo->msgBufPtr));
|
||||
if (rv==0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Sent message ignored");
|
||||
}
|
||||
_resetBuffer(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _startMsg(AQH_MSG_WRITER *xo, AQH_OBJECT *fdObject)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv=AQH_FdObject_StartMsg(fdObject);
|
||||
if (rv<0) {
|
||||
/* line is busy */
|
||||
return rv;
|
||||
}
|
||||
xo->flags|=AQH_MSGWRITER_FLAGS_MSGSTARTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _endMsg(AQH_MSG_WRITER *xo, AQH_OBJECT *fdObject)
|
||||
{
|
||||
xo->flags&=~AQH_MSGWRITER_FLAGS_MSGSTARTED;
|
||||
AQH_FdObject_EndMsg(fdObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _resetBuffer(AQH_OBJECT *o)
|
||||
{
|
||||
AQH_MSG_WRITER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_WRITER, o);
|
||||
if (xo) {
|
||||
xo->msgBufPtr=NULL;
|
||||
xo->msgBufLen=0;
|
||||
xo->currentPtr=NULL;
|
||||
xo->bytesLeft=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbEnable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_MSG_WRITER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_WRITER, o);
|
||||
if (xo && xo->fdObject)
|
||||
AQH_Object_Enable(xo->fdObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbDisable(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
AQH_MSG_WRITER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_WRITER, o);
|
||||
if (xo && xo->fdObject)
|
||||
AQH_Object_Disable(xo->fdObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
38
aqhome/ipc2/msgwriter.h
Normal file
38
aqhome/ipc2/msgwriter.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_MSGWRITER_H
|
||||
#define AQH_MSGWRITER_H
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
|
||||
enum {
|
||||
/** param1=msgSize, param2=msgPointer */
|
||||
AQH_MSG_WRITER_SIGNAL_MSGSENT=AQH_OBJECT_SIGNAL_LAST,
|
||||
/** param1: error code */
|
||||
AQH_MSG_WRITER_SIGNAL_ERROR,
|
||||
AQH_MSG_WRITER_SIGNAL_CLOSED
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
AQH_MSGWRITER_SLOT_SOCKETREADY=1
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT *AQH_MsgWriter_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *fdObject);
|
||||
|
||||
|
||||
void AQH_MsgWriter_SendMsg(AQH_OBJECT *o, const uint8_t *ptr, int len);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
34
aqhome/ipc2/msgwriter_p.h
Normal file
34
aqhome/ipc2/msgwriter_p.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_MSGWRITER_P_H
|
||||
#define AQH_MSGWRITER_P_H
|
||||
|
||||
|
||||
#include "./msgwriter.h"
|
||||
|
||||
|
||||
|
||||
typedef struct AQH_MSG_WRITER AQH_MSG_WRITER;
|
||||
struct AQH_MSG_WRITER {
|
||||
int msgBufLen;
|
||||
const uint8_t *msgBufPtr;
|
||||
|
||||
int bytesLeft;
|
||||
const uint8_t *currentPtr;
|
||||
|
||||
uint32_t flags;
|
||||
|
||||
AQH_OBJECT *fdObject;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
185
aqhome/ipc2/nodemsgreader.c
Normal file
185
aqhome/ipc2/nodemsgreader.c
Normal file
@@ -0,0 +1,185 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./nodemsgreader.h"
|
||||
#include "./msgreader_p.h"
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endianfns.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* definitions
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define AQH_MSG_READER_HEADER_SIZE 2
|
||||
#define AQH_MSG_READER_MAXMSGSIZE 32
|
||||
|
||||
#define AQH_MSG_READER_FLAG_SKIPPING 0x0001
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static int _readMsg(AQH_OBJECT *o);
|
||||
static int _readHeaderFromRingbuffer(AQH_OBJECT *o, AQH_MSG_READER *xo);
|
||||
static uint8_t _calcCrc8Checksum(const uint8_t *ptr, uint8_t len);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_NodeMsgReader_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *fdObject)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
|
||||
o=AQH_MsgReader_new(eventLoop, fdObject);
|
||||
AQH_MsgReader_SetReadMsgFn(o, _readMsg);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _readMsg(AQH_OBJECT *o)
|
||||
{
|
||||
AQH_MSG_READER *xo;
|
||||
|
||||
xo=AQH_MsgReader_GetData(o);
|
||||
if (xo) {
|
||||
int rv;
|
||||
|
||||
if (xo->bytesReceived<AQH_MSG_READER_HEADER_SIZE) {
|
||||
rv=_readHeaderFromRingbuffer(o, xo);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (xo->bytesReceived>=AQH_MSG_READER_HEADER_SIZE) {
|
||||
/* reading remainder of msg directly into allocated buffer */
|
||||
rv=AQH_MsgReader_ReadRemainderFromRingbuffer(o);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
else if (rv==1) {
|
||||
int msgLen;
|
||||
uint8_t *msgPtr;
|
||||
|
||||
msgLen=xo->bytesReceived;
|
||||
msgPtr=xo->currentMsgBuf;
|
||||
|
||||
xo->bytesReceived=0;
|
||||
xo->bytesLeft=0;
|
||||
xo->currentMsgBuf=NULL;
|
||||
|
||||
if (_calcCrc8Checksum(msgPtr, msgLen)==0) {
|
||||
rv=AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_MSGRECVD, msgLen, (void*) msgPtr);
|
||||
if (rv==0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Received message ignored");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Bad CRC");
|
||||
AQH_MsgReader_StartSkipping(o);
|
||||
}
|
||||
free(msgPtr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _readHeaderFromRingbuffer(AQH_OBJECT *o, AQH_MSG_READER *xo)
|
||||
{
|
||||
uint32_t remaining;
|
||||
int rv;
|
||||
uint32_t xferSize;
|
||||
uint32_t bytesInBuffer;
|
||||
|
||||
bytesInBuffer=GWEN_RingBuffer_GetUsedBytes(xo->ringBuffer);
|
||||
|
||||
/* still reading header */
|
||||
remaining=AQH_MSG_READER_HEADER_SIZE-xo->bytesReceived;
|
||||
if (bytesInBuffer<remaining)
|
||||
remaining=bytesInBuffer;
|
||||
xferSize=remaining;
|
||||
rv=GWEN_RingBuffer_ReadBytes(xo->ringBuffer, (char*) (xo->headerBuffer+xo->bytesReceived), &xferSize);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Ringbuffer empty");
|
||||
return 0;
|
||||
}
|
||||
if (xferSize<remaining) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Read fewer bytes than available?");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
xo->bytesReceived+=xferSize;
|
||||
if (xo->bytesReceived==AQH_MSG_READER_HEADER_SIZE) {
|
||||
uint32_t msgLen;
|
||||
|
||||
/* full size received, parse msg size, allocate buffer */
|
||||
msgLen=xo->headerBuffer[1];
|
||||
if (msgLen>AQH_MSG_READER_MAXMSGSIZE) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Bad message size(%lu)", (unsigned long int) msgLen);
|
||||
AQH_MsgReader_StartSkipping(o);
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
xo->currentMsgBuf=(uint8_t*) malloc(msgLen+3); /* +3 (dest addr, msg len, crc) */
|
||||
memmove(xo->currentMsgBuf, xo->headerBuffer, xo->bytesReceived);
|
||||
xo->bytesLeft=(msgLen+3)-xo->bytesReceived;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t _calcCrc8Checksum(const uint8_t *ptr, uint8_t len)
|
||||
{
|
||||
int i;
|
||||
uint8_t x=0xff;
|
||||
|
||||
for (i=0; i<len; i++, ptr++) {
|
||||
int j;
|
||||
|
||||
x^=*ptr;
|
||||
for (j=0; j<8; j++) {
|
||||
if (x & 0x80)
|
||||
x=(uint8_t) (x<<1)^0x97;
|
||||
else
|
||||
x<<=1;
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
20
aqhome/ipc2/nodemsgreader.h
Normal file
20
aqhome/ipc2/nodemsgreader.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_NODEMSGREADER_H
|
||||
#define AQH_NODEMSGREADER_H
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
|
||||
AQHOME_API AQH_OBJECT *AQH_NodeMsgReader_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *fdObject);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
333
aqhome/ipc2/tcpd_object.c
Normal file
333
aqhome/ipc2/tcpd_object.c
Normal file
@@ -0,0 +1,333 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./tcpd_object_p.h"
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define MAX_BACKLOG 10
|
||||
|
||||
|
||||
enum {
|
||||
AQH_TCPD_OBJECT_SLOT_SOCKETREADY=1
|
||||
};
|
||||
|
||||
|
||||
GWEN_INHERIT(AQH_OBJECT, AQH_TCPD_OBJECT)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
|
||||
static int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
|
||||
static int _handleSocketReady(AQH_OBJECT *o);
|
||||
|
||||
static int _socketSetReuseAddress(int sk, int fl);
|
||||
static int _socketSetBlocking(int sk, int fl);
|
||||
static int _translateHError(int herr);
|
||||
static int _setHostAddr(struct in_addr *inetAddr, const char *sAddr);
|
||||
static int _setHostName(struct in_addr *inetAddr, const char *sAddr);
|
||||
static int _acceptConnection(int serverSocket);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_TcpdObject_new(AQH_EVENT_LOOP *eventLoop, int fd)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
AQH_TCPD_OBJECT *xo;
|
||||
|
||||
o=AQH_Object_new(eventLoop);
|
||||
GWEN_NEW_OBJECT(AQH_TCPD_OBJECT, xo);
|
||||
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_TCPD_OBJECT, o, xo, _freeData);
|
||||
AQH_Object_SetSignalHandlerFn(o, _handleSignal);
|
||||
|
||||
xo->fdSocket=fd;
|
||||
xo->fdObject=AQH_FdObject_new(eventLoop, fd, AQH_FDOBJECT_FDMODE_READ);
|
||||
|
||||
#if 0
|
||||
/* create object for readable socket, connect to THIS, enable */
|
||||
xo->fdObject=AQH_FdObject_new(AQH_Object_GetEventLoop(o), rv, AQH_FDOBJECT_FDMODE_READ);
|
||||
AQH_Object_AddLink(xo->fdObject, AQH_FDOBJECT_SIGNAL_ISREADY, AQH_TCPD_OBJECT_SLOT_SOCKETREADY, o);
|
||||
AQH_Object_Enable(xo->fdObject);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQH_TCPD_OBJECT *xo;
|
||||
|
||||
xo=(AQH_TCPD_OBJECT*) p;
|
||||
if (xo->fdObject) {
|
||||
AQH_Object_Disable(xo->fdObject);
|
||||
AQH_Object_free(xo->fdObject);
|
||||
}
|
||||
GWEN_FREE_OBJECT(xo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_TcpdObject_CreateListeningSocket(const char *addr, int port)
|
||||
{
|
||||
int sk;
|
||||
struct sockaddr_in inetAddr;
|
||||
int rv;
|
||||
|
||||
memset(&inetAddr, 0, sizeof(inetAddr));
|
||||
inetAddr.sin_family=AF_INET;
|
||||
rv=_setHostAddr(&inetAddr.sin_addr, addr); /* try tuple */
|
||||
if (rv<0) {
|
||||
rv=_setHostName(&inetAddr.sin_addr, addr); /* lookup name */
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
inetAddr.sin_port=htons(port);
|
||||
|
||||
sk=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (sk<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "socket(): %s", strerror(errno));
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
rv=_socketSetReuseAddress(sk, 1);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
close(sk);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv=_socketSetBlocking(sk, 0);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
close(sk);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv=bind(sk, (struct sockaddr*) &inetAddr, sizeof(inetAddr));
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
close(sk);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv=listen(sk, MAX_BACKLOG);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
close(sk);
|
||||
return rv;
|
||||
}
|
||||
return sk;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleSignal(AQH_OBJECT *o,
|
||||
uint32_t slotId,
|
||||
GWEN_UNUSED AQH_OBJECT *senderObject,
|
||||
GWEN_UNUSED int param1,
|
||||
GWEN_UNUSED void *param2)
|
||||
{
|
||||
switch(slotId) {
|
||||
case AQH_TCPD_OBJECT_SLOT_SOCKETREADY: return _handleSocketReady(o);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0; /* not handled */
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleSocketReady(AQH_OBJECT *o)
|
||||
{
|
||||
AQH_TCPD_OBJECT *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TCPD_OBJECT, o);
|
||||
if (xo) {
|
||||
int clientSk;
|
||||
|
||||
clientSk=_acceptConnection(xo->fdSocket);
|
||||
if (clientSk<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", clientSk);
|
||||
}
|
||||
else {
|
||||
if (0==AQH_Object_EmitSignal(o, AQH_TCPD_OBJECT_SIGNAL_NEWCONN, clientSk, NULL)) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "New connection not handled");
|
||||
close(clientSk);
|
||||
}
|
||||
}
|
||||
return 1; /* handled */
|
||||
}
|
||||
return 0; /* not handled */
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _setHostAddr(struct in_addr *inetAddr, const char *sAddr)
|
||||
{
|
||||
inetAddr->s_addr=0;
|
||||
if (!inet_aton(sAddr, inetAddr)) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Invalid address \"%s\"", sAddr);
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _setHostName(struct in_addr *inetAddr, const char *sAddr)
|
||||
{
|
||||
struct hostent *he;
|
||||
|
||||
he=gethostbyname(sAddr);
|
||||
if (!he) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "gethostbyname(\"%s\"): %s", sAddr, hstrerror(h_errno));
|
||||
return _translateHError(h_errno);
|
||||
}
|
||||
/* name resolved, store address */
|
||||
memcpy(inetAddr, he->h_addr_list[0], sizeof(struct in_addr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _socketSetBlocking(int sk, int fl)
|
||||
{
|
||||
int prevFlags;
|
||||
int newFlags;
|
||||
|
||||
/* get current socket flags */
|
||||
prevFlags=fcntl(sk, F_GETFL);
|
||||
if (prevFlags==-1) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "fcntl(): %s", strerror(errno));
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
/* set nonblocking/blocking */
|
||||
if (fl)
|
||||
newFlags=prevFlags&(~O_NONBLOCK);
|
||||
else
|
||||
newFlags=prevFlags|O_NONBLOCK;
|
||||
|
||||
if (-1==fcntl(sk, F_SETFL, newFlags)) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "fcntl(): %s", strerror(errno));
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
prevFlags=fcntl(sk, F_GETFL);
|
||||
if (prevFlags!=newFlags) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "fcntl() did not set flags correctly (%08x!=%08x)", prevFlags, newFlags);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _socketSetReuseAddress(int sk, int fl)
|
||||
{
|
||||
if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &fl, sizeof(fl))) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "setsockopt(): %s", strerror(errno));
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _translateHError(int herr)
|
||||
{
|
||||
int rv;
|
||||
|
||||
switch (herr) {
|
||||
case HOST_NOT_FOUND:
|
||||
rv=GWEN_ERROR_HOST_NOT_FOUND;
|
||||
break;
|
||||
#ifdef NO_ADDRESS
|
||||
case NO_ADDRESS:
|
||||
rv=GWEN_ERROR_NO_ADDRESS;
|
||||
break;
|
||||
#endif
|
||||
case NO_RECOVERY:
|
||||
rv=GWEN_ERROR_NO_RECOVERY;
|
||||
break;
|
||||
case TRY_AGAIN:
|
||||
rv=GWEN_ERROR_TRY_AGAIN;
|
||||
break;
|
||||
default:
|
||||
rv=GWEN_ERROR_UNKNOWN_DNS_ERROR;
|
||||
break;
|
||||
} /* switch */
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _acceptConnection(int serverSocket)
|
||||
{
|
||||
int clientSk;
|
||||
struct sockaddr_in inetAddr;
|
||||
unsigned int socklen;
|
||||
int rv;
|
||||
|
||||
socklen=sizeof(inetAddr);
|
||||
clientSk=accept(serverSocket, (struct sockaddr*) &inetAddr, &socklen);
|
||||
if (clientSk<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "accept(): %s", strerror(errno));
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Accepted incoming connection");
|
||||
|
||||
rv=_socketSetBlocking(clientSk, 0);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
close(clientSk);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return clientSk;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
38
aqhome/ipc2/tcpd_object.h
Normal file
38
aqhome/ipc2/tcpd_object.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_TCPD_OBJECT_H
|
||||
#define AQH_TCPD_OBJECT_H
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
enum {
|
||||
/** new client connected (param1 is fd for the new clients non-blocking socket) */
|
||||
AQH_TCPD_OBJECT_SIGNAL_NEWCONN=AQH_OBJECT_SIGNAL_LAST
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Start listening on the given socket which represents a tcp network socket.
|
||||
* The socket can be created by @ref AQH_TcpdObject_CreateListeningSocket().
|
||||
*
|
||||
*/
|
||||
AQHOME_API AQH_OBJECT *AQH_TcpdObject_new(AQH_EVENT_LOOP *eventLoop, int fd);
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to create a listening TCP socket.
|
||||
*/
|
||||
AQHOME_API int AQH_TcpdObject_CreateListeningSocket(const char *addr, int port);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
27
aqhome/ipc2/tcpd_object_p.h
Normal file
27
aqhome/ipc2/tcpd_object_p.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_TCPD_OBJECT_P_H
|
||||
#define AQH_TCPD_OBJECT_P_H
|
||||
|
||||
|
||||
#include "./tcpd_object.h"
|
||||
|
||||
|
||||
typedef struct AQH_TCPD_OBJECT AQH_TCPD_OBJECT;
|
||||
struct AQH_TCPD_OBJECT {
|
||||
int fdSocket;
|
||||
AQH_OBJECT *fdObject;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
57
aqhome/ipc2/tty_endpoint.c
Normal file
57
aqhome/ipc2/tty_endpoint.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./tty_endpoint.h"
|
||||
|
||||
#include <aqhome/ipc2/nodemsgreader.h>
|
||||
#include <aqhome/ipc2/msgwriter.h>
|
||||
#include <aqhome/ipc2/ttyobject.h>
|
||||
#include <aqhome/ipc2/endpoint.h>
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* code
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_TtyEndpoint2_new(AQH_EVENT_LOOP *eventLoop, int fd)
|
||||
{
|
||||
int fdCopy;
|
||||
AQH_OBJECT *fdReader;
|
||||
AQH_OBJECT *fdWriter;
|
||||
AQH_OBJECT *msgReader;
|
||||
AQH_OBJECT *msgWriter;
|
||||
AQH_OBJECT *endpoint;
|
||||
|
||||
fdCopy=dup(fd);
|
||||
|
||||
fdReader=AQH_TtyObject_new(eventLoop, fd, AQH_FDOBJECT_FDMODE_READ);
|
||||
AQH_FdObject_FlushInput(fdReader);
|
||||
msgReader=AQH_NodeMsgReader_new(eventLoop, fdReader);
|
||||
AQH_Object_Enable(msgReader);
|
||||
|
||||
fdWriter=AQH_FdObject_new(eventLoop, fdCopy, AQH_FDOBJECT_FDMODE_WRITE);
|
||||
msgWriter=AQH_MsgWriter_new(eventLoop, fdWriter);
|
||||
|
||||
endpoint=AQH_Endpoint_new(eventLoop, msgReader, msgWriter);
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
29
aqhome/ipc2/tty_endpoint.h
Normal file
29
aqhome/ipc2/tty_endpoint.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_TTY_ENDPOINT_H
|
||||
#define AQH_TTY_ENDPOINT_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param eventLoop pointer to eventLoop
|
||||
* @param fd open file descriptor for tty object (see @ref AQH_TtyObject_OpenAndInitDevice).
|
||||
*/
|
||||
AQHOME_API AQH_OBJECT *AQH_TtyEndpoint2_new(AQH_EVENT_LOOP *eventLoop, int fd);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
230
aqhome/ipc2/ttyobject.c
Normal file
230
aqhome/ipc2/ttyobject.c
Normal file
@@ -0,0 +1,230 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "./ttyobject.h"
|
||||
#include <aqhome/events2/fdobject.h>
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define AQH_TTYOBJECT_BAUDRATE B19200
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static int _startMsg(AQH_OBJECT *o);
|
||||
static void _endMsg(AQH_OBJECT *o);
|
||||
static int _getAttn(int fd);
|
||||
static int _setAttn(int fd, int val);
|
||||
static int _fdSetBlocking(int sk, int fl);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_OBJECT *AQH_TtyObject_new(AQH_EVENT_LOOP *eventLoop, int fd, int fdMode)
|
||||
{
|
||||
AQH_OBJECT *o;
|
||||
|
||||
o=AQH_FdObject_new(eventLoop, fd, fdMode);
|
||||
AQH_FdObject_SetStartMsgFn(o, _startMsg);
|
||||
AQH_FdObject_SetEndMsgFn(o, _endMsg);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _startMsg(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
int fd;
|
||||
int rv;
|
||||
|
||||
fd=AQH_FdObject_GetFd(o);
|
||||
if (fd==-1)
|
||||
return GWEN_ERROR_IO;
|
||||
rv=_getAttn(fd);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
else if (rv==0) {
|
||||
return GWEN_ERROR_TRY_AGAIN; /* line busy */
|
||||
}
|
||||
else {
|
||||
_setAttn(fd, 0); /* set ATTN low */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _endMsg(AQH_OBJECT *o)
|
||||
{
|
||||
if (o) {
|
||||
int fd;
|
||||
|
||||
fd=AQH_FdObject_GetFd(o);
|
||||
if (fd>=0)
|
||||
_setAttn(fd, 1); /* set ATTN high */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _getAttn(int fd)
|
||||
{
|
||||
int rv;
|
||||
int status;
|
||||
|
||||
rv=ioctl(fd, TIOCMGET, &status);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl: %s (%d)", strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
return (status & TIOCM_CTS)?0:1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _setAttn(int fd, int val)
|
||||
{
|
||||
int rv;
|
||||
int status;
|
||||
|
||||
rv=ioctl(fd, TIOCMGET, &status);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl: %s (%d)", strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
if (val)
|
||||
status &= ~ (TIOCM_DTR | TIOCM_RTS); /* attn high, clear the DTR pin (cave: signals inverted!) */
|
||||
else
|
||||
status |= TIOCM_DTR | TIOCM_RTS; /* attn low, set the DTR pin (cave: signals inverted!) */
|
||||
|
||||
rv=ioctl(fd, TIOCMSET, &status);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl: %s (%d)", strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_TtyObject_OpenAndInitDevice(const char *device, struct termios *initialTermiosState)
|
||||
{
|
||||
int fd;
|
||||
struct termios options;
|
||||
int rv;
|
||||
|
||||
fd=open(device, O_NOCTTY | O_NDELAY | O_RDWR);
|
||||
if (fd<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on open(%s): %s (%d)", device, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Device %s open (socket %d)", device, fd);
|
||||
|
||||
_fdSetBlocking(fd, 0);
|
||||
|
||||
rv=tcgetattr(fd, &options);
|
||||
if (initialTermiosState)
|
||||
*initialTermiosState=options;
|
||||
|
||||
options.c_cflag=CLOCAL | CREAD | CS8;
|
||||
options.c_iflag=IGNPAR | IGNBRK;
|
||||
options.c_oflag=0;
|
||||
options.c_lflag&= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
options.c_cc[VTIME]=0; /* read timeout in deciseconds */
|
||||
options.c_cc[VMIN]=0; /* no minimum number of receive bytes */
|
||||
cfmakeraw(&options);
|
||||
|
||||
rv=cfsetispeed(&options, AQH_TTYOBJECT_BAUDRATE);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on cfsetispeed(%s): %s (%d)", device, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
rv=cfsetospeed(&options, AQH_TTYOBJECT_BAUDRATE);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on cfsetospeed(%s): %s (%d)", device, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
rv=tcflush(fd, TCIOFLUSH);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcflush(%s): %s (%d)", device, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
rv=tcsetattr(fd, TCSANOW, &options);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcsetattr(%s): %s (%d)", device, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _fdSetBlocking(int fd, int fl)
|
||||
{
|
||||
int prevFlags;
|
||||
int newFlags;
|
||||
|
||||
/* get current socket flags */
|
||||
prevFlags=fcntl(fd, F_GETFL);
|
||||
if (prevFlags==-1) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "fcntl(): %s", strerror(errno));
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
/* set nonblocking/blocking */
|
||||
if (fl)
|
||||
newFlags=prevFlags&(~O_NONBLOCK);
|
||||
else
|
||||
newFlags=prevFlags|O_NONBLOCK;
|
||||
|
||||
if (-1==fcntl(fd, F_SETFL, newFlags)) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "fcntl(): %s", strerror(errno));
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
prevFlags=fcntl(fd, F_GETFL);
|
||||
if (prevFlags!=newFlags) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "fcntl() did not set flags correctly (%08x!=%08x)", prevFlags, newFlags);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
38
aqhome/ipc2/ttyobject.h
Normal file
38
aqhome/ipc2/ttyobject.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project Gwenhywfar.
|
||||
* Gwenhywfar (c) by 2023 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 AQH_TTYOBJECT_H
|
||||
#define AQH_TTYOBJECT_H
|
||||
|
||||
|
||||
#include <aqhome/events2/object.h>
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
|
||||
/**
|
||||
* Create Tty object for given filedescriptor and in given mode (read or write)
|
||||
*
|
||||
* @return object created
|
||||
* @param eventLoop event loop to assign the new object to
|
||||
* @param fd filedescriptor (e.g. created by calls to open or socket)
|
||||
* @param fdMode AQH_FDOBJECT_FDMODE_READ or AQH_FDOBJECT_FDMODE_WRITE
|
||||
*/
|
||||
AQHOME_API AQH_OBJECT *AQH_TtyObject_new(AQH_EVENT_LOOP *eventLoop, int fd, int fdMode);
|
||||
|
||||
/**
|
||||
* Open given device and setup TTY parameters for it.
|
||||
*
|
||||
* @return filedescriptor for the openened and initialized device
|
||||
* @param device path to device to open (e.g. "/dev/ttyUSB0")
|
||||
* @param initialTermiosState var to store initial state of the device (if given)
|
||||
*/
|
||||
AQHOME_API int AQH_TtyObject_OpenAndInitDevice(const char *device, struct termios *initialTermiosState);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -17,6 +17,15 @@
|
||||
#include "aqhome/hexfile/hexfile.h"
|
||||
#include "aqhome/hexfile/flashrecord.h"
|
||||
|
||||
#include "aqhome/events2/eventloop.h"
|
||||
#include "aqhome/events2/fdobject.h"
|
||||
#include "aqhome/ipc2/ttyobject.h"
|
||||
#include "aqhome/ipc2/nodemsgreader.h"
|
||||
#include "aqhome/ipc2/msgreader.h"
|
||||
#include "aqhome/ipc2/msgwriter.h"
|
||||
#include "aqhome/ipc2/endpoint.h"
|
||||
#include "aqhome/ipc2/tty_endpoint.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
@@ -463,6 +472,89 @@ int testFlashRecords(int argc, char **argv)
|
||||
|
||||
|
||||
|
||||
int testTty(int argc, char **argv)
|
||||
{
|
||||
const char *deviceName;
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
struct termios initialTermiosState;
|
||||
int fd;
|
||||
AQH_OBJECT *ttyReadObject;
|
||||
AQH_OBJECT *msgReaderObject;
|
||||
AQH_OBJECT *endpointObject;
|
||||
int rv;
|
||||
|
||||
if (argc<2) {
|
||||
fprintf(stderr, "Missing device name\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rv=AQH_Init();
|
||||
if (rv<0) {
|
||||
}
|
||||
|
||||
deviceName=argv[1];
|
||||
|
||||
eventLoop=AQH_EventLoop_new();
|
||||
fd=AQH_TtyObject_OpenAndInitDevice(deviceName, &initialTermiosState);
|
||||
if (fd<0) {
|
||||
fprintf(stderr, "Error opening device \"%s\"\n", deviceName);
|
||||
return 2;
|
||||
}
|
||||
|
||||
ttyReadObject=AQH_TtyObject_new(eventLoop, fd, AQH_FDOBJECT_FDMODE_READ);
|
||||
AQH_FdObject_FlushInput(ttyReadObject);
|
||||
msgReaderObject=AQH_NodeMsgReader_new(eventLoop, ttyReadObject);
|
||||
endpointObject=AQH_Endpoint_new(eventLoop, msgReaderObject, NULL);
|
||||
|
||||
AQH_Object_Enable(msgReaderObject);
|
||||
|
||||
for (;;) {
|
||||
AQH_EventLoop_Run(eventLoop);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int testTty2(int argc, char **argv)
|
||||
{
|
||||
const char *deviceName;
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
struct termios initialTermiosState;
|
||||
int fd;
|
||||
AQH_OBJECT *endpointObject;
|
||||
int rv;
|
||||
|
||||
if (argc<2) {
|
||||
fprintf(stderr, "Missing device name\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rv=AQH_Init();
|
||||
if (rv<0) {
|
||||
}
|
||||
|
||||
deviceName=argv[1];
|
||||
|
||||
eventLoop=AQH_EventLoop_new();
|
||||
fd=AQH_TtyObject_OpenAndInitDevice(deviceName, &initialTermiosState);
|
||||
if (fd<0) {
|
||||
fprintf(stderr, "Error opening device \"%s\"\n", deviceName);
|
||||
return 2;
|
||||
}
|
||||
|
||||
endpointObject=AQH_TtyEndpoint2_new(eventLoop, fd);
|
||||
|
||||
for (;;) {
|
||||
AQH_EventLoop_Run(eventLoop);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -471,7 +563,8 @@ int main(int argc, char **argv)
|
||||
//return testMqttConnection2();
|
||||
//return testMqttSubscribe2(argc, argv);
|
||||
//return testHttpDaemon();
|
||||
return testMqttSubscribe3(argc, argv);
|
||||
//return testMqttSubscribe3(argc, argv);
|
||||
return testTty2(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
msg_sysstats.h
|
||||
msg_value.h
|
||||
msg_value2.h
|
||||
msg_value3.h
|
||||
msg_device.h
|
||||
msg_flashready.h
|
||||
msg_flashstart.h
|
||||
@@ -107,9 +108,13 @@
|
||||
|
||||
|
||||
<useTargets>
|
||||
aqhmsg_node
|
||||
aqhmsg_ipc
|
||||
</useTargets>
|
||||
|
||||
<subdirs>
|
||||
node
|
||||
ipc
|
||||
</subdirs>
|
||||
|
||||
|
||||
|
||||
@@ -158,6 +158,7 @@ int AQH_TtyEndpoint_Connect(GWEN_MSG_ENDPOINT *ep)
|
||||
GWEN_Socket_free(sk);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
GWEN_Socket_AddFlags(sk, GWEN_SOCKET_FLAGS_DUMP_READ);
|
||||
|
||||
GWEN_MsgEndpoint_SetSocket(ep, sk);
|
||||
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
|
||||
@@ -212,15 +213,16 @@ int _openDevice(GWEN_MSG_ENDPOINT *ep)
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcgetattr(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
memset(&options, 0, sizeof(options)); /* preset */
|
||||
options=xep->previousOptions;
|
||||
// memset(&options, 0, sizeof(options)); /* preset */
|
||||
|
||||
options.c_cflag=CLOCAL | CREAD | CS8;
|
||||
options.c_iflag=IGNPAR | IGNBRK;
|
||||
options.c_oflag=0;
|
||||
options.c_lflag=0;
|
||||
cfmakeraw(&options);
|
||||
options.c_lflag&= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
options.c_cc[VTIME]=0; /* read timeout in deciseconds */
|
||||
options.c_cc[VMIN]=0; /* no minimum number of receive bytes */
|
||||
cfmakeraw(&options);
|
||||
|
||||
rv=cfsetispeed(&options, AQH_MSG_ENDPOINT_TTY_BAUDRATE);
|
||||
if (rv<0) {
|
||||
|
||||
86
aqhome/msg/ipc/0BUILD
Normal file
86
aqhome/msg/ipc/0BUILD
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<target type="ConvenienceLibrary" name="aqhmsg_ipc" >
|
||||
|
||||
<includes type="c" >
|
||||
$(gwenhywfar_cflags)
|
||||
-I$(topsrcdir)
|
||||
-I$(topbuilddir)
|
||||
</includes>
|
||||
|
||||
<includes type="tm2" >
|
||||
--include=$(builddir)
|
||||
--include=$(srcdir)
|
||||
</includes>
|
||||
|
||||
|
||||
<define name="BUILDING_AQHOME" />
|
||||
|
||||
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
||||
|
||||
|
||||
<setVar name="tm2flags" >
|
||||
--api=AQHOME_API
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/typefiles" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_sources" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_headers_pub">
|
||||
</setVar>
|
||||
|
||||
|
||||
<setVar name="local/built_headers_priv" >
|
||||
</setVar>
|
||||
|
||||
|
||||
<headers dist="false" install="$(pkgincludedir)/msg" >
|
||||
$(local/built_headers_pub)
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/msg" >
|
||||
m_ipc.h
|
||||
m_ipc_tag16.h
|
||||
m_ipc_result.h
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
</headers>
|
||||
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
|
||||
m_ipc.c
|
||||
m_ipc_tag16.c
|
||||
m_ipc_result.c
|
||||
</sources>
|
||||
|
||||
|
||||
<extradist>
|
||||
</extradist>
|
||||
|
||||
|
||||
<useTargets>
|
||||
aqhmsg_ipcd
|
||||
aqhmsg_ipcn
|
||||
</useTargets>
|
||||
|
||||
<subdirs>
|
||||
data
|
||||
nodes
|
||||
</subdirs>
|
||||
|
||||
|
||||
|
||||
|
||||
</target>
|
||||
|
||||
</gwbuild>
|
||||
90
aqhome/msg/ipc/data/0BUILD
Normal file
90
aqhome/msg/ipc/data/0BUILD
Normal file
@@ -0,0 +1,90 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<target type="ConvenienceLibrary" name="aqhmsg_ipcd" >
|
||||
|
||||
<includes type="c" >
|
||||
$(gwenhywfar_cflags)
|
||||
-I$(topsrcdir)
|
||||
-I$(topbuilddir)
|
||||
</includes>
|
||||
|
||||
<includes type="tm2" >
|
||||
--include=$(builddir)
|
||||
--include=$(srcdir)
|
||||
</includes>
|
||||
|
||||
|
||||
<define name="BUILDING_AQHOME" />
|
||||
|
||||
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
||||
|
||||
|
||||
<setVar name="tm2flags" >
|
||||
--api=AQHOME_API
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/typefiles" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_sources" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_headers_pub">
|
||||
</setVar>
|
||||
|
||||
|
||||
<setVar name="local/built_headers_priv" >
|
||||
</setVar>
|
||||
|
||||
|
||||
<headers dist="false" install="$(pkgincludedir)/msg" >
|
||||
$(local/built_headers_pub)
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/msg" >
|
||||
m_ipcd.h
|
||||
m_ipcd_connect.h
|
||||
m_ipcd_multidata.h
|
||||
m_ipcd_devices.h
|
||||
m_ipcd_values.h
|
||||
m_ipcd_getdata.h
|
||||
m_ipcd_setdata.h
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
</headers>
|
||||
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
|
||||
m_ipcd.c
|
||||
m_ipcd_connect.c
|
||||
m_ipcd_multidata.c
|
||||
m_ipcd_devices.c
|
||||
m_ipcd_values.c
|
||||
m_ipcd_getdata.c
|
||||
m_ipcd_setdata.c
|
||||
</sources>
|
||||
|
||||
|
||||
<extradist>
|
||||
</extradist>
|
||||
|
||||
|
||||
<useTargets>
|
||||
</useTargets>
|
||||
|
||||
<subdirs>
|
||||
</subdirs>
|
||||
|
||||
|
||||
|
||||
|
||||
</target>
|
||||
|
||||
</gwbuild>
|
||||
58
aqhome/msg/ipc/data/m_ipcd.c
Normal file
58
aqhome/msg/ipc/data/m_ipcd.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
const char *AQH_IpcdMessage_MsgTypeToChar(uint16_t i)
|
||||
{
|
||||
switch(i) {
|
||||
case AQH_MSGTYPE_IPC_DATA_RESULT: return "Result";
|
||||
case AQH_MSGTYPE_IPC_DATA_CONNECT_REQ: return "Connect(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_UPDATEDATA: return "UpdateData";
|
||||
case AQH_MSGTYPE_IPC_DATA_DATACHANGED: return "DataChanged";
|
||||
case AQH_MSGTYPE_IPC_DATA_SETDATA: return "SetData";
|
||||
case AQH_MSGTYPE_IPC_DATA_ADDVALUE: return "AddValue";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDATA_REQ: return "GetData(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDATA_RSP: return "GetData(Rsp)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ: return "GetLastData(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP: return "GetLastData(Rsp)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ: return "GetValues(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP: return "GetValues(Rsp)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ: return "GetDevices(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP: return "GetDevices(Rsp)";
|
||||
case AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ: return "ModDevice(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE: return "AnnounceValue";
|
||||
default: return "(unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
60
aqhome/msg/ipc/data/m_ipcd.h
Normal file
60
aqhome/msg/ipc/data/m_ipcd.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCD_H
|
||||
#define AQH_M_IPCD_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_IPC_PROTOCOL_DATA_ID 2
|
||||
#define AQH_IPC_PROTOCOL_DATA_VERSION 1
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_RESULT 0x0001 /* AQH_ResultIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_CONNECT_REQ 0x0010 /* serviceName, userName, password */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x0100 /* AQH_MultiDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x0200 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x0300 /* AQH_SetDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_ADDVALUE 0x0400 /* AQH_AddValueDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDATA_REQ 0x0500 /* AQH_GetDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDATA_RSP 0x0600 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x0700 /* AQH_GetDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x0800 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ 0x0900 /* GWEN_IpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0x0a00 /* AQH_ValuesDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ 0x0b00 /* GWEN_IpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP 0x0c00 /* AQH_DevicesDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ 0x0d00 /* AQH_DevicesDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE 0x0e00 /* AQH_ValuesDataIpcMsg */
|
||||
|
||||
|
||||
|
||||
AQHOME_API const char *AQH_IpcdMessage_MsgTypeToChar(uint16_t i);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
90
aqhome/msg/ipc/data/m_ipcd_connect.c
Normal file
90
aqhome/msg/ipc/data/m_ipcd_connect.c
Normal file
@@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/data/m_ipcd_connect.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcdMessageConnect_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
const char *clientId, const char *userId, const char *password, uint32_t flags)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
if (clientId && *clientId)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_CLIENTID, clientId, buf);
|
||||
if (userId && *userId)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_USERID, userId, buf);
|
||||
if (password && *password)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_PASSWORD, password, buf);
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_CONNECT_TAGS_FLAGS, flags, buf);
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcdMessageConnect_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
char *clientId=NULL;
|
||||
char *userId=NULL;
|
||||
uint32_t flags=0;
|
||||
|
||||
if (tagList) {
|
||||
clientId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_CLIENTID, NULL);
|
||||
userId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_USERID, NULL);
|
||||
flags=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_CONNECT_TAGS_FLAGS, 0);
|
||||
}
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"CONNECT(%s) %s (code=%d, proto=%d, proto version=%d, clientId=%s, userId=%s, flags=%08x)\n",
|
||||
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg),
|
||||
clientId?clientId:"<empty>",
|
||||
userId?userId:"<empty>",
|
||||
flags);
|
||||
free(userId);
|
||||
free(clientId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
40
aqhome/msg/ipc/data/m_ipcd_connect.h
Normal file
40
aqhome/msg/ipc/data/m_ipcd_connect.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCD_CONNECT_H
|
||||
#define AQH_M_IPCD_CONNECT_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
|
||||
|
||||
#define AQH_MSGDATA_CONNECT_TAGS_CLIENTID 0x0001
|
||||
#define AQH_MSGDATA_CONNECT_TAGS_USERID 0x0002
|
||||
#define AQH_MSGDATA_CONNECT_TAGS_PASSWORD 0x0003
|
||||
#define AQH_MSGDATA_CONNECT_TAGS_FLAGS 0x0004
|
||||
|
||||
#define AQH_MSGDATA_CONNECT_FLAGS_WANTUPDATES 0x0001
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageConnect_new(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const char *clientId, const char *userId, const char *password,
|
||||
uint32_t flags);
|
||||
|
||||
AQHOME_API void AQH_IpcdMessageConnect_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
143
aqhome/msg/ipc/data/m_ipcd_devices.c
Normal file
143
aqhome/msg/ipc/data/m_ipcd_devices.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/data/m_ipcd_devices.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcdMessageDevices_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t flags, const AQH_DEVICE_LIST *deviceList)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
int rv;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_DEVICES_TAGS_FLAGS, flags, buf);
|
||||
rv=AQH_Tag16_WriteDeviceListAsTagsToBuffer(AQH_MSGDATA_DEVICES_TAGS_DEVICE, deviceList, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_IpcdMessageDevices_newForOneDevice(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t flags, const AQH_DEVICE *device)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
int rv;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_DEVICES_TAGS_FLAGS, flags, buf);
|
||||
rv=AQH_Tag16_WriteDeviceAsTagToBuffer(AQH_MSGDATA_DEVICES_TAGS_DEVICE, device, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE_LIST *AQH_IpcdMessageDevices_ReadDeviceList(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
if (tagList) {
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
|
||||
deviceList=AQH_Tag16_ReadDevicesFromTagList(tagList, AQH_MSGDATA_DEVICES_TAGS_DEVICE);
|
||||
if (deviceList==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "No device list received");
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE *AQH_IpcdMessageDevices_ReadFirstDevice(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
if (tagList) {
|
||||
AQH_DEVICE *device;
|
||||
|
||||
device=AQH_Tag16_ReadDeviceFromTagList(tagList, AQH_MSGDATA_DEVICES_TAGS_DEVICE);
|
||||
if (device==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "No device received");
|
||||
}
|
||||
return device;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_IpcdMessageDevices_GetFlags(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
return tagList?AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_DEVICES_TAGS_FLAGS, 0):0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcdMessageDevices_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
flags=AQH_IpcdMessageDevices_GetFlags(tagList);
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"DEVICES(%s) %s (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
|
||||
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg),
|
||||
(unsigned int) flags);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
44
aqhome/msg/ipc/data/m_ipcd_devices.h
Normal file
44
aqhome/msg/ipc/data/m_ipcd_devices.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCD_DEVICES_H
|
||||
#define AQH_M_IPCD_DEVICES_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/device.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGDATA_DEVICES_FLAGS_LASTMSG 0x0001
|
||||
|
||||
#define AQH_MSGDATA_DEVICES_TAGS_FLAGS 0x01
|
||||
#define AQH_MSGDATA_DEVICES_TAGS_DEVICE 0xc2
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageDevices_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t flags, const AQH_DEVICE_LIST *deviceList);
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageDevices_newForOneDevice(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t flags, const AQH_DEVICE *device);
|
||||
|
||||
AQHOME_API AQH_DEVICE_LIST *AQH_IpcdMessageDevices_ReadDeviceList(const GWEN_TAG16_LIST *tagList);
|
||||
AQHOME_API AQH_DEVICE *AQH_IpcdMessageDevices_ReadFirstDevice(const GWEN_TAG16_LIST *tagList);
|
||||
AQHOME_API uint32_t AQH_IpcdMessageDevices_GetFlags(const GWEN_TAG16_LIST *tagList);
|
||||
|
||||
AQHOME_API void AQH_IpcdMessageDevices_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
87
aqhome/msg/ipc/data/m_ipcd_getdata.c
Normal file
87
aqhome/msg/ipc/data/m_ipcd_getdata.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/data/m_ipcd_getdata.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcdMessageGetData_new(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const char *valueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
|
||||
if (valueName && *valueName)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_GETDATA_TAGS_NAME, valueName, buf);
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_BEGIN, tsBegin, buf);
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_END, tsEnd, buf);
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_NUM, num, buf);
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcdMessageGetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
char *valueName;
|
||||
uint64_t tsBegin;
|
||||
uint64_t tsEnd;
|
||||
|
||||
valueName=tagList?AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_GETDATA_TAGS_NAME, NULL):NULL;
|
||||
tsBegin=tagList?AQH_Tag16_GetTagDataAsUint64(tagList, AQH_MSGDATA_GETDATA_TAGS_BEGIN, 0):0;
|
||||
tsEnd=tagList?AQH_Tag16_GetTagDataAsUint64(tagList, AQH_MSGDATA_GETDATA_TAGS_END, 0):0;
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"GETDATA(%s) %s (code=%d, proto=%d, proto version=%d, name=%s, tsBegin=%lu, tsEnd=%lu)\n",
|
||||
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg),
|
||||
valueName?valueName:"<empty>",
|
||||
(unsigned long int) tsBegin,
|
||||
(unsigned long int) tsEnd);
|
||||
free(valueName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
38
aqhome/msg/ipc/data/m_ipcd_getdata.h
Normal file
38
aqhome/msg/ipc/data/m_ipcd_getdata.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCD_GETDATA_H
|
||||
#define AQH_M_IPCD_GETDATA_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/value.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGDATA_GETDATA_TAGS_NAME 0x0001
|
||||
#define AQH_MSGDATA_GETDATA_TAGS_BEGIN 0x0020
|
||||
#define AQH_MSGDATA_GETDATA_TAGS_END 0x0021
|
||||
#define AQH_MSGDATA_GETDATA_TAGS_NUM 0x0022
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageGetData_new(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const char *valueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num);
|
||||
|
||||
AQHOME_API void AQH_IpcdMessageGetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
158
aqhome/msg/ipc/data/m_ipcd_multidata.c
Normal file
158
aqhome/msg/ipc/data/m_ipcd_multidata.c
Normal file
@@ -0,0 +1,158 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/data/m_ipcd_multidata.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcdMessageMultiData_new(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const AQH_VALUE *value, const uint64_t *i64Ptr, int numOfDataPoints)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
int rv;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
|
||||
rv=AQH_Tag16_WriteValueAsTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_VALUE, value, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (i64Ptr && numOfDataPoints)
|
||||
GWEN_Tag16_WriteTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_DATA, (const uint8_t*)i64Ptr, numOfDataPoints*2*sizeof(uint64_t), buf);
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_IpcdMessageMultiData_newForOne(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const AQH_VALUE *value, uint64_t timeStamp, double dataPoint)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
int rv;
|
||||
union {double f; uint64_t i;} u;
|
||||
uint64_t arrayToSend[2];
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
|
||||
rv=AQH_Tag16_WriteValueAsTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_VALUE, value, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
arrayToSend[0]=timeStamp;
|
||||
u.f=dataPoint;
|
||||
arrayToSend[1]=u.i;
|
||||
GWEN_Tag16_WriteTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_DATA, (const uint8_t*) arrayToSend, 2*sizeof(uint64_t), buf);
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE *AQH_IpcdMessageMultiData_ReadValue(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
return tagList?AQH_Tag16_ReadValueFromTagList(tagList, AQH_MSGDATA_MULTIDATA_TAGS_VALUE):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcdMessageMultiData_ReadDatapoints(const GWEN_TAG16_LIST *tagList, const uint64_t **pDataPtr, uint64_t *pNumberOfPoints)
|
||||
{
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
unsigned int numberOfPoints;
|
||||
const uint64_t *dataPoints;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_MULTIDATA_TAGS_DATA);
|
||||
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
|
||||
dataPoints=tag?((const uint64_t*) GWEN_Tag16_GetTagData(tag)):NULL;
|
||||
if (numberOfPoints>0 && dataPoints) {
|
||||
*pDataPtr=dataPoints;
|
||||
*pNumberOfPoints=numberOfPoints;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcdMessageMultiData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
AQH_VALUE *value;
|
||||
const GWEN_TAG16 *tag;
|
||||
const char *valueName;
|
||||
const char *valueUnits;
|
||||
int valueType;
|
||||
unsigned int numberOfPoints=0;
|
||||
|
||||
value=tagList?AQH_IpcdMessageMultiData_ReadValue(tagList):NULL;
|
||||
valueName=value?AQH_Value_GetNameForSystem(value):NULL;
|
||||
valueUnits=value?AQH_Value_GetValueUnits(value):NULL;
|
||||
valueType=value?AQH_Value_GetValueType(value):0;
|
||||
|
||||
tag=tagList?GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_MULTIDATA_TAGS_DATA):NULL;
|
||||
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"MULTIDATA(%s) %s (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d, datapoints=%u)\n",
|
||||
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg),
|
||||
valueName?valueName:"<empty>",
|
||||
valueUnits?valueUnits:"<empty>",
|
||||
valueType,
|
||||
numberOfPoints);
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
44
aqhome/msg/ipc/data/m_ipcd_multidata.h
Normal file
44
aqhome/msg/ipc/data/m_ipcd_multidata.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCD_MULTIDATA_H
|
||||
#define AQH_M_IPCD_MULTIDATA_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/value.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGDATA_MULTIDATA_TAGS_VALUE 0xc1
|
||||
#define AQH_MSGDATA_MULTIDATA_TAGS_DATA 0xc2
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageMultiData_new(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const AQH_VALUE *value, const uint64_t *i64Ptr, int numOfDataPoints);
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageMultiData_newForOne(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const AQH_VALUE *value, uint64_t timeStamp, double dataPoint);
|
||||
|
||||
AQHOME_API AQH_VALUE *AQH_IpcdMessageMultiData_ReadValue(const GWEN_TAG16_LIST *tagList);
|
||||
AQHOME_API void AQH_IpcdMessageMultiData_ReadDatapoints(const GWEN_TAG16_LIST *tagList,
|
||||
const uint64_t **pDataPtr, uint64_t *pNumberOfPoints);
|
||||
|
||||
AQHOME_API void AQH_IpcdMessageMultiData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
120
aqhome/msg/ipc/data/m_ipcd_setdata.c
Normal file
120
aqhome/msg/ipc/data/m_ipcd_setdata.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/data/m_ipcd_setdata.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcdMessageSetData_new(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const AQH_VALUE *value, const char *data)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
int rv;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
|
||||
rv=AQH_Tag16_WriteValueAsTagToBuffer(AQH_MSGDATA_SET_TAGS_VALUE, value, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
if (data && *data)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_SET_TAGS_DATA, data, buf);
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE *AQH_IpcdMessageSetData_ReadValue(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
if (tagList) {
|
||||
AQH_VALUE *value;
|
||||
|
||||
value=AQH_Tag16_ReadValueFromTagList(tagList, AQH_MSGDATA_SET_TAGS_VALUE);
|
||||
if (value==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "No value received");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *AQH_IpcdMessageSetData_ReadData(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
return AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_SET_TAGS_DATA, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcdMessageSetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
AQH_VALUE *value;
|
||||
const char *valueName;
|
||||
const char *valueUnits;
|
||||
int valueType;
|
||||
char *data;
|
||||
|
||||
value=tagList?AQH_IpcdMessageSetData_ReadValue(tagList):NULL;
|
||||
valueName=value?AQH_Value_GetNameForSystem(value):NULL;
|
||||
valueUnits=value?AQH_Value_GetValueUnits(value):NULL;
|
||||
valueType=value?AQH_Value_GetValueType(value):0;
|
||||
data=tagList?AQH_IpcdMessageSetData_ReadData(tagList):NULL;
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"SETDATA(%s) %s (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d, value=%s)\n",
|
||||
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg),
|
||||
valueName?valueName:"<empty>",
|
||||
valueUnits?valueUnits:"<empty>",
|
||||
valueType,
|
||||
data?data:"<empty>");
|
||||
free(data);
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
43
aqhome/msg/ipc/data/m_ipcd_setdata.h
Normal file
43
aqhome/msg/ipc/data/m_ipcd_setdata.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCD_SETDATA_H
|
||||
#define AQH_M_IPCD_SETDATA_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/value.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGDATA_SET_TAGS_VALUE 0xc1
|
||||
#define AQH_MSGDATA_SET_TAGS_DATA 0x02
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageSetData_new(uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
const AQH_VALUE *value, const char *data);
|
||||
|
||||
AQHOME_API AQH_VALUE *AQH_IpcdMessageSetData_ReadValue(const GWEN_TAG16_LIST *tagList);
|
||||
AQHOME_API char *AQH_IpcdMessageSetData_ReadData(const GWEN_TAG16_LIST *tagList);
|
||||
|
||||
AQHOME_API void AQH_IpcdMessageSetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
119
aqhome/msg/ipc/data/m_ipcd_values.c
Normal file
119
aqhome/msg/ipc/data/m_ipcd_values.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/data/m_ipcd_values.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcdMessageValues_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t flags, const AQH_VALUE_LIST *valueList)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
int rv;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_VALUES_TAGS_FLAGS, flags, buf);
|
||||
rv=AQH_Tag16_WriteValueListAsTagsToBuffer(AQH_MSGDATA_VALUES_TAGS_VALUE, valueList, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE_LIST *AQH_IpcdMessageDevices_ReadValueList(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
if (tagList) {
|
||||
AQH_VALUE_LIST *valueList;
|
||||
|
||||
valueList=AQH_Tag16_ReadValuesFromTagList(tagList, AQH_MSGDATA_VALUES_TAGS_VALUE);
|
||||
if (valueList==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "No value list received");
|
||||
}
|
||||
return valueList;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE *AQH_IpcdMessageValues_ReadFirstValue(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
if (tagList) {
|
||||
AQH_VALUE *value;
|
||||
|
||||
value=AQH_Tag16_ReadValueFromTagList(tagList, AQH_MSGDATA_VALUES_TAGS_VALUE);
|
||||
if (value==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "No value received");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_IpcdMessageValues_GetFlags(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
return tagList?AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_VALUES_TAGS_FLAGS, 0):0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcdMessageValues_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
flags=AQH_IpcdMessageValues_GetFlags(tagList);
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"VALUES(%s) %s (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
|
||||
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg),
|
||||
(unsigned int) flags);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
41
aqhome/msg/ipc/data/m_ipcd_values.h
Normal file
41
aqhome/msg/ipc/data/m_ipcd_values.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCD_VALUES_H
|
||||
#define AQH_M_IPCD_VALUES_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/value.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGDATA_VALUES_FLAGS_LASTMSG 0x0001
|
||||
|
||||
#define AQH_MSGDATA_VALUES_TAGS_FLAGS 0x01
|
||||
#define AQH_MSGDATA_VALUES_TAGS_VALUE 0xc2
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageValues_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t flags, const AQH_VALUE_LIST *valueList);
|
||||
AQHOME_API AQH_VALUE_LIST *AQH_IpcdMessageDevices_ReadValueList(const GWEN_TAG16_LIST *tagList);
|
||||
AQHOME_API AQH_VALUE *AQH_IpcdMessageValues_ReadFirstValue(const GWEN_TAG16_LIST *tagList);
|
||||
AQHOME_API uint32_t AQH_IpcdMessageValues_GetFlags(const GWEN_TAG16_LIST *tagList);
|
||||
|
||||
AQHOME_API void AQH_IpcdMessageValues_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
170
aqhome/msg/ipc/m_ipc.c
Normal file
170
aqhome/msg/ipc/m_ipc.c
Normal file
@@ -0,0 +1,170 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcMessage_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t payloadLen, const uint8_t *payload)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
uint32_t len;
|
||||
|
||||
len=AQH_IPCMSG_OFFS_PAYLOAD+payloadLen;
|
||||
msg=AQH_Message_new();
|
||||
AQH_Message_SetData(msg, NULL, len); /* auto-malloc len bytes */
|
||||
|
||||
AQH_Message_WriteUint32At(msg, AQH_IPCMSG_OFFS_SIZE, len);
|
||||
AQH_Message_WriteUint8At(msg, AQH_IPCMSG_OFFS_PROTOID, protoId);
|
||||
AQH_Message_WriteUint8At(msg, AQH_IPCMSG_OFFS_PROTOVER, protoVer);
|
||||
AQH_Message_WriteUint16At(msg, AQH_IPCMSG_OFFS_CODE, code);
|
||||
AQH_Message_WriteUint32At(msg, AQH_IPCMSG_OFFS_ID, msgId);
|
||||
AQH_Message_WriteUint32At(msg, AQH_IPCMSG_OFFS_REFID, refMsgId);
|
||||
if (payloadLen && payload)
|
||||
AQH_Message_WriteBytesAt(msg, AQH_IPCMSG_OFFS_PAYLOAD, payload, payloadLen);
|
||||
AQH_Message_SetUsedSize(msg, len);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_IpcMessage_fromBuffer(const uint8_t *ptr, uint32_t len)
|
||||
{
|
||||
if (ptr && len) {
|
||||
AQH_MESSAGE *msg;
|
||||
|
||||
msg=AQH_Message_new();
|
||||
AQH_Message_SetData(msg, ptr, len);
|
||||
AQH_Message_SetUsedSize(msg, len);
|
||||
return msg;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcMessage_AdjustMsgSize(AQH_MESSAGE *msg)
|
||||
{
|
||||
if (msg)
|
||||
AQH_Message_WriteUint32At(msg, AQH_IPCMSG_OFFS_SIZE, AQH_Message_GetUsedSize(msg));
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_IpcMessage_GetMsgSize(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint32At(msg, AQH_IPCMSG_OFFS_SIZE, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_IpcMessage_GetProtoId(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_IPCMSG_OFFS_PROTOID, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_IpcMessage_GetProtoVersion(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_IPCMSG_OFFS_PROTOVER, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_IpcMessage_GetCode(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint16At(msg, AQH_IPCMSG_OFFS_CODE, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_IpcMessage_GetMsgId(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint32At(msg, AQH_IPCMSG_OFFS_ID, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_IpcMessage_GetRefMsgId(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint32At(msg, AQH_IPCMSG_OFFS_REFID, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_IpcMessage_GetPayloadLength(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return msg?(AQH_IpcMessage_GetMsgSize(msg)-AQH_IPCMSG_OFFS_PAYLOAD):0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t *AQH_IpcMessage_GetPayloadPointer(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return msg?(AQH_Message_GetMsgPointer(msg)+AQH_IPCMSG_OFFS_PAYLOAD):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
GWEN_Buffer_AppendArgs(dbuf, "IPC message %s (code=%d, protocol=%d, protocol version=%d)\n",
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg));
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *AQH_IpcMessage_MsgTypeToChar(uint16_t i)
|
||||
{
|
||||
switch(i) {
|
||||
case AQH_MSGTYPE_IPC_DATA_RESULT: return "Result";
|
||||
case AQH_MSGTYPE_IPC_DATA_CONNECT_REQ: return "Connect(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_UPDATEDATA: return "UpdateData";
|
||||
case AQH_MSGTYPE_IPC_DATA_DATACHANGED: return "DataChanged";
|
||||
case AQH_MSGTYPE_IPC_DATA_SETDATA: return "SetData";
|
||||
case AQH_MSGTYPE_IPC_DATA_ADDVALUE: return "AddValue";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDATA_REQ: return "GetData(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDATA_RSP: return "GetData(Rsp)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ: return "GetLastData(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP: return "GetLastData(Rsp)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ: return "GetValues(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP: return "GetValues(Rsp)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ: return "GetDevices(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP: return "GetDevices(Rsp)";
|
||||
case AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ: return "ModDevice(Req)";
|
||||
case AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE: return "AnnounceValue";
|
||||
default: return "(unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
89
aqhome/msg/ipc/m_ipc.h
Normal file
89
aqhome/msg/ipc/m_ipc.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPC_H
|
||||
#define AQH_M_IPC_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
#define AQH_IPCMSG_OFFS_SIZE 0 /* 4 bytes: number of all bytes including size, protoid, protover and code */
|
||||
#define AQH_IPCMSG_OFFS_PROTOID 4 /* 1 byte: protocol id (free to use) */
|
||||
#define AQH_IPCMSG_OFFS_PROTOVER 5 /* 1 byte: protocol version (free to use) */
|
||||
#define AQH_IPCMSG_OFFS_CODE 6 /* 2 bytes msg code (meaning depends on protocol) */
|
||||
#define AQH_IPCMSG_OFFS_ID 8 /* 4 bytes msg id */
|
||||
#define AQH_IPCMSG_OFFS_REFID 12 /* 4 bytes reference msg id */
|
||||
#define AQH_IPCMSG_OFFS_PAYLOAD 16 /* begin of payload for a given message */
|
||||
|
||||
|
||||
|
||||
#define AQH_IPC_PROTOCOL_DATA_ID 2
|
||||
#define AQH_IPC_PROTOCOL_DATA_VERSION 1
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_RESULT 0x0001 /* AQH_ResultIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_CONNECT_REQ 0x0010 /* serviceName, userName, password */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x0100 /* AQH_MultiDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x0200 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x0300 /* AQH_SetDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_ADDVALUE 0x0400 /* AQH_AddValueDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDATA_REQ 0x0500 /* AQH_GetDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDATA_RSP 0x0600 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x0700 /* AQH_GetDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x0800 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ 0x0900 /* GWEN_IpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0x0a00 /* AQH_ValuesDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ 0x0b00 /* GWEN_IpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP 0x0c00 /* AQH_DevicesDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ 0x0d00 /* AQH_DevicesDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE 0x0e00 /* AQH_ValuesDataIpcMsg */
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcMessage_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t payloadLen, const uint8_t *payload);
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcMessage_fromBuffer(const uint8_t *ptr, uint32_t len);
|
||||
|
||||
AQHOME_API void AQH_IpcMessage_AdjustMsgSize(AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API uint32_t AQH_IpcMessage_GetMsgSize(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_IpcMessage_GetProtoId(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_IpcMessage_GetProtoVersion(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint16_t AQH_IpcMessage_GetCode(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint32_t AQH_IpcMessage_GetMsgId(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint32_t AQH_IpcMessage_GetRefMsgId(const AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API uint32_t AQH_IpcMessage_GetPayloadLength(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t *AQH_IpcMessage_GetPayloadPointer(const AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API void AQH_IpcMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
AQHOME_API const char *AQH_IpcMessage_MsgTypeToChar(uint16_t i);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
81
aqhome/msg/ipc/m_ipc_result.c
Normal file
81
aqhome/msg/ipc/m_ipc_result.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/m_ipc_result.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcMessageResult_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
int result, const char *text)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_RESULT_TAGS_RESULT, result, buf);
|
||||
if (text && *text)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_RESULT_TAGS_TEXT, text, buf);
|
||||
|
||||
msg=AQH_IpcMessage_new(protoId, protoVer, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcMessageResult_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
int result=0;
|
||||
char *text=NULL;
|
||||
|
||||
if (tagList) {
|
||||
result=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_RESULT_TAGS_RESULT, 0);
|
||||
text=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_RESULT_TAGS_TEXT, NULL);
|
||||
}
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"RESULT(%s) %s (code=%d, proto=%d, proto version=%d, result=%d, text=\"%s\")\n",
|
||||
AQH_IpcMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg),
|
||||
result,
|
||||
text?text:"");
|
||||
free(text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
33
aqhome/msg/ipc/m_ipc_result.h
Normal file
33
aqhome/msg/ipc/m_ipc_result.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPC_RESULT_H
|
||||
#define AQH_M_IPC_RESULT_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGDATA_RESULT_TAGS_RESULT 0x0001
|
||||
#define AQH_MSGDATA_RESULT_TAGS_TEXT 0x0002
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcMessageResult_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
|
||||
uint32_t msgId, uint32_t refMsgId,
|
||||
int result, const char *text);
|
||||
AQHOME_API void AQH_IpcMessageResult_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
#endif
|
||||
794
aqhome/msg/ipc/m_ipc_tag16.c
Normal file
794
aqhome/msg/ipc/m_ipc_tag16.c
Normal file
@@ -0,0 +1,794 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defines
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define AQH_IPCDATA_VALUE_TAGS_ID 0x01
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DRIVER 0x02
|
||||
#define AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER 0x03
|
||||
#define AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM 0x04
|
||||
#define AQH_IPCDATA_VALUE_TAGS_TYPE 0x05
|
||||
#define AQH_IPCDATA_VALUE_TAGS_UNITS 0x06
|
||||
#define AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION 0x07
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER 0x08
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM 0x09
|
||||
#define AQH_IPCDATA_VALUE_TAGS_MODALITY 0x0a
|
||||
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_ID 0x01
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_DRIVER 0x02
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_ROOMNAME 0x03
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER 0x04
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM 0x05
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI 0x06
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_LOCATION 0x07
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION 0x08
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_DEVTYPE 0x09
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER 0x0a
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION 0x0b
|
||||
|
||||
#define AQH_IPCDATA_NODE_TAGS_BUSADDR 0x01 /* uint8_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_UID 0x02 /* uint32_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_MANUFACTURER 0x03 /* uint32_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_DEVICETYPE 0x04 /* uint16_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_DEVICEVERSION 0x05 /* uint16_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_FIRMWAREVERSION 0x06 /* uint32_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_LASTCHANGE 0x07 /* uint64_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_STATSPACKETSOUT 0x08 /* uint16_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_STATSPACKETSIN 0x09 /* uint16_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_STATSCOLLISIONS 0x0a /* uint16_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_STATSBUSY 0x0b /* uint16_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_STATSCRCERRORS 0x0c /* uint16_t */
|
||||
#define AQH_IPCDATA_NODE_TAGS_STATSIOERRORS 0x0d /* uint16_t */
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf);
|
||||
static AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len);
|
||||
static void _writeDeviceFieldsAsTagsToBuffer(const AQH_DEVICE *device, GWEN_BUFFER *buf);
|
||||
static AQH_DEVICE *_readDeviceFromTag(const uint8_t *ptr, uint32_t len);
|
||||
static void _writeNodeInfoFieldsAsTagsToBuffer(const AQH_NODE_INFO *ni, GWEN_BUFFER *buf);
|
||||
static AQH_NODE_INFO *_readNodeInfoFromTag(const uint8_t *ptr, uint32_t len);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
GWEN_TAG16_LIST *AQH_IpcMessageTag16_ParsePayload(const AQH_MESSAGE *msg, int doCopy)
|
||||
{
|
||||
if (msg) {
|
||||
const uint8_t *payloadPtr;
|
||||
uint32_t payloadSize;
|
||||
|
||||
payloadPtr=AQH_IpcMessage_GetPayloadPointer(msg);
|
||||
payloadSize=AQH_IpcMessage_GetPayloadLength(msg);
|
||||
return AQH_Tag16_ParseTags(payloadPtr, payloadSize, doCopy);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_TAG16_LIST *AQH_Tag16_ParseTags(const uint8_t *payloadPtr, uint32_t payloadSize, int doCopy)
|
||||
{
|
||||
if (payloadPtr && payloadSize) {
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
|
||||
tagList=GWEN_Tag16_List_fromBuffer(payloadPtr, payloadSize, doCopy);
|
||||
if (tagList==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error reading tags from message");
|
||||
return NULL;
|
||||
}
|
||||
return tagList;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char *AQH_Tag16_GetTagDataAsNewString(const GWEN_TAG16_LIST *tagList, unsigned int tagType, const char *defaultValue)
|
||||
{
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, tagType);
|
||||
if (tag)
|
||||
return GWEN_Tag16_GetTagDataAsNewString(tag, defaultValue);
|
||||
}
|
||||
return defaultValue?strdup(defaultValue):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Tag16_GetTagDataAsUint32(const GWEN_TAG16_LIST *tagList, unsigned int tagType, uint32_t defaultValue)
|
||||
{
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, tagType);
|
||||
return tag?GWEN_Tag16_GetTagDataAsUint32(tag, defaultValue):defaultValue;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t AQH_Tag16_GetTagDataAsUint64(const GWEN_TAG16_LIST *tagList, unsigned int tagType, uint64_t defaultValue)
|
||||
{
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, tagType);
|
||||
return tag?GWEN_Tag16_GetTagDataAsUint64(tag, defaultValue):defaultValue;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Tag16_WriteValueListAsTagsToBuffer(unsigned int tagType, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *buf)
|
||||
{
|
||||
if (valueList) {
|
||||
const AQH_VALUE *value;
|
||||
|
||||
value=AQH_Value_List_First(valueList);
|
||||
while(value) {
|
||||
int rv;
|
||||
|
||||
rv=AQH_Tag16_WriteValueAsTagToBuffer(tagType, value, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
value=AQH_Value_List_Next(value);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Tag16_WriteValueAsTagToBuffer(unsigned int tagType, const AQH_VALUE *value, GWEN_BUFFER *buf)
|
||||
{
|
||||
int startPos;
|
||||
int rv;
|
||||
|
||||
startPos=GWEN_Tag16_StartTagInBuffer(tagType, buf);
|
||||
if (startPos<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", startPos);
|
||||
return startPos;
|
||||
}
|
||||
|
||||
_writeValueFieldsAsTagsToBuffer(value, buf);
|
||||
|
||||
rv=GWEN_Tag16_EndTagInBuffer(startPos, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Tag16_WriteDeviceListAsTagsToBuffer(unsigned int tagType, const AQH_DEVICE_LIST *deviceList, GWEN_BUFFER *buf)
|
||||
{
|
||||
if (deviceList) {
|
||||
const AQH_DEVICE *device;
|
||||
|
||||
device=AQH_Device_List_First(deviceList);
|
||||
while(device) {
|
||||
int rv;
|
||||
|
||||
rv=AQH_Tag16_WriteDeviceAsTagToBuffer(tagType, device, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
device=AQH_Device_List_Next(device);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Tag16_WriteDeviceAsTagToBuffer(unsigned int tagType, const AQH_DEVICE *device, GWEN_BUFFER *buf)
|
||||
{
|
||||
int startPos;
|
||||
int rv;
|
||||
|
||||
startPos=GWEN_Tag16_StartTagInBuffer(tagType, buf);
|
||||
if (startPos<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", startPos);
|
||||
return startPos;
|
||||
}
|
||||
|
||||
_writeDeviceFieldsAsTagsToBuffer(device, buf);
|
||||
|
||||
rv=GWEN_Tag16_EndTagInBuffer(startPos, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_VALUE_TAGS_ID, AQH_Value_GetId(value), buf);
|
||||
|
||||
s=AQH_Value_GetDriver(value);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DRIVER, s, buf);
|
||||
|
||||
s=AQH_Value_GetName(value);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER, s, buf);
|
||||
|
||||
s=AQH_Value_GetNameForSystem(value);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM, s, buf);
|
||||
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_VALUE_TAGS_TYPE, AQH_Value_GetValueType(value), buf);
|
||||
|
||||
s=AQH_Value_GetValueUnits(value);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_UNITS, s, buf);
|
||||
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION, AQH_Value_GetTimestampCreation(value), buf);
|
||||
|
||||
s=AQH_Value_GetDeviceName(value);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER, s, buf);
|
||||
|
||||
s=AQH_Value_GetDeviceNameForSystem(value);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM, s, buf);
|
||||
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_VALUE_TAGS_MODALITY, AQH_Value_GetModality(value), buf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AQH_VALUE_LIST *AQH_Tag16_ReadValuesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
|
||||
{
|
||||
AQH_VALUE_LIST *valueList;
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
valueList=AQH_Value_List_new();
|
||||
tag=GWEN_Tag16_List_First(tagList);
|
||||
while(tag) {
|
||||
unsigned int tagType;
|
||||
AQH_VALUE *value;
|
||||
|
||||
tagType=GWEN_Tag16_GetTagType(tag);
|
||||
if (tagType==wantedTagType) {
|
||||
value=_readValueFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag));
|
||||
if (value)
|
||||
AQH_Value_List_Add(value, valueList);
|
||||
}
|
||||
|
||||
tag=GWEN_Tag16_List_Next(tag);
|
||||
}
|
||||
|
||||
if (AQH_Value_List_GetCount(valueList)<1) {
|
||||
AQH_Value_List_free(valueList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return valueList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE *AQH_Tag16_ReadValueFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
|
||||
{
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, wantedTagType);
|
||||
return tag?_readValueFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)):NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE_LIST *AQH_Tag16_ReadDevicesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
|
||||
{
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
deviceList=AQH_Device_List_new();
|
||||
tag=GWEN_Tag16_List_First(tagList);
|
||||
while(tag) {
|
||||
unsigned int tagType;
|
||||
AQH_DEVICE *device;
|
||||
|
||||
tagType=GWEN_Tag16_GetTagType(tag);
|
||||
if (tagType==wantedTagType) {
|
||||
device=_readDeviceFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag));
|
||||
if (device)
|
||||
AQH_Device_List_Add(device, deviceList);
|
||||
}
|
||||
|
||||
tag=GWEN_Tag16_List_Next(tag);
|
||||
}
|
||||
|
||||
if (AQH_Device_List_GetCount(deviceList)<1) {
|
||||
AQH_Device_List_free(deviceList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE *AQH_Tag16_ReadDeviceFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
|
||||
{
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, wantedTagType);
|
||||
return tag?_readDeviceFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)):NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len)
|
||||
{
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
|
||||
tagList=GWEN_Tag16_List_fromBuffer(ptr, len, 0);
|
||||
if (tagList) {
|
||||
GWEN_TAG16 *tag;
|
||||
AQH_VALUE *value;
|
||||
|
||||
value=AQH_Value_new();
|
||||
tag=GWEN_Tag16_List_First(tagList);
|
||||
while(tag) {
|
||||
unsigned int tagType;
|
||||
char *s;
|
||||
|
||||
tagType=GWEN_Tag16_GetTagType(tag);
|
||||
switch(tagType) {
|
||||
case AQH_IPCDATA_VALUE_TAGS_ID:
|
||||
AQH_Value_SetId(value, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_DRIVER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Value_SetDriver(value, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Value_SetName(value, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Value_SetNameForSystem(value, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_TYPE:
|
||||
AQH_Value_SetValueType(value, GWEN_Tag16_GetTagDataAsUint32(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_UNITS:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Value_SetValueUnits(value, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION:
|
||||
AQH_Value_SetTimestampCreation(value, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Value_SetDeviceName(value, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Value_SetDeviceNameForSystem(value, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_VALUE_TAGS_MODALITY:
|
||||
AQH_Value_SetModality(value, GWEN_Tag16_GetTagDataAsUint32(tag, 0));
|
||||
break;
|
||||
default:
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType);
|
||||
break;
|
||||
}
|
||||
tag=GWEN_Tag16_List_Next(tag);
|
||||
}
|
||||
GWEN_Tag16_List_free(tagList);
|
||||
return value;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _writeDeviceFieldsAsTagsToBuffer(const AQH_DEVICE *device, GWEN_BUFFER *buf)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_DEVICE_TAGS_ID, AQH_Device_GetId(device), buf);
|
||||
|
||||
s=AQH_Device_GetDriver(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DRIVER, s, buf);
|
||||
|
||||
s=AQH_Device_GetRoomName(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_ROOMNAME, s, buf);
|
||||
|
||||
s=AQH_Device_GetName(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER, s, buf);
|
||||
|
||||
s=AQH_Device_GetNameForSystem(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM, s, buf);
|
||||
|
||||
s=AQH_Device_GetNameForGui(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI, s, buf);
|
||||
|
||||
s=AQH_Device_GetLocation(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_LOCATION, s, buf);
|
||||
|
||||
s=AQH_Device_GetDescription(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION, s, buf);
|
||||
|
||||
s=AQH_Device_GetDeviceType(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DEVTYPE, s, buf);
|
||||
|
||||
s=AQH_Device_GetManufacturer(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER, s, buf);
|
||||
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION, AQH_Device_GetTimestampCreation(device), buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE *_readDeviceFromTag(const uint8_t *ptr, uint32_t len)
|
||||
{
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
|
||||
tagList=GWEN_Tag16_List_fromBuffer(ptr, len, 0);
|
||||
if (tagList) {
|
||||
GWEN_TAG16 *tag;
|
||||
AQH_DEVICE *device;
|
||||
|
||||
device=AQH_Device_new();
|
||||
tag=GWEN_Tag16_List_First(tagList);
|
||||
while(tag) {
|
||||
unsigned int tagType;
|
||||
char *s;
|
||||
|
||||
tagType=GWEN_Tag16_GetTagType(tag);
|
||||
switch(tagType) {
|
||||
case AQH_IPCDATA_DEVICE_TAGS_ID:
|
||||
AQH_Device_SetId(device, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_DRIVER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetDriver(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_ROOMNAME:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetRoomName(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetName(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetNameForSystem(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetNameForGui(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_LOCATION:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetLocation(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetDescription(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_DEVTYPE:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetDeviceType(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetManufacturer(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION:
|
||||
AQH_Device_SetTimestampCreation(device, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
|
||||
break;
|
||||
default:
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType);
|
||||
break;
|
||||
}
|
||||
tag=GWEN_Tag16_List_Next(tag);
|
||||
}
|
||||
GWEN_Tag16_List_free(tagList);
|
||||
return device;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int AQH_Tag16_WriteNodeInfoListAsTagsToBuffer(unsigned int tagType, const AQH_NODE_INFO_LIST *nodeInfoList, GWEN_BUFFER *buf)
|
||||
{
|
||||
if (nodeInfoList) {
|
||||
const AQH_NODE_INFO *nodeInfo;
|
||||
|
||||
nodeInfo=AQH_NodeInfo_List_First(nodeInfoList);
|
||||
while(nodeInfo) {
|
||||
int rv;
|
||||
|
||||
rv=AQH_Tag16_WriteNodeInfoAsTagToBuffer(tagType, nodeInfo, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nodeInfo=AQH_NodeInfo_List_Next(nodeInfo);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int AQH_Tag16_WriteNodeInfoAsTagToBuffer(unsigned int tagType, const AQH_NODE_INFO *ni, GWEN_BUFFER *buf)
|
||||
{
|
||||
int startPos;
|
||||
int rv;
|
||||
|
||||
startPos=GWEN_Tag16_StartTagInBuffer(tagType, buf);
|
||||
if (startPos<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", startPos);
|
||||
return startPos;
|
||||
}
|
||||
|
||||
_writeNodeInfoFieldsAsTagsToBuffer(ni, buf);
|
||||
|
||||
rv=GWEN_Tag16_EndTagInBuffer(startPos, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _writeNodeInfoFieldsAsTagsToBuffer(const AQH_NODE_INFO *ni, GWEN_BUFFER *buf)
|
||||
{
|
||||
const GWEN_TIMESTAMP *t;
|
||||
|
||||
GWEN_Tag16_WriteUint8TagToBuffer(AQH_IPCDATA_NODE_TAGS_BUSADDR, AQH_NodeInfo_GetBusAddress(ni), buf);
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_NODE_TAGS_UID, AQH_NodeInfo_GetUid(ni), buf);
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_NODE_TAGS_MANUFACTURER, AQH_NodeInfo_GetManufacturer(ni), buf);
|
||||
GWEN_Tag16_WriteUint16TagToBuffer(AQH_IPCDATA_NODE_TAGS_DEVICETYPE, AQH_NodeInfo_GetDeviceType(ni), buf);
|
||||
GWEN_Tag16_WriteUint16TagToBuffer(AQH_IPCDATA_NODE_TAGS_DEVICEVERSION, AQH_NodeInfo_GetDeviceVersion(ni), buf);
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_NODE_TAGS_FIRMWAREVERSION, AQH_NodeInfo_GetFirmwareVersion(ni), buf);
|
||||
t=AQH_NodeInfo_GetTimestampLastChange(ni);
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_NODE_TAGS_LASTCHANGE, t?((uint64_t)GWEN_Timestamp_toInt64(t)):0L, buf);
|
||||
|
||||
GWEN_Tag16_WriteUint16TagToBuffer(AQH_IPCDATA_NODE_TAGS_STATSPACKETSOUT, AQH_NodeInfo_GetStatsPacketsOut(ni), buf);
|
||||
GWEN_Tag16_WriteUint16TagToBuffer(AQH_IPCDATA_NODE_TAGS_STATSPACKETSIN, AQH_NodeInfo_GetStatsPacketsIn(ni), buf);
|
||||
GWEN_Tag16_WriteUint16TagToBuffer(AQH_IPCDATA_NODE_TAGS_STATSCOLLISIONS, AQH_NodeInfo_GetStatsCollisions(ni), buf);
|
||||
GWEN_Tag16_WriteUint16TagToBuffer(AQH_IPCDATA_NODE_TAGS_STATSBUSY, AQH_NodeInfo_GetStatsBusy(ni), buf);
|
||||
GWEN_Tag16_WriteUint16TagToBuffer(AQH_IPCDATA_NODE_TAGS_STATSCRCERRORS, AQH_NodeInfo_GetStatsCrcErrors(ni), buf);
|
||||
GWEN_Tag16_WriteUint16TagToBuffer(AQH_IPCDATA_NODE_TAGS_STATSIOERRORS, AQH_NodeInfo_GetStatsIoErrors(ni), buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_NODE_INFO_LIST *AQH_Tag16_ReadNodeInfosFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
|
||||
{
|
||||
AQH_NODE_INFO_LIST *nodeInfoList;
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
nodeInfoList=AQH_NodeInfo_List_new();
|
||||
tag=GWEN_Tag16_List_First(tagList);
|
||||
while(tag) {
|
||||
unsigned int tagType;
|
||||
|
||||
tagType=GWEN_Tag16_GetTagType(tag);
|
||||
if (tagType==wantedTagType) {
|
||||
AQH_NODE_INFO *nodeInfo;
|
||||
|
||||
nodeInfo=_readNodeInfoFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag));
|
||||
if (nodeInfo)
|
||||
AQH_NodeInfo_List_Add(nodeInfo, nodeInfoList);
|
||||
}
|
||||
|
||||
tag=GWEN_Tag16_List_Next(tag);
|
||||
}
|
||||
|
||||
if (AQH_NodeInfo_List_GetCount(nodeInfoList)<1) {
|
||||
AQH_NodeInfo_List_free(nodeInfoList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nodeInfoList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_NODE_INFO *AQH_Tag16_ReadNodeInfoFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
|
||||
{
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, wantedTagType);
|
||||
return tag?_readNodeInfoFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)):NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_NODE_INFO *_readNodeInfoFromTag(const uint8_t *ptr, uint32_t len)
|
||||
{
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
|
||||
tagList=GWEN_Tag16_List_fromBuffer(ptr, len, 0);
|
||||
if (tagList) {
|
||||
GWEN_TAG16 *tag;
|
||||
AQH_NODE_INFO *ni;
|
||||
|
||||
ni=AQH_NodeInfo_new();
|
||||
tag=GWEN_Tag16_List_First(tagList);
|
||||
while(tag) {
|
||||
unsigned int tagType;
|
||||
uint64_t u64;
|
||||
|
||||
tagType=GWEN_Tag16_GetTagType(tag);
|
||||
switch(tagType) {
|
||||
case AQH_IPCDATA_NODE_TAGS_BUSADDR:
|
||||
AQH_NodeInfo_SetBusAddress(ni, GWEN_Tag16_GetTagDataAsUint8(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_UID:
|
||||
AQH_NodeInfo_SetUid(ni, GWEN_Tag16_GetTagDataAsUint32(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_MANUFACTURER:
|
||||
AQH_NodeInfo_SetManufacturer(ni, GWEN_Tag16_GetTagDataAsUint32(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_DEVICETYPE:
|
||||
AQH_NodeInfo_SetDeviceType(ni, GWEN_Tag16_GetTagDataAsUint16(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_DEVICEVERSION:
|
||||
AQH_NodeInfo_SetDeviceVersion(ni, GWEN_Tag16_GetTagDataAsUint16(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_FIRMWAREVERSION:
|
||||
AQH_NodeInfo_SetFirmwareVersion(ni, GWEN_Tag16_GetTagDataAsUint32(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_LASTCHANGE:
|
||||
u64=GWEN_Tag16_GetTagDataAsUint64(tag, 0);
|
||||
if (u64>0) {
|
||||
GWEN_TIMESTAMP *t;
|
||||
|
||||
t=GWEN_Timestamp_fromInt64((int64_t) u64);
|
||||
if (t) {
|
||||
AQH_NodeInfo_SetTimestampLastChange(ni, t);
|
||||
GWEN_Timestamp_free(t);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_STATSPACKETSOUT:
|
||||
AQH_NodeInfo_SetStatsPacketsOut(ni, GWEN_Tag16_GetTagDataAsUint16(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_STATSPACKETSIN:
|
||||
AQH_NodeInfo_SetStatsPacketsIn(ni, GWEN_Tag16_GetTagDataAsUint16(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_STATSCOLLISIONS:
|
||||
AQH_NodeInfo_SetStatsCollisions(ni, GWEN_Tag16_GetTagDataAsUint16(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_STATSBUSY:
|
||||
AQH_NodeInfo_SetStatsBusy(ni, GWEN_Tag16_GetTagDataAsUint16(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_STATSCRCERRORS:
|
||||
AQH_NodeInfo_SetStatsCrcErrors(ni, GWEN_Tag16_GetTagDataAsUint16(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_NODE_TAGS_STATSIOERRORS:
|
||||
AQH_NodeInfo_SetStatsIoErrors(ni, GWEN_Tag16_GetTagDataAsUint16(tag, 0));
|
||||
break;
|
||||
default:
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType);
|
||||
break;
|
||||
}
|
||||
tag=GWEN_Tag16_List_Next(tag);
|
||||
}
|
||||
GWEN_Tag16_List_free(tagList);
|
||||
return ni;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
50
aqhome/msg/ipc/m_ipc_tag16.h
Normal file
50
aqhome/msg/ipc/m_ipc_tag16.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPC_TAG16_H
|
||||
#define AQH_M_IPC_TAG16_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/value.h>
|
||||
#include <aqhome/data/device.h>
|
||||
#include <aqhome/nodes/nodeinfo.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
|
||||
|
||||
|
||||
AQHOME_API GWEN_TAG16_LIST *AQH_IpcMessageTag16_ParsePayload(const AQH_MESSAGE *msg, int doCopy);
|
||||
|
||||
AQHOME_API GWEN_TAG16_LIST *AQH_Tag16_ParseTags(const uint8_t *payloadPtr, uint32_t payloadSize, int doCopy);
|
||||
AQHOME_API char *AQH_Tag16_GetTagDataAsNewString(const GWEN_TAG16_LIST *tagList, unsigned int tagType, const char *defaultValue);
|
||||
AQHOME_API uint32_t AQH_Tag16_GetTagDataAsUint32(const GWEN_TAG16_LIST *tagList, unsigned int tagType, uint32_t defaultValue);
|
||||
AQHOME_API uint64_t AQH_Tag16_GetTagDataAsUint64(const GWEN_TAG16_LIST *tagList, unsigned int tagType, uint64_t defaultValue);
|
||||
|
||||
/* utils */
|
||||
AQHOME_API int AQH_Tag16_WriteValueListAsTagsToBuffer(unsigned int tagType, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *buf);
|
||||
AQHOME_API int AQH_Tag16_WriteValueAsTagToBuffer(unsigned int tagType, const AQH_VALUE *value, GWEN_BUFFER *buf);
|
||||
AQHOME_API AQH_VALUE_LIST *AQH_Tag16_ReadValuesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
AQHOME_API AQH_VALUE *AQH_Tag16_ReadValueFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
|
||||
AQHOME_API int AQH_Tag16_WriteDeviceListAsTagsToBuffer(unsigned int tagType, const AQH_DEVICE_LIST *deviceList, GWEN_BUFFER *buf);
|
||||
AQHOME_API int AQH_Tag16_WriteDeviceAsTagToBuffer(unsigned int tagType, const AQH_DEVICE *device, GWEN_BUFFER *buf);
|
||||
AQHOME_API AQH_DEVICE_LIST *AQH_Tag16_ReadDevicesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
AQHOME_API AQH_DEVICE *AQH_Tag16_ReadDeviceFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
|
||||
AQHOME_API int AQH_Tag16_WriteNodeInfoListAsTagsToBuffer(unsigned int tagType, const AQH_NODE_INFO_LIST *nodeInfoList, GWEN_BUFFER *buf);
|
||||
AQHOME_API int AQH_Tag16_WriteNodeInfoAsTagToBuffer(unsigned int tagType, const AQH_NODE_INFO *ni, GWEN_BUFFER *buf);
|
||||
|
||||
AQHOME_API AQH_NODE_INFO_LIST *AQH_Tag16_ReadNodeInfosFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
AQHOME_API AQH_NODE_INFO *AQH_Tag16_ReadNodeInfoFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
84
aqhome/msg/ipc/nodes/0BUILD
Normal file
84
aqhome/msg/ipc/nodes/0BUILD
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<target type="ConvenienceLibrary" name="aqhmsg_ipcn" >
|
||||
|
||||
<includes type="c" >
|
||||
$(gwenhywfar_cflags)
|
||||
-I$(topsrcdir)
|
||||
-I$(topbuilddir)
|
||||
</includes>
|
||||
|
||||
<includes type="tm2" >
|
||||
--include=$(builddir)
|
||||
--include=$(srcdir)
|
||||
</includes>
|
||||
|
||||
|
||||
<define name="BUILDING_AQHOME" />
|
||||
|
||||
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
||||
|
||||
|
||||
<setVar name="tm2flags" >
|
||||
--api=AQHOME_API
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/typefiles" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_sources" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_headers_pub">
|
||||
</setVar>
|
||||
|
||||
|
||||
<setVar name="local/built_headers_priv" >
|
||||
</setVar>
|
||||
|
||||
|
||||
<headers dist="false" install="$(pkgincludedir)/msg" >
|
||||
$(local/built_headers_pub)
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/msg" >
|
||||
m_ipcn.h
|
||||
m_ipcn_forward.h
|
||||
m_ipcn_getdevices_req.h
|
||||
m_ipcn_getdevices_rsp.h
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
</headers>
|
||||
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
|
||||
m_ipcn.c
|
||||
m_ipcn_forward.c
|
||||
m_ipcn_getdevices_req.c
|
||||
m_ipcn_getdevices_rsp.c
|
||||
</sources>
|
||||
|
||||
|
||||
<extradist>
|
||||
</extradist>
|
||||
|
||||
|
||||
<useTargets>
|
||||
</useTargets>
|
||||
|
||||
<subdirs>
|
||||
</subdirs>
|
||||
|
||||
|
||||
|
||||
|
||||
</target>
|
||||
|
||||
</gwbuild>
|
||||
46
aqhome/msg/ipc/nodes/m_ipcn.c
Normal file
46
aqhome/msg/ipc/nodes/m_ipcn.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
const char *AQH_IpcnMessage_MsgTypeToChar(uint16_t i)
|
||||
{
|
||||
switch(i) {
|
||||
case AQH_MSGTYPE_IPC_NODES_RESULT: return "Result";
|
||||
case AQH_MSGTYPE_IPC_NODES_FORWARD: return "Forward";
|
||||
case AQH_MSGTYPE_IPC_NODES_VALUE: return "Value";
|
||||
case AQH_MSGTYPE_IPC_NODES_PING: return "Ping";
|
||||
case AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS: return "SetAccMsgGroups";
|
||||
case AQH_MSGTYPE_IPC_NODES_GETDEVICES_REQ: return "GetDevices(Req)";
|
||||
case AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP: return "GetDevices(Rsp)";
|
||||
default: return "(unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
43
aqhome/msg/ipc/nodes/m_ipcn.h
Normal file
43
aqhome/msg/ipc/nodes/m_ipcn.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_MSG_IPC_NODES_M_IPCN_H
|
||||
#define AQH_MSG_IPC_NODES_M_IPCN_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/msg_ipc.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_IPC_PROTOCOL_NODES_ID 1
|
||||
#define AQH_IPC_PROTOCOL_NODES_VERSION 1
|
||||
|
||||
|
||||
#define AQH_MSGTYPE_IPC_NODES_RESULT 0xf001
|
||||
|
||||
#define AQH_MSGTYPE_IPC_NODES_FORWARD 0xf100
|
||||
#define AQH_MSGTYPE_IPC_NODES_VALUE 0xf200
|
||||
#define AQH_MSGTYPE_IPC_NODES_PING 0xf300
|
||||
#define AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS 0xf400
|
||||
#define AQH_MSGTYPE_IPC_NODES_GETDEVICES_REQ 0xf500
|
||||
#define AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP 0xf600
|
||||
|
||||
|
||||
AQHOME_API const char *AQH_IpcnMessage_MsgTypeToChar(uint16_t i);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
80
aqhome/msg/ipc/nodes/m_ipcn_forward.c
Normal file
80
aqhome/msg/ipc/nodes/m_ipcn_forward.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/nodes/m_ipcn_forward.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcnMessageForward_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
const uint8_t *ptr, uint32_t len)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
|
||||
GWEN_Tag16_WriteTagToBuffer(AQH_MSGNODE_FORWARD_TAGS_MSG, ptr, len, buf);
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcnMessageForward_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
const GWEN_TAG16 *tag;
|
||||
const uint8_t *ptr;
|
||||
uint32_t len;
|
||||
|
||||
tag=tagList?GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGNODE_FORWARD_TAGS_MSG):NULL;
|
||||
ptr=tag?GWEN_Tag16_GetTagData(tag):NULL;
|
||||
len=tag?GWEN_Tag16_GetTagLength(tag):0;
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf, "FORWARD(%s) %s (code=%d, protocol=%d, protocol version=%d)\n",
|
||||
AQH_IpcnMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg));
|
||||
if (ptr && len) {
|
||||
GWEN_Text_DumpString2Buffer((const char*)ptr, len, dbuf, 2);
|
||||
GWEN_Buffer_AppendByte(dbuf, '\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
37
aqhome/msg/ipc/nodes/m_ipcn_forward.h
Normal file
37
aqhome/msg/ipc/nodes/m_ipcn_forward.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCN_M_FORWARD_H
|
||||
#define AQH_M_IPCN_M_FORWARD_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/value.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGNODE_FORWARD_TAGS_MSG 0x01
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcnMessageForward_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
const uint8_t *ptr, uint32_t len);
|
||||
|
||||
AQHOME_API void AQH_IpcnMessageForward_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
57
aqhome/msg/ipc/nodes/m_ipcn_getdevices_req.c
Normal file
57
aqhome/msg/ipc/nodes/m_ipcn_getdevices_req.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/nodes/m_ipcn_getdevices_req.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcnMessageGetDevicesReq_new(uint16_t code, uint32_t msgId, uint32_t refMsgId)
|
||||
{
|
||||
return AQH_IpcMessage_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, msgId, refMsgId, 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcnMessageGetDevicesReq_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
GWEN_Buffer_AppendArgs(dbuf, "GETDEVICESREQ(%s) %s (code=%d, protocol=%d, protocol version=%d)\n",
|
||||
AQH_IpcnMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
30
aqhome/msg/ipc/nodes/m_ipcn_getdevices_req.h
Normal file
30
aqhome/msg/ipc/nodes/m_ipcn_getdevices_req.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCN_M_GETDEVICES_REQ_H
|
||||
#define AQH_M_IPCN_M_GETDEVICES_REQ_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/value.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcnMessageGetDevicesReq_new(uint16_t code, uint32_t msgId, uint32_t refMsgId);
|
||||
AQHOME_API void AQH_IpcnMessageGetDevicesReq_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
100
aqhome/msg/ipc/nodes/m_ipcn_getdevices_rsp.c
Normal file
100
aqhome/msg/ipc/nodes/m_ipcn_getdevices_rsp.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/ipc/nodes/m_ipcn_getdevices_rsp.h"
|
||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementation
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_MESSAGE *AQH_IpcnMessageGetDevicesRsp_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t flags, const AQH_NODE_INFO *ni)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
GWEN_BUFFER *buf;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
|
||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGNODE_GETDEVICES_RSP_TAGS_FLAGS, flags, buf);
|
||||
AQH_Tag16_WriteNodeInfoAsTagToBuffer(AQH_MSGNODE_GETDEVICES_RSP_TAGS_NODEINFO, ni, buf);
|
||||
|
||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, msgId, refMsgId,
|
||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_NODE_INFO *AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(const GWEN_TAG16_LIST *tagList)
|
||||
{
|
||||
if (tagList) {
|
||||
AQH_NODE_INFO *ni;
|
||||
|
||||
ni=AQH_Tag16_ReadNodeInfoFromTagList(tagList, AQH_MSGNODE_GETDEVICES_RSP_TAGS_NODEINFO);
|
||||
if (ni==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "No node info received");
|
||||
}
|
||||
return ni;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcnMessageGetDevicesRsp_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
AQH_NODE_INFO *ni;
|
||||
uint8_t busAddr;
|
||||
uint32_t uid;
|
||||
uint32_t flags;
|
||||
|
||||
ni=tagList?AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(tagList):NULL;
|
||||
busAddr=ni?AQH_NodeInfo_GetBusAddress(ni):0;
|
||||
uid=ni?AQH_NodeInfo_GetUid(ni):0;
|
||||
flags=tagList?AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGNODE_GETDEVICES_RSP_TAGS_FLAGS, 0):0;
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf, "GETDEVICESRSP(%s) %s (code=%d, protocol=%d/%d, flags=%04x, addr=%d, uid=%08x)\n",
|
||||
AQH_IpcnMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||
sText?sText:"",
|
||||
AQH_IpcMessage_GetCode(msg),
|
||||
AQH_IpcMessage_GetProtoId(msg),
|
||||
AQH_IpcMessage_GetProtoVersion(msg),
|
||||
flags,
|
||||
busAddr,
|
||||
uid);
|
||||
AQH_NodeInfo_free(ni);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
40
aqhome/msg/ipc/nodes/m_ipcn_getdevices_rsp.h
Normal file
40
aqhome/msg/ipc/nodes/m_ipcn_getdevices_rsp.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_IPCN_M_GETDEVICES_RSP_H
|
||||
#define AQH_M_IPCN_M_GETDEVICES_RSP_H
|
||||
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
#include <aqhome/data/value.h>
|
||||
#include <aqhome/nodes/nodeinfo.h>
|
||||
|
||||
#include <gwenhywfar/tag16.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSGNODE_GETDEVICES_RSP_TAGS_FLAGS 0x01
|
||||
#define AQH_MSGNODE_GETDEVICES_RSP_TAGS_NODEINFO 0xc2
|
||||
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_IpcnMessageGetDevicesRsp_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||
uint32_t flags, const AQH_NODE_INFO *ni);
|
||||
AQHOME_API AQH_NODE_INFO *AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(const GWEN_TAG16_LIST *tagList);
|
||||
|
||||
AQHOME_API void AQH_IpcnMessageGetDevicesRsp_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||
GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -122,6 +122,9 @@ const char *AQH_Value3Msg_GetValueTypeName(const GWEN_MSG *msg)
|
||||
case AQH_MSG_VALUE3_TYPE_TEMP: return "temperature";
|
||||
case AQH_MSG_VALUE3_TYPE_HUMIDITY: return "humidity";
|
||||
case AQH_MSG_VALUE3_TYPE_DOOR: return "door_window";
|
||||
case AQH_MSG_VALUE3_TYPE_MOTION: return "motion";
|
||||
case AQH_MSG_VALUE3_TYPE_CO2: return "CO2";
|
||||
case AQH_MSG_VALUE3_TYPE_TVOC: return "TVOC";
|
||||
default: break;
|
||||
}
|
||||
return "unknown";
|
||||
@@ -151,6 +154,8 @@ const char *AQH_Value3Msg_GetValueTypeUnits(const GWEN_MSG *msg)
|
||||
case AQH_MSG_VALUE3_TYPE_TEMP: return "Celsius";
|
||||
case AQH_MSG_VALUE3_TYPE_HUMIDITY: return "%";
|
||||
case AQH_MSG_VALUE3_TYPE_DOOR: return NULL;
|
||||
case AQH_MSG_VALUE3_TYPE_CO2: return "ppm";
|
||||
case AQH_MSG_VALUE3_TYPE_TVOC: return "ppb";
|
||||
default: break;
|
||||
}
|
||||
return NULL;
|
||||
@@ -194,7 +199,8 @@ void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch
|
||||
}
|
||||
|
||||
if (AQH_Value3Msg_GetValueType(msg)==AQH_MSG_VALUE3_TYPE_DOOR)
|
||||
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%s)\n",
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%s [%04x/%04x])\n",
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg),
|
||||
sCmd,
|
||||
@@ -203,7 +209,9 @@ void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch
|
||||
(unsigned int)AQH_Value3Msg_GetMsgId(msg),
|
||||
AQH_Value3Msg_GetValueId(msg),
|
||||
AQH_Value3Msg_GetValueTypeName(msg),
|
||||
AQH_Value3Msg_GetValueAsWindowStateString(msg));
|
||||
AQH_Value3Msg_GetValueAsWindowStateString(msg),
|
||||
AQH_Value3Msg_GetValueNom(msg),
|
||||
AQH_Value3Msg_GetValueDenom(msg));
|
||||
else
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%f [%04x/%04x])\n",
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#define AQH_MSG_VALUE3_TYPE_TEMP 1
|
||||
#define AQH_MSG_VALUE3_TYPE_HUMIDITY 2
|
||||
#define AQH_MSG_VALUE3_TYPE_DOOR 3
|
||||
#define AQH_MSG_VALUE3_TYPE_MOTION 6
|
||||
#define AQH_MSG_VALUE3_TYPE_CO2 7
|
||||
#define AQH_MSG_VALUE3_TYPE_TVOC 8
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG *AQH_Value3Msg_new(uint8_t srcAddr, uint8_t destAddr,
|
||||
|
||||
110
aqhome/msg/node/0BUILD
Normal file
110
aqhome/msg/node/0BUILD
Normal file
@@ -0,0 +1,110 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<target type="ConvenienceLibrary" name="aqhmsg_node" >
|
||||
|
||||
<includes type="c" >
|
||||
$(gwenhywfar_cflags)
|
||||
-I$(topsrcdir)
|
||||
-I$(topbuilddir)
|
||||
</includes>
|
||||
|
||||
<includes type="tm2" >
|
||||
--include=$(builddir)
|
||||
--include=$(srcdir)
|
||||
</includes>
|
||||
|
||||
|
||||
<define name="BUILDING_AQHOME" />
|
||||
|
||||
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
||||
|
||||
|
||||
<setVar name="tm2flags" >
|
||||
--api=AQHOME_API
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/typefiles" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_sources" >
|
||||
</setVar>
|
||||
|
||||
<setVar name="local/built_headers_pub">
|
||||
</setVar>
|
||||
|
||||
|
||||
<setVar name="local/built_headers_priv" >
|
||||
</setVar>
|
||||
|
||||
|
||||
<headers dist="false" install="$(pkgincludedir)/msg" >
|
||||
$(local/built_headers_pub)
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/msg" >
|
||||
m_node.h
|
||||
m_device.h
|
||||
m_recvstats.h
|
||||
m_sendstats.h
|
||||
m_memstats.h
|
||||
m_sysstats.h
|
||||
m_addr.h
|
||||
m_needaddr.h
|
||||
m_ping.h
|
||||
m_pong.h
|
||||
m_reboot.h
|
||||
m_value.h
|
||||
m_flashstart.h
|
||||
m_flashdata.h
|
||||
m_flashend.h
|
||||
m_flashready.h
|
||||
m_flashresponse.h
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
</headers>
|
||||
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
|
||||
m_node.c
|
||||
m_device.c
|
||||
m_recvstats.c
|
||||
m_sendstats.c
|
||||
m_memstats.c
|
||||
m_sysstats.c
|
||||
m_addr.c
|
||||
m_needaddr.c
|
||||
m_ping.c
|
||||
m_pong.c
|
||||
m_reboot.c
|
||||
m_value.c
|
||||
m_flashstart.c
|
||||
m_flashdata.c
|
||||
m_flashend.c
|
||||
m_flashready.c
|
||||
m_flashresponse.c
|
||||
</sources>
|
||||
|
||||
|
||||
<extradist>
|
||||
</extradist>
|
||||
|
||||
|
||||
<useTargets>
|
||||
</useTargets>
|
||||
|
||||
<subdirs>
|
||||
</subdirs>
|
||||
|
||||
|
||||
|
||||
|
||||
</target>
|
||||
|
||||
</gwbuild>
|
||||
52
aqhome/msg/node/m_addr.c
Normal file
52
aqhome/msg/node/m_addr.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 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 "aqhome/msg/node/m_addr.h"
|
||||
#include "aqhome/msg/node/m_node.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_ADDR_UID 0 /* 4 bytes */
|
||||
#define AQH_MSG_OFFS_ADDR_ADDR 4 /* 1 bytes */
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_AddrMessage_GetUid(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_ADDR_UID, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_AddrMessage_GetAddr(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_ADDR_ADDR, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_AddrMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"0x%02x->0x%02x: ADDR(%s) %s (uid=0x%08x, addr=%d)\n",
|
||||
AQH_NodeMessage_GetSourceAddress(msg),
|
||||
AQH_NodeMessage_GetDestAddress(msg),
|
||||
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
|
||||
sText,
|
||||
(unsigned int) AQH_AddrMessage_GetUid(msg),
|
||||
AQH_AddrMessage_GetAddr(msg));
|
||||
}
|
||||
|
||||
|
||||
28
aqhome/msg/node/m_addr.h
Normal file
28
aqhome/msg/node/m_addr.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_ADDR_H
|
||||
#define AQH_M_ADDR_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
/* This message is used for message types ClaimAddr, DenyAddr, HaveAddr */
|
||||
|
||||
AQHOME_API uint32_t AQH_AddrMessage_GetUid(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_AddrMessage_GetAddr(const AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API void AQH_AddrMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
186
aqhome/msg/node/m_device.c
Normal file
186
aqhome/msg/node/m_device.c
Normal file
@@ -0,0 +1,186 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 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 "aqhome/msg/node/m_device.h"
|
||||
#include "aqhome/msg/node/m_node.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_DEVICE_UID 0 /* 4 bytes */
|
||||
#define AQH_MSG_OFFS_DEVICE_MANUF 4 /* 4 bytes */
|
||||
#define AQH_MSG_OFFS_DEVICE_DEVTYPE 8 /* 2 bytes */
|
||||
#define AQH_MSG_OFFS_DEVICE_DEVVERSION 10 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_DEVREVISION 11 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWVARIANT 12 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWVMAJOR 13 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWVMINOR 14 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWVPATCH 15 /* 1 byte */
|
||||
|
||||
|
||||
|
||||
static void _addDeviceId(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf);
|
||||
static int _isAllGraphic(uint32_t value, int len);
|
||||
static void _printChars(uint32_t value, int len, GWEN_BUFFER *dbuf);
|
||||
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_DeviceMessage_GetUid(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_UID, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_DeviceMessage_GetManufacturer(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MANUF, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_DeviceMessage_GetDeviceType(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVTYPE, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMessage_GetDeviceVersion(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVVERSION, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMessage_GetDeviceRevision(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVREVISION, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMessage_GetFirmwareVariant(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVARIANT, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMessage_GetFirmwareVersionMajor(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVMAJOR, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMessage_GetFirmwareVersionMinor(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVMINOR, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMessage_GetFirmwareVersionPatchlevel(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVPATCH, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_DeviceMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
if (msg) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"0x%02x->0x%02x: DEVICE %s (uid=0x%08x, dev=%08x:%04x v%d.%d (",
|
||||
AQH_NodeMessage_GetSourceAddress(msg),
|
||||
AQH_NodeMessage_GetDestAddress(msg),
|
||||
sText,
|
||||
(unsigned int) AQH_DeviceMessage_GetUid(msg),
|
||||
AQH_DeviceMessage_GetManufacturer(msg),
|
||||
AQH_DeviceMessage_GetDeviceType(msg),
|
||||
AQH_DeviceMessage_GetDeviceVersion(msg),
|
||||
AQH_DeviceMessage_GetDeviceRevision(msg));
|
||||
_addDeviceId(msg, dbuf);
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"), fw=%d.%d.%d (%d))\n",
|
||||
AQH_DeviceMessage_GetFirmwareVersionMajor(msg),
|
||||
AQH_DeviceMessage_GetFirmwareVersionMinor(msg),
|
||||
AQH_DeviceMessage_GetFirmwareVersionPatchlevel(msg),
|
||||
AQH_DeviceMessage_GetFirmwareVariant(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _addDeviceId(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
uint32_t v;
|
||||
|
||||
v=AQH_DeviceMessage_GetManufacturer(msg);
|
||||
if (_isAllGraphic(v, 4))
|
||||
_printChars(v, 4, dbuf);
|
||||
else
|
||||
GWEN_Buffer_AppendArgs(dbuf, "%08x", v);
|
||||
|
||||
GWEN_Buffer_AppendByte(dbuf, ' ');
|
||||
|
||||
v=AQH_DeviceMessage_GetDeviceType(msg);
|
||||
if (_isAllGraphic(v, 2)) {
|
||||
_printChars(v, 2, dbuf);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "%d", AQH_DeviceMessage_GetDeviceVersion(msg));
|
||||
}
|
||||
else {
|
||||
GWEN_Buffer_AppendArgs(dbuf, "%04x", v);
|
||||
GWEN_Buffer_AppendArgs(dbuf, " v%d", AQH_DeviceMessage_GetDeviceVersion(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _isAllGraphic(uint32_t value, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
uint8_t v;
|
||||
|
||||
v=value & 0xff;
|
||||
if (!(isgraph(v) || isblank(v) || v==0))
|
||||
return 0;
|
||||
value=value>>8;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _printChars(uint32_t value, int len, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
uint8_t v;
|
||||
|
||||
v=value&0xff;
|
||||
if (isgraph(v))
|
||||
GWEN_Buffer_AppendByte(dbuf, v);
|
||||
value=value>>8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
42
aqhome/msg/node/m_device.h
Normal file
42
aqhome/msg/node/m_device.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_DEVICE_H
|
||||
#define AQH_M_DEVICE_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
|
||||
AQHOME_API uint32_t AQH_DeviceMessage_GetUid(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint32_t AQH_DeviceMessage_GetManufacturer(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint16_t AQH_DeviceMessage_GetDeviceType(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMessage_GetDeviceVersion(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMessage_GetDeviceRevision(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMessage_GetFirmwareVariant(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMessage_GetFirmwareVersionMajor(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMessage_GetFirmwareVersionMinor(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMessage_GetFirmwareVersionPatchlevel(const AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API void AQH_DeviceMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
99
aqhome/msg/node/m_flashdata.c
Normal file
99
aqhome/msg/node/m_flashdata.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/node/m_flashdata.h"
|
||||
#include "aqhome/msg/node/m_node.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endianfns.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_FLASHDATA_ADDRESS 0 /* 4 bytes */
|
||||
#define AQH_MSG_OFFS_FLASHDATA_DATA 4 /* x bytes */
|
||||
|
||||
#define AQH_MSG_FLASHDATA_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_DATA)
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_FlashDataMessage_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr,
|
||||
const uint8_t *dataPtr, uint32_t dataLen)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
uint8_t *ptr;
|
||||
uint32_t i;
|
||||
|
||||
msg=AQH_NodeMessage_prepare(destAddr, srcAddr, code, dataLen+4);
|
||||
|
||||
ptr=AQH_NodeMessage_GetPayloadPointer(msg);
|
||||
*(ptr++)=addr & 0xff;
|
||||
*(ptr++)=(addr>>8) & 0xff;
|
||||
*(ptr++)=(addr>>16) & 0xff;
|
||||
*(ptr++)=(addr>>24) & 0xff;
|
||||
|
||||
for (i=0; i<dataLen; i++) {
|
||||
*(ptr++)=*(dataPtr++);
|
||||
}
|
||||
AQH_NodeMessage_AddChecksum(msg);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_FlashDataMessage_GetAddress(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_ADDRESS, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_FlashDataMessage_GetDataLen(const AQH_MESSAGE *msg)
|
||||
{
|
||||
if (msg) {
|
||||
uint8_t payloadLen;
|
||||
|
||||
payloadLen=AQH_NodeMessage_GetPayloadLength(msg);
|
||||
if (payloadLen>=4)
|
||||
return payloadLen-4; /* subtract uid bytes */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const uint8_t *AQH_FlashDataMessage_GetDataPtr(const AQH_MESSAGE *msg)
|
||||
{
|
||||
if (msg && AQH_FlashDataMessage_GetDataLen(msg))
|
||||
return AQH_NodeMessage_GetPayloadPointer(msg)+4;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_FlashDataMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHDATA(%s) %s (data address=0x%04x, data length=%d)\n",
|
||||
AQH_NodeMessage_GetSourceAddress(msg),
|
||||
AQH_NodeMessage_GetDestAddress(msg),
|
||||
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
|
||||
sText,
|
||||
AQH_FlashDataMessage_GetAddress(msg),
|
||||
AQH_FlashDataMessage_GetDataLen(msg));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
31
aqhome/msg/node/m_flashdata.h
Normal file
31
aqhome/msg/node/m_flashdata.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 AQH_M_FLASHDATA_H
|
||||
#define AQH_M_FLASHDATA_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc2/message.h>
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
AQHOME_API AQH_MESSAGE *AQH_FlashDataMessage_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr,
|
||||
const uint8_t *dataPtr, uint32_t dataLen);
|
||||
AQHOME_API uint32_t AQH_FlashDataMessage_GetAddress(const AQH_MESSAGE *msg);
|
||||
AQHOME_API uint8_t AQH_FlashDataMessage_GetDataLen(const AQH_MESSAGE *msg);
|
||||
AQHOME_API const uint8_t *AQH_FlashDataMessage_GetDataPtr(const AQH_MESSAGE *msg);
|
||||
|
||||
AQHOME_API void AQH_FlashDataMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
62
aqhome/msg/node/m_flashend.c
Normal file
62
aqhome/msg/node/m_flashend.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 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 "aqhome/msg/node/m_flashend.h"
|
||||
#include "aqhome/msg/node/m_node.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endianfns.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_FLASHEND_REASON 0 /* 1 byte */
|
||||
|
||||
|
||||
|
||||
AQH_MESSAGE *AQH_FlashEndMessage_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason)
|
||||
{
|
||||
AQH_MESSAGE *msg;
|
||||
uint8_t *ptr;
|
||||
|
||||
msg=AQH_NodeMessage_prepare(destAddr, srcAddr, code, 1);
|
||||
|
||||
ptr=AQH_NodeMessage_GetPayloadPointer(msg);
|
||||
*(ptr++)=reason & 0xff;
|
||||
AQH_NodeMessage_AddChecksum(msg);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_FlashEndMessage_GetReason(const AQH_MESSAGE *msg)
|
||||
{
|
||||
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_FlashEndMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHEND(%s) %s (reason=%d)\n",
|
||||
AQH_NodeMessage_GetSourceAddress(msg),
|
||||
AQH_NodeMessage_GetDestAddress(msg),
|
||||
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
|
||||
sText,
|
||||
AQH_FlashEndMessage_GetReason(msg));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user