#ifndef SSTIME_HH
#define SSTIME_HH

#include "TimeP.h"
#include "ssdbg.hh"

/****************************************************************************
 **
 ** Just some defines and a set of utility functions for handling time so that
 ** there is a nice map between simulation and life.
 **
 ****************************************************************************/

#ifdef SELF_TEST
// All times (including period) divided by 250 in test mode.
#define SMARTSAMPLER_CLOCKDIV 50
#else
#define SMARTSAMPLER_CLOCKDIV 1
#endif

class SSTime {
public:

  SSTime(){
    setStart();
  };
  ~SSTime(){};

  // Time in (adjusted) seconds since mission start.
  double missionTime(){
    struct timespec timeSpec;
    double newtime;
    clock_gettime(CLOCK_REALTIME, &timeSpec);
    newtime = Time::seconds(&timeSpec);
    return((newtime - _starttime)*SMARTSAMPLER_CLOCKDIV);
  }

private:
  double _starttime;

  // Times are always measured in offset from mission start.
  void setStart(){
    struct timespec timeSpec;
    clock_gettime(CLOCK_REALTIME, &timeSpec);
    _starttime = Time::seconds(&timeSpec);
  }
};

#endif // SSTIME_HH
