Instrument Neutral Distributed Interface INDI  2.0.2
simpleskeleton.cpp

A skeleton file is an external XML file with the driver properties already defined. This tutorial illustrates how to create a driver from a skeleton file and parse/process the properties. The skeleton file name is tutorial_four_sk.xml

Note
Please note that if you create your own skeleton file, you must append _sk postfix to your skeleton file name.
#if 0
Simple Skeleton - Tutorial Four
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 "simpleskeleton.h"
#include <cstdlib>
#include <cstring>
#include <memory>
#include <sys/stat.h>
/* Our simpleSkeleton auto pointer */
std::unique_ptr<SimpleSkeleton> simpleSkeleton(new SimpleSkeleton());
//const int POLLMS = 1000; // Period of update, 1 second.
/**************************************************************************************
** Initialize all properties & set default values.
**************************************************************************************/
{
DefaultDevice::initProperties();
// This is the default driver skeleton file location
// Convention is: drivername_sk_xml
// Default location is /usr/share/indi
const char *skelFileName = "/usr/share/indi/tutorial_four_sk.xml";
struct stat st;
char *skel = getenv("INDISKEL");
if (skel != nullptr)
else if (stat(skelFileName, &st) == 0)
buildSkeleton(skelFileName);
else
"No skeleton file was specified. Set environment variable INDISKEL to the skeleton path and try again.\n");
// Optional: Add aux controls for configuration, debug & simulation that get added in the Options tab
// of the driver.
// Let's print a list of all device properties
int i = 0;
for(const auto &oneProperty : getProperties())
IDLog("Property #%d: %s\n", i++, oneProperty.getName());
// Set the green light (IPS_OK) for a "Number Property" if changed
INDI::PropertyNumber number = getNumber("Number Property");
number.onUpdate([number, this]() mutable
{
if (!isConnected())
{
number.apply("Cannot change property while device is disconnected.");
return;
}
number.setState(IPS_OK);
number.apply();
});
// Set random light state for selected switch index
menu.onUpdate([menu, this]() mutable
{
if (!isConnected())
{
menu.apply("Cannot change property while device is disconnected.");
return;
}
auto index = menu.findOnSwitchIndex();
if (index < 0)
return;
INDI::PropertyLight light = getLight("Light Property");
light[index].setState(static_cast<IPState>(rand() % 4));
light.setState(IPS_OK);
light.apply();
});
// Show blob if changed
INDI::PropertyBlob blob = getBLOB("BLOB Test");
blob.onUpdate([blob, this]() mutable
{
if (!isConnected())
{
blob.apply("Cannot change property while device is disconnected.");
return;
}
IDLog("Received BLOB with name %s, format %s, and size %d, and bloblen %d\n",
blob[0].getName(), blob[0].getFormat(), blob[0].getSize(), blob[0].getBlobLen());
IDLog("BLOB Content:\n"
"##################################\n"
"%s\n"
"##################################\n",
blob[0].getBlobAsString().c_str());
blob[0].setSize(0);
blob.apply();
});
return true;
}
/**************************************************************************************
** Define Basic properties to clients.
***************************************************************************************/
void SimpleSkeleton::ISGetProperties(const char *dev)
{
static int configLoaded = 0;
// Ask the default driver first to send properties.
// If no configuration is load before, then load it now.
if (configLoaded == 0)
{
configLoaded = 1;
}
}
/**************************************************************************************
**
***************************************************************************************/
{
return true;
}
{
return true;
}
{
return "Simple Skeleton";
}
bool isConnected() const
Definition: basedevice.cpp:520
INDI::PropertyNumber getNumber(const char *name) const
Definition: basedevice.cpp:89
bool buildSkeleton(const char *filename)
Build driver properties from a skeleton file.
Definition: basedevice.cpp:302
INDI::PropertySwitch getSwitch(const char *name) const
Definition: basedevice.cpp:99
INDI::PropertyBlob getBLOB(const char *name) const
Definition: basedevice.cpp:109
INDI::PropertyLight getLight(const char *name) const
Definition: basedevice.cpp:104
Properties getProperties()
Return a list of all properties in the device.
Definition: basedevice.cpp:158
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void onUpdate(const std::function< void()> &callback)
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
const char * getDefaultName() override
bool Disconnect() override
Disconnect from device.
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
IPState
Property state.
Definition: indiapi.h:160
@ IPS_ALERT
Definition: indiapi.h:164
@ IPS_OK
Definition: indiapi.h:162
void IDLog(const char *fmt,...)
Definition: indicom.c:316
std::unique_ptr< SimpleSkeleton > simpleSkeleton(new SimpleSkeleton())
Construct a basic INDI CCD device that demonstrates ability to define properties from a skeleton file...