Config now reads sensors configuration

Wed, 23 Apr 2014 21:17:44 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 23 Apr 2014 21:17:44 +0200
changeset 9
91218bc77abc
parent 8
e584bc0177df
child 10
5600a1789644

Config now reads sensors configuration

lib/mbselib.h file | annotate | diff | comparison | revisions
lib/rdconfig.c file | annotate | diff | comparison | revisions
--- a/lib/mbselib.h	Wed Apr 23 17:19:00 2014 +0200
+++ b/lib/mbselib.h	Wed Apr 23 21:17:44 2014 +0200
@@ -29,14 +29,25 @@
     char	**dest;
 } key_list;
 
+typedef struct _w1_therm {
+    struct _w1_therm    *next;
+    char                *master;                /* Master for this device       */
+    int                 bus;                    /* Reserved for ds2482-800      */
+    char                *name;                  /* Name of this device          */
+    char                *alias;                 /* Friendly name                */
+    int                 present;                /* 1=present, 0=absent          */
+    int                 lastval;                /* Last valid value             */
+} w1_therm;
 
 typedef struct _sys_config {
-    char	*name;			/* Configuration name		*/
-    char	*mosq_host;		/* mosquitto server hostname	*/
-    int		mosq_port;		/* mosquitto server port	*/
+    char		*name;			/* Configuration name		*/
+    char		*mosq_host;		/* mosquitto server hostname	*/
+    int			mosq_port;		/* mosquitto server port	*/
+    w1_therm		*w1therms;		/* 1-wire temp sensors		*/
 } sys_config;
 
 
+
 void killconfig(void);
 int  rdconfig(void);
 
--- a/lib/rdconfig.c	Wed Apr 23 17:19:00 2014 +0200
+++ b/lib/rdconfig.c	Wed Apr 23 21:17:44 2014 +0200
@@ -34,6 +34,7 @@
 
 static int getstr(char **);
 static int getint(char **);
+static int getw1(char **);
 //static int getbyt(char **);
 //static int gethex(char **);
 
@@ -46,6 +47,7 @@
 key_list keytab[] = {
     {(char *)"mosq_host",	getstr,		&Config.mosq_host},
     {(char *)"mosq_port",	getint,		(char **)&Config.mosq_port},
+    {(char *)"w1therm",		getw1,		(char **)&Config.w1therms},
     {NULL,			NULL,		NULL}
 };
 
@@ -53,6 +55,8 @@
 
 void killconfig(void)
 {
+    w1_therm	*tmp1, *old1;
+
     if (Config.name)
 	free(Config.name);
     Config.name = NULL;
@@ -61,6 +65,18 @@
 	free(Config.mosq_host);
     Config.mosq_host= (char *)"localhost";
     Config.mosq_port = 1883;
+
+    for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
+	old1 = tmp1->next;
+	if (tmp1->master)
+	    free(tmp1->master);
+	if (tmp1->name)
+	    free(tmp1->name);
+	if (tmp1->alias)
+	    free(tmp1->alias);
+	free(tmp1);
+    }
+    Config.w1therms = NULL;
 }
 
 
@@ -158,6 +174,57 @@
 }
 
 
+
+static int getw1(char **dest)
+{
+    char	*p, *q = NULL, *r = NULL;
+    w1_therm	**tmpm;
+    int		rc = 0, tmpp;
+
+    for (p = v; *p && !isspace(*p); p++);
+    if (*p)
+	*p++ = '\0';
+    while (*p && isspace(*p))
+	p++;
+    if (*p == '\0') {
+	syslog(LOG_NOTICE, "rdconfig: %s(%d): less then two tokens", mypath, linecnt);
+	return 1;
+    }
+
+    for (q = p; *q && !isspace(*q); q++);
+    if (*q && isspace(*q)) {
+	if (*q)
+	    *q++ = '\0';
+	while (*q && isspace(*q))
+	    q++;
+
+	for (r = q; *r && !isspace(*r); r++);
+	if (*r)
+	    *r++ = '\0';
+	rc = sscanf(p, "%d", &tmpp);
+	if (rc != 1) {
+	    syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s is not a integer value", mypath, linecnt, p);
+	    return 1;
+	}
+	if (debug)
+	    syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s %d %s %s", mypath, linecnt, v, tmpp, q, r);
+    }
+
+    for (tmpm = (w1_therm**)dest; *tmpm; tmpm=&((*tmpm)->next));
+    (*tmpm) = (w1_therm *) xmalloc(sizeof(w1_therm));
+    (*tmpm)->next = NULL;
+    (*tmpm)->master = xstrcpy(v);
+    (*tmpm)->bus = tmpp;
+    (*tmpm)->name = xstrcpy(q);
+    (*tmpm)->alias = xstrcpy(r);
+    (*tmpm)->present = 0;
+    (*tmpm)->lastval = 0;
+
+    return 0;
+}
+
+
+
 /*
 static int getbyt(char **dest)
 {

mercurial