/* ROVER CONTROL SOFTWARE VERSION 1.1 */

#include <ctype.h>
#include <stdio.h>
#include <timing.h>
#include <stdlib.h>

#include "rovlib.h"
#include "rovint.h"
#include "rovsys.h"
#include "rovtest.h"
#include "rovfile.h"

#ifdef AZTEC_C
#include <userio.h>
#include <offload.h>

#else                 /* For Turbo C */
#include <conio.h>
#include "tt7pclib.h"
#include "tt7pcio.h"
#endif

/*FUNCTION PROTOTYPES*/

int deploy(void);
int setup(void);
int datafiles(void);

/*********************************************/

main() {
  
   char inkey; 

   tt7init();
   file_init();
   printf("\nTattletale Model7 Initialized");

   while(1) {
     printf("\n\n\nRover System Main Menu V1.1");
     printf("\n\n  1 -- Test Functions");
     printf("\n  2 -- Setup Deployment");
     printf("\n  3 -- Deploy");
     printf("\n  4 -- Data Files");
     printf("\n  8 -- Test Deployment");
     printf("\n  9 -- Reset");
     printf("\n\nEnter Selection: ");
     inkey = SerGetByteLP();
     switch(inkey){
       case '1':
	 testfunc();    /* In rovtest.c */
	 break;
       case '2':
	 setup();
	 break;
       case '3':
	 deploy();
	 break;
       case '4':
	 datafiles();
	 break;
       case '8':
	 testdeploy();     /* In rovtest.c */
	 break;
       case '9':
	 reset();
	 break;
     }
   }
} /*main*/

/*********************************************
      SETUP FUNCTION
*********************************************/

int setup(void){
  char menukey;
  struct tm	t;

  do{
    printf("\n\n\nRover Setup Menu");
    printf("\n\n  1 -- Set Clock");
    printf("\n  2 -- Change Mission Defaults");
    printf("\n  3 -- Change System Defaults");
    printf("\n  4 -- Change Calibration Coefficients");
    printf("\n  9 -- Exit");
    QueryChar("\nEnter Selection: ",'9',"12349",&menukey);

    switch(menukey){
      case '1':  /*Set Clock*/
	printf("\nSet Current Date and Time (CMD-D from CrossCut)");
	if(! QueryDateTime("\n<CR> for default", TRUE, &t))
	  return;
	SetTimeTM(&t, NULL);
	break;

      case '2':  /* Mission Defaults */
	while(!kbhit()){
	printf("\nTime in Tens of Milliseconds: %ld", TensMilliSecs());
	delaysecs(1);
	}
	break;

      case '3':  /* System Defaults */
	break;

      case '4':  /* Calibration Coefficients */
	break;
    }

  } while(menukey != '9');

  return 0;
}

/*******************************************************
	      Deploy Function
********************************************************/

int deploy(void){
  unsigned long delaytime = 240;

  QueryNum("\n\nEnter Deployment Delay Time (min): ","%ld","%ld", &delaytime);
  printf("\nRover will activate in %ld minutes.", delaytime);
  printf("\nDisconnect comm. cable and deploy");

  return 0;
}


/*******************************************************
	      Datafiles Function
********************************************************/

int datafiles(void){
  char menukey;
  XmdmErr xerr;

  do{
    printf("\n\n\nRover Datafiles Menu");
    printf("\n\n  1 -- Display File Status");
    printf("\n  2 -- Offload Rover Data Files");
    printf("\n  3 -- Offload Benthic Chamber Files");
    printf("\n  4 -- Offload Microprofiler Files");
    printf("\n  7 -- Display Data");
    printf("\n  8 -- Fill Memory with Test Data");
    printf("\n  9 -- Exit");
    QueryChar("\nEnter Selection: ",'9',"1234789", &menukey);

    switch(menukey){

      case '1':  /*Datafile Status*/
	file_status();
	break;

      case '2':  /* Rover Data */
	if(QueryYesNo("\n\nOffload the data", FALSE)){
	  printf("\n\nStarting XMODEM transfer ... ");
	  offload();
	}
	break;

      case '3':  /* Benthic Chamber Data */
	break;

      case '4':  /* Microprofiler Data */
	break;

      case '7':  /* Display Data */
	display_data();
	break;

      case '8':  /* Test Data */
	test_data();
	break;
    }  /* Switch ends */

  } while(menukey != '9');   /* Do loop ends */

  return 0;
}

/*******************************************************
	       Misc. Functions
*******************************************************/

