shit happens

This commit is contained in:
2025-02-25 23:32:51 +03:00
parent f83f95c9cc
commit 5b89a968eb
17 changed files with 214 additions and 102 deletions

View File

@@ -48,8 +48,8 @@ static struct timeval encRtmout = {0}, mntRtmout = {0};
// encoders raw data
typedef struct __attribute__((packed)){
uint8_t magick;
int32_t encX;
int32_t encY;
int32_t encX;
uint8_t CRC[4];
} enc_t;
@@ -82,6 +82,13 @@ static void gttime(){
*/
static void parse_encbuf(uint8_t databuf[ENC_DATALEN], struct timeval *tv){
enc_t *edata = (enc_t*) databuf;
/*
#ifdef EBUG
DBG("ENCBUF:");
for(int i = 0; i < ENC_DATALEN; ++i) printf("%02X ", databuf[i]);
printf("\n");
#endif
*/
if(edata->magick != ENC_MAGICK){
DBG("No magick");
return;
@@ -112,7 +119,7 @@ static void parse_encbuf(uint8_t databuf[ENC_DATALEN], struct timeval *tv){
mountdata.encposition.Y = Y_ENC2RAD(edata->encY);
mountdata.encposition.msrtime = *tv;
pthread_mutex_unlock(&datamutex);
DBG("time = %zd+%zd/1e6, X=%g deg, Y=%g deg", tv->tv_sec, tv->tv_usec, mountdata.encposition.X*180./M_PI, mountdata.encposition.Y*180./M_PI);
//DBG("time = %zd+%zd/1e6, X=%g deg, Y=%g deg", tv->tv_sec, tv->tv_usec, mountdata.encposition.X*180./M_PI, mountdata.encposition.Y*180./M_PI);
}
// try to read 1 byte from encoder; return -1 if nothing to read or -2 if device seems to be disconnected
@@ -181,10 +188,10 @@ static void *encoderthread(void _U_ *u){
if(b == -2) ++errctr;
if(b < 0) continue;
errctr = 0;
DBG("Got byte from Encoder: 0x%02X", b);
// DBG("Got byte from Encoder: 0x%02X", b);
if(wridx == 0){
if((uint8_t)b == ENC_MAGICK){
DBG("Got magic -> start filling packet");
// DBG("Got magic -> start filling packet");
databuf[wridx++] = (uint8_t) b;
gettimeofday(&tv, NULL);
}
@@ -239,7 +246,11 @@ static void *mountthread(void _U_ *u){
struct timeval tgot;
if(0 != gettimeofday(&tgot, NULL)) continue;
if(!MountWriteRead(cmd_getstat, &d) || d.len != sizeof(SSstat)){
#ifdef EBUG
DBG("Can't read SSstat, need %zd got %zd bytes", sizeof(SSstat), d.len);
for(size_t i = 0; i < d.len; ++i) printf("%02X ", d.buf[i]);
printf("\n");
#endif
++errctr; continue;
}
if(SScalcChecksum(buf, sizeof(SSstat)-2) != status->checksum){