Removed old 1-wire bus

Thu, 31 Jul 2014 23:57:04 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 31 Jul 2014 23:57:04 +0200
changeset 165
e97829d0f8f9
parent 164
f16def8472ba
child 166
c31ea86fec43

Removed old 1-wire bus

thermferm/Makefile file | annotate | diff | comparison | revisions
thermferm/rdconfig.c file | annotate | diff | comparison | revisions
thermferm/sensors.c file | annotate | diff | comparison | revisions
thermferm/sensors.h file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/thermferm/Makefile	Thu Jul 31 23:39:11 2014 +0200
+++ b/thermferm/Makefile	Thu Jul 31 23:57:04 2014 +0200
@@ -54,9 +54,8 @@
 
 # DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
 # Dependencies generated by make depend
-thermferm.o: lock.h logger.h rdconfig.h sensors.h devices.h server.h thermferm.h lcd-pcf8574.h lcd-buffer.h futil.h units.h xutil.h
+thermferm.o: lock.h logger.h rdconfig.h devices.h server.h thermferm.h lcd-pcf8574.h lcd-buffer.h futil.h units.h xutil.h
 devices.o: devices.h thermferm.h xutil.h
-sensors.o: sensors.h thermferm.h xutil.h
 lcd-buffer.o: thermferm.h lcd-buffer.h lcd-pcf8574.h
 futil.o: thermferm.h futil.h
 lock.o: lock.h thermferm.h
--- a/thermferm/rdconfig.c	Thu Jul 31 23:39:11 2014 +0200
+++ b/thermferm/rdconfig.c	Thu Jul 31 23:57:04 2014 +0200
@@ -43,7 +43,6 @@
 
 void killconfig(void)
 {
-    w1_therm		*tmp1;
     units_list		*tmp2;
     profiles_list	*tmp3;
     prof_step		*tmp4;
@@ -53,16 +52,6 @@
 	free(Config.name);
     Config.name = NULL;
 
-    for (tmp1 = Config.w1therms; tmp1; tmp1 = 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;
     Config.my_port = 6554;
     Config.tempFormat = 'C';
     if (Config.air_address)
@@ -131,7 +120,6 @@
     FILE		*fp;
     xmlTextWriterPtr	writer;
     xmlBufferPtr	buf;
-    w1_therm    	*tmp1;
     units_list		*tmp3;
     profiles_list	*tmp4;
     prof_step		*tmp5;
@@ -259,50 +247,6 @@
 #endif
 
     /*
-     * For backwards compatibility, the old setup
-     */
-    if (Config.w1therms) {
-	if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "W1THERMS")) < 0) {
-	    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
-	    return 1;
-	}
-	for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
-	    if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "W1THERM")) < 0) {
-		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
-		return 1;
-	    }
-	    if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) {
-		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
-		return 1;
-	    }
-	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASTER", "%s", tmp1->master)) < 0) {
-		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
-		return 1;
-	    }
-	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BUS", "%d", tmp1->bus)) < 0) {
-		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
-		return 1;
-	    }
-	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", tmp1->name)) < 0) {
-		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
-		return 1;
-	    }
-	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ALIAS", "%s", tmp1->alias)) < 0) {
-		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
-		return 1;
-	    }
-	    if ((rc = xmlTextWriterEndElement(writer)) < 0) {
-		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
-		return 1;
-	    }
-	}
-	if ((rc = xmlTextWriterEndElement(writer)) < 0) {
-	    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
-	    return 1;
-	}
-    }
-
-    /*
      * Fermenter units
      */
     if (Config.units) {
@@ -676,75 +620,6 @@
 
 
 
-int parseW1therm(xmlDocPtr doc, xmlNodePtr cur)
-{
-    xmlChar     *key;
-    int         ival;
-    w1_therm	*w1therm, *tmp;
-
-    w1therm = (w1_therm *)malloc(sizeof(w1_therm));
-    w1therm->next = NULL;
-    w1therm->master = w1therm->name = w1therm->alias = NULL;
-    w1therm->bus = w1therm->present = w1therm->lastval = w1therm->update = 0;
-
-    cur = cur->xmlChildrenNode;
-    while (cur != NULL) {
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (xmlStrcmp(key, (const xmlChar *)"1")) {
-		xmlFree(key);
-		return 1;
-	    }
-	    xmlFree(key);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASTER"))) {
-	    w1therm->master = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"BUS"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (sscanf((const char *)key, "%d", &ival) == 1)
-		w1therm->bus = ival;
-	    xmlFree(key);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
-	    w1therm->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"ALIAS"))) {
-	    w1therm->alias = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	}
-	cur = cur->next;
-    }
-
-    if (Config.w1therms == NULL) {
-	Config.w1therms = w1therm;
-    } else {
-	for (tmp = Config.w1therms; tmp; tmp = tmp->next) {
-	    if (tmp->next == NULL) {
-		tmp->next = w1therm;
-		break;
-	    }
-	}
-    }
-
-    return 0;
-}
-
-
-
-int parseW1therms(xmlDocPtr doc, xmlNodePtr cur)
-{
-    cur = cur->xmlChildrenNode;
-    while (cur != NULL) {
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"W1THERM"))) {
-	    parseW1therm(doc, cur);
-	}
-	cur = cur->next;
-    }
-    return 0;
-}
-
-
-
 /*
  * Parse a fermenter unit
  */
