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 .= '