7 #ifndef flipperCtrl_hpp
8 #define flipperCtrl_hpp
11 #include "../../libMagAOX/libMagAOX.hpp"
12 #include "../../magaox_git_version.h"
128 config.add(
"flipper.reverse",
"",
"flipper.reverse", argType::Required,
"flipper",
"reverse",
false,
"bool",
"If true, reverse the positions for in and out.");
147 _config(rev,
"flipper.reverse");
164 log<software_critical>({__FILE__, __LINE__});
176 log<software_error>({__FILE__,__LINE__});
213 std::stringstream logs;
215 log<text_log>(logs.str());
224 std::stringstream logs;
226 log<text_log>(logs.str());
233 elevatedPrivileges ep(
this);
253 std::stringstream logs;
255 log<text_log>(logs.str());
314 log<software_error>({__FILE__, __LINE__});
333 std::string header(6,
'\0');
344 std::string response;
347 log<software_error>({__FILE__,__LINE__,
"error getting response from flipper"});
350 if(response[16] == 1)
364 std::string header(6,
'\0');
391 if(
ipRecv.getName() != m_indiP_position.getName())
393 log<software_error>({__FILE__, __LINE__,
"invalid indi property received"});
402 if(
ipRecv[
"in"].getSwitchState() == pcf::IndiElement::On)
410 if(
ipRecv[
"out"].getSwitchState() == pcf::IndiElement::On)
416 else newpos = m_outPos;
424 std::unique_lock<std::mutex>
lock(m_indiMutex);
427 m_indiDriver->sendSetProperty (m_indiP_position);
432 if(moveTo(m_tgt) < 0)
461 static int last_pos = -1;
462 static int last_moving = -1;
466 if(last_pos !=
m_pos || last_moving != moving || force)
468 std::string ps =
"in";
471 telem<telem_stage>({ (int8_t) moving, (
double)
m_pos, ps});
474 last_moving = moving;
The base-class for MagAO-X applications.
stateCodes::stateCodeT state()
Get the current state code.
int registerIndiPropertyNew(pcf::IndiProperty &prop, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is exposed for others to request a New Property for.
int m_shutdown
Flag to signal it's time to shutdown. When not 0, the main loop exits.
void updateSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, const pcf::IndiElement::SwitchStateType &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI switch element value if it has changed.
int stateLogged()
Updates and returns the value of m_stateLogged. Will be 0 on first call after a state change,...
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
std::mutex m_indiMutex
Mutex for locking INDI communications.
int createStandardIndiSelectionSw(pcf::IndiProperty &prop, const std::string &name, const std::vector< std::string > &elements, const std::vector< std::string > &elementLabels, const std::string &label="", const std::string &group="")
Create a standard R/W INDI selection (one of many) switch with vector of elements and element labels.
friend class flipperCtrl_test
flipperCtrl()
Default c'tor.
pcf::IndiProperty m_indiP_position
int recordTelem(const telem_stage *)
~flipperCtrl() noexcept
D'tor, declared and defined for noexcept.
INDI_NEWCALLBACK_DECL(flipperCtrl, m_indiP_position)
virtual void setupConfig()
virtual int appLogic()
Implementation of the FSM for flipperCtrl.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
virtual int appStartup()
Startup function.
virtual void loadConfig()
int recordStage(bool force=false)
virtual int appShutdown()
Shutdown the app.
dev::telemeter< flipperCtrl > telemeterT
#define INDI_NEWCALLBACK(prop)
Get the name of the static callback wrapper for a new property.
@ OPERATING
The device is operating, other than homing.
@ NODEVICE
No device exists for the application to control.
@ FAILURE
The application has failed, should be used when m_shutdown is set for an error.
@ READY
The device is ready for operation, but is not operating.
@ CONNECTED
The application has connected to the device or service.
@ NOTCONNECTED
The application is not connected to the device or service.
@ POWERON
The device power is on.
std::string ttyErrorString(int ec)
Get a text explanation of a TTY_E_ error code.
int ttyWrite(const std::string &buffWrite, int fd, int timeoutWrite)
Write to the tty console indicated by a file descriptor.
int ttyRead(std::string &strRead, int bytes, int fd, int timeoutRead)
Read from a tty console indicated by a file-descriptor, until a given number of bytes are read.
const pcf::IndiProperty & ipRecv
INDI_NEWCALLBACK_DEFN(acesxeCtrl, m_indiP_windspeed)(const pcf
std::unique_lock< std::mutex > lock(m_indiMutex)
constexpr static logPrioT LOG_ERROR
An error has occured which the software will attempt to correct.
An input/output capable device.
unsigned m_writeTimeout
The write timeout [msec].
int loadConfig(mx::app::appConfigurator &config)
Load the device section from an application configurator.
int setupConfig(mx::app::appConfigurator &config)
Setup an application configurator for the device section.
unsigned m_readTimeout
The read timeout [msec].
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 appStartup()
Starts the telemetry log thread.
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
Log entry recording stdMotionStage status.
A USB device as a TTY device.
std::string m_deviceName
The device path name, e.g. /dev/ttyUSB0.
int m_fileDescrip
The file descriptor.
int connect()
Connect to the device.
int getDeviceName()
Get the device name from udev using the vendor, product, and serial number.
std::string m_idProduct
The product id 4-digit code.
int setupConfig(mx::app::appConfigurator &config)
Setup an application configurator for the USB section.
std::string m_serial
The serial number.
int loadConfig(mx::app::appConfigurator &config)
Load the USB section from an application configurator.
speed_t m_baudRate
The baud rate specification.
std::string m_idVendor
The vendor id 4-digit code.
#define TTY_E_DEVNOTFOUND