Instrument Neutral Distributed Interface INDI  2.0.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 <basedevice.h>
#include <cstring>
#include <fstream>
#include <iostream>
#include <memory>
int main(int, char *[])
{
MyClient myClient;
myClient.setServer("localhost", 7624);
myClient.connectServer();
myClient.setBLOBMode(B_ALSO, "Simple CCD", nullptr);
myClient.enableDirectBlobAccess("Simple CCD", nullptr);
std::cout << "Press Enter key to terminate the client.\n";
std::cin.ignore();
}
/**************************************************************************************
**
***************************************************************************************/
{
// wait for the availability of the device
watchDevice("Simple CCD", [this](INDI::BaseDevice device)
{
mSimpleCCD = device; // save device
// wait for the availability of the "CONNECTION" property
device.watchProperty("CONNECTION", [this](INDI::Property)
{
IDLog("Connecting to INDI Driver...\n");
connectDevice("Simple CCD");
// wait for the availability of the "CCD_TEMPERATURE" property
device.watchProperty("CCD_TEMPERATURE", [this](INDI::PropertyNumber property)
{
if (mSimpleCCD.isConnected())
{
IDLog("CCD is connected.\n");
}
// call lambda function if property changed
property.onUpdate([property, this]()
{
IDLog("Receving new CCD Temperature: %g C\n", property[0].getValue());
if (property[0].getValue() == -20)
{
IDLog("CCD temperature reached desired value!\n");
}
});
// call if updated of the "CCD1" property - simplified way
device.watchProperty("CCD1", [](INDI::PropertyBlob property)
{
// Save FITS file to disk
std::ofstream myfile;
myfile.open("ccd_simulator.fits", std::ios::out | std::ios::binary);
myfile.write(static_cast<char *>(property[0].getBlob()), property[0].getBlobLen());
myfile.close();
IDLog("Received image, saved as ccd_simulator.fits\n");
});
}
/**************************************************************************************
**
***************************************************************************************/
void MyClient::setTemperature(double value)
{
INDI::PropertyNumber ccdTemperature = mSimpleCCD.getProperty("CCD_TEMPERATURE");
if (!ccdTemperature.isValid())
{
IDLog("Error: unable to find Simple CCD, CCD_TEMPERATURE property...\n");
return;
}
IDLog("Setting temperature to %g C.\n", value);
ccdTemperature[0].setValue(value);
sendNewProperty(ccdTemperature);
}
/**************************************************************************************
**
***************************************************************************************/
void MyClient::takeExposure(double seconds)
{
INDI::PropertyNumber ccdExposure = mSimpleCCD.getProperty("CCD_EXPOSURE");
if (!ccdExposure.isValid())
{
IDLog("Error: unable to find CCD Simulator CCD_EXPOSURE property...\n");
return;
}
// Take a 1 second exposure
IDLog("Taking a %g second exposure.\n", seconds);
ccdExposure[0].setValue(seconds);
sendNewProperty(ccdExposure);
}
/**************************************************************************************
**
***************************************************************************************/
void MyClient::newMessage(INDI::BaseDevice baseDevice, int messageID)
{
if (!baseDevice.isDeviceNameMatch("Simple CCD"))
return;
IDLog("Recveing message from Server:\n"
" %s\n\n",
baseDevice.messageQueue(messageID).c_str());
}
hid_device * device
void setServer(const char *hostname, unsigned int port)
Set the server host name and port.
void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop=nullptr)
Set Binary Large Object policy mode.
void sendNewProperty(INDI::Property pp)
Send new Property command to server.
void connectDevice(const char *deviceName)
Disconnect INDI driver.
void watchDevice(const char *deviceName)
Add a device to the watch list.
void enableDirectBlobAccess(const char *dev=nullptr, const char *prop=nullptr)
activate zero-copy delivering of the blob content. When enabled, all blob copy will be avoided when p...
Definition: baseclient.cpp:360
bool connectServer() override
Connect to INDI server.
Definition: baseclient.cpp:308
Class to provide basic INDI device functionality.
Definition: basedevice.h:52
bool isConnected() const
Definition: basedevice.cpp:520
const std::string & messageQueue(size_t index) const
Definition: basedevice.cpp:888
Property getProperty(const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
Return a property and its type given its name.
Definition: basedevice.cpp:138
bool isDeviceNameMatch(const char *otherName) const
Check that the device name matches the argument.
Definition: basedevice.cpp:827
Provides generic container for INDI properties.
Definition: indiproperty.h:48
bool isValid() const
void setTemperature(double value)
void newMessage(INDI::BaseDevice baseDevice, int messageID) override
Emmited when a new message arrives from INDI server.
void takeExposure(double seconds)
void IDLog(const char *fmt,...)
Definition: indicom.c:316
@ B_ALSO
Definition: indidevapi.h:268
int main(int, char *[])
Construct a basic INDI client that demonstrates INDI::Client capabilities. This client must be used w...