Code cleanup

Tue, 29 Jul 2014 21:05:40 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 29 Jul 2014 21:05:40 +0200
changeset 145
1396350141cf
parent 144
3446371e0bdb
child 146
11f431ac253d

Code cleanup

thermometers/rdconfig.c file | annotate | diff | comparison | revisions
thermometers/thermometers.c file | annotate | diff | comparison | revisions
thermometers/thermometers.h file | annotate | diff | comparison | revisions
--- a/thermometers/rdconfig.c	Tue Jul 29 20:42:02 2014 +0200
+++ b/thermometers/rdconfig.c	Tue Jul 29 21:05:40 2014 +0200
@@ -33,12 +33,9 @@
 
 static int getw1(char **);
 #ifdef HAVE_WIRINGPI_H
-static int getstr(char **);
 static int getint(char **);
 static int getrcs(char **);
 #endif
-//static int getbyt(char **);
-//static int gethex(char **);
 
 #define XSTR(x) #x
 #define STR(x) XSTR(x)
@@ -193,17 +190,6 @@
 
 
 #ifdef HAVE_WIRINGPI_H
-static int getstr(char **dest)
-{
-    if (debug)
-	syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
-
-    *dest = xstrcpy(v);
-    return 0;
-}
-
-
-
 static int getint(char **dest)
 {
     if (debug)
--- a/thermometers/thermometers.c	Tue Jul 29 20:42:02 2014 +0200
+++ b/thermometers/thermometers.c	Tue Jul 29 21:05:40 2014 +0200
@@ -109,7 +109,7 @@
 
     if (rdconfig((char *)"thermometers.conf")) {
 	fprintf(stderr, "Error reading configuration\n");
-	syslog(LOG_NOTICE, "halted");
+	syslog(LOG_NOTICE, "Error reading configuration, halted");
 	return 1;
     }
 
@@ -208,29 +208,15 @@
 
 int server(void)
 {
-    char                hostname[256], buf[1024];
-    int                 temp, rc = 0, deviation;
+    char                buf[1024];
+    int                 temp, rc = 0;
 #ifdef HAVE_WIRINGPI_H
     int			lcdupdate;
 #endif
-    w1_therm		*tmp1, *old1;
-    char		*device, *alias, line[60], *p = NULL;
+    w1_therm		*tmp1;
+    char		*device, line[60], *p = NULL;
     FILE		*fp;
 
-    /*
-     * Build MQTT id
-     */
-    hostname[0] = '\0';
-    gethostname(hostname, 256);
-    hostname[255] = '\0';
-
-    /*
-     * Initialise is complete, report our presence state
-     */
-#ifdef HAVE_WIRINGPI_H
-//    setBacklight(0);
-#endif
-
     if (debug)
 	fprintf(stdout, (char *)"Enter loop\n");
 
@@ -242,8 +228,7 @@
 	    /*
 	     * Here send our 1-wire sensors values
 	     */
-	    for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
-		old1 = tmp1->next;
+	    for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
 
 		/*
 		 * Build path and alias topic
@@ -253,13 +238,6 @@
 		device = xstrcat(device, (char *)"/");
 		device = xstrcat(device, tmp1->name);
 		device = xstrcat(device, (char *)"/w1_slave");
-		alias = xstrcpy((char *)"/raw/");
-		alias = xstrcat(alias, hostname);
-		alias = xstrcat(alias, (char *)"/thermometers/w1/");
-		alias = xstrcat(alias, tmp1->master);
-		alias = xstrcat(alias, (char *)"/");
-		alias = xstrcat(alias, tmp1->name);
-		alias = xstrcat(alias, (char *)"/temperature");
 
 		/*
 		 * Read sensor data
@@ -282,27 +260,6 @@
 			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, update and publish this.
-			    	 */
-			    	sprintf(buf, "%.1f", temp / 1000.0);
-			    } 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;
 #ifdef HAVE_WIRINGPI_H
 			    lcdupdate = TRUE;
@@ -321,8 +278,6 @@
 
 		free(device);
 		device = NULL;
-		free(alias);
-		alias = NULL;
 	    }
 
 #ifdef HAVE_WIRINGPI_H
@@ -331,8 +286,7 @@
 		tmp1 = Config.w1therms;
 		snprintf(buf, 16, "%5.1f %cC %s            ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
 		lcdPuts(lcdHandle, buf);
-		old1 = tmp1->next;
-		tmp1 = old1;
+		tmp1 = tmp1->next;
 		lcdPosition(lcdHandle, 0, 1);
 		snprintf(buf, 16, "%5.1f %cC %s            ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
 		lcdPuts(lcdHandle, buf);
--- a/thermometers/thermometers.h	Tue Jul 29 20:42:02 2014 +0200
+++ b/thermometers/thermometers.h	Tue Jul 29 21:05:40 2014 +0200
@@ -116,34 +116,6 @@
 void mb_lcdClear(const int);
 
 
-/* logger.c */
-void logger(char *, char *, char *);
-
-
-/* rc-switch.c */
-int  toggleSwitch(char *);
-int  toggleTypeA(char *, char *, bool);
-int  toggleTypeB(int, int, bool);
-int  toggleTypeC(char, int, int, bool);
-int  toggleTypeE(char, int, bool);
-
-void enableReceiveIRQ(int interrupt);
-void enableReceive(void);
-void disableReceive(void);
-bool available(void);
-void resetAvailable(void);
-
-unsigned long getReceivedValue(void);
-unsigned int getReceivedBitlength(void);
-unsigned int getReceivedDelay(void);
-unsigned int getReceivedProtocol(void);
-unsigned int *getReceivedRawdata(void);
-
-void enableTransmit(int);
-void disableTransmit(void);
-
-char *dec2binWzerofill(unsigned long, unsigned int);
-
 
 #endif
 

mercurial