FILE *reinit_timer(FILE *port, char *name, int config, int lanes_expected) { FILE *fd; char tmp[LINE_LEN]; int lanes; printf("Wow, something's messed with your timer. Let's try again.\n"); close_timer(port); printf("Please power cycle your timer.\n"); printf("If you have a USB timer, just unplug it, wait a few seconds, and reconnect\n"); printf("it to the SAME port.\n"); printf("\nWhen you're done, press Enter and we'll try to get reconnected.\n"); retry: fgets(tmp, LINE_LEN, stdin); printf("Opening port.\n"); fd = open_timer(name, config); if (!fd) { printf("Eek! Unable to open timer port! Please power cycle it again.\n"); printf("Double-check that you plugged your USB timer into the same port!\n"); printf("Press Enter to try again. (Ctrl-C to give up - you will lose all results.)\n"); goto retry; } /* reset timer */ lanes = init_timer(fd); if (lanes != lanes_expected) { close_timer(fd); printf("Eek! Invalid number of lanes! (Expected %d, got %d from timer.\n", lanes_expected, lanes); printf("Please power cycle your timer again and check all sensor connections.\n"); printf("Press Enter to try again. (Ctrl-C to give up - you will lose all results.)\n"); goto retry; } return fd; }
void tcpudp_act_cyc(uint8_t cycact) { switch (cycact) { case 0: tcpip_flag_ = 0; close_timer(); break; case 1: tcpip_flag_ = 1; open_timer(); break; default: break; } }
int main(int argc, char **argv) { FILE *port; char *filename; int c, i, j, tmp; int debugmode = 0; int lanes; float times[MAX_LANES]; float prev_times[MAX_LANES][4]; int prev_head = 0;\ char *tmpbuf[10]; /* parse command line options */ if (argc == 1) { usage(); return 0; } opterr = 0; while ((c = getopt (argc, argv, "dp:")) != -1) { switch (c) { case 'd': printf("Debugging mode enabled\n"); debugmode = 1; break; case 'p': filename = optarg; break; case '?': default: usage(); return 1; } } /* open timer */ port = open_timer(filename, !debugmode); if (!port) { fprintf(stderr, "Eek! Unable to open timer port! Cannot continue.\n"); fprintf(stderr, "Possible problems:\n"); fprintf(stderr, "\tbad filename for port (if USB timer, check dmesg for port id\n"); fprintf(stderr, "\tno write access to device (check permissions or run as root)\n"); fprintf(stderr, "\tUSB timer not connected\n"); return 1; } /* reset timer */ lanes = init_timer(port); if (!lanes) { fprintf(stderr, "Eek! Cannot initialize timer! Cannot continue!\n"); fprintf(stderr, "Make sure your timer is supported by this program.\n"); close_timer(port); return 1; } memset(prev_times, 0, sizeof(float) * 3 * MAX_LANES); printf("Press enter to continue.\n"); fgets(tmpbuf, 10, stdin); /* main loop */ while (1) { printf("Begin racing when ready.\n"); tmp = get_times(port, lanes, times, debugmode); printf("Run is complete. Results:\n"); if (tmp > 0) { /* good race! */ display_winner(tmp); printf("\n"); // save current time, drop last time display_times(lanes, times); for (j = 0; j < lanes; j++) { prev_times[j][prev_head] = times[j]; } printf("\nPrevious results:\n"); i = prev_head - 1; if (i < 0) i = 3; while (i != prev_head) { for (j = 0; j < lanes; j++) printf("\t%1.4f", prev_times[j][i]); printf("\n"); i--; if (i < 0) i = 3; } prev_head++; if (prev_head == 4) prev_head = 0; } if (tmp == 0) { printf("Null race result! Please redo this run.\n"); } if (tmp < 0) { port = reinit_timer(port, filename, !debugmode, lanes); /* if this returns, we've succeeded */ } printf("Press enter to continue, X to exit.\n"); fgets(tmpbuf, 10, stdin); if (strchr(tmpbuf, 'x') || strchr(tmpbuf, 'X')) break; rearm_timer(port, debugmode); } /* all done */ printf("\nDone.\n"); close_timer(port); return 0; }