TwiceAsNice  2019-02-18
Functions
IU Functions: Functions drivers call to perform handy utility routines.


More...

Functions

ITextIUFindText (const ITextVectorProperty *tvp, const char *name)
 Find an IText member in a vector text property. More...
 
INumberIUFindNumber (const INumberVectorProperty *nvp, const char *name)
 Find an INumber member in a number text property. More...
 
ISwitchIUFindSwitch (const ISwitchVectorProperty *svp, const char *name)
 Find an ISwitch member in a vector switch property. More...
 
ILightIUFindLight (const ILightVectorProperty *lvp, const char *name)
 Find an ILight member in a vector Light property. More...
 
IBLOBIUFindBLOB (const IBLOBVectorProperty *bvp, const char *name)
 Find an IBLOB member in a vector BLOB property. More...
 
ISwitchIUFindOnSwitch (const ISwitchVectorProperty *sp)
 Returns the first ON switch it finds in the vector switch property. More...
 
int IUFindIndex (const char *needle, char **hay, unsigned int n)
 Returns the index of the string in a string array. More...
 
int IUFindOnSwitchIndex (const ISwitchVectorProperty *sp)
 Returns the index of first ON switch it finds in the vector switch property. More...
 
const char * IUFindOnSwitchName (ISState *states, char *names[], int n)
 Returns the name of the first ON switch it finds in the supplied arguments. More...
 
void IUResetSwitch (ISwitchVectorProperty *svp)
 Reset all switches in a switch vector property to OFF. More...
 
int IUUpdateSwitch (ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
 Update all switches in a switch vector property. More...
 
int IUUpdateNumber (INumberVectorProperty *nvp, double values[], char *names[], int n)
 Update all numbers in a number vector property. More...
 
int IUUpdateText (ITextVectorProperty *tvp, char *texts[], char *names[], int n)
 Update all text members in a text vector property. More...
 
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. More...
 
int IUSaveBLOB (IBLOB *bp, int size, int blobsize, char *blob, char *format)
 Function to save blob metadata in the corresponding blob. More...
 
void IUUpdateMinMax (const INumberVectorProperty *nvp)
 Function to update the min and max elements of a number in the client. More...
 
void IUSaveText (IText *tp, const char *newtext)
 Function to reliably save new text in a IText. More...
 
void IUFillSwitch (ISwitch *sp, const char *name, const char *label, ISState s)
 Assign attributes for a switch property. More...
 
void IUFillLight (ILight *lp, const char *name, const char *label, IPState s)
 Assign attributes for a light property. More...
 
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. More...
 
void IUFillText (IText *tp, const char *name, const char *label, const char *initialText)
 Assign attributes for a text property. More...
 
void IUFillBLOB (IBLOB *bp, const char *name, const char *label, const char *format)
 Assign attributes for a BLOB property. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int IUSnoopNumber (XMLEle *root, INumberVectorProperty *nvp)
 Update a snooped number vector property from the given XML root element. More...
 
int IUSnoopText (XMLEle *root, ITextVectorProperty *tvp)
 Update a snooped text vector property from the given XML root element. More...
 
int IUSnoopLight (XMLEle *root, ILightVectorProperty *lvp)
 Update a snooped light vector property from the given XML root element. More...
 
int IUSnoopSwitch (XMLEle *root, ISwitchVectorProperty *svp)
 Update a snooped switch vector property from the given XML root element. More...
 
int IUSnoopBLOB (XMLEle *root, IBLOBVectorProperty *bvp)
 Update a snooped BLOB vector property from the given XML root element. More...
 

Detailed Description


This section describes handy utility functions that are provided by the framework for tasks commonly required in the processing of client messages. It is not strictly necessary to use these functions, but it both prudent and efficient to do so.

These do not communicate with the Client in any way.

Function Documentation

◆ 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.

◆ 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.

◆ 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)

◆ 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.

◆ 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

◆ 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.

◆ 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.

Parameters
sppointer a switch property to fill
namethe switch name
labelthe switch label
sthe switch state (ISS_ON or ISS_OFF)

◆ 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.

◆ 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

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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 convience 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.

◆ 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.

◆ IUFindText()

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

Find an IText member in a vector text property.

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

◆ IUResetSwitch()

void IUResetSwitch ( ISwitchVectorProperty svp)

Reset all switches in a switch vector property to OFF.

Parameters
svpa pointer to a switch vector property.

◆ 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.

◆ 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

◆ 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.

◆ 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.

◆ IUSnoopNumber()

int IUSnoopNumber ( XMLEle root,
INumberVectorProperty nvp 
)

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

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

◆ 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.

◆ 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.

◆ IUUpdateBLOB()

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.

Parameters
bvpa pointer to a BLOB vector property.
sizessizes of the blobs.
blobsizessize of the blobs, raw without compression.
blobsa pointer to the BLOB members
namesthe names of the IBLOB members to update.
formatsThe blob format or extension.
nthe number of IBLOB members to update.
Returns
0 if update successful, -1 otherwise. Update will fail in case of property name mismatch.

◆ IUUpdateMinMax()

void IUUpdateMinMax ( const INumberVectorProperty nvp)

Function to update the min and max elements of a number in the client.

Parameters
nvppointer to an INumberVectorProperty.
Warning
This call is not INDI protocol compliant. It sends setNumberVector along with updated Min/Max/Step values so that the client updates the range accordingly for this property. In the INDI-compliant paradigm, it is NOT possible to update min/max/step step of an existing number property and the only way is to do so is to delete and redefine the number property again. However, due to the many problems with approach in device drivers, INDI Library defines this function to simplify the update process without requiring a complete delete/define cycle.

◆ IUUpdateNumber()

int IUUpdateNumber ( INumberVectorProperty nvp,
double  values[],
char *  names[],
int  n 
)

Update all numbers in a number vector property.

Parameters
nvpa pointer to a number vector property.
valuesthe states of the new INumber members.
namesthe names of the INumber members to update.
nthe number of INumber members to update.
Returns
0 if update successful, -1 otherwise. Update will fail if values are out of scope, or in case of property name mismatch.

◆ IUUpdateSwitch()

int IUUpdateSwitch ( ISwitchVectorProperty svp,
ISState states,
char *  names[],
int  n 
)

Update all switches in a switch vector property.

Parameters
svpa pointer to a switch vector property.
statesthe states of the new ISwitch members.
namesthe names of the ISwtich members to update.
nthe number of ISwitch members to update.
Returns
0 if update successful, -1 otherwise.

◆ IUUpdateText()

int IUUpdateText ( ITextVectorProperty tvp,
char *  texts[],
char *  names[],
int  n 
)

Update all text members in a text vector property.

Parameters
tvpa pointer to a text vector property.
textsa pointer to the text members
namesthe names of the IText members to update.
nthe number of IText members to update.
Returns
0 if update successful, -1 otherwise. Update will fail in case of property name mismatch.