11#include <shared_mutex>
13#include "../../libMagAOX/libMagAOX.hpp"
14#include "../../magaox_git_version.h"
16#include <mx/sigproc/circularBuffer.hpp>
40 return "gainFactShmim";
53 return "multFactShmim";
66 return "pcGainFactShmim";
79 return "pcMultFactShmim";
105 return "bcoeffShmim";
118 return "modevalShmim";
432 config.add(
"circBuff.fpsDevice",
434 "circBuff.fpsDevice",
440 "Device name for getting fps to set circular buffer length." );
441 config.add(
"circBuff.fpsProperty",
443 "circBuff.fpsProperty",
449 "Property name for getting fps to set circular buffer length. Default is 'fps'." );
450 config.add(
"circBuff.fpsElement",
452 "circBuff.fpsElement",
458 "Property name for getting fps to set circular buffer length. Default is 'current'." );
459 config.add(
"circBuff.fpsTol",
467 "Tolerance for detecting a change in FPS. Default is 0." );
469 config.add(
"loop.number",
477 "The number of the loop. Used to set shmim names, as in aolN_mgainfact. Default is 1." );
479 config.add(
"loop.name",
487 "The name of the loop control INDI device name. Default is \"ho\"." );
575 {
__FILE__,
__LINE__,
"FPS source is not configurated (circBuff.fpsDevice)" } );
658 static_cast<void>(
dummy );
680 static_cast<void>(
dummy );
693 static_cast<void>(
dummy );
715 static_cast<void>(
dummy );
728 static_cast<void>(
dummy );
750 static_cast<void>(
dummy );
763 static_cast<void>(
dummy );
785 static_cast<void>(
dummy );
798 static_cast<void>(
dummy );
804 if( w - 1 !=
m_as.rows() || h !=
m_as.cols() || h !=
m_Na.size() )
809 m_as.resize( w - 1, h );
819 static_cast<void>(
dummy );
835 std::cerr <<
"Got pc a-coeffs. Mode 0 has " <<
m_Na[0] <<
'\n';
842 static_cast<void>(
dummy );
848 if( w - 1 !=
m_bs.rows() || h !=
m_bs.cols() || h !=
m_Nb.size() )
853 m_bs.resize( w - 1, h );
858 std::cerr <<
"Got pc b-coeffs. Mode 0 has " <<
m_Nb[0] <<
'\n';
865 static_cast<void>(
dummy );
885 static_cast<void>(
dummy );
910 static_cast<void>(
dummy );
914 float *
F =
reinterpret_cast<float *
>(
curr_src );
1007 for(
int c = 0;
c <
m_Na[mode]; ++
c)
1012 for(
int c = 0;
c <
m_Nb[mode]; ++
c)
1094 if(
ipRecv.find( m_fpsElement ) !=
true )
1096 log<software_error>( { __FILE__, __LINE__,
"No current property in fps source." } );
1100 std::lock_guard<std::mutex> guard( m_indiMutex );
1102 float fps =
ipRecv[m_fpsElement].get<
float>();
1104 if( fabs( fps - m_fps ) > m_fpsTol )
1108 frameGrabberT::m_reconfig =
true;
1119 if(
ipRecv.find(
"toggle" ) )
1121 if(
ipRecv[
"toggle"].getSwitchState() == pcf::IndiElement::On )
1147 if( indiTargetUpdate( m_indiP_gain, target,
ipRecv,
true ) < 0 )
1149 log<software_error>( { __FILE__, __LINE__ } );
1155 std::cerr <<
"Got global gain: " << m_gain <<
'\n';
1165 if( indiTargetUpdate( m_indiP_mult, target,
ipRecv,
true ) < 0 )
1167 log<software_error>( { __FILE__, __LINE__ } );
1173 std::cerr <<
"Got global mc: " << m_mc <<
'\n';
1183 if( indiTargetUpdate( m_indiP_pcGain, target,
ipRecv,
true ) < 0 )
1185 log<software_error>( { __FILE__, __LINE__ } );
1191 std::cerr <<
"Got global pc gain: " << m_pcGain <<
'\n';
1200 if( indiTargetUpdate( m_indiP_pcMult, target,
ipRecv,
true ) < 0 )
1202 log<software_error>( { __FILE__, __LINE__ } );
1208 std::cerr <<
"Got global pc mc: " << m_mc <<
'\n';
1217 if(
ipRecv.find(
"toggle" ) )
1219 if(
ipRecv[
"toggle"].getSwitchState() == pcf::IndiElement::On )
The base-class for MagAO-X applications.
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.
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.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
timespec m_currImageTimestamp
The timestamp of the current image.
uint32_t m_width
The width of the image, once deinterlaced etc.
int recordFGTimings(bool force=false)
uint8_t m_dataType
The ImageStreamIO type code.
uint32_t m_height
The height of the image, once deinterlaced etc.
uint32_t m_width
The width of the images in the stream.
uint32_t m_height
The height of the images in the stream.
The MagAO-X modal filter.
virtual int appLogic()
Implementation of the FSM for modalFilter.
int recordTelem(const telem_fgtimings *)
pcf::IndiProperty m_indiP_fpsSource
std::string m_fpsDevice
Device name for getting fps to set circular buffer length.
INDI_NEWCALLBACK_DECL(modalFilter, m_indiP_mult)
INDI_SETCALLBACK_DECL(modalFilter, m_indiP_fpsSource)
pcf::IndiProperty m_indiP_mult
int acquireAndCheckValid()
Implementation of the framegrabber acquireAndCheckValid interface.
std::vector< float > m_pcGainfacts
virtual void loadConfig()
pcf::IndiProperty m_indiP_pcMult
dev::shmimMonitor< modalFilter, acoeffShmimT > acoeffShmimMonitorT
sem_t m_filtSem
Semaphore used to signal that fresh modevals are waiting to be filtered.
float fps()
Implementation of the frameGrabber fps interface.
pcf::IndiProperty m_indiP_pcOn
~modalFilter() noexcept
D'tor, declared and defined for noexcept.
int loadImageIntoStream(void *dest)
Implementation of the framegrabber loadImageIntoStream interface.
INDI_NEWCALLBACK_DECL(modalFilter, m_indiP_pcMult)
dev::shmimMonitor< modalFilter, modevalShmimT > modevalShmimMonitorT
std::shared_mutex m_filtMutex
Mutex for locking access to filter parameters.
int allocate(const gainFactShmimT &)
std::string m_loopName
The name of the loop control INDI device name. Defalt is "ho".
dev::telemeter< modalFilter > telemeterT
int32_t m_modevalCBLength
The length of the modeval circular buffers. Default is 1000 entries.
dev::frameGrabber< modalFilter > frameGrabberT
INDI_NEWCALLBACK_DECL(modalFilter, m_indiP_loop)
virtual void setupConfig()
mx::sigproc::circularBufferIndex< std::vector< float >, int32_t > m_modevalDM
int startAcquisition()
Implementation of the framegrabber startAcquisition interface.
virtual int appStartup()
Startup function.
static constexpr bool c_frameGrabber_flippable
dev::shmimMonitor< modalFilter, pcMultFactShmimT > pcMultFactShmimMonitorT
friend class modalFilter_test
pcf::IndiProperty m_indiP_gain
INDI_NEWCALLBACK_DECL(modalFilter, m_indiP_pcOn)
pcf::IndiProperty m_indiP_pcGain
mx::sigproc::circularBufferIndex< std::vector< float >, int32_t > m_modevalWFS
virtual int appShutdown()
Shutdown the app.
dev::shmimMonitor< modalFilter, gainFactShmimT > gainFactShmimMonitorT
dev::shmimMonitor< modalFilter, multFactShmimT > multFactShmimMonitorT
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
INDI_NEWCALLBACK_DECL(modalFilter, m_indiP_pcGain)
INDI_NEWCALLBACK_DECL(modalFilter, m_indiP_gain)
float m_fpsTol
The tolerance for detecting a change in FPS.
std::vector< float > m_pcMultfacts
std::string m_fpsElement
Element name for getting fps to set circular buffer length.
dev::shmimMonitor< modalFilter, pcGainFactShmimT > pcGainFactShmimMonitorT
pcf::IndiProperty m_indiP_loop
std::vector< float > m_gainfacts
timespec m_atime
The acq time of the WFS modevals.
int reconfig()
Implementation of the framegrabber reconfig interface.
int configureAcquisition()
Implementation of the framegrabber configureAcquisition interface.
int processImage(void *curr_src, const gainFactShmimT &)
dev::shmimMonitor< modalFilter, bcoeffShmimT > bcoeffShmimMonitorT
std::string m_fpsProperty
Property name for getting fps to set circular buffer length.
bool m_sizesMatch
Flag indicating that all sizes are consistent.
std::vector< float > m_multfacts
int m_loopNum
The number of the loop. Used to set shmim names, as in aolN_mgainfact. Default is 1.
bool m_pcSizesMatch
Flag indicating that all sizes are consistent.
modalFilter()
Default c'tor.
#define FRAMEGRABBER_SETUP_CONFIG(cfig)
Call frameGrabberT::setupConfig with error checking for frameGrabber.
#define FRAMEGRABBER_APP_LOGIC
Call frameGrabberT::appLogic with error checking for frameGrabber.
#define FRAMEGRABBER_APP_SHUTDOWN
Call frameGrabberT::appShutdown with error checking for frameGrabber.
#define FRAMEGRABBER_UPDATE_INDI
Call frameGrabberT::updateINDI with error checking for frameGrabber.
#define FRAMEGRABBER_LOAD_CONFIG(cfig)
Call frameGrabberT::loadConfig with error checking for frameGrabber.
#define FRAMEGRABBER_APP_STARTUP
Call frameGrabberT::appStartup with error checking for frameGrabber.
#define INDI_NEWCALLBACK_DEFN(class, prop)
Define the callback for a new property request.
#define CREATE_REG_INDI_NEW_TOGGLESWITCH(prop, name)
Create and register a NEW INDI property as a standard toggle switch, 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...
#define INDI_SETCALLBACK_DEFN(class, prop)
Define the callback for a set property request.
#define REG_INDI_SETPROP(prop, devName, propName)
Register a SET INDI property with the class, using the standard callback name.
@ OPERATING
The device is operating, other than homing.
#define INDI_VALIDATE_CALLBACK_PROPS(prop1, prop2)
Standard check for matching INDI properties in a callback.
const pcf::IndiProperty & ipRecv
std::unique_lock< std::mutex > lock(m_indiMutex)
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.
#define XWC_SEM_WAIT_TS(ts, sec, nsec)
Add the wait time to a timespec for a sem_timedwait call, with -1 returned on error.
#define SHMIMMONITORT_APP_STARTUP(SHMIMMONITORT)
Call shmimMonitorT::appStartup with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITORT_UPDATE_INDI(SHMIMMONITORT)
Call shmimMonitorT::updateINDI with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITORT_SETUP_CONFIG(SHMIMMONITORT, cfig)
Call shmimMonitorT::setupConfig with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITORT_APP_LOGIC(SHMIMMONITORT)
Call shmimMonitorT::appLogic with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITORT_APP_SHUTDOWN(SHMIMMONITORT)
Call shmimMonitorT::appShutodwn with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITORT_LOAD_CONFIG(SHMIMMONITORT, cfig)
Call shmimMonitorT::loadConfig with error checking for a typedef-ed shmimMonitor.
static std::string configSection()
static std::string indiPrefix()
static std::string indiPrefix()
static std::string configSection()
A device base class which saves telemetry.
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
static std::string configSection()
static std::string indiPrefix()
static std::string indiPrefix()
static std::string configSection()
static std::string configSection()
static std::string indiPrefix()
static std::string configSection()
static std::string indiPrefix()
static std::string indiPrefix()
static std::string configSection()
Software CRITICAL log entry.
Log entry recording framegrabber timings.
#define TELEMETER_APP_LOGIC
Call telemeter::appLogic with error checking.
#define TELEMETER_LOAD_CONFIG(cfig)
Call telemeter::loadConfig with error checking.
#define TELEMETER_APP_STARTUP
Call telemeter::appStartup with error checking.
#define TELEMETER_SETUP_CONFIG(cfig)
Call telemeter::setupConfig with error checking.
#define TELEMETER_APP_SHUTDOWN
Call telemeter::appShutdown with error checking.