adapted to latest changes in gwen (msgio API v2 becomes v1).

This commit is contained in:
Martin Preuss
2023-07-12 19:30:53 +02:00
parent 7a4edb6854
commit 0fd58567fe
37 changed files with 956 additions and 956 deletions

View File

@@ -45,7 +45,7 @@
<headers dist="true" install="$(pkgincludedir)/msg" >
endpoint2_tty.h
endpoint_tty.h
msg_node.h
msg_ping.h
msg_pong.h
@@ -70,14 +70,14 @@
<headers dist="true" >
endpoint2_tty_p.h
endpoint_tty_p.h
</headers>
<sources>
$(local/typefiles)
endpoint2_tty.c
endpoint_tty.c
msg_node.c
msg_ping.c
msg_pong.c

View File

@@ -11,14 +11,14 @@
#endif
#include "aqhome/msg/endpoint2_tty_p.h"
#include "aqhome/msg/endpoint_tty_p.h"
#include "aqhome/msg/msg_node.h"
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#include <gwenhywfar/endpoint2_msgio.h>
#include <gwenhywfar/endpoint_msgio.h>
#include <fcntl.h>
#include <termios.h>
@@ -28,13 +28,13 @@
#define AQH_MSG_ENDPOINT2_TTY_BAUDRATE B19200
#define AQH_MSG_ENDPOINT2_TTY_BYTE_MICROSECS 520
#define GWEN_ENDPOINT2_TTY_RECONNECT_TIME 10
#define AQH_MSG_ENDPOINT_TTY_BAUDRATE B19200
#define AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS 520
#define GWEN_ENDPOINT_TTY_RECONNECT_TIME 10
GWEN_INHERIT(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY)
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY)
@@ -46,20 +46,20 @@ GWEN_INHERIT(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY)
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
/* virtual fn for GWEN_MSG_ENDPOINT2 */
static void _addSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
/* virtual fn for GWEN_MSG_ENDPOINT */
static void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet);
/* virtual fns for GWEN_MSG_ENDPOINT2_MSGIO */
static int _getBytesNeededForMessage(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg);
static int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg);
static void _endMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg);
/* virtual fns for GWEN_MSG_ENDPOINT_MSGIO */
static int _getBytesNeededForMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
static int _startMsg(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
static void _endMsg(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
/* private fns */
static int _getSocketFd(GWEN_MSG_ENDPOINT2 *ep);
static int _openDevice(GWEN_MSG_ENDPOINT2 *ep);
static int _attnLow(GWEN_MSG_ENDPOINT2 *ep);
static int _attnHigh(GWEN_MSG_ENDPOINT2 *ep);
static int _isAttnLow(GWEN_MSG_ENDPOINT2 *ep);
static int _getSocketFd(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);
@@ -69,26 +69,26 @@ static int _isAttnLow(GWEN_MSG_ENDPOINT2 *ep);
*/
GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint2_new(const char *devicePath, int groupId)
GWEN_MSG_ENDPOINT *AQH_TtyEndpoint_new(const char *devicePath, int groupId)
{
GWEN_MSG_ENDPOINT2 *ep;
AQH_MSG_ENDPOINT2_TTY *xep;
GWEN_MSG_ENDPOINT *ep;
AQH_MSG_ENDPOINT_TTY *xep;
ep=GWEN_MsgEndpoint2_new(AQH_MSG_ENDPOINT2_TTY_NAME, groupId);
GWEN_MsgEndpoint2_SetDefaultMessageSize(ep, AQH_MAXMSGSIZE);
ep=GWEN_MsgEndpoint_new(AQH_MSG_ENDPOINT_TTY_NAME, groupId);
GWEN_MsgEndpoint_SetDefaultMessageSize(ep, AQH_MAXMSGSIZE);
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT2_TTY, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep, xep, _freeData);
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_TTY, xep);
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep, xep, _freeData);
xep->deviceName=strdup(devicePath);
GWEN_MsgEndpoint2_SetAddSocketsFn(ep, _addSockets);
GWEN_MsgEndpoint_SetAddSocketsFn(ep, _addSockets);
/* extend with msg handling code */
GWEN_MsgIoEndpoint2_Extend(ep);
GWEN_MsgIoEndpoint2_SetGetNeededBytesFn(ep, _getBytesNeededForMessage);
GWEN_MsgIoEndpoint2_SetSendMsgStartFn(ep, _startMsg);
GWEN_MsgIoEndpoint2_SetSendMsgFinishFn(ep, _endMsg);
GWEN_MsgIoEndpoint_Extend(ep);
GWEN_MsgIoEndpoint_SetGetNeededBytesFn(ep, _getBytesNeededForMessage);
GWEN_MsgIoEndpoint_SetSendMsgStartFn(ep, _startMsg);
GWEN_MsgIoEndpoint_SetSendMsgFinishFn(ep, _endMsg);
return ep;
}
@@ -97,48 +97,48 @@ GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint2_new(const char *devicePath, int groupId)
void _freeData(void *bp, void *p)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
xep=(AQH_MSG_ENDPOINT2_TTY*) p;
xep=(AQH_MSG_ENDPOINT_TTY*) p;
free(xep->deviceName);
GWEN_FREE_OBJECT(xep);
}
void _addSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet)
void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet)
{
if (ep) {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
time_t now;
now=time(NULL);
if ((now-GWEN_MsgEndpoint2_GetTimeOfLastStateChange(ep))>=GWEN_ENDPOINT2_TTY_RECONNECT_TIME) {
if ((now-GWEN_MsgEndpoint_GetTimeOfLastStateChange(ep))>=GWEN_ENDPOINT_TTY_RECONNECT_TIME) {
int rv;
/* (re)connect, set state */
DBG_INFO(AQH_LOGDOMAIN, "Starting to (re-)connect");
rv=GWEN_TtyEndpoint2_Connect(ep);
rv=AQH_TtyEndpoint_Connect(ep);
if (rv<0) {
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
}
}
}
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
GWEN_SocketSet_AddSocket(readSet, GWEN_MsgEndpoint2_GetSocket(ep));
if (GWEN_MsgEndpoint2_HaveMessageToSend(ep))
GWEN_SocketSet_AddSocket(writeSet, GWEN_MsgEndpoint2_GetSocket(ep));
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
GWEN_SocketSet_AddSocket(readSet, GWEN_MsgEndpoint_GetSocket(ep));
if (GWEN_MsgEndpoint_HaveMessageToSend(ep))
GWEN_SocketSet_AddSocket(writeSet, GWEN_MsgEndpoint_GetSocket(ep));
}
} /* if (ep) */
}
int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep)
int AQH_TtyEndpoint_Connect(GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
int fd;
DBG_INFO(AQH_LOGDOMAIN, "Connecting TTY device");
@@ -151,15 +151,15 @@ int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep)
GWEN_SOCKET *sk;
sk=GWEN_Socket_fromFile(fd);
GWEN_MsgEndpoint2_SetSocket(ep, sk);
GWEN_MsgEndpoint2_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
GWEN_MsgEndpoint2_DiscardInput(ep);
GWEN_MsgEndpoint_SetSocket(ep, sk);
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
GWEN_MsgEndpoint_DiscardInput(ep);
_attnHigh(ep);
return 0;
}
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Endpoint %s: Not unconnected", GWEN_MsgEndpoint2_GetName(ep));
DBG_ERROR(AQH_LOGDOMAIN, "Endpoint %s: Not unconnected", GWEN_MsgEndpoint_GetName(ep));
return GWEN_ERROR_INVALID;
}
}
@@ -168,12 +168,12 @@ int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep)
int _getSocketFd(GWEN_MSG_ENDPOINT2 *ep)
int _getSocketFd(GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
GWEN_SOCKET *sk;
sk=GWEN_MsgEndpoint2_GetSocket(ep);
sk=GWEN_MsgEndpoint_GetSocket(ep);
if (sk) {
return GWEN_Socket_GetSocketInt(sk);
}
@@ -183,14 +183,14 @@ int _getSocketFd(GWEN_MSG_ENDPOINT2 *ep)
int _openDevice(GWEN_MSG_ENDPOINT2 *ep)
int _openDevice(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
int fd;
struct termios options;
int rv;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
DBG_INFO(AQH_LOGDOMAIN, "Opening device %s", xep->deviceName);
fd=open(xep->deviceName, O_NOCTTY | O_NDELAY | O_RDWR);
@@ -214,12 +214,12 @@ int _openDevice(GWEN_MSG_ENDPOINT2 *ep)
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_ENDPOINT2_TTY_BAUDRATE);
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_ENDPOINT2_TTY_BAUDRATE);
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;
@@ -242,12 +242,12 @@ int _openDevice(GWEN_MSG_ENDPOINT2 *ep)
int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
int _startMsg(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG *msg)
{
if (ep) {
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
if (xep->intendedAttnState==1) {
int rv;
@@ -259,7 +259,7 @@ int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
}
if (rv>0) {
DBG_INFO(AQH_LOGDOMAIN, "Line busy");
usleep(AQH_MSG_ENDPOINT2_TTY_BYTE_MICROSECS);
usleep(AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS);
return GWEN_ERROR_TIMEOUT;
}
@@ -268,7 +268,7 @@ int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
usleep(AQH_MSG_ENDPOINT2_TTY_BYTE_MICROSECS/5);
usleep(AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS/5);
}
}
return 0;
@@ -276,7 +276,7 @@ int _startMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
void _endMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
void _endMsg(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG *msg)
{
/* TODO: flush before releasing ATTN */
_attnHigh(ep);
@@ -284,7 +284,7 @@ void _endMsg(GWEN_MSG_ENDPOINT2 *ep, GWEN_UNUSED GWEN_MSG *msg)
int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg)
int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg)
{
uint32_t bytesInMsg;
@@ -309,14 +309,14 @@ int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg)
int _attnLow(GWEN_MSG_ENDPOINT2 *ep)
int _attnLow(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=_getSocketFd(ep);
if (fd<0) {
@@ -340,14 +340,14 @@ int _attnLow(GWEN_MSG_ENDPOINT2 *ep)
int _attnHigh(GWEN_MSG_ENDPOINT2 *ep)
int _attnHigh(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=_getSocketFd(ep);
if (fd<0) {
@@ -373,14 +373,14 @@ int _attnHigh(GWEN_MSG_ENDPOINT2 *ep)
int _isAttnLow(GWEN_MSG_ENDPOINT2 *ep)
int _isAttnLow(GWEN_MSG_ENDPOINT *ep)
{
AQH_MSG_ENDPOINT2_TTY *xep;
AQH_MSG_ENDPOINT_TTY *xep;
int status;
int rv;
int fd;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
assert(xep);
fd=_getSocketFd(ep);
if (fd<0) {

View File

@@ -6,21 +6,21 @@
* should have received along with this file.
****************************************************************************/
#ifndef AQH_MSGENDPOINT2_TTY_H
#define AQH_MSGENDPOINT2_TTY_H
#ifndef AQH_MSGENDPOINT_TTY_H
#define AQH_MSGENDPOINT_TTY_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint2.h>
#include <gwenhywfar/endpoint.h>
#define AQH_MSG_ENDPOINT2_TTY_NAME "tty"
#define AQH_MSG_ENDPOINT_TTY_NAME "tty"
AQHOME_API GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint2_new(const char *devicePath, int groupId);
AQHOME_API GWEN_MSG_ENDPOINT *AQH_TtyEndpoint_new(const char *devicePath, int groupId);
AQHOME_API int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep);
AQHOME_API int AQH_TtyEndpoint_Connect(GWEN_MSG_ENDPOINT *ep);
#endif

View File

@@ -6,22 +6,22 @@
* should have received along with this file.
****************************************************************************/
#ifndef AQH_MSGENDPOINT2_TTY_P_H
#define AQH_MSGENDPOINT2_TTY_P_H
#ifndef AQH_MSGENDPOINT_TTY_P_H
#define AQH_MSGENDPOINT_TTY_P_H
#include <aqhome/api.h>
#include "aqhome/msg/endpoint2_tty.h"
#include "aqhome/msg/endpoint_tty.h"
#include <termios.h>
typedef struct AQH_MSG_ENDPOINT2_TTY AQH_MSG_ENDPOINT2_TTY;
struct AQH_MSG_ENDPOINT2_TTY {
typedef struct AQH_MSG_ENDPOINT_TTY AQH_MSG_ENDPOINT_TTY;
struct AQH_MSG_ENDPOINT_TTY {
char *deviceName;
struct termios previousOptions;
int intendedAttnState;