diff -r 244de612c572 -r b73490398368 www-thermferm/units.php --- a/www-thermferm/units.php Sat Aug 02 22:33:15 2014 +0200 +++ b/www-thermferm/units.php Sun Aug 03 22:49:33 2014 +0200 @@ -29,7 +29,7 @@ load('index.php'); } -socket_write($sock, "LIST", 4096); +socket_write($sock, "UNIT LIST", 4096); $answer = ""; while (1) { $line = socket_read($sock, 4096); @@ -76,7 +76,7 @@ if ($_POST['key'] == 'Add') { - $cmd = "ADD UNIT ".$_POST['Name']; + $cmd = "UNIT ADD ".$_POST['Name']; $sock = open_socket(); if ($sock != false) { @@ -113,17 +113,11 @@ /* * Build the update command */ - if ($_POST['key'] == 'Delete') - $update_cmd = "DEL UNIT ".$_POST['UUID']; - else - $update_cmd = "XXXXXXX ".$_POST['UUID'].",".$_POST['Name']; - + if ($_POST['key'] == 'Delete') { $sock = open_socket(); if ($sock != false) { - /* - * Send command and absorb the result. - */ - socket_write($sock, $update_cmd, 4096); + socket_write($sock, "UNIT DEL ".$_POST['UUID'], 4096); + /* Absorb response */ while (1) { $line = socket_read($sock, 4096); if ($line === '') @@ -131,9 +125,54 @@ } socket_close($sock); } + } + + if ($_POST['key'] == 'Save') { + $sock = open_socket(); + if ($sock != false) { + /* + * Send command and absorb the result. + */ + socket_write($sock, "UNIT PUT ".$_POST['UUID'], 4096); + usleep(20000); + socket_write($sock, "NAME,".$_POST['Name'], 4096); + usleep(20000); + socket_write($sock, "VOLUME,".$_POST['Volume'], 4096); + usleep(20000); + socket_write($sock, "AIR_ADDRESS,".$_POST['AirAddress'], 4096); + usleep(20000); + socket_write($sock, "BEER_ADDRESS,".$_POST['BeerAddress'], 4096); + usleep(20000); + socket_write($sock, "HEATER_ADDRESS,".$_POST['HeaterAddress'], 4096); + usleep(20000); + socket_write($sock, "COOLER_ADDRESS,".$_POST['CoolerAddress'], 4096); + usleep(20000); + socket_write($sock, "FAN_ADDRESS,".$_POST['FanAddress'], 4096); + usleep(20000); + socket_write($sock, "DOOR_ADDRESS,".$_POST['DoorAddress'], 4096); + usleep(20000); + socket_write($sock, "TEMP_SET_MIN,".$_POST['TempSetMin'], 4096); + usleep(20000); + socket_write($sock, "TEMP_SET_MAX,".$_POST['TempSetMax'], 4096); + usleep(20000); + socket_write($sock, "IDLE_RANGE_L,".$_POST['IdleRangeL'], 4096); + usleep(20000); + socket_write($sock, "IDLE_RANGE_H,".$_POST['IdleRangeH'], 4096); + usleep(20000); + + socket_write($sock, ".", 4096); + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + } + } unset($_POST['UUID']); unset($_POST['Name']); + unset($_POST['Volume']); unset($_POST['key']); unset($_POST['command']); load('units.php'); @@ -159,7 +198,10 @@ global $arr; - if (isset($_POST['UUID']) && isset($_POST['Name']) && isset($_POST['key']) && isset($_POST['command'])) { + if (isset($_POST['UUID']) && isset($_POST['Name']) && isset($_POST['Volume']) && isset($_POST['AirAddress']) && + isset($_POST['BeerAddress']) && isset($_POST['HeaterAddress']) && isset($_POST['CoolerAddress']) && + isset($_POST['FanAddress']) && isset($_POST['DoorAddress']) && isset($_POST['TempSetMin']) && isset($_POST['TempSetMax']) && + isset($_POST['IdleRangeL']) && isset($_POST['IdleRangeH']) && isset($_POST['key']) && isset($_POST['command'])) { if ($_POST['key'] == 'Cancel') return 99; @@ -223,7 +265,7 @@ $heading = 'ThermFerm - Edit Unit'; } - edit_screen($_POST['UUID'], $_POST['Name'], $_POST['command'], $heading, $error); + edit_screen($_POST['UUID'], $_POST['command'], $heading, $error); } @@ -232,12 +274,51 @@ * Unit edit screen. Used by unit_edit(), unit_add() and testdata() * * @param string $UUID The record UUID (fixed). - * @param string $Name The Unit Name. * @param string $command 'add' or 'update' * @param string $heading Page heading title. * @Param string $error_message Blank or previous error. */ -function edit_screen($UUID, $Name, $command, $heading, $error_message) { +function edit_screen($UUID, $command, $heading, $error_message) { + + /* + * Get list of devices, we need it later + */ + $sock = open_socket(); + if ($sock == false) { + load("units.php"); + return; + } + + socket_write($sock, "DEVICE LIST", 4096); + $answer = ""; + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + $answer .= $line; + } + socket_close($sock); + $devices = explode("\r\n", $answer); + + /* + * Get current unit data + */ + $sock = open_socket(); + if ($sock == false) { + load("units.php"); + return; + } + + socket_write($sock, "UNIT GET ".$UUID, 4096); + $answer = ""; + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + $answer .= $line; + } + socket_close($sock); + $reply = explode("\r\n", $answer); $outstr = build_header($heading); $outstr .= '
'.PHP_EOL; @@ -246,14 +327,179 @@ $outstr .= '
'.PHP_EOL; $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; + + if (startsWith($reply[0], "213")) { + $i = 1; + while (1) { + if (strcmp($reply[$i], ".") == 0) + break; + $f = explode(",", $reply[$i]); + + if ($f[0] == "NAME") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "VOLUME") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "AIR_ADDRESS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "BEER_ADDRESS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "HEATER_ADDRESS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "COOLER_ADDRESS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "FAN_ADDRESS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "DOOR_ADDRESS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "TEMP_SET_MIN") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "TEMP_SET_MAX") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "IDLE_RANGE_L") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "IDLE_RANGE_H") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + $i++; + } + } $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; + $outstr .= ''; $outstr .= ''; $outstr .= ''; $outstr .= '';
UUID'.$UUID.'
Unit Name
Unit Name
Unit Volume
Air Sensor Address
Beer Sensor Address
Heater Switch Address
Cooler Switch Address
Fan Switch Address
Door Sensor Address
Min. temp setting
Max. temp setting
Idle Range Low
Idle Range High
'; @@ -278,27 +524,9 @@ * @param string $_GET['UUID'] The UUID of the Unit. */ function unit_edit() { - - global $arr; - if ($_GET['action'] == 'edit') { - - if (startsWith($arr[0], "212")) { - $j = 1; - while (1) { - if (strcmp($arr[$j], ".") == 0) - break; - $f = explode(",", $arr[$j]); - if (strcmp($f[0], $_GET['UUID']) == 0) { - edit_screen($f[0], $f[1], 'update', 'ThermFerm - Edit Unit', ''); - return; - } - $j++; - } - } else { - load('units.php'); - } - + edit_screen($_GET['UUID'], 'update', 'ThermFerm - Edit Unit', ''); + return; } else { load('units.php'); } @@ -357,6 +585,7 @@ $outstr .= ' Unit Name