#ifndef _BUOYLAUNCHERDRIVER_H
#define _BUOYLAUNCHERDRIVER_H

#include "PeriodicTask.h"
#include "SerialDevice.h"
#include "BuoyLauncherInput.h"
#include "BuoyLauncherOutput.h"
#include "BuoyLauncherLog.h"
#include "BuoyLauncherIF.h"
#include "LcXmodem.h"

class BuoyLauncherDriver : public PeriodicTask {

  friend class BuoyLauncherLog;

public:
  BuoyLauncherDriver(SerialDevice *device, int period);

  virtual ~BuoyLauncherDriver();

protected:

  // Called on every cycle of control loop
  void periodicCallback();

  // Called when event is received from server
  void eventCallback(TaskInterface *taskIF, EventCode event);

  //load configuration data
  void loadConfiguration();

  Boolean launchBuoy(char real_or_dummy);

  void rotateBuoy();

  void rotateCarousel();

  void rotateToLaunchPosition(char); // handles both real and dummy commands

  void ejectBuoy();

  void currentBuoy();

  void xferData(char);

  void clearLC();

  void uploadLog();

  void reinitLauncher();

  void pushAndRetract();

  void retractArms();

  void rotateAPosition(char launch_or_data);

  Boolean status(char);

  void printStatus(LauncherStatus ls);

  Boolean sendCmdToLC(char);

  Boolean sendTimeToLC(time_t);

  char readAckFromLC(unsigned timeout_in_secs);

  BuoyLauncherInput *_input;
  BuoyLauncherOutput *_output;
  BuoyLauncherLog *_log;

  SerialDevice *_device;
  LcXmodem *_lcx;
  Boolean _initialized;
  Boolean _statusCalls;
  Boolean _buoyInLaunchPosition;

  time_t _lastStatusCheck;

  int _period;

  // Interface to server. Driver subscribes to Initialize
  // and other events from server
  BuoyLauncherIF *_serverProxy;

  Boolean initialize();

  void logError(int error_code);

 };


#endif
