serial: Set ATTN line high on start. Added checks.

This commit is contained in:
Martin Preuss
2023-01-26 18:58:32 +01:00
parent e9541761fd
commit 53716b37d5

View File

@@ -15,6 +15,7 @@
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#include <string.h>
@@ -116,6 +117,9 @@ int AQH_Serial_Open(AQH_SERIAL *sr)
}
sr->fd=fd;
_attnHigh(sr);
return 0;
}
@@ -380,6 +384,7 @@ int _check(const uint8_t *ptr, uint8_t len)
}
if (x) {
DBG_ERROR(NULL, "Bad checksum");
GWEN_Text_DumpString(ptr, len, 2);
return GWEN_ERROR_GENERIC;
}
@@ -438,7 +443,14 @@ int _readFromFd(AQH_SERIAL *sr)
}
else {
if (sr->bytesToRead==0) {
/* msg received, handle */
/* msg received, check */
if (_check(sr->readBuffer, sr->readPos)<0) {
DBG_INFO(0, "here (%d)", rv);
sr->readPos=0;
sr->bytesToRead=2;
return 0;
}
/* valid msg received, handle */
AQH_Serial_PacketReceived(sr, sr->readBuffer, sr->readPos);
sr->readPos=0;
sr->bytesToRead=2;
@@ -502,7 +514,7 @@ int AQH_Serial_StartWriting(AQH_SERIAL *sr, const uint8_t *ptr, uint8_t len)
return rv;
}
usleep(10);
usleep(50);
return 0;
}
@@ -516,7 +528,7 @@ int AQH_Serial_Loop(AQH_SERIAL *sr)
struct timeval tv;
int rv;
tv.tv_sec=5;
tv.tv_sec=2;
tv.tv_usec=0;
if (sr->bytesToWrite) {
@@ -528,6 +540,10 @@ int AQH_Serial_Loop(AQH_SERIAL *sr)
rv=select(sr->fd+1, &readSet, (sr->bytesToWrite)?(&writeSet):NULL, NULL, &tv);
if (rv<0) {
if (errno!=EINTR) {
DBG_ERROR(NULL, "Error on select");
return GWEN_ERROR_IO;
}
}
else if (rv) {
if (FD_ISSET(sr->fd, &readSet)) {
@@ -545,6 +561,11 @@ int AQH_Serial_Loop(AQH_SERIAL *sr)
}
}
}
else if (rv==0) {
/* timeout */
sr->readPos=0;
sr->bytesToRead=2;
}
return 0;
}