Instrument Neutral Distributed Interface INDI 2.2.5
ccd_simulator.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3 Copyright(c) 2010 Gerry Rozema. All rights reserved.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7 .
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12 .
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#pragma once
20
21#include <deque>
22#include <vector>
23#include <map>
24#include <string>
25
26#include <indiccd.h>
27#include "sky_renderer.h"
28#include "indifilterinterface.h"
29
50{
51 public:
52
53 enum
54 {
71 SIM_N
72 };
73
74 CCDSim();
75 virtual ~CCDSim() override = default;
76
77 const char *getDefaultName() override;
78
79 bool initProperties() override;
80 bool updateProperties() override;
81
82 void ISGetProperties(const char *dev) override;
83
84 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
85 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
86 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
87 virtual bool ISSnoopDevice(XMLEle *root) override;
88
89 static void *streamVideoHelper(void *context);
90 void *streamVideo();
91
92 protected:
93
94 bool Connect() override;
95 bool Disconnect() override;
96
97 bool StartExposure(float duration) override;
98 bool StartGuideExposure(float) override;
99
100 bool AbortExposure() override;
101 bool AbortGuideExposure() override;
102
103 void TimerHit() override;
104
105 int DrawCcdFrame(INDI::CCDChip *targetChip);
106
107 virtual IPState GuideNorth(uint32_t) override;
108 virtual IPState GuideSouth(uint32_t) override;
109 virtual IPState GuideEast(uint32_t) override;
110 virtual IPState GuideWest(uint32_t) override;
111
112 virtual bool saveConfigItems(FILE *fp) override;
113 virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector<INDI::FITSRecord> &fitsKeyword) override;
114 virtual void activeDevicesUpdated() override;
115 virtual int SetTemperature(double temperature) override;
116 virtual bool UpdateCCDFrame(int x, int y, int w, int h) override;
117 virtual bool UpdateCCDBin(int hor, int ver) override;
118 virtual bool UpdateGuiderBin(int hor, int ver) override;
119
120 virtual bool SetCaptureFormat(uint8_t index) override;
121
122 virtual bool StartStreaming() override;
123 virtual bool StopStreaming() override;
124
125 // Filter
126 bool SelectFilter(int) override;
127 int QueryFilter() override;
128
129 protected:
130
131 bool watchDirectory();
132 bool loadNextImage();
133 bool loadNextFITSImage(const std::string &filename);
134#ifdef HAVE_XISF
135 bool loadNextXISFImage(const std::string &filename);
136#endif
137 bool setupParameters();
138 bool renderPlanet();
139
140 // Turns on/off Bayer RGB simulation.
141 void setBayerEnabled(bool onOff);
142
143 float CalcTimeLeft(timeval start, float req);
144
146
147 // ADU ceiling and magnitude calibration -- updated from INDI properties each frame.
148 int m_MaxVal {65000};
149 float m_LimitingMag {11.5f};
150 float m_SaturationMag {2.0f};
151 float m_Seeing {3.5f}; // arcsec FWHM, updated by focus simulation
152
153 double TemperatureRequest { 0 };
154
155 float ExposureRequest { 0 };
156 struct timeval ExpStart
157 {
158 0, 0
159 };
160
162 struct timeval GuideExpStart
163 {
164 0, 0
165 };
166
167 int testvalue { 0 };
168 bool ShowStarField { true };
169 int m_Bias { 1500 };
170 int m_MaxNoise { 20 };
171 float m_SkyGlow { 40 };
172 // An oag is offset this much from center of scope position (arcminutes)
173 float m_OAGOffset { 0 };
174 float m_TimeFactor { 1 };
175 // With a rotator device "RotatorAngle" is snooped and defined, so the
176 // resulting camera rotation is the addition of offset and rotator angle.
177 // Without a rotator device ("Manual Rotator") the rotator angle is
178 // considered fixed to 0° and the camera rotation is equal to offset
179 float m_RotationOffset { 0 };
180
181 bool m_SimulateBayer { false };
182 bool m_SimulateTimeout { false };
183
184 // our zero point calcs used for drawing stars
185 //float k { 0 };
186 //float z { 0 };
187
188 bool AbortGuideFrame { false };
189 bool AbortPrimaryFrame { false };
190
192 float GuideRate { 7 };
193
195 float m_PEPeriod { 0 };
196 // PE max in arcsecs
197 float m_PEMax { 0 };
198
199 double currentRA { 0 };
200 double currentDE { 0 };
201 bool usePE { false };
202 double raPE { 0 }; // J2000 RA from snooped EQUATORIAL_PE (hours)
203 double decPE { 0 }; // J2000 Dec from snooped EQUATORIAL_PE (degrees)
204 time_t RunStart;
205
206 float guideNSOffset {0};
207 float guideWEOffset {0};
208
209 float m_PolarError { 0 };
210 float m_PolarDrift { 0 };
211
213
215 pthread_t primary_thread;
217
218 std::deque<std::string> m_AllFiles, m_RemainingFiles;
219
220 // And this lives in our simulator settings page
222
224 enum
225 {
229 };
230 // We are going to snoop these from focuser
233
234 // Focuser positions for focusing simulation
235 // FocuserPosition[0] is the position where the scope is in focus
236 // FocuserPosition[1] is the maximal position the focuser may move to (@see FOCUS_MAX in #indifocuserinterface.cpp)
237 // FocuserPosition[2] is the seeing (in arcsec)
238 // We need to have these values here, since we cannot snoop it from the focuser (the focuser does not
239 // publish these values)
241 enum
242 {
246 };
247
249 enum
250 {
253 };
254
256
258
260
262
265
267 inline static const std::vector<std::pair<uint32_t, uint32_t>> Resolutions =
268 {
269 {1280, 1024},
270 {6000, 4000},
271 {0, 0} // Custom
272 };
273
274 // ==================== Planet Simulation ====================
275
276 // Lookup table: average angular diameter at opposition (arcsec)
277 // Moon and Sun are mean apparent diameters
278 inline static const std::map<std::string, float> PlanetAngularDiameter =
279 {
280 {"mercury", 11.0f},
281 {"venus", 35.0f},
282 {"mars", 18.0f},
283 {"jupiter", 42.0f},
284 {"saturn", 42.0f}, // including rings
285 {"uranus", 3.7f},
286 {"neptune", 2.3f},
287 {"moon", 1860.0f}, // ~0.5°
288 {"sun", 1920.0f} // ~0.53°
289 };
290
291 // Planet mode toggle
293 enum
294 {
297 };
298
299 // Planet selection switch (one per body)
301 enum
302 {
312 };
313
314 // Planet refresh interval in minutes, and optional size override in arcsec (0 = use lookup table)
316 enum
317 {
320 };
321
322 // xplanet executable path and config file path
324 enum
325 {
328 };
329
330 // Planet simulation state
331 bool m_PlanetMode {false};
332 bool m_IsRGBFormat {false};
333 std::string m_SelectedPlanet {"jupiter"};
335 float m_PlanetSizeOverride {0.0f}; // 0 = use lookup table
336 std::string m_XPlanetBinary {"xplanet"};
337 std::string m_XPlanetConfig {"/usr/share/xplanet/config/default"};
340 std::vector<uint8_t> m_CachedPlanetBuffer;
341 std::vector<uint8_t> m_CachedStreamBuffer; // raw xplanet PNG bytes for direct streaming
346 uint32_t m_CachedWidth {0};
347 std::string m_CachedPlanet;
348
349 static const constexpr char* SIMULATOR_TAB = "Simulator Config";
350};
double temperature
The CCDSim class provides an advanced simulator for a CCD that includes a dedicated on-board guide ch...
virtual bool UpdateCCDFrame(int x, int y, int w, int h) override
CCD calls this function when CCD Frame dimension needs to be updated in the hardware....
bool m_IsRGBFormat
INDI::PropertyNumber TiltSimulationNP
float m_CachedPixelSizeX
bool m_SimulateBayer
double m_LastTemperature
uint32_t m_CachedPlanetHeight
bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
float guideWEOffset
void setBayerEnabled(bool onOff)
INDI::PropertyNumber FocusSimulationNP
bool StartExposure(float duration) override
Start exposing primary CCD chip.
@ SIM_SATURATION
@ SIM_LIMITINGMAG
@ SIM_TIME_FACTOR
@ SIM_PE_PERIOD
@ SIM_OAGOFFSET
@ SIM_POLARDRIFT
bool loadNextFITSImage(const std::string &filename)
virtual IPState GuideSouth(uint32_t) override
Guide southward for ms milliseconds.
INDI::PropertyText PlanetPathsTP
INDI::PropertyText DirectoryTP
INDI::PropertyNumber GainNP
bool ShowStarField
static const constexpr char * SIMULATOR_TAB
std::string m_XPlanetConfig
bool watchDirectory()
float GuideRate
Guide rate is 7 arcseconds per second.
bool AbortGuideFrame
float m_RotationOffset
bool Disconnect() override
Disconnect from device.
float m_SkyGlow
INDI::PropertyNumber EqPENP
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void * streamVideo()
float guideNSOffset
bool StartGuideExposure(float) override
Start exposing guide CCD chip.
std::vector< uint8_t > m_CachedPlanetBuffer
virtual bool SetCaptureFormat(uint8_t index) override
SetCaptureFormat Set Active Capture format.
INDI::PropertySwitch SimTestsSP
uint32_t m_CachedWidth
float m_PolarDrift
@ SIM_TESTS_TIMEOUT
@ SIM_TESTS_BAYER
@ SIM_TESTS_CRASH
pthread_t primary_thread
std::string m_XPlanetBinary
virtual ~CCDSim() override=default
float m_PEMax
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
@ PLANET_DISABLED
virtual int SetTemperature(double temperature) override
Set CCD temperature.
static const std::map< std::string, float > PlanetAngularDiameter
uint32_t m_CachedPlanetWidth
const char * getDefaultName() override
std::deque< std::string > m_AllFiles
INDI::PropertySwitch CoolerSP
virtual bool StartStreaming() override
StartStreaming Start live video streaming.
INDI::PropertyNumber SimulatorSettingsNP
static void * streamVideoHelper(void *context)
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
float m_PolarError
bool setupParameters()
float m_PlanetRefreshMinutes
SkyRenderer m_Renderer
virtual IPState GuideEast(uint32_t) override
Guide easward for ms milliseconds.
bool m_PlanetMode
time_t RunStart
float m_PlanetSizeOverride
double raPE
virtual IPState GuideWest(uint32_t) override
Guide westward for ms milliseconds.
float m_OAGOffset
bool renderPlanet()
int QueryFilter() override
Return current filter position.
INumber FWHMN[1]
virtual bool StopStreaming() override
StopStreaming Stop live video streaming.
float m_PEPeriod
PEPeriod in minutes.
bool SelectFilter(int) override
Select a new filter position.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
double currentDE
@ PLANET_XPLANET_PATH
@ PLANET_XPLANET_CONFIG
INDI::PropertyNumber OffsetNP
bool loadNextImage()
std::vector< uint8_t > m_CachedStreamBuffer
bool AbortPrimaryFrame
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool UpdateCCDBin(int hor, int ver) override
CCD calls this function when CCD Binning needs to be updated in the hardware. Derived classes should ...
int testvalue
float m_LimitingMag
static const std::vector< std::pair< uint32_t, uint32_t > > Resolutions
INDI::PropertySwitch ResolutionSP
INumberVectorProperty FWHMNP
std::string m_SelectedPlanet
virtual IPState GuideNorth(uint32_t) override
Guide northward for ms milliseconds.
bool AbortExposure() override
Abort ongoing exposure.
INDI::PropertyNumber PlanetSettingsNP
INDI::PropertySwitch PlanetSelectSP
bool m_SimulateTimeout
float m_CachedFocalLength
float m_TimeFactor
float m_SaturationMag
int streamPredicate
double decPE
std::string m_CachedPlanet
double TemperatureRequest
@ SIM_FOCUS_POSITION
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
INDI::PropertySwitch DirectorySP
virtual void activeDevicesUpdated() override
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
double currentRA
time_t m_LastPlanetRenderTime
float ExposureRequest
int m_MaxNoise
std::deque< std::string > m_RemainingFiles
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
INDI::PropertySwitch PlanetModeSP
bool terminateThread
float CalcTimeLeft(timeval start, float req)
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save configuration items in XML file.
virtual bool UpdateGuiderBin(int hor, int ver) override
CCD calls this function when Guide head binning is updated by the client. Derived classes should impl...
float m_Seeing
bool m_LastRenderWasCacheHit
float GuideExposureRequest
virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector< INDI::FITSRecord > &fitsKeyword) override
Generate FITS keywords that will be added to FIST/XISF file.
bool AbortGuideExposure() override
Abort ongoing exposure.
int DrawCcdFrame(INDI::CCDChip *targetChip)
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition indiccdchip.h:39
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition indiccd.h:108
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
One number descriptor.
Number vector property descriptor.
Definition indiapi.h:317