From: Subject: Date: Sun, 4 Feb 2007 18:17:07 -0500 MIME-Version: 1.0 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Content-Location: http://www.ecs.umass.edu/ece/sdp/sdp04/janaswamy/bike.c X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
/*************************************************************=
****
bike.c

Univerisity of Massachusetts
Senior Design Project 2004
*****************************************************************/

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

#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyUSB0"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define BUFF_SIZE 1000
#define COUNT 5

int main(int argc, char **argv) {

  int mask =3D 255;
  int fd;
  int retval =3D 1;
  int i;
  char F =3D 'a';
  struct termios oldtios, newtios;
  char *buf;
  char *inport;
  inport =3D malloc(6);
  buf =3D malloc(127);
  memset(inport, 0, 5);

  // open the serial port
  fd =3D open(MODEMDEVICE, O_RDWR | O_NOCTTY);

  // get the old port settings
  tcgetattr(fd, &oldtios);

  // setup new port settings
  memset(&newtios, 0, sizeof(newtios));
  newtios.c_cflag =3D BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
  newtios.c_iflag =3D 0;                  // no input processing
  newtios.c_oflag =3D 0;                  // no output processing
  newtios.c_lflag =3D 0;
  newtios.c_cc[VTIME]    =3D 0;   // timer is not used
  newtios.c_cc[VMIN]     =3D 0;   // no blocking on read

  // flush and set parameters
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &newtios);

  //sync
  retval =3D write(fd, &F, 1);

   //main receiving loop
  while(retval > 0){
    i=3D0;

    while(i<1)
      i =3D read(fd, &F, 1);
    retval =3D sprintf(buf, "%u\n", mask & (int)F);
    write(1, buf, retval);
  }
  tcsetattr(fd, TCSANOW, &oldtios);
  close(fd);

  return 0;
}