9 #ifndef app_telemeter_hpp
10 #define app_telemeter_hpp
67 template <
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);
179 template <
class derivedT>
184 template <
class derivedT>
185 template <
typename telT>
192 clock_gettime(CLOCK_REALTIME, &telT::lastRecord);
197 template <
class derivedT>
198 template <
typename telT>
205 clock_gettime(CLOCK_REALTIME, &telT::lastRecord);
210 template <
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.");
222 template <
class derivedT>
229 m_tel.logExt(
"bintel");
231 m_tel.logName(derived().m_configName);
233 m_tel.loadConfig(config);
235 config(m_maxInterval,
"telemeter.maxInterval");
240 template <
class derivedT>
247 m_tel.logThreadStart();
251 while (m_tel.logThreadRunning() ==
false && w < 20)
254 std::this_thread::sleep_for(std::chrono::duration<unsigned long, std::nano>(100000000));
258 if (m_tel.logThreadRunning() ==
false)
260 derivedT::template log<software_critical>({__FILE__, __LINE__,
"telemetry thread not running. exiting."});
267 template <
class derivedT>
270 return derived().checkRecordTimes();
273 template <
class derivedT>
279 template <
class derivedT>
280 template <
class telT,
class... telTs>
285 clock_gettime(CLOCK_REALTIME, &ts);
286 return checkRecordTimes(ts, tel, tels...);
289 template <
class derivedT>
290 template <
class telT,
class... telTs>
294 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)
296 derived().recordTelem(&tel);
299 return checkRecordTimes(ts, tels...);
302 template <
class derivedT>
305 static_cast<void>(ts);
314 #define TELEMETER_SETUP_CONFIG( cfig ) \
315 if (telemeterT::setupConfig( cfig) < 0) \
317 log<software_error>({__FILE__, __LINE__, "Error from telemeterT::setupConfig"}); \
325 #define TELEMETER_LOAD_CONFIG( cfig ) \
326 if (telemeterT::loadConfig(cfig) < 0) \
328 return log<software_error, -1>({__FILE__, __LINE__, "Error from telemeterT::loadConfig"}); \
332 #define TELEMETER_APP_STARTUP \
333 if (telemeterT::appStartup() < 0) \
335 return log<software_error, -1>({__FILE__, __LINE__}); \
339 #define TELEMETER_APP_LOGIC \
340 if (telemeterT::appLogic() < 0) \
342 return log<software_error, -1>({__FILE__, __LINE__}); \
346 #define TELEMETER_APP_SHUTDOWN \
347 if (telemeterT::appShutdown() < 0) \
349 log<software_error>({__FILE__, __LINE__, "error from telemeterT::appShutdown"}); \
#define MAGAOX_telRelPath
The relative path to the telemetry directory.
constexpr static logPrioT LOG_TELEM
A telemetry recording.
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.
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.
derivedT & derived()
Access the derived class.