/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : System.h                                                      */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _SYSTEM_H
#define _SYSTEM_H

#include <sys/types.h>

// Period of Navigation task
#define NavigationPeriodMillisec 200

// Environment variable names
#define AuvConfigDirName "AUV_CONFIG_DIR"
#define AuvLogDirName    "AUV_LOG_DIR"
#define AuvPlanDirName   "AUV_PLAN_DIR"

// Link to latest data log subdirectory
#define LatestLogDirName "latest"

// System period in millisec
#define SystemPeriodMillisec 200

// Highest reasonable priority for QNX 
#define HighestPriority 	  19

#define CriticalDriverPriority    19
#define NavigationPriority        18
#define NavigationServerPriority  17
#define DynamicControlPriority    16
#define TailconeDriverPriority    15
#define LayeredControlPriority    14

#define CriticalServerPriority    11	// Servers use Floating Priority
#define NonCriticalDriverPriority 11
#define NonCriticalServerPriority 11	// Servers use Floating Priority
#define DynamicCtrlServerPriority 11	// Servers use Floating Priority
#define TailconeServerPriority    11	// Servers use Floating Priority
#define LayeredCtrlServerPriority 11	// Servers use Floating Priority
#define SimulatorPriority         10
#define BackgroundPriority        10
#define TerrainAidPriority         9

/*
CLASS 
System

DESCRIPTION
Various utilities for AUV system configuration

AUTHOR
Tom O'Reilly
*/
class System {

public:

  ///////////////////////////////////////////////////////////////////
  // Default configuration file name
  // [input] basename: Name of configuration file, sans directory
  //                   (e.g. "vehicle.cfg")
  static const char *configurationFile(const char *basename);

  ///////////////////////////////////////////////////////////////////
  // Default mission plan file name
  // [input] basename: Name of mission plan file, sans directory
  //                   (e.g. "abort.plan")
  static const char *missionPlanFile(const char *basename);

  ///////////////////////////////////////////////////////////////////
  // Spawn specified program, with specified arguments
  static pid_t spawn(const char *programName, const char *args);

  ///////////////////////////////////////////////////////////////////
  // Set process priority to specified value
  static int setTaskPriority(int priority);

  ///////////////////////////////////////////////////////////////////
  // Copy specified file to log directory
  static void copyToLogDir(const char *filename);

  ///////////////////////////////////////////////////////////////////
  // Sleep for the indicated period
  static void milliSleep( unsigned long millisecs);

  static int findServer(const char *name);

  ///////////////////////////////////////////////////////////////////
  // Ping a host
  // Returns:
  //   0 -> Host is responding
  //   1 -> Host failed to respond before timeout
  //  -1 -> Do not have permission to create ICMP socket
  //  -2 -> Failed to create ICMP socket
  //  -3 -> No host information available (host unknown)
  //  -4 -> Failed to send ping
  //
  static int ping(const char* host, unsigned int timeout_in_milliseconds);

  ///////////////////////////////////////////////////////////////////
  // Ping a host
  // Returns:
  //   0 -> Host is responding
  //   1 -> Host failed to respond before timeout
  //  -1 -> Do not have permission to create ICMP socket
  //  -2 -> Failed to create ICMP socket
  //  -3 -> No host information available (host unknown)
  //  -4 -> Failed to send ping
  //
  static int auvping(const char* host, unsigned int timeout_in_milliseconds);

protected:

  static int _pingsock;
};
#endif
