9#ifndef app_telemeter_hpp
10#define app_telemeter_hpp
67template <
class derivedT>
86 template <
typename telT>
87 int telem(
const typename telT::messageT &
msg );
96 template <
typename telT>
147 template <
class telT,
class... telTs>
158 template <
class telT,
class... telTs>
175 return *
static_cast<derivedT *
>(
this);
179template <
class derivedT>
184template <
class derivedT>
185template <
typename telT>
189 m_tel.template log<telT>(
msg, logPrio::LOG_TELEM);
192 clock_gettime(CLOCK_REALTIME, &telT::lastRecord);
197template <
class derivedT>
198template <
typename telT>
202 m_tel.template log<telT>(logPrio::LOG_TELEM);
205 clock_gettime(CLOCK_REALTIME, &telT::lastRecord);
210template <
class derivedT>
213 m_tel.m_configSection =
"telemeter";
215 m_tel.setupConfig(config);
217 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.");
222template <
class derivedT>
225 m_tel.m_logLevel = logPrio::LOG_TELEM;
233 m_tel.logPath(std::string(derived().basePath()) +
"/" + tmpstr);
235 m_tel.logExt(
"bintel");
237 m_tel.logName(derived().m_configName);
239 m_tel.loadConfig(config);
241 config(m_maxInterval,
"telemeter.maxInterval");
246template <
class derivedT>
253 m_tel.logThreadStart();
257 while (m_tel.logThreadRunning() ==
false && w < 20)
260 std::this_thread::sleep_for(std::chrono::duration<unsigned long, std::nano>(100000000));
264 if (m_tel.logThreadRunning() ==
false)
266 derivedT::template log<software_critical>({__FILE__, __LINE__,
"telemetry thread not running. exiting."});
273template <
class derivedT>
276 return derived().checkRecordTimes();
279template <
class derivedT>
285template <
class derivedT>
286template <
class telT,
class... telTs>
291 clock_gettime(CLOCK_REALTIME, &ts);
292 return checkRecordTimes(ts, tel, tels...);
295template <
class derivedT>
296template <
class telT,
class... telTs>
300 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)
302 derived().recordTelem(&tel);
305 return checkRecordTimes(ts, tels...);
308template <
class derivedT>
311 static_cast<void>(ts);
320#define TELEMETER_SETUP_CONFIG( cfig ) \
321 if (telemeterT::setupConfig( cfig) < 0) \
323 log<software_error>({__FILE__, __LINE__, "Error from telemeterT::setupConfig"}); \
331#define TELEMETER_LOAD_CONFIG( cfig ) \
332 if (telemeterT::loadConfig(cfig) < 0) \
334 return log<software_error, -1>({__FILE__, __LINE__, "Error from telemeterT::loadConfig"}); \
338#define TELEMETER_APP_STARTUP \
339 if (telemeterT::appStartup() < 0) \
341 return log<software_error, -1>({__FILE__, __LINE__}); \
345#define TELEMETER_APP_LOGIC \
346 if (telemeterT::appLogic() < 0) \
348 return log<software_error, -1>({__FILE__, __LINE__}); \
352#define TELEMETER_APP_SHUTDOWN \
353 if (telemeterT::appShutdown() < 0) \
355 log<software_error>({__FILE__, __LINE__, "error from telemeterT::appShutdown"}); \
#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.
double m_maxInterval
The maximum interval, in seconds, between telemetry records. Default is 10.0 seconds.
int telem()
Make a telemetry recording, for an empty record.
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.
logger::logManager< derivedT, logFileRaw > logManagerT
The log manager type.
derivedT & derived()
Access the derived class.
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.