void ListValues::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn; connections_t::iterator iter; rts2core::ValueVector::iterator variter; int i = 0; // print results for single device.. for (iter = serv->getCentraldConns ()->begin (); iter != serv->getCentraldConns ()->end (); iter++) { conn = *iter; std::string deviceName = (*iter)->getName (); // filter device list for (variter = conn->valueBegin (); variter != conn->valueEnd (); variter++, i++) { result[i] = deviceName + "." + (*variter)->getName (); } } for (iter = serv->getConnections ()->begin (); iter != serv->getConnections ()->end (); iter++) { conn = *iter; std::string deviceName = (*iter)->getName (); // filter device list for (variter = conn->valueBegin (); variter != conn->valueEnd (); variter++, i++) { result[i] = deviceName + "." + (*variter)->getName (); } } }
void GetPrettyValue::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { std::string devName = params[0]; std::string valueName = params[1]; HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn; if (devName.length () == 0) { conn = serv->getSingleCentralConn (); } else { conn = serv->getOpenConnection (devName.c_str ()); } if (!conn) { throw XmlRpcException ("Cannot find connection '" + std::string (devName) + "'."); } rts2core::Value *val = conn->getValue (valueName.c_str ()); if (!val) { throw XmlRpcException ("Cannot find value '" + std::string (valueName) + "' on device '" + std::string (devName) + "'."); } result = getDisplayValue (val); }
void DeviceCommand::sessionExecute (XmlRpcValue& params, XmlRpcValue &result) { if (params.size () != 2) throw XmlRpcException ("Device name and command (as single parameter) expected"); HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn = serv->getOpenConnection (((std::string)params[0]).c_str()); if (conn == NULL) throw XmlRpcException ("Device named " + (std::string)params[0] + " does not exists"); conn->queCommand (new rts2core::Command (serv, ((std::string)params[1]).c_str())); }
void DeviceType::sessionExecute (XmlRpcValue& params, XmlRpcValue &result) { if (params.size () != 1) throw XmlRpcException ("Single device name expected"); HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn = serv->getOpenConnection (((std::string)params[0]).c_str()); if (conn == NULL) throw XmlRpcException ("Cannot get device with name " + (std::string)params[0]); result = conn->getOtherType (); }
void ListDevices::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { HttpD *serv = (HttpD *) getMasterApp (); connections_t::iterator iter; int i = 0; for (iter = serv->getConnections ()->begin (); iter != serv->getConnections ()->end (); iter++, i++) { result[i] = (*iter)->getName (); } }
void SetValue::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { std::string devName = params[0]; std::string valueName = params[1]; HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn = serv->getOpenConnection (devName.c_str ()); if (!conn) { throw XmlRpcException ("Cannot find connection '" + std::string (devName) + "'."); } setXmlValutRts2 (conn, valueName, params[2]); }
void GetValue::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { std::string devName = params[0]; std::string valueName = params[1]; HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn; if (devName.length () == 0) { conn = serv->getSingleCentralConn (); } else { conn = serv->getOpenConnection (devName.c_str ()); } if (!conn) { throw XmlRpcException ("Cannot find connection '" + std::string (devName) + "'."); } rts2core::Value *val = conn->getValue (valueName.c_str ()); if (!val) { throw XmlRpcException ("Cannot find value '" + std::string (valueName) + "' on device '" + std::string (devName) + "'."); } switch (val->getValueBaseType ()) { case RTS2_VALUE_INTEGER: case RTS2_VALUE_LONGINT: result = val->getValueInteger (); break; case RTS2_VALUE_FLOAT: result = val->getValueFloat (); break; case RTS2_VALUE_DOUBLE: result = val->getValueDouble (); break; case RTS2_VALUE_BOOL: result = ((rts2core::ValueBool *)val)->getValueBool (); break; case RTS2_VALUE_TIME: struct tm tm_s; long usec; ((rts2core::ValueTime*)val)->getStructTm (&tm_s, &usec); result = XmlRpcValue (&tm_s); break; default: result = val->getValue (); break; } }
void DeviceByType::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { HttpD *serv = (HttpD *) getMasterApp (); connections_t::iterator iter = serv->getConnections ()->begin (); int i = 0; int type = params[0]; while (true) { serv->getOpenConnectionType (type, iter); if (iter == serv->getConnections ()->end ()) break; result[i] = (*iter)->getName (); iter++; i++; } }
void DeviceState::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { if (params.size () != 1) { throw XmlRpcException ("Invalid number of parameters"); } HttpD *serv = (HttpD *) getMasterApp (); std::string p1 = std::string (params[0]); rts2core::Connection *conn; if (p1 == "centrald" || p1 == "") conn = *(serv->getCentraldConns ()->begin ()); else conn = serv->getOpenConnection (p1.c_str ()); if (conn == NULL) { throw XmlRpcException ("Cannot find specified device"); } result[0] = conn->getStateString (); result[1] = (int) conn->getRealState (); }
void SetValueByType::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { int devType = params[0]; std::string valueName = params[1]; HttpD *serv = (HttpD *) getMasterApp (); connections_t::iterator iter = serv->getConnections ()->begin (); serv->getOpenConnectionType (devType, iter); if (iter == serv->getConnections ()->end ()) { throw XmlRpcException ("Cannot find connection of given type"); } for (; iter != serv->getConnections ()->end (); serv->getOpenConnectionType (devType, ++iter)) { setXmlValutRts2 (*iter, valueName, params[2]); } }
void CurrentPosition::authorizedExecute (XmlRpc::XmlRpcSource *source, std::string path, XmlRpc::HttpParams *params, const char* &response_type, char* &response, size_t &response_length) { int s = params->getInteger ("s", 250); rts2json::AltAz altaz = rts2json::AltAz (s, s); altaz.rotation = params->getInteger ("rot", 180); altaz.mirror = params->getBoolean ("mirror", true); bool showHorizon = params->getBoolean ("horizon", true); bool showSunMoon = params->getBoolean ("sunmoon", true); double bsc_limmag = params->getDouble ("starsmag", 3.9); double bsc_maxsize = params->getDouble ("starssize", 0); if (!bsc_maxsize && s >= 250) bsc_maxsize = 2.5; struct ln_equ_posn pos; struct ln_hrz_posn hrz; double JD = ln_get_julian_from_sys (); if (bsc_maxsize > 0.0) { for (bsc_record *star = bsc; star->hrn >= 0; star++) { if (star->mag > bsc_limmag) continue; pos.ra = star->ra; pos.dec = star->dec; ln_get_hrz_from_equ (&pos, Configuration::instance ()->getObserver (), JD, &hrz); if (hrz.alt <= 0.0) continue; altaz.plot (&hrz, NULL, "grey30", PLOT_TYPE_POINT, - (star->mag - bsc_limmag) / bsc_limmag * bsc_maxsize); } } if (showHorizon) altaz.plotAltAzHorizon (); altaz.plotAltAzGrid (); // position of sun & moon if (showSunMoon) { ln_get_solar_equ_coords (JD, &pos); ln_get_hrz_from_equ (&pos, Configuration::instance ()->getObserver (), JD, &hrz); altaz.plot (&hrz, "☉", "OrangeRed", PLOT_TYPE_POINT, 4); ln_get_lunar_equ_coords (JD, &pos); ln_get_hrz_from_equ (&pos, Configuration::instance ()->getObserver (), JD, &hrz); altaz.plot (&hrz, "☾", "grey10", PLOT_TYPE_POINT, 4); } // get current target position.. HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn = serv->getOpenConnection (DEVICE_TYPE_MOUNT); rts2core::Value *val; if (conn) { val = conn->getValue ("TEL_"); if (val && val->getValueType () == RTS2_VALUE_ALTAZ) { hrz.alt = ((rts2core::ValueAltAz *) val)->getAlt (); hrz.az = ((rts2core::ValueAltAz *) val)->getAz (); altaz.plot (&hrz, "TEL", "red", PLOT_TYPE_TELESCOPE, 12); } val = conn->getValue ("TAR"); if (val && val->getValueType () == RTS2_VALUE_RADEC) { pos.ra = ((rts2core::ValueRaDec *) val)->getRa (); pos.dec = ((rts2core::ValueRaDec *) val)->getDec (); if (!(std::isnan (pos.ra) || std::isnan (pos.dec))) { ln_get_hrz_from_equ (&pos, Configuration::instance ()->getObserver (), JD, &hrz); altaz.plotCross (&hrz, NULL, "blue"); } } } #ifdef RTS2_HAVE_PGSQL conn = serv->getOpenConnection (DEVICE_TYPE_EXECUTOR); if (conn) { rts2db::Target *tar; val = conn->getValue ("current"); if (val && val->getValueInteger () >= 0) { tar = createTarget (val->getValueInteger (), Configuration::instance ()->getObserver (), Configuration::instance ()->getObservatoryAltitude ()); if (tar) { tar->getAltAz (&hrz, JD); altaz.plotCross (&hrz, tar->getTargetName (), "green"); delete tar; } } val = conn->getValue ("next"); if (val && val->getValueInteger () >= 0) { tar = createTarget (val->getValueInteger (), Configuration::instance ()->getObserver (), Configuration::instance ()->getObservatoryAltitude ()); if (tar) { tar->getAltAz (&hrz, JD); altaz.plotCross (&hrz, tar->getTargetName (), "blue"); delete tar; } } } #endif /* RTS2_HAVE_PGSQL */ Magick::Blob blob; altaz.write (&blob, "JPEG"); response_type = "image/jpeg"; response_length = blob.length(); response = new char[response_length]; memcpy (response, blob.data(), response_length); }
int BBAPI::scheduleTarget (time_t &ret_from, XmlRpc::HttpParams *params, bool only_confirm, std::vector <std::pair <double, double> > &free_time) { rts2db::Target *tar = rts2json::getTarget (params); double from = params->getDouble ("from", getNow ()); double to = params->getDouble ("to", from + 86400); if (to < from) { delete tar; throw JSONException ("to time is before from time"); } int observatory_id = -1; int schedule_id = -1; if (only_confirm) { observatory_id = params->getInteger ("observatory_id", -1); schedule_id = params->getInteger ("schedule_id", -1); if (observatory_id == -1 || schedule_id == -1) { delete tar; throw JSONException ("missing schedule ID"); } } // find free spots HttpD *master = (HttpD*) getMasterApp (); connections_t::iterator iter = master->getConnections ()->begin (); master->getOpenConnectionType (DEVICE_TYPE_SELECTOR, iter); rts2core::TimeArray *free_start = NULL; rts2core::TimeArray *free_end = NULL; std::vector <double>::iterator iter_fstart; std::vector <double>::iterator iter_fend; if (iter != master->getConnections ()->end ()) { rts2core::Value *f_start = (*iter)->getValue ("free_start"); rts2core::Value *f_end = (*iter)->getValue ("free_end"); if (f_start == NULL || f_end == NULL) { logStream (MESSAGE_WARNING) << "cannot find free_start or free_end variables in " << (*iter)->getName () << sendLog; } else if (f_start->getValueType () == (RTS2_VALUE_TIME | RTS2_VALUE_ARRAY) && f_end->getValueType () == (RTS2_VALUE_TIME | RTS2_VALUE_ARRAY)) { free_start = (rts2core::TimeArray*) f_start; free_end = (rts2core::TimeArray*) f_end; iter_fstart = free_start->valueBegin (); iter_fend = free_end->valueBegin (); } else { logStream (MESSAGE_WARNING) << "invalid free_start or free_end types: " << std::hex << f_start->getValueType () << " " << std::hex << f_end->getValueType () << sendLog; } } // get target observability rts2db::ConstraintsList violated; time_t f = from; double JD = ln_get_julian_from_timet (&f); time_t tto = to; double JD_end = ln_get_julian_from_timet (&tto); double dur = rts2script::getMaximalScriptDuration (tar, ((HttpD *) getMasterApp ())->cameras); if (dur < 60) dur = 60; dur /= 86400.0; double t; // go through nights double fstart_JD = NAN; double fend_JD = NAN; if (free_start && iter_fstart != free_start->valueEnd () && iter_fend != free_end->valueEnd ()) { f = *iter_fstart; fstart_JD = ln_get_julian_from_timet (&f); f = *iter_fend; fend_JD = ln_get_julian_from_timet (&f); if (JD < fstart_JD) JD = fstart_JD; } else { delete tar; return -1; } for (t = JD; t < JD_end; t += dur) { if (t > fend_JD) { iter_fstart++; iter_fend++; if (iter_fstart == free_start->valueEnd () || iter_fend == free_end->valueEnd ()) { t = JD_end; break; } else { time_t tt = *iter_fstart; fstart_JD = ln_get_julian_from_timet (&tt); tt = *iter_fend; fend_JD = ln_get_julian_from_timet (&tt); } } if (tar->isGood (t)) { double t2; // check full duration interval for (t2 = t; t2 < t + dur; t2 += 60 / 86400.0) { if (!(tar->isGood (t2))) { t = t2; continue; } } if (t2 >= t + dur) { ln_get_timet_from_julian (t, &ret_from); if (only_confirm) { confirmSchedule (tar, from, observatory_id, schedule_id); } break; } } } if (t >= JD_end) return -2; delete tar; return 0; }
void IncValue::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { std::string devName = params[0]; std::string valueName = params[1]; HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn = serv->getOpenConnection (devName.c_str ()); if (!conn) { throw XmlRpcException ("Cannot find connection '" + std::string (devName) + "'."); } rts2core::Value *val = conn->getValue (valueName.c_str ()); if (!val) { throw XmlRpcException ("Cannot find value '" + std::string (valueName) + "' on device '" + std::string (devName) + "'."); } int i_val; double d_val; std::string s_val; XmlRpcValue x_val = params[2]; switch (val->getValueBaseType ()) { case RTS2_VALUE_INTEGER: case RTS2_VALUE_LONGINT: if (x_val.getType () == XmlRpcValue::TypeInt) { i_val = (int) (x_val); } else { s_val = (std::string) (x_val); i_val = atoi (s_val.c_str ()); } conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '+', i_val)); break; case RTS2_VALUE_DOUBLE: if (x_val.getType () == XmlRpcValue::TypeDouble) { d_val = (double) (x_val); } else { s_val = (std::string) (x_val); d_val = atof (s_val.c_str ()); } conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '+', d_val)); break; case RTS2_VALUE_FLOAT: if (x_val.getType () == XmlRpcValue::TypeDouble) { d_val = (double) (x_val); } else { s_val = (std::string) (x_val); d_val = atof (s_val.c_str ()); } conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '+', (float) d_val)); break; case RTS2_VALUE_STRING: conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '+', (std::string) (params[2]))); break; default: conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '+', (std::string) (params[2]), true)); break; } }
void ListPrettyValuesDevice::sessionExecute (XmlRpcValue& params, XmlRpcValue& result) { HttpD *serv = (HttpD *) getMasterApp (); rts2core::Connection *conn; int i = 0; // print results for a single device.. if (params.size() == 1) { if (((std::string) params[0]).length () == 0) conn = serv->getSingleCentralConn (); else conn = serv->getOpenConnection (((std::string)params[0]).c_str()); if (!conn) { throw XmlRpcException ("Cannot get device " + (std::string) params[0]); } connectionValuesToXmlRpc (conn, result, true); } // print from all else { connections_t::iterator iter; rts2core::ValueVector::iterator variter; for (iter = serv->getCentraldConns ()->begin (); iter != serv->getCentraldConns ()->end (); iter++) { conn = *iter; std::string deviceName = (*iter)->getName (); // filter device list int v; for (v = 0; v < params.size (); v++) { if (((std::string) params[v]) == deviceName) break; } if (v == params.size ()) continue; for (variter = conn->valueBegin (); variter != conn->valueEnd (); variter++, i++) { result[i] = deviceName + "." + (*variter)->getName (); } } for (iter = serv->getConnections ()->begin (); iter != serv->getConnections ()->end (); iter++) { conn = *iter; std::string deviceName = (*iter)->getName (); // filter device list int v; for (v = 0; v < params.size (); v++) { if (((std::string) params[v]) == deviceName) break; } if (v == params.size ()) continue; for (variter = conn->valueBegin (); variter != conn->valueEnd (); variter++, i++) { result[i] = deviceName + "." + (*variter)->getName (); } } } }