示例#1
0
//----------------------------------------
//	TestSchedule
//----------------------------------------
void TestSchedule(ScopedLogMessage& msg, Poco::Util::Timer& timer)
{
	msg.Message("--- schedule ---");

	const Poco::Timestamp::TimeDiff kTimeDiff = 500000;	// 500msec

	Poco::Event event;
	MyTimerTask task(msg, event);
	Poco::Util::TimerTask::Ptr pTask = new Poco::Util::TimerTaskAdapter<MyTimerTask>(task, &MyTimerTask::onTimer);

	Poco::Timestamp time;
	time += kTimeDiff;
	timer.schedule(pTask, time);
	
	event.wait();
	msg.Message(Poco::format("    execution delay from scheduled: %Ldusec"
							, pTask->lastExecution().epochMicroseconds()-time.epochMicroseconds()));
}
示例#2
0
CFileUpLoad::~CFileUpLoad(void)
{
	UnInit();
	std::string strLog = "CFileUpLoad exit.";
	g_pLogger->information(strLog);
	TRACE(strLog.c_str());
#ifndef TEST_MULTI_SENDER
	g_eFileUpLoadThreadExit.set();
#endif
}
示例#3
0
//----------------------------------------
//	WaitAndShowTime
//----------------------------------------
Poco::Timestamp::TimeVal WaitAndShowTime(	ScopedLogMessage& msg
										,	Poco::Event& event
										,	Poco::Util::TimerTask::Ptr& pTask
										,	const std::string& text
										,	Poco::Timestamp::TimeVal refTime)
{
	event.wait();
	Poco::Timestamp::TimeVal val = pTask->lastExecution().epochMicroseconds();
	msg.Message(Poco::format("%s %7.3fmsec", text, 0.001*(val-refTime)));
	return val;
}
示例#4
0
void CScanTool2Dlg::ReleaseThreads()
{
	//识别线程
	for (int i = 0; i < m_vecRecogThreadObj.size(); i++)
	{
		m_vecRecogThreadObj[i]->eExit.wait();
		m_pRecogThread[i].join();
	}
	std::vector<CRecognizeThread*>::iterator itRecogObj = m_vecRecogThreadObj.begin();
	for (; itRecogObj != m_vecRecogThreadObj.end();)
	{
		CRecognizeThread* pObj = *itRecogObj;
		SAFE_RELEASE(pObj);
		itRecogObj = m_vecRecogThreadObj.erase(itRecogObj);
	}
	if (m_pRecogThread)
	{
		delete[] m_pRecogThread;
		m_pRecogThread = NULL;
	}

	//文件发送线程
// 	m_SendFileThread->join();
// 	SAFE_RELEASE(m_pSendFileObj);
// 	g_eSendFileThreadExit.wait();
// 	SAFE_RELEASE(m_SendFileThread);

	//tcp命令线程
	m_TcpCmdThread->join();
	SAFE_RELEASE(m_pTcpCmdObj);
	g_eTcpThreadExit.wait();
	SAFE_RELEASE(m_TcpCmdThread);

	//压缩线程
	m_pCompressThread->join();
	SAFE_RELEASE(m_pCompressObj);
	g_eCompressThreadExit.wait();
	SAFE_RELEASE(m_pCompressThread);
}
示例#5
0
// Shutdown Live Tracker
void LiveTrackerShutdown()
{
  if (_Thread.isRunning()) {
    _t_end = false;
    _t_run = false;
    NewDataEvent.set();
    _Thread.join();
    StartupStore(TEXT(". LiveTracker closed.%s"),NEWLINE);
  }
#ifdef WIN32
  if (_ws_inited) {
    WSACleanup();
  }
#endif
}
示例#6
0
// Update live tracker data, non blocking
void LiveTrackerUpdate(NMEA_INFO *Basic, DERIVED_INFO *Calculated)
{
  if (!_inited) return;               // Do nothing if not inited
  if (LiveTrackerInterval==0) return; // Disabled
  if (Basic->NAVWarning) return;      // Do not log if no gps fix

  livetracker_point_t newpoint;
  static int logtime = 0;

  
  ScopeLock guard(_t_mutex);

  //Check if sending needed (time interval)
  if (Basic->Time >= logtime) { 
    logtime = (int)Basic->Time + LiveTrackerInterval;
    if (logtime>=86400) logtime-=86400;
  } else return;

  // Half hour FIFO must be enough
  if (_t_points.size() > (unsigned int)(1800 / LiveTrackerInterval)) {
    // points in queue are full, drop oldest point 
    _t_points.pop_front();
  }
  
  struct tm t;
  time_t t_of_day;
  t.tm_year = Basic->Year - 1900;
  t.tm_mon = Basic->Month - 1; // Month, 0 - jan
  t.tm_mday = Basic->Day;
  t.tm_hour = Basic->Hour;
  t.tm_min = Basic->Minute;
  t.tm_sec = Basic->Second;
  t.tm_isdst = 0; // Is DST on? 1 = yes, 0 = no, -1 = unknown
  t_of_day = mkgmtime(&t);
  
  newpoint.unix_timestamp = t_of_day;
  newpoint.flying = Calculated->Flying;
  newpoint.latitude = Basic->Latitude;
  newpoint.longitude = Basic->Longitude;
  newpoint.alt = Calculated->NavAltitude;
  newpoint.ground_speed = Basic->Speed;
  newpoint.course_over_ground = Calculated->Heading;
  
  _t_points.push_back(newpoint);
  NewDataEvent.set();
}  
示例#7
0
BOOL CScanTool2Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	USES_CONVERSION;
	CString strTitle = _T("");
	strTitle.Format(_T("%s %s"), SYS_BASE_NAME, SOFT_VERSION);
	SetWindowText(strTitle);

	InitThreads();
	m_pExamInfoMgrDlg = new CExamInfoMgrDlg(this);
	m_pExamInfoMgrDlg->Create(CExamInfoMgrDlg::IDD, this);
	m_pExamInfoMgrDlg->ShowWindow(SW_SHOW);

	m_pScanMgrDlg = new CScanMgrDlg(this);
	m_pScanMgrDlg->Create(CScanMgrDlg::IDD, this);
	m_pScanMgrDlg->ShowWindow(SW_HIDE);

	try
	{
		g_eGetExamList.wait(5000);
	}
	catch (Poco::TimeoutException &e)
	{
	}
	InitUI();
	m_pExamInfoMgrDlg->InitShowData();
//	m_pExamInfoMgrDlg->Invalidate();

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
示例#8
0
// Leonardo Live Tracker (www.livetrack24.com) data exchange thread
static void LiveTrackerThread()
{
  int tracker_fsm = 0;
  livetracker_point_t sendpoint = {0};
  bool sendpoint_valid = false;
  bool sendpoint_processed = false;
  bool sendpoint_processed_old = false;
  // Session variables
  unsigned int packet_id = 0;
  unsigned int session_id = 0;               
  int userid = -1;
  
  _t_end = false;
  _t_run = true;

  srand(MonotonicClockMS());

  do {
    if (NewDataEvent.tryWait(5000)) NewDataEvent.reset();
    if (!_t_run) break;
    do {
      if (1) {
        sendpoint_valid = false;
        ScopeLock guard(_t_mutex);
        if (!_t_points.empty()) {
          sendpoint = _t_points.front();
          sendpoint_valid = true;
        }
      } //mutex
        if (sendpoint_valid) {
          sendpoint_processed = false;
          do {
            switch (tracker_fsm) {
              default:
              case 0:   // Wait for flying
                if (!sendpoint.flying) {
                  sendpoint_processed = true;
                  break;
                }
                tracker_fsm++;
                break;
                  
              case 1:
                // Get User ID
                userid = GetUserIDFromServer();
                sendpoint_processed = false;
                if (userid>=0) tracker_fsm++;
                break;
                
              case 2:
                //Start of track packet
                sendpoint_processed = SendStartOfTrackPacket(&packet_id, &session_id, userid);
                if (sendpoint_processed) {
                  StartupStore(TEXT(". Livetracker new track started.%s"),NEWLINE);
                  sendpoint_processed_old = true;
                  tracker_fsm++;
                }
                break;

              case 3:
                //Gps point packet
                sendpoint_processed = SendGPSPointPacket(&packet_id, &session_id, &sendpoint);
                
                //Connection lost to server
                if (sendpoint_processed_old && !sendpoint_processed) {
                  StartupStore(TEXT(". Livetracker connection to server lost.%s"), NEWLINE);
                }
                //Connection established to server
                if (!sendpoint_processed_old && sendpoint_processed) {
                  ScopeLock guard(_t_mutex);
                  int queue_size = _t_points.size();
                  StartupStore(TEXT(". Livetracker connection to server established, start sending %d queued packets.%s"), queue_size, NEWLINE);
                }
                sendpoint_processed_old = sendpoint_processed;
                
                if (!sendpoint.flying) {
                  tracker_fsm++;
                }
                break;

              case 4:
                //End of track packet
                sendpoint_processed = SendEndOfTrackPacket(&packet_id, &session_id);
                if (sendpoint_processed) {
                  StartupStore(TEXT(". Livetracker track finished, sent %d points.%s"), packet_id, NEWLINE);
                  tracker_fsm=0;
                }
                break;
            }// sw
            
            if (sendpoint_processed) {
              ScopeLock guard(_t_mutex);
              _t_points.pop_front();
            } else InterruptibleSleep(2500);
            sendpoint_processed_old = sendpoint_processed;
          } while (!sendpoint_processed && _t_run);
      }
    } while (sendpoint_valid && _t_run);
  } while (_t_run);
  
  _t_end = true;
}