aqhome: implemented IPC client, fixed some bugs.
sending a PING request and retrieving the PONG response works now.
This commit is contained in:
@@ -27,8 +27,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define AQH_MSG_ENDPOINT_TTY_NAME "tty"
|
||||
|
||||
#define AQH_MSG_ENDPOINT_TTY_BAUDRATE B19200
|
||||
#define AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS 520
|
||||
|
||||
@@ -73,6 +71,8 @@ GWEN_MSG_ENDPOINT *AQH_TtyNodeEndpoint_new(const char *devicePath, int groupId)
|
||||
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);
|
||||
@@ -113,6 +113,7 @@ int _connect(GWEN_MSG_ENDPOINT *ep)
|
||||
return fd;
|
||||
}
|
||||
GWEN_MsgEndpoint_SetFd(ep, fd);
|
||||
GWEN_ConnectableMsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_CONN_STATE_CONNECTED);
|
||||
_attnHigh(ep);
|
||||
}
|
||||
return 0;
|
||||
@@ -137,11 +138,11 @@ int _handleReadable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *em
|
||||
if (rv<0) {
|
||||
if (errno==EAGAIN || errno==EWOULDBLOCK)
|
||||
return GWEN_ERROR_TRY_AGAIN;
|
||||
DBG_ERROR(GWEN_LOGDOMAIN, "Error on read(): %s (%d)", strerror(errno), errno);
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "Error on read(): %s (%d)", strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
else if (rv==0) {
|
||||
DBG_ERROR(GWEN_LOGDOMAIN, "EOF met on read()");
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "EOF met on read()");
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
len=rv;
|
||||
@@ -157,7 +158,7 @@ int _handleReadable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *em
|
||||
}
|
||||
rv=GWEN_Msg_AddByte(msg, buffer[i]);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
rv=AQH_NodeMsg_IsMsgComplete(msg);
|
||||
@@ -167,7 +168,7 @@ int _handleReadable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *em
|
||||
GWEN_MsgEndpoint_SetCurrentlyReceivedMsg(ep, NULL);
|
||||
rv=GWEN_MsgEndpoint_DiscardInput(ep);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -179,7 +180,7 @@ int _handleReadable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *em
|
||||
GWEN_MsgEndpoint_SetCurrentlyReceivedMsg(ep, NULL);
|
||||
rv=GWEN_MsgEndpoint_DiscardInput(ep);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -200,7 +201,7 @@ int _handleWritable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *em
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
|
||||
DBG_DEBUG(GWEN_LOGDOMAIN, "Writing to endpoint %s", GWEN_MsgEndpoint_GetName(ep));
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Writing to endpoint %s", GWEN_MsgEndpoint_GetName(ep));
|
||||
msg=GWEN_MsgEndpoint_GetFirstSendMessage(ep);
|
||||
if (msg) {
|
||||
uint8_t pos;
|
||||
@@ -217,13 +218,13 @@ int _handleWritable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *em
|
||||
/* start new message */
|
||||
rv=_isLineBusy(ep);
|
||||
if (rv<0 || rv==1) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Line busy, not sending");
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Line busy, not sending");
|
||||
usleep(100);
|
||||
return 0;
|
||||
}
|
||||
rv=_startMsg(ep);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -237,7 +238,7 @@ int _handleWritable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *em
|
||||
if (rv<0) {
|
||||
if (errno==EAGAIN || errno==EWOULDBLOCK)
|
||||
return GWEN_ERROR_TRY_AGAIN;
|
||||
DBG_ERROR(GWEN_LOGDOMAIN, "Error on write(): %s (%d)", strerror(errno), errno);
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "Error on write(): %s (%d)", strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
GWEN_Msg_IncCurrentPos(msg, rv);
|
||||
@@ -247,11 +248,14 @@ int _handleWritable(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG_ENDPOINT_MGR *em
|
||||
GWEN_Msg_List_Del(msg);
|
||||
GWEN_Msg_free(msg);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "No remaining bytes in msg");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user