@@ -1307,9 +1182,6 @@
 	    parseLCDs(doc, cur);
 	}
 #endif
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"W1THERMS"))) {
-	    parseW1therms(doc, cur);
-	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTERS"))) {
 	    parseFermenters(doc, cur);
 	}
--- a/thermferm/sensors.c	Thu Jul 31 23:39:11 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2014
- *   
- * Michiel Broek <mbroek at mbse dot eu>
- *
- * This file is part of the mbsePi-apps
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * mbsePi-apps 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
- * General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with EC-65K; see the file COPYING.  If not, write to the Free
- * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- *****************************************************************************/
-
-#include "sensors.h"
-#include "thermferm.h"
-#include "xutil.h"
-
-
-extern int		debug;
-extern sys_config	Config;
-extern int		my_shutdown;
-
-
-#ifdef HAVE_WIRINGPI_H
-PI_THREAD (my_sensors_loop)
-#else
-void *my_sensors_loop(void *threadid)
-#endif
-{
-    w1_therm		*tmp1, *old1;
-    char		*device, line[60], *p = NULL;
-    FILE		*fp;
-    int			temp, rc, deviation;
-
-    syslog(LOG_NOTICE, "Thread my_sensors_loop started");
-    if (debug)
-	fprintf(stdout, "Thread my_sensors_loop started\n");
-
-    /*
-     * Loop forever until the external shutdown variable is set.
-     */
-    for (;;) {
-
-    	/*
-    	 * Here send our 1-wire sensors values
-    	 */
-    	for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
-	    old1 = tmp1->next;
-
-	    if (my_shutdown) {
-		syslog(LOG_NOTICE, "Thread my_sensors_loop stopped");
-		if (debug)
-		    fprintf(stdout, "Thread my_sensors_loop stopped\n");
-	    	return 0;
-	    }
-
-	    /*
-	     * Build path to the on-wire sensor
-	     */
-	    device = xstrcpy((char *)"/sys/bus/w1/devices/");
-	    device = xstrcat(device, tmp1->master);
-	    device = xstrcat(device, (char *)"/");
-	    device = xstrcat(device, tmp1->name);
-	    device = xstrcat(device, (char *)"/w1_slave");
-
-	    /*
-	     * Read sensor data
-	     */
-	    if ((fp = fopen(device, "r"))) {
-		/*
-		 * The output looks like:
-		 * 72 01 4b 46 7f ff 0e 10 57 : crc=57 YES
-		 * 72 01 4b 46 7f ff 0e 10 57 t=23125
-		 */
-		fgets(line, 50, fp);
-		line[strlen(line)-1] = '\0';
-		if ((line[36] == 'Y') && (line[37] == 'E')) {
-		    /*
-		     * CRC is Ok, continue
-		     */
-		    fgets(line, 50, fp);
-		    line[strlen(line)-1] = '\0';
-		    strtok(line, (char *)"=");
-		    p = strtok(NULL, (char *)"=");
-		    rc = sscanf(p, "%d", &temp);
-		    if ((rc == 1) && (tmp1->lastval != temp)) {
-			/*
-			 * It is possible to have read errors or extreme values.
-			 * This can happen with bad connections so we compare the
-			 * value with the previous one. If the difference is too
-			 * much, we don't send that value. That also means that if
-			 * the next value is ok again, it will be marked invalid too.
-			 * Maximum error is 20 degrees for now.
-			 */
-			deviation = 20000;
-			if ( (tmp1->lastval == 0) ||
-			     (tmp1->lastval && (temp > (tmp1->lastval - deviation)) && (temp < (tmp1->lastval + deviation))) ) {
-			    /*
-			     * Temperature is changed and valid, set flag.
-			     */
-			    tmp1->update = TRUE;
-			} else {
-			    syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, tmp1->lastval, temp);
-			    if (debug) {
-				fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, tmp1->lastval, temp);
-			    }
-			}
-			tmp1->lastval = temp;
-		    }
-		} else {
-		    syslog(LOG_NOTICE, "sensor %s/%s CRC error", tmp1->master, tmp1->name);
-		}
-		fclose(fp);
-		tmp1->present = 1;
-	    } else {
-		tmp1->present = 0;
-		if (debug)
-		    printf("sensor %s is missing\n", tmp1->name);
-	    }
-
-	    free(device);
-	    device = NULL;
-    	}
-	usleep(10000);
-    }
-}
-
-
-
--- a/thermferm/sensors.h	Thu Jul 31 23:39:11 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-#ifndef SENSORS_H
-#define	SENSORS_H
-
-
-#ifdef HAVE_WIRINGPI_H
-PI_THREAD (my_sensors_loop);
-#else
-void *my_sensors_loop(void *);
-#endif
-
-#endif
--- a/thermferm/thermferm.c	Thu Jul 31 23:39:11 2014 +0200
+++ b/thermferm/thermferm.c	Thu Jul 31 23:57:04 2014 +0200
@@ -23,7 +23,6 @@
 #include "lock.h"
 #include "logger.h"
 #include "rdconfig.h"
