void sender_pipe(void) { fprintf(stderr,"sender\n"); make_realtime(98); size_t i; for(i = 0; i < SECS*FREQUENCY; i ++) { ticks_t ticks = get_ticks(); ssize_t r = write(fd[1], &ticks, sizeof(ticks)); if(sizeof(ticks) != r) abort(); usleep((useconds_t)(1e6/FREQUENCY)); } }
void sender_ach(void) { fprintf(stderr,"sender\n"); make_realtime(98); size_t i; for( i = 0; i < SECS*FREQUENCY; i ++) { ticks_t ticks = get_ticks(); int r = ach_put(&chan, &ticks, sizeof(ticks)); if(ACH_OK != r) abort(); usleep((useconds_t)(1e6/FREQUENCY)); } }
void calibrate(void) { make_realtime(30); double a = 0; ticks_t r0,r1; size_t i; overhead = 0; for( i = 0; i<1000; i++ ) { r0 = get_ticks(); r1 = get_ticks(); a += ticks_delta(r0,r1); } overhead = (a) / 1000; }
void receiver_ach(int rt) { fprintf(stderr,"receiver\n"); make_realtime(99); /* flush some initial delayed messages */ size_t i; for( i = 0; i < 5; i ++ ) { ticks_t ticks; size_t fs; enum ach_status r = ach_get(&chan, &ticks, sizeof(ticks), &fs, NULL, ACH_O_LAST | ACH_O_WAIT); switch (r) { case ACH_OK: case ACH_MISSED_FRAME: break; default: fprintf(stderr, "bad ach_get result: %s\n", ach_result_to_string(r)); exit(EXIT_FAILURE); } } /* now the good stuff */ ticks_t ticks = get_ticks(); while(1) { size_t fs; ticks_t then; if (KERNDEV) { then.tv_sec = 1; then.tv_nsec = 0; } else { then = ticks; then.tv_sec += 1; } int r = ach_get(&chan, &ticks, sizeof(ticks), &fs, &then, ACH_O_LAST | ACH_O_WAIT); ticks_t now = get_ticks(); if( ACH_TIMEOUT == r ) break; assert(ACH_OK == r || sizeof(ticks) == fs); /* only print real-time latencies */ if (rt) { send_time((float)ticks_delta(ticks,now)); } } }
void receiver_pipe(int rt) { (void)rt; fprintf(stderr,"receiver\n"); make_realtime(99); /* flush some initial delayed messages */ size_t i; for( i = 0; i < 5; i ++ ) { ticks_t ticks; ssize_t r = read(fd[0], &ticks, sizeof(ticks)); if(sizeof(ticks) != r) abort(); } /* now the good stuff */ while(1) { ticks_t ticks; ssize_t r = read(fd[0], &ticks, sizeof(ticks)); ticks_t now = get_ticks(); if(sizeof(ticks) != r) abort(); send_time((float)ticks_delta(ticks,now)); } }
int main() { make_realtime(Runner::_process, new Runner); }