Instrument Neutral Distributed Interface INDI 2.2.5
Macros | Functions
indidevapi.c File Reference
#include "indidevapi.h"
#include "indicom.h"
#include "locale_compat.h"
#include "base64.h"
#include "userio.h"
#include "indiuserio.h"
#include "indiutility.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/stat.h>

Go to the source code of this file.

Macros

#define MAXRBUF   2048
 

Functions

void IUSaveConfigNumber (FILE *fp, const INumberVectorProperty *nvp)
 Add a number vector property value to the configuration file.
 
void IUSaveConfigText (FILE *fp, const ITextVectorProperty *tvp)
 Add a text vector property value to the configuration file.
 
void IUSaveConfigSwitch (FILE *fp, const ISwitchVectorProperty *svp)
 Add a switch vector property value to the configuration file.
 
void IUSaveConfigBLOB (FILE *fp, const IBLOBVectorProperty *bvp)
 Add a BLOB vector property value to the configuration file.
 
void IUSaveText (IText *tp, const char *newtext)
 Function to reliably save new text in a IText.
 
int IUSaveBLOB (IBLOB *bp, int size, int blobsize, char *blob, char *format)
 Function to save blob metadata in the corresponding blob.
 
XMLEle * configRootFP (const char *device)
 
int IULoadConfigNumber (const INumberVectorProperty *nvp)
 Load a number vector property value from the configuration file.
 
int IULoadConfigText (const ITextVectorProperty *tvp)
 Load a text vector property value from the configuration file.
 
int IULoadConfigSwitch (const ISwitchVectorProperty *svp)
 Add a switch vector property value to the configuration file.
 
IText * IUFindText (const ITextVectorProperty *tvp, const char *name)
 Find an IText member in a vector text property.
 
INumber * IUFindNumber (const INumberVectorProperty *nvp, const char *name)
 Find an INumber member in a number text property.
 
ISwitch * IUFindSwitch (const ISwitchVectorProperty *svp, const char *name)
 Find an ISwitch member in a vector switch property.
 
ILight * IUFindLight (const ILightVectorProperty *lvp, const char *name)
 Find an ILight member in a vector Light property.
 
IBLOB * IUFindBLOB (const IBLOBVectorProperty *bvp, const char *name)
 Find an IBLOB member in a vector BLOB property.
 
ISwitch * IUFindOnSwitch (const ISwitchVectorProperty *svp)
 Returns the first ON switch it finds in the vector switch property.
 
int IUFindIndex (const char *needle, char **hay, unsigned int n)
 Returns the index of the string in a string array.
 
int IUFindOnSwitchIndex (const ISwitchVectorProperty *svp)
 Returns the index of first ON switch it finds in the vector switch property.
 
int IUFindOnStateIndex (ISState *states, int n)
 Returns the index of first ON switch it finds in the ISState array.
 
const char * IUFindOnSwitchName (ISState *states, char *names[], int n)
 Returns the name of the first ON switch it finds in the supplied arguments.
 
void IUResetSwitch (ISwitchVectorProperty *svp)
 Reset all switches in a switch vector property to OFF.
 
void IUFillSwitch (ISwitch *sp, const char *name, const char *label, ISState s)
 Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
 
void IUFillLight (ILight *lp, const char *name, const char *label, IPState s)
 Assign attributes for a light property. The light's auxiliary elements will be set to NULL.
 
