36#if defined(HAVE_LIBNOVA)
37#include <libnova/julian_day.h>
38#include <libnova/sidereal_time.h>
39#include <libnova/ln_types.h>
40#include <libnova/transform.h>
63#if !defined(_WIN32) && !defined(__CYGWIN__)
64#include <sys/socket.h>
65#include <netinet/in.h>
69#include <mach/clock.h>
71#include <IOKit/serial/ioss.h>
83#define snprintf _snprintf
86#pragma warning(disable : 4996)
91static int tty_debug = 0;
92static int tty_gemini_udp_format = 0;
93static int tty_generic_udp_format = 0;
94static int tty_generic_udp_read_error_occured = 0;
95static int tty_auto_reset_udp_session = 0;
96static int tty_sequence_number = 1;
97static int tty_clear_trailing_lf = 0;
99#if defined(HAVE_LIBNOVA)
104 if (strptime(timestr,
"%Y/%m/%dT%H:%M:%S", &utm))
106 ln_get_date_from_tm(&utm, iso_date);
110 if (strptime(timestr,
"%Y-%m-%dT%H:%M:%S", &utm))
112 ln_get_date_from_tm(&utm, iso_date);
130int fs_sexa(
char *out,
double a,
int w,
int fracbase)
146 n = (
unsigned long)(a * fracbase + 0.5);
154 out += snprintf(out,
MAXINDIFORMAT,
"%*d", w, isneg ? -d : d);
160 m = f / (fracbase / 60);
164 out += snprintf(out,
MAXINDIFORMAT,
":%02d.%1d", f / 10, f % 10);
167 m = f / (fracbase / 60);
168 s = f % (fracbase / 60);
172 m = f / (fracbase / 60);
173 s = f % (fracbase / 60);
174 out += snprintf(out,
MAXINDIFORMAT,
":%02d:%02d.%1d", m, s / 10, s % 10);
177 m = f / (fracbase / 60);
178 s = f % (fracbase / 60);
179 out += snprintf(out,
MAXINDIFORMAT,
":%02d:%02d.%02d", m, s / 100, s % 100);
182 printf(
"fs_sexa: unknown fracbase: %d\n", fracbase);
186 return (
int)(out - out0);
199 double a = 0, b = 0, c = 0;
202 uint8_t isNegative=0;
206 strncpy(str, str0,
sizeof(str) - 1);
207 str[
sizeof(str) - 1] =
'\0';
231 r = sscanf(str,
"%lf%*[^0-9]%lf%*[^0-9]%lf", &a, &b, &c);
233 indi_locale_C_numeric_pop(orig);
237 *dp = a + b / 60 + c / 3600;
245 *d = (int32_t)fabs(value);
246 *m = (int32_t)((fabs(value) - *d) * 60.0);
247 *s = (int32_t)rint(((fabs(value) - *d) * 60.0 - *m) * 60.0);
268 *d = (int32_t)fabs(value);
269 *m = (int32_t)((fabs(value) - *d) * 60.0);
270 *s = (double)(((fabs(value) - *d) * 60.0 - *m) * 60.0);
282 if (sscanf(format,
"%%%d.%d%c", &w, &f, &m) == 3 && m ==
'm')
287 case 9: s = 360000;
break;
288 case 8: s = 36000;
break;
289 case 6: s = 3600;
break;
290 case 5: s = 600;
break;
291 default: s = 60;
break;
293 return (
fs_sexa(buf, value, w - f, s));
311 vfprintf(stderr,
fmt, ap);
318#if defined(HAVE_TIMESPEC_GET)
319 timespec_get(&ts, TIME_UTC);
320#elif defined(HAVE_CLOCK_GETTIME)
321 clock_gettime(CLOCK_REALTIME, &ts);
322#elif defined(__APPLE__)
325 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
326 clock_get_time(cclock, &mts);
327 mach_port_deallocate(mach_task_self(), cclock);
328 ts.tv_sec = mts.tv_sec;
329 ts.tv_nsec = mts.tv_nsec;
331 #error "Unsupported platform"
333 return (
double)ts.tv_sec+(double)(ts.tv_nsec%1000000000)/1000000000.0;
345 strftime(ts,
sizeof(ts),
"%Y-%m-%dT%H:%M:%S", tp);
356 tty_auto_reset_udp_session = flag;
361 tty_gemini_udp_format = enabled;
366 tty_generic_udp_format = enabled;
371 tty_clear_trailing_lf = enabled;
381#if defined(_WIN32) || defined(ANDROID)
396 FD_SET(
fd, &readout);
399 tv.tv_sec = timeout_seconds;
400 tv.tv_usec = timeout_microseconds;
403 retval = select(
fd + 1, &readout, NULL, NULL, &tv);
409 else if (retval == -1)
418int tty_write(
int fd,
const char *buf,
int nbytes,
int *nbytes_written)
423 int geminiBuffer[66]={0};
424 char *buffer = (
char *)buf;
426 if (tty_gemini_udp_format)
428 buffer = (
char*)geminiBuffer;
429 geminiBuffer[0] = ++tty_sequence_number;
431 memcpy((
char *)&geminiBuffer[2], buf, nbytes);
445 for (i = 0; i < nbytes; i++)
446 IDLog(
"%s: buffer[%d]=%#X (%c)\n", __FUNCTION__, i, (
unsigned char)buf[i], buf[i]);
449 if(tty_generic_udp_format && tty_auto_reset_udp_session > 0) {
450 int only_if_timeout = tty_auto_reset_udp_session == 1 ? 1 : 0;
456 bytes_w = write(
fd, buffer + (*nbytes_written), nbytes);
461 *nbytes_written += bytes_w;
465 if (tty_gemini_udp_format)
466 *nbytes_written -= 9;
476 nbytes = (int)strlen(buf);
485 (void)only_if_timeout_happened;
488 struct sockaddr_in server_addr;
491 if(!tty_generic_udp_format)
494 if(only_if_timeout_happened && !tty_generic_udp_read_error_occured)
498 IDLog(
"%s: Request to reset session for fd %d\n", __FUNCTION__,
fd);
501 new_fd = socket(AF_INET, SOCK_DGRAM, 0);
505 socklen_t len =
sizeof(server_addr);
508 if(getpeername(
fd,(
struct sockaddr *)&server_addr, &len) < 0)
511 if (connect(new_fd, (
struct sockaddr *)&server_addr,
sizeof(server_addr)) < 0)
516 if(getsockopt(
fd, SOL_SOCKET, SO_RCVTIMEO, &ts, &len) == 0) {
517 setsockopt(new_fd, SOL_SOCKET, SO_RCVTIMEO, &ts,len);
521 if(getsockopt(
fd, SOL_SOCKET, SO_SNDTIMEO, &ts, &len) == 0) {
522 setsockopt(new_fd, SOL_SOCKET, SO_SNDTIMEO, &ts,len);
527 if(dup2(new_fd,
fd) < 0)
533 tty_generic_udp_read_error_occured = 0;
538 IDLog(
"%s: Failed to create new session for fd %d: %s\n", __FUNCTION__,
fd, strerror(
errno));
541 perror(
"tty_reset_udp_session");
548int tty_read(
int fd,
char *buf,
int nbytes,
int timeout,
int *nbytes_read)
553int tty_read_expanded(
int fd,
char *buf,
int nbytes,
long timeout_seconds,
long timeout_microseconds,
int *nbytes_read)
562 int numBytesToRead = nbytes;
571 IDLog(
"%s: Request to read %d bytes with %ld s, %ld us timeout for fd %d\n", __FUNCTION__, nbytes, timeout_seconds, timeout_microseconds,
fd);
573 char geminiBuffer[257]={0};
576 if (tty_gemini_udp_format)
578 numBytesToRead = nbytes + 8;
579 buffer = geminiBuffer;
582 int zero_read_count = 0;
583 const int MAX_ZERO_READS = 3;
585 while (numBytesToRead > 0)
588 if(tty_generic_udp_format)
589 tty_generic_udp_read_error_occured = 1;
593 bytesRead = read(
fd, buffer + (*nbytes_read), ((uint32_t)numBytesToRead));
601 if (zero_read_count >= MAX_ZERO_READS)
604 IDLog(
"%s: Device not responding (zero bytes read %d times)\n", __FUNCTION__, MAX_ZERO_READS);
615 IDLog(
"%d bytes read and %d bytes remaining...\n", bytesRead, numBytesToRead - bytesRead);
617 for (i = *nbytes_read; i < (*nbytes_read + bytesRead); i++)
618 IDLog(
"%s: buffer[%d]=%#X (%c)\n", __FUNCTION__, i, (
unsigned char)buf[i], buf[i]);
621 if (*nbytes_read == 0 && tty_clear_trailing_lf && *buffer == 0x0A)
624 IDLog(
"%s: Cleared LF char left in buf\n", __FUNCTION__);
626 memcpy(buffer, buffer+1,bytesRead);
630 *nbytes_read += bytesRead;
631 numBytesToRead -= bytesRead;
635 if (tty_gemini_udp_format)
637 int *intSizedBuffer = (
int *)geminiBuffer;
638 if (intSizedBuffer[0] != tty_sequence_number)
641 return tty_read_expanded(
fd, buf, nbytes, timeout_seconds, timeout_microseconds, nbytes_read);
645 memcpy(buf, geminiBuffer+8, *nbytes_read);
664 char readBuffer[257]={0};
673 uint8_t *read_char = 0;
676 IDLog(
"%s: Request to read until stop char '%#02X' with %ld s %ld us timeout for fd %d\n", __FUNCTION__, stop_char, timeout_seconds, timeout_microseconds,
fd);
678 if (tty_gemini_udp_format)
682 bytesRead = read(
fd, readBuffer, 255);
687 int *intSizedBuffer = (
int *)readBuffer;
688 if (intSizedBuffer[0] != tty_sequence_number)
694 for (
int index = 8; index < bytesRead; index++)
698 if (*(readBuffer+index) == stop_char)
700 strncpy(buf, readBuffer+8, *nbytes_read);
705 else if (tty_generic_udp_format)
708 tty_generic_udp_read_error_occured = 1;
711 bytesRead = read(
fd, readBuffer, 255);
714 for (
int index = 0; index < bytesRead; index++)
718 if (*(readBuffer+index) == stop_char)
720 strncpy(buf, readBuffer, *nbytes_read);
732 read_char = (uint8_t*)(buf + *nbytes_read);
733 bytesRead = read(
fd, read_char, 1);
739 IDLog(
"%s: buffer[%d]=%#X (%c)\n", __FUNCTION__, (*nbytes_read), *read_char, *read_char);
741 if (!(tty_clear_trailing_lf && *read_char == 0X0A && *nbytes_read == 0))
745 IDLog(
"%s: Cleared LF char left in buf\n", __FUNCTION__);
748 if (*read_char == stop_char) {
774 if (tty_gemini_udp_format || tty_generic_udp_format)
780 uint8_t *read_char = 0;
781 memset(buf, 0, nsize);
784 IDLog(
"%s: Request to read until stop char '%#02X' with %ld s %ld us timeout for fd %d\n", __FUNCTION__, stop_char, timeout_seconds, timeout_microseconds,
fd);
791 read_char = (uint8_t*)(buf + *nbytes_read);
792 bytesRead = read(
fd, read_char, 1);
798 IDLog(
"%s: buffer[%d]=%#X (%c)\n", __FUNCTION__, (*nbytes_read), *read_char, *read_char);
800 if (!(tty_clear_trailing_lf && *read_char == 0X0A && *nbytes_read == 0))
804 IDLog(
"%s: Cleared LF char left in buf\n", __FUNCTION__);
807 if (*read_char == stop_char)
809 else if (*nbytes_read >= nsize)
817#if defined(BSD) && !defined(__GNU__)
819int tty_connect(
const char *
device,
int bit_rate,
int word_size,
int parity,
int stop_bits,
int *
fd)
831 t_fd = open(
device, O_RDWR | O_NOCTTY | O_NONBLOCK);
843 if (ioctl(t_fd, TIOCEXCL) == -1)
852 if (fcntl(t_fd, F_SETFL, 0) == -1)
876 case 0: bps = B0;
break;
877 case 50: bps = B50;
break;
878 case 75: bps = B75;
break;
879 case 110: bps = B110;
break;
880 case 134: bps = B134;
break;
881 case 150: bps = B150;
break;
882 case 200: bps = B200;
break;
883 case 300: bps = B300;
break;
884 case 600: bps = B600;
break;
885 case 1200: bps = B1200;
break;
886 case 1800: bps = B1800;
break;
887 case 2400: bps = B2400;
break;
888 case 4800: bps = B4800;
break;
889 case 9600: bps = B9600;
break;
890 case 19200: bps = B19200;
break;
891 case 38400: bps = B38400;
break;
892 case 57600: bps = B57600;
break;
893 case 115200: bps = B115200;
break;
894 case 230400: bps = B230400;
break;
895#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
896 case 460800: bps = B460800;
break;
897 case 576000: bps = B576000;
break;
898 case 921600: bps = B921600;
break;
901 if (snprintf(msg,
sizeof(msg),
"tty_connect: %d is not a valid bit rate.", bit_rate) < 0)
917 if (snprintf(msg,
sizeof(msg),
"tty_connect: %d is not a valid data bit count.", word_size) < 0)
937 if (snprintf(msg,
sizeof(msg),
"tty_connect: %d is not a valid parity selection value.", parity) < 0)
954 if (snprintf(msg,
sizeof(msg),
"tty_connect: %d is not a valid stop bit count.", stop_bits) < 0)
962#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
968 speed_t speed = 14400;
969 if (ioctl(t_fd, IOSSIOSPEED, &speed) == -1)
971 IDLog(
"Error calling ioctl(..., IOSSIOSPEED, ...) - %s(%d).\n", strerror(
errno),
errno);
983 if (ioctl(t_fd, TIOCMGET, &handshake) == -1)
988 IDLog(
"Handshake lines currently set to %d\n", handshake);
990#if defined(MAC_OS_X_VERSION_10_3) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3)
991 unsigned long mics = 1UL;
999 if (ioctl(t_fd, IOSSDATALAT, &mics) == -1)
1034 int ignore_exclusive_close = strstr(
device,
"rfcomm") || strstr(
device,
"Bluetooth") || strstr(
device,
"virtualcom");
1038 for (i = 0 ; i < 3 ; i++)
1041 t_fd = open(
device, O_RDWR | O_NOCTTY | (ignore_exclusive_close ? 0 : O_CLOEXEC));
1060#if !defined(__CYGWIN__)
1063 if (ignore_exclusive_close == 0 && ioctl(t_fd, TIOCEXCL) == -1)
1065 perror(
"tty_connect: Error setting TIOCEXC.");
1074 perror(
"tty_connect: failed getting tty attributes.");
1083 case 0: bps = B0;
break;
1084 case 50: bps = B50;
break;
1085 case 75: bps = B75;
break;
1086 case 110: bps = B110;
break;
1087 case 134: bps = B134;
break;
1088 case 150: bps = B150;
break;
1089 case 200: bps = B200;
break;
1090 case 300: bps = B300;
break;
1091 case 600: bps = B600;
break;
1092 case 1200: bps = B1200;
break;
1093 case 1800: bps = B1800;
break;
1094 case 2400: bps = B2400;
break;
1095 case 4800: bps = B4800;
break;
1096 case 9600: bps = B9600;
break;
1097 case 19200: bps = B19200;
break;
1098 case 38400: bps = B38400;
break;
1099 case 57600: bps = B57600;
break;
1100 case 115200: bps = B115200;
break;
1101 case 230400: bps = B230400;
break;
1102 case 460800: bps = B460800;
break;
1103 case 576000: bps = B576000;
break;
1104 case 921600: bps = B921600;
break;
1106 if (snprintf(msg,
sizeof(msg),
"tty_connect: %d is not a valid bit rate.", bit_rate) < 0)
1115 perror(
"tty_connect: failed setting bit rate.");
1124 tty_setting.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | HUPCL | CRTSCTS);
1136 fprintf(stderr,
"Default\n");
1137 if (snprintf(msg,
sizeof(msg),
"tty_connect: %d is not a valid data bit count.", word_size) < 0)
1159 fprintf(stderr,
"Default1\n");
1160 if (snprintf(msg,
sizeof(msg),
"tty_connect: %d is not a valid parity selection value.", parity) < 0)
1178 fprintf(stderr,
"Default2\n");
1179 if (snprintf(msg,
sizeof(msg),
"tty_connect: %d is not a valid stop bit count.", stop_bits) < 0)
1190 tty_setting.c_iflag &= ~(PARMRK | ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON | IXANY);
1199 tty_setting.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG | IEXTEN | NOFLSH | TOSTOP);
1207 tcflush(t_fd, TCIOFLUSH);
1210 perror(
"tty_connect: failed setting attributes on serial port.");
1233 tcflush(
fd, TCIOFLUSH);
1248 snprintf(err_msg, err_msg_len,
"No Error");
1252 snprintf(err_msg, err_msg_len,
"Read Error: %s", strerror(
errno));
1256 snprintf(err_msg, err_msg_len,
"Write Error: %s", strerror(
errno));
1260 snprintf(err_msg, err_msg_len,
"Select Error: %s", strerror(
errno));
1264 snprintf(err_msg, err_msg_len,
"Timeout error");
1268 if (
errno == EACCES)
1269 snprintf(err_msg, err_msg_len,
1270 "Port failure Error: %s. Try adding your user to the dialout group and restart (sudo adduser "
1274 snprintf(err_msg, err_msg_len,
"Port failure Error: %s. Check if device is connected to this port.",
1280 snprintf(err_msg, err_msg_len,
"Parameter error");
1284 snprintf(err_msg, err_msg_len,
"%s", strerror(
errno));
1288 snprintf(err_msg, err_msg_len,
"Read overflow");
1292 snprintf(err_msg, err_msg_len,
"Port is busy");
1296 snprintf(err_msg, err_msg_len,
"Error: unrecognized error code");
1334 while (res < -180.0)
1343 if ((decdegrees >= 270.0) && (decdegrees <= 360.0))
1344 return (decdegrees - 360.0);
1345 if ((decdegrees >= 180.0) && (decdegrees < 270.0))
1346 return (180.0 - decdegrees);
1347 if ((decdegrees >= 90.0) && (decdegrees < 180.0))
1348 return (180.0 - decdegrees);
1352#if defined(HAVE_LIBNOVA)
1355 return range24(ln_get_apparent_sidereal_time(ln_get_julian_from_sys()) + longitude / 15.0);
1358void get_hrz_from_equ(
struct ln_equ_posn *
object,
struct ln_lnlat_posn *observer,
double JD,
struct ln_hrz_posn *position)
1360 ln_get_hrz_from_equ(
object, observer, JD, position);
1361 position->az -= 180;
1362 if (position->az < 0)
1363 position->az += 360;
1366void get_equ_from_hrz(
struct ln_hrz_posn *
object,
struct ln_lnlat_posn *observer,
double JD,
struct ln_equ_posn *position)
1368 struct ln_hrz_posn libnova_object;
1369 libnova_object.az =
object->az + 180;
1370 if (libnova_object.az > 360)
1371 libnova_object.az -= 360;
1372 libnova_object.alt =
object->alt;
1374 ln_get_equ_from_hrz(&libnova_object, observer, JD, position);
1381 double HA = sideral_time -
ra;
1389 Dec *=
M_PI / 180.0;
1390 Lat *=
M_PI / 180.0;
1391 alt = asin(sin(Dec) * sin(Lat) + cos(Dec) * cos(Lat) * cos(Ha));
1392 az = acos((sin(Dec) - sin(alt)*sin(Lat)) / (cos(alt) * cos(Lat)));
1393 alt *= 180.0 /
M_PI;
1403 Lat *=
M_PI / 180.0;
1411 Alt *=
M_PI / 180.0;
1413 Lat *=
M_PI / 180.0;
1414 double ret = cos(Lat) * cos(Az) / cos(Alt);
1415 ret *= 180.0 /
M_PI;
1431 return as *
M_PI / (60.0*60.0*12.0);
1436 return rad * (60.0*60.0*12.0) /
M_PI;
1441 return parallax_radius / sin(
as2rad(parsecs));
1451 double delta_mag = 0;
1452 for(
int l = 0; l < spectrum_size; l++) {
1453 delta_mag += spectrum[l] * mag_ratio * ref_spectrum[l] / spectrum[l];
1455 delta_mag /= spectrum_size;
1461 return delta_mag * ref_size;
1471 return orbit_radius*pow(star_drift*orbit_radius, 3)*3*star_mass;
1476 return pow(dropoff_ratio*pow(star_size, 2), 0.5);
1479double calc_photon_flux(
double rel_magnitude,
double filter_bandwidth,
double wavelength,
double steradian)
1481 return pow(10, rel_magnitude*-0.4)*(
LUMEN(wavelength)*steradian*filter_bandwidth);
1484double calc_rel_magnitude(
double photon_flux,
double filter_bandwidth,
double wavelength,
double steradian)
1486 return pow(10, 1.0/(photon_flux/(
LUMEN(wavelength)*steradian*filter_bandwidth)))/-0.4;
1491 return sqrt(delta_dist) * delta_mag;
1497 alt *=
M_PI / 180.0;
1498 uvresult[0] = (baseline[0] * sin(az) + baseline[1] * cos(az));
1499 uvresult[1] = (baseline[1] * sin(alt) * sin(az) - baseline[0] * sin(alt) * cos(az) + baseline[2] * cos(alt));
1500 uvresult[0] *=
AIRY / wavelength;
1501 uvresult[1] *=
AIRY / wavelength;
1507 alt *=
M_PI / 180.0;
1508 return cos(az) * baseline[1] * cos(alt) - baseline[0] * sin(az) * cos(alt) + sin(alt) * baseline[2];
1511#if defined(_MSC_VER)
std::string fmt(const char *fmt,...)
void get_alt_az_coordinates(double Ha, double Dec, double Lat, double *Alt, double *Az)
get_alt_az_coordinates Returns alt-azimuth coordinates of an object
double estimate_secondary_size(double star_size, double dropoff_ratio)
estimate the size of an object occulting a star in star_size units.
void tty_set_generic_udp_format(int enabled)
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...
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.
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...
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
void getSexComponentsIID(double value, int *d, int *m, double *s)
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double. x can be anything non-numeric. Any missing A,...
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.
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...
void tty_set_debug(int debug)
tty_set_debug Enable or disable debug which prints verbose information.
double estimate_distance(double parsecs, double parallax_radius)
estimate_distance Convert parallax arcseconds into meters
double estimate_absolute_magnitude(double delta_dist, double delta_mag)
estimate_absolute_magnitude Returns an estimation of the absolute magnitude of an object given its di...
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
double estimate_field_rotation(double HA, double rate)
estimate_field_rotation Returns an estimation of the field rotation rate of the object
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.
int tty_disconnect(int fd)
Closes a tty connection and flushes the bus.
void IDLog(const char *fmt,...)
double estimate_field_rotation_rate(double Alt, double Az, double Lat)
estimate_field_rotation_rate Returns an estimation of the field rotation rate of the object
void tty_set_auto_reset_udp_session(int flag)
automatically reset UDP session on write
int tty_timeout_microseconds(int fd, long timeout_seconds, long timeout_microseconds)
double rangeHA(double r)
rangeHA Limits the hour angle value to be between -12 —> 12
void getSexComponents(double value, int *d, int *m, int *s)
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
double calc_star_mass(double delta_mag, double ref_size)
double range180(double r)
range180 Limits an angle to be between -180 to +180 degrees
double m2au(double m)
m2au Convert meters into astronomical units
double range24(double r)
range24 Limits a number to be between 0-24 range.
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
const char * indi_timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
int tty_timeout(int fd, int timeout)
double as2rad(double as)
as2rad Convert arcseconds into radians
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
double rangeDec(double decdegrees)
rangeDec Limits declination value to be in -90 to 90 range.
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
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
void tty_reset_udp_session(int fd, int only_if_timeout_happened)
create new UDP session to prevent packet conflict
double time_ns()
Get a unix timestamp with nanosecond precision.
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
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[].
int numberFormat(char *buf, const char *format, double value)
Fill buffer with properly formatted INumber string.
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
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
void tty_clr_trailing_read_lf(int enabled)
void tty_set_gemini_udp_format(int enabled)
int tty_nread_section_expanded(int fd, char *buf, int nsize, char stop_char, long timeout_seconds, long timeout_microseconds, int *nbytes_read)
read buffer from terminal with a delimiter
double get_local_hour_angle(double sideral_time, double ra)
get_local_hour_angle Returns local hour angle of an object
double estimate_geocentric_elevation(double Lat, double El)
estimate_geocentric_elevation Returns an estimation of the actual geocentric elevation
double rad2as(double rad)
rad2as Convert radians into arcseconds
Implementations for common driver routines.
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sidereal time given longitude and system clock.
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.
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
Interface to the reference INDI C API device implementation on the Device Driver side.
#define LUMEN(wavelength)
#define DOPPLER(shift, speed)
#define EARTHRADIUSEQUATORIAL
#define REDSHIFT(wavelength, reference)
@ error
throw a parse_error exception in case of a tag
struct termios tty_setting