10#include "../../libMagAOX/libMagAOX.hpp"
11#include "../../magaox_git_version.h"
13#include <mx/sigproc/circularBuffer.hpp>
14#include <mx/sigproc/signalWindows.hpp>
16#include <mx/math/ft/fftwEnvironment.hpp>
17#include <mx/math/ft/fftT.hpp>
59 typedef mx::sigproc::circularBufferIndex<realT *, cbIndexT>
ampCircBuffT;
110 mx::math::ft::fftT<realT, std::complex<realT>, 1, 0>
m_fft;
223 config.add(
"circBuff.fpsDevice",
225 "circBuff.fpsDevice",
231 "Device name for getting fps to set circular buffer length." );
232 config.add(
"circBuff.fpsProperty",
234 "circBuff.fpsProperty",
240 "Property name for getting fps to set circular buffer length. Default is 'fps'." );
241 config.add(
"circBuff.fpsElement",
243 "circBuff.fpsElement",
249 "Property name for getting fps to set circular buffer length. Default is 'current'." );
250 config.add(
"circBuff.fpsTol",
258 "Tolerance for detecting a change in FPS. Default is 0." );
259 config.add(
"circBuff.defaultFPS",
261 "circBuff.defaultFPS",
267 "Default FPS at startup, will enable changing average length with psdTime before INDI available." );
268 config.add(
"circBuff.psdTime",
276 "The length of time over which to calculate PSDs. The default is 1 sec." );
311 {
__FILE__,
__LINE__,
"FPS source is not configurated (circBuff.fpsDevice)" } );
389 static_cast<void>(
dummy );
409 mx::sys::microSleep( 100 );
476 mx::sigproc::window::hann(
m_win );
492 m_fftWork = mx::math::ft::fftw_malloc<std::complex<realT>>( (
m_tsSize / 2 + 1 ) );
525 for(
size_t n = 0;
n <
m_psd.size(); ++
n )
607 static_cast<void>(
dummy );
639 mx::sys::microSleep( 100 );
660 mx::sys::nanoSleep(
stime );
665 ampCircBuffT::indexT
ne0;
666 ampCircBuffT::indexT
mne0;
723 for(
size_t n = 0;
n <
m_psd.size(); ++
n )
730 for(
size_t n = 0;
n <
m_psd.size(); ++
n )
829 mx::sys::microSleep( 0.2 * 1000000.0 /
m_fps );
852 if( indiTargetUpdate( m_indiP_psdTime, target,
ipRecv,
true ) < 0 )
854 log<software_error>( { __FILE__, __LINE__ } );
858 if( m_psdTime != target )
860 std::lock_guard<std::mutex> guard( m_indiMutex );
867 shmimMonitorT::m_restart =
true;
881 if( indiTargetUpdate( m_indiP_psdAvgTime, target,
ipRecv,
true ) < 0 )
883 log<software_error>( { __FILE__, __LINE__ } );
887 if( m_psdAvgTime != target )
889 std::lock_guard<std::mutex> guard( m_indiMutex );
891 m_psdAvgTime = target;
896 log<text_log>(
"set psdAvgTime to " + std::to_string( m_psdAvgTime ),
logPrio::LOG_NOTICE );
906 if(
ipRecv.find( m_fpsElement ) !=
true )
908 log<software_error>( { __FILE__, __LINE__,
"No current property in fps source." } );
912 std::lock_guard<std::mutex> guard( m_indiMutex );
914 realT fps =
ipRecv[m_fpsElement].get<realT>();
916 if( fabs( fps - m_fps ) > m_fpsTol )
921 shmimMonitorT::m_restart =
true;
#define IMAGESTRUCT_FLOAT
#define XWCAPP_THREAD_CHECK(thrdSt, thrdName)
Error handling wrapper for checking on thread status with tryjoin.
#define XWCAPP_THREAD_START(thrdSt, thrdInit, thrdId, thrdProp, thrdPrio, thrdCpuset, thrdName, thrdStart)
Error handling wrapper for the threadStart function of the XWCApp.
#define XWCAPP_THREAD_STOP(thrdSt)
Error handlng wrapper for stopping a thread.
The base-class for MagAO-X applications.
std::string m_configName
The name of the configuration file (minus .conf).
stateCodes::stateCodeT state()
Get the current state code.
int shutdown()
Get the value of the shutdown flag.
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.
uint32_t m_depth
The depth of the circular buffer in the stream.
uint32_t m_width
The width of the images in the stream.
uint32_t m_height
The height of the images in the stream.
std::string m_shmimName
The name of the shared memory image, is used in /tmp/<shmimName>.im.shm. Derived classes should set a...
uint8_t m_dataType
The ImageStreamIO type code.
Class for application to calculate rolling PSDs of modal amplitudes.
realT m_psdOverlapFraction
The fraction of the sample time to overlap by.
pcf::IndiProperty m_psdThreadProp
The property to hold the PSD Calculation thread details.
pcf::IndiProperty m_indiP_psdAvgTime
INDI_NEWCALLBACK_DECL(modalPSDs, m_indiP_overSize)
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
pid_t m_psdThreadID
PSD Calculation thread PID.
mx::improc::eigenImage< realT > m_psdBuffer
std::string m_fpsElement
Element name for getting fps to set circular buffer length.
std::thread m_psdThread
The PSD Calculation thread.
pcf::IndiProperty m_indiP_overSize
std::complex< realT > * m_fftWork
INDI_NEWCALLBACK_DECL(modalPSDs, m_indiP_psdTime)
realT m_fpsTol
The tolerance for detecting a change in FPS.
static void psdThreadStart(modalPSDs *p)
PS Calculation thread starter function.
cbIndexT m_tsSize
The length of the time series sample over which the PSD is calculated.
std::vector< realT > m_win
The window function. By default this is Hann.
virtual int appStartup()
Startup function.
INDI_SETCALLBACK_DECL(modalPSDs, m_indiP_fpsSource)
INDI_NEWCALLBACK_DECL(modalPSDs, m_indiP_psdAvgTime)
IMAGE * m_avgpsdStream
The ImageStreamIO shared memory buffer to hold the average psds.
size_t m_nModes
the number of modes to calculate PSDs for.
IMAGE * m_rawpsdStream
The ImageStreamIO shared memory buffer to hold the raw psds.
mx::sigproc::circularBufferIndex< realT *, cbIndexT > ampCircBuffT
The amplitude circular buffer type.
mx::math::ft::fftwEnvironment< realT > m_fftEnv
modalPSDs()
Default c'tor.
virtual void loadConfig()
std::string m_fpsDevice
Device name for getting fps to set circular buffer length.
pcf::IndiProperty m_indiP_fps
virtual int appLogic()
Implementation of the FSM for modalPSDs.
cbIndexT m_meanSize
The length of the time series over which to calculate the mean.
int processImage(void *curr_src, const dev::shmimT &dummy)
IMAGE * m_freqStream
The ImageStreamIO shared memory buffer to hold the frequency scale.
mx::math::ft::fftT< realT, std::complex< realT >, 1, 0 > m_fft
realT m_psdAvgTime
The time over which to average PSDs. The default is 10 sec.
virtual void setupConfig()
ampCircBuffT m_ampCircBuff
int m_psdThreadPrio
Priority of the PSD Calculation thread.
std::string m_psdThreadCpuset
The cpuset to use for the PSD Calculation thread.
std::complex< realT > complexT
int allocate(const dev::shmimT &dummy)
int32_t cbIndexT
The index for the circular buffer.
cbIndexT m_tsOverlapSize
The number of samples in the overlap.
pcf::IndiProperty m_indiP_psdTime
pcf::IndiProperty m_indiP_fpsSource
realT m_psdTime
The length of time over which to calculate PSDs. The default is 1 sec.
void psdThreadExec()
PSD Calculation thread function.
bool m_psdThreadInit
Initialization flag for the PSD Calculation thread.
std::string m_fpsProperty
Property name for getting fps to set circular buffer length.
virtual int appShutdown()
Shutdown the app.
~modalPSDs() noexcept
D'tor, declared and defined for noexcept.
std::vector< realT > m_psd
dev::shmimMonitor< modalPSDs > shmimMonitorT
The base shmimMonitor type.
#define INDI_NEWCALLBACK_DEFN(class, prop)
Define the callback for a new property request.
#define CREATE_REG_INDI_NEW_NUMBERU(prop, name, min, max, step, format, label, group)
Create and register a NEW INDI property as a standard number as unsigned int, using the standard call...
#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.
#define CREATE_REG_INDI_RO_NUMBER(prop, name, label, group)
Create and register a RO INDI property as a number, 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
updateIfChanged(m_indiP_angle, "target", m_angle)
std::unique_lock< std::mutex > lock(m_indiMutex)
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.
static constexpr logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
#define SHMIMMONITOR_APP_SHUTDOWN
Call shmimMonitorT::appShutdown with error checking for shmimMonitor.
#define SHMIMMONITOR_APP_LOGIC
Call shmimMonitorT::appLogic with error checking for shmimMonitor.
#define SHMIMMONITOR_APP_STARTUP
Call shmimMonitorT::appStartup with error checking for shmimMonitor.
#define SHMIMMONITOR_LOAD_CONFIG(cfig)
Call shmimMonitorT::loadConfig with error checking for shmimMonitor.
#define SHMIMMONITOR_UPDATE_INDI
Call shmimMonitorT::updateINDI with error checking for shmimMonitor.
#define SHMIMMONITOR_SETUP_CONFIG(cfig)
Call shmimMonitorT::setupConfig with error checking for shmimMonitor.
Software CRITICAL log entry.