mirror of
https://github.com/eddyem/small_tel.git
synced 2026-11-22 13:40:17 +03:00
add corrected coordinates conversion; add info and update
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#define CMD_GETALT ":GA#"
|
#define CMD_GETALT ":GA#"
|
||||||
#define CMD_GETAZIM ":GZ#"
|
#define CMD_GETAZIM ":GZ#"
|
||||||
#define CMD_GETDEC ":GD#"
|
#define CMD_GETDEC ":GD#"
|
||||||
|
#define CMD_GETINFO ":Ginfo#"
|
||||||
#define CMD_GETSTAT ":Gstat#"
|
#define CMD_GETSTAT ":Gstat#"
|
||||||
#define CMD_GETRA ":GR#"
|
#define CMD_GETRA ":GR#"
|
||||||
#define CMD_GETPS ":pS#"
|
#define CMD_GETPS ":pS#"
|
||||||
@@ -41,7 +42,8 @@
|
|||||||
// setters
|
// setters
|
||||||
#define CMD_SETALT ":Sa%s#"
|
#define CMD_SETALT ":Sa%s#"
|
||||||
#define CMD_SETDEC ":Sd%s#"
|
#define CMD_SETDEC ":Sd%s#"
|
||||||
#define CMD_SETTIME ":SLDT%04d-%02d-%02d,%02d:%02d:%02d.%02ld#"
|
//#define CMD_SETTIME ":SLDT%04d-%02d-%02d,%02d:%02d:%02d.%02ld#"
|
||||||
|
#define CMD_SETTIME ":SLDT%04d-%02d-%02d,%02d:%02d:%.2f#"
|
||||||
#define CMD_SETMINALT ":So%d#"
|
#define CMD_SETMINALT ":So%d#"
|
||||||
#define CMD_SETRA ":Sr%s#"
|
#define CMD_SETRA ":Sr%s#"
|
||||||
#define CMD_SETPRESSURE ":SRPRS%.1f#"
|
#define CMD_SETPRESSURE ":SRPRS%.1f#"
|
||||||
|
|||||||
@@ -392,11 +392,11 @@ bool get_LST(sMJD_t *mjd, double *LST){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief raha - convert HA to RA and vice versa
|
* @brief rahaNow - convert HA to RA and vice versa
|
||||||
* @param hara - HA or RA
|
* @param hara - HA or RA
|
||||||
* @return RA or HA
|
* @return RA or HA
|
||||||
*/
|
*/
|
||||||
double raha(double hara){
|
double rahaNow(double hara){
|
||||||
double LST;
|
double LST;
|
||||||
if(get_LST(NULL, &LST)) return eraAnp(LST - hara);
|
if(get_LST(NULL, &LST)) return eraAnp(LST - hara);
|
||||||
return 0.;
|
return 0.;
|
||||||
@@ -460,7 +460,7 @@ bool get_ObsPlace(struct timeval *tval, polarCrds_t *p2000, polarCrds_t *pnow, h
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
// used in two functions
|
// used in two functions
|
||||||
static bool J2000to_ep_(const polarCrds_t *j2000, polarCrds_t *jepoch, double date1, double date2){
|
static bool J2000to_ep_(const polarCrds_t *j2000, polarCrds_t *jepoch, double date1, double date2){
|
||||||
if(!j2000 || !jepoch) return false;
|
if(!j2000 || !jepoch) return false;
|
||||||
@@ -549,8 +549,75 @@ bool JXtoJnow(const polarCrds_t *in, polarCrds_t *out, double Jx){
|
|||||||
// and convert J2000 to Jnow
|
// and convert J2000 to Jnow
|
||||||
return J2000to_ep_(&j2000, out, MJD.tt1, MJD.tt2);
|
return J2000to_ep_(&j2000, out, MJD.tt1, MJD.tt2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0
|
static int is_leap_year(int year){
|
||||||
|
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void epoch2timeval(double frac_year, struct timeval *tval){
|
||||||
|
if(!tval) return;
|
||||||
|
int year = (int)frac_year;
|
||||||
|
double fraction = frac_year - year;
|
||||||
|
int days_in_year = is_leap_year(year) ? 366 : 365;
|
||||||
|
double seconds_in_year = days_in_year * 86400.0;
|
||||||
|
struct tm start_of_year = {0};
|
||||||
|
start_of_year.tm_year = year - 1900;
|
||||||
|
start_of_year.tm_mon = 0;
|
||||||
|
start_of_year.tm_mday = 1;
|
||||||
|
start_of_year.tm_hour = 0;
|
||||||
|
start_of_year.tm_min = 0;
|
||||||
|
start_of_year.tm_sec = 0;
|
||||||
|
start_of_year.tm_isdst = 0;
|
||||||
|
// UNIX time for start of year
|
||||||
|
time_t unix_start = timegm(&start_of_year);
|
||||||
|
// total time
|
||||||
|
fraction *= seconds_in_year; // seconds from year's start
|
||||||
|
tval->tv_sec = (time_t)(seconds_in_year); // integer fraction
|
||||||
|
tval->tv_usec = (int)((fraction - tval->tv_sec)* 1e6);
|
||||||
|
tval->tv_sec += unix_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief JxtoJ2000 - convert (with aberrations, prec/nut, etc) coordinates from given epoch to J2000
|
||||||
|
* @param in - for `epoch`
|
||||||
|
* @param out - for J2000
|
||||||
|
* @param epoch - like 2050.
|
||||||
|
* @return false if failed
|
||||||
|
*/
|
||||||
|
bool JXtoJ2000(const polarCrds_t *in, polarCrds_t *out, double epoch){
|
||||||
|
if(!in || !out || epoch < EPOCH_MIN || epoch > EPOCH_MAX) return false;
|
||||||
|
struct timeval tv;
|
||||||
|
epoch2timeval(epoch, &tv);
|
||||||
|
sMJD_t MJD;
|
||||||
|
if(!get_MJDt(&tv, &MJD)) return false;
|
||||||
|
double ri, eo;
|
||||||
|
eraAtic13(in->ra, in->dec, MJD.tt1, MJD.tt2, &ri, &out->dec, &eo);
|
||||||
|
out->ra = eraAnp(ri);
|
||||||
|
// LST @J2000, Greenwich = 18:41:50.548 = 4.894961
|
||||||
|
out->ha = eraAnp(J2000LST0 + place.slong - out->ra);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief J2000toJx - reverse of JxtoJ2000
|
||||||
|
* @param in - for J2000
|
||||||
|
* @param out - for `epoch`
|
||||||
|
* @param epoch - like 2030.
|
||||||
|
* @return false if failed
|
||||||
|
*/
|
||||||
|
bool J2000toJX(const polarCrds_t *in, polarCrds_t *out, double epoch){
|
||||||
|
if(!in || !out || epoch < EPOCH_MIN || epoch > EPOCH_MAX) return false;
|
||||||
|
struct timeval tv;
|
||||||
|
epoch2timeval(epoch, &tv);
|
||||||
|
sMJD_t MJD;
|
||||||
|
if(!get_MJDt(&tv, &MJD)) return false;
|
||||||
|
double ri, eo, lst;
|
||||||
|
eraAtci13(in->ra, in->dec, 0., 0., 0., 0., MJD.tt1, MJD.tt2, &ri, &out->dec, &eo);
|
||||||
|
out->ra = eraAnp(ri);
|
||||||
|
if(get_LST(&MJD, &lst)) out->ha = eraAnp(lst - out->ra);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert geocentric coordinates (nowadays, CIRS) to mean (JD2000, ICRS)
|
* convert geocentric coordinates (nowadays, CIRS) to mean (JD2000, ICRS)
|
||||||
@@ -558,50 +625,41 @@ bool JXtoJnow(const polarCrds_t *in, polarCrds_t *out, double Jx){
|
|||||||
* @return false if failed
|
* @return false if failed
|
||||||
*/
|
*/
|
||||||
bool JnowtoJ2000(const polarCrds_t *in, polarCrds_t *out){
|
bool JnowtoJ2000(const polarCrds_t *in, polarCrds_t *out){
|
||||||
|
if(!in || !out) return false;
|
||||||
bool ret = false;
|
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;
|
sMJD_t MJD;
|
||||||
if(!get_MJDt(NULL, &MJD)) return false;
|
if(!get_MJDt(NULL, &MJD)) return false;
|
||||||
double ri = 0., di = 0., eo = 0.;
|
double ri = 0., eo = 0.;
|
||||||
eraAtic13(in->ra, in->dec, MJD.tt1, MJD.tt2, &ri, &di, &eo);
|
// Jx to J2000
|
||||||
if(out){
|
eraAtic13(in->ra, in->dec, MJD.tt1, MJD.tt2, &ri, &out->dec, &eo);
|
||||||
out->ha = 0.; out->eo = 0.;
|
out->ra = eraAnp(ri);
|
||||||
//out->ra = eraAnp(ri - eo);
|
out->ha = eraAnp(J2000LST0 + place.slong - out->ra);
|
||||||
out->ra = ri;
|
|
||||||
out->dec = di;
|
|
||||||
DBG("JnowtoJ2000: ra=%gdeg, dec=%gdeg", RAD2DEG(out->ra), RAD2DEG(out->dec));
|
|
||||||
}
|
|
||||||
ret = true;
|
ret = true;
|
||||||
//#undef ERFA
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
bool J2000toJnow(const polarCrds_t *in, polarCrds_t *out){
|
||||||
* @brief JXtoJnow - convert ra/dec between epochs
|
if(!in || !out) return false;
|
||||||
* @param in - coordinates for Jx (degrees)
|
sMJD_t MJD;
|
||||||
* @param out - Jnow (degrees)
|
if(!get_MJDt(NULL, &MJD)) return false;
|
||||||
* @param Jx - Epoch for `in`
|
double ri, eo;
|
||||||
* @return false if failed
|
eraAtci13(in->ra, in->dec, 0., 0., 0., 0., MJD.tt1, MJD.tt2, &ri, &out->dec, &eo);
|
||||||
*/
|
out->ra = eraAnp(ri);
|
||||||
bool JXtoJnow(const polarCrds_t *in, polarCrds_t *out, double Jx){
|
out->ha = rahaNow(out->ra);
|
||||||
DBG("JXRA: %ghrs, JXDec: %gdegr; epoch X: %g", RAD2HRS(in->ra), RAD2DEG(in->dec), Jx);
|
|
||||||
if(!in) 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, ERFA_DJM0, Jx, &ri, &di, &eo);
|
|
||||||
LOGDBG("ri: %ghrs, eo: %ghrs, di: %gdeg", RAD2HRS(ri), RAD2HRS(eo), RAD2DEG(di));
|
|
||||||
if(out){
|
|
||||||
out->ha = 0.; out->eo = 0.;
|
|
||||||
//out->ra = eraAnp(ri - eo);
|
|
||||||
out->ra = ri;
|
|
||||||
out->dec = di;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
/**
|
||||||
|
* @brief JXtoJnow - convert ra/dec between epochs with aberrations, prec/nut, ...
|
||||||
|
* @param in - coordinates for Jx
|
||||||
|
* @param out - Jnow
|
||||||
|
* @param epoch - Epoch for `in`
|
||||||
|
* @return false if failed
|
||||||
|
*/
|
||||||
|
bool JXtoJnow(const polarCrds_t *in, polarCrds_t *out, double epoch){
|
||||||
|
if(!in || !out || epoch < EPOCH_MIN || epoch > EPOCH_MAX) return false;
|
||||||
|
polarCrds_t j2000;
|
||||||
|
if(fabs(epoch - 2000.) < 1e-3) j2000 = *in;
|
||||||
|
else if(!JXtoJ2000(in, &j2000, epoch)) return false;
|
||||||
|
return J2000toJnow(&j2000, out);
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,12 @@
|
|||||||
|
|
||||||
#define RADEC_STR_MAXLEN 64
|
#define RADEC_STR_MAXLEN 64
|
||||||
|
|
||||||
|
// LST for Greenwich @ J2000
|
||||||
|
#define J2000LST0 4.894961
|
||||||
|
// min/max Epoch
|
||||||
|
#define EPOCH_MIN 1950.
|
||||||
|
#define EPOCH_MAX 2050.
|
||||||
|
|
||||||
#define RAD2DEG(angle) ((angle) * ERFA_DR2D)
|
#define RAD2DEG(angle) ((angle) * ERFA_DR2D)
|
||||||
#define DEG2RAD(angle) ((angle) * ERFA_DD2R)
|
#define DEG2RAD(angle) ((angle) * ERFA_DD2R)
|
||||||
#define RAD2HRS(angle) ((angle) * 12. / ERFA_DPI)
|
#define RAD2HRS(angle) ((angle) * 12. / ERFA_DPI)
|
||||||
@@ -74,7 +80,7 @@ void norm_RADEC(double *ra, double *dec);
|
|||||||
void norm_RADECr(double *ra, double *dec);
|
void norm_RADECr(double *ra, double *dec);
|
||||||
void norm_angle180(double *a);
|
void norm_angle180(double *a);
|
||||||
|
|
||||||
double raha(double hara);
|
double rahaNow(double hara);
|
||||||
|
|
||||||
void hor2eq(horizCrds_t *h, polarCrds_t *pc, double sidTime);
|
void hor2eq(horizCrds_t *h, polarCrds_t *pc, double sidTime);
|
||||||
void eq2horH(polarCrds_t *pc, horizCrds_t *h);
|
void eq2horH(polarCrds_t *pc, horizCrds_t *h);
|
||||||
@@ -100,5 +106,8 @@ void getPlaceData(placeData_t *pd);
|
|||||||
bool J2000_to_epoch_pn(const polarCrds_t *j2000, double epoch, polarCrds_t *jepoch);
|
bool J2000_to_epoch_pn(const polarCrds_t *j2000, double epoch, polarCrds_t *jepoch);
|
||||||
bool epoch_to_J2000_pn(const polarCrds_t *jepoch, double epoch, polarCrds_t *j2000);
|
bool epoch_to_J2000_pn(const polarCrds_t *jepoch, double epoch, polarCrds_t *j2000);
|
||||||
|
|
||||||
|
bool JXtoJ2000(const polarCrds_t *in, polarCrds_t *out, double epoch);
|
||||||
|
bool J2000toJX(const polarCrds_t *in, polarCrds_t *out, double epoch);
|
||||||
bool JnowtoJ2000(const polarCrds_t *in, polarCrds_t *out);
|
bool JnowtoJ2000(const polarCrds_t *in, polarCrds_t *out);
|
||||||
|
bool J2000toJnow(const polarCrds_t *in, polarCrds_t *out);
|
||||||
bool JXtoJnow(const polarCrds_t *in, polarCrds_t *out, double Jx);
|
bool JXtoJnow(const polarCrds_t *in, polarCrds_t *out, double Jx);
|
||||||
|
|||||||
@@ -87,17 +87,9 @@ static int printhdr(int fd, const char *key, const char *val, const char *cmnt){
|
|||||||
*/
|
*/
|
||||||
void wrhdr(fitsheader_t *HDR){
|
void wrhdr(fitsheader_t *HDR){
|
||||||
if(!HDR) return;
|
if(!HDR) return;
|
||||||
static time_t lastcorr = 0; // last time of time/weather corrections sent to mount
|
|
||||||
double curtime = sl_dtime();
|
double curtime = sl_dtime();
|
||||||
//bool haveweather = false;
|
//bool haveweather = false;
|
||||||
bool poweredON = (HDR->status == MNT_S_ERROR || HDR->status == MNT_S_OFF) ? false : true;
|
bool poweredON = (HDR->status == MNT_S_ERROR || HDR->status == MNT_S_OFF) ? false : true;
|
||||||
// weather block
|
|
||||||
if(time(NULL) - HDR->weather.last_update < (int)(1. + MOUNT_CHECK_T * 10.)){ // weather data is good
|
|
||||||
if(poweredON && time(NULL) - lastcorr > CORRECTIONS_TIMEDIFF){ // make correction once per hour
|
|
||||||
if(mount_corrdata(&HDR->weather)) lastcorr = time(NULL);
|
|
||||||
}
|
|
||||||
//haveweather = true;
|
|
||||||
}else WARNX("bad weather; curtime - HDR->weather.last_update = %g", curtime - HDR->weather.last_update);
|
|
||||||
if(!hdname){
|
if(!hdname){
|
||||||
DBG("hdname not given!");
|
DBG("hdname not given!");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ bool mount_setInpHA(double ha){
|
|||||||
if(ha < 0) ha += 24.;
|
if(ha < 0) ha += 24.;
|
||||||
if(ha < 0. || ha >= 24.) return false;
|
if(ha < 0. || ha >= 24.) return false;
|
||||||
InpCoords.ha = HRS2RAD(ha);
|
InpCoords.ha = HRS2RAD(ha);
|
||||||
InpCoords.ra = raha(InpCoords.ha);
|
InpCoords.ra = rahaNow(InpCoords.ha);
|
||||||
InpCTime = sl_dtime();
|
InpCTime = sl_dtime();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ bool mount_setInpHA(double ha){
|
|||||||
bool mount_setInpRA(double ra){
|
bool mount_setInpRA(double ra){
|
||||||
if(ra < 0. || ra >= 24.) return false;
|
if(ra < 0. || ra >= 24.) return false;
|
||||||
InpCoords.ra = HRS2RAD(ra);
|
InpCoords.ra = HRS2RAD(ra);
|
||||||
InpCoords.ha = raha(InpCoords.ra);
|
InpCoords.ha = rahaNow(InpCoords.ra);
|
||||||
InpCTime = sl_dtime();
|
InpCTime = sl_dtime();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -142,6 +142,7 @@ bool mount_setInpZ(double Z){
|
|||||||
}
|
}
|
||||||
// without checking
|
// without checking
|
||||||
bool mount_setInpEpoch(double epoch){
|
bool mount_setInpEpoch(double epoch){
|
||||||
|
if(epoch < EPOCH_MIN || epoch > EPOCH_MAX) return false;
|
||||||
InpEpoch = epoch;
|
InpEpoch = epoch;
|
||||||
InpETime = sl_dtime();
|
InpETime = sl_dtime();
|
||||||
return true;
|
return true;
|
||||||
@@ -305,10 +306,11 @@ mount_status_t mount_status(){
|
|||||||
return MNT_S_OFF;
|
return MNT_S_OFF;
|
||||||
}
|
}
|
||||||
char resp[64];
|
char resp[64];
|
||||||
pthread_mutex_lock(&mntdev_mutex);
|
|
||||||
int ntry = 0;
|
int ntry = 0;
|
||||||
|
pthread_mutex_lock(&mntdev_mutex);
|
||||||
for(; ntry < 3; ++ntry)
|
for(; ntry < 3; ++ntry)
|
||||||
if(send_cmd_resp(CMD_GETSTAT, resp, sizeof(resp))) break;
|
if(send_cmd_resp(CMD_GETSTAT, resp, sizeof(resp))) break;
|
||||||
|
pthread_mutex_unlock(&mntdev_mutex);
|
||||||
if(ntry == 3){ // mount not responded -> set status OFF
|
if(ntry == 3){ // mount not responded -> set status OFF
|
||||||
curst = MNT_S_OFF;
|
curst = MNT_S_OFF;
|
||||||
}else{ // parsing of status
|
}else{ // parsing of status
|
||||||
@@ -319,7 +321,6 @@ mount_status_t mount_status(){
|
|||||||
else curst = (mount_status_t) statN;
|
else curst = (mount_status_t) statN;
|
||||||
DBG("STATUS: %s (%d)", statuses[curst], curst);
|
DBG("STATUS: %s (%d)", statuses[curst], curst);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mntdev_mutex);
|
|
||||||
atomic_store(&mountstatus, curst);
|
atomic_store(&mountstatus, curst);
|
||||||
return curst;
|
return curst;
|
||||||
}
|
}
|
||||||
@@ -449,7 +450,7 @@ bool mount_point(double ra, double dec){
|
|||||||
}
|
}
|
||||||
ret = true;
|
ret = true;
|
||||||
TagCoords.ra = HRS2RAD(ra);
|
TagCoords.ra = HRS2RAD(ra);
|
||||||
TagCoords.ha = raha(TagCoords.ra);
|
TagCoords.ha = rahaNow(TagCoords.ra);
|
||||||
TagCoords.dec = DEG2RAD(dec);
|
TagCoords.dec = DEG2RAD(dec);
|
||||||
TagTime = sl_dtime();
|
TagTime = sl_dtime();
|
||||||
LOGMSG("Go to RA/Decl: %s/%s", rastr, decstr);
|
LOGMSG("Go to RA/Decl: %s/%s", rastr, decstr);
|
||||||
@@ -558,6 +559,51 @@ retn:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool mount_getinfo(mount_info_t *info){
|
||||||
|
if(!info || !mount_dev) return false;
|
||||||
|
double ra, dec, az, zd, jd;
|
||||||
|
char pier;
|
||||||
|
int stat, slew;
|
||||||
|
char resp[128];
|
||||||
|
if(isemulated){
|
||||||
|
mount_getaz(&az, &zd);
|
||||||
|
mount_getcoords(&ra, &dec);
|
||||||
|
sMJD_t mjd;
|
||||||
|
get_MJDt(NULL, &mjd);
|
||||||
|
jd = mjd.MJD;
|
||||||
|
pier = 'x';
|
||||||
|
stat = emulation_status();
|
||||||
|
slew = 0;
|
||||||
|
}else{
|
||||||
|
bool OK = false;
|
||||||
|
pthread_mutex_lock(&mntdev_mutex);
|
||||||
|
if(send_cmd_resp(CMD_GETINFO, resp, sizeof(resp))) OK = true;
|
||||||
|
pthread_mutex_unlock(&mntdev_mutex);
|
||||||
|
if(!OK) return false;
|
||||||
|
double alt;
|
||||||
|
if(8 != sscanf(resp, "%lf,%lf,%c,%lf,%lf,%lf,%d,%d",
|
||||||
|
&ra, &dec, &pier, &az, &alt, &jd, &stat, &slew)) return false;
|
||||||
|
//LOGDBG("ra=%g, dec=%g, az=%g, alt=%g, jd=%g", ra, dec, az, alt, jd);
|
||||||
|
zd = 90. - alt;
|
||||||
|
}
|
||||||
|
info->ra = HRS2RAD(ra);
|
||||||
|
info->dec = DEG2RAD(dec);
|
||||||
|
info->az = DEG2RAD(az);
|
||||||
|
info->zd = DEG2RAD(zd);
|
||||||
|
info->JD = jd;
|
||||||
|
const char *pierside = "Unknown";
|
||||||
|
switch(pier){
|
||||||
|
case 'W': pierside = "West"; break;
|
||||||
|
case 'E': pierside = "East"; break;
|
||||||
|
default : break;
|
||||||
|
}
|
||||||
|
strcpy(info->pierside, pierside);
|
||||||
|
info->status = (mount_status_t) stat;
|
||||||
|
info->slewing = slew;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief mount_stop - stop any moving
|
* @brief mount_stop - stop any moving
|
||||||
* @return false if failed
|
* @return false if failed
|
||||||
@@ -597,7 +643,7 @@ bool mount_tracking_start(){
|
|||||||
if(!mount_getcoords(&ra, &dec)) return false;
|
if(!mount_getcoords(&ra, &dec)) return false;
|
||||||
TagCoords.ra = HRS2RAD(ra);
|
TagCoords.ra = HRS2RAD(ra);
|
||||||
TagCoords.dec = DEG2RAD(dec);
|
TagCoords.dec = DEG2RAD(dec);
|
||||||
TagCoords.ha = raha(TagCoords.ra);
|
TagCoords.ha = rahaNow(TagCoords.ra);
|
||||||
TagTime = sl_dtime();
|
TagTime = sl_dtime();
|
||||||
mount_setInpEpoch(-1.); // Jnow
|
mount_setInpEpoch(-1.); // Jnow
|
||||||
if(isemulated){
|
if(isemulated){
|
||||||
@@ -684,19 +730,20 @@ bool mount_getpierside(char *Ps, size_t len){
|
|||||||
bool mount_corrdata(weather_data_t *w){
|
bool mount_corrdata(weather_data_t *w){
|
||||||
if(isemulated) return true;
|
if(isemulated) return true;
|
||||||
if(!w) return false;
|
if(!w) return false;
|
||||||
bool ret = true; // returning value
|
|
||||||
mount_status_t curst = mount_status();
|
|
||||||
if(curst == MNT_S_SLEWING || curst == MNT_S_TRACKING) return true;
|
|
||||||
DBG("Refresh datetime");
|
|
||||||
pthread_mutex_lock(&mntdev_mutex);
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
buf[127] = 0;
|
buf[127] = 0;
|
||||||
time_t t = time(NULL);
|
bool ret = true; // returning value
|
||||||
struct tm *stm = localtime(&t);
|
|
||||||
struct timeval tv;
|
DBG("Refresh datetime");
|
||||||
gettimeofday(&tv, NULL);
|
pthread_mutex_lock(&mntdev_mutex);
|
||||||
|
|
||||||
|
double curt = sl_dtime() + FRAC_T_TODO;
|
||||||
|
time_t seconds = (int) curt;
|
||||||
|
double frac = curt - seconds;
|
||||||
|
struct tm tm_buf;
|
||||||
|
struct tm *stm = localtime_r(&seconds, &tm_buf);
|
||||||
snprintf(buf, 127, CMD_SETTIME, 1900+stm->tm_year, stm->tm_mon+1, stm->tm_mday,
|
snprintf(buf, 127, CMD_SETTIME, 1900+stm->tm_year, stm->tm_mon+1, stm->tm_mday,
|
||||||
stm->tm_hour, stm->tm_min, stm->tm_sec, tv.tv_usec/10000);
|
stm->tm_hour, stm->tm_min, (double)stm->tm_sec + frac);
|
||||||
DBG("write: %s", buf);
|
DBG("write: %s", buf);
|
||||||
if(!write_cmd(buf, true)){
|
if(!write_cmd(buf, true)){
|
||||||
WARNX("Can't write current date/time");
|
WARNX("Can't write current date/time");
|
||||||
@@ -740,11 +787,11 @@ bool mount_shutdown(){
|
|||||||
* @return false if failed
|
* @return false if failed
|
||||||
*/
|
*/
|
||||||
bool mount_rawcmd(const char *cmd, char *ans, size_t anslen){
|
bool mount_rawcmd(const char *cmd, char *ans, size_t anslen){
|
||||||
if(isemulated) return false;
|
if(!cmd || isemulated) return false;
|
||||||
pthread_mutex_lock(&mntdev_mutex);
|
pthread_mutex_lock(&mntdev_mutex);
|
||||||
LOGDBG("Send %s", cmd);
|
//LOGDBG("Send %s", cmd);
|
||||||
bool ret = send_cmd_resp(cmd, ans, anslen);
|
bool ret = send_cmd_resp(cmd, ans, anslen);
|
||||||
LOGDBG("Ans: %s", ret ? "true" : "false");
|
//LOGDBG("Ans: %s", ret ? "true" : "false");
|
||||||
pthread_mutex_unlock(&mntdev_mutex);
|
pthread_mutex_unlock(&mntdev_mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -759,7 +806,7 @@ static double get_guide_rate(){
|
|||||||
char resp[32];
|
char resp[32];
|
||||||
if(send_cmd_resp(CMD_GETGUIDERATE, resp, sizeof(resp))){
|
if(send_cmd_resp(CMD_GETGUIDERATE, resp, sizeof(resp))){
|
||||||
double rate = atof(resp);
|
double rate = atof(resp);
|
||||||
LOGDBG("get guide rate: %g", rate);
|
//LOGDBG("get guide rate: %g", rate);
|
||||||
if(rate > 0.0 && rate <= SIDEREAL_RATE){
|
if(rate > 0.0 && rate <= SIDEREAL_RATE){
|
||||||
return rate;
|
return rate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,16 @@
|
|||||||
|
|
||||||
#include "angles.h"
|
#include "angles.h"
|
||||||
|
|
||||||
|
// TODO: this value should be changed by config & proto
|
||||||
|
// (add this to time, sent to mount)
|
||||||
|
#define FRAC_T_TODO (.5)
|
||||||
|
|
||||||
|
|
||||||
// input coordinates lifetime - 24hrs
|
// input coordinates lifetime - 24hrs
|
||||||
#define COORDS_OLD_T (86400)
|
#define COORDS_OLD_T (86400)
|
||||||
|
|
||||||
// make datetime/pressure/temperature corrections each CORRECTIONS_TIMEDIFF seconds
|
// make datetime/pressure/temperature corrections each CORRECTIONS_TIMEDIFF seconds
|
||||||
#define CORRECTIONS_TIMEDIFF (3600)
|
#define CORRECTIONS_TIMEDIFF (60)
|
||||||
|
|
||||||
// sidereal tracking rate
|
// sidereal tracking rate
|
||||||
#define SIDEREAL_RATE 15.041
|
#define SIDEREAL_RATE 15.041
|
||||||
@@ -56,6 +61,18 @@ typedef enum{
|
|||||||
MNT_S_STATAMOUNT // number of statuses
|
MNT_S_STATAMOUNT // number of statuses
|
||||||
} mount_status_t;
|
} mount_status_t;
|
||||||
|
|
||||||
|
// ALL coordinates here are in radians instead of degrees like in other functions!
|
||||||
|
typedef struct{
|
||||||
|
double ra;
|
||||||
|
double dec;
|
||||||
|
char pierside[8]; // 'West' or 'East'
|
||||||
|
double az;
|
||||||
|
double zd;
|
||||||
|
double JD;
|
||||||
|
mount_status_t status;
|
||||||
|
uint8_t slewing;
|
||||||
|
} mount_info_t;
|
||||||
|
|
||||||
void set_emulation_mode();
|
void set_emulation_mode();
|
||||||
|
|
||||||
bool mount_setInpHA(double ha);
|
bool mount_setInpHA(double ha);
|
||||||
@@ -79,6 +96,7 @@ mount_status_t mount_status();
|
|||||||
bool mount_connect();
|
bool mount_connect();
|
||||||
void mount_disconnect();
|
void mount_disconnect();
|
||||||
|
|
||||||
|
bool mount_getinfo(mount_info_t *info);
|
||||||
bool mount_getcoords(double *ra, double *dec);
|
bool mount_getcoords(double *ra, double *dec);
|
||||||
bool mount_getaz(double *a, double *z);
|
bool mount_getaz(double *a, double *z);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 20.0.1, 2026-10-16T02:19:07. -->
|
<!-- Written by QtCreator 20.0.1, 2026-10-17T02:13:38. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
|||||||
@@ -66,6 +66,7 @@
|
|||||||
#define CMD_TELZD "telzd"
|
#define CMD_TELZD "telzd"
|
||||||
#define CMD_TRACK "track"
|
#define CMD_TRACK "track"
|
||||||
#define CMD_UNIXT "unixt"
|
#define CMD_UNIXT "unixt"
|
||||||
|
#define CMD_UPDATE "update"
|
||||||
|
|
||||||
|
|
||||||
// main command socket
|
// main command socket
|
||||||
@@ -79,6 +80,9 @@ volatile bool isrunning = true;
|
|||||||
// lost weather flag
|
// lost weather flag
|
||||||
static bool weatherlost = false;
|
static bool weatherlost = false;
|
||||||
|
|
||||||
|
// make weather/time correction even in tracking state
|
||||||
|
static bool needcorr = false;
|
||||||
|
|
||||||
// data for FITS-header (also to send user)
|
// data for FITS-header (also to send user)
|
||||||
static fitsheader_t HDR = {0};
|
static fitsheader_t HDR = {0};
|
||||||
static pthread_mutex_t headermutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t headermutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
@@ -282,7 +286,7 @@ static sl_sock_hresult_e cmd_gotorh(_U_ sl_sock_t *c, _U_ sl_sock_hitem_t *item,
|
|||||||
if(weatherlost || HDR.status == MNT_S_ERROR) return RESULT_FAIL;
|
if(weatherlost || HDR.status == MNT_S_ERROR) return RESULT_FAIL;
|
||||||
polarCrds_t p;
|
polarCrds_t p;
|
||||||
mount_getInpCoords(&p);
|
mount_getInpCoords(&p);
|
||||||
double RA_rad = raha(p.ha); // re-convert (as time could have passed)
|
double RA_rad = rahaNow(p.ha); // re-convert (as time could have passed)
|
||||||
double ra_h = RAD2HRS(RA_rad);
|
double ra_h = RAD2HRS(RA_rad);
|
||||||
double dec_d = RAD2DEG(p.dec);
|
double dec_d = RAD2DEG(p.dec);
|
||||||
LOGDBG("Client %d asks to point to HA/Dec", c->fd);
|
LOGDBG("Client %d asks to point to HA/Dec", c->fd);
|
||||||
@@ -441,18 +445,34 @@ static sl_sock_hresult_e cmd_place(sl_sock_t *c, sl_sock_hitem_t _U_ *item, cons
|
|||||||
return RESULT_SILENCE;
|
return RESULT_SILENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static sl_sock_hresult_e cmd_raw(sl_sock_t *c, sl_sock_hitem_t _U_ *item, const char *req){
|
// parsing of raw command (for `cmd_raw` and `unknown_command`)
|
||||||
|
static sl_sock_hresult_e rawcommand(sl_sock_t *c, const char *req){
|
||||||
char buf[128];
|
char buf[128];
|
||||||
if(!req || !*req) return RESULT_BADVAL;
|
if(!mount_rawcmd(req, buf, 126)){
|
||||||
if(!mount_rawcmd(req, buf, 126)) strcpy(buf, "No answer");
|
LOGMSG("Client %d asks for raw command '%s'; got no answer or error", c->fd, req);
|
||||||
size_t L = strlen(buf);
|
return RESULT_FAIL;
|
||||||
buf[L] = '\n';
|
}else{
|
||||||
buf[L + 1] = 0;
|
size_t L = strlen(buf);
|
||||||
LOGMSG("Client %d asks for raw command '%s'; answer: '%s'", req, buf);
|
if(L > 126){ L = 126; buf[126] = 0; }
|
||||||
|
LOGMSG("Client %d asks for raw command '%s'; answer: '%s'", c->fd, req, buf);
|
||||||
|
buf[L] = '\n';
|
||||||
|
buf[L + 1] = 0;
|
||||||
|
}
|
||||||
sl_sock_sendstrmessage(c, buf);
|
sl_sock_sendstrmessage(c, buf);
|
||||||
return RESULT_SILENCE;
|
return RESULT_SILENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sl_sock_hresult_e cmd_raw(sl_sock_t *c, sl_sock_hitem_t _U_ *item, const char *req){
|
||||||
|
char cmdbuf[32], *cmdptr = cmdbuf;
|
||||||
|
if(!req || !*req) return RESULT_BADVAL;
|
||||||
|
size_t L = strlen(req);
|
||||||
|
if(L < 1 || L > 29) return RESULT_BADVAL;
|
||||||
|
if(*req != ':') *cmdptr++ = ':';
|
||||||
|
if(req[L-1] != '#') sprintf(cmdptr, "%s#", req);
|
||||||
|
else strcpy(cmdptr, req);
|
||||||
|
return rawcommand(c, cmdbuf);
|
||||||
|
}
|
||||||
|
|
||||||
static sl_sock_hresult_e cmd_shutdown(sl_sock_t *c, sl_sock_hitem_t *item, const char *req){
|
static sl_sock_hresult_e cmd_shutdown(sl_sock_t *c, sl_sock_hitem_t *item, const char *req){
|
||||||
double val;
|
double val;
|
||||||
static int shtdwnkey = -1;
|
static int shtdwnkey = -1;
|
||||||
@@ -500,6 +520,19 @@ static sl_sock_hresult_e cmd_corra(sl_sock_t *c, sl_sock_hitem_t _U_ *item, cons
|
|||||||
return RESULT_FAIL;
|
return RESULT_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sl_sock_hresult_e cmd_update(sl_sock_t _U_ *c, sl_sock_hitem_t _U_ *item, const char _U_ *req){
|
||||||
|
if(HDR.status == MNT_S_OFF) return RESULT_FAIL;
|
||||||
|
needcorr = true;
|
||||||
|
return RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// default handler: if message starts from ':' and ends by '#' treat it as raw command
|
||||||
|
static sl_sock_hresult_e unknown_command(struct sl_sock *c, const char *str){
|
||||||
|
if(!str || !*str) return RESULT_BADKEY;
|
||||||
|
size_t L = strlen(str);
|
||||||
|
if(*str != ':' || str[L-1] != '#') return RESULT_BADKEY;
|
||||||
|
return rawcommand(c, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// and all handlers collection
|
// and all handlers collection
|
||||||
@@ -535,6 +568,7 @@ static sl_sock_hitem_t handlers[] = {
|
|||||||
{dtimeh, CMD_UNIXT, "get server's UNIX time", NULL},
|
{dtimeh, CMD_UNIXT, "get server's UNIX time", NULL},
|
||||||
{cmd_corra, CMD_CORRA, "correct RA by x arcseconds", NULL},
|
{cmd_corra, CMD_CORRA, "correct RA by x arcseconds", NULL},
|
||||||
{cmd_cordec, CMD_CORDEC, "correct Dec by x arcseconds", NULL},
|
{cmd_cordec, CMD_CORDEC, "correct Dec by x arcseconds", NULL},
|
||||||
|
{cmd_update, CMD_UPDATE, "update time/weather data to mount", NULL},
|
||||||
{NULL, NULL, NULL, NULL}
|
{NULL, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -580,6 +614,7 @@ bool server_check(server_sock_t *sockt){
|
|||||||
sl_sock_maxclhandler(cmd_socket, toomuch);
|
sl_sock_maxclhandler(cmd_socket, toomuch);
|
||||||
sl_sock_connhandler(cmd_socket, connected);
|
sl_sock_connhandler(cmd_socket, connected);
|
||||||
sl_sock_dischandler(cmd_socket, disconnected);
|
sl_sock_dischandler(cmd_socket, disconnected);
|
||||||
|
sl_sock_defmsghandler(cmd_socket, unknown_command);
|
||||||
stellarium_sockfd = sl_sock_open(SOCKT_NET, sockt->stellport, 1, 0);
|
stellarium_sockfd = sl_sock_open(SOCKT_NET, sockt->stellport, 1, 0);
|
||||||
if(stellarium_sockfd < 0){
|
if(stellarium_sockfd < 0){
|
||||||
LOGERR("Can't start stellarium socket");
|
LOGERR("Can't start stellarium socket");
|
||||||
@@ -618,12 +653,15 @@ void server_run(){
|
|||||||
if(!mount_connect()){
|
if(!mount_connect()){
|
||||||
LOGWARN("Can't connect to mount, will try to reconnect later");
|
LOGWARN("Can't connect to mount, will try to reconnect later");
|
||||||
}
|
}
|
||||||
DBG("While");
|
|
||||||
double tcheck = sl_dtime(), treconnect = 0.;
|
double tcheck = sl_dtime(), treconnect = 0.;
|
||||||
time_t lastweathertime = 0;
|
bool notlogged = true;
|
||||||
|
double lastweathertime = 0; // last weather checking time
|
||||||
|
double lastcorr = 0.; // last time of time/weather corrections sent to mount
|
||||||
|
|
||||||
getPlaceData(&HDR.place);
|
getPlaceData(&HDR.place);
|
||||||
mount_get_name(HDR.mountname, MAX_HDR_STRLEN);
|
mount_get_name(HDR.mountname, MAX_HDR_STRLEN);
|
||||||
bool notlogged = true;
|
DBG("While");
|
||||||
while(isrunning && cmd_socket && cmd_socket->connected){
|
while(isrunning && cmd_socket && cmd_socket->connected){
|
||||||
usleep(sleept);
|
usleep(sleept);
|
||||||
if(!cmd_socket->rthread){
|
if(!cmd_socket->rthread){
|
||||||
@@ -634,7 +672,7 @@ void server_run(){
|
|||||||
double tnow = sl_dtime();
|
double tnow = sl_dtime();
|
||||||
if(tnow - tcheck >= MOUNT_CHECK_T){
|
if(tnow - tcheck >= MOUNT_CHECK_T){
|
||||||
tcheck = tnow;
|
tcheck = tnow;
|
||||||
if(get_weather_data(&HDR.weather) == 0){
|
if(get_weather_data(&HDR.weather) == 0){ // for airmass
|
||||||
lastweathertime = HDR.weather.last_update;
|
lastweathertime = HDR.weather.last_update;
|
||||||
}else{
|
}else{
|
||||||
WARNX("Can't get weather data");
|
WARNX("Can't get weather data");
|
||||||
@@ -642,12 +680,23 @@ void server_run(){
|
|||||||
// collect data for other fields
|
// collect data for other fields
|
||||||
pthread_mutex_lock(&headermutex);
|
pthread_mutex_lock(&headermutex);
|
||||||
HDR.status = mount_status();
|
HDR.status = mount_status();
|
||||||
|
get_MJDt(NULL, &HDR.MJD);
|
||||||
|
get_LST(&HDR.MJD, &HDR.sidtime);
|
||||||
if(HDR.status != MNT_S_OFF){
|
if(HDR.status != MNT_S_OFF){
|
||||||
|
mount_info_t info;
|
||||||
|
if(mount_getinfo(&info)){
|
||||||
|
LOGDBG("Got info; JDtel-JDcomp=%gs", 86400.*(info.JD - ERFA_DJM0 - HDR.MJD.MJD));
|
||||||
|
HDR.altaz.az = info.az;
|
||||||
|
HDR.altaz.zd = info.zd;
|
||||||
|
HDR.polar.dec = info.dec;
|
||||||
|
HDR.polar.ra = info.ra;
|
||||||
|
HDR.polar.ha = eraAnp(HDR.sidtime - HDR.polar.ra);
|
||||||
|
strcpy(HDR.pierside, info.pierside);
|
||||||
|
}else LOGWARN("Can't get mount info");
|
||||||
|
/*
|
||||||
double deg1, deg2;
|
double deg1, deg2;
|
||||||
DBG("Take coordinates");
|
DBG("Take coordinates");
|
||||||
if(mount_getcoords(°1, °2)){
|
if(mount_getcoords(°1, °2)){
|
||||||
get_MJDt(NULL, &HDR.MJD);
|
|
||||||
get_LST(&HDR.MJD, &HDR.sidtime);
|
|
||||||
HDR.polar.ra = HRS2RAD(deg1);
|
HDR.polar.ra = HRS2RAD(deg1);
|
||||||
HDR.polar.dec = DEG2RAD(deg2);
|
HDR.polar.dec = DEG2RAD(deg2);
|
||||||
HDR.polar.ha = eraAnp(HDR.sidtime - HDR.polar.ra);
|
HDR.polar.ha = eraAnp(HDR.sidtime - HDR.polar.ra);
|
||||||
@@ -656,19 +705,28 @@ void server_run(){
|
|||||||
HDR.altaz.az = DEG2RAD(deg1);
|
HDR.altaz.az = DEG2RAD(deg1);
|
||||||
HDR.altaz.zd = DEG2RAD(deg2);
|
HDR.altaz.zd = DEG2RAD(deg2);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if(tnow - lastweathertime > MOUNT_WEATHER_ALRM){
|
if(tnow - lastweathertime > MOUNT_WEATHER_ALRM){
|
||||||
weatherlost = true;
|
weatherlost = true;
|
||||||
if(HDR.status == MNT_S_TRACKING || HDR.status == MNT_S_SLEWING){
|
if(HDR.status == MNT_S_TRACKING || HDR.status == MNT_S_SLEWING){
|
||||||
LOGERR("Lost meteo connection -> park");
|
LOGERR("Lost meteo connection -> park");
|
||||||
if(mount_park()) lastweathertime = tnow;
|
if(mount_park()) lastweathertime = tnow;
|
||||||
}
|
}
|
||||||
} else weatherlost = false;
|
} else {
|
||||||
}else{
|
weatherlost = false;
|
||||||
get_MJDt(NULL, &HDR.MJD);
|
if(tnow - lastweathertime < (int)(1. + MOUNT_CHECK_T * 10.)){ // weather data is good
|
||||||
get_LST(&HDR.MJD, &HDR.sidtime);
|
// make correction once per hour, but only in non-tracking state
|
||||||
|
if(needcorr || ((HDR.status != MNT_S_TRACKING) && tnow - lastcorr > CORRECTIONS_TIMEDIFF)){
|
||||||
|
if(mount_corrdata(&HDR.weather)){
|
||||||
|
needcorr = false;
|
||||||
|
lastcorr = tnow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else WARNX("bad weather; curtime - HDR->weather.last_update = %g", tnow - lastweathertime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getDUT(&HDR.dut);
|
getDUT(&HDR.dut);
|
||||||
if(HDR.status == MNT_S_OFF || !mount_getpierside(HDR.pierside, MAX_HDR_STRLEN)) *HDR.pierside = 0;
|
//if(HDR.status == MNT_S_OFF || !mount_getpierside(HDR.pierside, MAX_HDR_STRLEN)) *HDR.pierside = 0;
|
||||||
pthread_mutex_unlock(&headermutex);
|
pthread_mutex_unlock(&headermutex);
|
||||||
// and write FITS-header
|
// and write FITS-header
|
||||||
wrhdr(&HDR);
|
wrhdr(&HDR);
|
||||||
|
|||||||
Reference in New Issue
Block a user