/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : StartCamera.cc						    */
/* Author   : rsm                                                           */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 1 May 2008                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#include "MissionTimeAttribute.h"
#include "IntegerAttribute.h"
#include "FloatAttribute.h"
#include "StartCamera.h"
#include "Syslog.h"

StartCamera::StartCamera()
   : Behavior(StartCameraBehaviorName, Sequential)
{
   Attribute::Input *input;

   attributes.add(new IntegerAttribute("nSamplePeriods",
				       "nSamplePeriods",
				       &_nSamplePeriods, 0));

   attributes.add(new IntegerAttribute("nPhotos",
				       "nPhotos",
				       &_nPhotos, 0));

   attributes.add(new FloatAttribute("distance",
				     "distance",
				     &_distance, 0.0));
   try 
   {
      _camera = new CameraIF(CameraIFServerName);
   } 
   catch (Exception e) 
   {
      Syslog::write("StartCamera:: Caught exception on creation "
		    "of CameraIF:%s\n", e.msg);
      abortMission();
   }
   catch(...)
   {
      Syslog::write("StartCamera:: -- Failed to initialize connection "
		    "to CameraIF\n");
      abortMission();
   }
}


StartCamera::~StartCamera()
{
   delete _camera ;
}

Boolean StartCamera::validInput()
{
  return True;
}

Boolean StartCamera::shouldBehaviorStart( )
{
     return bothSequence();
}

void StartCamera::execute()
{
   //
   // Start the driver running with the above parameters
   //
   if( _nPhotos )
   {
      _camera->start(_nPhotos, _nSamplePeriods, _distance);
      Syslog::write("The StartCamera Behavior has executed at t = %15.2f; "
		    "Taking %d photographs.",
		    _missionClock->seconds(), _nPhotos);
   }
   else
   {
      _camera->onContinuously(_nSamplePeriods, _distance);
      Syslog::write("The StartCamera Behavior has executed at t = %15.2f; "
		    "The camera will run until commanded to stop.",
		    _missionClock->seconds(), _nPhotos);
   }
   setState(Finished);
   return;
}