void IUFillNumber (INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
 Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
 
void IUFillText (IText *tp, const char *name, const char *label, const char *initialText)
 Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
 
void IUFillBLOB (IBLOB *bp, const char *name, const char *label, const char *format)
 Assign attributes for a BLOB property. The BLOB's data and auxiliary elements will be set to NULL.
 
void IUFillSwitchVector (ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
 Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
 
void IUFillLightVector (ILightVectorProperty *lvp, ILight *lp, int nlp, const char *dev, const char *name, const char *label, const char *group, IPState s)
 Assign attributes for a light vector property. The vector's auxiliary elements will be set to NULL.
 
void IUFillNumberVector (INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
 Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
 
void IUFillTextVector (ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
 Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
 
void IUFillBLOBVector (IBLOBVectorProperty *bvp, IBLOB *bp, int nbp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
 Assign attributes for a BLOB vector property. The vector's auxiliary elements will be set to NULL.
 
int IUSnoopNumber (XMLEle *root, INumberVectorProperty *nvp)
 Update a snooped number vector property from the given XML root element.
 
int IUSnoopText (XMLEle *root, ITextVectorProperty *tvp)
 Update a snooped text vector property from the given XML root element.
 
int IUSnoopLight (XMLEle *root, ILightVectorProperty *lvp)
 Update a snooped light vector property from the given XML root element.
 
int IUSnoopSwitch (XMLEle *root, ISwitchVectorProperty *svp)
 Update a snooped switch vector property from the given XML root element.
 
int IUSnoopBLOB (XMLEle *root, IBLOBVectorProperty *bvp)
 Update a snooped BLOB vector property from the given XML root element.
 
int crackDN (XMLEle *root, char **dev, char **name, char msg[])
 Extract dev and name attributes from an XML element.
 
int crackIPState (const char *str, IPState *ip)
 Extract property state (Idle, OK, Busy, Alert) from the supplied string.
 
int crackISState (const char *str, ISState *ip)
 Extract switch state (On or Off) from the supplied string.
 
int crackIPerm (const char *str, IPerm *ip)
 Extract property permission state (RW, RO, WO) from the supplied string.
 
int crackISRule (const char *str, ISRule *ip)
 Extract switch rule (OneOfMany, OnlyOne..etc) from the supplied string.
 
const char * pstateStr (IPState s)
 
const char * sstateStr (ISState s)
 
const char * ruleStr (ISRule r)
 
const char * permStr (IPerm p)
 
void xmlv1 ()
 print the boilerplate comment introducing xml
 

Macro Definition Documentation

◆ MAXRBUF

#define MAXRBUF   2048

Definition at line 19 of file indidevapi.c.

Function Documentation

◆ configRootFP()

XMLEle * configRootFP ( const char *  device)

Get configuration root XML pointer N.B. Must be freed by the caller

Definition at line 63 of file indidevapi.c.

◆ crackDN()

int crackDN ( XMLEle *  root,
char **  dev,
char **  name,
char  msg[] 
)

Extract dev and name attributes from an XML element.

Definition at line 770 of file indidevapi.c.

◆ crackIPerm()

int crackIPerm ( const char *  str,
IPerm *  ip 
)

Extract property permission state (RW, RO, WO) from the supplied string.

Parameters
strA string representation of the permission state.
ipPointer to IPerm structure to store the extracted permission state.
Returns
0 if successful, -1 if error is encountered.

Definition at line 819 of file indidevapi.c.

◆ crackIPState()

int crackIPState ( const char *  str,
IPState *  ip 
)

Extract property state (Idle, OK, Busy, Alert) from the supplied string.

Parameters
strA string representation of the state.
ipPointer to IPState structure to store the extracted property state.
Returns
0 if successful, -1 if error is encountered.

Definition at line 793 of file indidevapi.c.

◆ crackISRule()

int crackISRule ( const char *  str,
ISRule *  ip 
)

Extract switch rule (OneOfMany, OnlyOne..etc) from the supplied string.

Parameters
strA string representation of the switch rule.
ipPointer to ISRule structure to store the extracted switch rule.
Returns
0 if successful, -1 if error is encountered.

Definition at line 832 of file indidevapi.c.

◆ crackISState()

int crackISState ( const char *  str,
ISState *  ip 
)

Extract switch state (On or Off) from the supplied string.

Parameters
strA string representation of the switch state.
ipPointer to ISState structure to store the extracted switch state.
Returns
0 if successful, -1 if error is encountered.

Definition at line 808 of file indidevapi.c.

◆ IUFillBLOB()

void IUFillBLOB ( IBLOB *  bp,
const char *  name,
const char *  label,
const char *  format 
)

Assign attributes for a BLOB property. The BLOB's data and auxiliary elements will be set to NULL.

Parameters
bppointer a BLOB property to fill
namethe BLOB name
labelthe BLOB label
formatthe BLOB format.

Definition at line 434 of file indidevapi.c.

◆ IUFillBLOBVector()

void IUFillBLOBVector ( IBLOBVectorProperty *  bvp,
IBLOB *  bp,
int  nbp,
const char *  dev,
const char *  name,
const char *  label,
const char *  group,
IPerm  p,
double  timeout,
IPState  s 
)

Assign attributes for a BLOB vector property. The vector's auxiliary elements will be set to NULL.

Parameters
bvppointer a BLOB vector property to fill
bppointer to an array of BLOBs
nbpthe dimension of bp
devthe device name this vector property belongs to
namethe vector property name
labelthe vector property label
groupthe vector property group
pthe vector property permission
timeoutvector property timeout in seconds
sthe vector property initial state.

Definition at line 528 of file indidevapi.c.

◆ IUFillLight()

void IUFillLight ( ILight *  lp,
const char *  name,
const char *  label,
IPState  s 
)

Assign attributes for a light property. The light's auxiliary elements will be set to NULL.

Parameters
lppointer a light property to fill
namethe light name
labelthe light label
sthe light state (IDLE, WARNING, OK, ALERT)

Definition at line 387 of file indidevapi.c.

◆ IUFillLightVector()

void IUFillLightVector ( ILightVectorProperty *  lvp,
ILight *  lp,
int  nlp,
const char *  dev,
const char *  name,
const char *  label,
const char *  group,
IPState  s 
)

Assign attributes for a light vector property. The vector's auxiliary elements will be set to NULL.

Parameters
lvppointer a light vector property to fill
lppointer to an array of lights
nlpthe dimension of lp
devthe device name this vector property belongs to
namethe vector property name
labelthe vector property label
groupthe vector property group
sthe vector property initial state.

Definition at line 473 of file indidevapi.c.

◆ IUFillNumber()

void IUFillNumber ( INumber *  np,
const char *  name,
const char *  label,
const char *  format,
double  min,
double  max,
double  step,
double  value 
)

Assign attributes for a number property. The number's auxiliary elements will be set to NULL.

Parameters
nppointer a number property to fill
namethe number name
labelthe number label
formatthe number format in printf style (e.g. "%02d")
minthe minimum possible value
maxthe maximum possible value
stepthe step used to climb from minimum value to maximum value
valuethe number's current value

Definition at line 398 of file indidevapi.c.

◆ IUFillNumberVector()

void IUFillNumberVector ( INumberVectorProperty *  nvp,
INumber *  np,
int  nnp,
const char *  dev,
const char *  name,
const char *  label,
const char *  group,
IPerm  p,
double  timeout,
IPState  s 
)

Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.

Parameters
nvppointer a number vector property to fill
nppointer to an array of numbers
nnpthe dimension of np
devthe device name this vector property belongs to
namethe vector property name
labelthe vector property label
groupthe vector property group
pthe vector property permission
timeoutvector property timeout in seconds
sthe vector property initial state.

Definition at line 490 of file indidevapi.c.

◆ IUFillSwitch()

void IUFillSwitch ( ISwitch *  sp,
const char *  name,
const char *  label,
ISState  s 
)

Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.

IUUpdate

IUFill

Definition at line 376 of file indidevapi.c.

◆ IUFillSwitchVector()

void IUFillSwitchVector ( ISwitchVectorProperty *  svp,
ISwitch *  sp,
int  nsp,
const char *  dev,
const char *  name,
const char *  label,
const char *  group,
IPerm  p,
ISRule  r,
double  timeout,
IPState  s 
)

Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.

Parameters
svppointer a switch vector property to fill
sppointer to an array of switches
nspthe dimension of sp
devthe device name this vector property belongs to
namethe vector property name
labelthe vector property label
groupthe vector property group
pthe vector property permission
rthe switches behavior
timeoutvector property timeout in seconds
sthe vector property initial state.

Definition at line 453 of file indidevapi.c.

◆ IUFillText()

void IUFillText ( IText *  tp,
const char *  name,
const char *  label,
const char *  initialText 
)

Assign attributes for a text property. The text's auxiliary elements will be set to NULL.

Parameters
tppointer a text property to fill
namethe text name
labelthe text label
initialTextthe initial text

Definition at line 416 of file indidevapi.c.

◆ IUFillTextVector()

void IUFillTextVector ( ITextVectorProperty *  tvp,
IText *  tp,
int  ntp,
const char *  dev,
const char *  name,
const char *  label,
const char *  group,
IPerm  p,
double  timeout,
IPState  s 
)

Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.

Parameters
tvppointer a text vector property to fill
tppointer to an array of texts
ntpthe dimension of tp
devthe device name this vector property belongs to
namethe vector property name
labelthe vector property label
groupthe vector property group
pthe vector property permission
timeoutvector property timeout in seconds
sthe vector property initial state.

Definition at line 509 of file indidevapi.c.

◆ IUFindBLOB()

IBLOB * IUFindBLOB ( const IBLOBVectorProperty *  bvp,
const char *  name 
)

Find an IBLOB member in a vector BLOB property.

Parameters
bvpa pointer to a BLOB vector property.
namethe name of the member to search for.
Returns
a pointer to an IBLOB member on match, or NULL if nothing is found.

Definition at line 305 of file indidevapi.c.

◆ IUFindIndex()

int IUFindIndex ( const char *  needle,
char **  hay,
unsigned int  n 
)

Returns the index of the string in a string array.

Parameters
needlethe string to match against each element in the hay
haya pointer to a string array to search in
nthe size of hay
Returns
index of needle if found in the hay. Otherwise -1 if not found.

Definition at line 326 of file indidevapi.c.

◆ IUFindLight()

ILight * IUFindLight ( const ILightVectorProperty *  lvp,
const char *  name 
)

Find an ILight member in a vector Light property.

Parameters
lvpa pointer to a Light vector property.
namethe name of the member to search for.
Returns
a pointer to an ILight member on match, or NULL if nothing is found.

Definition at line 295 of file indidevapi.c.

◆ IUFindNumber()

INumber * IUFindNumber ( const INumberVectorProperty *  nvp,
const char *  name 
)

Find an INumber member in a number text property.

Parameters
nvpa pointer to a number vector property.
namethe name of the member to search for.
Returns
a pointer to an INumber member on match, or NULL if nothing is found.

Definition at line 275 of file indidevapi.c.

◆ IUFindOnStateIndex()

int IUFindOnStateIndex ( ISState *  states,
int  n 
)

Returns the index of first ON switch it finds in the ISState array.

Note
This is only valid for ISR_1OFMANY mode. That is, when only one switch out of many is allowed to be ON. Do not use this function if you can have multiple ON switches in the same vector property.
Parameters
statea pointer to states array.
nlength of array.
Returns
index to the first ON ISwitch member if found. If all switches are off, -1 is returned.

Definition at line 346 of file indidevapi.c.

◆ IUFindOnSwitch()

ISwitch * IUFindOnSwitch ( const ISwitchVectorProperty *  sp)

Returns the first ON switch it finds in the vector switch property.

Note
This is only valid for ISR_1OFMANY mode. That is, when only one switch out of many is allowed to be ON. Do not use this function if you can have multiple ON switches in the same vector property.
Parameters
spa pointer to a switch vector property.
Returns
a pointer to the first ON ISwitch member if found. If all switches are off, NULL is returned.

Definition at line 317 of file indidevapi.c.

◆ IUFindOnSwitchIndex()

int IUFindOnSwitchIndex ( const ISwitchVectorProperty *  sp)

Returns the index of first ON switch it finds in the vector switch property.

Note
This is only valid for ISR_1OFMANY mode. That is, when only one switch out of many is allowed to be ON. Do not use this function if you can have multiple ON switches in the same vector property.
Parameters
spa pointer to a switch vector property.
Returns
index to the first ON ISwitch member if found. If all switches are off, -1 is returned.

Definition at line 337 of file indidevapi.c.

◆ IUFindOnSwitchName()

const char * IUFindOnSwitchName ( ISState *  states,
char *  names[],
int  n 
)

Returns the name of the first ON switch it finds in the supplied arguments.

Note
This is only valid for ISR_1OFMANY mode. That is, when only one switch out of many is allowed to be ON. Do not use this function if you can have multiple ON switches in the same vector property.
This is a convenience function intended to be used in ISNewSwitch(...) function to find out ON switch name without having to change actual switch state via IUUpdateSwitch(..)
Parameters
stateslist of switch states passed by ISNewSwitch()
nameslist of switch names passed by ISNewSwitch()
nnumber of switches passed by ISNewSwitch()
Returns
name of the first ON ISwitch member if found. If all switches are off, NULL is returned.

Definition at line 355 of file indidevapi.c.

◆ IUFindSwitch()

ISwitch * IUFindSwitch ( const ISwitchVectorProperty *  svp,
const char *  name 
)

Find an ISwitch member in a vector switch property.

Parameters
svpa pointer to a switch vector property.
namethe name of the member to search for.
Returns
a pointer to an ISwitch member on match, or NULL if nothing is found.

Definition at line 285 of file indidevapi.c.

◆ IUFindText()

IText * IUFindText ( const ITextVectorProperty *  tvp,
const char *  name 
)

Find an IText member in a vector text property.

IUFind

Definition at line 265 of file indidevapi.c.

◆ IULoadConfigNumber()

int IULoadConfigNumber ( const INumberVectorProperty *  nvp)

Load a number vector property value from the configuration file.

IULoad

Definition at line 126 of file indidevapi.c.

◆ IULoadConfigSwitch()

int IULoadConfigSwitch ( const ISwitchVectorProperty *  svp)

Add a switch vector property value to the configuration file.

Parameters
svppointer to a switch vector property.
Returns
Number of members successfully updated or 0 on failure

Definition at line 214 of file indidevapi.c.

◆ IULoadConfigText()

int IULoadConfigText ( const ITextVectorProperty *  tvp)

Load a text vector property value from the configuration file.

Parameters
tvppointer to a text vector property.
Returns
Number of members successfully updated or 0 on failure

Definition at line 170 of file indidevapi.c.

◆ IUResetSwitch()

void IUResetSwitch ( ISwitchVectorProperty *  svp)

Reset all switches in a switch vector property to OFF.

IUReset

Definition at line 366 of file indidevapi.c.

◆ IUSaveBLOB()

int IUSaveBLOB ( IBLOB *  bp,
int  size,
int  blobsize,
char *  blob,
char *  format 
)

Function to save blob metadata in the corresponding blob.

Parameters
bppointer to an IBLOB member.
sizesize of the blob buffer encoded in base64
blobsizeactual size of the buffer after base64 decoding. This is the actual byte count used in drivers.
blobpointer to the blob buffer
formatformat of the blob buffer
Note
Do not call this function directly, it is called internally by IUUpdateBLOB.

Definition at line 52 of file indidevapi.c.

◆ IUSaveConfigBLOB()

void IUSaveConfigBLOB ( FILE *  fp,
const IBLOBVectorProperty *  bvp 
)

Add a BLOB vector property value to the configuration file.

Parameters
fpfile pointer to a configuration file.
bvppointer to a BLOB vector property.
Note
If the BLOB size is large, this function will block until the BLOB contents are written to the file.

Definition at line 38 of file indidevapi.c.

◆ IUSaveConfigNumber()

void IUSaveConfigNumber ( FILE *  fp,
const INumberVectorProperty *  nvp 
)

Add a number vector property value to the configuration file.

IUSave

Definition at line 23 of file indidevapi.c.

◆ IUSaveConfigSwitch()

void IUSaveConfigSwitch ( FILE *  fp,
const ISwitchVectorProperty *  svp 
)

Add a switch vector property value to the configuration file.

Parameters
fpfile pointer to a configuration file.
svppointer to a switch vector property.

Definition at line 33 of file indidevapi.c.

◆ IUSaveConfigText()

void IUSaveConfigText ( FILE *  fp,
const ITextVectorProperty *  tvp 
)

Add a text vector property value to the configuration file.

Parameters
fpfile pointer to a configuration file.
tvppointer to a text vector property.

Definition at line 28 of file indidevapi.c.

◆ IUSaveText()

void IUSaveText ( IText *  tp,
const char *  newtext 
)

Function to reliably save new text in a IText.

Parameters
tppointer to an IText member.
newtextthe new text to be saved

Definition at line 44 of file indidevapi.c.

◆ IUSnoopBLOB()

int IUSnoopBLOB ( XMLEle *  root,
IBLOBVectorProperty *  bvp 
)

Update a snooped BLOB vector property from the given XML root element.

Parameters
rootXML root elememnt containing the snopped property content
bvpa pointer to the BLOB vector property to be updated.
Returns
0 if cracking the XML element and updating the property proceeded without errors, -1 if trouble.

Definition at line 720 of file indidevapi.c.

◆ IUSnoopLight()

int IUSnoopLight ( XMLEle *  root,
ILightVectorProperty *  lvp 
)

Update a snooped light vector property from the given XML root element.

Parameters
rootXML root elememnt containing the snopped property content
lvpa pointer to the light vector property to be updated.
Returns
0 if cracking the XML element and updating the property proceeded without errors, -1 if trouble.

Definition at line 636 of file indidevapi.c.

◆ IUSnoopNumber()

int IUSnoopNumber ( XMLEle *  root,
INumberVectorProperty *  nvp 
)

Update a snooped number vector property from the given XML root element.

IUSnoop

Definition at line 555 of file indidevapi.c.

◆ IUSnoopSwitch()

int IUSnoopSwitch ( XMLEle *  root,
ISwitchVectorProperty *  svp 
)

Update a snooped switch vector property from the given XML root element.

Parameters
rootXML root elememnt containing the snopped property content
svpa pointer to the switch vector property to be updated.
Returns
0 if cracking the XML element and updating the property proceeded without errors, -1 if trouble.

Definition at line 678 of file indidevapi.c.

◆ IUSnoopText()

int IUSnoopText ( XMLEle *  root,
ITextVectorProperty *  tvp 
)

Update a snooped text vector property from the given XML root element.

Parameters
rootXML root elememnt containing the snopped property content
tvpa pointer to the text vector property to be updated.
Returns
0 if cracking the XML element and updating the property proceeded without errors, -1 if trouble.

Definition at line 600 of file indidevapi.c.

◆ permStr()

const char * permStr ( IPerm  p)
Returns
Returns a string representation of the supplied permission value.

Definition at line 893 of file indidevapi.c.

◆ pstateStr()

const char * pstateStr ( IPState  s)
Returns
Returns a string representation of the supplied property state.

Definition at line 845 of file indidevapi.c.

◆ ruleStr()

const char * ruleStr ( ISRule  r)
Returns
Returns a string representation of the supplied switch rule.

Definition at line 877 of file indidevapi.c.

◆ sstateStr()

const char * sstateStr ( ISState  s)
Returns
Returns a string representation of the supplied switch status.

Definition at line 863 of file indidevapi.c.

◆ xmlv1()

void xmlv1 ( )

print the boilerplate comment introducing xml

Definition at line 909 of file indidevapi.c.