Exemple #1
0
DWORD WINAPI WatchDog::Thread_WatchDog_HeartBeat(LPVOID pParam)//zhouzx
{
	WatchDog * pThis = (WatchDog *)pParam;
	DOG_STATUS struDogStatus;

	for(;;)
	{
		//给看门狗发送正常的心跳接口
		SendHeartbeat(DOG_NORMAL);

		//狗进程不存在时重启狗进程
		struDogStatus = GetWatchdogStatus();
		if (DOG_NOTACTIVE == struDogStatus)
		{
			//TRACE("==YQ== 狗进程重启!!!");
			OpenWatchDog(6);
		}

		//控制发送心跳的时间间隔
		if(WaitForSingleObject(pThis->m_hCloseWatchDogEvent,6000) == WAIT_OBJECT_0)
		{
			break;
		}
	}

	return 0;
}
bool HealthCheckedConnection::Setup() {
  // setup the RX timeout
  ResumeTimer();

  // send a heartbeat now and setup the TX timer
  SendHeartbeat();
  HeartbeatSent();
  return true;
}
bool MavLinkInterpreter::CheckConnection()
{
	if (millis() > _hb_timer)
	{
		_hb_timer = millis() + 1500;
		if (_connected)
		{
			SendHeartbeat();
		}

		// Sending Mavlink configuration after 10sec, to give FC enough time to boot.
		if (_send_mavlink_connection_config < 10 && millis() > 10000 && !_connected)
		{
			debugSerial.printf("%d\tConfiguring connection...\r\n", millis());
			ConfigureConnection();			
		}

		if (millis() > _mavLinkConnectedTimer && ++_hb_count_lost > 5)
		{ // if no HEARTBEAT from APM  in 1.5s then we are not connected			
			_lastConnected = _connected;
			_connected = false;			
			_hb_count = 0;				//reset the counter
#ifdef DEBUG_APM_CONNECTION
			if (_lastConnected)
			{
				debugSerial.printf("%d\tLost MavLink connection...\r\n", millis());
			}
			else
			{
				debugSerial.printf("%d\tMavLink not connected.\r\n", millis());
			}
#endif 
		}
		else if (_hb_count >= 10)
		{ // If  received > 10 heartbeats from MavLink then we are connected
			_lastConnected = _connected;
			_connected = true;
			_hb_count_lost = 0;
#ifdef DEBUG_APM_CONNECTION
			if (_hb_count == 10)
			{
				debugSerial.println("###############################################");
				debugSerial.printf("%d\tMavLink connection etablished. Version: %d\r\n", millis(), _m->MavlinkVersion);
				debugSerial.println("###############################################");
				_send_mavlink_connection_config = 0;
			}
#endif
			digitalWrite(LED_BOARD_P, HIGH); // LED will be ON when connected to MavLink, else it will slowly blink
		}

		//Store bool state in the main public message data
		_m->MavLinkConnected = _connected;
	}

	return _connected;
}
void* Listener(void * args)
{
	char buf[BUFSIZE];
	SDMSubreqst sub;
	SDMDeletesub del;
	MessageManager mm;
	mm.Async_Init(my_port);
	
	// Send one hearbeat, let the app fail
	SendHeartbeat();
	
	while(1)
	{
		if(mm.IsReady())
		{
			//SendHeartbeat();
#ifdef WIN32
			switch(mm.GetMsg(buf))
#else
			switch(mm.GetMessage(buf))
#endif
			{
			case SDM_Subreqst:
				sub.Unmarshal(buf);
				printf("Subscription Rec'd for %d\n",sub.msg_id.getInterfaceMessagePair()); fflush(NULL);
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.AddSubscription(sub);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			case SDM_Deletesub:
				printf("Cancel Rec'd\n");
				del.Unmarshal(buf);
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.RemoveSubscription(del);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			default:
				printf("Invalid Message found!\n");
				fflush(NULL);
				break;
			}
		}
		else
		{
			usleep(100000);
		}
	}
	return NULL;
}
Exemple #5
0
void WatchDog::ClosedWatchDog()
{
	//关闭看门狗
	if (m_hWatchDog != NULL)
	{ 	
		SetEvent(m_hCloseWatchDogEvent);

		if( WaitForSingleObject(m_hWatchDog, INFINITE) == WAIT_OBJECT_0)
		{
			CloseHandle(m_hWatchDog);
			m_hWatchDog = NULL;

			CloseHandle(m_hCloseWatchDogEvent);
			m_hCloseWatchDogEvent = NULL;

			//给看门狗发送正常退出的心跳,表明程序是正常退出,而非异常退出。这样看门狗就不会重新启动pc。
			SendHeartbeat(DOG_EXIT);
		}

		LOG(LEVEL_INFO, "关闭看门狗程序");
	}
}
bool HealthCheckedConnection::SendNextHeartbeat() {
  SendHeartbeat();
  return true;
}
Exemple #7
0
	void Run () {
		LOGINFO (TEXT ("Runner thread started"));
		bool bRetry = true;
		bool bStatus = true;
		do {
			if (!m_poService->SetState (STARTING)) break;
			LOGINFO (TEXT ("Starting Java framework"));
			if (!m_poService->CreatePipes ()) {
				LOGERROR (TEXT ("Unable to open pipes to Java framework"));
				CAlert::Bad (TEXT ("Unable to connect to service"));
				bStatus = false;
				break;
			}
			if (!m_poService->StartJVM ()) {
				if (bRetry) {
					LOGWARN (TEXT ("Unable to initiate Java framework"));
					m_poService->ClosePipes ();
					CAlert::Bad (TEXT ("Restarting service"));
					bRetry = false;
					continue;
				}
				LOGERROR (TEXT ("Unable to initiate Java framework"));
				CAlert::Bad (TEXT ("Unable to start service"));
				bStatus = false;
				break;
			}
			if (!m_poService->ConnectPipes ()) {
				if (bRetry) {
					LOGWARN (TEXT ("Unable to connect to Java framework"));
					m_poService->ClosePipes ();
					CAlert::Bad (TEXT ("Restarting service"));
					m_poService->StopJVM ();
					bRetry = false;
					continue;
				}
				LOGERROR (TEXT ("Unable to connect to Java framework"));
				CAlert::Bad (TEXT ("Unable to start service"));
				bStatus = false;
				break;
			}
			if (!SendHeartbeat (true) || !WaitForHeartbeatResponse ()) {
				if (bRetry) {
					LOGWARN (TEXT ("Java framework is not responding"));
					m_poService->ClosePipes ();
					CAlert::Bad (TEXT ("Restarting service"));
					m_poService->StopJVM ();
					bRetry = false;
					continue;
				}
				LOGERROR (TEXT ("Java framework is not responding"));
				CAlert::Bad (TEXT ("Service is not responding"));
				// TODO: [XLS-43] (needs moving to PLAT) Can we get information from the log to pop-up if the user cloicks on the bubble?
				// TODO: [XLS-43] (needs a hook to implement) What about a "retry" button to force Excel to unload and re-load the plugin
				bStatus = false;
				break;
			}
			bRetry = true;
			if (!m_poService->SetState (RUNNING)) break;
			LOGINFO (TEXT ("Java framework started and connected"));
			// TODO: [XLS-43] (needs moving back to XLS project) Display messages a bit more sensibly - e.g. route them in from UDF when everything's registered
			CAlert::Good (TEXT ("Connected to service"));
			LOGDEBUG (TEXT ("Waiting for first message"));
			FudgeMsgEnvelope env = m_poService->Recv (m_lHeartbeatTimeout);
			while (env) {
				m_poService->DispatchAndRelease (env);
				if (m_poService->HeartbeatNeeded (m_lHeartbeatTimeout) && !SendHeartbeat (false)) break;
				LOGDEBUG (TEXT ("Waiting for message"));
				env = m_poService->Recv (m_lHeartbeatTimeout);
			}
			do {
				int ec = GetLastError ();
				if (ec == ETIMEDOUT) {
					if (!SendHeartbeat (false)) goto endMessageLoop;
				} else {
					LOGWARN (TEXT ("Couldn't read message, error ") << ec);
					goto endMessageLoop;
				}
				LOGDEBUG (TEXT ("Waiting for critical message"));
				env = m_poService->Recv (m_lHeartbeatTimeout);
				if (!env) {
					LOGWARN (TEXT ("Heartbeat missed"));
					goto endMessageLoop;
				}
				do {
					m_poService->DispatchAndRelease (env);
					if (m_poService->HeartbeatNeeded (m_lHeartbeatTimeout) && !SendHeartbeat (false)) goto endMessageLoop;
					LOGDEBUG (TEXT ("Waiting for message"));
					env = m_poService->Recv (m_lHeartbeatTimeout);
				} while (env);
			} while (m_poService->GetState () == RUNNING);
endMessageLoop:
			m_poService->ClosePipes ();
			if (!m_poService->SetState (STOPPING)) break;
			LOGINFO (TEXT ("Restarting Java framework"));
			CAlert::Bad (TEXT ("Reconnecting to service"));
		} while (true);
		if (m_poService->GetState () != POISONED) {
			LOGINFO (TEXT ("Poisoning Java framework"));
			m_poService->SetState (POISONED);
			bStatus &= m_poService->SendPoison ();
		}
		m_poService->ClosePipes ();
		m_poService->SetState (bStatus ? STOPPED : ERRORED);
		LOGINFO (TEXT ("Runner thread stopped"));
	}
