void perf_reset_all(void) { perf_counter_t handle = (perf_counter_t)sq_peek(&perf_counters); while (handle != NULL) { perf_reset(handle); handle = (perf_counter_t)sq_next(&handle->link); } for (int i = 0; i <= latency_bucket_count; i++) { latency_counters[i] = 0; } }
int hott_telemetry_thread_main(int argc, char *argv[]) { warnx("starting"); connect_count = perf_alloc(PC_COUNT, "reconnects "); recon_port = perf_alloc(PC_COUNT, "reopen port "); reqs_count = perf_alloc(PC_COUNT, "requests "); bin_reply = perf_alloc(PC_COUNT, "bin replies "); txt_reply = perf_alloc(PC_COUNT, "text replies "); bad_reply = perf_alloc(PC_COUNT, "unknown replies "); dead_reply = perf_alloc(PC_COUNT, "dead replies "); thread_running = true; const char *device = DEFAULT_UART; /* read commandline arguments */ for (int i = 0; i < argc && argv[i]; i++) { if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) { //device set if (argc > i + 1) { device = argv[i + 1]; } else { thread_running = false; errx(1, "missing parameter to -d\n%s", commandline_usage); } } } /* enable UART, writes potentially an empty buffer, but multiplexing is disabled */ int uart = open_uart(device); if (uart < 0) { errx(1, "Failed opening HoTT UART, exiting."); thread_running = false; } init_sub_messages(); uint8_t buffer[MAX_MESSAGE_BUFFER_SIZE]; size_t size = 0; uint8_t id = 0; bool connected = true; int recon = 0; while (!thread_should_exit) { // Listen for and serve poll from the receiver. if (recv_req_id(uart, &id) == OK) { if (!connected) { connected = true; warnx("OK"); } switch (id) { case EAM_SENSOR_ID: build_eam_response(buffer, &size); perf_count(bin_reply); break; case GAM_SENSOR_ID: build_gam_response(buffer, &size); perf_count(bin_reply); break; case GPS_SENSOR_ID: build_gps_response(buffer, &size); perf_count(bin_reply); break; case BINARY_MODE_REQUEST_ID: perf_count(dead_reply); break; default: perf_count(bad_reply); continue; // Not a module we support. } send_data(uart, buffer, size); } else { if (connected) { connected = false; } else { recon++; } if (recon > 100) { perf_count(recon_port); close(uart); uart = open_uart(device); perf_reset(reqs_count); perf_reset(bin_reply); perf_reset(txt_reply); perf_reset(dead_reply); perf_reset(bad_reply); } } } warnx("exiting"); close(uart); thread_running = false; perf_free(connect_count); perf_free(recon_port); perf_free(reqs_count); perf_free(bin_reply); perf_free(txt_reply); perf_free(bad_reply); perf_free(dead_reply); return 0; }