diff --git a/Daemons/10micron_stellarium/angles.h b/Daemons/10micron_stellarium/angles.h index dab9a35..6adfbab 100644 --- a/Daemons/10micron_stellarium/angles.h +++ b/Daemons/10micron_stellarium/angles.h @@ -21,7 +21,7 @@ #include #include -#define RADEC_STR_MAXLEN 64 +#define RADEC_STR_MAXLEN 16 // LST for Greenwich @ J2000 #define J2000LST0 4.894961 diff --git a/Daemons/10micron_stellarium/emulation.c b/Daemons/10micron_stellarium/emulation.c index 1494dfc..9b0668c 100644 --- a/Daemons/10micron_stellarium/emulation.c +++ b/Daemons/10micron_stellarium/emulation.c @@ -29,17 +29,17 @@ #define RASPEED (DEG2RAD(5.)) #define DECSPEED (DEG2RAD(8.)) // limiting Zen.d. -#define ZD_LIMIT (DEG2RAD(80.)) +#define ZD_LIMIT (DEG2RAD(90.)) // pointing tolerance: ~1'' #define POINTING_TOL (DEG2RAD(0.0003)) // current emulation status (only MNT_S_STOPPED, MNT_S_TRACKING and MNT_S_SLEWING supported) static atomic_int emul_status = MNT_S_STOPPED; -// current & target coordinates for stationary process +// current & target coordinates for stationary process (radians) static horizCrds_t CurAZ = {.az = DEG2RAD(180.), .zd = DEG2RAD(80.)}, TagAZ = {0}; // pointing to AZ and stop static bool pointAZ = false; -// current and target Ra/Dec +// current and target Ra/Dec (radians) static polarCrds_t CurRD = {0}, TagRD = {0}; // last time user asks for coordinates or change something static double tlast = -1.; @@ -131,9 +131,11 @@ static void get_flip_target(const polarCrds_t *src, polarCrds_t *dst){ * get coordinates (emulation) */ void get_emul_coords(double *ra, double *decl){ + FNAME(); mount_status_t curstat = emulation_status(); double LST, tcur = sl_dtime(); if(!get_LST(NULL, &LST)) return; + DBG("Get coords"); if(curstat == MNT_S_STOPPED){ // just show constant A/Z DBG("Stopped -> get from a=%gdeg, z=%gdeg", RAD2DEG(CurAZ.az), RAD2DEG(CurAZ.zd)); hor2eq(&CurAZ, &CurRD, LST); @@ -175,8 +177,10 @@ void get_emul_coords(double *ra, double *decl){ double dt = tcur - tlast; if(dist < POINTING_TOL || time_to_reach < dt){ // on position DBG("ON Position, time to reach=%gs, dt=%gs\n\n\n", time_to_reach, dt); - if(pointAZ) emulation_stop(); // got A/Z position, stop - else atomic_store(&emul_status, MNT_S_TRACKING); + if(pointAZ){ + emulation_stop(); // got A/Z position, stop + CurAZ = TagAZ; + }else atomic_store(&emul_status, MNT_S_TRACKING); if(flip_in_progress) flip_in_progress = false; CurRD = TagRD; // fix to dec <=90 }else{ @@ -224,3 +228,17 @@ mount_status_t emulation_status(){ mount_status_t curstate = (mount_status_t) atomic_load(&emul_status); return curstate; } + +// emulated correction (simplest as possible) +bool emul_corra(double dra){ + if(MNT_S_TRACKING != emulation_status() || fabs(dra) > MAX_ARCSEC_CORR) return false; + CurRD.ra += DEG2RAD(dra / 3600.); + norm_RADECr(&CurRD.ra, &CurRD.dec); + return true; +} +bool emul_cordec(double ddec){ + if(MNT_S_TRACKING != emulation_status() || fabs(ddec) > MAX_ARCSEC_CORR) return false; + CurRD.dec += DEG2RAD(ddec / 3600.); + norm_RADECr(&CurRD.ra, &CurRD.dec); + return true; +} diff --git a/Daemons/10micron_stellarium/emulation.h b/Daemons/10micron_stellarium/emulation.h index e7a9223..da6c4b6 100644 --- a/Daemons/10micron_stellarium/emulation.h +++ b/Daemons/10micron_stellarium/emulation.h @@ -20,6 +20,9 @@ #include "mount.h" // mount status +// maximal correction, arcsec +#define MAX_ARCSEC_CORR 75. + bool point_emulation(double ra, double decl); bool pointAZ_emulation(double a, double z); mount_status_t emulation_status(); @@ -27,3 +30,5 @@ mount_status_t emulation_status(); void get_emul_coords(double *ra, double *decl); void emulation_stop(); void emul_start_tracking(); +bool emul_corra(double dra); +bool emul_cordec(double ddec); diff --git a/Daemons/10micron_stellarium/fitshdr.c b/Daemons/10micron_stellarium/fitshdr.c index 8d085e2..d4af991 100644 --- a/Daemons/10micron_stellarium/fitshdr.c +++ b/Daemons/10micron_stellarium/fitshdr.c @@ -103,7 +103,7 @@ void wrhdr(fitsheader_t *HDR){ return; } fchmod(fd, 0644); -#define VALLEN 22 +#define VALLEN 64 #define CMNTLEN 51 char val[VALLEN+1]; char ang[RADEC_STR_MAXLEN], cmnt[CMNTLEN+1]; @@ -194,18 +194,20 @@ void wrhdr(fitsheader_t *HDR){ WRHDR("ZDCALC", val, cmnt); // calculate airmass time_t t_now = time(NULL); - struct tm *tm_loc; - tm_loc = localtime(&t_now); - double am, acd, wcd, wam; - calc_airmass(tm_loc->tm_yday, &HDR->weather, &HDR->place, hor.zd, &am, &acd, &wcd, &wam); - snprintf(val, VALLEN, "%.2f", am); - WRHDR("AIRMASS", val, "Air mass by Reed D. Meyer"); - snprintf(val, VALLEN, "%.2f", acd); - WRHDR("ATMDENS", val, "Atm. column density by Reed D. Meyer (g/cm^2)"); - snprintf(val, VALLEN, "%.2f", wcd); - WRHDR("WVDENS", val, "WV column density by Reed D. Meyer (g/cm^2)"); - snprintf(val, VALLEN, "%.2f", wam); - WRHDR("WVAM", val, "Water vapour air mass by Reed D. Meyer"); + if(t_now - HDR->weather.last_update < MOUNT_WEATHER_ALRM){ + struct tm *tm_loc; + tm_loc = localtime(&t_now); + double am, acd, wcd, wam; + calc_airmass(tm_loc->tm_yday, &HDR->weather, &HDR->place, hor.zd, &am, &acd, &wcd, &wam); + snprintf(val, VALLEN, "%.2f", am); + WRHDR("AIRMASS", val, "Air mass by Reed D. Meyer"); + snprintf(val, VALLEN, "%.2f", acd); + WRHDR("ATMDENS", val, "Atm. column density by Reed D. Meyer (g/cm^2)"); + snprintf(val, VALLEN, "%.2f", wcd); + WRHDR("WVDENS", val, "WV column density by Reed D. Meyer (g/cm^2)"); + snprintf(val, VALLEN, "%.2f", wam); + WRHDR("WVAM", val, "Water vapour air mass by Reed D. Meyer"); + } } WRHDR("TELSTAT", mount_status_str(HDR->status), "Telescope mount status"); double epoch; diff --git a/Daemons/10micron_stellarium/fitshdr.h b/Daemons/10micron_stellarium/fitshdr.h index 672f51d..dbabf6f 100644 --- a/Daemons/10micron_stellarium/fitshdr.h +++ b/Daemons/10micron_stellarium/fitshdr.h @@ -43,6 +43,9 @@ typedef struct { // status checking interval and writing FITS-header, seconds #define MOUNT_CHECK_T 0.5 +// max weather lost time +#define MOUNT_WEATHER_ALRM 900. + #ifndef FLT_EPSILON #define FLT_EPSILON 1e-6 #endif diff --git a/Daemons/10micron_stellarium/main.c b/Daemons/10micron_stellarium/main.c index 1d49ac1..1684988 100644 --- a/Daemons/10micron_stellarium/main.c +++ b/Daemons/10micron_stellarium/main.c @@ -130,7 +130,7 @@ int main(int argc, char **argv){ if(!isrunning) return 0; #endif - if(G->emulation) set_emulation_mode(); + if(G->emulation) mount_emulation_set(); else if(!mount_set_dev(G->device, G->serspeed, G->sertmout)){ WARNX("Can't open device %s @ %d", G->device, G->serspeed); return 4; diff --git a/Daemons/10micron_stellarium/mount.c b/Daemons/10micron_stellarium/mount.c index be440fa..8f52fad 100644 --- a/Daemons/10micron_stellarium/mount.c +++ b/Daemons/10micron_stellarium/mount.c @@ -498,10 +498,14 @@ retn: return ret; } -void set_emulation_mode(){ +void mount_emulation_set(){ isemulated = true; } +bool mount_emulation_get(){ + return isemulated; +} + static bool get_declination(double *dec){ char resp[64]; if(!send_cmd_resp(CMD_GETDEC, resp, sizeof(resp))) return false; @@ -561,12 +565,12 @@ retn: 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){ + DBG("Get emul info"); mount_getaz(&az, &zd); mount_getcoords(&ra, &dec); sMJD_t mjd; @@ -576,6 +580,7 @@ bool mount_getinfo(mount_info_t *info){ stat = emulation_status(); slew = 0; }else{ + if(!info || !mount_dev) return false; bool OK = false; pthread_mutex_lock(&mntdev_mutex); if(send_cmd_resp(CMD_GETINFO, resp, sizeof(resp))) OK = true; @@ -834,6 +839,7 @@ static bool send_pulse(const char *dir_cmd, int total_ms){ */ bool correct_ra(double arcsec){ if(fabs(arcsec) < 1e-6) return false; // near pole there's may be... + if(isemulated) return emul_corra(arcsec); bool ret = false; pthread_mutex_lock(&mntdev_mutex); double guide_rate = get_guide_rate(); @@ -867,6 +873,7 @@ rtn: */ bool correct_dec(double arcsec){ if(fabs(arcsec) < MIN_CORR_ANGLE) return false; + if(isemulated) return emul_cordec(arcsec); bool ret = false; pthread_mutex_lock(&mntdev_mutex); double guide_rate = get_guide_rate(); diff --git a/Daemons/10micron_stellarium/mount.h b/Daemons/10micron_stellarium/mount.h index cc08f39..357feef 100644 --- a/Daemons/10micron_stellarium/mount.h +++ b/Daemons/10micron_stellarium/mount.h @@ -73,7 +73,9 @@ typedef struct{ uint8_t slewing; } mount_info_t; -void set_emulation_mode(); +void mount_emulation_set(); +bool mount_emulation_get(); + bool mount_setInpHA(double ha); bool mount_setInpRA(double ra); diff --git a/Daemons/10micron_stellarium/mountdaemon_10micron.creator.user b/Daemons/10micron_stellarium/mountdaemon_10micron.creator.user index 42a78f1..39bd6eb 100644 --- a/Daemons/10micron_stellarium/mountdaemon_10micron.creator.user +++ b/Daemons/10micron_stellarium/mountdaemon_10micron.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/Daemons/10micron_stellarium/server.c b/Daemons/10micron_stellarium/server.c index 00ad41e..62d4d0a 100644 --- a/Daemons/10micron_stellarium/server.c +++ b/Daemons/10micron_stellarium/server.c @@ -67,6 +67,7 @@ #define CMD_TRACK "track" #define CMD_UNIXT "unixt" #define CMD_UPDATE "update" +#define CMD_FORMAT "format" // main command socket @@ -94,9 +95,38 @@ bool server_setsleept(unsigned int t){ return true; } +// print hours and angles in user's format +static void print_hour(sl_sock_t *c, const char *key, double radians){ + int format = (intptr_t)c->data; + char buf[64], valbuf[RADEC_STR_MAXLEN]; + size_t L = 0; + if(0 == format){ // default: double number + L = snprintf(buf, 63, "%s=%.8f\n", key, RAD2HRS(radians)); + }else{ + r2sHMS(radians, valbuf); + L = snprintf(buf, 63, "%s=%s\n", key, valbuf); + } + if(L > 62) buf[63] = 0; + sl_sock_sendstrmessage(c, buf); +} + +static void print_deg(sl_sock_t *c, const char *key, double radians){ + int format = (intptr_t)c->data; + char buf[64], valbuf[RADEC_STR_MAXLEN]; + size_t L = 0; + if(0 == format){ // default: double number + L = snprintf(buf, 63, "%s=%.8f\n", key, RAD2DEG(radians)); + }else{ + r2sDMS(radians, valbuf); + L = snprintf(buf, 63, "%s=%s\n", key, valbuf); + } + if(L > 62) buf[63] = 0; + sl_sock_sendstrmessage(c, buf); +} + /////// handlers // unixt - send to ALL clients -static sl_sock_hresult_e dtimeh(sl_sock_t *c, _U_ sl_sock_hitem_t *item, _U_ const char *req){ +static sl_sock_hresult_e cmd_dtimeh(sl_sock_t *c, _U_ sl_sock_hitem_t *item, _U_ const char *req){ char buf[32]; snprintf(buf, 31, "%s=%.2f\n", item->key, sl_dtime()); LOGDBG("Client %d asks time: %s", c->fd, buf); @@ -105,7 +135,7 @@ static sl_sock_hresult_e dtimeh(sl_sock_t *c, _U_ sl_sock_hitem_t *item, _U_ con } // statust - text format status -static sl_sock_hresult_e status(sl_sock_t *c, sl_sock_hitem_t *item, _U_ const char *req){ +static sl_sock_hresult_e cmd_status(sl_sock_t *c, sl_sock_hitem_t *item, _U_ const char *req){ char buf[BUFSIZ]; snprintf(buf, BUFSIZ-1, "%s=%s\n", item->key, mount_status_str(HDR.status)); LOGDBG("Client %d asks status: %s", c->fd, buf); @@ -131,14 +161,10 @@ static sl_sock_hresult_e cmd_tagra(sl_sock_t *c, sl_sock_hitem_t *item, const ch LOGDBG("Client %d set tagra: %g", c->fd, val); if(mount_setInpRA(val)) return RESULT_OK; return RESULT_BADVAL; - }else{ // getter - polarCrds_t p; - mount_getInpCoords(&p); - double ra_h = RAD2HRS(p.ra); - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, ra_h); - sl_sock_sendstrmessage(c, buf); - } + } // getter + polarCrds_t p; + mount_getInpCoords(&p); + print_hour(c, item->key, p.ra); return RESULT_SILENCE; } @@ -150,14 +176,10 @@ static sl_sock_hresult_e cmd_tagdec(sl_sock_t *c, sl_sock_hitem_t *item, const c LOGDBG("Client %d set tagdec: %g", c->fd, val); if(mount_setInpDec(val)) return RESULT_OK; return RESULT_BADVAL; - }else{ - polarCrds_t p; - mount_getInpCoords(&p); - double dec_d = RAD2DEG(p.dec); - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, dec_d); - sl_sock_sendstrmessage(c, buf); } + polarCrds_t p; + mount_getInpCoords(&p); + print_deg(c, item->key, p.dec); return RESULT_SILENCE; } @@ -169,14 +191,10 @@ static sl_sock_hresult_e cmd_tagha(sl_sock_t *c, sl_sock_hitem_t *item, const ch LOGDBG("Client %d set tagha: %g", c->fd, val); if(mount_setInpHA(val)) return RESULT_OK; return RESULT_BADVAL; - }else{ - polarCrds_t p; - mount_getInpCoords(&p); - double ha_h = RAD2HRS(p.ha); - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, ha_h); - sl_sock_sendstrmessage(c, buf); } + polarCrds_t p; + mount_getInpCoords(&p); + print_hour(c, item->key, p.ha); return RESULT_SILENCE; } @@ -188,14 +206,10 @@ static sl_sock_hresult_e cmd_tagaz(sl_sock_t *c, sl_sock_hitem_t *item, const ch LOGDBG("Client %d set tagaz: %g", c->fd, val); if(mount_setInpA(val)) return RESULT_OK; return RESULT_BADVAL; - }else{ - horizCrds_t h; - mount_getInpHor(&h); - double az_d = RAD2DEG(h.az); - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, az_d); - sl_sock_sendstrmessage(c, buf); } + horizCrds_t h; + mount_getInpHor(&h); + print_deg(c, item->key, h.az); return RESULT_SILENCE; } @@ -207,61 +221,45 @@ static sl_sock_hresult_e cmd_tagzd(sl_sock_t *c, sl_sock_hitem_t *item, const ch LOGDBG("Client %d set tagzd: %g", c->fd, val); if(mount_setInpZ(val)) return RESULT_OK; return RESULT_BADVAL; - }else{ - horizCrds_t h; - mount_getInpHor(&h); - double zd_d = RAD2DEG(h.zd); - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, zd_d); - sl_sock_sendstrmessage(c, buf); } + horizCrds_t h; + mount_getInpHor(&h); + print_deg(c, item->key, h.zd); return RESULT_SILENCE; } static sl_sock_hresult_e cmd_lst(sl_sock_t *c, sl_sock_hitem_t *item, _U_ const char *req){ - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, RAD2HRS(HDR.sidtime)); - sl_sock_sendstrmessage(c, buf); + print_hour(c, item->key, HDR.sidtime); return RESULT_SILENCE; } static sl_sock_hresult_e cmd_telra(sl_sock_t *c, sl_sock_hitem_t *item, _U_ const char *req){ if(weatherlost || HDR.status == MNT_S_ERROR) return RESULT_FAIL; - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, RAD2HRS(HDR.polar.ra)); - sl_sock_sendstrmessage(c, buf); + print_hour(c, item->key, HDR.polar.ra); return RESULT_SILENCE; } static sl_sock_hresult_e cmd_telha(sl_sock_t *c, sl_sock_hitem_t *item, _U_ const char *req){ if(weatherlost || HDR.status == MNT_S_ERROR) return RESULT_FAIL; - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, RAD2HRS(HDR.polar.ha)); - sl_sock_sendstrmessage(c, buf); + print_hour(c, item->key, HDR.polar.ha); return RESULT_SILENCE; } static sl_sock_hresult_e cmd_teldec(sl_sock_t *c, sl_sock_hitem_t *item, _U_ const char *req){ if(weatherlost || HDR.status == MNT_S_ERROR) return RESULT_FAIL; - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, RAD2DEG(HDR.polar.dec)); - sl_sock_sendstrmessage(c, buf); + print_deg(c, item->key, HDR.polar.dec); return RESULT_SILENCE; } static sl_sock_hresult_e cmd_telaz(sl_sock_t *c, sl_sock_hitem_t *item, _U_ const char *req){ if(weatherlost || HDR.status == MNT_S_ERROR) return RESULT_FAIL; - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, RAD2DEG(HDR.altaz.az)); - sl_sock_sendstrmessage(c, buf); + print_deg(c, item->key, HDR.altaz.az); return RESULT_SILENCE; } static sl_sock_hresult_e cmd_telzd(sl_sock_t *c, sl_sock_hitem_t *item, _U_ const char *req){ if(weatherlost || HDR.status == MNT_S_ERROR) return RESULT_FAIL; - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, RAD2DEG(HDR.altaz.zd)); - sl_sock_sendstrmessage(c, buf); + print_deg(c, item->key, HDR.altaz.zd); return RESULT_SILENCE; } @@ -338,13 +336,10 @@ static sl_sock_hresult_e cmd_parkaz(sl_sock_t *c, sl_sock_hitem_t *item, const c LOGDBG("Client %d set parking Az to %g", c->fd, val); if(mount_setParkAz(val)) return RESULT_OK; return RESULT_BADVAL; - }else{ - horizCrds_t h; - mount_getPark(&h); - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, RAD2DEG(h.az)); - sl_sock_sendstrmessage(c, buf); } + horizCrds_t h; + mount_getPark(&h); + print_deg(c, item->key, h.az); return RESULT_SILENCE; } static sl_sock_hresult_e cmd_parkzd(sl_sock_t *c, sl_sock_hitem_t *item, const char *req){ @@ -355,13 +350,10 @@ static sl_sock_hresult_e cmd_parkzd(sl_sock_t *c, sl_sock_hitem_t *item, const c LOGDBG("Client %d set parking ZD to %g", c->fd, val); if(mount_setParkZD(val)) return RESULT_OK; return RESULT_BADVAL; - }else{ - horizCrds_t h; - mount_getPark(&h); - char buf[64]; - snprintf(buf, 63, "%s=%.6f\n", item->key, RAD2DEG(h.zd)); - sl_sock_sendstrmessage(c, buf); } + horizCrds_t h; + mount_getPark(&h); + print_deg(c, item->key, h.zd); return RESULT_SILENCE; } @@ -436,11 +428,12 @@ static sl_sock_hresult_e cmd_polary(sl_sock_t *c, sl_sock_hitem_t *item, const c } static sl_sock_hresult_e cmd_place(sl_sock_t *c, sl_sock_hitem_t _U_ *item, const char _U_ *req){ - char buf[128]; + char buf[32]; placeData_t place; getPlaceData(&place); - snprintf(buf, 127, "latitude=%.7f\nlongitude=%.7f\naltitude=%.7f\n", - RAD2DEG(place.slat), RAD2DEG(place.slong), place.salt); + print_deg(c, "latitude", place.slat); + print_deg(c, "longitude", place.slong); + snprintf(buf, 31, "altitude=%.7f\n", place.salt); sl_sock_sendstrmessage(c, buf); return RESULT_SILENCE; } @@ -451,13 +444,12 @@ static sl_sock_hresult_e rawcommand(sl_sock_t *c, const char *req){ if(!mount_rawcmd(req, buf, 126)){ LOGMSG("Client %d asks for raw command '%s'; got no answer or error", c->fd, req); return RESULT_FAIL; - }else{ - size_t L = strlen(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; } + size_t L = strlen(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); return RESULT_SILENCE; } @@ -526,6 +518,19 @@ static sl_sock_hresult_e cmd_update(sl_sock_t _U_ *c, sl_sock_hitem_t _U_ *item, return RESULT_OK; } +static sl_sock_hresult_e cmd_format(sl_sock_t *c, sl_sock_hitem_t *item, const char *req){ + double val; + char buf[32]; + int res = parse_key_value(req, &val); + if(res < 0) return RESULT_BADVAL; + if(res > 0){ // set format: 0 - double, 1 - string + c->data = (val < 0.5) ? (void*)(intptr_t)0 : (void*)(intptr_t)1; + } + snprintf(buf, 31, "%s=%" PRIdPTR "\n", item->key, (intptr_t)c->data); + sl_sock_sendstrmessage(c, buf); + return RESULT_SILENCE; +} + // 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; @@ -537,38 +542,51 @@ static sl_sock_hresult_e unknown_command(struct sl_sock *c, const char *str){ // and all handlers collection static sl_sock_hitem_t handlers[] = { - {cmd_dut1, CMD_DUT1, "set DUT1 (s)", NULL}, + {sl_comment, NULL, " Moving", NULL}, {cmd_gotoaz, CMD_GOTOAZ, "point telescope by input Az/ZD and stop", NULL}, {cmd_gotord, CMD_GOTORD, "point telescope by input RA/Dec and start tracking", NULL}, {cmd_gotorh, CMD_GOTORH, "point telescope by input RA/HA and start tracking", NULL}, - {cmd_lst, CMD_LST, "get current local sidereal time", NULL}, {cmd_park, CMD_PARK, "park telescope", NULL}, - {cmd_parkaz, CMD_PARKAZ, "set parking azimuth (Deg: 0 - north, 90 - east)", NULL}, - {cmd_parkzd, CMD_PARKZD, "set parking zenith distance (Deg)", NULL}, - {cmd_place, CMD_PLACE, "get place data", NULL}, - {cmd_polarx, CMD_POLARX, "set polar X value (m)", NULL}, - {cmd_polary, CMD_POLARY, "set polar Y value (m)", NULL}, - {cmd_raw, CMD_RAW, "send raw command to mount", NULL}, - {cmd_shutdown, CMD_SHUTDOWN, "shut down mount power", NULL}, - {status, CMD_STATUS, "get mount status", NULL}, {cmd_stop, CMD_STOP, "stop telescope", NULL}, {cmd_stoptrk, CMD_STOPTRK, "stop tracking", NULL}, - {cmd_tagaz, CMD_TAGAZ, "get/set target azimuth (Deg)", NULL}, - {cmd_tagdec, CMD_TAGDEC, "get/set target declination (Deg)", NULL}, - {cmd_tagha, CMD_TAGHA, "get/set target hour angle (Hrs)", NULL}, - {cmd_tagepoch, CMD_TAGEPOCH, "get/set target epoch (-1 for Jnow), like 2050.", NULL}, - {cmd_tagra, CMD_TAGRA, "get/set target right acsention (Hrs)", NULL}, - {cmd_tagzd, CMD_TAGZD, "get/set target zenith distance (Deg)", NULL}, + {cmd_track, CMD_TRACK, "start tracking from current position", NULL}, + + {sl_comment, NULL, " Get coordinates", NULL}, + {cmd_telaz, CMD_TELAZ, "get current telescope azimuth (Deg)", NULL}, {cmd_teldec, CMD_TELDEC, "get current telescope declination (Deg)", NULL}, {cmd_telha, CMD_TELHA, "get current telescope hour angle (Hrs)", NULL}, {cmd_telra, CMD_TELRA, "get current telescope right acsention (Hrs)", NULL}, - {cmd_telaz, CMD_TELAZ, "get current telescope azimuth (Deg)", NULL}, {cmd_telzd, CMD_TELZD, "get current telescope zenith distance (Deg)", NULL}, - {cmd_track, CMD_TRACK, "start tracking from current position", NULL}, - {dtimeh, CMD_UNIXT, "get server's UNIX time", NULL}, - {cmd_corra, CMD_CORRA, "correct RA by x arcseconds", NULL}, + + {sl_comment, NULL, " Set coordinates", NULL}, + {cmd_parkaz, CMD_PARKAZ, "set parking azimuth (Deg: 0 - north, 90 - east)", NULL}, + {cmd_parkzd, CMD_PARKZD, "set parking zenith distance (Deg)", NULL}, + {cmd_tagaz, CMD_TAGAZ, "get/set target azimuth (Deg)", NULL}, + {cmd_tagdec, CMD_TAGDEC, "get/set target declination (Deg)", NULL}, + {cmd_tagepoch, CMD_TAGEPOCH, "get/set target epoch (-1 for Jnow), like 2050.", NULL}, + {cmd_tagha, CMD_TAGHA, "get/set target hour angle (Hrs)", NULL}, + {cmd_tagra, CMD_TAGRA, "get/set target right acsention (Hrs)", NULL}, + {cmd_tagzd, CMD_TAGZD, "get/set target zenith distance (Deg)", NULL}, + + {sl_comment, NULL, " Correction", NULL}, {cmd_cordec, CMD_CORDEC, "correct Dec by x arcseconds", NULL}, + {cmd_corra, CMD_CORRA, "correct RA by x arcseconds", NULL}, {cmd_update, CMD_UPDATE, "update time/weather data to mount", NULL}, + + {sl_comment, NULL, " Mount specific", NULL}, + {cmd_raw, CMD_RAW, "send raw command to mount", NULL}, + {cmd_shutdown, CMD_SHUTDOWN, "shut down mount power", NULL}, + {cmd_status, CMD_STATUS, "get mount status", NULL}, + + {sl_comment, NULL, " Miscellaneous", NULL}, + {cmd_dtimeh, CMD_UNIXT, "get server's UNIX time", NULL}, + {cmd_dut1, CMD_DUT1, "set DUT1 (s)", NULL}, + {cmd_format, CMD_FORMAT, "change output angles format: floating (0) or string (1)", NULL}, + {cmd_lst, CMD_LST, "get current local sidereal time", NULL}, + {cmd_place, CMD_PLACE, "get place data", NULL}, + {cmd_polarx, CMD_POLARX, "set polar X value (m)", NULL}, + {cmd_polary, CMD_POLARY, "set polar Y value (m)", NULL}, + {NULL, NULL, NULL, NULL} }; @@ -661,6 +679,7 @@ void server_run(){ getPlaceData(&HDR.place); mount_get_name(HDR.mountname, MAX_HDR_STRLEN); + bool isemulated = mount_emulation_get(); DBG("While"); while(isrunning && cmd_socket && cmd_socket->connected){ usleep(sleept); @@ -672,10 +691,12 @@ void server_run(){ double tnow = sl_dtime(); if(tnow - tcheck >= MOUNT_CHECK_T){ tcheck = tnow; - if(get_weather_data(&HDR.weather) == 0){ // for airmass - lastweathertime = HDR.weather.last_update; - }else{ - WARNX("Can't get weather data"); + if(!isemulated){ + if(get_weather_data(&HDR.weather) == 0){ // for airmass + lastweathertime = HDR.weather.last_update; + }else{ + WARNX("Can't get weather data"); + } } // collect data for other fields pthread_mutex_lock(&headermutex); @@ -706,23 +727,25 @@ void server_run(){ HDR.altaz.zd = DEG2RAD(deg2); } */ - if(tnow - lastweathertime > MOUNT_WEATHER_ALRM){ - weatherlost = true; - if(HDR.status == MNT_S_TRACKING || HDR.status == MNT_S_SLEWING){ - LOGERR("Lost meteo connection -> park"); - if(mount_park()) lastweathertime = tnow; - } - } else { - weatherlost = false; - if(tnow - lastweathertime < (int)(1. + MOUNT_CHECK_T * 10.)){ // weather data is good - // 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; - } + if(!isemulated){ + if(tnow - lastweathertime > MOUNT_WEATHER_ALRM){ + weatherlost = true; + if(HDR.status == MNT_S_TRACKING || HDR.status == MNT_S_SLEWING){ + LOGERR("Lost meteo connection -> park"); + if(mount_park()) lastweathertime = tnow; } - }else WARNX("bad weather; curtime - HDR->weather.last_update = %g", tnow - lastweathertime); + } else { + weatherlost = false; + if(tnow - lastweathertime < (int)(1. + MOUNT_CHECK_T * 10.)){ // weather data is good + // 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); diff --git a/Daemons/10micron_stellarium/server.h b/Daemons/10micron_stellarium/server.h index 754c156..cdff1f7 100644 --- a/Daemons/10micron_stellarium/server.h +++ b/Daemons/10micron_stellarium/server.h @@ -31,8 +31,6 @@ // try to reconnect each RECONN seconds #define MOUNT_RECONNECT_T 60. -// max weather lost time -#define MOUNT_WEATHER_ALRM 900. // shutdown key refresh period (5min) #define SHTDWN_KEY_TMOUT 300