Instrument Neutral Distributed Interface INDI
1.9.5
|
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 <cstdlib>
#include <cstring>
#include <memory>
#include <sys/stat.h>
{
DefaultDevice::initProperties();
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)
else
"No skeleton file was specified. Set environment variable INDISKEL to the skeleton path and try again.\n");
int i = 0;
IDLog(
"Property #%d: %s\n", i++, oneProperty->getName());
return true;
}
{
static int configLoaded = 0;
if (configLoaded == 0)
{
configLoaded = 1;
}
}
{
return false;
return false;
}
{
return false;
if (nvp == nullptr)
return false;
{
IDSetNumber(nvp,
"Cannot change property while device is disconnected.");
return false;
}
if (strcmp(nvp->
name,
"Number Property") != 0)
{
return true;
}
return false;
}
{
int lightState = 0;
int lightIndex = 0;
return false;
return true;
{
IDSetSwitch(svp,
"Cannot change property while device is disconnected.");
return false;
}
if (svp == nullptr || lvp == nullptr)
return false;
if (strcmp(svp->
name,
"Menu") == 0)
{
if (lightIndex < 0 || lightIndex > lvp->
nlp)
return false;
if (onSW != nullptr)
{
lightState = rand() % 4;
IDSetSwitch(svp,
"Setting to switch %s is successful. Changing corresponding light property to %s.",
}
return true;
}
return false;
}
char *formats[], char *names[], int n)
{
return false;
if (bvp == nullptr)
return false;
{
IDSetBLOB(bvp,
"Cannot change property while device is disconnected.");
return false;
}
if (strcmp(bvp->
name,
"BLOB Test") == 0)
{
IUUpdateBLOB(bvp, sizes, blobsizes, blobs, formats, names, n);
if (bp == nullptr)
return false;
IDLog(
"Received BLOB with name %s, format %s, and size %d, and bloblen %d\n", bp->name, bp->format, bp->size,
bp->bloblen);
char *blobBuffer = new char[bp->bloblen + 1];
strncpy(blobBuffer, ((char *)bp->blob), bp->bloblen);
blobBuffer[bp->bloblen] = '\0';
IDLog(
"BLOB Content:\n##################################\n%s\n##################################\n",
blobBuffer);
delete[] blobBuffer;
bp->size = 0;
}
return true;
}
{
return true;
}
{
return true;
}
{
return "Simple Skeleton";
}
Properties getProperties()
Return a list of all properties in the device.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
Light vector property descriptor.
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
BLOB (Binary Large Object) vector property descriptor.
INDI::PropertyView< IBLOB > * getBLOB(const char *name) const
INDI::PropertyView< INumber > * getNumber(const char *name) const
bool buildSkeleton(const char *filename)
Build driver properties from a skeleton file.
IBLOB * IUFindBLOB(const IBLOBVectorProperty *bvp, const char *name)
Find an IBLOB member in a vector BLOB property.
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
const char * getDeviceName() const
void void void void void void void void void IDSetBLOB(const IBLOBVectorProperty *b, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing BLOB vector property.
INDI::PropertyView< ISwitch > * getSwitch(const char *name) const
void void void void void IDLog(const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(1
Function Drivers call to log a message locally.
ISwitch * IUFindOnSwitch(const ISwitchVectorProperty *sp)
Returns the first ON switch it finds in the vector switch property.
Number vector property descriptor.
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * pstateStr(IPState s)
void void void void void void void IDSetLight(const ILightVectorProperty *l, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing light vector property.
void ISGetProperties(const char *dev) override
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.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
bool Disconnect() override
Disconnect from device.
const char * getDefaultName() override
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
std::unique_ptr< SimpleSkeleton > simpleSkeleton(new SimpleSkeleton())
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
Construct a basic INDI CCD device that demonstrates ability to define properties from a skeleton file...
int IUUpdateBLOB(IBLOBVectorProperty *bvp, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Update all BLOB members in a BLOB vector property.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *sp)
Returns the index of first ON switch it finds in the vector switch property.
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
void void void IDSetNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing number vector property.
void void void void void IDSetSwitch(const ISwitchVectorProperty *s, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing switch vector property.
One Blob (Binary Large Object) descriptor.
INDI::PropertyView< ILight > * getLight(const char *name) const
bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
Process the client newBLOB command.
Switch vector property descriptor.