Instrument Neutral Distributed Interface INDI  1.9.2
indicom.h
Go to the documentation of this file.
1 /*
2  INDI LIB
3  Common routines used by all drivers
4  Copyright (C) 2003 by Jason Harris (jharris@30doradus.org)
5  Elwood C. Downey
6  Jasem Mutlaq
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 */
23 
42 #pragma once
43 
44 #if defined(_MSC_VER)
45 #define _USE_MATH_DEFINES
46 #endif
47 
48 #include <math.h>
49 
50 #define J2000 2451545.0
51 #define ERRMSG_SIZE 1024
52 
53 #define STELLAR_DAY 86164.098903691
54 #define TRACKRATE_SIDEREAL ((360.0 * 3600.0) / STELLAR_DAY)
55 #define SOLAR_DAY 86400
56 #define TRACKRATE_SOLAR ((360.0 * 3600.0) / SOLAR_DAY)
57 #define TRACKRATE_LUNAR 14.511415
58 #define EARTHRADIUSEQUATORIAL 6378137.0
59 #define EARTHRADIUSPOLAR 6356752.0
60 #define EARTHRADIUSMEAN 6372797.0
61 #define SUNMASS 1.98847E+30
62 #define PLANK_H 6.62607015E-34
63 #define DIRAC_H (PLANK_H/(2*M_PI))
64 #define EINSTEIN_G 6.67408E-11
65 #define EULER 2.71828182845904523536028747135266249775724709369995
66 #define ROOT2 1.41421356237309504880168872420969807856967187537694
67 #define AIRY 1.21966
68 #define CIRCLE_DEG 360
69 #define CIRCLE_AM (CIRCLE_DEG * 60)
70 #define CIRCLE_AS (CIRCLE_AM * 60)
71 #define RAD_AS (CIRCLE_AS/(M_PI*2))
72 #define ASTRONOMICALUNIT 1.495978707E+11
73 #define PARSEC (ASTRONOMICALUNIT*RAD_AS)
74 #define LIGHTSPEED 299792458.0
75 #define JULIAN_LY (LIGHTSPEED * SOLAR_DAY * 365)
76 #define STELLAR_LY (LIGHTSPEED * STELLAR_DAY * 365)
77 #define FLUX(wavelength) (wavelength/(PLANK_H*LIGHTSPEED))
78 #define CANDLE ((1.0/683.0)*FLUX(555))
79 #define LUMEN(wavelength) (CANDLE/(4*M_PI)*pow((FLUX(wavelength)/FLUX(555)), 0.25))
80 #define REDSHIFT(wavelength, reference) (1.0-(reference/wavelength))
81 #define DOPPLER(shift, speed) (speed*shift)
82 
83 extern const char *Direction[];
84 extern const char *SolarSystem[];
85 
86 struct ln_date;
87 struct ln_equ_posn;
88 struct ln_lnlat_posn;
89 struct ln_hrz_posn;
90 
91 /* TTY Error Codes */
93 {
94  TTY_OK = 0,
101  TTY_ERRNO = -7,
104 };
105 
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109 
115 
124 int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read);
125 
135 int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read);
136 
147 int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read);
148 
156 int tty_write(int fd, const char *buffer, int nbytes, int *nbytes_written);
157 
164 int tty_write_string(int fd, const char *buffer, int *nbytes_written);
165 
177 int tty_connect(const char *device, int bit_rate, int word_size, int parity, int stop_bits, int *fd);
178 
183 int tty_disconnect(int fd);
184 
190 void tty_error_msg(int err_code, char *err_msg, int err_msg_len);
191 
196 void tty_set_debug(int debug);
197 void tty_set_gemini_udp_format(int enabled);
198 void tty_set_generic_udp_format(int enabled);
199 void tty_clr_trailing_read_lf(int enabled);
200 
201 int tty_timeout(int fd, int timeout);
208 
225 int fs_sexa(char *out, double a, int w, int fracbase);
226 
235 int f_scansexa(const char *str0, double *dp);
236 
242 #ifndef _WIN32
243 int extractISOTime(const char *timestr, struct ln_date *iso_date);
244 #endif
245 
246 void getSexComponents(double value, int *d, int *m, int *s);
247 void getSexComponentsIID(double value, int *d, int *m, double *s);
248 
257 int numberFormat(char *buf, const char *format, double value);
258 
262 double time_ns();
263 
267 const char *timestamp();
268 
274 double rangeHA(double r);
275 
281 double range24(double r);
282 
288 double range360(double r);
289 
295 double rangeDec(double r);
296 
302 double get_local_sidereal_time(double longitude);
303 
310 double get_local_hour_angle(double local_sideral_time, double ra);
311 
312 
321 void get_hrz_from_equ(struct ln_equ_posn *object, struct ln_lnlat_posn *observer, double JD, struct ln_hrz_posn *position);
322 
331 void get_equ_from_hrz(struct ln_hrz_posn *object, struct ln_lnlat_posn *observer, double JD,
332  struct ln_equ_posn *position);
341 void get_alt_az_coordinates(double hour_angle, double dec, double latitude, double* alt, double *az);
342 
349 double estimate_geocentric_elevation(double latitude, double sea_level_elevation);
350 
358 double estimate_field_rotation_rate(double Alt, double Az, double latitude);
359 
366 double estimate_field_rotation(double hour_angle, double field_rotation_rate);
367 
373 double as2rad(double as);
374 
380 double rad2as(double rad);
381 
387 double estimate_distance(double parsecs, double parallax_radius);
388 
394 double m2au(double m);
395 
404 double calc_delta_magnitude(double mag_ratio, double *spectrum, double *ref_spectrum, int spectrum_size);
405 
414 double calc_photon_flux(double rel_magnitude, double filter_bandwidth, double wavelength, double steradian);
415 
424 double calc_rel_magnitude(double photon_flux, double filter_bandwidth, double wavelength, double steradian);
425 
432 double estimate_absolute_magnitude(double dist, double delta_mag);
433 
439 double estimate_star_mass(double delta_mag, double ref_mass);
440 
447 double estimate_orbit_radius(double obs_lambda, double ref_lambda, double period);
448 
455 double estimate_secondary_mass(double star_mass, double star_drift, double orbit_radius);
456 
462 double estimate_secondary_size(double star_size, double dropoff_ratio);
463 
472 void baseline_2d_projection(double alt, double az, double baseline[3], double wavelength, double uvresult[2]);
473 
482 double baseline_delay(double alt, double az, double baseline[3]);
485 #ifdef __cplusplus
486 }
487 #endif
estimate_star_mass
double estimate_star_mass(double delta_mag, double ref_mass)
estimate the star mass in ref_size units e.g. sun masses or kgs
rangeHA
double rangeHA(double r)
rangeHA Limits the hour angle value to be between -12 —> 12
Definition: indicom.c:1454
tty_read_section
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:541
TTY_TIME_OUT
@ TTY_TIME_OUT
Definition: indicom.h:98
estimate_field_rotation_rate
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:1552
tty_connect
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:916
TTY_ERROR
TTY_ERROR
Definition: indicom.h:92
tty_set_debug
void tty_set_debug(int debug)
tty_set_debug Enable or disable debug which prints verbose information.
Definition: indicom.c:346
calc_delta_magnitude
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:1592
tty_set_gemini_udp_format
void tty_set_gemini_udp_format(int enabled)
Definition: indicom.c:351
calc_photon_flux
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:1622
m2au
double m2au(double m)
m2au Convert meters into astronomical units
Definition: indicom.c:1587
TTY_READ_ERROR
@ TTY_READ_ERROR
Definition: indicom.h:95
TTY_OVERFLOW
@ TTY_OVERFLOW
Definition: indicom.h:102
tty_disconnect
int tty_disconnect(int fd)
Closes a tty connection and flushes the bus.
Definition: indicom.c:1116
rad2as
double rad2as(double rad)
rad2as Convert radians into arcseconds
Definition: indicom.c:1577
tty_write_string
int tty_write_string(int fd, const char *buffer, int *nbytes_written)
Writes a null terminated string to fd.
Definition: indicom.c:454
baseline_delay
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:1647
estimate_orbit_radius
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:1607
timestamp
const char * timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
Definition: indicom.c:334
estimate_absolute_magnitude
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:1632
Direction
const char * Direction[]
fs_sexa
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string.
Definition: indicom.c:131
get_alt_az_coordinates
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:1528
tty_write
int tty_write(int fd, const char *buffer, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition: indicom.c:404
device
hid_device * device
Definition: activefocuser_utils.cpp:92
TTY_PARAM_ERROR
@ TTY_PARAM_ERROR
Definition: indicom.h:100
baseline_2d_projection
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:1637
TTY_PORT_FAILURE
@ TTY_PORT_FAILURE
Definition: indicom.h:99
ra
double ra
Definition: ieqprolegacydriver.cpp:43
range360
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1474
TTY_ERRNO
@ TTY_ERRNO
Definition: indicom.h:101
SolarSystem
const char * SolarSystem[]
estimate_geocentric_elevation
double estimate_geocentric_elevation(double latitude, double sea_level_elevation)
estimate_geocentric_elevation Returns an estimation of the actual geocentric elevation
Definition: indicom.c:1544
tty_nread_section
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:636
estimate_distance
double estimate_distance(double parsecs, double parallax_radius)
estimate_distance Convert parallax arcseconds into meters
Definition: indicom.c:1582
get_hrz_from_equ
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.
TTY_WRITE_ERROR
@ TTY_WRITE_ERROR
Definition: indicom.h:96
dec
double dec
Definition: ieqprolegacydriver.cpp:44
extractISOTime
int extractISOTime(const char *timestr, struct ln_date *iso_date)
Extract ISO 8601 time and store it in a tm struct.
f_scansexa
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double.
Definition: indicom.c:195
tty_error_msg
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Definition: indicom.c:1135
estimate_field_rotation
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:1562
numberFormat
int numberFormat(char *buf, const char *format, double value)
Fill buffer with properly formatted INumber string.
Definition: indicom.c:278
getSexComponentsIID
void getSexComponentsIID(double value, int *d, int *m, double *s)
Definition: indicom.c:267
get_local_sidereal_time
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sideral time given longitude and system clock.
tty_clr_trailing_read_lf
void tty_clr_trailing_read_lf(int enabled)
Definition: indicom.c:361
fd
int fd
Definition: intelliscope.c:43
get_equ_from_hrz
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
range24
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition: indicom.c:1464
calc_rel_magnitude
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:1627
estimate_secondary_size
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:1617
rangeDec
double rangeDec(double r)
rangeDec Limits declination value to be in -90 to 90 range.
Definition: indicom.c:1484
TTY_SELECT_ERROR
@ TTY_SELECT_ERROR
Definition: indicom.h:97
TTY_PORT_BUSY
@ TTY_PORT_BUSY
Definition: indicom.h:103
get_local_hour_angle
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:1522
time_ns
double time_ns()
Get a unix timestamp with nanosecond precision.
Definition: indicom.c:316
TTY_OK
@ TTY_OK
Definition: indicom.h:94
tty_timeout
int tty_timeout(int fd, int timeout)
Definition: indicom.c:366
as2rad
double as2rad(double as)
as2rad Convert arcseconds into radians
Definition: indicom.c:1572
getSexComponents
void getSexComponents(double value, int *d, int *m, int *s)
Definition: indicom.c:244
estimate_secondary_mass
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:1612
Aux::buffer
std::vector< uint8_t > buffer
Definition: celestronauxpacket.h:38
tty_set_generic_udp_format
void tty_set_generic_udp_format(int enabled)
Definition: indicom.c:356
tty_read
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition: indicom.c:462