11#ifndef smc100ccCtrl_hpp
12#define smc100ccCtrl_hpp
14#include "../../libMagAOX/libMagAOX.hpp"
15#include "../../magaox_git_version.h"
111 const std::string &
com
193 config.add(
"stage.homingOffset",
"",
"stage.homingOffset", argType::Required,
"stage",
"homingOffset",
false,
"float",
"Homing offset, a.k.a. default starting position.");
194 config.add(
"stage.opDelta",
"",
"stage.opDelta", argType::Required,
"stage",
"opDelta",
false,
"float",
"Threshold move size for switching to OPERATING.");
308 std::stringstream
logs;
340 std::stringstream
logs;
351 std::stringstream
logs;
386 std::stringstream
logs;
418 std::stringstream
logs;
669 std::stringstream
logs;
696 std::string
buffer{
"1TS\r\n"};
723 const std::string & com
742 if(
resp.length() < 3)
770 if(
resp.length() < 4 )
val =
"";
774 while(
val[
val.size()-1] ==
'\r' ||
val[
val.size()-1] ==
'\n')
777 if(
val.size() < 1)
break;
783 if(
resp.length() < 4)
791 if(
resp.length() < 5)
val =
"";
796 while(
val[
val.size()-1] ==
'\r' ||
val[
val.size()-1] ==
'\n')
799 if(
val.size() < 1)
break;
849 if(
rval.length() != 6)
863 std::string
buffer{
"1TP\r\n"};
889 std::string
buffer{
"1TE\r\n"};
908 catch (
const std::out_of_range&
oor)
911 errorString =
"Unknown output; controller not responding correctly.";
924 errorString =
"Unknown message code or floating point controller address.";
930 errorString =
"Parameter missing or out of range.";
945 errorString =
"Command not allowed in NOT REFERENCED state.";
948 errorString =
"Command not allowed in CONFIGURATION state.";
951 errorString =
"Command not allowed in DISABLE state.";
954 errorString =
"Command not allowed in READY state.";
957 errorString =
"Command not allowed in HOMING state.";
960 errorString =
"UCommand not allowed in MOVING state.";
963 errorString =
"Current position out of software limit.";
975 errorString =
"Command not allowed for PP version.";
978 errorString =
"Command not allowed for CC version.";
982 std::cerr <<
"unkown status: " <<
status <<
"\n";
996 log<text_log>(
"can not command position in current state");
1001 float current = -1e55, target = -1e55;
1005 current =
ipRecv[
"current"].get<
float>();
1011 target =
ipRecv[
"target"].get<
float>();
1015 if(target == -1e55) target = current;
1017 if(target == -1e55)
return 0;
1020 std::unique_lock<std::mutex>
lock(m_indiMutex);
1026 return moveTo(target);
1037 std::string
buffer{
"1ST\r\n"};
1058 std::string
buffer{
"1OR\r\n"};
1094 std::string
buffer{
"1PA"};
Internal class to manage setuid privilege escalation with RAII.
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.
int m_powerState
Current power state, 1=On, 0=Off, -1=Unk.
indiDriver< MagAOXApp > * m_indiDriver
The INDI driver wrapper. Constructed and initialized by execute, which starts and stops communication...
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.
bool powerOnWaitElapsed()
This method tests whether the power on wait time has elapsed.
unsigned long m_powerOnWait
Time in sec to wait for device to boot after power on.
std::mutex m_indiMutex
Mutex for locking INDI communications.
int m_powerTargetState
Current target power state, 1=On, 0=Off, -1=Unk.
MagAO-X standard motion stage interface.
int loadConfig(mx::app::appConfigurator &config)
load the configuration system results
std::vector< std::string > m_presetNames
The names of each position on the stage.
bool m_powerOnHome
If true, then the motor is homed at startup (by this software or actual power on)
float m_preset_target
The target numerical preset position [1.0 is index 0 in the preset name vector].
pcf::IndiProperty m_indiP_home
Command the stage to home. .
bool m_defaultPositions
Flag controlling whether the default preset positions (the vector index) are set in loadConfig.
int updateINDI()
Update the INDI properties for this device controller.
int setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
int8_t m_moving
Whether or not the stage is moving. -2 means powered off, -1 means not homed, 0 means not moving,...
pcf::IndiProperty m_indiP_stop
Command the stage to halt.
float m_preset
The current numerical preset position [1.0 is index 0 in the preset name vector].
int appStartup()
Startup function.
std::vector< float > m_presetPositions
The positions, in arbitrary units, of each preset. If 0, then the integer position number (starting f...
int getPosition(double &pos)
Verifies current status of controller.
int recordTelem(const telem_stage *)
std::vector< std::string > validStateCodes
int getLastError(std::string &errStr)
Returns any error controller has.
virtual int appLogic()
Changes device state based on testing connection and device status.
bool m_moveOp
Flag indicating that OPERATING should not be set for a move, because it's less than m_opDelta.
int testConnection()
Tests if device is cabale of recieving/executing IO commands.
INDI_NEWCALLBACK_DECL(smc100ccCtrl, m_indiP_position)
smc100ccCtrl()
Default c'tor.
double m_opDelta
The threshold for switching to OPERATING.
virtual void setupConfig()
Setup the configuration system (called by MagAOXApp::setup())
virtual void loadConfig()
Load the configuration system results (called by MagAOXApp::setup())
int moveTo(double position)
int recordStage(bool force=false)
virtual int appShutdown()
Do any needed shutdown tasks. Currently nothing in this app.
int recordPosition(bool force=false)
pcf::IndiProperty m_indiP_position
Indi variable for reporting the stage position.
int getCtrlState(std::string &state)
virtual int appStartup()
Checks if the device was found during loadConfig.
int makeCom(std::string &str, const std::string &com)
int splitResponse(int &axis, std::string &com, std::string &val, std::string &resp)
virtual int onPowerOff()
This method is called when the change to poweroff is detected.
#define INDI_NEWCALLBACK_DEFN(class, prop)
Define the callback for a new property request.
#define REG_INDI_NEWPROP(prop, propName, type)
Register a NEW INDI property with the class, using the standard callback name.
@ OPERATING
The device is operating, other than homing.
@ NODEVICE
No device exists for the application to control.
@ NOTHOMED
The device has not been homed.
@ HOMING
The device is homing.
@ FAILURE
The application has failed, should be used when m_shutdown is set for an error.
@ ERROR
The application has encountered an error, from which it is recovering (with or without intervention)
@ READY
The device is ready for operation, but is not operating.
@ CONNECTED
The application has connected to the device or service.
@ UNINITIALIZED
The application is unitialized, the default.
@ INITIALIZED
The application has been initialized, set just before calling appStartup().
@ NOTCONNECTED
The application is not connected to the device or service.
@ POWERON
The device power is on.
int ttyWriteRead(std::string &strRead, const std::string &strWrite, const std::string &eot, bool swallowEcho, int fd, int timeoutWrite, int timeoutRead)
Write to a tty on an open file descriptor, then get the result.
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.
#define INDI_VALIDATE_CALLBACK_PROPS(prop1, prop2)
Standard check for matching INDI properties in a callback.
const pcf::IndiProperty & ipRecv
updateIfChanged(m_indiP_angle, "target", m_angle)
std::unique_lock< std::mutex > lock(m_indiMutex)
static constexpr logPrioT LOG_CRITICAL
The process can not continue and will shut down (fatal)
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 setupConfig(appConfigurator &config)
Setup an application configurator for the device section.
int appStartup()
Starts the telemetry log thread.
Log entry recording position stage specific status.
Log entry recording stdMotionStage status.
A simple text log, a string-type log.
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