7#include "../../libMagAOX/libMagAOX.hpp"
8#include "../../magaox_git_version.h"
39 std::vector<double>
m_maxAmp = {1.2801, 1.2801, 1.0201};
243 const pcf::IndiProperty &
ipRecv
261 const pcf::IndiProperty &
ipRecv
279 const pcf::IndiProperty &
ipRecv
297 const pcf::IndiProperty &
ipRecv
315 const pcf::IndiProperty &
ipRecv
333 const pcf::IndiProperty &
ipRecv
352 const pcf::IndiProperty &
ipRecv
370 const pcf::IndiProperty &
ipRecv
454 config.add(
"device.address",
"a",
"device.address", argType::Required,
"device",
"address",
false,
"string",
"The device address.");
455 config.add(
"device.port",
"p",
"device.port", argType::Required,
"device",
"port",
false,
"string",
"The device port.");
457 config.add(
"timeouts.write",
"",
"timeouts.write", argType::Required,
"timeouts",
"write",
false,
"int",
"The timeout for writing to the device [msec]. Default = 1000");
458 config.add(
"timeouts.read",
"",
"timeouts.read", argType::Required,
"timeouts",
"read",
false,
"int",
"The timeout for reading the device [msec]. Default = 2000");
460 config.add(
"fxngen.C1outpOn",
"",
"fxngen.C1outpOn", argType::Required,
"fxngen",
"C1outpOn",
false,
"bool",
"Whether (true) or not (false) C1 output is enabled at startup. Only effective wavefrom is pulse. Default is false.");
461 config.add(
"fxngen.waveform",
"w",
"fxngen.waveform", argType::Required,
"fxngen",
"waveform",
false,
"string",
"The waveform to populate function.");
463 config.add(
"fxngen.C1ampDefault",
"",
"fxngen.C1ampDefault", argType::Required,
"fxngen",
"C1ampDefault",
false,
"float",
"C1 Default P2V Amplitude of waveform . Default = 0.0");
464 config.add(
"fxngen.C2ampDefault",
"",
"fxngen.C2ampDefault", argType::Required,
"fxngen",
"C2ampDefault",
false,
"float",
"C2 Default P2V Amplitude of waveform . Default = 0.0");
683 std::stringstream
logs;
694 std::stringstream
logs;
1005 const std::string & command
1015 std::cout <<
"writeRead return val was " <<
rv <<
"\n";
1070 const std::string & afterColon
1073 std::string command =
"C";
1074 command += mx::ioutils::convertToString<int>(channel);
1076 command += afterColon;
1285 rv =
parseBSWV(
resp_channel,
resp_wvtp,
resp_freq,
resp_peri,
resp_amp,
resp_ampvrms,
resp_ofst,
resp_hlev,
resp_llev,
resp_phse,
resp_wdth,
strRead );
1322 else if(channel == 2)
1446 else if(channel == 2)
1605 std::cerr <<
"Normalizing . . .";
1688 std::cerr <<
"Done\n";
1694 const std::string & newOutp
1725 if(channel == 1 &&
no ==
"ON")
1737 const pcf::IndiProperty &
ipRecv
1799 std::cerr <<
"Max Amp @ " <<
amp <<
" = " <<
m_maxAmp[
i] <<
" (freq)\n";
1820 std::string
afterColon =
"BSWV FRQ," + mx::ioutils::convertToString<double>(
newFreq);
1858 const pcf::IndiProperty &
ipRecv
1928 std::cerr <<
"Max Amp @ " << freq <<
" = " <<
maxAmp <<
"\n";
1955 std::string
afterColon =
"BSWV AMP," + mx::ioutils::convertToString<double>(
newAmp);
1975 const pcf::IndiProperty &
ipRecv
2041 std::string
afterColon =
"BSWV OFST," + mx::ioutils::convertToString<double>(
newOfst);
2059 const pcf::IndiProperty &
ipRecv
2103 std::string
afterColon =
"BSWV PHSE," + mx::ioutils::convertToString<double>(
newPhse);
2121 const pcf::IndiProperty &
ipRecv
2165 std::string
afterColon =
"BSWV WIDTH," + mx::ioutils::convertToString<double>(
newWdth);
2183 const pcf::IndiProperty &
ipRecv
2218 const std::string & newWvtp
2241 const pcf::IndiProperty &
ipRecv
2304 const pcf::IndiProperty &
ipRecv
2313 if(!
ipRecv.find(
"toggle"))
return 0;
2343 return changeOutp(1,
ipRecv);
2351 return changeFreq(1,
ipRecv);
2358 return changeAmp(1,
ipRecv);
2365 return changeOfst(1,
ipRecv);
2372 return changePhse(1,
ipRecv);
2379 return changeWdth(1,
ipRecv);
2386 return changeWvtp(1,
ipRecv);
2393 return changeSync(1,
ipRecv);
2400 return changeOutp(2,
ipRecv);
2407 return changeFreq(2,
ipRecv);
2414 return changeAmp(2,
ipRecv);
2421 return changeOfst(2,
ipRecv);
2428 return changePhse(2,
ipRecv);
2435 return changeWdth(2,
ipRecv);
2442 return changeWvtp(2,
ipRecv);
2449 return changeSync(2,
ipRecv);
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 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 createStandardIndiToggleSw(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 toggle element.
unsigned long m_loopPause
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.
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 m_powerTargetState
Current target power state, 1=On, 0=Off, -1=Unk.
static constexpr double cs_MaxVolts
int writeCommand(const std::string &commmand)
Write a command to the device.
int querySYNC(bool &sync, int channel)
Send the SYNC? query for a channel.
int writeRead(std::string &strRead, const std::string &command)
Write a command to the device and get the response. Not mutex-ed.
double m_C1ofst
The offset voltage of channel 1.
double m_C1vpp
The peak-2-peak voltage of channel 1.
int changePhse(int channel, double newPhse)
Send a change phase command to the device.
virtual int onPowerOff()
Implementation of the on-power-off FSM logic.
int queryOUTP(int channel)
Send the OUTP? query for a channel.
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C1outp)
int recordParams(bool force=false)
int querySWWV(std::string &state, int channel)
Send the SWWV? query and get the response state.
int checkSetup()
Check the setup is correct and safe for PI TTM control.
double m_bootDelay
Time in seconds it takes the device to boot.
tty::telnetConn m_telnetConn
The telnet connection manager.
double m_C1frequency
The output frequency of channel 1.
std::string m_devicePort
The device port.
uint8_t m_C2outp
The output status channel 2.
double m_C1vppDefault
default value for vpp of channel 1
virtual int appStartup()
Startup functions.
int changeAmp(int channel, double newAmp)
Send a change amplitude command to the device.
pcf::IndiProperty m_indiP_C2sync
pcf::IndiProperty m_indiP_C2wvtp
double m_C2phse
The phase of channel 2 (SINE only)
pcf::IndiProperty m_indiP_C2freq
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C1wvtp)
std::string m_C1wvtp
The wave type of channel 1.
int changeWdth(int channel, double newWdth)
Send a width command to the device.
double m_powerOnCounter
Counts the number of loops since power-on, used to control logging of connect failures.
~siglentSDG() noexcept
D'tor, declared and defined for noexcept.
virtual void loadConfig()
load the configuration system results (called by MagAOXApp::setup())
std::vector< double > m_maxAmp
int changeWvtp(int channel, const std::string &newWvtp)
Send a change wavetype command to the device.
static constexpr double cs_MaxOfst
pcf::IndiProperty m_indiP_C1amp
pcf::IndiProperty m_indiP_C2wdth
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C2phse)
pcf::IndiProperty m_indiP_status
pcf::IndiProperty m_indiP_C1peri
pcf::IndiProperty m_indiP_C2ofst
int queryMDWV(std::string &state, int channel)
Send the MDWV? query and get the response state.
double m_C2wdth
The width of channel 2 (PULSE only)
pcf::IndiProperty m_indiP_C2llev
double m_C2vppDefault
default value for vpp of channel 2
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C1sync)
pcf::IndiProperty m_indiP_C1ofst
virtual int whilePowerOff()
Implementation of the while-powered-off FSM.
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C1phse)
int changeOfst(int channel, double newOfst)
Send a change offset command to the device.
pcf::IndiProperty m_indiP_C2amp
pcf::IndiProperty m_indiP_C1wdth
pcf::IndiProperty m_indiP_C1wvtp
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C2sync)
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C2wdth)
int queryBSWV(int channel)
Send the BSWV? query for a channel.
pcf::IndiProperty m_indiP_C2peri
std::vector< double > m_maxFreq
pcf::IndiProperty m_indiP_C1freq
double m_C1phse
The phase of channel 1 (SINE only)
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C2outp)
double m_C2setVoltage
the set position voltage of Ch. 2.
virtual int appLogic()
Implementation of the FSM for the Siglent SDG.
pcf::IndiProperty m_indiP_C2ampvrms
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C2wvtp)
pcf::IndiProperty m_indiP_C1hlev
siglentSDG()
Default c'tor.
virtual void setupConfig()
Setup the configuration system (called by MagAOXApp::setup())
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C1amp)
std::string m_deviceAddr
The device address.
pcf::IndiProperty m_indiP_C2hlev
int changeSync(int channel, bool newSync)
Send a change sync command to the device.
pcf::IndiProperty m_indiP_C1phse
pcf::IndiProperty m_indiP_C1outp
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C1freq)
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C2ofst)
int changeOutp(int channel, const std::string &newOutp)
Change the output status (on/off) of one channel.
pcf::IndiProperty m_indiP_C2outp
int recordTelem(const telem_fxngen *)
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C2amp)
double m_C1wdth
The width of channel 1 (PULSE only)
int m_readTimeOut
The timeout for reading from the device [msec].
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C1wdth)
int queryARWV(int &index, int channel)
Send the ARWV? query and get the response index.
pcf::IndiProperty m_indiP_C1llev
double m_C2frequency
The output frequency of channel 2.
virtual int appShutdown()
Do any needed shutdown tasks. Currently nothing in this app.
int m_writeTimeOut
The timeout for writing to the device [msec].
int normalizeSetup()
Normalize the setup, called during connection if checkSetup shows a problem, or on power-up.
friend class siglentSDG_test
uint8_t m_C1outp
std::string m_clock; ///<INTernal or EXTernal
pcf::IndiProperty m_indiP_C2phse
int changeFreq(int channel, double newFreq)
Send a change frequency command to the device.
double m_C2vpp
The peak-2-peak voltage of channel 2.
double m_C2ofst
The offset voltage of channel 2.
double m_C1setVoltage
the set position voltage of Ch. 1.
std::string m_C2wvtp
The wave type of channel 2.
pcf::IndiProperty m_indiP_C1sync
int queryBTWV(std::string &state, int channel)
Send the BTWV? query and get the response state.
pcf::IndiProperty m_indiP_C1ampvrms
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C1ofst)
INDI_NEWCALLBACK_DECL(siglentSDG, m_indiP_C2freq)
#define INDI_NEWCALLBACK_DEFN(class, prop)
Define the callback for a new property request.
#define REG_INDI_NEWPROP_NOCB(prop, propName, type)
Register a NEW INDI property with the class, with no callback.
#define REG_INDI_NEWPROP(prop, propName, type)
Register a NEW INDI property with the class, using the standard callback name.
#define CREATE_REG_INDI_NEW_NUMBERF(prop, name, min, max, step, format, label, group)
Create and register a NEW INDI property as a standard number as float, using the standard callback na...
@ OPERATING
The device is operating, other than homing.
@ CONFIGURING
The application is configuring the device.
@ 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.
std::string ttyErrorString(int ec)
Get a text explanation of a TTY_E_ error code.
#define INDI_VALIDATE_CALLBACK_PROPS(prop1, prop2)
Standard check for matching INDI properties in a callback.
int parseOUTP(int &channel, int &output, const std::string &strRead)
Parse the SDG response to the OUTP query.
int parseSWWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the SWWV query.
int parseMDWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the MDWV query.
std::string makeCommand(int channel, const std::string &afterColon)
int parseBSWV(int &channel, std::string &wvtp, double &freq, double &peri, double &, double &vrms, double &ofst, double &hlev, double &llev, double &phse, double &wdth, const std::string &strRead)
Parse the SDG response to the BSWV query.
const pcf::IndiProperty & ipRecv
int parseBTWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the BTWV query.
int parseARWV(int &channel, int &index, const std::string &strRead)
Parse the SDG response to the ARWV query.
int parseSYNC(int &channel, bool &sync, const std::string &strRead)
Parse the SDG response to the SYNC query.
std::unique_lock< std::mutex > lock(m_indiMutex)
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.
static constexpr logPrioT LOG_CRITICAL
The process can not continue and will shut down (fatal)
static constexpr logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
static constexpr logPrioT LOG_ERROR
An error has occured which the software will attempt to correct.
#define SDG_PARSEERR_WVTP
A device base class which saves telemetry.
int appShutdown()
Perform telemeter application shutdown.
int loadConfig(appConfigurator &config)
Load the device section from an application configurator.
int setupConfig(appConfigurator &config)
Setup an application configurator for the device section.
int16_t stateCodeT
The type of the state code.
static std::string codeText(const stateCodeT &stateCode)
Get an ASCII string corresponding to an application stateCode.
Log entry recording the function generator parameters.
A Telnet connection manager, wrapping libtelnet.
int write(const std::string &buffWrite, int timeoutWrite)
Write to a telnet connection.
std::string m_strRead
The accumulated string read from the device.
int noLogin()
Set flags as if we're logged in, used when device doesn't require it.
std::string m_prompt
The device's prompt, used for detecting end of transmission.
int writeRead(const std::string &strWrite, bool swallowEcho, int timeoutWrite, int timeoutRead)
Write to a telnet connection, then get the reply.
int read(const std::string &eot, int timeoutRead, bool clear=true)
Read from a telnet connection, until end-of-transmission string is read.
int connect(const std::string &host, const std::string &port)
Connect to the device.
#define TELEM_FXNGEN_WVTP_DC
#define TELEM_FXNGEN_WVTP_PULSE
#define TELEM_FXNGEN_WVTP_SINE