www-thermferm/devices.php

changeset 196
4d7a96c5d1ff
parent 174
244de612c572
child 209
c5b1dfd83e81
--- a/www-thermferm/devices.php	Fri Aug 08 23:07:44 2014 +0200
+++ b/www-thermferm/devices.php	Sat Aug 09 11:29:02 2014 +0200
@@ -23,26 +23,10 @@
 
 require_once('utilities.php');
 
-
-$sock = open_socket();
-if ($sock == false) {
-    echo "";
-    return;
-}
-
-socket_write($sock, "DEVICE LIST", 4096);
-$answer = "";
-while (1) {
-    $line = socket_read($sock, 4096);
-    if ($line === '')
-	break;
-    $answer .= $line;
-}
-socket_close($sock);
-
 /*
  * $arr contains the complete reply of the LIST BUS command
  */
+$answer = send_cmd("DEVICE LIST");
 $arr = explode("\r\n", $answer);
 
 
@@ -124,17 +108,7 @@
      * Build the update command
      */
     if ($_POST['key'] == 'Delete') {
-	$sock = open_socket();
-	if ($sock != false) {
-	    socket_write($sock, "DEVICE DEL ".$_POST['UUID'], 4096);
-	    /* Absorb response */
-	    while (1) {
-		$line = socket_read($sock, 4096);
-		if ($line === '')
-		    break;
-	    }
-	    socket_close($sock);
-	}
+	send_cmd("DEVICE DEL ".$_POST['UUID']);
     }
 
     if ($_POST['key'] == 'Save') {
@@ -310,20 +284,7 @@
  */
 function edit_screen($UUID, $command, $heading, $error_message) {
 
-    $sock = open_socket();
-    if ($sock == false) {
-	load('devices.php');
-    }
-
-    socket_write($sock, "DEVICE GET ".$UUID, 4096);
-    $answer = "";
-    while (1) {
-	$line = socket_read($sock, 4096);
-	if ($line === '')
-	    break;
-	$answer .= $line;
-    }
-    socket_close($sock);
+    $answer = send_cmd("DEVICE GET ".$UUID);
     $reply = explode("\r\n", $answer);
 
     $outstr  = build_header($heading);

mercurial