Instrument Neutral Distributed Interface INDI  1.9.2
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:

indiserver tutorial_three

Then in another terminal, run the client:

tutorial_client

The client will connect to the CCD driver and attempts to change the CCD temperature.

#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
#include <cstring>
#include <fstream>
#include <iostream>
#include <memory>
#define MYCCD "Simple CCD"
static std::unique_ptr<MyClient> camera_client(new MyClient());
int main(int /*argc*/, char **/*argv*/)
{
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;
}
/**************************************************************************************
**
***************************************************************************************/
{
ccd_simulator = nullptr;
}
/**************************************************************************************
**
***************************************************************************************/
{
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);
}
/**************************************************************************************
**
***************************************************************************************/
{
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);
}
/**************************************************************************************
**
***************************************************************************************/
{
if (strcmp(dp->getDeviceName(), MYCCD) == 0)
IDLog("Receiving %s Device...\n", dp->getDeviceName());
ccd_simulator = dp;
}
/**************************************************************************************
**
*************************************************************************************/
{
if (strcmp(property->getDeviceName(), MYCCD) == 0 && strcmp(property->getName(), "CONNECTION") == 0)
{
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");
}
return;
}
}
/**************************************************************************************
**
***************************************************************************************/
{
// 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");
}
}
}
/**************************************************************************************
**
***************************************************************************************/
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());
}
/**************************************************************************************
**
***************************************************************************************/
{
// Save FITS file to disk
std::ofstream myfile;
myfile.open("ccd_simulator.fits", std::ios::out | std::ios::binary);
myfile.write(static_cast<char *>(bp->blob), bp->bloblen);
myfile.close();
IDLog("Received image, saved as ccd_simulator.fits\n");
}
MYCCD
#define MYCCD
Definition: tutorial_client.cpp:49
INDI::BaseClient::connectDevice
void connectDevice(const char *deviceName)
Connect to INDI driver.
Definition: baseclient.cpp:900
basedevice.h
MyClient::newNumber
void newNumber(INumberVectorProperty *nvp) override
Emmited when a new number value arrives from INDI server.
Definition: tutorial_client.cpp:152
Aux::ANY
@ ANY
Definition: celestronauxpacket.h:86
INDI::Property::getName
const char * getName() const
Definition: indiproperty.cpp:289
INDI::Property::getDeviceName
const char * getDeviceName() const
Definition: indiproperty.cpp:310
INDI::BaseDevice::getNumber
INDI::PropertyView< INumber > * getNumber(const char *name) const
Definition: basedevice.cpp:99
INDI::BaseDevice::messageQueue
const std::string & messageQueue(size_t index) const
Definition: basedevice.cpp:867
MyClient::newProperty
void newProperty(INDI::Property *property) override
Emmited when a new property is created for an INDI driver.
Definition: tutorial_client.cpp:130
INDI::BaseDevice::getDeviceName
const char * getDeviceName() const
Definition: basedevice.cpp:799
IDLog
void void void void void IDLog(const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(1
Function Drivers call to log a message locally.
INDI::Property
Provides generic container for INDI properties.
Definition: indiproperty.h:43
INDI::BaseClient::sendNewNumber
void sendNewNumber(INumberVectorProperty *pp)
Send new Number command to server.
Definition: baseclient.cpp:976
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
MyClient
Definition: tutorial_client.h:39
MyClient::newBLOB
void newBLOB(IBLOB *bp) override
Emmited when a new BLOB value arrives from INDI server.
Definition: tutorial_client.cpp:182
B_ALSO
@ B_ALSO
Definition: indidevapi.h:271
_INumberVectorProperty::np
INumber * np
Definition: indiapi.h:334
_INumberVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:322
MyClient::takeExposure
void takeExposure()
Definition: tutorial_client.cpp:98
INDI::BaseDevice::isConnected
bool isConnected() const
Definition: basedevice.cpp:518
MyClient::setTemperature
void setTemperature()
Definition: tutorial_client.cpp:79
tutorial_client.h
Construct a basic INDI client that demonstrates INDI::Client capabilities. This client must be used w...
main
int main(int, char **)
Definition: tutorial_client.cpp:53
MyClient::MyClient
MyClient()
Definition: tutorial_client.cpp:71
MyClient::newDevice
void newDevice(INDI::BaseDevice *dp) override
Emmited when a new device is created from INDI server.
Definition: tutorial_client.cpp:119
MyClient::newMessage
void newMessage(INDI::BaseDevice *dp, int messageID) override
Emmited when a new message arrives from INDI server.
Definition: tutorial_client.cpp:170
INDI::BaseDevice
Class to provide basic INDI device functionality.
Definition: basedevice.h:45
IBLOB
One Blob (Binary Large Object) descriptor.