Exemple #8
0
void* Listener(void * args)
{
	char buf[BUFSIZE];
	SDMSubreqst sub;
	SDMDeletesub del;
	MessageManager mm;
	mm.Async_Init(myPort);
	while(1)
	{
		pthread_testcancel();
		if(mm.IsReady())
		{
			SendHeartbeat();
#ifdef WIN32
			switch(mm.GetMsg(buf))
#else
			switch(mm.GetMessage(buf))
#endif
			{
			case SDM_ACK:
				printf("SDMAck received\n");
				helloReply = true;
				break;
			case SDM_Register:
				printf("SDMRegister received\n");
				waitForReg = false;
				break;
			case SDM_ID:
				printf("SDMID received\n");
				myID.Unmarshal(buf);
				printf("CompID: \n");
				printf("   SensorID: %li\n", myID.destination.getSensorID());
				printf("    Address: %lx\n", myID.destination.getAddress());
				printf("       Port: %i\n", myID.destination.getPort());
				waitForID = false;					
				break;
			case SDM_Subreqst:
				sub.Unmarshal(buf);
				printf("Subscription Rec'd for %d\n",sub.msg_id.getInterfaceMessagePair());
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.AddSubscription(sub);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			case SDM_Deletesub:
				printf("Cancel Rec'd\n");
				del.Unmarshal(buf);
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.RemoveSubscription(del);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			default:
				printf("Invalid Message found!\n");
				break;
			}
		}
		else
		{
			usleep(100000);
		}
	}
	return NULL;
}