Header File #include "libindi/baseclient.h" #include "libindi/basedevice.h" #include #include #include #include class MyClient : public INDI::BaseClient { public: MyClient(); ~MyClient() = default; void setTemperature(); void takeExposure(); protected: virtual void newDevice(INDI::BaseDevice *dp); virtual void removeDevice(INDI::BaseDevice *dp) {} virtual void newProperty(INDI::Property *property); virtual void removeProperty(INDI::Property *property) {} virtual void newBLOB(IBLOB *bp); virtual void newSwitch(ISwitchVectorProperty *svp) {} virtual void newNumber(INumberVectorProperty *nvp); virtual void newMessage(INDI::BaseDevice *dp, int messageID); virtual void newText(ITextVectorProperty *tvp) {} virtual void newLight(ILightVectorProperty *lvp) {} virtual void serverConnected() {} virtual void serverDisconnected(int exit_code) {} private: INDI::BaseDevice *ccd_simulator; }; void test(); Source File #include "functions.hpp" #define MYCCD "CCD Simulator" /* Our client auto pointer */ std::unique_ptr camera_client(new MyClient()); void test() { camera_client->setServer("localhost", 7624); camera_client->watchDevice(MYCCD); camera_client->connectServer(); camera_client->setBLOBMode(B_ALSO, MYCCD, nullptr); std::cout << "Press any key to terminate the client.\n"; std::string term; std::cin >> term; } /******************************************************************************* *******************************************************************************/ MyClient::MyClient() { ccd_simulator = nullptr; } /******************************************************************************* *******************************************************************************/ void MyClient::setTemperature() { INumberVectorProperty *ccd_temperature = nullptr; ccd_temperature = ccd_simulator->getNumber("CCD_TEMPERATURE"); if (ccd_temperature == nullptr) { // IDLog("Error: unable to find CCD Simulator CCD_TEMPERATURE property." // "..\n"); return; } ccd_temperature->np[0].value = -20; sendNewNumber(ccd_temperature); } /******************************************************************************* *******************************************************************************/ void MyClient::takeExposure() { INumberVectorProperty *ccd_exposure = nullptr; ccd_exposure = ccd_simulator->getNumber("CCD_EXPOSURE"); if (ccd_exposure == nullptr) { // IDLog("Error: unable to find CCD Simulator CCD_EXPOSURE property.." // ".\n"); return; } // Take a 1 second exposure // IDLog("Taking a 1 second exposure.\n"); ccd_exposure->np[0].value = 1; sendNewNumber(ccd_exposure); } /******************************************************************************* *******************************************************************************/ void MyClient::newDevice(INDI::BaseDevice *dp) { if (strcmp(dp->getDeviceName(), MYCCD) == 0) // IDLog("Receiving %s Device...\n", dp->getDeviceName()); ccd_simulator = dp; } /******************************************************************************* *******************************************************************************/ void MyClient::newProperty(INDI::Property *property) { if (strcmp(property->getDeviceName(), MYCCD) == 0 && strcmp(property->getName(), "CONNECTION") == 0) { connectDevice(MYCCD); return; } if (strcmp(property->getDeviceName(), MYCCD) == 0 && strcmp(property->getName(), "CCD_TEMPERATURE") == 0) { if (ccd_simulator->isConnected()) { //IDLog("CCD is connected. Setting temperature to -20 C.\n"); setTemperature(); } return; } } /******************************************************************************* *******************************************************************************/ void MyClient::newNumber(INumberVectorProperty *nvp) { // Let's check if we get any new values for CCD_TEMPERATURE if (strcmp(nvp->name, "CCD_TEMPERATURE") == 0) { // IDLog("Receving new CCD Temperature: %g C\n", nvp->np[0].value); if (nvp->np[0].value == -20) { // IDLog("CCD temperature reached desired value!\n"); takeExposure(); } } } /******************************************************************************* *******************************************************************************/ void MyClient::newMessage(INDI::BaseDevice *dp, int messageID) { if (strcmp(dp->getDeviceName(), MYCCD) != 0) return; //IDLog("Recveing message from " // "Server:\n\n########################\n%s\n" // "########################\n\n", //dp->messageQueue(messageID).c_str()); } /******************************************************************************* *******************************************************************************/ void MyClient::newBLOB(IBLOB *bp) { // Save FITS file to disk std::ofstream myfile; myfile.open("ccd_simulator.fits", std::ios::out | std::ios::binary); myfile.write(static_cast(bp->blob), bp->bloblen); myfile.close(); //IDLog("Received image, saved as ccd_simulator.fits\n"); }