11 #include "../../libMagAOX/libMagAOX.hpp"
12 #include "../../magaox_git_version.h"
146 config.add(
"temp.warning",
"",
"temp.warning", argType::Required,
"temp",
"warning",
false,
"float",
"Temperature at which to issue a warning. Default is 40.");
147 config.add(
"temp.alert",
"",
"temp.alert", argType::Required,
"temp",
"alert",
false,
"float",
"Temperature at which to issue an alert. Default is 50.");
148 config.add(
"temp.emergency",
"",
"temp.emergency", argType::Required,
"temp",
"emergency",
false,
"float",
"Temperature at which to issue an emergency. Default is 55.");
151 config.add(
"usb.idVendor",
"",
"usb.idVendor", argType::Required,
"usb",
"idVendor",
false,
"string",
"USB vendor id, 4 digits");
152 config.add(
"usb.idProduct",
"",
"usb.idProduct", argType::Required,
"usb",
"idProduct",
false,
"string",
"USB product id, 4 digits");
170 std::vector<std::string> sections;
172 _config.unusedSections(sections);
174 if( sections.size() == 0 )
181 for(
size_t i=0; i< sections.size(); ++i)
183 if(config.isSetUnused(mx::app::iniFile::makeKey(sections[i],
"serial" )))
186 config.configUnused(
m_probes.back().m_serial, mx::app::iniFile::makeKey(sections[i],
"serial" ));
189 m_probes.back().m_location = sections[i];
190 config.configUnused(
m_probes.back().m_location, mx::app::iniFile::makeKey(sections[i],
"location" ));
209 for(
size_t n =0; n <
m_probes.size(); ++n)
227 bool checkConn =
false;
228 for(
size_t n =0; n <
m_probes.size(); ++n)
232 float temperature = -1e37;
235 log<software_error>({__FILE__, __LINE__,
"Did not get temp from " +
m_probes[n].m_location +
". Error: " +
DS18B20_errmsg()});
242 m_probes[n].m_temperature = temperature;
263 log<software_error>({__FILE__, __LINE__,
"Error from " +
m_probes[n].m_location +
". Error: " +
DS18B20_errmsg()});
292 log<software_error>({__FILE__, __LINE__});
306 std::vector<std::string> devNames;
311 for(
size_t i=0; i< devNames.size(); ++i)
313 elevatedPrivileges ep(
this);
320 log<software_error>({__FILE__,__LINE__, std::string(
DS18B20_errmsg())});
331 log<software_error>({__FILE__,__LINE__, std::string(
DS18B20_errmsg())});
338 snprintf(romstr + 2*i, 3,
"%02x", rom[i]);
341 for(
size_t j=0;j<
m_probes.size();++j)
347 if(
m_probes[j].m_devName == devNames[i])
368 log<software_error>({__FILE__, __LINE__,
"Error from " +
m_probes[j].m_location +
". Error: " +
DS18B20_errmsg()});
379 log<text_log>(
"no match for " + devNames[i]);
410 std::vector<float> temps;
412 for(
size_t n=0; n<temps.size(); ++n)
414 temps[n] =
m_probes[n].m_temperature;
420 telem<telem_temps>(temps);
The base-class for MagAO-X applications.
void updateIfChanged(pcf::IndiProperty &p, const std::string &el, const T &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI property element value if it has changed.
stateCodes::stateCodeT state()
Get the current state code.
int m_shutdown
Flag to signal it's time to shutdown. When not 0, the main loop exits.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
int createROIndiNumber(pcf::IndiProperty &prop, const std::string &propName, const std::string &propLabel="", const std::string &propGroup="")
Create a ReadOnly INDI Number property.
int registerIndiPropertyReadOnly(pcf::IndiProperty &prop)
Register an INDI property which is read only.
pcf::IndiProperty m_indiP_temps
virtual int appStartup()
Startup function.
virtual int appShutdown()
Shutdown the app.
virtual void loadConfig()
~usbtempMon() noexcept
D'tor, declared and defined for noexcept.
std::vector< probe > m_probes
friend class usbtempMon_test
std::vector< float > m_lastTemps
int recordTelem(const telem_temps *)
virtual int appLogic()
Implementation of the FSM for usbtempMon.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
int recordTemps(bool force=false)
virtual void setupConfig()
usbtempMon()
Default c'tor.
@ OPERATING
The device is operating, other than homing.
@ CONNECTED
The application has connected to the device or service.
@ NOTCONNECTED
The application is not connected to the device or service.
int ttyUSBDevNames(std::vector< std::string > &devNames, const std::string &vendor, const std::string &product)
Get the ttyUSB device name for a set of devices specified by their vendor and product ids.
std::string toLower(std::string const &s)
constexpr static logPrioT LOG_CRITICAL
The process can not continue and will shut down (fatal)
constexpr static logPrioT LOG_ALERT
This should only be used if some action is required by operators to keep the system safe.
constexpr static logPrioT LOG_EMERGENCY
Normal operations of the entire system should be shut down immediately.
constexpr static logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
A device base class which saves telemetry.
int loadConfig(appConfigurator &config)
Load the device section from an application configurator.
int appLogic()
Perform telemeter application logic.
int setupConfig(appConfigurator &config)
Setup an application configurator for the device section.
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
bool operator<(const probe &p) const
Log entry recording electronics rack temperature.
A USB device as a TTY device.
std::string m_idProduct
The product id 4-digit code.
std::string m_serial
The serial number.
std::string m_idVendor
The vendor id 4-digit code.
char * DS18B20_errmsg(void)
int DS18B20_acquire(HANDLE fd, float *temperature)
int DS18B20_measure(HANDLE fd)
HANDLE DS18B20_open(const char *serial_port)
void DS18B20_close(HANDLE fd)
int is_fd_valid(HANDLE fd)
int DS18B20_rom(HANDLE fd, unsigned char *rom)