From fd37853735f8efa15e2390042148edc607068ca9 Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Fri, 19 Jun 2026 14:47:06 +0300 Subject: [PATCH] cont --- Daemons/10micron_stellarium/angles.c | 83 +++++++++++++++++++++--- Daemons/10micron_stellarium/mount.c | 40 +++++++++++- Daemons/10micron_stellarium/mount.h | 9 ++- Daemons/10micron_stellarium/server.c | 5 ++ Daemons/10micron_stellarium/stellarium.c | 20 ++++-- 5 files changed, 141 insertions(+), 16 deletions(-) diff --git a/Daemons/10micron_stellarium/angles.c b/Daemons/10micron_stellarium/angles.c index 043757c..424d48d 100644 --- a/Daemons/10micron_stellarium/angles.c +++ b/Daemons/10micron_stellarium/angles.c @@ -212,7 +212,10 @@ void r2sDMS(double radians, char *dms, int len){ bool get_MJDt(struct timeval *tval, sMJD_t *MJD){ struct tm tms; double tSeconds; - if(!MJD) return false; + if(!MJD){ + WARNX("get_MJDt(): no input data"); + return false; + } if(!tval){ struct timespec ts; if(clock_gettime(CLOCK_REALTIME, &ts)){ @@ -231,15 +234,23 @@ bool get_MJDt(struct timeval *tval, sMJD_t *MJD){ d = tms.tm_mday; double utc1, utc2; /* UTC date. */ - if(eraDtf2d("UTC", y, m, d, tms.tm_hour, tms.tm_min, tSeconds, &utc1, &utc2) < 0) return false; - if(!MJD) return false; + if(eraDtf2d("UTC", y, m, d, tms.tm_hour, tms.tm_min, tSeconds, &utc1, &utc2) < 0){ + WARNX("get_MJDt(): eraDtf2d() error"); + return false; + } MJD->MJD = utc1 - ERFA_DJM0 + utc2; MJD->utc1 = utc1; MJD->utc2 = 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"); - 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"); 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 rv = 0.0; // radial velocity (km/s, positive if receding) sMJD_t MJD; - if(!tval || !p2000) return false; - if(get_MJDt(tval, &MJD)) return false; + if(!p2000){ + WARNX("get_ObsPlace(): no input coordinates"); + return false; + } + if(!get_MJDt(tval, &MJD)) return false; /* Effective wavelength (microns) */ double wl = 0.55; /* 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; weather_data_t weath; if(get_weather_data(&weath)){ + WARNX("Can't get weather - use default values"); + }else{ p = 1.3332239 * weath.pressure; 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, pr, pd, px, rv, MJD.utc1, MJD.utc2, @@ -317,6 +334,56 @@ bool get_ObsPlace(struct timeval *tval, polarCrds_t *p2000, polarCrds_t *pnow, h 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 typedef enum { diff --git a/Daemons/10micron_stellarium/mount.c b/Daemons/10micron_stellarium/mount.c index e332002..a0fc91a 100644 --- a/Daemons/10micron_stellarium/mount.c +++ b/Daemons/10micron_stellarium/mount.c @@ -20,8 +20,8 @@ #include #include #include +#include -#include "angles.h" #include "emulation.h" #include "mount.h" @@ -40,8 +40,31 @@ static sl_ringbuffer_t *RBin = NULL; static atomic_int mountstatus = MNT_S_ERROR; // input and current target coordinates -polarCrds_t InpCoords = {0}, TagCoords = {0}; -horizCrds_t InpHoriz = {0}; +static polarCrds_t InpCoords = {0}, // input as user give (for epoch InpMJD) + 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 /** @@ -52,6 +75,7 @@ horizCrds_t InpHoriz = {0}; bool mount_setInpHA(double ha){ if(ha < 0. || ha >= 24.) return false; InpCoords.ha = HRS2RAD(ha); + InpCTime = sl_dtime(); return true; } /** @@ -62,6 +86,7 @@ bool mount_setInpHA(double ha){ bool mount_setInpRA(double ra){ if(ra < 0. || ra >= 360.) return false; InpCoords.ra = DEG2RAD(ra); + InpCTime = sl_dtime(); return true; } /** @@ -72,6 +97,7 @@ bool mount_setInpRA(double ra){ bool mount_setInpDec(double dec){ if(dec < -90. || dec > 90.) return false; InpCoords.dec = DEG2RAD(dec); + InpCTime = sl_dtime(); return true; } /** @@ -82,6 +108,7 @@ bool mount_setInpDec(double dec){ bool mount_setInpA(double A){ if(A < 0. || A >= 360.) return false; InpHoriz.az = DEG2RAD(A); + InpHTime = sl_dtime(); return true; } /** @@ -92,6 +119,13 @@ bool mount_setInpA(double A){ bool mount_setInpZ(double Z){ if(Z < 0 || Z > 90) return false; InpHoriz.zd = DEG2RAD(Z); + InpHTime = sl_dtime(); + return true; +} +// without checking +bool mount_setInpMJD(double m){ + InpMJD = m; + InpMTime = sl_dtime(); return true; } diff --git a/Daemons/10micron_stellarium/mount.h b/Daemons/10micron_stellarium/mount.h index 65eb135..19863c7 100644 --- a/Daemons/10micron_stellarium/mount.h +++ b/Daemons/10micron_stellarium/mount.h @@ -18,7 +18,7 @@ #pragma once -#include +#include "angles.h" // mount statuses typedef enum{ @@ -45,6 +45,13 @@ bool mount_setInpRA(double ra); bool mount_setInpDec(double dec); bool mount_setInpA(double A); 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_dev(char *dev, int speed, int timeout); diff --git a/Daemons/10micron_stellarium/server.c b/Daemons/10micron_stellarium/server.c index 460eb0b..6c05a5a 100644 --- a/Daemons/10micron_stellarium/server.c +++ b/Daemons/10micron_stellarium/server.c @@ -138,6 +138,11 @@ bool server_check(server_sock_t *sockt){ close(stellarium_sockfd); 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); LOGMSG("Prepared stellarium socket: %s", sockt->stellport); DBG("Prepared stellarium socket: %s", sockt->stellport); diff --git a/Daemons/10micron_stellarium/stellarium.c b/Daemons/10micron_stellarium/stellarium.c index 9411721..e232a93 100644 --- a/Daemons/10micron_stellarium/stellarium.c +++ b/Daemons/10micron_stellarium/stellarium.c @@ -129,6 +129,7 @@ static bool proc_data(uint8_t *data, ssize_t len){ double tagRA = RA2DEG(ra), tagDec = DEC2DEG(dec); 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); +#if 0 // check RA/DEC horizCrds_t hnow; // without refraction polarCrds_t p2000, pnow; @@ -141,7 +142,8 @@ static bool proc_data(uint8_t *data, ssize_t len){ } tagRA = RAD2DEG(pnow.ra - pnow.eo); 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)); if(!send_data((uint8_t*)&dout, sizeof(outdata), sock)) break; //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 uint8_t buff[BUFLEN]; ssize_t rd = read(sock, buff, BUFLEN-1); @@ -198,7 +203,10 @@ static void *handle_socket(void *sockd){ buff[rd] = 0; DBG("read %zd (%s)", rd, buff); if(!proc_data(buff, rd)) dout.status = -1; - else dout.status = 0; + else{ + DBG("sent OK"); + dout.status = 0; + } } close(sock); return NULL; @@ -226,9 +234,13 @@ static void* start(void *F){ socklen_t size = sizeof(struct sockaddr_in); struct sockaddr_in myaddr; int newsock; + DBG("ACCEPT"); newsock = accept(sockfd, (struct sockaddr*)&myaddr, &size); if(newsock <= 0){ - if(errno == EAGAIN) continue; // nothing available + if(errno == EAGAIN){ + usleep(1000); + continue; // nothing available + } WARN("accept()"); LOGWARN("Stellarium socket error in accept()"); sleep(1);