9#ifndef app_telemeter_hpp
10#define app_telemeter_hpp
19#ifdef XWCTEST_NAMESPACE
73template <
class derivedT>
83 double m_maxInterval{10.0};
94 template <
typename telT>
95 int telem(
const typename telT::messageT &msg );
155 template <
class telT,
class... telTs>
166 template <
class telT,
class... telTs>
183 return *
static_cast<derivedT *
>(
this);
187template <
class derivedT>
192template <
class derivedT>
193template <
typename telT>
197 m_tel.template log<telT>(
msg, logPrio::LOG_TELEM);
200 clock_gettime(CLOCK_REALTIME, &telT::lastRecord);
219template <
class derivedT>
222 m_tel.m_configSection =
"telemeter";
226 config.add(
"telemeter.maxInterval",
"",
"telemeter.maxInterval", argType::Required,
"telemeter",
"maxInterval",
false,
"double",
"The maximum interval, in seconds, between telemetry records. Default is 10.0 seconds.");
231template <
class derivedT>
234 m_tel.m_logLevel = logPrio::LOG_TELEM;
242 m_tel.logPath(std::string(derived().basePath()) +
"/" + tmpstr);
244 m_tel.logExt(
"bintel");
246 m_tel.logName(derived().m_configName);
248 m_tel.loadConfig(config);
250 config(m_maxInterval,
"telemeter.maxInterval");
255template <
class derivedT>
262 m_tel.logThreadStart();
265 #ifdef XWCTEST_TELEMETER_LOGSTART
266 m_tel.logShutdown(
true);
272 while (m_tel.logThreadRunning() ==
false && w < 20)
275 std::this_thread::sleep_for(std::chrono::duration<unsigned long, std::nano>(100000000));
279 if (m_tel.logThreadRunning() ==
false)
281 derivedT::template log<software_critical>({__FILE__, __LINE__,
"telemetry thread not running. exiting."});
288template <
class derivedT>
291 if( m_tel.logThreadRunning() ==
false )
293 derived().state( stateCodes::FAILURE );
296 std::cerr <<
"\nCRITICAL: telemetry thread not running. Exiting.\n\n";
298 derived().m_shutdown = 1;
306template <
class derivedT>
312template <
class derivedT>
313template <
class telT,
class... telTs>
318 clock_gettime(CLOCK_REALTIME, &ts);
319 return checkRecordTimes(ts, tel, tels...);
322template <
class derivedT>
323template <
class telT,
class... telTs>
327 if (((
double)ts.tv_sec - ((
double)ts.tv_nsec) / 1e9) - ((
double)telT::lastRecord.tv_sec - ((
double)telT::lastRecord.tv_nsec) / 1e9) > m_maxInterval - ((
double)derived().m_loopPause) / 1e9)
329 derived().recordTelem(&tel);
332 return checkRecordTimes(ts, tels...);
335template <
class derivedT>
338 static_cast<void>(ts);
347#define TELEMETER_SETUP_CONFIG( cfig ) \
348 if (telemeterT::setupConfig( cfig) < 0) \
350 log<software_error>({__FILE__, __LINE__, "Error from telemeterT::setupConfig"}); \
358#define TELEMETER_LOAD_CONFIG( cfig ) \
359 if (telemeterT::loadConfig(cfig) < 0) \
361 return log<software_error, -1>({__FILE__, __LINE__, "Error from telemeterT::loadConfig"}); \
365#define TELEMETER_APP_STARTUP \
366 if (telemeterT::appStartup() < 0) \
368 return log<software_error, -1>({__FILE__, __LINE__}); \
372#define TELEMETER_APP_LOGIC \
373 if (telemeterT::appLogic() < 0) \
375 return log<software_error, -1>({__FILE__, __LINE__}); \
379#define TELEMETER_APP_SHUTDOWN \
380 if (telemeterT::appShutdown() < 0) \
382 log<software_error>({__FILE__, __LINE__, "error from telemeterT::appShutdown"}); \
386#ifdef XWCTEST_NAMESPACE
#define XWC_DEFAULT_VERBOSITY
#define MAGAOX_telRelPath
The relative path to the telemetry directory.
#define MAGAOX_env_telem
Environment variable setting the relative telem path.
A device base class which saves telemetry.
XWC_DEFAULT_VERBOSITY verboseT
int appShutdown()
Perform telemeter application shutdown.
int loadConfig(appConfigurator &config)
Load the device section from an application configurator.
int telem(const typename telT::messageT &msg)
Make a telemetry recording.
int appLogic()
Perform telemeter application logic.
derivedT & derived()
Access the derived class.
logger::logManager< derivedT, logFileRaw< verboseT > > logManagerT
The log manager type.
int checkRecordTimes(timespec &ts)
Empty function called at the end of the template list.
int setupConfig(appConfigurator &config)
Setup an application configurator for the device section.
int appStartup()
Starts the telemetry log thread.
int checkRecordTimes(timespec &ts, const telT &tel, telTs... tels)
Worker function to actually perform the record time checking logic.
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
The standard MagAOX log manager, used for both process logs and telemetry streams.
#define XWCTEST_NAMESPACE