#include "clock.h"

main()
{
int	clockdev;	/* file descriptor  to the clock terminal device */
char	clockreply[17];	/* string into which to put the clocks reply */
int	n;		/* number of characters returned */
struct	termios	attr;	/* gettting and setting termios attributes   */
 

clockdev=devopen();


if (write(clockdev,"o",1)<0)
        {
        perror("error sending character");
        exit(EXIT_FAILURE);
        }
tcdrain(clockdev);
perror("error code before read");
 
/* We should now see this character echoed back to us */
if((n=read(clockdev,clockreply,1))<0)
        {
        perror("error reading command character");
        exit(EXIT_FAILURE);
        }
 
printf("number %i\n\r",n);
printf("character %s\n\r",clockreply);
 
/* now we have to wait for a bit for some unknown reason */
usleep(8000);
 
/* now we can send the cr */
 
if (write(clockdev,"\r",1)<0)
        {
        perror("error sending character");
        exit(EXIT_FAILURE);
        }
tcdrain(clockdev);
 
/* and now read in the echoed character*/
if((n=read(clockdev,clockreply,1))<0)
        {
        perror("error reading cr");
        exit(EXIT_FAILURE);
        }
 
printf("number %i\n\r",n);
printf("character %s\n\r",clockreply);
 
/* now finally we can read in the reply string */
while((n=read(clockdev,clockreply,1))>0)
        {
        printf("reply character %s\n\r",clockreply);
        }
 
 
 
 
 
close(clockdev);
}

