thread showstats so it does not go crazy

This commit is contained in:
Paul Dino Jones 2025-12-12 15:26:50 -05:00
parent 03f807ac34
commit 82a246a4b1
1 changed files with 23 additions and 1 deletions

View File

@ -26,6 +26,7 @@ struct sigaction act;
uv_idle_t idler; uv_idle_t idler;
uv_timer_t datachecktimer; uv_timer_t datachecktimer;
uv_timer_t showstatstimer;
uv_timer_t datamaptimer; uv_timer_t datamaptimer;
uv_udp_t recv_socket; uv_udp_t recv_socket;
@ -33,6 +34,7 @@ bool doui = false;
int appstate = 0; int appstate = 0;
void shmdatamapcallback(uv_timer_t* handle); void shmdatamapcallback(uv_timer_t* handle);
void showstatscallback(uv_timer_t* handle);
void datacheckcallback(uv_timer_t* handle); void datacheckcallback(uv_timer_t* handle);
void startdatalogger(MonocoqueSettings* ms, loop_data* l); void startdatalogger(MonocoqueSettings* ms, loop_data* l);
@ -281,11 +283,12 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
} }
uv_timer_start(&showstatstimer, showstatscallback, 0, 100);
doui = false; doui = false;
} }
else else
{ {
showstats(simdata); //showstats(simdata);
//SimDevice* devices = f->simdevices; //SimDevice* devices = f->simdevices;
//int numdevices = f->numdevices; //int numdevices = f->numdevices;
//for (int x = 0; x < numdevices; x++) //for (int x = 0; x < numdevices; x++)
@ -298,6 +301,17 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
} }
} }
void showstatscallback(uv_timer_t* handle)
{
void* b = uv_handle_get_data((uv_handle_t*) handle);
loop_data* f = (loop_data*) b;
SimData* simdata = f->simdata;
if(appstate == 2)
{
showstats(simdata);
}
}
void shmdatamapcallback(uv_timer_t* handle) void shmdatamapcallback(uv_timer_t* handle)
{ {
void* b = uv_handle_get_data((uv_handle_t*) handle); void* b = uv_handle_get_data((uv_handle_t*) handle);
@ -318,6 +332,7 @@ void shmdatamapcallback(uv_timer_t* handle)
{ {
f->releasing = true; f->releasing = true;
uv_timer_stop(handle); uv_timer_stop(handle);
uv_timer_stop(&showstatstimer);
slogi("releasing devices, please wait"); slogi("releasing devices, please wait");
f->uion = false; f->uion = false;
SimDevice* devices = f->simdevices; SimDevice* devices = f->simdevices;
@ -390,6 +405,10 @@ static void on_udp_recv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* rcvbuf,
if (nread > 0) { if (nread > 0) {
slogt("udp data received"); slogt("udp data received");
} }
if (nread <= 0) {
free(rcvbuf->base);
return;
}
char* a; char* a;
a = rcvbuf->base; a = rcvbuf->base;
@ -412,6 +431,7 @@ static void on_udp_recv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* rcvbuf,
{ {
f->releasing = true; f->releasing = true;
uv_udp_recv_stop(handle); uv_udp_recv_stop(handle);
uv_timer_stop(&showstatstimer);
slogi("releasing devices, please wait"); slogi("releasing devices, please wait");
f->uion = false; f->uion = false;
SimDevice* devices = f->simdevices; SimDevice* devices = f->simdevices;
@ -611,11 +631,13 @@ int monocoque_mainloop(MonocoqueSettings* ms)
baton->req.data = (void*) baton; baton->req.data = (void*) baton;
uv_handle_set_data((uv_handle_t*) &datachecktimer, (void*) baton); uv_handle_set_data((uv_handle_t*) &datachecktimer, (void*) baton);
uv_handle_set_data((uv_handle_t*) &datamaptimer, (void*) baton); uv_handle_set_data((uv_handle_t*) &datamaptimer, (void*) baton);
uv_handle_set_data((uv_handle_t*) &showstatstimer, (void*) baton);
uv_handle_set_data((uv_handle_t*) &recv_socket, (void*) baton); uv_handle_set_data((uv_handle_t*) &recv_socket, (void*) baton);
uv_handle_set_data((uv_handle_t*) poll, (void*) baton); uv_handle_set_data((uv_handle_t*) poll, (void*) baton);
appstate = 1; appstate = 1;
slogd("setting initial app state"); slogd("setting initial app state");
uv_timer_init(uv_default_loop(), &datachecktimer); uv_timer_init(uv_default_loop(), &datachecktimer);
uv_timer_init(uv_default_loop(), &showstatstimer);
fprintf(stdout, "Searching for sim data... Press q to quit...\n"); fprintf(stdout, "Searching for sim data... Press q to quit...\n");
uv_timer_start(&datachecktimer, datacheckcallback, 1000, 1000); uv_timer_start(&datachecktimer, datacheckcallback, 1000, 1000);