Instrument Neutral Distributed Interface INDI  2.0.2
guide_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 "indiccd.h"
22 #include "indifilterinterface.h"
23 #include "indipropertyswitch.h"
24 #include "fitskeyword.h"
25 
42 class GuideSim : public INDI::CCD
43 {
44  public:
45 
46  GuideSim();
47  virtual ~GuideSim() override = default;
48 
49  const char *getDefaultName() override;
50 
51  bool initProperties() override;
52  bool updateProperties() override;
53 
54  void ISGetProperties(const char *dev) override;
55 
56  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
57  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
58  virtual bool ISSnoopDevice(XMLEle *root) override;
59 
60  static void *streamVideoHelper(void *context);
61  void *streamVideo();
62 
63  protected:
64 
65  bool Connect() override;
66  bool Disconnect() override;
67 
68  bool StartExposure(float duration) override;
69 
70  bool AbortExposure() override;
71 
72  void TimerHit() override;
73 
74  int DrawCcdFrame(INDI::CCDChip *targetChip);
75 
76  int DrawImageStar(INDI::CCDChip *targetChip, float, float, float, float ExposureTime);
77  int AddToPixel(INDI::CCDChip *targetChip, int, int, int);
78 
79  virtual IPState GuideNorth(uint32_t) override;
80  virtual IPState GuideSouth(uint32_t) override;
81  virtual IPState GuideEast(uint32_t) override;
82  virtual IPState GuideWest(uint32_t) override;
83 
84  virtual bool saveConfigItems(FILE *fp) override;
85  virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector<INDI::FITSRecord> &fitsKeywords) override;
86  virtual void activeDevicesUpdated() override;
87  virtual int SetTemperature(double temperature) override;
88  virtual bool UpdateCCDFrame(int x, int y, int w, int h) override;
89  virtual bool UpdateCCDBin(int hor, int ver) override;
90 
91  virtual bool StartStreaming() override;
92  virtual bool StopStreaming() override;
93 
94  private:
95 
96  float CalcTimeLeft(timeval, float);
97  bool SetupParms();
98 
99  // Turns on/off Bayer RGB simulation.
100  void setRGB(bool onOff);
101 
102  double TemperatureRequest { 0 };
103 
104  float ExposureRequest { 0 };
105  struct timeval ExpStart
106  {
107  0, 0
108  };
109 
110 
111  int testvalue { 0 };
112  bool ShowStarField { true };
113  int bias { 1500 };
114  int maxnoise { 20 };
115  int maxval { 65000 };
116  int maxpix { 0 };
117  int minpix { 65000 };
118  float skyglow { 40 };
119  float limitingmag { 11.5 };
120  float saturationmag { 2 };
121  float seeing { 3.5 };
122  float ImageScalex { 1.0 };
123  float ImageScaley { 1.0 };
124  // An oag is offset this much from center of scope position (arcminutes)
125  float OAGoffset { 0 };
126  double rotationCW { 0 };
127  float TimeFactor { 1 };
128 
129  bool simulateRGB { false };
130 
131  // our zero point calcs used for drawing stars
132  float k { 0 };
133  float z { 0 };
134 
135  bool AbortPrimaryFrame { false };
136 
138  float GuideRate { 7 };
139 
141  float PEPeriod { 8 * 60 };
142  float PEMax { 11 };
143 
144  double currentRA { 0 };
145  double currentDE { 0 };
146  bool usePE { false };
147  time_t RunStart;
148 
149  float guideNSOffset {0};
150  float guideWEOffset {0};
151 
152  float polarError { 0 };
153  float polarDrift { 0 };
154  float king_gamma = { 0 };
155  float king_theta = { 0 };
156 
157  int streamPredicate;
158  pthread_t primary_thread;
159  bool terminateThread;
160 
161  // And this lives in our simulator settings page
162 
163  INumberVectorProperty SimulatorSettingsNP;
164  INumber SimulatorSettingsN[17];
165 
166  ISwitchVectorProperty SimulateRgbSP;
167  ISwitch SimulateRgbS[2];
168 
169  INumberVectorProperty EqPENP;
170  INumber EqPEN[2];
171 
172  ISwitch CoolerS[2];
173  ISwitchVectorProperty CoolerSP;
174 
175  INumber GainN[1];
176  INumberVectorProperty GainNP;
177 
178  INDI::PropertySwitch ToggleTimeoutSP {2};
179 
180  static constexpr const char *SIMULATOR_TAB {"Simulator Settings"};
181 };
The GuideSim class provides an advanced simulator for a CCD that includes a dedicated on-board guide ...
virtual IPState GuideNorth(uint32_t) override
Guide northward for ms milliseconds.
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....
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save configuration items in XML file.
virtual IPState GuideEast(uint32_t) override
Guide easward for ms milliseconds.
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual ~GuideSim() override=default
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 DrawCcdFrame(INDI::CCDChip *targetChip)
virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector< INDI::FITSRecord > &fitsKeywords) override
Generate FITS keywords that will be added to FIST/XISF file.
const char * getDefaultName() override
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
bool Disconnect() override
Disconnect from device.
int AddToPixel(INDI::CCDChip *targetChip, int, int, int)
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
bool AbortExposure() override
Abort ongoing exposure.
virtual bool StartStreaming() override
StartStreaming Start live video streaming.
virtual bool StopStreaming() override
StopStreaming Stop live video streaming.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void * streamVideo()
virtual IPState GuideSouth(uint32_t) override
Guide southward for ms milliseconds.
static void * streamVideoHelper(void *context)
bool StartExposure(float duration) override
Start exposing primary CCD chip.
virtual void activeDevicesUpdated() override
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
int DrawImageStar(INDI::CCDChip *targetChip, float, float, float, float ExposureTime)
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual IPState GuideWest(uint32_t) override
Guide westward for ms milliseconds.
virtual int SetTemperature(double temperature) override
Set CCD temperature.
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.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367