#include <stdio.h>
#include "video_conf.h"
#include "rpd_driver.h"
       
extern char *getenv();

VCONF_DEVTABLE	vdt;	/* video device table */

main(argc, argv)
int argc;
char **argv;
{
RPD_ptr	rpd;
int	rpd_index;
int	res;
char	cmd[64];
int	i,f1,f2;


if (argc != 4)
{
        fprintf(stderr,"%s:Incorrect argument count\n", argv[0]);
	usage(argv[0]);
}

        vdt.dev[0].type = RPD_DEV;
        strcpy(vdt.dev[0].model, argv[1]);
        strcpy(vdt.dev[0].tty, argv[2]);
        vdt.dev[0].baud = atoi (argv[3]);
        vdt.dev[0].parity = 0;
        vdt.ndevs = 1;

	if( (rpd = rpdutil_open( &vdt, 0 )) == NULL )
	{
		fprintf(stderr,"unable to open rpd %s on %s\n",
			rpd->devname, rpd->port );
		exit(1);
	}

	while(1)
	{
		printf("command? ");
		gets(cmd);
		if( !strcmp(cmd,"quit") )
			exit(0);
		
		if( !strcmp(cmd,"indexon") )
			res =	(*rpd->cmd)(rpd,INDEX_ON);
		else if( !strcmp(cmd,"indexoff") )
			res =	(*rpd->cmd)(rpd,INDEX_OFF);

		else if( !strcmp(cmd,"@") )
			printf("@ %d\n",(*rpd->getframe)(rpd));

		else if( !strcmp(cmd,"fjog") )
			res =	(*rpd->jog)(rpd,1);
		else if( !strcmp(cmd,"rjog") )
			res =	(*rpd->jog)(rpd,-1);

		else if( !strcmp(cmd,"reset") )
			res =	(*rpd->reset)(rpd);

		else if( !strcmp(cmd,"ffast") )
			res =	(*rpd->varspeed)(rpd,F_FAST);
		else if( !strcmp(cmd,"rfast") )
			res =	(*rpd->varspeed)(rpd,R_FAST);
		else if( !strcmp(cmd,"fplay") )
			res =	(*rpd->varspeed)(rpd,F_PLAY);
		else if( !strcmp(cmd,"rplay") )
			res =	(*rpd->varspeed)(rpd,R_PLAY);
		else if( !strcmp(cmd,"fslow") )
			res =	(*rpd->varspeed)(rpd,F_SLOW);
		else if( !strcmp(cmd,"rslow") )
			res =	(*rpd->varspeed)(rpd,R_SLOW);
		else if( !strcmp(cmd,"still") )
			res =	(*rpd->varspeed)(rpd,STOP);

		else if( !strcmp(cmd,"segplay") )
		{
			printf("from? ");
			gets(cmd);
			f1 = atoi(cmd);
			printf("to? ");	
			gets(cmd);
			f2 = atoi(cmd);
			res =	(*rpd->segplay)(rpd,f1,f2,1);
		}

		else if( !strcmp(cmd,"search") )
		{
			printf("to? ");
			gets(cmd);
			if( (i=atoi(cmd)) )
				res =	(*rpd->search)(rpd,i,1);
		}
 
		else
		  {
		    printf("Commands are:\n");
		printf(" quit \n indexon \n indexoff \n @ \n fjog \n rjog \n reset \n ffast \n rfast \n fplay \n rplay \n fslow \n rslow \n still \n segplay \n search\n");
	      }

		printf("result of command is %d\n",res);
	}

	
}

usage(prog)
char *prog;
{
printf("Usage: %s model tty baud \n", prog);
printf("where model is one of DEC_VDP50, SONY_LDP1000A, PANA_OMDR\n");
printf("and tty is of form 'tty??' \n");
exit(0);
}
