// Pyld Console Simulator.cpp : Defines the entry point for the console application.
//

/*
#include <windows.h>
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
*/

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>




#include "common.h"

BOOL runThreads = TRUE;

int main(int argc, char* argv[])
{
	HANDLE hThread = NULL;
	int c = 0;
	//int retval = FAIL;
	int retval = -1;
	char fileName[15] = {0};
	int portNum = 1;
        int 		thread_create_rtn;
	pthread_t	thread_id;

	retval = SerialPortOpen(1);  //  Passed parameter is ignored.
        if(retval != -1)
        {
          printf("Creating listener thread....\n");
          thread_create_rtn = pthread_create(&thread_id, NULL, FloatComms, NULL);
        }
        else
        {
          printf("can't open serial port, exiting\n");
          exit(0);
	}

        if (thread_create_rtn == 0)
	  printf("Serial Port Listen Thread Created\n");
	else
        {
          printf("Unable to create Serial Port Listen Thread\n");
          printf("Return value from pthread_create == %d\n", thread_create_rtn);
          printf("Exiting!\n");
          exit(0);
        }

	while(1)	
        {
	  sleep(1);

          if (runThreads == 0)
          {
             printf("Exiting - halting system\n");
	     fflush(stdout);
	     fflush(stderr);
	     system("halt");
          }
    }
}

