From daf966eaa629d59487b57f907b62f642995d829e Mon Sep 17 00:00:00 2001 From: Astrid Smith Date: Fri, 28 Oct 2011 21:44:42 -0700 Subject: Calibrator, version that works (kind of) with milliseconds --- host/calibrator_client.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 host/calibrator_client.c (limited to 'host/calibrator_client.c') diff --git a/host/calibrator_client.c b/host/calibrator_client.c new file mode 100644 index 0000000..3b5eee5 --- /dev/null +++ b/host/calibrator_client.c @@ -0,0 +1,82 @@ +/* Thinger to read 60hz cycle times and display diagnostics in a kind + * of stripcharty way. + */ + +#include +#include +#include +#include +#include + +// window for reporting, in cycles +#define REPORT_FREQ 60 +// width of the bargraph +#define WIDTH 40 +// timer cycles per second +#define SCALE 1000000 +// length between nominal timer overflows, in microseconds +// (1 overflow / 65'536 microseconds) * (1'000'000 microseconds) +#define TICKSIZE (SCALE / 65536) + +#define NANOSECOND 1000000000 +#define MILLISECOND 1000 + +#define NOMINAL 60 +#define MOTION 0.2 + +int main(int *argc, char **argv) +{ + char line[WIDTH + 10]; + char blankline[] = " | "; + double bottom = SCALE/(NOMINAL-MOTION); + double top = SCALE/(NOMINAL+MOTION); + double center = SCALE/(NOMINAL); + int counter; + int qpos = 0; + int fd = open("/dev/ttyACM0", O_RDONLY); + + long int count_total = 0; // total overflows so far ever + struct timespec initial; // initial timestamp + + signed long long int initial_nsec; + signed long int initial_msec; + + strcpy(&line, &blankline); + + clock_gettime(CLOCK_REALTIME, &initial); + + initial_nsec = initial.tv_nsec; + + initial_msec = (initial.tv_sec * 1000) + (initial.tv_nsec / (1000 * 1000)); + + while (1) { + double current, average; + char inlin[20]; + int position, pos_avg, i; + int len; + + struct timespec current_time; + signed long long int cur_nsec; + signed long int cur_msec; + + long double nominal, measured; + + len = read(fd, &inlin, 1); + if (len == 0) { + puts("Fucked\n"); + continue; + } + clock_gettime(CLOCK_REALTIME, ¤t_time); + cur_nsec = (current_time.tv_nsec) + ((current_time.tv_sec - initial.tv_sec) * 1000 * 1000 * 1000); + cur_msec = (current_time.tv_nsec / (1000 * 1000)) + ((current_time.tv_sec) * 1000); + + count_total++; + + nominal = (long double) count_total / TICKSIZE; + //measured = (cur_nsec - initial_nsec) / NANOSECOND; + measured = (cur_msec - initial_msec) / MILLISECOND; + + printf("% '05.8Lf - % '05.8Lf, % '05.8Lf\n", nominal, measured, measured/nominal); + + } +} -- cgit v1.2.3