mirror of
https://github.com/eddyem/small_tel.git
synced 2026-06-21 11:26:30 +03:00
cont
This commit is contained in:
@@ -212,7 +212,10 @@ void r2sDMS(double radians, char *dms, int len){
|
|||||||
bool get_MJDt(struct timeval *tval, sMJD_t *MJD){
|
bool get_MJDt(struct timeval *tval, sMJD_t *MJD){
|
||||||
struct tm tms;
|
struct tm tms;
|
||||||
double tSeconds;
|
double tSeconds;
|
||||||
if(!MJD) return false;
|
if(!MJD){
|
||||||
|
WARNX("get_MJDt(): no input data");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if(!tval){
|
if(!tval){
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
if(clock_gettime(CLOCK_REALTIME, &ts)){
|
if(clock_gettime(CLOCK_REALTIME, &ts)){
|
||||||
@@ -231,15 +234,23 @@ bool get_MJDt(struct timeval *tval, sMJD_t *MJD){
|
|||||||
d = tms.tm_mday;
|
d = tms.tm_mday;
|
||||||
double utc1, utc2;
|
double utc1, utc2;
|
||||||
/* UTC date. */
|
/* UTC date. */
|
||||||
if(eraDtf2d("UTC", y, m, d, tms.tm_hour, tms.tm_min, tSeconds, &utc1, &utc2) < 0) return false;
|
if(eraDtf2d("UTC", y, m, d, tms.tm_hour, tms.tm_min, tSeconds, &utc1, &utc2) < 0){
|
||||||
if(!MJD) return false;
|
WARNX("get_MJDt(): eraDtf2d() error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
MJD->MJD = utc1 - ERFA_DJM0 + utc2;
|
MJD->MJD = utc1 - ERFA_DJM0 + utc2;
|
||||||
MJD->utc1 = utc1;
|
MJD->utc1 = utc1;
|
||||||
MJD->utc2 = utc2;
|
MJD->utc2 = utc2;
|
||||||
//DBG("UTC(m): %g, %.8f\n", utc1 - 2400000.5, utc2);
|
//DBG("UTC(m): %g, %.8f\n", utc1 - 2400000.5, utc2);
|
||||||
if(eraUtctai(utc1, utc2, &MJD->tai1, &MJD->tai2)) return false;
|
if(eraUtctai(utc1, utc2, &MJD->tai1, &MJD->tai2)){
|
||||||
|
WARNX("get_MJDt(): eraUtctai() error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
//DBG("TAI");
|
//DBG("TAI");
|
||||||
if(eraTaitt(MJD->tai1, MJD->tai2, &MJD->tt1, &MJD->tt2)) return false;
|
if(eraTaitt(MJD->tai1, MJD->tai2, &MJD->tt1, &MJD->tt2)){
|
||||||
|
WARNX("get_MJDt(): eraTaitt() error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
//DBG("TT");
|
//DBG("TT");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -282,8 +293,11 @@ bool get_ObsPlace(struct timeval *tval, polarCrds_t *p2000, polarCrds_t *pnow, h
|
|||||||
double px = 0.0; // parallax (arcsec)
|
double px = 0.0; // parallax (arcsec)
|
||||||
double rv = 0.0; // radial velocity (km/s, positive if receding)
|
double rv = 0.0; // radial velocity (km/s, positive if receding)
|
||||||
sMJD_t MJD;
|
sMJD_t MJD;
|
||||||
if(!tval || !p2000) return false;
|
if(!p2000){
|
||||||
if(get_MJDt(tval, &MJD)) return false;
|
WARNX("get_ObsPlace(): no input coordinates");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!get_MJDt(tval, &MJD)) return false;
|
||||||
/* Effective wavelength (microns) */
|
/* Effective wavelength (microns) */
|
||||||
double wl = 0.55;
|
double wl = 0.55;
|
||||||
/* ICRS to observed. */
|
/* ICRS to observed. */
|
||||||
@@ -291,9 +305,12 @@ bool get_ObsPlace(struct timeval *tval, polarCrds_t *p2000, polarCrds_t *pnow, h
|
|||||||
double p = 1000., t = 0., h = place.salt;
|
double p = 1000., t = 0., h = place.salt;
|
||||||
weather_data_t weath;
|
weather_data_t weath;
|
||||||
if(get_weather_data(&weath)){
|
if(get_weather_data(&weath)){
|
||||||
|
WARNX("Can't get weather - use default values");
|
||||||
|
}else{
|
||||||
p = 1.3332239 * weath.pressure;
|
p = 1.3332239 * weath.pressure;
|
||||||
t = weath.exttemp;
|
t = weath.exttemp;
|
||||||
}else WARNX("Can't get weather - use default values");
|
DBG("pressure=%.1fhPa, temperature=%.1fdegC", p, t);
|
||||||
|
}
|
||||||
if(eraAtco13(p2000->ra, p2000->dec,
|
if(eraAtco13(p2000->ra, p2000->dec,
|
||||||
pr, pd, px, rv,
|
pr, pd, px, rv,
|
||||||
MJD.utc1, MJD.utc2,
|
MJD.utc1, MJD.utc2,
|
||||||
@@ -317,6 +334,56 @@ bool get_ObsPlace(struct timeval *tval, polarCrds_t *p2000, polarCrds_t *pnow, h
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert geocentric coordinates (nowadays, CIRS) to mean (JD2000, ICRS)
|
||||||
|
* in, out - input and output coordinates
|
||||||
|
* @return false if failed
|
||||||
|
*/
|
||||||
|
bool JnowtoJ2000(const polarCrds_t *in, polarCrds_t *out){
|
||||||
|
bool ret = false;
|
||||||
|
DBG("appRa: %gdegr, appDecl: %gdegr", RAD2DEG(in->ra), RAD2DEG(in->dec));
|
||||||
|
#define ERFA(f, ...) do{if(f(__VA_ARGS__)){WARNX("Error in " #f); goto rtn;}}while(0)
|
||||||
|
sMJD_t MJD;
|
||||||
|
if(!get_MJDt(NULL, &MJD)) return false;
|
||||||
|
double ri = 0., di = 0., eo = 0.;
|
||||||
|
eraAtic13(in->ra, in->dec, MJD.tt1, MJD.tt2, &ri, &di, &eo);
|
||||||
|
if(out){
|
||||||
|
out->ha = 0.; out->eo = 0.;
|
||||||
|
out->ra = eraAnp(ri + eo);
|
||||||
|
out->dec = di;
|
||||||
|
DBG("JnowtoJ2000: ra=%gdeg, dec=%gdeg", RAD2DEG(out->ra), RAD2DEG(out->dec));
|
||||||
|
}
|
||||||
|
ret = true;
|
||||||
|
#undef ERFA
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief J2000toJnow - convert ra/dec between epochs
|
||||||
|
* @param in - J2000 (degrees)
|
||||||
|
* @param out - Jnow (degrees)
|
||||||
|
* @return false if failed
|
||||||
|
*/
|
||||||
|
bool J2000toJnow(const polarCrds_t *in, polarCrds_t *out){
|
||||||
|
DBG("J200RA: %gdegr, J200Dec: %gdegr", RAD2DEG(in->ra), RAD2DEG(in->dec));
|
||||||
|
sMJD_t MJD;
|
||||||
|
if(!in) return false;
|
||||||
|
if(!get_MJDt(NULL, &MJD)) return false;
|
||||||
|
// these values could be changed (e.g. by user's input)
|
||||||
|
double pr = 0.0; // RA proper motion (radians/year)
|
||||||
|
double pd = 0.0; // Dec proper motion (radians/year)
|
||||||
|
double px = 0.0; // parallax (arcsec)
|
||||||
|
double rv = 0.0; // radial velocity (km/s, positive if receding)
|
||||||
|
double ri, di, eo;
|
||||||
|
eraAtci13(in->ra, in->dec, pr, pd, px, rv, MJD.tt1, MJD.tt2, &ri, &di, &eo);
|
||||||
|
if(out){
|
||||||
|
out->ra = eraAnp(ri - eo);
|
||||||
|
out->dec = di;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
#include "angles.h"
|
|
||||||
#include "emulation.h"
|
#include "emulation.h"
|
||||||
#include "mount.h"
|
#include "mount.h"
|
||||||
|
|
||||||
@@ -40,8 +40,31 @@ static sl_ringbuffer_t *RBin = NULL;
|
|||||||
static atomic_int mountstatus = MNT_S_ERROR;
|
static atomic_int mountstatus = MNT_S_ERROR;
|
||||||
|
|
||||||
// input and current target coordinates
|
// input and current target coordinates
|
||||||
polarCrds_t InpCoords = {0}, TagCoords = {0};
|
static polarCrds_t InpCoords = {0}, // input as user give (for epoch InpMJD)
|
||||||
horizCrds_t InpHoriz = {0};
|
TagCoords = {0}; // target for Jnow after command "point to input"
|
||||||
|
static horizCrds_t InpHoriz = {0};
|
||||||
|
// input MJD (Modified Julian Date: started from ERFA_DJM0==2400000.5
|
||||||
|
static double InpMJD = ERFA_DJM00; // J2000
|
||||||
|
// times of coords/mjd change
|
||||||
|
static double InpCTime = 0., TagTime = 0., InpHTime = 0., InpMTime = 0.;
|
||||||
|
|
||||||
|
// return time of modification
|
||||||
|
double mount_getInpCoords(polarCrds_t *c){
|
||||||
|
if(c) *c = InpCoords;
|
||||||
|
return InpCTime;
|
||||||
|
}
|
||||||
|
double mount_getTagCoords(polarCrds_t *c){
|
||||||
|
if(c) *c = TagCoords;
|
||||||
|
return TagTime;
|
||||||
|
}
|
||||||
|
double mount_getInpMJD(double *MJD){
|
||||||
|
if(MJD) *MJD = InpMJD;
|
||||||
|
return InpMTime;
|
||||||
|
}
|
||||||
|
double mount_getInpHor(horizCrds_t *c){
|
||||||
|
if(c) *c = InpHoriz;
|
||||||
|
return InpHTime;
|
||||||
|
}
|
||||||
|
|
||||||
// change input coordinates
|
// change input coordinates
|
||||||
/**
|
/**
|
||||||
@@ -52,6 +75,7 @@ horizCrds_t InpHoriz = {0};
|
|||||||
bool mount_setInpHA(double ha){
|
bool mount_setInpHA(double ha){
|
||||||
if(ha < 0. || ha >= 24.) return false;
|
if(ha < 0. || ha >= 24.) return false;
|
||||||
InpCoords.ha = HRS2RAD(ha);
|
InpCoords.ha = HRS2RAD(ha);
|
||||||
|
InpCTime = sl_dtime();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -62,6 +86,7 @@ bool mount_setInpHA(double ha){
|
|||||||
bool mount_setInpRA(double ra){
|
bool mount_setInpRA(double ra){
|
||||||
if(ra < 0. || ra >= 360.) return false;
|
if(ra < 0. || ra >= 360.) return false;
|
||||||
InpCoords.ra = DEG2RAD(ra);
|
InpCoords.ra = DEG2RAD(ra);
|
||||||
|
InpCTime = sl_dtime();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +97,7 @@ bool mount_setInpRA(double ra){
|
|||||||
bool mount_setInpDec(double dec){
|
bool mount_setInpDec(double dec){
|
||||||
if(dec < -90. || dec > 90.) return false;
|
if(dec < -90. || dec > 90.) return false;
|
||||||
InpCoords.dec = DEG2RAD(dec);
|
InpCoords.dec = DEG2RAD(dec);
|
||||||
|
InpCTime = sl_dtime();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -82,6 +108,7 @@ bool mount_setInpDec(double dec){
|
|||||||
bool mount_setInpA(double A){
|
bool mount_setInpA(double A){
|
||||||
if(A < 0. || A >= 360.) return false;
|
if(A < 0. || A >= 360.) return false;
|
||||||
InpHoriz.az = DEG2RAD(A);
|
InpHoriz.az = DEG2RAD(A);
|
||||||
|
InpHTime = sl_dtime();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -92,6 +119,13 @@ bool mount_setInpA(double A){
|
|||||||
bool mount_setInpZ(double Z){
|
bool mount_setInpZ(double Z){
|
||||||
if(Z < 0 || Z > 90) return false;
|
if(Z < 0 || Z > 90) return false;
|
||||||
InpHoriz.zd = DEG2RAD(Z);
|
InpHoriz.zd = DEG2RAD(Z);
|
||||||
|
InpHTime = sl_dtime();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// without checking
|
||||||
|
bool mount_setInpMJD(double m){
|
||||||
|
InpMJD = m;
|
||||||
|
InpMTime = sl_dtime();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <usefull_macros.h>
|
#include "angles.h"
|
||||||
|
|
||||||
// mount statuses
|
// mount statuses
|
||||||
typedef enum{
|
typedef enum{
|
||||||
@@ -45,6 +45,13 @@ bool mount_setInpRA(double ra);
|
|||||||
bool mount_setInpDec(double dec);
|
bool mount_setInpDec(double dec);
|
||||||
bool mount_setInpA(double A);
|
bool mount_setInpA(double A);
|
||||||
bool mount_setInpZ(double Z);
|
bool mount_setInpZ(double Z);
|
||||||
|
bool mount_setInpMJD(double m);
|
||||||
|
|
||||||
|
double mount_getInpCoords(polarCrds_t *c);
|
||||||
|
double mount_getTagCoords(polarCrds_t *c);
|
||||||
|
double mount_getInpMJD(double *MJD);
|
||||||
|
double mount_getInpHor(horizCrds_t *c);
|
||||||
|
|
||||||
|
|
||||||
bool mount_set_name(const char *name);
|
bool mount_set_name(const char *name);
|
||||||
bool mount_set_dev(char *dev, int speed, int timeout);
|
bool mount_set_dev(char *dev, int speed, int timeout);
|
||||||
|
|||||||
@@ -138,6 +138,11 @@ bool server_check(server_sock_t *sockt){
|
|||||||
close(stellarium_sockfd);
|
close(stellarium_sockfd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
int enable = 0;
|
||||||
|
if(ioctl(stellarium_sockfd, FIONBIO, (void *)&enable) < 0){ // make socket blocking again
|
||||||
|
WARN("ioctl()");
|
||||||
|
LOGERR("Can't make stellarium socket blocking");
|
||||||
|
}
|
||||||
DBG("stellarium_sockfd=%d", stellarium_sockfd);
|
DBG("stellarium_sockfd=%d", stellarium_sockfd);
|
||||||
LOGMSG("Prepared stellarium socket: %s", sockt->stellport);
|
LOGMSG("Prepared stellarium socket: %s", sockt->stellport);
|
||||||
DBG("Prepared stellarium socket: %s", sockt->stellport);
|
DBG("Prepared stellarium socket: %s", sockt->stellport);
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ static bool proc_data(uint8_t *data, ssize_t len){
|
|||||||
double tagRA = RA2DEG(ra), tagDec = DEC2DEG(dec);
|
double tagRA = RA2DEG(ra), tagDec = DEC2DEG(dec);
|
||||||
DBG("RA: %u (%g degr), DEC: %d (%g degr)", ra, tagRA, dec, tagDec);
|
DBG("RA: %u (%g degr), DEC: %d (%g degr)", ra, tagRA, dec, tagDec);
|
||||||
LOGMSG("(stellarium) RA: %u (%g degr), DEC: %d (%g degr)", ra, tagRA, dec, tagDec);
|
LOGMSG("(stellarium) RA: %u (%g degr), DEC: %d (%g degr)", ra, tagRA, dec, tagDec);
|
||||||
|
#if 0
|
||||||
// check RA/DEC
|
// check RA/DEC
|
||||||
horizCrds_t hnow; // without refraction
|
horizCrds_t hnow; // without refraction
|
||||||
polarCrds_t p2000, pnow;
|
polarCrds_t p2000, pnow;
|
||||||
@@ -141,7 +142,8 @@ static bool proc_data(uint8_t *data, ssize_t len){
|
|||||||
}
|
}
|
||||||
tagRA = RAD2DEG(pnow.ra - pnow.eo);
|
tagRA = RAD2DEG(pnow.ra - pnow.eo);
|
||||||
tagDec = RAD2DEG(pnow.dec);
|
tagDec = RAD2DEG(pnow.dec);
|
||||||
return (mount_setInpRA(tagRA) && mount_setInpDec(tagDec));
|
#endif
|
||||||
|
return (mount_setInpRA(tagRA) && mount_setInpDec(tagDec) && mount_setInpMJD(ERFA_DJM00));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,7 +188,10 @@ static void *handle_socket(void *sockd){
|
|||||||
dout.dec = (int32_t)htole32(DEG2DEC(Decl));
|
dout.dec = (int32_t)htole32(DEG2DEC(Decl));
|
||||||
if(!send_data((uint8_t*)&dout, sizeof(outdata), sock)) break;
|
if(!send_data((uint8_t*)&dout, sizeof(outdata), sock)) break;
|
||||||
//DBG("sent ra = %g, dec = %g", RA2HRS(dout.ra), DEC2DEG(dout.dec));
|
//DBG("sent ra = %g, dec = %g", RA2HRS(dout.ra), DEC2DEG(dout.dec));
|
||||||
if(!sl_canread(sock)) continue;
|
if(!sl_canread(sock)){
|
||||||
|
sleep(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// fill incoming buffer
|
// fill incoming buffer
|
||||||
uint8_t buff[BUFLEN];
|
uint8_t buff[BUFLEN];
|
||||||
ssize_t rd = read(sock, buff, BUFLEN-1);
|
ssize_t rd = read(sock, buff, BUFLEN-1);
|
||||||
@@ -198,7 +203,10 @@ static void *handle_socket(void *sockd){
|
|||||||
buff[rd] = 0;
|
buff[rd] = 0;
|
||||||
DBG("read %zd (%s)", rd, buff);
|
DBG("read %zd (%s)", rd, buff);
|
||||||
if(!proc_data(buff, rd)) dout.status = -1;
|
if(!proc_data(buff, rd)) dout.status = -1;
|
||||||
else dout.status = 0;
|
else{
|
||||||
|
DBG("sent OK");
|
||||||
|
dout.status = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close(sock);
|
close(sock);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -226,9 +234,13 @@ static void* start(void *F){
|
|||||||
socklen_t size = sizeof(struct sockaddr_in);
|
socklen_t size = sizeof(struct sockaddr_in);
|
||||||
struct sockaddr_in myaddr;
|
struct sockaddr_in myaddr;
|
||||||
int newsock;
|
int newsock;
|
||||||
|
DBG("ACCEPT");
|
||||||
newsock = accept(sockfd, (struct sockaddr*)&myaddr, &size);
|
newsock = accept(sockfd, (struct sockaddr*)&myaddr, &size);
|
||||||
if(newsock <= 0){
|
if(newsock <= 0){
|
||||||
if(errno == EAGAIN) continue; // nothing available
|
if(errno == EAGAIN){
|
||||||
|
usleep(1000);
|
||||||
|
continue; // nothing available
|
||||||
|
}
|
||||||
WARN("accept()");
|
WARN("accept()");
|
||||||
LOGWARN("Stellarium socket error in accept()");
|
LOGWARN("Stellarium socket error in accept()");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user