aqhome: completed adapting to msgio2 interface.

This commit is contained in:
Martin Preuss
2023-07-12 13:33:04 +02:00
parent 39987b31c7
commit 08c3875a26
66 changed files with 1765 additions and 3914 deletions

View File

@@ -45,11 +45,6 @@
<headers dist="true" install="$(pkgincludedir)/msg" >
endpointmgr.h
endpoint_node.h
endpoint_log.h
endpoint_write.h
endpoint_tty.h
endpoint2_tty.h
msg_node.h
msg_ping.h
@@ -75,24 +70,14 @@
<headers dist="true" >
endpointmgr_p.h
endpoint_node_p.h
endpoint_log_p.h
endpoint_tty_p.h
endpoint2_tty_p.h
endpoint_write_p.h
</headers>
<sources>
$(local/typefiles)
endpointmgr.c
endpoint_node.c
endpoint_log.c
endpoint_tty.c
endpoint2_tty.c
endpoint_write.c
msg_node.c
msg_ping.c
msg_pong.c

View File

@@ -1,185 +0,0 @@
/****************************************************************************
* 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/endpoint_log_p.h"
#include "aqhome/msg/endpoint_node.h"
#include "aqhome/msg/msg_value.h"
#include "aqhome/msg/msg_value2.h"
#include "aqhome/msg/msg_sendstats.h"
#include "aqhome/msg/msg_recvstats.h"
#include "aqhome/msg/msg_memstats.h"
#include "aqhome/msg/msg_sysstats.h"
#include "aqhome/msg/msg_ping.h"
#include "aqhome/msg/msg_pong.h"
#include "aqhome/msg/msg_needaddr.h"
#include "aqhome/msg/msg_claimaddr.h"
#include "aqhome/msg/msg_haveaddr.h"
#include "aqhome/msg/msg_denyaddr.h"
#include "aqhome/msg/msg_device.h"
#include "aqhome/msg/msg_flashready.h"
#include "aqhome/msg/msg_flashstart.h"
#include "aqhome/msg/msg_flashresponse.h"
#include "aqhome/msg/msg_flashend.h"
#include "aqhome/msg/msg_flashdata.h"
#include "aqhome/msg/msg_reboot.h"
#include <gwenhywfar/list.h>
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/gwentime.h>
#include <gwenhywfar/text.h>
#define AQH_MSG_ENDPOINT_LOG_NAME "log"
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_LOG)
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
static void _run(GWEN_MSG_ENDPOINT *ep);
static void _logMessage(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
static void _writeToLogFile(const char *filename, const char *txt);
GWEN_MSG_ENDPOINT *AQH_LogEndpoint_new(const char *filename, int groupId)
{
GWEN_MSG_ENDPOINT *ep;
AQH_MSG_ENDPOINT_LOG *xep;
ep=AQH_NodeEndpoint_new(AQH_MSG_ENDPOINT_LOG_NAME, groupId);
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_LOG, xep);
xep->filename=strdup(filename);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_LOG, ep, xep, _freeData);
AQH_NodeEndpoint_SetAcceptedMsgGroups(ep, AQH_MSG_TYPEGROUP_ALL);
GWEN_MsgEndpoint_AddFlags(ep, GWEN_MSG_ENDPOINT_FLAGS_NOIO);
GWEN_MsgEndpoint_SetRunFn(ep, _run);
return ep;
}
void _freeData(void *bp, void *p)
{
AQH_MSG_ENDPOINT_LOG *xep;
xep=(AQH_MSG_ENDPOINT_LOG*) p;
free(xep->filename);
GWEN_FREE_OBJECT(xep);
}
void _run(GWEN_MSG_ENDPOINT *ep)
{
GWEN_MSG_LIST *msgList;
msgList=GWEN_MsgEndpoint_GetSendMessageList(ep);
if (msgList && GWEN_Msg_List_GetCount(msgList)) {
GWEN_MSG *msg;
msg=GWEN_Msg_List_First(msgList);
while(msg) {
GWEN_MSG *next;
next=GWEN_Msg_List_Next(msg);
if (GWEN_Msg_GetGroupId(msg)==GWEN_MsgEndpoint_GetGroupId(ep))
_logMessage(ep, msg);
GWEN_Msg_free(msg);
msg=next;
}
}
}
void _logMessage(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
{
AQH_MSG_ENDPOINT_LOG *xep;
uint8_t msgType;
int msgIsValid;
GWEN_BUFFER *dbuf;
GWEN_TIME *ti;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_LOG, ep);
assert(xep);
dbuf=GWEN_Buffer_new(0, 256, 0, 1);
ti=GWEN_CurrentTime();
GWEN_Time_toString(ti, "YYYY-MM-DD hh:mm:ss ", dbuf);
GWEN_Time_free(ti);
ti=NULL;
msgIsValid=(AQH_NodeMsg_IsChecksumValid(msg) && AQH_NodeMsg_IsMsgComplete(msg));
msgType=AQH_NodeMsg_GetMsgType(msg);
if (msgIsValid) {
switch(msgType) {
case AQH_MSG_TYPE_PING: AQH_PingMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_PONG: AQH_PongMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_COMSENDSTATS: AQH_SendStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_COMRECVSTATS: AQH_RecvStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_TWIBUSMEMBER: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_DEBUG: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_VALUE: AQH_ValueMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_VALUE2: AQH_Value2Msg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_NEED_ADDRESS: AQH_NeedAddrMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_CLAIM_ADDRESS: AQH_ClaimAddrMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_HAVE_ADDRESS: AQH_HaveAddrMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_DENY_ADDRESS: AQH_DenyAddrMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_DEVICE: AQH_DeviceMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_MEMSTATS: AQH_MemStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_SYSSTATS: AQH_SysStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_READY: AQH_FlashReadyMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_START: AQH_FlashStartMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_RSP: AQH_FlashResponseMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_END: AQH_FlashEndMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_DATA: AQH_FlashDataMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_REBOOT_REQ: AQH_RebootRequestMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_REBOOT_RSP: AQH_RebootResponseMsg_DumpToBuffer(msg, dbuf, "received"); break;
default: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;
}
}
else {
AQH_NodeMsg_DumpToBuffer(msg, dbuf, "(invalid) received");
}
_writeToLogFile(xep->filename, GWEN_Buffer_GetStart(dbuf));
GWEN_Buffer_free(dbuf);
}
void _writeToLogFile(const char *filename, const char *txt)
{
if (txt && *txt) {
FILE *f;
f=fopen(filename, "a+");
if (f) {
if (1!=fwrite(txt, strlen(txt), 1, f)) {
DBG_ERROR(AQH_LOGDOMAIN, "Error logging.");
}
fclose(f);
}
}
}

View File

@@ -1,23 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_ENDPOINT_LOG_H
#define AQH_ENDPOINT_LOG_H
#include "aqhome/msg/endpoint_node.h"
AQHOME_API GWEN_MSG_ENDPOINT *AQH_LogEndpoint_new(const char *filename, int groupId);
#endif

View File

@@ -1,29 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_ENDPOINT_LOG_P_H
#define AQH_ENDPOINT_LOG_P_H
#include <aqhome/api.h>
#include "aqhome/msg/endpoint_log.h"
#include <gwenhywfar/list.h>
#include <gwenhywfar/inherit.h>
typedef struct AQH_MSG_ENDPOINT_LOG AQH_MSG_ENDPOINT_LOG;
struct AQH_MSG_ENDPOINT_LOG {
char *filename;
};
#endif

View File

@@ -1,118 +0,0 @@
/****************************************************************************
* 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/endpoint_node_p.h"
#include "aqhome/msg/msg_node.h"
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#define AQH_MSG_ENDPOINT_NODE_NAME "node"
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_NODE)
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
GWEN_MSG_ENDPOINT *AQH_NodeEndpoint_new(const char *name, int groupId)
{
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_MsgEndpoint_new(name?name:AQH_MSG_ENDPOINT_NODE_NAME, groupId);
AQH_NodeEndpoint_Extend(ep);
return ep;
}
void AQH_NodeEndpoint_Extend(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT_NODE *xep;
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_NODE, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_NODE, ep, xep, _freeData);
}
void _freeData(void *bp, void *p)
{
AQH_MSG_ENDPOINT_NODE *xep;
xep=(AQH_MSG_ENDPOINT_NODE*) p;
GWEN_FREE_OBJECT(xep);
}
uint32_t AQH_NodeEndpoint_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT *ep)
{
const AQH_MSG_ENDPOINT_NODE *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_NODE, ep);
assert(xep);
if (xep)
return xep->acceptedMsgGroups;
return 0;
}
void AQH_NodeEndpoint_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t f)
{
AQH_MSG_ENDPOINT_NODE *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_NODE, ep);
assert(xep);
if (xep)
xep->acceptedMsgGroups=f;
}
void AQH_NodeEndpoint_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t f)
{
AQH_MSG_ENDPOINT_NODE *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_NODE, ep);
assert(xep);
if (xep)
xep->acceptedMsgGroups|=f;
}
void AQH_NodeEndpoint_DelAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t f)
{
AQH_MSG_ENDPOINT_NODE *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_NODE, ep);
assert(xep);
if (xep)
xep->acceptedMsgGroups&=~f;
}

View File

@@ -1,32 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSGENDPOINT_NODE_H
#define AQH_MSGENDPOINT_NODE_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint.h>
#define AQH_MSGEP_NODE_FLAGS_NOMESSAGES 0x0002
AQHOME_API GWEN_MSG_ENDPOINT *AQH_NodeEndpoint_new(const char *name, int groupId);
AQHOME_API void AQH_NodeEndpoint_Extend(GWEN_MSG_ENDPOINT *ep);
AQHOME_API uint32_t AQH_NodeEndpoint_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_NodeEndpoint_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t f);
AQHOME_API void AQH_NodeEndpoint_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t f);
AQHOME_API void AQH_NodeEndpoint_DelAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t f);
#endif

View File

@@ -1,30 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSGENDPOINT_NODE_P_H
#define AQH_MSGENDPOINT_NODE_P_H
#include <aqhome/api.h>
#include "aqhome/msg/endpoint_node.h"
#include <termios.h>
typedef struct AQH_MSG_ENDPOINT_NODE AQH_MSG_ENDPOINT_NODE;
struct AQH_MSG_ENDPOINT_NODE {
uint32_t acceptedMsgGroups;
};
#endif

View File

@@ -1,449 +0,0 @@
/****************************************************************************
* 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/endpoint_tty_p.h"
#include "aqhome/msg/endpoint_node.h"
#include "aqhome/msg/msg_node.h"
#include <gwenhywfar/endpoint_connectable.h>
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <unistd.h>
#define AQH_MSG_ENDPOINT_TTY_BAUDRATE B19200
#define AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS 520
#define AQH_MSG_ENDPOINT_TTY_BUFFERSIZE 128
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY)
static int _handleReadable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *emgr);
static int _handleWritable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *emgr);
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
static int _connect(GWEN_MSG_ENDPOINT *ep);
static int _startMsg(GWEN_MSG_ENDPOINT *ep);
static int _endMsg(GWEN_MSG_ENDPOINT *ep);
static int _isLineBusy(GWEN_MSG_ENDPOINT *ep);
static int _openDevice(GWEN_MSG_ENDPOINT *ep);
static int _attnLow(GWEN_MSG_ENDPOINT *ep);
static int _attnHigh(GWEN_MSG_ENDPOINT *ep);
static int _isAttnLow(GWEN_MSG_ENDPOINT *ep);
GWEN_MSG_ENDPOINT *AQH_TtyNodeEndpoint_new(const char *devicePath, int groupId)
{
GWEN_MSG_ENDPOINT *ep;
AQH_MSG_ENDPOINT_TTY *xep;
ep=AQH_NodeEndpoint_new(AQH_MSG_ENDPOINT_TTY_NAME, groupId);
GWEN_ConnectableMsgEndpoint_Extend(ep);
GWEN_ConnectableMsgEndpoint_SetReconnectWaitTime(ep, 5);
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_TTY, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep, xep, _freeData);
AQH_NodeEndpoint_SetAcceptedMsgGroups(ep, AQH_MSG_TYPEGROUP_ALL);
GWEN_MsgEndpoint_SetHandleReadableFn(ep, _handleReadable);
GWEN_MsgEndpoint_SetHandleWritableFn(ep, _handleWritable);
GWEN_ConnectableMsgEndpoint_SetConnectFn(ep, _connect);
xep->deviceName=strdup(devicePath);
return ep;
}
void _freeData(void *bp, void *p)
{
AQH_MSG_ENDPOINT_TTY *xep;
xep=(AQH_MSG_ENDPOINT_TTY*) p;
free(xep->deviceName);
GWEN_FREE_OBJECT(xep);
}
int _connect(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT_TTY *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
if (xep) {
int state;
state=GWEN_ConnectableMsgEndpoint_GetState(ep);
if (state<GWEN_MSG_ENDPOINT_CONN_STATE_CONNECTED) {
int fd;
DBG_INFO(AQH_LOGDOMAIN, "Opening device %s", xep->deviceName);
fd=_openDevice(ep);
if (fd<0) {
DBG_INFO(NULL, "here (%d)", fd);
return fd;
}
GWEN_MsgEndpoint_SetFd(ep, fd);
GWEN_ConnectableMsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_CONN_STATE_CONNECTED);
_attnHigh(ep);
}
return 0;
}
return GWEN_ERROR_GENERIC;
}
int _handleReadable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *emgr)
{
int rv;
uint8_t buffer[AQH_MSG_ENDPOINT_TTY_BUFFERSIZE];
int len;
int i;
DBG_DEBUG(GWEN_LOGDOMAIN, "Reading from endpoint %s", GWEN_MsgEndpoint_GetName(ep));
do {
rv=read(GWEN_MsgEndpoint_GetFd(ep), buffer, sizeof(buffer));
} while( (rv<0) && errno==EINTR);
if (rv<0) {
if (errno==EAGAIN || errno==EWOULDBLOCK)
return GWEN_ERROR_TRY_AGAIN;
DBG_INFO(GWEN_LOGDOMAIN, "Error on read(): %s (%d)", strerror(errno), errno);
return GWEN_ERROR_IO;
}
else if (rv==0) {
DBG_INFO(GWEN_LOGDOMAIN, "EOF met on read()");
return GWEN_ERROR_IO;
}
len=rv;
for (i=0; i<len; i++) {
GWEN_MSG *msg;
msg=GWEN_MsgEndpoint_GetCurrentlyReceivedMsg(ep);
if (msg==NULL) {
msg=GWEN_Msg_new(AQH_MSG_ENDPOINT_TTY_BUFFERSIZE);
GWEN_Msg_SetGroupId(msg, GWEN_MsgEndpoint_GetGroupId(ep));
GWEN_MsgEndpoint_SetCurrentlyReceivedMsg(ep, msg);
}
rv=GWEN_Msg_AddByte(msg, buffer[i]);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
return rv;
}
rv=AQH_NodeMsg_IsMsgComplete(msg);
if (rv<0) {
/* invalid message */
DBG_ERROR(GWEN_LOGDOMAIN, "Invalid message, discarding");
GWEN_MsgEndpoint_SetCurrentlyReceivedMsg(ep, NULL);
rv=GWEN_MsgEndpoint_DiscardInput(ep);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
return rv;
}
break;
}
else if (rv>0) {
/* complete msg received, add to list */
if (!AQH_NodeMsg_IsChecksumValid(msg)) {
DBG_ERROR(AQH_LOGDOMAIN, "Invalid checksum, discarding message");
GWEN_Text_DumpString((const char*) GWEN_Msg_GetBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), 6);
GWEN_MsgEndpoint_SetCurrentlyReceivedMsg(ep, NULL);
rv=GWEN_MsgEndpoint_DiscardInput(ep);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
return rv;
}
}
else {
GWEN_Msg_Attach(msg);
GWEN_MsgEndpoint_SetCurrentlyReceivedMsg(ep, NULL);
GWEN_MsgEndpoint_AddReceivedMessage(ep, msg);
}
}
} /* for */
return 0;
}
int _handleWritable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *emgr)
{
GWEN_MSG *msg;
DBG_DEBUG(AQH_LOGDOMAIN, "Writing to endpoint %s", GWEN_MsgEndpoint_GetName(ep));
msg=GWEN_MsgEndpoint_GetFirstSendMessage(ep);
if (msg) {
uint8_t pos;
int remaining;
int rv;
pos=GWEN_Msg_GetCurrentPos(msg);
remaining=GWEN_Msg_GetRemainingBytes(msg);
if (remaining>0) {
const uint8_t *buf;
int fd;
if (pos==0) {
/* start new message */
rv=_isLineBusy(ep);
if (rv<0 || rv==1) {
DBG_INFO(AQH_LOGDOMAIN, "Line busy, not sending");
usleep(100);
return 0;
}
rv=_startMsg(ep);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
}
fd=GWEN_MsgEndpoint_GetFd(ep);
/* start new message */
buf=GWEN_Msg_GetBuffer(msg)+pos;
do {
rv=write(fd, buf, remaining);
} while(rv<0 && errno==EINTR);
if (rv<0) {
if (errno==EAGAIN || errno==EWOULDBLOCK)
return GWEN_ERROR_TRY_AGAIN;
DBG_INFO(GWEN_LOGDOMAIN, "Error on write(): %s (%d)", strerror(errno), errno);
return GWEN_ERROR_IO;
}
GWEN_Msg_IncCurrentPos(msg, rv);
if (rv==remaining) {
/* end current message */
rv=_endMsg(ep);
GWEN_Msg_List_Del(msg);
GWEN_Msg_free(msg);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
}
}
else {
DBG_INFO(AQH_LOGDOMAIN, "No remaining bytes in msg");
}
}
return 0;
}
int _openDevice(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT_TTY *xep;
int fd;
struct termios options;
int rv;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=open(xep->deviceName, O_NOCTTY | O_NDELAY | O_RDWR);
if (fd<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on open(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
rv=tcgetattr(fd, &(xep->previousOptions));
if (rv<0) {
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.c_cflag=CLOCAL | CREAD | CS8;
options.c_iflag=IGNPAR | IGNBRK;
options.c_oflag=0;
options.c_lflag=0;
cfmakeraw(&options);
options.c_cc[VTIME]=0; /* read timeout in deciseconds */
options.c_cc[VMIN]=0; /* no minimum number of receive bytes */
rv=cfsetispeed(&options, AQH_MSG_ENDPOINT_TTY_BAUDRATE);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on cfsetispeed(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
rv=cfsetospeed(&options, AQH_MSG_ENDPOINT_TTY_BAUDRATE);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on cfsetospeed(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
rv=tcflush(fd, TCIOFLUSH);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcflush(%s): %s (%d)", xep->deviceName, 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)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
return fd;
}
int _startMsg(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT_TTY *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
if (xep->intendedAttnState==1) {
int rv;
rv=_attnLow(ep);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
usleep(AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS/5);
}
return 0;
}
int _endMsg(GWEN_MSG_ENDPOINT *ep)
{
/* TODO: flush before releasing ATTN */
_attnHigh(ep);
return 0;
}
int _isLineBusy(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT_TTY *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
if (xep->intendedAttnState==0) {
/* we pulled the line low ourselves, and because of the circuitry nobody can pull it high */
return 0;
}
return _isAttnLow(ep);
}
int _attnLow(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=GWEN_MsgEndpoint_GetFd(ep);
rv=ioctl(fd, TIOCMGET, &status); /* GET the State of MODEM bits in Status */
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
status |= TIOCM_DTR | TIOCM_RTS; /* clear the DTR pin (cave: signals inverted!) */
rv=ioctl(fd, TIOCMSET, &status);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
xep->intendedAttnState=0;
return 0;
}
int _attnHigh(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=GWEN_MsgEndpoint_GetFd(ep);
rv=ioctl(fd, TIOCMGET, &status);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
status |= TIOCM_DTR; /* Set the DTR pin */
status &= ~ (TIOCM_DTR | TIOCM_RTS); /* clear the DTR pin (cave: signals inverted!) */
rv=ioctl(fd, TIOCMSET, &status);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
xep->intendedAttnState=1;
return 0;
}
int _isAttnLow(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=GWEN_MsgEndpoint_GetFd(ep);
rv=ioctl(fd, TIOCMGET, &status);
if (rv<0) {
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
return GWEN_ERROR_IO;
}
return (status & TIOCM_CTS)?1:0;
}

View File

@@ -1,24 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSGENDPOINT_TTY_H
#define AQH_MSGENDPOINT_TTY_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint.h>
#define AQH_MSG_ENDPOINT_TTY_NAME "tty"
AQHOME_API GWEN_MSG_ENDPOINT *AQH_TtyNodeEndpoint_new(const char *devicePath, int groupId);
#endif

View File

@@ -1,32 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSGENDPOINT_TTY_P_H
#define AQH_MSGENDPOINT_TTY_P_H
#include <aqhome/api.h>
#include "aqhome/msg/endpoint_tty.h"
#include <termios.h>
typedef struct AQH_MSG_ENDPOINT_TTY AQH_MSG_ENDPOINT_TTY;
struct AQH_MSG_ENDPOINT_TTY {
char *deviceName;
struct termios previousOptions;
int intendedAttnState;
};
#endif

View File

@@ -1,268 +0,0 @@
/****************************************************************************
* 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/endpoint_write_p.h"
#include "aqhome/msg/endpoint_node.h"
#include "aqhome/msg/msg_value2.h"
#include "aqhome/msg/msg_sendstats.h"
#include "aqhome/msg/msg_recvstats.h"
#include "aqhome/msg/msg_memstats.h"
#include "aqhome/msg/msg_sysstats.h"
#include <gwenhywfar/list.h>
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/gwentime.h>
#include <gwenhywfar/text.h>
#include <gwenhywfar/directory.h>
#include <unistd.h>
#include <stdio.h>
#define AQH_MSG_ENDPOINT_WRITE_NAME "write"
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_WRITE)
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
static void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
static void _processValue2Message(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
static void _processSendStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
static void _processRecvStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
static void _writeDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v);
static void _writeInt(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, int v);
static void _writeString(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, const char *v);
static void _writeToFile(const char *filename, const char *txt);
GWEN_MSG_ENDPOINT *AQH_WriteEndpoint_new(const char *folder, int groupId)
{
GWEN_MSG_ENDPOINT *ep;
AQH_MSG_ENDPOINT_WRITE *xep;
ep=AQH_NodeEndpoint_new(AQH_MSG_ENDPOINT_WRITE_NAME, groupId);
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_WRITE, xep);
xep->folder=strdup(folder);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_WRITE, ep, xep, _freeData);
AQH_NodeEndpoint_SetAcceptedMsgGroups(ep, AQH_MSG_TYPEGROUP_INFO | AQH_MSG_TYPEGROUP_VALUES);
GWEN_MsgEndpoint_AddFlags(ep, GWEN_MSG_ENDPOINT_FLAGS_NOIO);
GWEN_MsgEndpoint_SetProcessOutMsgFn(ep, _processOutMessage);
return ep;
}
void _freeData(void *bp, void *p)
{
AQH_MSG_ENDPOINT_WRITE *xep;
xep=(AQH_MSG_ENDPOINT_WRITE*) p;
free(xep->folder);
GWEN_FREE_OBJECT(xep);
}
void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
{
DBG_DEBUG(AQH_LOGDOMAIN, "Processing output message");
switch(AQH_NodeMsg_GetMsgType(nodeMsg)) {
case AQH_MSG_TYPE_VALUE2:
_processValue2Message(ep, nodeMsg);
break;
case AQH_MSG_TYPE_COMSENDSTATS:
_processSendStatsMessage(ep, nodeMsg);
break;
case AQH_MSG_TYPE_COMRECVSTATS:
_processRecvStatsMessage(ep, nodeMsg);
break;
default:
break;
}
GWEN_Msg_free(nodeMsg);
}
void _processValue2Message(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
{
const char *sType;
sType=AQH_Value2Msg_GetValueTypeName(nodeMsg);
if (sType && *sType) {
if (AQH_Value2Msg_GetValueType(nodeMsg)==AQH_MSG_VALUE2_TYPE_DOOR)
_writeString(ep,
AQH_Value2Msg_GetUid(nodeMsg),
AQH_Value2Msg_GetValueId(nodeMsg),
sType,
AQH_Value2Msg_GetValueAsWindowStateString(nodeMsg));
else
_writeDouble(ep,
AQH_Value2Msg_GetUid(nodeMsg),
AQH_Value2Msg_GetValueId(nodeMsg),
sType,
AQH_Value2Msg_GetValue(nodeMsg));
}
_writeDouble(ep,
AQH_Value2Msg_GetUid(nodeMsg),
AQH_Value2Msg_GetValueId(nodeMsg),
"value",
AQH_Value2Msg_GetValue(nodeMsg));
}
void _processSendStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
{
uint16_t packetsOutInt;
packetsOutInt=AQH_SendStatsMsg_GetPacketsOut(nodeMsg);
if (packetsOutInt) {
double packetsOut;
double collisions;
double busy;
double collisionsPercentage=0.0;
double busyPercentage=0.0;
packetsOut=(double) packetsOutInt;
collisions=(double)AQH_SendStatsMsg_GetCollisions(nodeMsg);
busy=(double)AQH_SendStatsMsg_GetBusyErrors(nodeMsg);
collisionsPercentage=collisions*100.0/packetsOut;
busyPercentage=busy*100.0/packetsOut;
_writeInt(ep, AQH_SendStatsMsg_GetUid(nodeMsg), 0, "net/packetsOut", packetsOutInt);
_writeInt(ep, AQH_SendStatsMsg_GetUid(nodeMsg), 0, "net/collisions", (int) AQH_SendStatsMsg_GetCollisions(nodeMsg));
_writeDouble(ep, AQH_SendStatsMsg_GetUid(nodeMsg), 0, "net/collisionsPercent", collisionsPercentage);
_writeDouble(ep, AQH_SendStatsMsg_GetUid(nodeMsg), 0, "net/busyPercent", busyPercentage);
}
}
void _processRecvStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
{
uint16_t packetsInInt;
packetsInInt=AQH_RecvStatsMsg_GetPacketsIn(nodeMsg);
if (packetsInInt) {
double packetsIn;
double crcErrors;
double ioErrors;
double crcErrorsPercentage=0.0;
double ioErrorsPercentage=0.0;
packetsIn=(double) packetsInInt;
crcErrors=(double)AQH_RecvStatsMsg_GetCrcErrors(nodeMsg);
ioErrors=(double)AQH_RecvStatsMsg_GetIoErrors(nodeMsg);
crcErrorsPercentage=crcErrors*100.0/packetsIn;
ioErrorsPercentage=ioErrors*100.0/packetsIn;
_writeInt(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/packetsIn", packetsInInt);
_writeInt(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/crcerrors", (int) AQH_RecvStatsMsg_GetCrcErrors(nodeMsg));
_writeInt(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/ioerrors", (int) AQH_RecvStatsMsg_GetIoErrors(nodeMsg));
_writeDouble(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/crcerrorsPercent", crcErrorsPercentage);
_writeDouble(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/ioerrorsPercent", ioErrorsPercentage);
}
}
void _writeDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v)
{
char numBuf[16];
snprintf(numBuf, sizeof(numBuf)-1, "%f", v);
numBuf[sizeof(numBuf)-1]=0;
_writeString(ep, uid, valueId, valuePath, numBuf);
}
void _writeInt(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, int v)
{
char numBuf[16];
snprintf(numBuf, sizeof(numBuf)-1, "%d", v);
numBuf[sizeof(numBuf)-1]=0;
_writeString(ep, uid, valueId, valuePath, numBuf);
}
void _writeString(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, const char *v)
{
AQH_MSG_ENDPOINT_WRITE *xep;
GWEN_BUFFER *bufFilename;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_WRITE, ep);
bufFilename=GWEN_Buffer_new(0, 64, 0, 1);
if (valueId>0)
GWEN_Buffer_AppendArgs(bufFilename, "%s/%08x/%d/%s", xep->folder, uid, valueId, valuePath);
else
GWEN_Buffer_AppendArgs(bufFilename, "%s/%08x/%s", xep->folder, uid, valuePath);
_writeToFile(GWEN_Buffer_GetStart(bufFilename), v);
GWEN_Buffer_free(bufFilename);
}
void _writeToFile(const char *filename, const char *txt)
{
if (txt && *txt) {
GWEN_BUFFER *tmpNameBuf;
int rv;
tmpNameBuf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendString(tmpNameBuf, filename);
GWEN_Buffer_AppendString(tmpNameBuf, ".tmp");
rv=GWEN_Directory_GetPath(GWEN_Buffer_GetStart(tmpNameBuf), GWEN_PATH_FLAGS_VARIABLE);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "Error getting path for %s (%d)", GWEN_Buffer_GetStart(tmpNameBuf), rv);
}
else {
FILE *f;
f=fopen(GWEN_Buffer_GetStart(tmpNameBuf), "w");
if (f) {
if (1!=fwrite(txt, strlen(txt), 1, f)) {
DBG_ERROR(AQH_LOGDOMAIN, "Error writing.");
fclose(f);
}
else {
fclose(f);
rename(GWEN_Buffer_GetStart(tmpNameBuf), filename);
}
}
}
GWEN_Buffer_free(tmpNameBuf);
}
}

View File

@@ -1,23 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_ENDPOINT_WRITE_H
#define AQH_ENDPOINT_WRITE_H
#include "aqhome/msg/endpoint_node.h"
AQHOME_API GWEN_MSG_ENDPOINT *AQH_WriteEndpoint_new(const char *folder, int groupId);
#endif

View File

@@ -1,29 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_ENDPOINT_WRITE_P_H
#define AQH_ENDPOINT_WRITE_P_H
#include <aqhome/api.h>
#include "aqhome/msg/endpoint_write.h"
#include <gwenhywfar/list.h>
#include <gwenhywfar/inherit.h>
typedef struct AQH_MSG_ENDPOINT_WRITE AQH_MSG_ENDPOINT_WRITE;
struct AQH_MSG_ENDPOINT_WRITE {
char *folder;
};
#endif

View File

@@ -1,138 +0,0 @@
/****************************************************************************
* 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/endpointmgr_p.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/msg/endpoint_node.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
GWEN_INHERIT(GWEN_MSG_ENDPOINT_MGR, AQH_MSG_ENDPOINT_MGR);
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
GWEN_MSG_ENDPOINT_MGR *AQH_MsgEndpointMgr_new(uint8_t busAddr)
{
GWEN_MSG_ENDPOINT_MGR *mgr;
AQH_MSG_ENDPOINT_MGR *xmgr;
mgr=GWEN_MsgEndpointMgr_new();
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_MGR, xmgr);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT_MGR, AQH_MSG_ENDPOINT_MGR, mgr, xmgr, _freeData);
xmgr->busAddr=busAddr;
return mgr;
}
void _freeData(void *bp, void *p)
{
AQH_MSG_ENDPOINT_MGR *xmgr;
xmgr=(AQH_MSG_ENDPOINT_MGR*) p;
GWEN_FREE_OBJECT(xmgr);
}
uint8_t AQH_MsgEndpointMgr_GetBusAddr(GWEN_MSG_ENDPOINT_MGR *emgr)
{
AQH_MSG_ENDPOINT_MGR *xmgr;
xmgr=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT_MGR, AQH_MSG_ENDPOINT_MGR, emgr);
if (xmgr)
return xmgr->busAddr;
return 0;
}
void AQH_MsgEndpointMgr_DistributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr,
GWEN_MSG_ENDPOINT *srcEp,
const GWEN_MSG *msg,
int groupId,
const char *wantedTypeName)
{
GWEN_MSG_ENDPOINT_LIST *endpointList;
endpointList=GWEN_MsgEndpointMgr_GetEndpointList(emgr);
if (endpointList) {
GWEN_MSG_ENDPOINT *ep;
uint32_t msgGroup;
msgGroup=AQH_NodeMsg_GetMsgGroup(AQH_NodeMsg_GetMsgType(msg));
ep=GWEN_MsgEndpoint_List_First(endpointList);
while(ep) {
if (ep!=srcEp) {
const char *epTypeName;
epTypeName=GWEN_MsgEndpoint_GetName(ep);
if (wantedTypeName==NULL || (wantedTypeName && epTypeName && strcasecmp(epTypeName, wantedTypeName)==0)) {
if (!(GWEN_MsgEndpoint_GetFlags(ep) & AQH_MSGEP_NODE_FLAGS_NOMESSAGES)) {
int acceptedGroupIds;
uint32_t acceptedMsgGroups;
acceptedGroupIds=GWEN_MsgEndpoint_GetAcceptedGroupIds(ep);
acceptedMsgGroups=AQH_NodeEndpoint_GetAcceptedMsgGroups(ep);
DBG_DEBUG(AQH_LOGDOMAIN, "- checking endpoint %s (msgGroup=%08x, accept: %08x, flags: %08x)",
GWEN_MsgEndpoint_GetName(ep),
msgGroup, acceptedMsgGroups,
GWEN_MsgEndpoint_GetFlags(ep));
if (acceptedGroupIds & groupId) {
if ((msgGroup & acceptedMsgGroups)) {
/* endpoint accepts this message */
DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s accepts message", GWEN_MsgEndpoint_GetName(ep));
GWEN_MsgEndpoint_ProcessOutMessage(ep, GWEN_Msg_dup(msg));
}
else {
DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s does not accept message", GWEN_MsgEndpoint_GetName(ep));
}
} /* if (acceptedGroupIds & groupId) */
else {
DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s does not contain groupId %d (%d)",
GWEN_MsgEndpoint_GetName(ep), groupId, acceptedGroupIds);
}
} /* !(GWEN_MsgEndpoint_GetFlags(ep) & AQH_MSGEP_NODE_FLAGS_NOMESSAGES) */
else {
DBG_DEBUG(AQH_LOGDOMAIN, "Not checking endpoint %s (NOMSG set)", epTypeName);
}
} /* if wantedTypeName matches */
else {
DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s doesn't match", epTypeName);
}
} /* if (ep!=srcEp) */
ep=GWEN_MsgEndpoint_List_Next(ep);
} /* while */
}
}

View File

@@ -1,32 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSG_ENDPOINT_MGR_H
#define AQH_MSG_ENDPOINT_MGR_H
#include <aqhome/api.h>
#include <gwenhywfar/endpointmgr.h>
AQHOME_API GWEN_MSG_ENDPOINT_MGR *AQH_MsgEndpointMgr_new(uint8_t busAddr);
AQHOME_API uint8_t AQH_MsgEndpointMgr_GetBusAddr(GWEN_MSG_ENDPOINT_MGR *emgr);
AQHOME_API void AQH_MsgEndpointMgr_DistributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr,
GWEN_MSG_ENDPOINT *srcEp,
const GWEN_MSG *msg,
int groupId,
const char *wantedTypeName);
#endif

View File

@@ -1,29 +0,0 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSG_ENDPOINT_MGR_P_H
#define AQH_MSG_ENDPOINT_MGR_P_H
#include <aqhome/api.h>
#include "aqhome/msg/endpointmgr.h"
typedef struct AQH_MSG_ENDPOINT_MGR AQH_MSG_ENDPOINT_MGR;
struct AQH_MSG_ENDPOINT_MGR {
uint8_t busAddr;
};
#endif