Added maintenance tabs and extended server output

Wed, 23 Jul 2014 16:49:37 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 23 Jul 2014 16:49:37 +0200
changeset 124
350401bac16e
parent 123
597688feda2f
child 125
94aea38d4da5

Added maintenance tabs and extended server output

thermferm/server.c file | annotate | diff | comparison | revisions
www-thermferm/getprofiles.php file | annotate | diff | comparison | revisions
www-thermferm/index.php file | annotate | diff | comparison | revisions
www-thermferm/liveview.php file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Tue Jul 22 23:14:19 2014 +0200
+++ b/thermferm/server.c	Wed Jul 23 16:49:37 2014 +0200
@@ -201,7 +201,8 @@
     char		*opt, *filename, *p, q[2], buffer[256];
     units_list		*unit;
     profiles_list	*profile;
-    int			i;
+    prof_step		*step;
+    int			i, j, ref;
     DIR			*fd;
     FILE		*fp;
     struct dirent	*de;
@@ -230,18 +231,47 @@
 	    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,N/A,System device", de->d_name);
+			srv_send((char *)"%s,0,NA,System device", de->d_name);
 		    } else if (strncmp(de->d_name, (char *)"10", 2) == 0) {
-			srv_send((char *)"%s,18S20,Digital thermometer", de->d_name);
+			if (Config.air_address && (strncmp((char *)"10", Config.air_address, 2) == 0))
+			    ref++;
+			for (unit = Config.units; unit; unit = unit->next) {
+			    if (unit->air_address && (strncmp((char *)"10", unit->air_address, 2) == 0))
+				ref++;
+			    if (unit->beer_address && (strncmp((char *)"10", unit->beer_address, 2) == 0))
+				ref++;
+			}
+			srv_send((char *)"%s,%d,18S20,Digital thermometer", ref, de->d_name);
 		    } else if (strncmp(de->d_name, (char *)"28", 2) == 0) {
-			srv_send((char *)"%s,18B20,Digital thermometer", de->d_name);
+			if (Config.air_address && (strncmp((char *)"28", Config.air_address, 2) == 0))
+			    ref++;
+			for (unit = Config.units; unit; unit = unit->next) {
+			    if (unit->air_address && (strncmp((char *)"28", unit->air_address, 2) == 0))
+				ref++;
+			    if (unit->beer_address && (strncmp((char *)"28", unit->beer_address, 2) == 0))
+				ref++;
+			}
+			srv_send((char *)"%s,%d,18B20,Digital thermometer", ref, de->d_name);
 		    } else if (strncmp(de->d_name, (char *)"29", 2) == 0) {
-			srv_send((char *)"%s,2408,8 Channel addressable switch/LCD", de->d_name);
+			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", ref, de->d_name);
 		    } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) {
-			srv_send((char *)"%s,2413,Dual channel addressable switchs", de->d_name);
+			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 switchs", ref, de->d_name);
 		    } else {
-			srv_send((char *)"%s,N/A,Unknown device", de->d_name);
+			srv_send((char *)"%s,0,NA,Unknown device", de->d_name);
 		    }
 		}
 	    }
@@ -305,7 +335,10 @@
 	i = 0;
 	for (profile = Config.profiles; profile; profile = profile->next) {
 	    i++;
-	    srv_send((char *)"%d,%s,%s", i, profile->uuid, profile->name);
+	    j = 0;
+	    for (step = profile->steps; step; step = step->next)
+		j++;
+	    srv_send((char *)"%d,%s,%s,%d", i, profile->uuid, profile->name, j);
 	}
 	srv_send((char *)".");
 	return 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www-thermferm/getprofiles.php	Wed Jul 23 16:49:37 2014 +0200
@@ -0,0 +1,64 @@
+<?php
+/*****************************************************************************
+ * Copyright (C) 2014
+ *   
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of ThermFerm
+ *
+ * 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.
+ *
+ * ThermFerm 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 ThermFerm; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+require_once('utilities.php');
+
+
+$sock = open_socket();
+if ($sock == false) {
+    echo "";
+    return;
+}
+
+socket_write($sock, "LIST PROFILES", 4096);
+$answer = "";
+while (1) {
+    $line = socket_read($sock, 4096);
+    if ($line === '')
+	break;
+    $answer .= $line;
+}
+socket_close($sock);
+$arr = explode("\r\n", $answer);
+
+
+$row = '[';
+
+/* We don't use json_encode because it doesn't work for our purpose */
+if (startsWith($arr[0], "212")) {
+    $j = 1;
+    while (1) {
+	if (strcmp($arr[$j], ".") == 0)
+		break;
+	if ($j > 1)
+	    $row .= ',';
+	$f = explode(",", $arr[$j]);
+	$row .= '{"Id":"'.$f[0].'","UUID":"'.$f[1].'","Name":"'.$f[2].'","Steps":"'.$f[3].'"}';
+	$j++;
+    }
+}
+
+$row .= ']';
+echo $row;
+
+?>
--- a/www-thermferm/index.php	Tue Jul 22 23:14:19 2014 +0200
+++ b/www-thermferm/index.php	Wed Jul 23 16:49:37 2014 +0200
@@ -60,10 +60,9 @@
 $outstr .= '         height: 400, width: 800, autoOpen: false, theme: \''.$my_style.'\', '.PHP_EOL;
 $outstr .= '         position: { x:100, y:50 }, '.PHP_EOL;
 $outstr .= '         resizable: false, isModal: true, modalOpacity: 0.5, '.PHP_EOL;
