39 size_t size = strlen(newtext) + 1;
40 tp->text = realloc(tp->text, size);
41 memcpy(tp->text, newtext, size);
46 bp->bloblen = blobsize;
58 for (
int i = 0; i < tvp->
ntp; i++)
59 if (strcmp(tvp->
tp[i].name, name) == 0)
61 fprintf(stderr,
"No IText '%s' in %s.%s\n", name, tvp->
device, tvp->
name);
68 for (
int i = 0; i < nvp->
nnp; i++)
69 if (strcmp(nvp->
np[i].name, name) == 0)
71 fprintf(stderr,
"No INumber '%s' in %s.%s\n", name, nvp->
device, nvp->
name);
78 for (
int i = 0; i < svp->
nsp; i++)
79 if (strcmp(svp->
sp[i].name, name) == 0)
81 fprintf(stderr,
"No ISwitch '%s' in %s.%s\n", name, svp->
device, svp->
name);
88 for (
int i = 0; i < lvp->
nlp; i++)
89 if (strcmp(lvp->
lp[i].name, name) == 0)
91 fprintf(stderr,
"No ILight '%s' in %s.%s\n", name, lvp->
device, lvp->
name);
98 for (
int i = 0; i < bvp->
nbp; i++)
99 if (strcmp(bvp->
bp[i].name, name) == 0)
100 return (&bvp->
bp[i]);
101 fprintf(stderr,
"No IBLOB '%s' in %s.%s\n", name, bvp->
device, bvp->
name);
110 for (
int i = 0; i < svp->
nsp; i++)
112 return (&svp->
sp[i]);
119 for (
int i = 0; i < (int)n; i++)
121 if (!strcmp(hay[i], needle))
130 for (
int i = 0; i < svp->
nsp; i++)
139 for (
int i = 0; i < n; i++)
150 for (
int i = 0; i < svp->
nsp; i++)
160 indi_strlcpy(sp->name, name,
sizeof(sp->name));
162 indi_strlcpy(sp->label, label[0] ? label : name,
sizeof(sp->label));
171 indi_strlcpy(lp->name, name,
sizeof(lp->name));
173 indi_strlcpy(lp->label, label[0] ? label : name,
sizeof(lp->label));
181 double step,
double value)
183 indi_strlcpy(np->name, name,
sizeof(np->name));
185 indi_strlcpy(np->label, label[0] ? label : name,
sizeof(np->label));
187 indi_strlcpy(np->format, format,
sizeof(np->format));
198 void IUFillText(
IText *tp,
const char *name,
const char *label,
const char *initialText)
200 indi_strlcpy(tp->name, name,
sizeof(tp->name));
202 indi_strlcpy(tp->label, label[0] ? label : name,
sizeof(tp->label));
204 if (tp->text && tp->text[0])
212 if (initialText && initialText[0])
218 memset(bp, 0,
sizeof(
IBLOB));
220 indi_strlcpy(bp->name, name,
sizeof(bp->name));
222 indi_strlcpy(bp->label, label[0] ? label : name,
sizeof(bp->label));
224 indi_strlcpy(bp->format, format,
sizeof(bp->format));
240 indi_strlcpy(svp->
name, name,
sizeof(svp->
name));
242 indi_strlcpy(svp->
label, label[0] ? label : name,
sizeof(svp->
label));
244 indi_strlcpy(svp->
group, group,
sizeof(svp->
group));
256 const char *label,
const char *group,
IPState s)
260 indi_strlcpy(lvp->
name, name,
sizeof(lvp->
name));
262 indi_strlcpy(lvp->
label, label[0] ? label : name,
sizeof(lvp->
label));
264 indi_strlcpy(lvp->
group, group,
sizeof(lvp->
group));
273 const char *label,
const char *group,
IPerm p,
double timeout,
IPState s)
277 indi_strlcpy(nvp->
name, name,
sizeof(nvp->
name));
279 indi_strlcpy(nvp->
label, label[0] ? label : name,
sizeof(nvp->
label));
281 indi_strlcpy(nvp->
group, group,
sizeof(nvp->
group));
292 const char *label,
const char *group,
IPerm p,
double timeout,
IPState s)
296 indi_strlcpy(tvp->
name, name,
sizeof(tvp->
name));
298 indi_strlcpy(tvp->
label, label[0] ? label : name,
sizeof(tvp->
label));
300 indi_strlcpy(tvp->
group, group,
sizeof(tvp->
group));
311 const char *label,
const char *group,
IPerm p,
double timeout,
IPState s)
316 indi_strlcpy(bvp->
name, name,
sizeof(bvp->
name));
318 indi_strlcpy(bvp->
label, label[0] ? label : name,
sizeof(bvp->
label));
320 indi_strlcpy(bvp->
group, group,
sizeof(bvp->
group));
343 if (strcmp(
tagXMLEle(root) + 3,
"NumberVector") ||
crackDN(root, &dev, &name, NULL) < 0)
345 if (strcmp(dev, nvp->
device) || strcmp(name, nvp->
name))
351 for (
int i = 0; i < nvp->
nnp; i++)
359 indi_locale_C_numeric_pop(orig);
367 indi_locale_C_numeric_pop(orig);
371 indi_locale_C_numeric_pop(orig);
388 if (strcmp(
tagXMLEle(root) + 3,
"TextVector") ||
crackDN(root, &dev, &name, NULL) < 0)
390 if (strcmp(dev, tvp->
device) || strcmp(name, tvp->
name))
395 for (
int i = 0; i < tvp->
ntp; i++)
424 if (strcmp(
tagXMLEle(root) + 3,
"LightVector") ||
crackDN(root, &dev, &name, NULL) < 0)
426 if (strcmp(dev, lvp->
device) || strcmp(name, lvp->
name))
437 for (
int i = 0; i < lvp->
nlp; i++)
439 if (!strcmp(lvp->
lp[i].name, name))
466 if (strcmp(
tagXMLEle(root) + 3,
"SwitchVector") ||
crackDN(root, &dev, &name, NULL) < 0)
468 if (strcmp(dev, svp->
device) || strcmp(name, svp->
name))
475 if (!strcmp(
tagXMLEle(ep) + 3,
"Switch"))
478 for (
int i = 0; i < svp->
nsp; i++)
480 if (!strcmp(svp->
sp[i].name, name))
508 if (strcmp(
tagXMLEle(root),
"setBLOBVector") ||
crackDN(root, &dev, &name, NULL) < 0)
511 if (strcmp(dev, bvp->
device) || strcmp(name, bvp->
name))
518 if (strcmp(
tagXMLEle(ep),
"oneBLOB") == 0)
535 assert_mem(bp->blob = realloc(bp->blob, 3 * enclen / 4));
560 sprintf(msg,
"%s requires 'device' attribute",
tagXMLEle(root));
568 sprintf(msg,
"%s requires 'name' attribute",
tagXMLEle(root));
578 if (!strcmp(str,
"Idle"))
580 else if (!strncmp(str,
"Ok", 2))
582 else if (!strcmp(str,
"Busy"))
584 else if (!strcmp(str,
"Alert"))
593 if (!strncmp(str,
"On", 2))
595 else if (!strcmp(str,
"Off"))
604 if (!strncmp(str,
"rw", 2))
606 else if (!strncmp(str,
"ro", 2))
608 else if (!strncmp(str,
"wo", 2))
617 if (!strcmp(str,
"OneOfMany"))
619 else if (!strcmp(str,
"AtMostOne"))
621 else if (!strcmp(str,
"AnyOfMany"))
641 fprintf(stderr,
"Impossible IPState %d\n", s);
655 fprintf(stderr,
"Impossible ISState %d\n", s);
671 fprintf(stderr,
"Impossible ISRule %d\n", r);
687 fprintf(stderr,
"Impossible IPerm %d\n", p);
int from64tobits_fast(char *out, const char *in, int inlen)
#define assert_mem(p)
Bails out if memory pointer is 0. Prints file and function.
IPerm
Permission hint, with respect to client.
ISRule
Switch vector rule hint.
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double. x can be anything non-numeric. Any missing A,...
Implementations for common driver routines.
int IUSnoopSwitch(XMLEle *root, ISwitchVectorProperty *svp)
Update a snooped switch vector property from the given XML root element.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
const char * ruleStr(ISRule r)
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 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.
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
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 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.
const char * IUFindOnSwitchName(ISState *states, char *names[], int n)
Returns the name of the first ON switch it finds in the supplied arguments.
ISwitch * IUFindOnSwitch(const ISwitchVectorProperty *svp)
Returns the first ON switch it finds in the vector switch property.
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
int IUFindIndex(const char *needle, char **hay, unsigned int n)
Returns the index of the string in a string array.
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 IUSnoopLight(XMLEle *root, ILightVectorProperty *lvp)
Update a snooped light vector property from the given XML root element.
int IUSaveBLOB(IBLOB *bp, int size, int blobsize, char *blob, char *format)
Function to save blob metadata in the corresponding blob.
void IUSaveConfigBLOB(FILE *fp, const IBLOBVectorProperty *bvp)
Add a BLOB vector property value to the configuration file.
int IUSnoopText(XMLEle *root, ITextVectorProperty *tvp)
Update a snooped text vector property from the given XML root element.
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
int IUSnoopNumber(XMLEle *root, INumberVectorProperty *nvp)
Update a snooped number vector property from the given XML root element.
void xmlv1()
print the boilerplate comment introducing xml
const char * pstateStr(IPState s)
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 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 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.
int crackIPerm(const char *str, IPerm *ip)
Extract property permission state (RW, RO, WO) from the supplied string.
void IUSaveConfigText(FILE *fp, const ITextVectorProperty *tvp)
Add a text vector property value to the configuration file.
int crackIPState(const char *str, IPState *ip)
Extract property state (Idle, OK, Busy, Alert) from the supplied string.
IBLOB * IUFindBLOB(const IBLOBVectorProperty *bvp, const char *name)
Find an IBLOB member in a vector BLOB property.
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.
IText * IUFindText(const ITextVectorProperty *tvp, const char *name)
Find an IText member in a vector text property.
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.
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.
ILight * IUFindLight(const ILightVectorProperty *lvp, const char *name)
Find an ILight member in a vector Light property.
int crackISRule(const char *str, ISRule *ip)
Extract switch rule (OneOfMany, OnlyOne..etc) from the supplied string.
const char * sstateStr(ISState s)
const char * permStr(IPerm p)
int crackISState(const char *str, ISState *ip)
Extract switch state (On or Off) from the supplied string.
ISwitch * IUFindSwitch(const ISwitchVectorProperty *svp, const char *name)
Find an ISwitch member in a vector switch property.
Interface to the reference INDI C API device implementation on the Device Driver side.
void IUUserIONewBLOB(const userio *io, void *user, const IBLOBVectorProperty *bvp)
void IUUserIONewSwitchFull(const userio *io, void *user, const ISwitchVectorProperty *svp)
void IUUserIONewText(const userio *io, void *user, const ITextVectorProperty *tvp)
void IUUserIONewNumber(const userio *io, void *user, const INumberVectorProperty *nvp)
XMLAtt * findXMLAtt(XMLEle *ep, const char *name)
Find an XML attribute within an XML element.
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
char * tagXMLEle(XMLEle *ep)
Return the tag of an XML element.
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
char * valuXMLAtt(XMLAtt *ap)
Return the value of an XML attribute.
One Blob (Binary Large Object) descriptor.
BLOB (Binary Large Object) vector property descriptor.
char timestamp[MAXINDITSTAMP]
char device[MAXINDIDEVICE]
Light vector property descriptor.
char device[MAXINDIDEVICE]
char timestamp[MAXINDITSTAMP]
Number vector property descriptor.
char device[MAXINDIDEVICE]
char timestamp[MAXINDITSTAMP]
Switch vector property descriptor.
char device[MAXINDIDEVICE]
char timestamp[MAXINDITSTAMP]
Text vector property descriptor.
char device[MAXINDIDEVICE]
char timestamp[MAXINDITSTAMP]
const struct userio * userio_file()
void userio_xmlv1(const userio *io, void *user)