#include "StdAfx.h" #include "PCOcomm.h" #include "PCOcameraDlg.h" #include "PCOcamera2.h" #import #include "tcs.h" #include #include "TCScomI.h" #include #include using namespace IceGrid; using namespace Ice; using namespace tcs; using namespace std; using namespace MSXML2; extern CPCOcameraApp theApp; // helper functions to split a string std::vector &split(const std::string &s, char delim, std::vector &elems) { std::stringstream ss(s); std::string item; while(std::getline(ss, item, delim)) { elems.push_back(item); } return elems; } std::vector split(const std::string &s, char delim) { std::vector elems; return split(s, delim, elems); } std::vector split(const std::string &s) { std::vector elems; char delim=' '; return split(s, delim, elems); } CPCOcomm::CPCOcomm(void) { // initialize ATL (for MSXML) HRESULT hr; hr = CoInitializeEx(NULL,COINIT_MULTITHREADED); } CPCOcomm::~CPCOcomm(void) { if(m_communicator) { if(m_HQproxy) // send unregister message to HQ { std::string str="PCOcam"; // inform subsystems that we are about to quit TCScomPrx onewayprx; onewayprx=TCScomPrx::uncheckedCast(m_HQproxy->ice_oneway()); try { onewayprx->Unregister(str); } catch(const IceUtil::Exception& ex) { std::string s = ex.ice_name(); CString cs(s.c_str()); #ifdef _DEBUG // MessageBox(NULL, cs, _T("shutdown"), MB_OK|MB_ICONEXCLAMATION); #endif } } // remove object from registry and destroy comminicator // first get admin proxy, since session may have expired // since version 3.2 we have to do it hard way, with authentication Ice::ObjectPrx base = m_communicator->stringToProxy("IceGrid/Registry"); IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(base); string username = "o"; string password = "o"; IceGrid::AdminSessionPrx session; m_admin=NULL; try { session = registry->createAdminSession(username, password); m_admin=session->getAdmin(); } catch (const IceGrid::PermissionDeniedException & ex) { std::ostringstream ostr; ostr << "permission denied:\n" << ex.reason; std::string s = ostr.str(); AfxMessageBox(CString(s.c_str()), MB_OK|MB_ICONEXCLAMATION); m_admin=NULL; // return -1; } if(m_admin) { try { m_admin->removeObject(m_communicator->stringToIdentity("PCOcamobject")); } catch(const IceUtil::Exception& ex) { std::string s = ex.ice_name(); CString cs(s.c_str()); // MessageBox(NULL, cs, _T("shutdown"), MB_OK|MB_ICONEXCLAMATION); } } try { m_communicator->destroy(); } catch(const IceUtil::Exception& ex) { std::string s = ex.ice_name(); CString cs(s.c_str()); // MessageBox(NULL, cs, _T("shutdown"), MB_OK|MB_ICONEXCLAMATION); } } // XMLPlatformUtils::Terminate(); CoUninitialize(); } int CPCOcomm::Initialize() { Ice::ObjectAdapterPtr adapter; Ice::PropertiesPtr properties; Ice::ObjectPtr object; // initialize Ice communicator, get IceGrid admin proxy m_admin=NULL; try { int argc = 0; properties = Ice::createProperties(); try { properties->load("d:\\tcs\\config.pco"); } catch (const Ice::SyscallException &) { MessageBox(NULL, _T("Can't open config file!"), _T("initialize"), MB_OK|MB_ICONEXCLAMATION); return -1; } Ice::InitializationData id; id.properties=properties; m_communicator = Ice::initialize(argc, 0, id); // get proxy to IceGrid registry administrator // first get admin proxy, since session may have expired // since version 3.2 we have to do it hard way, with authentication Ice::ObjectPrx base = m_communicator->stringToProxy("IceGrid/Registry"); IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(base); string username = "o"; string password = "o"; IceGrid::AdminSessionPrx session; m_admin=NULL; try { session = registry->createAdminSession(username, password); m_admin=session->getAdmin(); } catch (const IceGrid::PermissionDeniedException & ex) { std::ostringstream ostr; ostr << "permission denied:\n" << ex.reason; std::string s = ostr.str(); AfxMessageBox(CString(s.c_str()), MB_OK|MB_ICONEXCLAMATION); m_admin=NULL; return -1; } // m_admin=AdminPrx::checkedCast(m_communicator->stringToProxy("IceGrid/Admin")); // create PCO object adapter adapter = m_communicator->createObjectAdapter("PCOadapter"); } catch(const IceUtil::Exception& ex) { std::string s = ex.ice_name(); CString cs(s.c_str()); // AfxMessageBox(cs); MessageBox(NULL, cs, _T("initialize"), MB_OK|MB_ICONEXCLAMATION); return -1; } // create PCO object and add it to registry and adapter try { object = new TCScomI(this); PCOproxy=adapter->add(object, m_communicator->stringToIdentity("PCOcamobject")); adapter->activate(); m_admin->addObject(PCOproxy); } catch(const IceGrid::DeploymentException& ex) { std::string s = ex.ice_name(); std::ostringstream stream; ex.ice_print(stream); CString cs(s.c_str()); // AfxMessageBox(cs); MessageBox(NULL, cs, _T("initialize"), MB_OK|MB_ICONEXCLAMATION); return -1; } catch(const IceUtil::Exception& ex) { std::string s = ex.ice_name(); std::ostringstream stream; ex.ice_print(stream); CString cs(s.c_str()); // AfxMessageBox(cs); MessageBox(NULL, cs, _T("initialize"), MB_OK|MB_ICONEXCLAMATION); return -1; } // get HQ proxy m_HQproxy=0; try { Ice::ObjectPrx base = m_communicator->stringToProxy("HQobject"); m_HQproxy= tcs::TCScomPrx::checkedCast(base); } catch(const IceUtil::Exception&) { m_HQproxy=0; } // if we get a proxy, send connect message first if(m_HQproxy) { TCScomPrx onewayprx; onewayprx=TCScomPrx::uncheckedCast(m_HQproxy->ice_oneway()); try { onewayprx->Register("PCOcam"); } catch(const IceUtil::Exception& ex) { std::string s = ex.ice_name(); CString cs(s.c_str()); AfxMessageBox(cs, MB_OK|MB_ICONEXCLAMATION); } // CWSSDlg *pDlg=(CWSSDlg*)(theApp.m_pMainWnd); // pDlg->m_ctlConnectedIndicator.SetCheck(BST_CHECKED); } CString stmp=L""; // getWeatherData(stmp); m_nStatus=1; return 1; } CString CPCOcomm::makeUniqueID(void) { SYSTEMTIME systime; FILETIME filtime; GetSystemTime(&systime); SystemTimeToFileTime(&systime, &filtime); __int64 timmillis=((__int64)filtime.dwHighDateTime)<<32; timmillis+=filtime.dwLowDateTime; CString ID; ID.Format(_T("%I64d"), timmillis); return ID; } // parses and takes appropriate acction on XML command string received int CPCOcomm::CommandParser(std::string command) { return 1; } // parses and takes appropriate acctions on XML request string received, returns answer XML string int CPCOcomm::InfRequestParser(const std::string& request, std::string& answer) { MSXML2::IXMLDOMElementPtr root; // subsystem node MSXML2::IXMLDOMDocumentPtr pDoc; HRESULT hr; // CoInitialize(NULL); hr= pDoc.CreateInstance(__uuidof(DOMDocument40)); if (FAILED(hr)) { m_strErrorMessage="Failed to instantiate an MSXML DOM."; return -1; } pDoc->async = VARIANT_FALSE; // The default is true. _bstr_t breq=request.c_str(); if(pDoc->loadXML(breq) != VARIANT_TRUE) { m_strErrorMessage="Error loading XML request./nWrong format?"; pDoc.Release(); CoUninitialize(); return -1; } root=pDoc->documentElement; if(root == NULL) { m_strErrorMessage="Wrong XML format?"; pDoc.Release(); // CoUninitialize(); return -1; } // get subsystem's name (which sent this request) from "name" attribute _bstr_t name=L"name"; VARIANT vVal=root->getAttribute(name); CComBSTR bsubname=vVal.bstrVal; CString sname(bsubname); // get instrument name for the request MSXML2::IXMLDOMNodePtr instrNode=root->firstChild; MSXML2::IXMLDOMNamedNodeMapPtr attrs=instrNode->attributes; MSXML2::IXMLDOMNodePtr InstrNameNode=attrs->getNamedItem(name); vVal=InstrNameNode->nodeValue; CComBSTR binstrname=vVal.bstrVal; CString InstrName(binstrname); // get query name for the request MSXML2::IXMLDOMNodePtr queryNode=instrNode->firstChild; MSXML2::IXMLDOMNamedNodeMapPtr qattrs=queryNode->attributes; MSXML2::IXMLDOMNodePtr QueryNameNode=qattrs->getNamedItem(name); vVal=QueryNameNode->nodeValue; CComBSTR bqueryname=vVal.bstrVal; CString QueryName(bqueryname); // AfxMessageBox(QueryName); int querytype=1; // 1 - status, 2 - data if(QueryName.Compare(L"CurData") == 0) // request for current weather data { querytype=2; } else if(QueryName.Compare(L"Status") == 0) { querytype=1; } else // there is only one query plus status yet, so it must be an error { m_strErrorMessage=L"Wrong query for PCOcam."; pDoc.Release(); // CoUninitialize(); return -1; } // clean up //InstrNameNode->Release(); //QueryNameNode->Release(); //attrs->Release(); //qattrs->Release(); //queryNode->Release(); //instrNode->Release(); //root->Release(); //pDoc->Release(); // now create answer XML document MSXML2::IXMLDOMDocumentPtr pDoc2; hr= pDoc2.CreateInstance(__uuidof(DOMDocument40)); if (FAILED(hr)) { m_strErrorMessage=L"Failed to instantiate an MSXML DOM."; return -1; } pDoc2->async = VARIANT_FALSE; // The default is true. // Create a processing instruction targeted for xml. MSXML2::IXMLDOMProcessingInstructionPtr pi; pi = pDoc2->createProcessingInstruction("xml", "version='1.0'"); if (pi != NULL) { pDoc2->appendChild(pi); pi.Release(); } // create root MSXML2::IXMLDOMElementPtr newroot; newroot=pDoc2->createElement("subsystem"); // add name attribute MSXML2::IXMLDOMAttributePtr nameattr; nameattr=pDoc2->createAttribute("name"); nameattr->value=L"PCOcam"; newroot->setAttributeNode(nameattr); // add date attribute MSXML2::IXMLDOMAttributePtr dateattr; dateattr=pDoc2->createAttribute("date"); SYSTEMTIME systime; GetSystemTime(&systime); CString stime; stime.Format(_T("%d-%02d-%02d %02d:%02d:%02d.%03d"), systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds); CComBSTR btmp=stime; COleVariant vtime(stime); // vtime.bstrVal=btmp; dateattr->value=vtime; newroot->setAttributeNode(dateattr); // instrument node MSXML2::IXMLDOMElementPtr InstrNode; InstrNode=pDoc2->createElement("instrument"); // add name attribute MSXML2::IXMLDOMAttributePtr inameattr; inameattr=pDoc2->createAttribute("name"); inameattr->value=L"PCOcamera"; InstrNode->setAttributeNode(inameattr); // information node MSXML2::IXMLDOMElementPtr InfNode; InfNode=pDoc2->createElement("information"); // add name attribute MSXML2::IXMLDOMAttributePtr infnameattr; infnameattr=pDoc2->createAttribute("name"); if(querytype == 2) // data { infnameattr->value=L"CurData"; // now get weather data and set it as a text node CString wdata=L" "; // getWeatherData(wdata); btmp=wdata; } else // status { infnameattr->value=L"Status"; CString txt; if(m_nStatus == 1) // Ok txt=_T("Ok"); else // fail or acquiring { if(m_nStatus == 2) txt=_T("Ok acquiring"); else txt=_T("Fail"); } btmp=txt; } InfNode->setAttributeNode(infnameattr); InfNode->text=btmp.m_str; // now append created nodes (infnode->instrnode->newroot->pDoc2) InstrNode->appendChild(InfNode); newroot->appendChild(InstrNode); pDoc2->appendChild(newroot); // write XML document to a string CComBSTR bxmlstr=(pDoc2->xml).GetBSTR(); char buf[4096]; int ret=WideCharToMultiByte(CP_ACP, 0, bxmlstr, -1, buf, 4096, NULL, NULL); answer=buf; // std::string newanswer; // clean up //InstrNode.Release(); //InfNode.Release(); //inameattr.Release(); //dateattr.Release(); //newroot.Release(); pDoc2.Release(); // CoUninitialize(); return 1; } void CPCOcomm::OnRegister(const std::string& name) { // get HQ proxy m_HQproxy=0; try { Ice::ObjectPrx base = m_communicator->stringToProxy("HQobject"); m_HQproxy= tcs::TCScomPrx::checkedCast(base); } catch(const IceUtil::Exception&) { m_HQproxy=0; return; } CPCOcameraDlg *pDlg=(CPCOcameraDlg*)(theApp.m_pMainWnd); pDlg->m_ctlConnectedIndicator.SetCheck(BST_CHECKED); } // takes appropriate action on Unregister message void CPCOcomm::OnUnRegister(const std::string& name) { m_HQproxy=0; CPCOcameraDlg *pDlg=(CPCOcameraDlg*)(theApp.m_pMainWnd); pDlg->m_ctlConnectedIndicator.SetCheck(BST_UNCHECKED); } void CPCOcomm::NotificationMessageParser(string notification) { } bool CPCOcomm::IsConnected(void) { if(m_HQproxy) return true; else return false; } int CPCOcomm::GetCoordinates(double* X, double* Y, double *pa) { CString instrument(_T("Guider")); CString query(L"Position"), answer; if(sendQuery(instrument, query, answer) != 1) return 0; // parse answer string(xpos ypos rlong rlat) USES_CONVERSION; std::string instr=T2A(answer.GetString()); vector vstr=split(instr); double x=atof(vstr[0].c_str()); double y=atof(vstr[1].c_str()); // get P angle instrument=_T("SunEph"); query=_T("Eph"); if(sendQuery(instrument, query, answer) != 1) return 0; instr=T2A(answer.GetString()); vstr=split(instr); double Pangle=atof(vstr[1].c_str()); // x and y are in ra and dec coords, recalculate them to heliocentric // using P angle double Pa=Pangle*(3.1415926535/180.); double xcorr=x*cos(Pa)+y*sin(Pa); double ycorr=-x*sin(Pa)+y*cos(Pa); *X=xcorr; *Y=ycorr; *pa=Pa; return 1; } int CPCOcomm::sendQuery(CString& instrument, CString& queryname, CString& answer) { // make a request to GUI MSXML2::IXMLDOMDocumentPtr pDoc2; HRESULT hr= pDoc2.CreateInstance(__uuidof(DOMDocument40)); if (FAILED(hr)) { m_strErrorMessage=L"Failed to instantiate an MSXML DOM."; return -1; } pDoc2->async = VARIANT_FALSE; // The default is true. // Create a processing instruction targeted for xml. MSXML2::IXMLDOMProcessingInstructionPtr pi; pi = pDoc2->createProcessingInstruction("xml", "version='1.0'"); if (pi != NULL) { pDoc2->appendChild(pi); pi.Release(); } // create root MSXML2::IXMLDOMElementPtr newroot; newroot=pDoc2->createElement("subsystem"); // add name attribute MSXML2::IXMLDOMAttributePtr nameattr; nameattr=pDoc2->createAttribute("name"); nameattr->value=L"PCOcam"; newroot->setAttributeNode(nameattr); // add date attribute MSXML2::IXMLDOMAttributePtr dateattr; dateattr=pDoc2->createAttribute("date"); SYSTEMTIME systime; GetSystemTime(&systime); CString stime; stime.Format(_T("%d-%02d-%02d %02d:%02d:%02d.%03d"), systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds); CComBSTR btmp=stime; COleVariant vtime(stime); // vtime.bstrVal=btmp; dateattr->value=vtime; newroot->setAttributeNode(dateattr); // instrument node MSXML2::IXMLDOMElementPtr InstrNode; InstrNode=pDoc2->createElement("instrument"); // add name attribute MSXML2::IXMLDOMAttributePtr inameattr; inameattr=pDoc2->createAttribute("name"); inameattr->value=instrument.GetString(); InstrNode->setAttributeNode(inameattr); // query node MSXML2::IXMLDOMElementPtr InfNode; InfNode=pDoc2->createElement("query"); // add name attribute MSXML2::IXMLDOMAttributePtr infnameattr; infnameattr=pDoc2->createAttribute("name"); infnameattr->value=queryname.GetString();//L"Position"; InfNode->setAttributeNode(infnameattr); // InfNode->text=btmp.m_str; // now append created nodes (infnode->instrnode->newroot->pDoc2) InstrNode->appendChild(InfNode); newroot->appendChild(InstrNode); pDoc2->appendChild(newroot); // write XML document to a string CComBSTR bxmlstr=(pDoc2->xml).GetBSTR(); char buf[4096]; int ret=WideCharToMultiByte(CP_ACP, 0, bxmlstr, -1, buf, 4096, NULL, NULL); std::string query=buf; // send query to TCS // pDoc2->Release(); std::string information; try { m_HQproxy->RequestInformation(query, information); } catch(tcs::Error errex) { m_strErrorMessage=errex.reason.c_str(); if(errex.reason.find("not registered") == string::npos) return 0; else return -1; } catch(Ice::Exception ex) { m_strErrorMessage=ex.what(); return -2; } // parse answer MSXML2::IXMLDOMElementPtr root; // subsystem node MSXML2::IXMLDOMDocumentPtr pDoc; // CoInitialize(NULL); hr= pDoc.CreateInstance(__uuidof(DOMDocument40)); if (FAILED(hr)) { m_strErrorMessage="Failed to instantiate an MSXML DOM."; return -1; } pDoc->async = VARIANT_FALSE; // The default is true. _bstr_t breq=information.c_str(); if(pDoc->loadXML(breq) != VARIANT_TRUE) { m_strErrorMessage="Error loading XML request./nWrong format?"; // pDoc.Release(); // CoUninitialize(); return -1; } root=pDoc->documentElement; if(root == NULL) { m_strErrorMessage="Wrong XML format?"; // pDoc.Release(); // CoUninitialize(); return -1; } // get subsystem's name (which sent this request) from "name" attribute _bstr_t name=L"name"; VARIANT vVal=root->getAttribute(name); CComBSTR bsubname=vVal.bstrVal; CString sname(bsubname); // get instrument name for the request MSXML2::IXMLDOMNodePtr instrNode=root->firstChild; MSXML2::IXMLDOMNamedNodeMapPtr attrs=instrNode->attributes; MSXML2::IXMLDOMNodePtr InstrNameNode=attrs->getNamedItem(name); vVal=InstrNameNode->nodeValue; CComBSTR binstrname=vVal.bstrVal; CString InstrName(binstrname); //get information node MSXML2::IXMLDOMNodePtr infNode=instrNode->firstChild; // get text CComBSTR infbstr(infNode->Gettext().GetBSTR()); CString cstext(infbstr); answer=cstext; // clean up //InstrNode.Release(); //InfNode.Release(); //inameattr.Release(); //dateattr.Release(); //newroot.Release(); // pDoc.Release(); // CoUninitialize(); return 1; } int CPCOcomm::GetTargetInfo(CString& TargetInfo) { CString instrument(_T("MainGUI")); CString query(L"ObjectInfo"); if(sendQuery(instrument, query, TargetInfo) != 1) return 0; return 1; } int CPCOcomm::sendCommand(CString& command, CString& instrument, CString& parameter, unsigned long long* id) { MSXML2::IXMLDOMDocumentPtr pDoc2; HRESULT hr= pDoc2.CreateInstance(__uuidof(DOMDocument40)); if (FAILED(hr)) { m_strErrorMessage=L"Failed to instantiate an MSXML DOM."; return -1; } pDoc2->async = VARIANT_FALSE; // The default is true. // Create a processing instruction targeted for xml. MSXML2::IXMLDOMProcessingInstructionPtr pi; pi = pDoc2->createProcessingInstruction("xml", "version='1.0'"); if (pi != NULL) { pDoc2->appendChild(pi); pi.Release(); } // create root MSXML2::IXMLDOMElementPtr newroot; newroot=pDoc2->createElement("subsystem"); // add name attribute MSXML2::IXMLDOMAttributePtr nameattr; nameattr=pDoc2->createAttribute("name"); nameattr->value=L"PCOcam"; newroot->setAttributeNode(nameattr); // add date attribute MSXML2::IXMLDOMAttributePtr dateattr; dateattr=pDoc2->createAttribute("date"); SYSTEMTIME systime; GetSystemTime(&systime); CString stime; stime.Format(_T("%d-%02d-%02d %02d:%02d:%02d.%03d"), systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds); CComBSTR btmp=stime; COleVariant vtime(stime); // vtime.bstrVal=btmp; dateattr->value=vtime; newroot->setAttributeNode(dateattr); // add id attribute unsigned long long lid=createUniqueID(); CString sid; sid.Format(L"%lld", lid); MSXML2::IXMLDOMAttributePtr IDattr; IDattr=pDoc2->createAttribute("ID"); IDattr->value=sid.GetString(); newroot->setAttributeNode(IDattr); // instrument node MSXML2::IXMLDOMElementPtr InstrNode; InstrNode=pDoc2->createElement("instrument"); // add name attribute MSXML2::IXMLDOMAttributePtr inameattr; inameattr=pDoc2->createAttribute("name"); inameattr->value=instrument.GetString(); InstrNode->setAttributeNode(inameattr); // command node MSXML2::IXMLDOMElementPtr ComNode; ComNode=pDoc2->createElement("command"); // add name attribute MSXML2::IXMLDOMAttributePtr comnameattr; comnameattr=pDoc2->createAttribute("name"); comnameattr->value=command.GetString();//L"Position"; ComNode->setAttributeNode(comnameattr); // create parameter node if parameter is not empty if(parameter.IsEmpty() == false) { MSXML2::IXMLDOMElementPtr ParamNode; ParamNode=pDoc2->createElement("parameter"); // CComBSTR btmp=stime; // COleVariant txtval(parameter); // ParamNode->put_nodeValue(txtval); CComBSTR bstrparam=parameter; ParamNode->put_text(bstrparam); ComNode->appendChild(ParamNode); } // add child nodes InstrNode->appendChild(ComNode); newroot->appendChild(InstrNode); pDoc2->appendChild(newroot); *id=lid; // write XML document to a string CComBSTR bxmlstr=(pDoc2->xml).GetBSTR(); char buf[4096]; int ret=WideCharToMultiByte(CP_ACP, 0, bxmlstr, -1, buf, 4096, NULL, NULL); std::string query=buf; try { m_HQproxy->SendCommand(query); // AfxMessageBox(bxmlstr); } catch(tcs::Error errex) { m_strErrorMessage=errex.reason.c_str(); if(errex.reason.find("not registered") == string::npos) return 0; else return -1; } catch(Ice::Exception ex) { m_strErrorMessage=ex.what(); return -2; } return 0; } unsigned long long CPCOcomm::createUniqueID(void) { // SYSTEMTIME syst; FILETIME ft; GetSystemTimeAsFileTime(&ft); ULARGE_INTEGER uli; uli.LowPart=ft.dwLowDateTime; uli.HighPart=ft.dwHighDateTime; unsigned long long ret=uli.QuadPart; return ret; } int CPCOcomm::MoveGuider(double xcoor, double ycoor) { CString instrument=_T("Guider"); CString command(L"COffset"); CString parameter; parameter.Format(L"%.1f %.1f", xcoor, ycoor); unsigned long long lid; sendCommand(command, instrument, parameter, &lid); return 0; } // move guider relative to the FoV center in pixels int CPCOcomm::MoveGuiderIncr(int xcoor, int ycoor) { CString command(L"COffset"); CString parameter; // get current position CString instrument(_T("Guider")); CString query(L"Position"), answer; if(sendQuery(instrument, query, answer) != 1) return 0; // parse answer string(xpos ypos rlong rlat) USES_CONVERSION; std::string instr=T2A(answer.GetString()); vector vstr=split(instr); double x=atof(vstr[0].c_str()); double y=atof(vstr[1].c_str()); // convert pixels to arcsecs CPCOcameraDlg *pDlg=(CPCOcameraDlg*)(theApp.m_pMainWnd); // double xratio=pDlg->m_nCurdx/pDlg->m_dFOVSize; // double yratio=pDlg->m_nCurdy/pDlg->m_dFOVSize; // if there is ROI used, then FoV value in arcsec corresponds to whole 2048 pix double xratio=2048./pDlg->m_dFOVSize; double yratio=2048./pDlg->m_dFOVSize; double aX=xcoor/xratio; double aY=ycoor/yratio; parameter.Format(L"%.1f %.1f", x+aX, y+aY); unsigned long long lid; sendCommand(command, instrument, parameter, &lid); return 1; } int CPCOcomm::GetCoordinatesNoTrans(double* X, double* Y) { CString instrument(_T("Guider")); CString query(L"Position"), answer; if(sendQuery(instrument, query, answer) != 1) return 0; // parse answer string(xpos ypos rlong rlat) USES_CONVERSION; std::string instr=T2A(answer.GetString()); vector vstr=split(instr); double x=atof(vstr[0].c_str()); double y=atof(vstr[1].c_str()); *X=x; *Y=y; return 1; } // enable or disable the guider int CPCOcomm::EnableGuider(bool enable) { CString instrument=_T("Guider"); CString command; if(enable == true) command=L"Start"; else command=L"Stop"; CString parameter=L""; unsigned long long lid; sendCommand(command, instrument, parameter, &lid); return 0; } // move the telescope like with the "handpaddle" int CPCOcomm::MoveTelescopeWithHandBox(char direction, bool start) { CString instrument=_T("Guider"); CString command=L"ManMove"; CString parameter; switch(direction) { case 'N': parameter=L"N"; break; case 'S': parameter=L"S"; break; case 'E': parameter=L"E"; break; case 'W': parameter=L"W"; break; default: return -1; } if(start) parameter=parameter+L"GO"; else // stop motion parameter=parameter+L"ST"; unsigned long long lid; sendCommand(command, instrument, parameter, &lid); return 1; } // set guide rate in arcsec per sec int CPCOcomm::SetGuideRate(int rate) { if(rate <= 0 || rate > 100) return -1; CString instrument=_T("Mount"); CString command=L"Guide"; CString parameter; double drate=rate/3600.; // convert to deg/sec parameter.Format(_T("%g"), drate); unsigned long long lid; sendCommand(command, instrument, parameter, &lid); return 1; }