Skip to content

Commit

Permalink
Minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
fernadosilva committed Apr 29, 2016
1 parent 7e34b4e commit 4939586
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 17 deletions.
14 changes: 9 additions & 5 deletions lib/orvfms/orvfms.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,14 @@ function setTimer($mac,$h,$m,$s,$act,&$s20Table){
printHex($hexMsg);
print("Rec\n");
printHex($recHex);
print("RecAux\n");
printHex($recHexAux);
print("RecAux\n"); printHex($recHexAux);
}
if(($msgRecCode != "00") && ($recHexAux == $hexMsg))
return 0;
else
else{
printHex($recHex);
error_log("Retrying in setTimer\n");
}
}
return 1;
}
Expand Down Expand Up @@ -1183,8 +1184,11 @@ function readData($fileName){
$dir = TMP_DIR;
}
$fname = $dir."/".$fileName;
$data = array();
if(!file_exists($fname))
return $data;
$fp = fopen($fname,"r");
$data = NULL;

if($fp){
$line=fgets($fp);
fclose($fp);
Expand Down Expand Up @@ -1242,7 +1246,7 @@ function getIpFromMac($mac,&$s20Table){
$recIP = "";
$recPort = 0;
while ( 1 ){
$n=@socket_recvfrom($s,$binRecMsg,BUFFER_SIZE,0,$recIP,$recPort);
$n=socket_recvfrom($s,$binRecMsg,BUFFER_SIZE,0,$recIP,$recPort);
$now = time();
if(!isset($n) || ($n == 0)){
if(++$loopCount > 6) {
Expand Down
14 changes: 8 additions & 6 deletions lib/orvfms/process_sceneAct.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
function processSceneAct($sceneList,&$s20Table,$sceneName){
$actList = $sceneList[$sceneName];
foreach($actList as $mac => $macAction){
$seconds = $macAction['time']+1;
$action = $macAction['action'];
$s20Table[$mac]['timerVal']=$seconds;
$s20Table[$mac]['timerAction']=$action;
$_SESSION['s20Table'] = $s20Table;
setTimer($mac,0,0,$seconds,$action,$s20Table);
if(array_key_exists($mac,$s20Table)){
$seconds = $macAction['time']+1;
$action = $macAction['action'];
$s20Table[$mac]['timerVal']=$seconds;
$s20Table[$mac]['timerAction']=$action;
$_SESSION['s20Table'] = $s20Table;
setTimer($mac,0,0,$seconds,$action,$s20Table);
}
}
}
?>
20 changes: 16 additions & 4 deletions lib/orvfms/setup_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,30 @@ function displaySocketTime(){
$now = time();
$delta = $now - $inactiveTimeStamp;
$deltaString = secToHourString($delta);
$msg = "This device is inactive since ".$inactiveString;
$msg = "This device seems to be inactive <br>at least since ".$inactiveString;
$msg = $msg." (".$deltaString."s ago)<p>";
$msg = $msg."It did not reply to a re-activate command. Is it connected and on-line?<p>";
$msg =$msg."Last known name: ".$s20Table[$mac]['name'];
echo $msg;
?>
<hr>
<button type="submit" name="toMainPage" value="procSetupDel<?php echo $mac ?>" id="deleteButton">Delete device</button>
<p>
<p><p>
<hr><P>
<button type="submit" name="toMainPage" value="procSetupCancel<?php echo $mac ?>" id="cancelButton">Cancel</button>


<p>
<?php
if(substr($_POST[toSetupPage],0,4)=="wake"){
echo "Retry failed<p>";
?>
<button type="submit" name="toSetupPage" value="wake<?php echo $mac ?>" id="cancelButton">Retry again</button>
<?php
}
else{
?>
<button type="submit" name="toSetupPage" value="wake<?php echo $mac ?>" id="cancelButton">Retry</button>
<?php
}
}
?>
</form>
Expand Down
3 changes: 2 additions & 1 deletion lib/orvfms/timer_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function timerSettings(&$s20Table,$mac,$actionValue){
// Confirm
$s20Table[$mac]['timerVal'] = checkTimerSec($mac,$s20Table,$action);
$s20Table[$mac]['timerAction'] = $action;
if(($s20Table[$mac]['timerVal'] != $sec) ||
$dif = (abs($s20Table[$mac]['timerVal'] - $sec) > 1);
if($dif &&
($s20Table[$mac]['timerAction'] != $act)){
error_log("Unexpected inconsistency in timerSettings function: ".$mac." Set=(".$sec.",".$act.") Res=("
.$s20Table[$mac]['timerVal'].",".$s20Table[$mac]['timerAction'].")\n");
Expand Down
23 changes: 22 additions & 1 deletion s20/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,38 @@ function getMacAndActionFromPost(&$action,$postVal){
displayEditPage($mac,$editIndex,$s20Table,$myUrl);
}
else if(isset($_POST['toSetupPage'])){
$toSetup = 1;
$mac = getMacAndActionFromPost($actionValue,$_POST['toSetupPage']);
if($actionValue == "procSync"){ // Sync socket TZ to server TZ
$serverTz = $s20Table[$mac]['serverTimeZone'];
$serverDst = $s20Table[$mac]['serverDst'];
setTimeZone($mac,$serverTz,$serverDst,$s20Table);
}
elseif($actionValue=="wake"){
$ip = getIpFromMac($mac,$s20Table);
$s20Table[$mac]['lastOffCheck'] = time();
$_SESSION['s20Table'] = $s20Table;
if($ip!=0){
$s20Table[$mac]['ip'] = $ip;
$st = checkStatus($mac,$s20Table);
$_SESSION["s20Table"] = $s20Table;
if($st >= 0){
unset($s20Table[$mac]['off']);
$s20Table[$mac]['st'] = $st;
$_SESSION['s20Table'] = $s20Table;
require_once(ORVFMS_PATH."main_page.php");
displayMainPage($s20Table,$myUrl);
require_once(ORVFMS_PATH."main_page_scripts.php");
$toSetup = 0;
}
}
}
else if($actionValue != "setup"){
echo "Unexpected error in setup (505)<p>\n";
}
require_once(ORVFMS_PATH."setup_page.php");
displaySetupPage($mac,$s20Table,$myUrl);
if($toSetup)
displaySetupPage($mac,$s20Table,$myUrl);
}
else if(isset($_POST['toSceneList'])){
$sceneVal = $_POST['toSceneList'];
Expand Down

0 comments on commit 4939586

Please sign in to comment.