10 #define xt1121Ctrl_hpp
13 #include "../../libMagAOX/libMagAOX.hpp"
14 #include "../../magaox_git_version.h"
132 pcf::IndiProperty & ipToSet,
133 const pcf::IndiProperty &
ipRecv
176 config.add(
"device.address",
"",
"device.address", argType::Required,
"device",
"address",
true,
"string",
"The device I.P. address.");
177 config.add(
"device.port",
"",
"device.port", argType::Required,
"device",
"port",
true,
"int",
"The device port. Default is 502.");
178 config.add(
"device.powerOnWait",
"",
"device.powerOnWait", argType::Required,
"device",
"powerOnWait",
false,
"int",
"Time after power-on to begin attempting connections [sec]. Default is 2 sec.");
179 config.add(
"device.inputOnly",
"",
"device.inputOnly", argType::Required,
"device",
"inputOnly",
false,
"vector<int>",
"List of channels which are input-only.");
190 config(
m_port,
"device.port");
193 std::vector<int> ino;
194 config(ino,
"device.inputOnly");
196 for(
size_t i=0; i< ino.size();++i)
200 log<text_log>(
"Error setting channel " + std::to_string(i) +
" to input only.",
logPrio::LOG_ERROR);
317 std::string response;
335 log<text_log>(
"connect failed at " +
m_address +
":" + std::to_string(
m_port));
343 log<text_log>(
"connected to " +
m_address +
":" + std::to_string(
m_port));
359 return log<software_error,0>({__FILE__,__LINE__});
369 if(!
lock.owns_lock())
return 0;
472 catch(std::exception & e)
476 return log<
software_error,-1>({__FILE__, __LINE__, std::string(
"Exception caught: ") + e.what()});
508 pcf::IndiProperty & ipToSet,
509 const pcf::IndiProperty &
ipRecv
512 int current = -1, target = -1;
514 if(
ipRecv.find(
"current"))
516 current =
ipRecv[
"current"].get<
unsigned>();
521 target =
ipRecv[
"target"].get<
unsigned>();
524 if(target == -1) target = current;
526 if(target < 0)
return 0;
549 catch(std::exception & e)
553 return log<
software_error,-1>({__FILE__, __LINE__, std::string(
"Exception caught: ") + e.what()});
557 log<text_log>(
"Set channel " + std::to_string(chNo) +
" to " + std::to_string(target));
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.
unsigned long m_loopPause
int m_powerState
Current power state, 1=On, 0=Off, -1=Unk.
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.
virtual void setupConfig()
Setup the configuration system (called by MagAOXApp::setup())
pcf::IndiProperty m_indiP_ch11
virtual void loadConfig()
load the configuration system results (called by MagAOXApp::setup())
virtual int appLogic()
Implementation of the FSM for the Siglent SDG.
pcf::IndiProperty m_indiP_ch02
pcf::IndiProperty m_indiP_ch14
virtual int appStartup()
Startup functions.
~xt1121Ctrl() noexcept
Destructor.
virtual int appShutdown()
Do any needed shutdown tasks. Currently nothing in this app.
pcf::IndiProperty m_indiP_ch07
std::string m_address
The I.P. address of the device.
uint16_t m_port
The port to use. Default is 502 for modbus.
pcf::IndiProperty m_indiP_ch10
int getState()
Get the current state of the outlets.
pcf::IndiProperty m_indiP_ch00
pcf::IndiProperty m_indiP_ch08
pcf::IndiProperty m_indiP_ch06
pcf::IndiProperty m_indiP_ch15
int m_powerOnCounter
Counts numer of loops after power on, implements delay for camera bootup.
pcf::IndiProperty m_indiP_ch01
pcf::IndiProperty m_indiP_ch05
xt1121Ctrl()
Default c'tor.
pcf::IndiProperty m_indiP_ch09
virtual int whilePowerOff()
Implementation of the while-powered-off FSM.
modbus * m_mb
The modbus protocol communication object.
virtual int onPowerOff()
Implementation of the on-power-off FSM logic.
pcf::IndiProperty m_indiP_ch12
unsigned long m_powerOnWait
Time in sec to wait for device to boot after power on.
pcf::IndiProperty m_indiP_ch03
pcf::IndiProperty m_indiP_ch13
INDI_NEWCALLBACK_DECL(xt1121Ctrl, m_indiP_ch00)
pcf::IndiProperty m_indiP_ch04
int channelSetCallback(size_t chNo, pcf::IndiProperty &ipToSet, const pcf::IndiProperty &ipRecv)
Callback worker to actually set or clear a channel and send it to the device.
void modbus_read_input_registers(int address, int amount, uint16_t *buffer)
void modbus_set_slave_id(int id)
void modbus_write_registers(int address, int amount, uint16_t *value)
#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.
@ 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.
@ NOTCONNECTED
The application is not connected to the device or service.
@ POWERON
The device power is on.
INDI_VALIDATE_CALLBACK_PROPS(function, ipRecv)
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.
Software CRITICAL log entry.
Utility class for managing Acromag xt12XX digital I/O channels.
int setRegisters(uint16_t registers[numRegisters])
Set registers based on current channel states.
int setChannel(size_t chNo)
Set a channel to true.
static constexpr int numRegisters
The number of registers needed for the number of channels.
int channel(size_t chNo)
Gets the current state of a channel.
int setInputOnly(size_t chNo)
Set a channel to be input only.
int clearChannel(size_t chNo)
Set a channel to false.
int readRegisters(uint16_t registers[numRegisters])
Read channel states from the registers.
Utility class for managing Acromag xt12XX digital I/O channels.