Instrument Neutral Distributed Interface INDI  2.0.2
indicom.h
Go to the documentation of this file.
1 
38 #pragma once
39 
40 #if defined(_MSC_VER)
41 #define _USE_MATH_DEFINES
42 #endif
43 
44 #include <math.h>
45 
46 #ifndef J2000
47 #define J2000 2451545.0
48 #endif
49 #define ERRMSG_SIZE 1024
50 
51 #ifndef STELLAR_DAY
52 #define STELLAR_DAY 86164.098903691
53 #endif
54 #ifndef TRACKRATE_SIDEREAL
55 #define TRACKRATE_SIDEREAL ((360.0 * 3600.0) / STELLAR_DAY)
56 #endif
57 #ifndef SOLAR_DAY
58 #define SOLAR_DAY 86400
59 #endif
60 #ifndef TRACKRATE_SOLAR
61 #define TRACKRATE_SOLAR ((360.0 * 3600.0) / SOLAR_DAY)
62 #endif
63 #ifndef TRACKRATE_LUNAR
64 #define TRACKRATE_LUNAR 14.511415
65 #endif
66 #ifndef EARTHRADIUSEQUATORIAL
67 #define EARTHRADIUSEQUATORIAL 6378137.0
68 #endif
69 #ifndef EARTHRADIUSPOLAR
70 #define EARTHRADIUSPOLAR 6356752.0
71 #endif
72 #ifndef EARTHRADIUSMEAN
73 #define EARTHRADIUSMEAN 6372797.0
74 #endif
75 #ifndef SUNMASS
76 #define SUNMASS 1.98847E+30
77 #endif
78 #ifndef PLANK_H
79 #define PLANK_H 6.62607015E-34
80 #endif
81 #ifndef DIRAC_H
82 #define DIRAC_H (PLANK_H/(2*M_PI))
83 #endif
84 #ifndef EINSTEIN_G
85 #define EINSTEIN_G 6.67408E-11
86 #endif
87 #ifndef EULER
88 #define EULER 2.71828182845904523536028747135266249775724709369995
89 #endif
90 #ifndef ROOT2
91 #define ROOT2 1.41421356237309504880168872420969807856967187537694
92 #endif
93 #ifndef AIRY
94 #define AIRY 1.21966
95 #endif
96 #ifndef CIRCLE_DEG
97 #define CIRCLE_DEG 360
98 #endif
99 #ifndef CIRCLE_AM
100 #define CIRCLE_AM (CIRCLE_DEG * 60)
101 #endif
102 #ifndef CIRCLE_AS
103 #define CIRCLE_AS (CIRCLE_AM * 60)
104 #endif
105 #ifndef RAD_AS
106 #define RAD_AS (CIRCLE_AS/(M_PI*2))
107 #endif
108 #ifndef ASTRONOMICALUNIT
109 #define ASTRONOMICALUNIT 1.495978707E+11
110 #endif
111 #ifndef PARSEC
112 #define PARSEC (ASTRONOMICALUNIT*RAD_AS)
113 #endif
114 #ifndef LIGHTSPEED
115 #define LIGHTSPEED 299792458.0
116 #endif
117 #ifndef JULIAN_LY
118 #define JULIAN_LY (LIGHTSPEED * SOLAR_DAY * 365)
119 #endif
120 #ifndef STELLAR_LY
121 #define STELLAR_LY (LIGHTSPEED * STELLAR_DAY * 365)
122 #endif
123 #ifndef FLUX
124 #define FLUX(wavelength) (wavelength/(PLANK_H*LIGHTSPEED))
125 #endif
126 #ifndef CANDLE
127 #define CANDLE ((1.0/683.0)*FLUX(555))
128 #endif
129 #ifndef LUMEN
130 #define LUMEN(wavelength) (CANDLE/(4*M_PI)*pow((FLUX(wavelength)/FLUX(555)), 0.25))
131 #endif
132 #ifndef REDSHIFT
133 #define REDSHIFT(wavelength, reference) (1.0-(reference/wavelength))
134 #endif
135 #ifndef DOPPLER
136 #define DOPPLER(shift, speed) (speed*shift)
137 #endif
138 
139 extern const char *Direction[];
140 extern const char *SolarSystem[];
141 
142 struct ln_date;
143 struct ln_equ_posn;
144 struct ln_lnlat_posn;
145 struct ln_hrz_posn;
146 
147 /* TTY Error Codes */
149 {
150  TTY_OK = 0,
157  TTY_ERRNO = -7,
160 };
161 
162 #ifdef __cplusplus
163 extern "C" {
164 #endif
165 
170 /* @{ */
171 
180 int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read);
181 
195 int tty_read_expanded(int fd, char *buf, int nbytes, long timeout_seconds, long timeout_microseconds, int *nbytes_read);
196 
205 int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read);
206 
221 int tty_read_section_expanded(int fd, char *buf, char stop_char, long timeout_seconds, long timeout_microseconds,
222  int *nbytes_read);
223 
233 int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read);
234 
242 int tty_write(int fd, const char *buffer, int nbytes, int *nbytes_written);
243 
250 int tty_write_string(int fd, const char *buffer, int *nbytes_written);
251 
262 int tty_connect(const char *device, int bit_rate, int word_size, int parity, int stop_bits, int *fd);
263 
268 int tty_disconnect(int fd);
269 
275 void tty_error_msg(int err_code, char *err_msg, int err_msg_len);
276 
280 void tty_set_debug(int debug);
281 void tty_set_gemini_udp_format(int enabled);
282 void tty_set_generic_udp_format(int enabled);
283 void tty_clr_trailing_read_lf(int enabled);
284 
285 int tty_timeout(int fd, int timeout);
286 
287 int tty_timeout_microseconds(int fd, long timeout_seconds, long timeout_microseconds);
288 
289 /* @} */
290 
295 /* @{ */
296 
310 int fs_sexa(char *out, double a, int w, int fracbase);
311 
318 int f_scansexa(const char *str0, double *dp);
319 
325 #ifndef _WIN32
326 int extractISOTime(const char *timestr, struct ln_date *iso_date);
327 #endif
328 
329 void getSexComponents(double value, int *d, int *m, int *s);
330 void getSexComponentsIID(double value, int *d, int *m, double *s);
331 
339 int numberFormat(char *buf, const char *format, double value);
340 
344 double time_ns();
345 
349 const char *indi_timestamp();
350 
355 double rangeHA(double r);
356 
361 double range24(double r);
362 
367 double range360(double r);
368 
373 double rangeDec(double r);
374 
379 double get_local_sidereal_time(double longitude);
380 
386 double get_local_hour_angle(double local_sideral_time, double ra);
387 
388 
396 void get_hrz_from_equ(struct ln_equ_posn *object, struct ln_lnlat_posn *observer, double JD, struct ln_hrz_posn *position);
397 
405 void get_equ_from_hrz(struct ln_hrz_posn *object, struct ln_lnlat_posn *observer, double JD,
406  struct ln_equ_posn *position);
414 void get_alt_az_coordinates(double hour_angle, double dec, double latitude, double* alt, double *az);
415 
421 double estimate_geocentric_elevation(double latitude, double sea_level_elevation);
422 
429 double estimate_field_rotation_rate(double Alt, double Az, double latitude);
430 
436 double estimate_field_rotation(double hour_angle, double field_rotation_rate);
437 
442 double as2rad(double as);
443 
448 double rad2as(double rad);
449 
454 double estimate_distance(double parsecs, double parallax_radius);
455 
460 double m2au(double m);
461 
469 double calc_delta_magnitude(double mag_ratio, double *spectrum, double *ref_spectrum, int spectrum_size);
470 
478 double calc_photon_flux(double rel_magnitude, double filter_bandwidth, double wavelength, double steradian);
479 
487 double calc_rel_magnitude(double photon_flux, double filter_bandwidth, double wavelength, double steradian);
488 
494 double estimate_absolute_magnitude(double dist, double delta_mag);
495 
500 double estimate_star_mass(double delta_mag, double ref_mass);
501 
507 double estimate_orbit_radius(double obs_lambda, double ref_lambda, double period);
508 
514 double estimate_secondary_mass(double star_mass, double star_drift, double orbit_radius);
515 
520 double estimate_secondary_size(double star_size, double dropoff_ratio);
521 
529 void baseline_2d_projection(double alt, double az, double baseline[3], double wavelength, double uvresult[2]);
530 
538 double baseline_delay(double alt, double az, double baseline[3]);
539 
540 /* @} */
541 
542 #ifdef __cplusplus
543 }
544 #endif
hid_device * device
double ra
double dec
double estimate_secondary_size(double star_size, double dropoff_ratio)
estimate the size of an object occulting a star in star_size units.
Definition: indicom.c:1388
int tty_write_string(int fd, const char *buffer, int *nbytes_written)
Writes a null terminated string to fd.
Definition: indicom.c:474
void tty_set_generic_udp_format(int enabled)
Definition: indicom.c:370
double estimate_geocentric_elevation(double latitude, double sea_level_elevation)
estimate_geocentric_elevation Returns an estimation of the actual geocentric elevation
Definition: indicom.c:1315
double rangeDec(double r)
rangeDec Limits declination value to be in -90 to 90 range.
Definition: indicom.c:1255
double calc_rel_magnitude(double photon_flux, double filter_bandwidth, double wavelength, double steradian)
calc_rel_magnitude Returns the relative magnitude of the object with the given photon flux measured a...
Definition: indicom.c:1398
double estimate_secondary_mass(double star_mass, double star_drift, double orbit_radius)
estimate the mass of an object with known mass orbiting around a star.
Definition: indicom.c:1383
TTY_ERROR
Definition: indicom.h:149
@ TTY_PORT_FAILURE
Definition: indicom.h:155
@ TTY_OK
Definition: indicom.h:150
@ TTY_READ_ERROR
Definition: indicom.h:151
@ TTY_SELECT_ERROR
Definition: indicom.h:153
@ TTY_TIME_OUT
Definition: indicom.h:154
@ TTY_PORT_BUSY
Definition: indicom.h:159
@ TTY_PARAM_ERROR
Definition: indicom.h:156
@ TTY_OVERFLOW
Definition: indicom.h:158
@ TTY_WRITE_ERROR
Definition: indicom.h:152
@ TTY_ERRNO
Definition: indicom.h:157
void baseline_2d_projection(double alt, double az, double baseline[3], double wavelength, double uvresult[2])
baseline_2d_projection Returns the coordinates of the projection of a single baseline targeting the o...
Definition: indicom.c:1408
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Definition: indicom.c:566
void getSexComponentsIID(double value, int *d, int *m, double *s)
Definition: indicom.c:277
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double. x can be anything non-numeric. Any missing A,...
Definition: indicom.c:205
int tty_connect(const char *device, int bit_rate, int word_size, int parity, int stop_bits, int *fd)
Establishes a tty connection to a terminal device.
Definition: indicom.c:946
double calc_photon_flux(double rel_magnitude, double filter_bandwidth, double wavelength, double steradian)
calc_photon_flux Returns the photon flux of the object with the given magnitude observed at a determi...
Definition: indicom.c:1393
void tty_set_debug(int debug)
tty_set_debug Enable or disable debug which prints verbose information.
Definition: indicom.c:360
void get_alt_az_coordinates(double hour_angle, double dec, double latitude, double *alt, double *az)
get_alt_az_coordinates Returns alt-azimuth coordinates of an object
Definition: indicom.c:1299
double estimate_field_rotation_rate(double Alt, double Az, double latitude)
estimate_field_rotation_rate Returns an estimation of the field rotation rate of the object
Definition: indicom.c:1323
double estimate_distance(double parsecs, double parallax_radius)
estimate_distance Convert parallax arcseconds into meters
Definition: indicom.c:1353
double estimate_orbit_radius(double obs_lambda, double ref_lambda, double period)
estimate the orbit radius of an object with known mass orbiting around a star.
Definition: indicom.c:1378
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sideral time given longitude and system clock.
int tty_disconnect(int fd)
Closes a tty connection and flushes the bus.
Definition: indicom.c:1148
const char * SolarSystem[]
int tty_timeout_microseconds(int fd, long timeout_seconds, long timeout_microseconds)
Definition: indicom.c:385
double rangeHA(double r)
rangeHA Limits the hour angle value to be between -12 —> 12
Definition: indicom.c:1225
void getSexComponents(double value, int *d, int *m, int *s)
Definition: indicom.c:254
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition: indicom.c:482
double estimate_absolute_magnitude(double dist, double delta_mag)
estimate_absolute_magnitude Returns an estimation of the absolute magnitude of an object given its di...
Definition: indicom.c:1403
double m2au(double m)
m2au Convert meters into astronomical units
Definition: indicom.c:1358
const char * indi_timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
Definition: indicom.c:348
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition: indicom.c:1235
int tty_read_section_expanded(int fd, char *buf, char stop_char, long timeout_seconds, long timeout_microseconds, int *nbytes_read)
read buffer from terminal with a delimiter
Definition: indicom.c:571
void get_hrz_from_equ(struct ln_equ_posn *object, struct ln_lnlat_posn *observer, double JD, struct ln_hrz_posn *position)
get_hrz_from_equ Calculate horizontal coordinates from equatorial coordinates.
double estimate_field_rotation(double hour_angle, double field_rotation_rate)
estimate_field_rotation Returns an estimation of the field rotation rate of the object
Definition: indicom.c:1333
int tty_timeout(int fd, int timeout)
Definition: indicom.c:380
double as2rad(double as)
as2rad Convert arcseconds into radians
Definition: indicom.c:1343
double estimate_star_mass(double delta_mag, double ref_mass)
estimate the star mass in ref_size units e.g. sun masses or kgs
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1245
double baseline_delay(double alt, double az, double baseline[3])
baseline_delay Returns the delay in meters of a single baseline targeting the object by coordinates
Definition: indicom.c:1418
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Definition: indicom.c:1167
int tty_write(int fd, const char *buffer, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition: indicom.c:424
double time_ns()
Get a unix timestamp with nanosecond precision.
Definition: indicom.c:326
double calc_delta_magnitude(double mag_ratio, double *spectrum, double *ref_spectrum, int spectrum_size)
calc_delta_magnitude Returns the difference of magnitudes given two spectra
Definition: indicom.c:1363
int extractISOTime(const char *timestr, struct ln_date *iso_date)
Extract ISO 8601 time and store it in a tm struct.
void get_equ_from_hrz(struct ln_hrz_posn *object, struct ln_lnlat_posn *observer, double JD, struct ln_equ_posn *position)
ln_get_equ_from_hrz Calculate Equatorial EOD Coordinates from horizontal coordinates
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Definition: indicom.c:141
int numberFormat(char *buf, const char *format, double value)
Fill buffer with properly formatted INumber string.
Definition: indicom.c:288
int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Definition: indicom.c:666
int tty_read_expanded(int fd, char *buf, int nbytes, long timeout_seconds, long timeout_microseconds, int *nbytes_read)
read buffer from terminal with a delimiter
Definition: indicom.c:487
void tty_clr_trailing_read_lf(int enabled)
Definition: indicom.c:375
void tty_set_gemini_udp_format(int enabled)
Definition: indicom.c:365
double get_local_hour_angle(double local_sideral_time, double ra)
get_local_hour_angle Returns local hour angle of an object
Definition: indicom.c:1293
double rad2as(double rad)
rad2as Convert radians into arcseconds
Definition: indicom.c:1348
const char * Direction[]
int fd
Definition: intelliscope.c:43
std::vector< uint8_t > buffer