/****************************************************************************/
/* Copyright 1992 to 1996 MBARI                                             */
/****************************************************************************/
/* Summary  : Main Pilot Console CPU2 VxWorks                               */
/* Filename : startup.c                                                     */
/* Author   : Andrew Pearce                                                 */
/* Project  : Tiburon ROV                                                   */
/* Version  : Version 1.0                                                   */
/* Created  : 06/06/97                                                      */
/* Modified : 06/06/97                                                      */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/* $Header: $
 * $Log:    $
 * 
 */
/****************************************************************************/

#include <vxWorks.h>                /* vxWorks system declarations          */
#include <stdioLib.h>               /* VxWorks standard I/O library         */
#include <strLib.h>                 /* vxWorks string library functions     */
#include <taskLib.h>                /* vxWorks task library functions       */
#include <rebootLib.h>              /* vxWorks system reboot library funcs  */

#include "types.h"                  /* mbari style guide type declarations  */
#include "usrTime.h"                /* MBARI time and date functions        */
#include "rovPriority.h"            /* mbari Rov Application Priorities     */

extern "C" {

#include "datamgr.h"                /* Data Manager Declarations            */
#include "sio32Server.h"            /* SIO32 Protocol Server Declarations   */
#include "tiburon.h"	            /* Tiburon definitions                  */
#include "idleCpu.h"                /* Idle CPU Monitor Task                */
#include "recorder.h"               /* Flight Recorder Task                 */
#include "videoOverlay.h"	    /* Video Overlay Task                   */

#include "../sio32Chan.h"	    /* SIO32 Serial Channel Allocations     */

extern Void rovnavTask( Void );

} 

#include "iviewTask.h"	            /* Integrated Viewing Task (IView)      */
#include "lapBox.h"	            /* Lapbox Interface Task                */
#include "pilotTray.h"	            /* Pilot Tray Interface Task            */

extern  int telnetTaskPriority;

#define FLIGHT_RECORDER_CFG	"/usr/tiburon/config/fltRecorder.cfg"

/****************************************************************************/
/* Function    : spawnTask                                                  */
/* Purpose     : Executes a vxWorks task. Convenience function for taskSpawn*/
/* Inputs      : name, priority, stack size, task options, messages for     */
/*               successful and unsuccessful task creation. func ptr & args */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
spawnTask( char *taskName, int priority, int stacksize, int options,
    char *okMsg, char *errorMsg, FUNCPTR entryPoint,
    int arg1, int arg2, int arg3)
{
                                    /* Initialize Task                      */
    if ( taskSpawn( taskName, priority, options, stacksize,
       entryPoint, arg1, arg2, arg3, 0, 0, 0, 0, 0, 0, 0 ) != ERROR)
    {
       logMsg(okMsg);
       return (OK);
    } /* if */
    
    logMsg(errorMsg);
    return(ERROR);
} /* spawnTask() */

/****************************************************************************/
/* Function    : consoleInit                                                */
/* Purpose     : Initializes application software for the pilot console     */
/* Inputs      : None - Add calls to start application software here        */
/* Outputs     : None                                                       */
/****************************************************************************/
    Void
consoleInit( Void )
{				    /* Set priority of initialization task  */
    taskPrioritySet(taskIdSelf(),  CONSOLE_INIT_TASK_PRIORITY);

    usrTimeInit();		    /* Initialize MBARI time library         */
    
    telnetTaskPriority = 200;

    if (netDevCreate ("batray:", "batray.mbari.org", 0) != OK)
	logMsg("Console Init: error creating ftp file system device\n");

    dm_init( (DM_Define*) NULL );   /* Initialize Data Manager              */	
    taskDelay(3 * sysClkRateGet());

    spawnTask("recordInit", 100, 20000, 0,
	"Flight Recorder Task Initialized\n",
        "Flight Recorder Task Initialization Failed\n", 
	(FUNCPTR) recordInit, (int) FLIGHT_RECORDER_CFG, 10, NULL);

#if 0
    spawnTask("idleCpu", IDLE_CPU_TASK_PRIORITY, IDLE_CPU_TASK_STACKSIZE, 0,
	"Idle CPU Task Initialized\n",
        "Idle CPU Task Initialization Failed\n", 
	(FUNCPTR) idleCpuTask,
        (int) TIBURON_DM_PREFIX CONSOLE_IDLE2_CPU_PERCENT_DM,
        (int) TIBURON_DM_PREFIX CONSOLE_IDLE2_CPU_ALARM_DM, NULL);
#endif

#if 0
    spawnTask("overlay2",
        VIDEO_OVERLAY_TASK_PRIORITY, VIDEO_OVERLAY_TASK_STACKSIZE, VX_FP_TASK,
        "Console Init: Tiburon Video Overlay Task Initialized\n",
	"Console Init: Tiburon  Video Overlay Task Initialization Failed\n",
	(FUNCPTR) videoOverlayTask2, NULL, NULL, NULL);
#endif

    spawnTask("lapbox1", LAPBOX_SRQ_PRIORITY, LAP_BOX_STACKSIZE, 0,
        "Console Init: Lapbox Task Initialized\n",
	"Console Init: Lapbox Task Failed\n",
        (FUNCPTR) LapBoxTask, LAPBOX_1_SERIAL_CHAN,
        (int) "Lapbox 1", (int) LAP_BOX1_DM_PREFIX);

    spawnTask("lapbox2", LAPBOX_SRQ_PRIORITY, LAP_BOX_STACKSIZE, 0,
        "Console Init: Lapbox Task Initialized\n",
	"Console Init: Lapbox Task Failed\n",
        (FUNCPTR) LapBoxTask, LAPBOX_2_SERIAL_CHAN,
        (int) "Lapbox 2", (int) LAP_BOX2_DM_PREFIX);

    spawnTask("pilotTray", PILOT_TRAY_SRQ_PRIORITY, PILOT_TRAY_STACKSIZE, 0,
        "Console Init: Pilot Tray Task Initialized\n",
	"Console Init: Pilot Tray Task Failed\n",
        (FUNCPTR) PilotTrayTask, (int) "Pilot Tray", NULL, NULL);

    spawnTask("iView", IVIEW_PRIORITY, IVIEW_STACKSIZE, VX_FP_TASK,
        "Console Init: Integrated Viewing Initialized\n",
	"Console Init: Integrated Viewing Initialization Failed\n",
	(FUNCPTR) iview, NULL, NULL, NULL);

    spawnTask("rovnavTest", 100, 5000, 0,
	"ROVNAV Test Task Initialized\n",
        "ROVNAV Test Task Initialization Failed\n", 
	(FUNCPTR) rovnavTask, 0, 0, NULL);

    logMsg("Console VME Init: Software Initialization Complete\n");
} /* consoleInit() */






