📄 rtitask.cpp
字号:
/*** *** See the file "L2_RTI_EO1/disclaimers-and-notices-L2.txt" for *** information on usage and redistribution of this file, *** and for a DISCLAIMER OF ALL WARRANTIES. ***/#include <TimeStamp.h>#include "RTITask.hpp"#include <stdio.h> // for errno#include <taskLib.h>#include "ExceptionAction.hpp"#include "Logging.hpp"#include "TimerTask.hpp"RTITask::RTITask( void ) { }RTITask::~RTITask( void ) { RTIMessage livingstoneMessage(L2_EXIT); if (msgQSend(RTI_TO_L2_MQID, (char*)(&livingstoneMessage), sizeof(RTIMessage), WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR) { ExceptionAction::sendFailure(ExceptionAction::SND_REAL_TIME_INTERFACE, ExceptionAction::RCV_LIVINGSTONE_DISPATCHER, errno); } else { Logging::log(Logging::L2_DEBUG, "RTI:: Sent L2_EXIT to L2\n"); } killTimerTask();}void RTITask::listenForMonitorEvents( void ) { while (true) { MONITOR_DATA monitor; if (msgQReceive(SCL_TO_RTI_MQID, (char*)&monitor, sizeof(MONITOR_DATA), WAIT_FOREVER) == ERROR) { ExceptionAction::receiveFailure(ExceptionAction::RCV_REAL_TIME_INTERFACE, errno); } else { // invokePolicy() returns true on exit if (invokePolicy(monitor)) { return; } } } char str [MAX_MSG_LENGTH]; sprintf(str, "RTI:: number of outstanding timers on exit is %d\n", d_policy.outstandingTimerCount()); Logging::log(Logging::L2_DEBUG, str);}int RTITask::invokePolicy(MONITOR_DATA& monitor) { char str [MAX_MSG_LENGTH]; // Build the time stamp TimeStamp TimeStamp; char timeStamp[MAX_MSG_LENGTH]; monitor.time.seconds = TimeStamp.seconds(); monitor.time.nanosec = TimeStamp.nanoSeconds(); sprintf(timeStamp, "at time seconds %d, nanosec %d \n", monitor.time.seconds, monitor.time.nanosec); switch ( monitor.msgType ) { case L2_COMMAND: if (d_policy.beat.numberOfCommandsReceived < MAX_LONGINT) d_policy.beat.numberOfCommandsReceived++; else d_policy.beat.numberOfCommandsReceived = 0; sprintf(str, "RTI:: received L2_COMMAND %d %d %s", monitor.variable, monitor.value, timeStamp); Logging::log(Logging::L2_DEBUG, str); d_policy.commandPolicy(monitor); break; case L2_OBSERVATION: if (d_policy.beat.numberOfObservationsReceived < MAX_LONGINT) d_policy.beat.numberOfObservationsReceived++; else d_policy.beat.numberOfObservationsReceived = 0; sprintf(str, "RTI:: received L2_OBSERVATION %d %d %s", monitor.variable, monitor.value, timeStamp); Logging::log(Logging::L2_DEBUG, str); d_policy.observationPolicy(monitor); break; case TIMER_EXPIRATION: if (d_policy.beat.numberOfTimersExpired < MAX_LONGINT) d_policy.beat.numberOfTimersExpired++; else d_policy.beat.numberOfTimersExpired = 0; sprintf(str, "RTI:: received TIMER_EXPIRATION %s", timeStamp); Logging::log(Logging::L2_DEBUG, str); d_policy.timeoutPolicy(monitor); break; case TIMER_HEARTBEAT: if (d_policy.beat.numberOfHeartbeats < MAX_LONGINT) d_policy.beat.numberOfHeartbeats++; else d_policy.beat.numberOfHeartbeats = 0; d_policy.heartbeatPolicy(monitor); break; case CMD_EXIT: sprintf(str, "RTI:: received CMD_EXIT %s", timeStamp); Logging::log(Logging::L2_DEBUG, str); return true; // exit default: ExceptionAction::unhandledRTIOpCode(monitor.msgType); break; } return false; // do not exit}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -