LIST BUS now displays the new devices table. Adjusted the web screen

Thu, 31 Jul 2014 22:15:22 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 31 Jul 2014 22:15:22 +0200
changeset 163
3d813570a5e3
parent 162
6fc9e3f7962f
child 164
f16def8472ba

LIST BUS now displays the new devices table. Adjusted the web screen

thermferm/devices.c file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
www-thermferm/devices.php file | annotate | diff | comparison | revisions
--- a/thermferm/devices.c	Thu Jul 31 21:04:06 2014 +0200
+++ b/thermferm/devices.c	Thu Jul 31 22:15:22 2014 +0200
@@ -150,8 +150,7 @@
 	    	ndev->type = DEVTYPE_GPIO;
 	    	ndev->value = digitalRead(pin);
 	    	ndev->present = DEVPRESENT_YES;
-	    	snprintf(buf, 39, "GPIO%d", i);
-	    	ndev->address = xstrcpy(buf);
+	    	ndev->address = xstrcpy((char *)"GPIO");
 	    	snprintf(buf, 39, "Raspberry GPIO %d", i);
 	    	ndev->description = xstrcpy(buf);
 	    	ndev->subdevice = i;
--- a/thermferm/server.c	Thu Jul 31 21:04:06 2014 +0200
+++ b/thermferm/server.c	Thu Jul 31 22:15:22 2014 +0200
@@ -348,10 +348,9 @@
     units_list		*unit;
     profiles_list	*profile;
     prof_step		*step;
-    int			j, ref;
-    DIR			*fd;
+    devices_list	*device;
+    int			j;
     FILE		*fp;
-    struct dirent	*de;
 
     opt = strtok(buf, " \0");
     opt = strtok(NULL, "\0");
@@ -369,63 +368,14 @@
 
     } else if (strcmp(opt, (char *)"BUS") == 0) {
 	/*
-	 * 1-wire bus
+	 * Bus devices
 	 */
-	if ((fd = opendir((char *)"/sys/bus/w1/devices"))) {
-	    srv_send((char *)"212 1-wire bus devices:");
-	    while ((de = readdir(fd))) {
-		if (de->d_name[0] != '.') {
-		    ref = 0;
-		    if (strncmp(de->d_name, (char *)"w1", 2) == 0) {
-			srv_send((char *)"%s,0,NA,System device", de->d_name);
-		    } else if (strncmp(de->d_name, (char *)"10", 2) == 0) {
-			if (Config.air_address && (strcmp(de->d_name, Config.air_address) == 0))
-			    ref++;
-			for (unit = Config.units; unit; unit = unit->next) {
-			    if (unit->air_address && (strcmp(de->d_name, unit->air_address) == 0))
-				ref++;
-			    if (unit->beer_address && (strcmp(de->d_name, unit->beer_address) == 0))
-				ref++;
-			}
-			srv_send((char *)"%s,%d,18S20,Digital thermometer", de->d_name, ref);
-		    } else if (strncmp(de->d_name, (char *)"28", 2) == 0) {
-			if (Config.air_address && (strcmp(de->d_name, Config.air_address) == 0))
-			    ref++;
-			for (unit = Config.units; unit; unit = unit->next) {
-			    if (unit->air_address && (strcmp(de->d_name, unit->air_address) == 0))
-				ref++;
-			    if (unit->beer_address && (strcmp(de->d_name, unit->beer_address) == 0))
-				ref++;
-			}
-			srv_send((char *)"%s,%d,18B20,Digital thermometer", de->d_name, ref);
-		    } else if (strncmp(de->d_name, (char *)"29", 2) == 0) {
-			for (unit = Config.units; unit; unit = unit->next) {
-			    if (unit->io1_address && (strncmp((char *)"29", unit->io1_address, 2) == 0))
-				ref++;
-			    if (unit->io2_address && (strncmp((char *)"29", unit->io2_address, 2) == 0))
-				ref++;
-			}
-			srv_send((char *)"%s,%d,2408,8 Channel addressable switch/LCD", de->d_name, ref);
-		    } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) {
-			for (unit = Config.units; unit; unit = unit->next) {
-			    if (unit->io1_address && (strncmp((char *)"3a", unit->io1_address, 2) == 0))
-				ref++;
-			    if (unit->io2_address && (strncmp((char *)"3a", unit->io2_address, 2) == 0))
-				ref++;
-			}
-			srv_send((char *)"%s,%d,2413,Dual channel addressable switch", de->d_name, ref);
-		    } else {
-			srv_send((char *)"%s,0,NA,Unknown device", de->d_name);
-		    }
-		}
-	    }
-	    srv_send((char *)".");
-	    closedir(fd);
-	    return 0;
-	} else {
-	    srv_send((char *)"503 directory /sys/bus/w1/devices: %s", strerror(errno));
-	    return 1;
+	srv_send((char *)"212 bus devices:");
+	for (device = Config.devices; device; device = device->next) {
+	    srv_send((char *)"%s,%s,%d,%d,%s", device->uuid, device->address, device->subdevice, device->inuse, device->comment);
 	}
+	srv_send((char *)".");
+	return 0;
 
     } else if (strcmp(opt, (char *)"LOG") == 0) {
 	/*
--- a/www-thermferm/devices.php	Thu Jul 31 21:04:06 2014 +0200
+++ b/www-thermferm/devices.php	Thu Jul 31 22:15:22 2014 +0200
@@ -64,7 +64,13 @@
 $outstr .= '    <div id="etable">'.PHP_EOL;
 
 $outstr .= '     <table class="setup">'.PHP_EOL;
-$outstr .= '      <tr class="trhead"><td class="setup">Address</td><td class="setup">Refcnt</td><td class="setup">Chip</td><td class="setup">Description</td></tr>'.PHP_EOL;
+$outstr .= '      <tr class="trhead">'.PHP_EOL;
+$outstr .= '       <td class="setup">UUID</td>'.PHP_EOL;
+$outstr .= '       <td class="setup">Address</td>'.PHP_EOL;
+$outstr .= '       <td class="setup">Subdev</td>'.PHP_EOL;
+$outstr .= '       <td class="setup">Refcnt</td>'.PHP_EOL;
+$outstr .= '       <td class="setup">Comment</td>'.PHP_EOL;
+$outstr .= '      </tr>'.PHP_EOL;
 
 if (startsWith($arr[0], "212")) {
     $j = 1;
@@ -72,7 +78,13 @@
 	if (strcmp($arr[$j], ".") == 0)
 	    break;
 	$f = explode(",", $arr[$j]);
-	$outstr .= '      <tr class="setup"><td class="setup">'.$f[0].'</td><td class="setup">'.$f[1].'</td><td class="setup">'.$f[2].'</td><td class="setup">'.$f[3].'</td></tr>'.PHP_EOL;
+	$outstr .= '      <tr class="setup">'.PHP_EOL;
+	$outstr .= '       <td class="setup">'.$f[0].'</td>'.PHP_EOL;
+	$outstr .= '       <td class="setup">'.$f[1].'</td>'.PHP_EOL;
+	$outstr .= '       <td class="setup">'.$f[2].'</td>'.PHP_EOL;
+	$outstr .= '       <td class="setup">'.$f[3].'</td>'.PHP_EOL;
+	$outstr .= '       <td class="setup">'.$f[4].'</td>'.PHP_EOL;
+	$outstr .= '      </tr>'.PHP_EOL;
 	$j++;
     }
 }

mercurial