-$outstr .= '         okButton: $("#maintenance_ok"), cancelButton: $("#maintenance_cancel"),'.PHP_EOL;
+$outstr .= '         okButton: $("#maintenance_ok"), '.PHP_EOL;
 $outstr .= '         initContent: function () {'.PHP_EOL;
-$outstr .= '           $("#maintenance_ok").jqxButton({ width: 65, height: 25, theme: \''.$my_style.'\' });'.PHP_EOL;
-$outstr .= '           $("#maintenance_cancel").jqxButton({ width: 65, height: 25, theme: \''.$my_style.'\' });'.PHP_EOL;
+$outstr .= '           $("#maintenance_ok").jqxButton({ width: 70, height: 25, theme: \''.$my_style.'\' });'.PHP_EOL;
 $outstr .= '         }'.PHP_EOL;
 $outstr .= '       });'.PHP_EOL;
 $outstr .= '       $("#maintenance").jqxButton({ width: 150, height: 25, theme: \''.$my_style.'\'});'.PHP_EOL;
@@ -84,10 +83,33 @@
 $outstr .= '     Maintenance panel'.PHP_EOL;
 $outstr .= '    </div>'.PHP_EOL;
 $outstr .= '    <div id="maintenance_content">'.PHP_EOL;
-$outstr .= '     Maintenancecontent'.PHP_EOL;
-$outstr .= '     <input type="button" id="maintenance_ok" value="OK" style="margin-right: 10px" />'.PHP_EOL;
-$outstr .= '     <input type="button" id="maintenance_cancel" value="Cancel" />'.PHP_EOL;
+$outstr .= '     <div id="jqxTabs_maint">'.PHP_EOL;
+$outstr .= '      <ul>'.PHP_EOL;
+$outstr .= '       <li style="margin-left: 20px;">General</li>'.PHP_EOL;
+$outstr .= '       <li style="margin-left: 20px;">1-Wire Bus</li>'.PHP_EOL;
+$outstr .= '       <li style="margin-left: 20px;">Profiles</li>'.PHP_EOL;
+$outstr .= '       <li style="margin-left: 20px;">Units</li>'.PHP_EOL;
+$outstr .= '      </ul>'.PHP_EOL;
+$outstr .= '      <div>'.PHP_EOL;
+$outstr .= '       General'.PHP_EOL;
+$outstr .= '      </div>'.PHP_EOL;
+$outstr .= '      <div>'.PHP_EOL;
+$outstr .= '       1-Wire Bus'.PHP_EOL;
+$outstr .= '      </div>'.PHP_EOL;
+$outstr .= '      <div>'.PHP_EOL;
+$outstr .= '       Profiles'.PHP_EOL;
+$outstr .= '      </div>'.PHP_EOL;
+$outstr .= '      <div>'.PHP_EOL;
+$outstr .= '       Units'.PHP_EOL;
+$outstr .= '      </div>'.PHP_EOL;
+$outstr .= '     </div>'.PHP_EOL;
+$outstr .= '     <input type="button" id="maintenance_ok" value="Dismiss" style="margin-top: 5px; margin-left: 365px" />'.PHP_EOL;
 $outstr .= '    </div>'.PHP_EOL;
+$outstr .= '    <script type="text/javascript">'.PHP_EOL;
+$outstr .= '     $(document).ready(function () {'.PHP_EOL;
+$outstr .= '       $("#jqxTabs_maint").jqxTabs({ width: 790, height: 330, position: \'top\', theme: \''.$my_style.'\'});'.PHP_EOL;
+$outstr .= '     });'.PHP_EOL;
+$outstr .= '    </script>'.PHP_EOL;
 $outstr .= '   </div> <!-- maintenance_window -->'.PHP_EOL;
 
 /* Create the tabs */
--- a/www-thermferm/liveview.php	Tue Jul 22 23:14:19 2014 +0200
+++ b/www-thermferm/liveview.php	Wed Jul 23 16:49:37 2014 +0200
@@ -83,7 +83,7 @@
 	$outstr .= '             { name: \'Fan\' },'.PHP_EOL;
 	$outstr .= '             { name: \'Door\' }'.PHP_EOL;
 	$outstr .= '          ],'.PHP_EOL;
-	$outstr .= '          url: \'getlog.php?unit='.$unr.'\''.PHP_EOL;
+	$outstr .= '          url: \'getlog.php?unit='.$unit.'\''.PHP_EOL;
 	$outstr .= '       };'.PHP_EOL;
 
 	$outstr .= '       var dataAdapter'.$unr.' = new $.jqx.dataAdapter(source'.$unr.','.PHP_EOL;
@@ -291,7 +291,7 @@
 		if (strcmp($arr[$i], ".") == 0)
 			break;
 		$parts = explode(",", $arr[$i]);
-		$outstr .= '     <li style="margin-left: 30px;">'.$parts[2].'</li>'.PHP_EOL;
+		$outstr .= '     <li style="margin-left: 20px;">'.$parts[2].'</li>'.PHP_EOL;
 		$i++;
 	    }
 	}

mercurial