// Telerobotics Senior Project
// Webbot 1.0 - Robot Control System
// (c) 2000 Bradley University ECE
// ---------------------------------
// botmove.c - Send movement commands to the robot
// Written by: John Kiolbasa
// Command line syntax:
//	botmove d a [-v]
//	
//	where:	d is f, b, r or l
//		a is 1, 2, 3 or 4
//		-v   verbose output

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	int sp;
	struct termios tios;
	int buff;
	int i = 0;
	char cmd;
	int amt;

	cmd = argv[1][0];
	amt = atoi(argv[2]);

	switch(cmd)
	{
		case 'f':
			buff = 127;
			break;
		case 'b':
			buff = 131;
			break;
		case 'r':
			buff = 135;
			break;
		case 'l':
			buff = 139;
			break;
		default:
			printf("Bad command");
	}

	buff += amt;

	sp = open("/dev/ttyS0", O_RDWR|O_NOCTTY);
	if(sp == -1)
	{
		printf("Error opening serial port.\n");
		return 1;
	}

	tcflush(sp, TCIOFLUSH);
	write(sp, &buff, 1);
	while(!read(sp, &buff, 1)) {}

	if(argc > 3 && argv[3][0] == '-' && argv[3][1] == 'v')
	{
		printf("Command sent: %d\n", buff);
	}

	return 0;
}


syntax highlighted by Code2HTML, v. 0.8.11