//=========================================================================
// Summary  : */
// Filename : SerialDeviceTest.cc
// Author   : */
// Project  : */
// Revision : 1
// Created  : 2000/08/19
// Modified : 2000/08/19
//=========================================================================
// Description :
//=========================================================================
#include <stdio.h>
#include <string.h>

#include "SerialDevice.h"

#define DEV_NAME "/dev/ser1"

int main(int argc, char **argv)
{
  SerialDevice *device;
  char buf[30];

  printf ("SerialDevice class test utility V1.0\n\n");

  printf ("Calling constructor for SerialDevice class for %s\n", DEV_NAME);

  device = new SerialDevice(DEV_NAME);

  device->commsDebugMode(SerialDevice::DebugOff);

  printf ("File descriptor for %s is %d\n", DEV_NAME, device->getFd());

  if (strcmp(device->devName(), DEV_NAME) == 0)
    printf ("Device Name is correct %s\n", DEV_NAME);
  else
    printf ("Device Name is NOT correct %s\n", DEV_NAME);

  printf ("Setting port to 9600 baud, 8 data, 1 stop, even parity\n");
  device->setLineFormat(9600, 8, 1, "EVEN");

  device->printTermios();

  printf ("\n\nWriting 20 test messages to port\n");

  int i;
  for (i = 0; i < 20; i++)
  {
    sprintf (buf, "This is test message %d\n", i + 1);
    device->write(buf, strlen(buf));

    if (device->read (buf, sizeof(buf), 1000) != ERROR)
      printf ("Received:  %s", buf);
    else
      printf ("Nothing read\n");

    sleep(1);
   
    tcflush(device->getFd(), TCIOFLUSH);
  }

  printf ("Calling destructor for SerialDevice\n");
  delete device;

  return 0;
}
