Instrument Neutral Distributed Interface INDI  2.0.2
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 
23 #include "indiccd.h"
24 #include "indifilterinterface.h"
25 
42 class CCDSim : public INDI::CCD, public INDI::FilterInterface
43 {
44  public:
45 
46  enum
47  {
64  SIM_N
65  };
66 
67  CCDSim();
68  virtual ~CCDSim() override = default;
69 
70  const char *getDefaultName() override;
71 
72  bool initProperties() override;
73  bool updateProperties() override;
74 
75  void ISGetProperties(const char *dev) override;
76 
77  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
78  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
79  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
80  virtual bool ISSnoopDevice(XMLEle *root) override;
81 
82  static void *streamVideoHelper(void *context);
83  void *streamVideo();
84 
85  protected:
86 
87  bool Connect() override;
88  bool Disconnect() override;
89 
90  bool StartExposure(float duration) override;
91  bool StartGuideExposure(float) override;
92 
93  bool AbortExposure() override;
94  bool AbortGuideExposure() override;
95 
96  void TimerHit() override;
97 
98  int DrawCcdFrame(INDI::CCDChip *targetChip);
99 
100  int DrawImageStar(INDI::CCDChip *targetChip, float, float, float, float ExposureTime);
101  int AddToPixel(INDI::CCDChip *targetChip, int, int, int);
102 
103  virtual IPState GuideNorth(uint32_t) override;
104  virtual IPState GuideSouth(uint32_t) override;
105  virtual IPState GuideEast(uint32_t) override;
106  virtual IPState GuideWest(uint32_t) override;
107 
108  virtual bool saveConfigItems(FILE *fp) override;
109  virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector<INDI::FITSRecord> &fitsKeyword) override;
110  virtual void activeDevicesUpdated() override;
111  virtual int SetTemperature(double temperature) override;
112  virtual bool UpdateCCDFrame(int x, int y, int w, int h) override;
113  virtual bool UpdateCCDBin(int hor, int ver) override;
114  virtual bool UpdateGuiderBin(int hor, int ver) override;
115 
116  virtual bool SetCaptureFormat(uint8_t index) override;
117 
118  virtual bool StartStreaming() override;
119  virtual bool StopStreaming() override;
120 
121  // Filter
122  bool SelectFilter(int) override;
123  int QueryFilter() override;
124 
125  protected:
126 
127  float CalcTimeLeft(timeval, float);
128  bool loadNextImage();
129  bool setupParameters();
130 
131  // Turns on/off Bayer RGB simulation.
132  void setBayerEnabled(bool onOff);
133 
134  double flux(double magnitude) const;
135 
136  double TemperatureRequest { 0 };
137 
138  float ExposureRequest { 0 };
139  struct timeval ExpStart
140  {
141  0, 0
142  };
143 
144  float GuideExposureRequest { 0 };
145  struct timeval GuideExpStart
146  {
147  0, 0
148  };
149 
150  int testvalue { 0 };
151  bool ShowStarField { true };
152  int m_Bias { 1500 };
153  int m_MaxNoise { 20 };
154  int m_MaxVal { 65000 };
155  int maxpix { 0 };
156  int minpix { 65000 };
157  float m_SkyGlow { 40 };
158  float m_LimitingMag { 11.5 };
159  float m_SaturationMag { 2 };
160  float seeing { 3.5 };
161  float ImageScalex { 1.0 };
162  float ImageScaley { 1.0 };
163  // An oag is offset this much from center of scope position (arcminutes)
164  float m_OAGOffset { 0 };
165  float m_RotationCW { 0 };
166  float m_TimeFactor { 1 };
167 
168  bool m_SimulateBayer { false };
169 
170  // our zero point calcs used for drawing stars
171  //float k { 0 };
172  //float z { 0 };
173 
174  bool AbortGuideFrame { false };
175  bool AbortPrimaryFrame { false };
176 
178  float GuideRate { 7 };
179 
181  float m_PEPeriod { 0 };
182  // PE max in arcsecs
183  float m_PEMax { 0 };
184 
185  double currentRA { 0 };
186  double currentDE { 0 };
187  bool usePE { false };
188  time_t RunStart;
189 
190  float guideNSOffset {0};
191  float guideWEOffset {0};
192 
193  float m_PolarError { 0 };
194  float m_PolarDrift { 0 };
195 
196  double m_LastTemperature {0};
197 
199  pthread_t primary_thread;
201 
202  std::deque<std::string> m_AllFiles, m_RemainingFiles;
203 
204  // And this lives in our simulator settings page
207 
210 
211  // We are going to snoop these from focuser
214 
215  // Focuser positions for focusing simulation
216  // FocuserPosition[0] is the position where the scope is in focus
217  // FocuserPosition[1] is the maximal position the focuser may move to (@see FOCUS_MAX in #indifocuserinterface.cpp)
218  // FocuserPosition[2] is the seeing (in arcsec)
219  // We need to have these values here, since we cannot snoop it from the focuser (the focuser does not
220  // publish these values)
223 
226 
229 
232 
235 
238 
241 
244 
245  static const constexpr char* SIMULATOR_TAB = "Simulator Config";
246 };
The CCDSim class provides an advanced simulator for a CCD that includes a dedicated on-board guide ch...
Definition: ccd_simulator.h:43
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....
@ SIM_PE_MAX
Definition: ccd_simulator.h:61
@ SIM_SATURATION
Definition: ccd_simulator.h:53
@ SIM_LIMITINGMAG
Definition: ccd_simulator.h:54
@ SIM_MAXVAL
Definition: ccd_simulator.h:52
@ SIM_SKYGLOW
Definition: ccd_simulator.h:56
@ SIM_ROTATION
Definition: ccd_simulator.h:63
@ SIM_TIME_FACTOR
Definition: ccd_simulator.h:62
@ SIM_PE_PERIOD
Definition: ccd_simulator.h:60
@ SIM_OAGOFFSET
Definition: ccd_simulator.h:57
@ SIM_POLARDRIFT
Definition: ccd_simulator.h:59
int maxpix
bool m_SimulateBayer
double m_LastTemperature
ISwitch CoolerS[2]
ISwitchVectorProperty CoolerSP
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
float guideWEOffset
void setBayerEnabled(bool onOff)
bool StartExposure(float duration) override
Start exposing primary CCD chip.
virtual IPState GuideSouth(uint32_t) override
Guide southward for ms milliseconds.
INumberVectorProperty OffsetNP
float ImageScalex
float m_RotationCW
bool ShowStarField
int m_Bias
float GuideRate
Guide rate is 7 arcseconds per second.
bool AbortGuideFrame
bool Disconnect() override
Disconnect from device.
float m_SkyGlow
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 seeing
float guideNSOffset
bool StartGuideExposure(float) override
Start exposing guide CCD chip.
virtual bool SetCaptureFormat(uint8_t index) override
SetCaptureFormat Set Active Capture format.
float m_PolarDrift
pthread_t primary_thread
INumber EqPEN[2]
INumber FocusSimulationN[3]
int AddToPixel(INDI::CCDChip *targetChip, int, int, int)
int DrawImageStar(INDI::CCDChip *targetChip, float, float, float, float ExposureTime)
virtual ~CCDSim() override=default
int m_MaxVal
float m_PEMax
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual int SetTemperature(double temperature) override
Set CCD temperature.
const char * getDefaultName() override
std::deque< std::string > m_AllFiles
virtual bool StartStreaming() override
StartStreaming Start live video streaming.
static void * streamVideoHelper(void *context)
ISwitch CrashS[1]
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
int minpix
float m_PolarError
bool setupParameters()
IText DirectoryT[1]
virtual IPState GuideEast(uint32_t) override
Guide easward for ms milliseconds.
ISwitchVectorProperty CrashSP
INumberVectorProperty FocusSimulationNP
time_t RunStart
double flux(double magnitude) const
virtual IPState GuideWest(uint32_t) override
Guide westward for ms milliseconds.
float m_OAGOffset
ISwitchVectorProperty SimulateBayerSP
int QueryFilter() override
Return current filter position.
INumberVectorProperty SimulatorSettingsNP
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
bool loadNextImage()
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
ITextVectorProperty DirectoryTP
float m_LimitingMag
INumber GainN[1]
INumberVectorProperty FWHMNP
virtual IPState GuideNorth(uint32_t) override
Guide northward for ms milliseconds.
float CalcTimeLeft(timeval, float)
bool AbortExposure() override
Abort ongoing exposure.
float m_TimeFactor
float m_SaturationMag
ISwitch SimulateBayerS[2]
ISwitch DirectoryS[2]
int streamPredicate
INumber SimulatorSettingsN[SIM_N]
ISwitchVectorProperty DirectorySP
double TemperatureRequest
INumber OffsetN[1]
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual void activeDevicesUpdated() override
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
double currentRA
bool usePE
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.
bool terminateThread
INumberVectorProperty GainNP
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...
static constexpr const char * SIMULATOR_TAB
INumberVectorProperty EqPENP
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)
float ImageScaley
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition: indiccdchip.h:35
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition: indiccd.h:116
double ExposureTime
Definition: indiccd.h:594
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246