This commit is contained in:
2026-08-10 10:45:53 +03:00
parent 71b0c9f5af
commit e7b345b377
8 changed files with 43 additions and 37 deletions

2
BTA_dome_modbus/build Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
su -c "make debug; chmod a+s dome_client"

View File

@@ -274,48 +274,43 @@ static int process_system(SSL *ssl){
return TRUE; return TRUE;
} }
// check time sync // check time sync
static int brokenshm = FALSE; static int brokenshmctr = 0;
if(M_time - last_mtime + G.T_sync_lost > curtime - t0 || !check_shm_block(&sdat)){ // broken SHM if(M_time - last_mtime > curtime - t0 + G.T_sync_lost || !check_shm_block(&sdat)){ // broken SHM
if(!brokenshm){ if(brokenshmctr == 0){
LOGERR("Stalled or broken SHM block"); LOGERR("Stalled or broken SHM block");
brokenshm = TRUE;
} }
WARNX("Stalled or broken SHM block; %g -- %g", M_time - last_mtime + G.T_sync_lost, curtime - t0);
if(++brokenshmctr < 10) return TRUE;
return FALSE; return FALSE;
}else brokenshm = FALSE; }else brokenshmctr = 0;
static int modelused = FALSE; static int modelused = FALSE;
if(UseModel == FullModel){ // model if(!G.emulmode){
if(!modelused){ if(UseModel == FullModel){ // model
LOGWARN("Server is in model mode"); if(!modelused){
modelused = TRUE; LOGWARN("Server is in model mode");
stop_all(ssl); modelused = TRUE;
} stop_all(ssl);
return TRUE; }
}else modelused = FALSE; return TRUE;
static int serverisdead = FALSE; }else modelused = FALSE;
if(ServPID <= 0 || kill(ServPID, 0) < 0){ // dead server static int serverisdead = FALSE;
if(!serverisdead){ if(ServPID <= 0 || kill(ServPID, 0) < 0){ // dead server
LOGERR("Main server is dead"); WARNX("Main server is dead");
serverisdead = TRUE; if(!serverisdead){
} LOGERR("Main server is dead");
return FALSE; serverisdead = TRUE;
}else serverisdead = FALSE; return TRUE;
}
return FALSE;
}else serverisdead = FALSE;
}
if(check_motor(ssl, curMotNo)){ if(check_motor(ssl, curMotNo)){
// TODO: check state for errors // TODO: check state for errors
if(++curMotNo >= MOTORS_AMOUNT) curMotNo = 0; if(++curMotNo >= MOTORS_AMOUNT) curMotNo = 0;
} }
if(!D_Locked && Dome_State != D_Off) chk_dome_speed(ssl); if(!D_Locked && Dome_State != D_Off) chk_dome_speed(ssl);
#if 0
if(curtime - t0 > 3.){
sprintf(buf, "help\n");
SSL_write(ssl, buf, strlen(buf));
/*DBG("OLD: %g", val_Hmd);
val_Hmd = 55. + drand48() * 15.;
DBG("New: %g", val_Hmd);*/
t0 = curtime;
}
#endif
; ;
return FALSE; return TRUE;
} }
/* /*
@@ -358,18 +353,23 @@ void clientproc(SSL_CTX *ctx, int fd){
} }
while(isrunning){ while(isrunning){
if(!process_system(ssl)){ if(!process_system(ssl)){
LOGERR("Motors error");
WARNX("ERROR!");
stop_all(ssl); stop_all(ssl);
sleep(5); sleep(5);
break; break;
} }
// clear receiving buffer (TODO: parse it?)
bytes = SSL_nbread(ssl, buf, sizeof(buf)); bytes = SSL_nbread(ssl, buf, sizeof(buf));
if(bytes > 0){ if(bytes > 0){
buf[bytes] = 0; buf[bytes] = 0;
printf("Received: \"%s\"\n", buf); fprintf(stderr, "Received: \"%s\"\n", buf);
}else if(bytes < 0){ }else if(bytes < 0){
LOGWARN("Server disconnected or other error"); LOGWARN("Server disconnected or other error");
ERRX("Disconnected"); ERRX("Disconnected");
} }
usleep(100000);
} }
DBG("Exit; isrunning=%d", isrunning);
SSL_free(ssl); SSL_free(ssl);
} }

View File

@@ -71,6 +71,7 @@ static sl_option_t cmdlnopts[] = {
{"mottmout",NEED_ARG, NULL, 'M', arg_double, APTR(&G.speedchk_interval), _("interval of motor's speed checking, s (default: 10)")}, {"mottmout",NEED_ARG, NULL, 'M', arg_double, APTR(&G.speedchk_interval), _("interval of motor's speed checking, s (default: 10)")},
{"server", NEED_ARG, NULL, 's', arg_string, APTR(&G.serverhost), _("server node, IP:port")}, {"server", NEED_ARG, NULL, 's', arg_string, APTR(&G.serverhost), _("server node, IP:port")},
{"lostsync",NEED_ARG, NULL, 'L', arg_double, APTR(&G.T_sync_lost),_("\"lost synchronization\" timeout, s (default: 5)")}, {"lostsync",NEED_ARG, NULL, 'L', arg_double, APTR(&G.T_sync_lost),_("\"lost synchronization\" timeout, s (default: 5)")},
{"emulation",NO_ARGS, NULL, 'e', arg_int, APTR(&G.emulmode), _("run even in emulation mode")},
#endif #endif
end_option end_option
}; };

View File

@@ -34,6 +34,7 @@
* here are some typedef's for global data * here are some typedef's for global data
*/ */
typedef struct{ typedef struct{
int emulmode; // emulation mode: don't check server & run in model mode
double acc_timeout; // network timeout, s double acc_timeout; // network timeout, s
double T_sync_lost; // "lost synchronization" timeout, s double T_sync_lost; // "lost synchronization" timeout, s
double speedchk_interval;// interval of motors' speed checking (resend command if don't reach yet) double speedchk_interval;// interval of motors' speed checking (resend command if don't reach yet)

View File

@@ -24,5 +24,6 @@
int main(int argc, char **argv){ int main(int argc, char **argv){
sl_init(); sl_init();
parse_args(argc, argv); parse_args(argc, argv);
DBG("START");
return start_daemon(); return start_daemon();
} }

View File

@@ -36,7 +36,7 @@ current=xx - (sg)
// set points // set points
static double currentSet = 0., speedSet = 0.; static double currentSet = 0., speedSet = 0.;
// current motor for status etc. getters // current motor for status etc. getters (0..MOTORS_AMOUNT-1)
static int motindex = 0; static int motindex = 0;
// stop all // stop all
@@ -76,7 +76,8 @@ int motors_set_speedsetpoint(double val){
int motors_get_activenum(){ return motindex; } int motors_get_activenum(){ return motindex; }
// set number of active motor // set number of active motor
int motors_set_activenum(int N){ int motors_set_activenum(int N){
if(N < 1 || N > MOTORS_AMOUNT) return FALSE; DBG("Set active motor=%d", N);
if(N < 0 || N >= MOTORS_AMOUNT) return FALSE;
motindex = N; motindex = N;
return TRUE; return TRUE;
} }

View File

@@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
rm client.log 2>/dev/null rm client.log 2>/dev/null
./dome_client -a ca/ca/ca_cert.pem -c ca/client/client_cert.pem -k ca/client/private/client_key.pem -vvv -s localhost -l client.log ./dome_client -a ca/ca/ca_cert.pem -c ca/client/client_cert.pem -k ca/client/private/client_key.pem -vvv -s localhost -l client.log $@

View File

@@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
rm server.log 2>/dev/null rm server.log 2>/dev/null
./dome_server -a ca/ca/ca_cert.pem -c ca/server/server_cert.pem -k ca/server/private/server_key.pem -vvvl server.log ./dome_server -a ca/ca/ca_cert.pem -c ca/server/server_cert.pem -k ca/server/private/server_key.pem -vvvl server.log $@