Skip to content

Instantly share code, notes, and snippets.

@bengal123
Created March 26, 2021 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bengal123/4bbe4dcb0f5bd6ba474f7a4590f72655 to your computer and use it in GitHub Desktop.
Save bengal123/4bbe4dcb0f5bd6ba474f7a4590f72655 to your computer and use it in GitHub Desktop.
Reproduces "Invalid parameter -> Can not change rate while motor is running (direction differs)" EQMOD error
#if 0
Simple Client Tutorial
Demonstration of libindi v0.7 capabilities.
Copyright (C) 2010 Jasem Mutlaq (mutlaqja@ikarustech.com)
This library is free software;
you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY;
without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library;
if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA
#endif
/** \file tutorial_client.cpp
\brief Construct a basic INDI client that demonstrates INDI::Client capabilities. This client must be used with tutorial_three device "Simple CCD".
\author Jasem Mutlaq
\example tutorial_client.cpp
Construct a basic INDI client that demonstrates INDI::Client capabilities. This client must be used with tutorial_three device "Simple CCD".
To run the example, you must first run tutorial_three:
\code indiserver tutorial_three \endcode
Then in another terminal, run the client:
\code tutorial_client \endcode
The client will connect to the CCD driver and attempts to change the CCD temperature.
*/
#include "indibase/basedevice.h"
#include <cstring>
#include <fstream>
#include <iostream>
#include <memory>
#include "baseclient.h"
#define MYEQMOD "EQMod Mount"
class MyClient : public INDI::BaseClient
{
public:
MyClient();
~MyClient() = default;
void timedGuideNorth(float milliseconds);
void timedGuideSouth(float milliseconds);
protected:
void newDevice(INDI::BaseDevice *dp) override;
void removeDevice(INDI::BaseDevice */*dp*/) override {}
void newProperty(INDI::Property *property) override;
void removeProperty(INDI::Property */*property*/) override {}
void newBLOB(IBLOB *bp) override {};
void newSwitch(ISwitchVectorProperty */*svp*/) override {}
void newNumber(INumberVectorProperty *nvp) override {};
void newMessage(INDI::BaseDevice *dp, int messageID) override;
void newText(ITextVectorProperty */*tvp*/) override {}
void newLight(ILightVectorProperty */*lvp*/) override {}
void serverConnected() override {}
void serverDisconnected(int /*exit_code*/) override {}
private:
INDI::BaseDevice *mount;
};
static std::unique_ptr<MyClient> eqmod_client(new MyClient());
int main(int /*argc*/, char **/*argv*/)
{
eqmod_client->setServer("localhost", 7624);
eqmod_client->watchDevice(MYEQMOD);
eqmod_client->connectServer();
std::cout << "Press any key to start the guiding test.\n";
std::string term;
std::cin >> term;
// Go north
eqmod_client->timedGuideNorth(13);
// Wait for 10ms
const struct timespec timeout = {0, 100000000L};
nanosleep(&timeout, nullptr);
// Go south
eqmod_client->timedGuideSouth(13);
std::cout << "Press any key to terminate the client.\n";
std::cin >> term;
}
/**************************************************************************************
**
***************************************************************************************/
MyClient::MyClient()
{
mount = nullptr;
}
void MyClient::timedGuideNorth(float milliseconds)
{
INumberVectorProperty *timed_guide_number = nullptr;
std::cout << "A\n";
timed_guide_number = mount->getNumber("TELESCOPE_TIMED_GUIDE_NS");
if (timed_guide_number == nullptr)
{
IDLog("Error: unable to find TELESCOPE_TIMED_GUIDE_NS property...\n");
return;
}
timed_guide_number->np[0].value = milliseconds;
sendNewNumber(timed_guide_number);
}
void MyClient::timedGuideSouth(float milliseconds)
{
INumberVectorProperty *timed_guide_number = nullptr;
std::cout << "A";
timed_guide_number = mount->getNumber("TELESCOPE_TIMED_GUIDE_NS");
if (timed_guide_number == nullptr)
{
IDLog("Error: unable to find CCD Simulator TELESCOPE_TIMED_GUIDE_NS property...\n");
return;
}
timed_guide_number->np[0].value = 0;
timed_guide_number->np[1].value = milliseconds;
sendNewNumber(timed_guide_number);
}
/**************************************************************************************
**
***************************************************************************************/
void MyClient::newDevice(INDI::BaseDevice *dp)
{
IDLog("\nReceiving %s Device...\n", dp->getDeviceName());
mount = dp;
}
/**************************************************************************************
**
*************************************************************************************/
void MyClient::newProperty(INDI::Property *property)
{
IDLog("New Property: %s\n", property->getName());
if (strcmp(property->getDeviceName(), MYEQMOD) == 0 && strcmp(property->getName(), "CONNECTION") == 0)
{
connectDevice(MYEQMOD);
return;
}
}
/**************************************************************************************
**
***************************************************************************************/
void MyClient::newMessage(INDI::BaseDevice *dp, int messageID)
{
if (strcmp(dp->getDeviceName(), MYEQMOD) != 0)
return;
IDLog("%s\n", dp->messageQueue(messageID).c_str());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment