API
 
Loading...
Searching...
No Matches
streamCircBuff.hpp
Go to the documentation of this file.
1/** \file streamCircBuff.hpp
2 * \brief The MagAO-X streamCircBuff app header file
3 *
4 * \ingroup streamCircBuff_files
5 */
6
7#ifndef streamCircBuff_hpp
8#define streamCircBuff_hpp
9
10
11#include "../../libMagAOX/libMagAOX.hpp" //Note this is included on command line to trigger pch
12#include "../../magaox_git_version.h"
13
14/** \defgroup streamCircBuff
15 * \brief An application to keep a circular buffer of a stream
16 *
17 * <a href="../handbook/operating/software/apps/streamCircBuff.html">Application Documentation</a>
18 *
19 * \ingroup apps
20 *
21 */
22
23/** \defgroup streamCircBuff_files
24 * \ingroup streamCircBuff
25 */
26
27namespace MagAOX
28{
29namespace app
30{
31
32/// Class for application to keep a circular buffer of a stream and publish it to another stream
33/**
34 * \ingroup streamCircBuff
35 */
36class streamCircBuff : public MagAOXApp<true>,
37 public dev::shmimMonitor<streamCircBuff>,
38 public dev::frameGrabber<streamCircBuff>,
39 public dev::telemeter<streamCircBuff>
40{
43 friend class dev::telemeter<streamCircBuff>;
44
45public:
46
47 /** \name app::dev Configurations
48 *@{
49 */
50
51 static constexpr bool c_frameGrabber_flippable = false; ///< app:dev config to tell framegrabber these images can not be flipped
52
53 ///@}
54
55 typedef float realT;
56
57 /// The base shmimMonitor type
59
60 /// The base frameGrabber type
62
63 /// The telemeter type
65
66
67protected:
68
69 /** \name Configurable Parameters
70 *@{
71 */
72 ///@}
73
74 char * m_currSrc {nullptr};
75
76 sem_t m_smSemaphore {0}; ///< Semaphore used to synchronize the fg thread and the sm thread.
77
78public:
79 /// Default c'tor.
81
82 /// D'tor, declared and defined for noexcept.
85
86 virtual void setupConfig();
87
88 /// Implementation of loadConfig logic, separated for testing.
89 /** This is called by loadConfig().
90 */
91 int loadConfigImpl( mx::app::appConfigurator & _config /**< [in] an application configuration from which to load values*/);
92
93 virtual void loadConfig();
94
95 /// Startup function
96 /**
97 *
98 */
99 virtual int appStartup();
100
101 /// Implementation of the FSM for streamCircBuff.
102 /**
103 * \returns 0 on no critical error
104 * \returns -1 on an error requiring shutdown
105 */
106 virtual int appLogic();
107
108 /// Shutdown the app.
109 /**
110 *
111 */
112 virtual int appShutdown();
113
114
115protected:
116
117 float (*pixget)(void *, size_t) {nullptr}; ///< Pointer to a function to extract the image data as float
118
119 //shmimMonitor Interface
120 int allocate( const dev::shmimT & dummy /**< [in] tag to differentiate shmimMonitor parents.*/);
121
123
124 int processImage( void * curr_src, ///< [in] pointer to start of current frame.
125 const dev::shmimT & dummy ///< [in] tag to differentiate shmimMonitor parents.
126 );
127
128 /** \name dev::frameGrabber interface
129 *
130 * @{
131 */
132
133 /// Implementation of the framegrabber configureAcquisition interface
134 /**
135 * \returns 0 on success
136 * \returns -1 on error
137 */
139
140 /// Implementation of the framegrabber fps interface
141 /**
142 * \todo this needs to infer the stream fps and return it
143 */
144 float fps()
145 {
146 return 1.0;
147 }
148
149 /// Implementation of the framegrabber startAcquisition interface
150 /**
151 * \returns 0 on success
152 * \returns -1 on error
153 */
154 int startAcquisition();
155
156 /// Implementation of the framegrabber acquireAndCheckValid interface
157 /**
158 * \returns 0 on success
159 * \returns -1 on error
160 */
162
163 /// Implementation of the framegrabber loadImageIntoStream interface
164 /**
165 * \returns 0 on success
166 * \returns -1 on error
167 */
168 int loadImageIntoStream( void * dest /**< [in] */);
169
170 /// Implementation of the framegrabber reconfig interface
171 /**
172 * \returns 0 on success
173 * \returns -1 on error
174 */
175 int reconfig();
176
177 /** \name Telemeter Interface
178 *
179 * @{
180 */
181 int checkRecordTimes();
182
183 int recordTelem( const telem_fgtimings * );
184
185 ///@}
186
187};
188
189streamCircBuff::streamCircBuff() : MagAOXApp(MAGAOX_CURRENT_SHA1, MAGAOX_REPO_MODIFIED)
190{
191
192 return;
193}
194
196{
198
200
202
203}
204
205int streamCircBuff::loadConfigImpl( mx::app::appConfigurator & _config )
206{
208
210
211 TELEMETER_LOAD_CONFIG(config);
212
213 return 0;
214}
215
217{
218 loadConfigImpl(config);
219}
220
222{
223 if(sem_init(&m_smSemaphore, 0,0) < 0)
224 {
225 log<software_critical>({__FILE__, __LINE__, errno,0, "Initializing S.M. semaphore"});
226 return -1;
227 }
228
230
232
234
236
237 return 0;
238}
239
241{
243
245
247
248 std::unique_lock<std::mutex> lock(m_indiMutex);
249
251
253
254 return 0;
255}
256
265
267{
268 static_cast<void>(dummy);
269
270 //we don't actually do anything here -- just a pass through to f.g.
271
273
274 m_reconfig = true;
275
276 return 0;
277}
278
279int streamCircBuff::processImage( void * curr_src,
280 const dev::shmimT & dummy
281 )
282{
283 static_cast<void>(dummy);
284
285 m_currSrc = static_cast<char *>(curr_src);
286
287 //Now tell the f.g. to get going
288 if(sem_post(&m_smSemaphore) < 0)
289 {
290 log<software_critical>({__FILE__, __LINE__, errno, 0, "Error posting to semaphore"});
291 return -1;
292 }
293
294 return 0;
295}
296
298{
299 std::unique_lock<std::mutex> lock(m_indiMutex);
300
301 ///\todo potential but verrrrry unlikely bug: shmimMonitorT could change these before allocate sets the lock above. Should use a local set of w/h instead.
303 {
304 //This means we haven't connected to the stream to accumulate. so wait.
305 lock.unlock(); //don't hold the lock for a whole second.
306 sleep(1);
307 return -1;
308 }
309
313
314 return 0;
315}
316
318{
319 return 0;
320}
321
323{
324 timespec ts;
325
327 {
328 log<software_critical>({__FILE__,__LINE__,errno,0,"clock_gettime"});
329 return -1;
330 }
331
332 ts.tv_sec += 1;
333
334 if(sem_timedwait(&m_smSemaphore, &ts) == 0)
335 {
337 return 0;
338 }
339 else
340 {
341 return 1;
342 }
343
344 if(m_currSrc == nullptr)
345 {
346 return 1;
347 }
348}
349
351{
352 if(m_currSrc == nullptr)
353 {
354 return -1;
355 }
356
357 float * fdest = reinterpret_cast<float *>(dest);
358
360 {
362 }
363
364 //memcpy(dest, m_currSrc, shmimMonitorT::m_width*shmimMonitorT::m_height*frameGrabberT::m_typeSize );
365 return 0;
366}
367
369{
370 return 0;
371}
372
377
379{
380 return recordFGTimings(true);
381}
382
383
384} //namespace app
385} //namespace MagAOX
386
387#endif //streamCircBuff_hpp
#define IMAGESTRUCT_FLOAT
The base-class for MagAO-X applications.
Definition MagAOXApp.hpp:73
stateCodes::stateCodeT state()
Get the current state code.
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.
timespec m_currImageTimestamp
The timestamp of the current image.
uint32_t m_width
The width of the image, once deinterlaced etc.
uint8_t m_dataType
The ImageStreamIO type code.
bool m_reconfig
Flag to set if a camera reconfiguration requires a framegrabber reset.
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.
uint8_t m_dataType
The ImageStreamIO type code.
Class for application to keep a circular buffer of a stream and publish it to another stream.
~streamCircBuff() noexcept
D'tor, declared and defined for noexcept.
dev::frameGrabber< streamCircBuff > frameGrabberT
The base frameGrabber type.
dev::shmimMonitor< streamCircBuff > shmimMonitorT
The base shmimMonitor type.
static constexpr bool c_frameGrabber_flippable
app:dev config to tell framegrabber these images can not be flipped
int acquireAndCheckValid()
Implementation of the framegrabber acquireAndCheckValid interface.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
virtual int appLogic()
Implementation of the FSM for streamCircBuff.
int allocate(const dev::shmimT &dummy)
Pointer to a function to extract the image data as float.
int processImage(void *curr_src, const dev::shmimT &dummy)
int loadImageIntoStream(void *dest)
Implementation of the framegrabber loadImageIntoStream interface.
dev::telemeter< streamCircBuff > telemeterT
The telemeter type.
int recordTelem(const telem_fgtimings *)
float(* pixget)(void *, size_t)
virtual int appShutdown()
Shutdown the app.
int configureAcquisition()
Implementation of the framegrabber configureAcquisition interface.
sem_t m_smSemaphore
Semaphore used to synchronize the fg thread and the sm thread.
int reconfig()
Implementation of the framegrabber reconfig interface.
int startAcquisition()
Implementation of the framegrabber startAcquisition interface.
virtual int appStartup()
Startup function.
float fps()
Implementation of the framegrabber fps interface.
#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.
@ OPERATING
The device is operating, other than homing.
std::unique_lock< std::mutex > lock(m_indiMutex)
Definition dm.hpp:26
#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.
A device base class which saves telemetry.
Definition telemeter.hpp:69
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
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.