fixed broken PID

This commit is contained in:
2026-03-18 18:10:05 +03:00
parent b0d0a323ee
commit db1058ddf8
7 changed files with 204 additions and 84 deletions

View File

@@ -382,7 +382,10 @@ static int readstrings(buf_t *buf, int fd){
// return TRUE if got, FALSE if no data found
static int getdata(buf_t *buf, long *out){
if(!buf || buf->len < 1 || buf->len > (XYBUFSZ+1)) return FALSE;
if(!buf || buf->len < 1 || buf->len > (XYBUFSZ+1)){
return FALSE;
}
DBG("got data");
// read record between last '\n' and previous (or start of string)
char *last = &buf->buf[buf->len - 1];
//DBG("buf: _%s_", buf->buf);
@@ -439,6 +442,7 @@ static void *encoderthread2(void _U_ *u){
for(int i = 0; i < 2; ++i){
if(pfds[i].revents && POLLIN){
if(!readstrings(&strbuf[i], encfd[i])){
DBG("ERR");
++errctr;
break;
}
@@ -446,7 +450,9 @@ static void *encoderthread2(void _U_ *u){
double curt = timefromstart();
if(getdata(&strbuf[i], &msrlast[i])) mtlast[i] = curt;
if(curt - t0[i] >= Conf.EncoderReqInterval){ // get last records
DBG("last rec %d, curt=%g, t0=%g, mtlast=%g", i, curt, t0[i], mtlast[i]);
if(curt - mtlast[i] < 1.5*Conf.EncoderReqInterval){
DBG("time OK");
pthread_mutex_lock(&datamutex);
double pos = (double)msrlast[i];
//DBG("pos[%d]=%g", i, pos);
@@ -626,8 +632,8 @@ static int ttyopen(const char *path, speed_t speed){
tty.c_cflag = BOTHER | CS8 | CREAD | CLOCAL; // other speed, 8bit, RW, ignore line ctrl
tty.c_ispeed = speed;
tty.c_ospeed = speed;
//tty.c_cc[VMIN] = 0; // non-canonical mode
//tty.c_cc[VTIME] = 5;
tty.c_cc[VMIN] = 0; // non-canonical mode
tty.c_cc[VTIME] = 5;
if(ioctl(fd, TCSETS2, &tty)){
DBG("Can't set TTY settings");
close(fd);