fixed some errors, didn't check yet

This commit is contained in:
Edward Emelianov
2026-10-13 23:38:39 +03:00
parent 5785cf2fad
commit 6916e0bcd4
9 changed files with 238 additions and 64 deletions

View File

@@ -24,7 +24,7 @@
#include "angles.h" #include "angles.h"
static placeData_t place = {.slong = 0.7232763200, .slat = 0.7618977414, .salt = 2070.}; static placeData_t place = {.slong = -0.7232763200, .slat = 0.7618977414, .salt = 2070.};
static almDut_t AlmDut = {0}; static almDut_t AlmDut = {0};
// set/get polar/DUT1 data // set/get polar/DUT1 data
@@ -189,9 +189,9 @@ void norm_RADECr(double *ra, double *dec){
// normalize angle to (-180, 180] // normalize angle to (-180, 180]
void norm_angle180(double *a){ void norm_angle180(double *a){
if(!a) return; if(!a) return;
double d = fmod(*a + 180.0, 360.0); double d = fmod(*a, 360.0);
if(d < 0.) d += 360.0; if(d < -180.) d += 360.0;
else d -= 180; else if(d > 180.) d -= 360.;
*a = d; *a = d;
} }
@@ -381,6 +381,7 @@ bool get_LST(sMJD_t *mjd, double *LST){
return true; return true;
} }
#if 0
/** /**
* @brief get_ObsPlace - calculate observed place (without PM etc) for given date @550nm * @brief get_ObsPlace - calculate observed place (without PM etc) for given date @550nm
* @param tval (i) - time * @param tval (i) - time
@@ -436,6 +437,99 @@ bool get_ObsPlace(struct timeval *tval, polarCrds_t *p2000, polarCrds_t *pnow, h
} }
return true; return true;
} }
#endif
// used in two functions
static bool J2000to_ep_(const polarCrds_t *j2000, polarCrds_t *jepoch, double date1, double date2){
if(!j2000 || !jepoch) return false;
double r_j2000[3], r_ep[3], rmat[3][3];
// spherical coordinates to vector
eraS2c(j2000->ra, j2000->dec, r_j2000);
// rmat - prec/nut matrix from J2000 to given epoch
eraPnm06a(date1, date2, rmat);
// r_ep = rmat * r_j2000
eraRxp(rmat, r_j2000, r_ep);
// vector to coordinates
eraC2s(r_ep, &jepoch->ra, &jepoch->dec);
// normalize angle
jepoch->ra = eraAnp(jepoch->ra);
return true;
}
static bool ep_toJ2000_(const polarCrds_t *jepoch, polarCrds_t *j2000, double date1, double date2){
if(!j2000 || !jepoch) return false;
double r_ep[3], r_j2000[3], rmat[3][3];
eraS2c(jepoch->ra, jepoch->dec, r_ep);
eraPnm06a(date1, date2, rmat);
// use eraTrxp for multiplication by transposed matrix (reverse transform)
eraTrxp(rmat, r_ep, r_j2000);
eraC2s(r_j2000, &j2000->ra, &j2000->dec);
j2000->ra = eraAnp(j2000->ra);
return true;
}
/**
* @brief J2000_to_epoch_pn - convert J2000 to given epoch (prec/nut)
* @param j2000 (i) - catalog coordinates
* @param epoch - epoch (like 2050.)
* @param jepoch (o) - coordinates for epoch
*/
bool J2000_to_epoch_pn(const polarCrds_t *j2000, double epoch, polarCrds_t *jepoch){
double date1, date2;
// calculate JD for target epoch
eraEpj2jd(epoch, &date1, &date2);
return J2000to_ep_(j2000, jepoch, date1, date2);
}
/**
* @brief epoch_to_J2000_pn - convert coordinates for given epoch to J2000
* @param jepoch (i) - coordinates for epoch
* @param epoch (o) - epoch (like 2050.)
*/
bool epoch_to_J2000_pn(const polarCrds_t *jepoch, double epoch, polarCrds_t *j2000){
double date1, date2;
eraEpj2jd(epoch, &date1, &date2);
return ep_toJ2000_(jepoch, j2000, date1, date2);
}
/**
* @brief JnowtoJ2000 - convert coordinates from Jnow to J2000
* @param in - current coordinates
* @param out - catalog coordinates
* @return false if arguments are wrong
*/
bool JnowtoJ2000(const polarCrds_t *in, polarCrds_t *out){
sMJD_t MJD;
// calculate current MJD
if(!get_MJDt(NULL, &MJD)) return false;
return ep_toJ2000_(in, out, MJD.tt1, MJD.tt2);
}
/**
* @brief JXtoJnow - convert coordinates from any epoch to Jnow
* @param in - epoch coordinates
* @param out - current coordinates
* @param Jx - given epoch like 2050.
* @return false if arguments are wrong
*/
bool JXtoJnow(const polarCrds_t *in, polarCrds_t *out, double Jx){
sMJD_t MJD;
polarCrds_t j2000;
// calculate current MJD
if(!get_MJDt(NULL, &MJD)) return false;
// convert Jx to J2000
if(!epoch_to_J2000_pn(in, Jx, &j2000)) return false;
// and convert J2000 to Jnow
return J2000to_ep_(&j2000, out, MJD.tt1, MJD.tt2);
}
#if 0
/** /**
* convert geocentric coordinates (nowadays, CIRS) to mean (JD2000, ICRS) * convert geocentric coordinates (nowadays, CIRS) to mean (JD2000, ICRS)
@@ -489,3 +583,4 @@ bool JXtoJnow(const polarCrds_t *in, polarCrds_t *out, double Jx){
return true; return true;
} }
#endif

View File

@@ -83,7 +83,9 @@ void d2sDMS(double degrees, char *dms, int len);
bool get_MJDt(struct timeval *tval, sMJD_t *MJD); bool get_MJDt(struct timeval *tval, sMJD_t *MJD);
bool get_LST(sMJD_t *mjd, double *LST); bool get_LST(sMJD_t *mjd, double *LST);
#if 0
bool get_ObsPlace(struct timeval *tval, polarCrds_t *p2000, polarCrds_t *pnow, horizCrds_t *hnow); bool get_ObsPlace(struct timeval *tval, polarCrds_t *p2000, polarCrds_t *pnow, horizCrds_t *hnow);
#endif
bool setDUT(almDut_t *D); bool setDUT(almDut_t *D);
void getDUT(almDut_t *D); void getDUT(almDut_t *D);
@@ -91,5 +93,8 @@ void getDUT(almDut_t *D);
bool setPlaceData(placeData_t *pd); bool setPlaceData(placeData_t *pd);
void getPlaceData(placeData_t *pd); void getPlaceData(placeData_t *pd);
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 JnowtoJ2000(const polarCrds_t *in, polarCrds_t *out); bool JnowtoJ2000(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);

View File

@@ -164,7 +164,7 @@ void wrhdr(fitsheader_t *HDR){
} }
WRHDR("TELSTAT", mount_status_str(HDR->status), "Telescope mount status"); WRHDR("TELSTAT", mount_status_str(HDR->status), "Telescope mount status");
double mjd; double mjd;
mount_getInpMJD(&mjd); mount_getInpEpoch(&mjd);
if(mjd > 0.) snprintf(val, 22, "%.10f", 2000.+(mjd - ERFA_DJM00)/365.25); // calculate EPOCH/EQUINOX if(mjd > 0.) snprintf(val, 22, "%.10f", 2000.+(mjd - ERFA_DJM00)/365.25); // calculate EPOCH/EQUINOX
else snprintf(val, 22, "%.10f", 2000.+(HDR->MJD.MJD - ERFA_DJM00)/365.25); else snprintf(val, 22, "%.10f", 2000.+(HDR->MJD.MJD - ERFA_DJM00)/365.25);
WRHDR("INPEQUIN", val, "Equinox of input celestial coordinate system"); WRHDR("INPEQUIN", val, "Equinox of input celestial coordinate system");

View File

@@ -68,11 +68,6 @@ int main(int argc, char **argv){
WARNX("Can't set sleep time to %d", G->sleept); WARNX("Can't set sleep time to %d", G->sleept);
return 3; return 3;
} }
if(G->emulation) set_emulation_mode();
else if(!mount_set_dev(G->device, G->serspeed, G->sertmout)){
WARNX("Can't open device %s @ %d", G->device, G->serspeed);
return 4;
}
if(!mount_set_name(G->mountname)){ if(!mount_set_name(G->mountname)){
WARNX("Can't set mount name to %s", G->mountname); WARNX("Can't set mount name to %s", G->mountname);
return 5; return 5;
@@ -134,6 +129,13 @@ int main(int argc, char **argv){
} }
if(!isrunning) return 0; if(!isrunning) return 0;
#endif #endif
if(G->emulation) set_emulation_mode();
else if(!mount_set_dev(G->device, G->serspeed, G->sertmout)){
WARNX("Can't open device %s @ %d", G->device, G->serspeed);
return 4;
}
server_sock_t sockt = { server_sock_t sockt = {
.cmd_isunix = G->isunix, .cmd_isunix = G->isunix,
.cmdnode = G->cmdnode, .cmdnode = G->cmdnode,

View File

@@ -52,10 +52,16 @@ static horizCrds_t ParkCoords = {.az = DEG2RAD(1.8105556), .zd = DEG2RAD(88.7752
static polarCrds_t InpCoords = {0}, // input as user give (for epoch InpMJD) static polarCrds_t InpCoords = {0}, // input as user give (for epoch InpMJD)
TagCoords = {0}; // target for Jnow after command "point to input" TagCoords = {0}; // target for Jnow after command "point to input"
static horizCrds_t InpHoriz = {0}; static horizCrds_t InpHoriz = {0};
// input MJD (Modified Julian Date: started from ERFA_DJM0==2400000.5) // epoch for input coordinates
static double InpMJD = ERFA_DJM00; // J2000 static double InpEpoch = 2000.; // J2000
// times of coords/mjd change // times of coords/epoch change
static double InpCTime = 0., TagTime = 0., InpHTime = 0., InpMTime = 0.; static double InpCTime = 0., TagTime = 0., InpHTime = 0., InpETime = 0.;
// safe strncpy
static void scpy(size_t len, char *dest, const char *src){
size_t l = snprintf(dest, len, "%s", src);
if(l >= len) dest[len-1] = 0;
}
// return time of modification // return time of modification
double mount_getInpCoords(polarCrds_t *c){ double mount_getInpCoords(polarCrds_t *c){
@@ -66,9 +72,9 @@ double mount_getTagCoords(polarCrds_t *c){
if(c) *c = TagCoords; if(c) *c = TagCoords;
return TagTime; return TagTime;
} }
double mount_getInpMJD(double *MJD){ double mount_getInpEpoch(double *epoch){
if(MJD) *MJD = InpMJD; if(epoch) *epoch = InpEpoch;
return InpMTime; return InpETime;
} }
double mount_getInpHor(horizCrds_t *c){ double mount_getInpHor(horizCrds_t *c){
if(c) *c = InpHoriz; if(c) *c = InpHoriz;
@@ -133,9 +139,9 @@ bool mount_setInpZ(double Z){
return true; return true;
} }
// without checking // without checking
bool mount_setInpMJD(double m){ bool mount_setInpEpoch(double epoch){
InpMJD = m; InpEpoch = epoch;
InpMTime = sl_dtime(); InpETime = sl_dtime();
return true; return true;
} }
@@ -169,6 +175,7 @@ void mount_get_name(char *nm, size_t l){
* @return false if failed to open device `dev` * @return false if failed to open device `dev`
*/ */
bool mount_set_dev(char *dev, int speed, double timeout){ bool mount_set_dev(char *dev, int speed, double timeout){
if(isemulated) return true;
pthread_mutex_lock(&mntdev_mutex); pthread_mutex_lock(&mntdev_mutex);
if(mount_dev) sl_tty_close(&mount_dev); if(mount_dev) sl_tty_close(&mount_dev);
mount_dev = sl_tty_new(dev, speed, 4096); mount_dev = sl_tty_new(dev, speed, 4096);
@@ -288,6 +295,7 @@ static bool write_cmd(const char *cmd, bool haveanswer){
// return current mount status // return current mount status
mount_status_t mount_status(){ mount_status_t mount_status(){
if(isemulated) return emulation_status();
mount_status_t curst = (mount_status_t)atomic_load(&mountstatus); mount_status_t curst = (mount_status_t)atomic_load(&mountstatus);
if(curst == MNT_S_OFF) return curst; // do nothing when mount if off if(curst == MNT_S_OFF) return curst; // do nothing when mount if off
if(!mount_dev){ if(!mount_dev){
@@ -588,7 +596,7 @@ bool mount_tracking_start(){
* @return false if failed to run command * @return false if failed to run command
*/ */
bool mount_park(){ bool mount_park(){
if(isemulated) return pointAZ_emulation(ParkCoords.az, ParkCoords.zd); if(isemulated) return pointAZ_emulation(RAD2DEG(ParkCoords.az), RAD2DEG(ParkCoords.zd));
char buf[64]; char buf[64];
snprintf(buf, 63, CMD_SETMINALT, 0); snprintf(buf, 63, CMD_SETMINALT, 0);
if(!write_cmd(buf, true)) return false; if(!write_cmd(buf, true)) return false;
@@ -633,6 +641,10 @@ void mount_getPark(horizCrds_t *c){
* @return false if failed * @return false if failed
*/ */
bool mount_getpierside(char *Ps, size_t len){ bool mount_getpierside(char *Ps, size_t len){
if(isemulated){
scpy(len, Ps, "Emulation");
return true;
}
pthread_mutex_lock(&mntdev_mutex); pthread_mutex_lock(&mntdev_mutex);
bool ret = send_cmd_resp(CMD_GETPS, Ps, len); bool ret = send_cmd_resp(CMD_GETPS, Ps, len);
pthread_mutex_unlock(&mntdev_mutex); pthread_mutex_unlock(&mntdev_mutex);
@@ -645,6 +657,7 @@ bool mount_getpierside(char *Ps, size_t len){
* @return false if failed to connect * @return false if failed to connect
*/ */
bool mount_corrdata(weather_data_t *w){ bool mount_corrdata(weather_data_t *w){
if(isemulated) return true;
if(!w) return false; if(!w) return false;
bool ret = true; // returning value bool ret = true; // returning value
mount_status_t curst = mount_status(); mount_status_t curst = mount_status();
@@ -687,6 +700,7 @@ bool mount_corrdata(weather_data_t *w){
* @return false if failed * @return false if failed
*/ */
bool mount_shutdown(){ bool mount_shutdown(){
if(isemulated) return false;
return write_cmd(CMD_SHUTDOWN, true); return write_cmd(CMD_SHUTDOWN, true);
} }
@@ -698,5 +712,6 @@ 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;
return send_cmd_resp(cmd, ans, anslen); return send_cmd_resp(cmd, ans, anslen);
} }

View File

@@ -54,11 +54,11 @@ 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); bool mount_setInpEpoch(double epoch);
double mount_getInpCoords(polarCrds_t *c); double mount_getInpCoords(polarCrds_t *c);
double mount_getTagCoords(polarCrds_t *c); double mount_getTagCoords(polarCrds_t *c);
double mount_getInpMJD(double *MJD); double mount_getInpEpoch(double *epoch);
double mount_getInpHor(horizCrds_t *c); double mount_getInpHor(horizCrds_t *c);

View File

@@ -1,10 +1,10 @@
<?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-09-29T09:41:26. --> <!-- Written by QtCreator 20.0.1, 2026-10-13T23:29:46. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value> <value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -30,13 +30,11 @@
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value> <value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value> <value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value> <value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value> <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabSize">8</value> <value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value> <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value> <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value> <value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
</valuemap> </valuemap>
</data> </data>
<data> <data>
@@ -56,7 +54,6 @@
<value type="int" key="AutoTest.RunAfterBuild">0</value> <value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value> <value type="bool" key="AutoTest.UseGlobal">true</value>
<valuemap type="QVariantMap" key="ClangTools"> <valuemap type="QVariantMap" key="ClangTools">
<value type="Utils::Id" key="ClangTools.DiagnosticConfig"></value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/> <valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/> <valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/> <valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
@@ -72,12 +69,12 @@
<value type="bool" key="HasPerBcDcs">true</value> <value type="bool" key="HasPerBcDcs">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{65a14f9e-e008-4c1b-89df-4eaa4774b6e3}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/10micron/C-sources/mountdaemon_10micron</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/tmp/r1/10micron_stellarium</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets"> <valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
@@ -109,7 +106,7 @@
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/> <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value> <value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<value type="UnknownType" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"></value> <value type="UnknownType" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
@@ -145,8 +142,26 @@
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value> <value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">%{RunConfig:Executable:Path}</value>
</valuemap> </valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.1">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.SuppressionFiles"/>
<value type="QList&lt;int&gt;" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">RemoteDebugger.RunConfig</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">2</value>
</valuemap> </valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value> <value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
@@ -181,8 +196,26 @@
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value> <value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">%{RunConfig:Executable:Path}</value>
</valuemap> </valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.1">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.SuppressionFiles"/>
<value type="QList&lt;int&gt;" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">RemoteDebugger.RunConfig</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">2</value>
</valuemap> </valuemap>
</data> </data>
<data> <data>

View File

@@ -53,8 +53,8 @@
#define CMD_STOPTRK "stoptrk" #define CMD_STOPTRK "stoptrk"
#define CMD_TAGAZ "tagaz" #define CMD_TAGAZ "tagaz"
#define CMD_TAGDEC "tagdec" #define CMD_TAGDEC "tagdec"
#define CMD_TAGEPOCH "tagepoch"
#define CMD_TAGHA "tagha" #define CMD_TAGHA "tagha"
#define CMD_TAGMJD "tagmjd"
#define CMD_TAGRA "tagra" #define CMD_TAGRA "tagra"
#define CMD_TAGZD "tagzd" #define CMD_TAGZD "tagzd"
#define CMD_TELAZ "telaz" #define CMD_TELAZ "telaz"
@@ -265,7 +265,7 @@ static sl_sock_hresult_e cmd_gotord(_U_ sl_sock_t *c, _U_ sl_sock_hitem_t *item,
polarCrds_t px, pnow; polarCrds_t px, pnow;
mount_getInpCoords(&px); mount_getInpCoords(&px);
double Epoch; double Epoch;
mount_getInpMJD(&Epoch); mount_getInpEpoch(&Epoch);
if(Epoch > 0.){ if(Epoch > 0.){
if(!JXtoJnow(&px, &pnow, Epoch)) return RESULT_FAIL; if(!JXtoJnow(&px, &pnow, Epoch)) return RESULT_FAIL;
}else pnow = px; }else pnow = px;
@@ -363,24 +363,18 @@ static sl_sock_hresult_e cmd_parkzd(sl_sock_t *c, sl_sock_hitem_t *item, const c
return RESULT_SILENCE; return RESULT_SILENCE;
} }
static sl_sock_hresult_e cmd_tagmjd(sl_sock_t *c, sl_sock_hitem_t *item, const char *req){ static sl_sock_hresult_e cmd_tagepoch(sl_sock_t *c, sl_sock_hitem_t *item, const char *req){
double val; double val;
bool isyear = false;
if(req && *req == 'J'){ // e.g. J2050.
++req;
isyear = true;
}
int res = parse_key_value(req, &val); int res = parse_key_value(req, &val);
if(res < 0) return RESULT_BADVAL; if(res < 0) return RESULT_BADVAL;
if(res > 0){ if(res > 0){ // setter
if(isyear) val = (val - 2000.)*365.25 + ERFA_DJM00; LOGDBG("Client %d set target epoch %g", res);
LOGDBG("Client %d set target epoch %g", c->fd, val); if(mount_setInpEpoch(val)) return RESULT_OK;
if(mount_setInpMJD(val)) return RESULT_OK;
return RESULT_BADVAL; return RESULT_BADVAL;
} }
mount_getInpMJD(&val); mount_getInpEpoch(&val);
char buf[64]; char buf[64];
snprintf(buf, 63, "%s=%.1f\n", item->key, val); snprintf(buf, 63, "%s=%.6f\n", item->key, val);
sl_sock_sendstrmessage(c, buf); sl_sock_sendstrmessage(c, buf);
return RESULT_SILENCE; return RESULT_SILENCE;
} }
@@ -511,7 +505,7 @@ static sl_sock_hitem_t handlers[] = {
{cmd_tagaz, CMD_TAGAZ, "get/set target azimuth (Deg)", NULL}, {cmd_tagaz, CMD_TAGAZ, "get/set target azimuth (Deg)", NULL},
{cmd_tagdec, CMD_TAGDEC, "get/set target declination (Deg)", NULL}, {cmd_tagdec, CMD_TAGDEC, "get/set target declination (Deg)", NULL},
{cmd_tagha, CMD_TAGHA, "get/set target hour angle (Hrs)", NULL}, {cmd_tagha, CMD_TAGHA, "get/set target hour angle (Hrs)", NULL},
{cmd_tagmjd, CMD_TAGMJD, "get/set target MJD epoch (-1 for Jnow) or Jxxx for year, like J2050.", 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_tagra, CMD_TAGRA, "get/set target right acsention (Hrs)", NULL},
{cmd_tagzd, CMD_TAGZD, "get/set target zenith distance (Deg)", NULL}, {cmd_tagzd, CMD_TAGZD, "get/set target zenith distance (Deg)", NULL},
{cmd_teldec, CMD_TELDEC, "get current telescope declination (Deg)", NULL}, {cmd_teldec, CMD_TELDEC, "get current telescope declination (Deg)", NULL},

View File

@@ -35,6 +35,8 @@
// running flag // running flag
extern volatile bool isrunning; extern volatile bool isrunning;
static pthread_t mainthread; static pthread_t mainthread;
static int newsockfd = -1; // new socket fd for handler thread
static pthread_mutex_t sockmutex = PTHREAD_MUTEX_INITIALIZER; // mutex for copying previous variable
//read: 0x14 0x0 0x0 0x0 0x5b 0x5a 0x2e 0xc6 0x8c 0x23 0x5 0x0 0x23 0x9 0xe5 0xaf 0x23 0x2e 0x34 0xed //read: 0x14 0x0 0x0 0x0 0x5b 0x5a 0x2e 0xc6 0x8c 0x23 0x5 0x0 0x23 0x9 0xe5 0xaf 0x23 0x2e 0x34 0xed
// command: goto 16h29 24.45 -26d25 55.62 // command: goto 16h29 24.45 -26d25 55.62
@@ -129,7 +131,7 @@ static bool proc_data(uint8_t *data, ssize_t len){
double tagRA = RA2HRS(ra), tagDec = DEC2DEG(dec); double tagRA = RA2HRS(ra), tagDec = DEC2DEG(dec);
DBG("RA: %u (%g hrs), DEC: %d (%g degr)", ra, tagRA, dec, tagDec); DBG("RA: %u (%g hrs), DEC: %d (%g degr)", ra, tagRA, dec, tagDec);
LOGMSG("(stellarium) RA: %u (%g hrs), DEC: %d (%g degr)", ra, tagRA, dec, tagDec); LOGMSG("(stellarium) RA: %u (%g hrs), DEC: %d (%g degr)", ra, tagRA, dec, tagDec);
return (mount_setInpRA(tagRA) && mount_setInpDec(tagDec) && mount_setInpMJD(ERFA_DJM00)); return (mount_setInpRA(tagRA) && mount_setInpDec(tagDec) && mount_setInpEpoch(ERFA_DJM00));
} }
/** /**
@@ -151,14 +153,35 @@ static bool send_data(uint8_t *data, size_t dlen, int sockfd){
return true; return true;
} }
// read exactly dlen bytes of data with timeout 1s
static ssize_t get_data(int sockfd, uint8_t *data, size_t dlen){
double t0 = sl_dtime();
uint8_t *ptr = data;
ssize_t got = 0;
while(sl_dtime() - t0 < 1. && dlen){
if(!sl_canread(sockfd)) continue;
ssize_t rd = read(sockfd, ptr, dlen);
if(rd < 0) return -1;
else if(rd == 0) break;
dlen -= rd;
ptr += rd;
got += rd;
}
return got;
}
/** /**
* main socket service procedure * main socket service procedure
*/ */
static void *handle_socket(void *sockd){ static void *handle_socket(void *sockd){
FNAME(); FNAME();
if(!isrunning) return NULL; if(!isrunning){
pthread_mutex_unlock(&sockmutex);
return NULL;
}
outdata dout; outdata dout;
int sock = *(int*)sockd; int sock = *(int*)sockd;
pthread_mutex_unlock(&sockmutex); // copy done
dout.len = htole16(sizeof(outdata)); dout.len = htole16(sizeof(outdata));
dout.type = 0; dout.type = 0;
while(isrunning){ while(isrunning){
@@ -174,8 +197,8 @@ static void *handle_socket(void *sockd){
dout.ra = htole32(RAD2RA(J2000.ra)); dout.ra = htole32(RAD2RA(J2000.ra));
dout.dec = (int32_t)htole32(RAD2DEC(J2000.dec)); dout.dec = (int32_t)htole32(RAD2DEC(J2000.dec));
*/ */
dout.ra = htole32(RAD2RA(HRS2RAD(HDR.polar.ra))); dout.ra = htole32(RAD2RA(HDR.polar.ra));
dout.dec = (int32_t)htole32(RAD2DEC(DEG2RAD(HDR.polar.dec))); dout.dec = (int32_t)htole32(RAD2DEC(HDR.polar.dec));
/**/ /**/
if(!send_data((uint8_t*)&dout, sizeof(outdata), sock)) break; // send data even in `off` state if(!send_data((uint8_t*)&dout, sizeof(outdata), sock)) break; // send data even in `off` state
if(!sl_canread(sock)){ if(!sl_canread(sock)){
@@ -184,7 +207,7 @@ static void *handle_socket(void *sockd){
} }
// 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 = get_data(sock, buff, sizeof(indata));
if(rd <= 0){ // error or disconnect if(rd <= 0){ // error or disconnect
DBG("Nothing to read from fd %d (ret: %zd)", sock, rd); DBG("Nothing to read from fd %d (ret: %zd)", sock, rd);
WARNX("Client disconnected?"); WARNX("Client disconnected?");
@@ -192,7 +215,7 @@ 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 = htole32(-1);
else{ else{
DBG("sent OK"); DBG("sent OK");
dout.status = 0; dout.status = 0;
@@ -218,10 +241,9 @@ static void* start(void *F){
while(isrunning){ while(isrunning){
socklen_t size = sizeof(struct sockaddr_in); socklen_t size = sizeof(struct sockaddr_in);
struct sockaddr_in myaddr; struct sockaddr_in myaddr;
int newsock;
DBG("ACCEPT"); DBG("ACCEPT");
newsock = accept(sockfd, (struct sockaddr*)&myaddr, &size); newsockfd = accept(sockfd, (struct sockaddr*)&myaddr, &size);
if(newsock <= 0){ if(newsockfd <= 0){
if(errno == EAGAIN){ if(errno == EAGAIN){
usleep(1000); usleep(1000);
continue; // nothing available continue; // nothing available
@@ -233,14 +255,14 @@ static void* start(void *F){
} }
struct sockaddr_in peer; struct sockaddr_in peer;
socklen_t peer_len = sizeof(peer); socklen_t peer_len = sizeof(peer);
if(getpeername(newsock, (struct sockaddr*)&peer, &peer_len) == -1){ if(getpeername(newsockfd, (struct sockaddr*)&peer, &peer_len) == -1){
LOGWARN("Stellarium socket error in getpeername()"); LOGWARN("Stellarium socket error in getpeername()");
WARN("getpeername()"); WARN("getpeername()");
close(newsock); close(newsockfd);
continue; continue;
} }
int sockport = -1; int sockport = -1;
if(getsockname(newsock, (struct sockaddr*)&peer, &peer_len) == 0){ if(getsockname(newsockfd, (struct sockaddr*)&peer, &peer_len) == 0){
sockport = ntohs(peer.sin_port); sockport = ntohs(peer.sin_port);
} }
char *peerIP = inet_ntoa(peer.sin_addr); char *peerIP = inet_ntoa(peer.sin_addr);
@@ -252,21 +274,29 @@ static void* start(void *F){
continue; continue;
}*/ }*/
pthread_t rthrd; pthread_t rthrd;
if(pthread_create(&rthrd, NULL, handle_socket, (void*)&newsock)){ pthread_mutex_lock(&sockmutex);
if(pthread_create(&rthrd, NULL, handle_socket, (void*)&newsockfd)){
WARN("Can't create socket thread"); WARN("Can't create socket thread");
LOGERR("Stellarium socket: error creating listen thread"); LOGERR("Stellarium socket: error creating listen thread");
}else{ }else{
DBG("Thread created, detouch"); DBG("Thread created, detouch");
pthread_detach(rthrd); // don't care about thread state pthread_detach(rthrd); // don't care about thread state
// mutex unlocking will be in thread, but care for timeout
double t0 = sl_dtime();
while(sl_dtime() - t0 < 3.){
if(0 == pthread_mutex_trylock(&sockmutex)){ // released
break;
}
}
} }
pthread_mutex_unlock(&sockmutex);
} }
close(sockfd); close(sockfd);
return NULL; return NULL;
} }
bool stellarium_start(int sockfd){ bool stellarium_start(int sockfd){
int fd = sockfd; if(pthread_create(&mainthread, NULL, start, (void*)&sockfd)){
if(pthread_create(&mainthread, NULL, start, (void*)&fd)){
WARN("pthread_create()"); WARN("pthread_create()");
return false; return false;
} }