15 #include "../../libMagAOX/libMagAOX.hpp"
16 #include "../../magaox_git_version.h"
104 const std::string & com
149 static_cast<void>(_config);
165 log<software_error>({__FILE__, __LINE__,
"error setting timeouts"});
169 createStandardIndiNumber<float>(
m_indiP_windspeed,
"windspeed", -60, 60, 0.0,
"%f");
207 log<software_error>({__FILE__, __LINE__,
"error in fnPerformaxComGetNumDevices"});
215 log<text_log>(
"ACE-SXE not found");
228 elevatedPrivileges elPriv(
this);
233 log<software_error>({__FILE__, __LINE__,
"error acquiring product serial number"});
236 lpDeviceString[
sizeof(lpDeviceString) - 1] =
'\0';
238 std::string serial = lpDeviceString;
243 log<software_error>({__FILE__, __LINE__,
"errovr acquiring product description"});
246 lpDeviceString[
sizeof(lpDeviceString) - 1] =
'\0';
248 std::string descrip = lpDeviceString;
250 log<text_log>(
"found ACE-SXE: " + descrip +
" " + serial);
266 log<software_error>({__FILE__, __LINE__,
"error closing existing handle"});
273 elevatedPrivileges elPriv(
this);
278 log<software_error>({__FILE__, __LINE__,
"error closing existing handle"});
287 log<software_error>({__FILE__, __LINE__,
"error flushing"});
295 strncpy(out,
"ID",
sizeof(out));
299 log<software_error>({__FILE__, __LINE__,
"error getting ID"});
303 in[
sizeof(in)-1] =
'\0';
306 strncpy(out,
"DN",
sizeof(out));
310 log<software_error>({__FILE__, __LINE__,
"error getting DN"});
318 log<text_log>(
"connected to ACE-SXE " +
id +
" " + dn);
333 log<software_error>({__FILE__,__LINE__});
337 log<text_log>(
"EDIO=" + resp);
342 log<software_error>({__FILE__,__LINE__});
346 log<text_log>(
"POL=" + resp);
351 log<software_error>({__FILE__,__LINE__});
355 log<text_log>(
"ACC=" + resp);
360 log<software_error>({__FILE__,__LINE__});
367 log<software_error>({__FILE__, __LINE__,
"not OK from LSPD="});
371 log<text_log>(
"set LSPD=" + std::to_string(
m_lspd) );
376 log<software_error>({__FILE__,__LINE__});
385 log<software_error>({__FILE__,__LINE__});
390 int mst = stoi(resp);
419 log<software_error>({__FILE__,__LINE__});
424 int mst = stoi(smst);
436 log<software_error>({__FILE__,__LINE__,
"bad state"});
453 strncpy(out, com.c_str(),
sizeof(out)-1);
457 log<software_error>({__FILE__, __LINE__, std::string(
"error getting ") + out});
461 in[
sizeof(in)-1] =
'\0';
480 log<software_error>({__FILE__,__LINE__});
487 log<software_error>({__FILE__, __LINE__,
"not OK from HSPD="});
495 log<software_error>({__FILE__,__LINE__});
502 log<text_log>(
"set HSPD to " + std::to_string(
m_hspd));
530 float ll =
m_lspd/9600.*60. * (12.7/12.0);
531 if(ws <= 0 && ws > -ll)
536 if(ws >= 0 && ws < ll)
542 int h = (12.0/12.7) / 60. * 9600 * fabs(ws);
547 log<software_error>({__FILE__,__LINE__});
552 log<text_log>(
"set wind speed to " + std::to_string(
windSpeed()));
565 std::string com =
"EO=1";
570 log<software_error>({__FILE__,__LINE__});
577 log<software_error>({__FILE__, __LINE__,
"not OK from " + com});
589 log<software_error>({__FILE__,__LINE__});
596 log<software_error>({__FILE__, __LINE__,
"not OK from " + com});
613 log<software_error>({__FILE__,__LINE__});
620 log<software_error>({__FILE__, __LINE__,
"not OK from STOP"});
625 std::string com =
"EO=0";
630 log<software_error>({__FILE__,__LINE__});
637 log<software_error>({__FILE__, __LINE__,
"not OK from " + com});
654 log<software_error>({__FILE__,__LINE__});
661 log<software_error>({__FILE__, __LINE__,
"not OK from ABORT"});
666 std::string com =
"EO=0";
671 log<software_error>({__FILE__,__LINE__});
678 log<software_error>({__FILE__, __LINE__,
"not OK from " + com});
693 if(
ipRecv.find(
"current"))
695 ws =
ipRecv[
"current"].get<
double>();
700 ws =
ipRecv[
"target"].get<
double>();
703 if(ws == 0)
return 0;
705 std::lock_guard<std::mutex> guard(m_indiMutex);
709 return windSpeed(ws);
719 if(!
ipRecv.find(
"request"))
return 0;
721 std::unique_lock<std::mutex>
lock(m_indiMutex);
723 if(
ipRecv[
"request"].getSwitchState() == pcf::IndiElement::On)
735 if(!
ipRecv.find(
"request"))
return 0;
737 std::unique_lock<std::mutex>
lock(m_indiMutex);
739 if(
ipRecv[
"request"].getSwitchState() == pcf::IndiElement::On)
751 if(!
ipRecv.find(
"request"))
return 0;
753 std::unique_lock<std::mutex>
lock(m_indiMutex);
755 if(
ipRecv[
"request"].getSwitchState() == pcf::IndiElement::On)
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.
int createStandardIndiRequestSw(pcf::IndiProperty &prop, const std::string &name, const std::string &label="", const std::string &group="")
Create a standard R/W INDI switch with a single request element.
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_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,...
std::mutex m_indiMutex
Mutex for locking INDI communications.
int m_powerTargetState
Current target power state, 1=On, 0=Off, -1=Unk.
virtual void loadConfig()
int sendRecv(std::string &sout, const std::string &com)
virtual int appStartup()
Startup function.
virtual void setupConfig()
pcf::IndiProperty m_indiP_start
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
INDI_NEWCALLBACK_DECL(acesxeCtrl, m_indiP_windspeed)
friend class acesxeCtrl_test
pcf::IndiProperty m_indiP_windspeed
virtual int appLogic()
Implementation of the FSM for acesxeCtrl.
acesxeCtrl()
Default c'tor.
~acesxeCtrl() noexcept
D'tor, declared and defined for noexcept.
INDI_NEWCALLBACK_DECL(acesxeCtrl, m_indiP_start)
pcf::IndiProperty m_indiP_abort
virtual int appShutdown()
Shutdown the app.
pcf::IndiProperty m_indiP_stop
INDI_NEWCALLBACK_DECL(acesxeCtrl, m_indiP_abort)
INDI_NEWCALLBACK_DECL(acesxeCtrl, m_indiP_stop)
#define INDI_NEWCALLBACK(prop)
Get the name of the static callback wrapper for a new property.
@ OPERATING
The device is operating, other than homing.
@ POWEROFF
The device power is off.
@ NODEVICE
No device exists for the application to control.
@ 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
updateIfChanged(m_indiP_angle, "target", m_angle)
INDI_NEWCALLBACK_DEFN(acesxeCtrl, m_indiP_windspeed)(const pcf
std::unique_lock< std::mutex > lock(m_indiMutex)
constexpr static logPrioT LOG_CRITICAL
The process can not continue and will shut down (fatal)
constexpr static logPrioT LOG_NOTICE
A normal but significant condition.