-#include "sensors.h"
 #include "devices.h"
 #include "server.h"
 #include "thermferm.h"
@@ -231,7 +230,6 @@
 {
     char                buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40];
     time_t		now, last = (time_t)0;
-    w1_therm		*tmp1;
     units_list		*unit;
     int			rc, run = 1, seconds = 0;
 #ifdef HAVE_WIRINGPI_H
@@ -269,20 +267,6 @@
     }
 
 #ifdef HAVE_WIRINGPI_H
-    rc = piThreadCreate(my_sensors_loop);
-#else
-    rc = pthread_create(&threads[t], NULL, my_sensors_loop, (void *)t );
-#endif
-    if (rc) {
-	fprintf(stderr, "my_sensors_loop thread didn't start rc=%d\n", rc);
-	syslog(LOG_NOTICE, "my_sensors_loop thread didn't start rc=%d", rc);
-#ifndef HAVE_WIRINGPI_H
-    } else {
-	t++;
-#endif
-    }
-
-#ifdef HAVE_WIRINGPI_H
     rc = piThreadCreate(my_server_loop);
 #else
     rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t );
@@ -322,18 +306,9 @@
     }
 
     do {
-	lcdupdate = FALSE;
-
 	if (my_shutdown)
 	    run = 0;
 
-	for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
-	    if (tmp1->update) {
-	    	tmp1->update = FALSE;
-	    	lcdupdate = TRUE;
-	    }
-	}
-
 	/*
 	 * Timed schedulers
 	 */
--- a/thermferm/thermferm.h	Thu Jul 31 23:39:11 2014 +0200
+++ b/thermferm/thermferm.h	Thu Jul 31 23:57:04 2014 +0200
@@ -170,16 +170,6 @@
 #define	DEVDIR_OUT_PWM		5		/* PWM outout			*/
 #define	DEVDIR_INTERN		6		/* Internal function		*/
 
-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             */
-    int			update;			/* Value updated		*/
-} w1_therm;
 
 typedef struct _sys_config {
     char		*name;			/* Configuration name		*/
@@ -188,7 +178,6 @@
     char		*air_address;		/* 1-wire environment sensor	*/
     int			air_state;		/* 0=ok, 1=missing, 2=error	*/
     int			air_temperature;	/* Air temperature in C * 1000	*/
-    w1_therm		*w1therms;		/* 1-wire temp sensors		*/
 #ifdef HAVE_WIRINGPI_H
     int			lcd_cols;		/* LCD display columns		*/
     int			lcd_rows;		/* LCD display rows		*/

mercurial