#include #include #include #include static int get_bit (struct parport *p) { int bit = ieee1284_read_status (p); return bit & 0x20 ? 1 : 0; } static void do_comm (struct parport *p) { // First, sync up. This could take several seconds.. int last_bit = get_bit (p); printf ("Please wait...\n"); while (get_bit (p) == last_bit) { struct timespec tv; tv.tv_sec = 0; tv.tv_nsec = 1000000; nanosleep (&tv, NULL); } printf ("Synchronised. Let's go.\n"); } static int timecomm (const char *port) { struct parport_list pl; int listing = 0; int i; if (!strcmp (port, "-l")) { listing = 1; printf ("Available ports:\n"); } ieee1284_find_ports (&pl, 0); for (i = 0; i < pl.portc; i++) { if (listing) printf ("%s\n", pl.portv[i]->name); else if (!strcmp (port, pl.portv[i]->name)) break; } if (listing) return 0; if (i == pl.portc) return 1; ieee1284_claim (pl.portv[i]); do_comm (pl.portv[i]); ieee1284_release (pl.portv[i]); ieee1284_free_ports (&pl); return 0; } int main (int argc, char **argv) { if (argc != 2) { printf ("Syntax: timecomm -l\n" " timecomm \n"); return 1; } return timecomm (argv[1]); }