Instrument Neutral Distributed Interface INDI  1.9.5
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 
139 int tty_read_expanded(int fd, char *buf, int nbytes, long timeout_seconds, long timeout_microseconds, int *nbytes_read);
140 
149 int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read);
150 
165 int tty_read_section_expanded(int fd, char *buf, char stop_char, long timeout_seconds, long timeout_microseconds, int *nbytes_read);
166 
176 int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read);
177 
185 int tty_write(int fd, const char *buffer, int nbytes, int *nbytes_written);
186 
193 int tty_write_string(int fd, const char *buffer, int *nbytes_written);
194 
205 int tty_connect(const char *device, int bit_rate, int word_size, int parity, int stop_bits, int *fd);
206 
211 int tty_disconnect(int fd);
212 
218 void tty_error_msg(int err_code, char *err_msg, int err_msg_len);
219 
224 void tty_set_debug(int debug);
225 void tty_set_gemini_udp_format(int enabled);
226 void tty_set_generic_udp_format(int enabled);
227 void tty_clr_trailing_read_lf(int enabled);
228 
229 int tty_timeout(int fd, int timeout);
232 int tty_timeout_microseconds(int fd, long timeout_seconds, long timeout_microseconds);
239 
256 int fs_sexa(char *out, double a, int w, int fracbase);
257 
266 int f_scansexa(const char *str0, double *dp);
267 
273 #ifndef _WIN32
274 int extractISOTime(const char *timestr, struct ln_date *iso_date);
275 #endif
276 
277 void getSexComponents(double value, int *d, int *m, int *s);
278 void getSexComponentsIID(double value, int *d, int *m, double *s);
279 
288 int numberFormat(char *buf, const char *format, double value);
289 
293 double time_ns();
294 
298 const char *timestamp();
299 
305 double rangeHA(double r);
306 
312 double range24(double r);
313 
319 double range360(double r);
320 
326 double rangeDec(double r);
327 
333 double get_local_sidereal_time(double longitude);
334 
341 double get_local_hour_angle(double local_sideral_time, double ra);
342 
343 
352 void get_hrz_from_equ(struct ln_equ_posn *object, struct ln_lnlat_posn *observer, double JD, struct ln_hrz_posn *position);
353 
362 void get_equ_from_hrz(struct ln_hrz_posn *object, struct ln_lnlat_posn *observer, double JD,
363  struct ln_equ_posn *position);
372 void get_alt_az_coordinates(double hour_angle, double dec, double latitude, double* alt, double *az);
373 
380 double estimate_geocentric_elevation(double latitude, double sea_level_elevation);
381 
389 double estimate_field_rotation_rate(double Alt, double Az, double latitude);
390 
397 double estimate_field_rotation(double hour_angle, double field_rotation_rate);
398 
404 double as2rad(double as);
405 
411 double rad2as(double rad);
412 
418 double estimate_distance(double parsecs, double parallax_radius);
419 
425 double m2au(double m);
426 
435 double calc_delta_magnitude(double mag_ratio, double *spectrum, double *ref_spectrum, int spectrum_size);
436 
445 double calc_photon_flux(double rel_magnitude, double filter_bandwidth, double wavelength, double steradian);
446 
455 double calc_rel_magnitude(double photon_flux, double filter_bandwidth, double wavelength, double steradian);
456 
463 double estimate_absolute_magnitude(double dist, double delta_mag);
464 
470 double estimate_star_mass(double delta_mag, double ref_mass);
471 
478 double estimate_orbit_radius(double obs_lambda, double ref_lambda, double period);
479 
486 double estimate_secondary_mass(double star_mass, double star_drift, double orbit_radius);
487 
493 double estimate_secondary_size(double star_size, double dropoff_ratio);
494 
503 void baseline_2d_projection(double alt, double az, double baseline[3], double wavelength, double uvresult[2]);
504 
513 double baseline_delay(double alt, double az, double baseline[3]);
516 #ifdef __cplusplus
517 }
518 #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:1475
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:557
TTY_TIME_OUT
@ TTY_TIME_OUT
Definition: indicom.h:98
fd
int fd
Definition: indiserver.c:117
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:1573
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:937
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:352
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:1613
tty_set_gemini_udp_format
void tty_set_gemini_udp_format(int enabled)
Definition: indicom.c:357
tty_read_expanded
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:478
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:1643
m2au
double m2au(double m)
m2au Convert meters into astronomical units
Definition: indicom.c:1608
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:1137
rad2as
double rad2as(double rad)
rad2as Convert radians into arcseconds
Definition: indicom.c:1598
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:465
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:1668
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:1628
timestamp
const char * timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
Definition: indicom.c:340
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:1653
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:137
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:1549
tty_write
int tty_write(int fd, const char *buffer, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition: indicom.c:415
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:1658
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:1495
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:1565
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:657
estimate_distance
double estimate_distance(double parsecs, double parallax_radius)
estimate_distance Convert parallax arcseconds into meters
Definition: indicom.c:1603
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:201
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:1156
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:1583
numberFormat
int numberFormat(char *buf, const char *format, double value)
Fill buffer with properly formatted INumber string.
Definition: indicom.c:284
getSexComponentsIID
void getSexComponentsIID(double value, int *d, int *m, double *s)
Definition: indicom.c:273
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:367
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:1485
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:1648
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:1638
rangeDec
double rangeDec(double r)
rangeDec Limits declination value to be in -90 to 90 range.
Definition: indicom.c:1505
TTY_SELECT_ERROR
@ TTY_SELECT_ERROR
Definition: indicom.h:97
tty_read_section_expanded
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:562
tty_timeout_microseconds
int tty_timeout_microseconds(int fd, long timeout_seconds, long timeout_microseconds)
Definition: indicom.c:377
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:1543
time_ns
double time_ns()
Get a unix timestamp with nanosecond precision.
Definition: indicom.c:322
TTY_OK
@ TTY_OK
Definition: indicom.h:94
tty_timeout
int tty_timeout(int fd, int timeout)
Definition: indicom.c:372
as2rad
double as2rad(double as)
as2rad Convert arcseconds into radians
Definition: indicom.c:1593
getSexComponents
void getSexComponents(double value, int *d, int *m, int *s)
Definition: indicom.c:250
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:1633
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:362
tty_read
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition: indicom.c:473