/************************************************************************************
URG RT-Component
Copyright (c) 2010, Segway-Japan, Ltd.
All rights reserved.

Contact us if you use this software for sell.
If you use this software not for sell, you can use this software under BSD lisence.
See the files LICENSE.TXT and LICENSE-BSD.TXT for more details.                     
************************************************************************************/

#ifndef URG_H
#define URG_H

#include <rtm/Manager.h>
#include <rtm/DataFlowComponentBase.h>
#include <rtm/CorbaPort.h>
#include <rtm/DataInPort.h>
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>

#include "scip2.h"
#include "x11win.h"
#include "intellirobotStub.h"


using namespace RTC;

class Urg
  : public RTC::DataFlowComponentBase
{
 public:
  Urg(RTC::Manager* manager);
  ~Urg();

  virtual RTC::ReturnCode_t onInitialize();
  virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
  virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
  virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);

 protected:
  // Configuration variable declaration
  // <rtc-template block="config_declare">
  std::string m_str_port;
  int m_start;
  int m_end;
  int m_skip;
  int m_win;
  int m_timesynccount;
  double m_timesyncperiod;

  TimedLongSeq m_Scan;
  OutPort<TimedLongSeq> m_ScanOut;

 private:
  FILE* dev;
  int dummy;

  x11win win;

  double timesyncnext;


  void drawlaser();

  int scan[SCIP2_TOPURG_SAMPLES];

  const static int PIXEL_PER_METER = 50;
  const static int limagew = 500;
  const static int limageh = 500;
  unsigned long scanimage[limagew*limageh];

};


extern "C"
{
  void UrgInit(RTC::Manager* manager);
};

#endif // URG_H
