aqhome: More work on endpoint system. Basically works.
This commit is contained in:
@@ -38,7 +38,7 @@ static int _startMsg(AQH_MSG_ENDPOINT *ep);
|
||||
static int _endMsg(AQH_MSG_ENDPOINT *ep);
|
||||
static int _checkMsg(AQH_MSG_ENDPOINT *ep);
|
||||
|
||||
static int _setupDevice(AQH_MSG_ENDPOINT *ep);
|
||||
static int _openDevice(AQH_MSG_ENDPOINT *ep);
|
||||
static int _attnLow(AQH_MSG_ENDPOINT *ep);
|
||||
static int _attnHigh(AQH_MSG_ENDPOINT *ep);
|
||||
static int _isAttnLow(AQH_MSG_ENDPOINT *ep);
|
||||
@@ -53,32 +53,27 @@ AQH_MSG_ENDPOINT *AQH_MsgEndpointTty_new(const char *deviceName)
|
||||
AQH_MSG_ENDPOINT *ep;
|
||||
AQH_MSG_ENDPOINT_TTY *xep;
|
||||
int fd;
|
||||
int rv;
|
||||
|
||||
fd=open(deviceName, O_NOCTTY | O_NDELAY | O_RDWR);
|
||||
if (fd<0) {
|
||||
DBG_ERROR(NULL, "Error on open(%s): %s (%d)", deviceName, strerror(errno), errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ep=AQH_MsgEndpoint_new(fd, AQH_MSG_ENDPOINT_ENDPOINTGROUP_BUS);
|
||||
ep=AQH_MsgEndpoint_new(-1, AQH_MSG_ENDPOINT_ENDPOINTGROUP_BUS, "TTY");
|
||||
AQH_MsgEndpoint_SetAcceptedEndpointGroups(ep, AQH_MSG_ENDPOINT_ENDPOINTGROUP_NET);
|
||||
AQH_MsgEndpoint_SetAcceptedMsgGroups(ep, AQH_MSG_ENDPOINT_MSGGROUP_ALL);
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_TTY, xep);
|
||||
GWEN_INHERIT_SETDATA(AQH_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep, xep, _freeData);
|
||||
xep->deviceName=strdup(deviceName);
|
||||
_attnHigh(ep);
|
||||
|
||||
AQH_MsgEndpoint_SetStartMsgFn(ep, _startMsg);
|
||||
AQH_MsgEndpoint_SetEndMsgFn(ep, _endMsg);
|
||||
AQH_MsgEndpoint_SetCheckMsgFn(ep, _checkMsg);
|
||||
|
||||
rv=_setupDevice(ep);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
fd=_openDevice(ep);
|
||||
if (fd<0) {
|
||||
DBG_INFO(NULL, "here (%d)", fd);
|
||||
AQH_MsgEndpoint_free(ep);
|
||||
return NULL;
|
||||
}
|
||||
AQH_MsgEndpoint_SetFd(ep, fd);
|
||||
_attnHigh(ep);
|
||||
|
||||
return ep;
|
||||
}
|
||||
@@ -112,7 +107,7 @@ int _startMsg(AQH_MSG_ENDPOINT *ep)
|
||||
|
||||
rv=_attnLow(ep);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "here (%d)", rv);
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
usleep(AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS/5);
|
||||
@@ -137,7 +132,7 @@ int _checkMsg(AQH_MSG_ENDPOINT *ep)
|
||||
|
||||
|
||||
|
||||
int _setupDevice(AQH_MSG_ENDPOINT *ep)
|
||||
int _openDevice(AQH_MSG_ENDPOINT *ep)
|
||||
{
|
||||
AQH_MSG_ENDPOINT_TTY *xep;
|
||||
int fd;
|
||||
@@ -148,10 +143,14 @@ int _setupDevice(AQH_MSG_ENDPOINT *ep)
|
||||
int m;
|
||||
|
||||
xep=GWEN_INHERIT_GETDATA(AQH_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep);
|
||||
fd=AQH_MsgEndpoint_GetFd(ep);
|
||||
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(NULL, "Error on tcgetattr(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
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 */
|
||||
@@ -166,30 +165,28 @@ int _setupDevice(AQH_MSG_ENDPOINT *ep)
|
||||
|
||||
rv=cfsetispeed(&options, AQH_MSG_ENDPOINT_TTY_BAUDRATE);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error on cfsetispeed(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
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(NULL, "Error on cfsetospeed(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
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(NULL, "Error on tcflush(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
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(NULL, "Error on tcsetattr(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcsetattr(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
_attnHigh(ep);
|
||||
|
||||
return 0;
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
@@ -205,13 +202,13 @@ int _attnLow(AQH_MSG_ENDPOINT *ep)
|
||||
fd=AQH_MsgEndpoint_GetFd(ep);
|
||||
rv=ioctl(fd, TIOCMGET, &status); /* GET the State of MODEM bits in Status */
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
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(NULL, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
xep->intendedAttnState=0;
|
||||
@@ -231,14 +228,14 @@ int _attnHigh(AQH_MSG_ENDPOINT *ep)
|
||||
fd=AQH_MsgEndpoint_GetFd(ep);
|
||||
rv=ioctl(fd, TIOCMGET, &status);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
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(NULL, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
|
||||
@@ -259,7 +256,7 @@ int _isAttnLow(AQH_MSG_ENDPOINT *ep)
|
||||
fd=AQH_MsgEndpoint_GetFd(ep);
|
||||
rv=ioctl(fd, TIOCMGET, &status);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user