<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-15">
<title>Disch Systems&trade; -- Visualization Example of TP-UART Interface</title>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" type="text/css" href="/disch.css">
<link rel="shortcut icon" href="/favicon.ico">
</head>
<?php

//
// dps_requests.php
// (c) 2001 - 2007, 2009 - 2010 Uwe Disch, http://disch-systems.de
// Use only with TP-UART Interface!  Other usage illegal!
//
// This file is used to switch light and to show it's condition.
// Furthermore it shows the temperature of an EIB-Pt 100 temperature sensor.
// Additionally statistics are included.
//

//
// Caution: format of arrays has changed!  Please see legend to split function
//          later in this file.  This was done to have a one to one separation
//          between entries of an array.
//

//
// Definitions of group addresses:
// Group addresses are provided as slashed version, i.e. 1/2/2
// or in decimal representation, i.e. 2561
// The dps_requests is capable of handling both formats.
//
// Please change like your installation need it.
//
$L1SW=2562;       // 1/2/2 light (decimal)
$L1ST=2562;       // 1/2/2 .. its status (possibly another group address)
$SE1T="3/1/5";    // 3/1/5 temperature

//
// Calcualating the decimal values of group addresses
// A/B/C -> A*2048 + B*256 + C
// example: 1/2/1 -> 1*2048 + 2*256 + 1 = 2561
//
// A/B -> A*2048 + B
// example: 1/3  -> 1*2048 + 3 = 2051
//

//
// A/B/C group addresses are defined in this way:
// C is composed by the 8 lower bits
// B is composed by the 3 next bits
// A is composed by the 4 higher bits
//
// This would mean for A/B/C group addresse that:
// A can range from 0 ... 15
// B can range from 0 ... 7
// C can range from 0 ... 255
//

include ('definitions.php');

// First Update - ask all group addresses
if($thefirst!="no"):
    
// Params: RNB=read_non_buffered, ipddr_of_eibdriver, number_of_pairs, [pairs(group_address, eis_type)]
    //         RBU=read_buffered, ipddr_of_eibdriver, number_of_pairs, [pairs(group_address, eis_type)]
    //
    // sample for two group addresses:
    // $command="dps_requests RBU ". $ipaddr. " 2 ". $L1ST. " ". $EIS1. " ". $L2ST. " ". $EIS1;
    //
    // Reading buffered:    all data is coming from process image.  This is the
    //                      preferred way, because of reduced bus load.  Please
    //                      be sure that your EIB objects send a telegram when
    //                      they change status.  Otherwise use RNB.
    // Reading unbuffered:  all data is coming directly from the EIB.  Some-
    //                      times this will not work because of devices that
    //                      are not readable.
    //
    
    // Use this if you read only one group address
    //$command="dps_requests RBU ". $ipaddr. " 1 ". $L1ST. " ". $EIS1;
    // This here is for reading two group addresses, RNB used because EIB
    // object isn't sending a telegram
    
$command="dps_requests RBU ". $ipaddr. " 2 ". $L1ST. " ". $EIS1. " ". $SE1T. " ". $EIS5;

    unset(
$retarray); unset($status);
    
$the_call = exec($command, $retarray, $ret);
    
// status of each asked group address: 1=ON, 0=OFF, else(-1)=undefined
    
$status=$retarray[0];
    
// The returned array, if number_of_pairs > 1, is defined as:
    // "Every value (entry of an array) has a single space in front of it and
    //  a single space on the end of it".
    // This is resulting in double spaces between two values of an array,
    // i.e.: " 5.234000  6.789897  1  0 "
    // Split into array, if number_of_pairs > 1, if you are having only one
    // group addres, you don't need the splitting
    
$status=split("  ", $retarray[0]);

    
// set the icon of each object
    // if ($status == 1): for one object, $status[0], if number_of_pairs > 1
    
if ($status[0] == 1):
        
$L1Icon="./pics/on.gif";
    else:
        if (
$status[0] == 0):
            
$L1Icon="./pics/off.gif";
        else:
            
$L1Icon="./pics/undefined.gif";
        endif;
    endif;

    if (
$status[0] == 1):
        
$L1Text="ON";
    else:
        if (
$status[0] == 0):
            
$L1Text="OFF";
        else:
            
$L1Text="?";
        endif;
    endif;

    
$temperature = "$status[1]";
    
$temperature = $temperature * 100;    
    
$temperature = round($temperature) / 100;
else:
    
// Handle All Commands
    // toggle command of the switch
    // (on more group addresses work with 'switch-case')
    
if ($L1Icon=="./pics/off.gif"):
        
// Params: WRI=write, ipddr_of_eibdriver, number_of_tripples, [tripples(group_address, eis_type, value)]
        
$command="dps_requests WRI ". $ipaddr." 1 ". $L1SW. " ". $EIS1. " 1";
        
$the_call = exec($command, $retarray, $ret);
        
// 1=OK else(!=1)=ERROR (on more tripples the return codes of the
        // witten values separated by double space)
        
if ($retarray[0]==1): $L1Icon="./pics/on.gif";
        else:
$L1Icon="./pics/undefined.gif"; endif;
        if (
$retarray[0]==1): $L1Text="ON";
        else:
$L1Text="?"; endif;
    else:
        
$command="dps_requests WRI ". $ipaddr." 1 ". $L1SW. " ". $EIS1. " 0 ";

        
$the_call = exec($command, $retarray, $ret);
        if (
$retarray[0]==1): $L1Icon="./pics/off.gif";
        else:
$L1Icon="./pics/undefined.gif"; endif;
        if (
$retarray[0]==1): $L1Text="OFF";
        else:
$L1Text="?"; endif;
    endif;
endif;

unset(
$thefirst);

// ... and now update the HTML picture!

?>
<body>
<table style="border=:0; width:100%; height:100%; align:center; valign:middle; cellspacing:0; cellpadding:0">
  <tr>
    <td valign="middle">
    <center>
        <br>
        &nbsp;
        <form action="dps_requests.php" method="post" name="form1">
            <input type=hidden name="thefirst" value="no">
            <input type=hidden name="L1Icon" value="<?php echo($L1Icon); ?>">
            <input type=hidden name="temperature" value="<?php echo($temperature); ?>">
            <!-- Show light condition as picture and in 'alt' respectively 'title' as text -->
            <img src="<?php echo($L1Icon); ?>"
                 alt="Light condition: <?php echo($L1Text); ?>"
                 title="Light condition: <?php echo($L1Text); ?>"
                 height="14" width="14">
            <br><br>
            <!-- Show the button to switch light -->
            <a href="javascript:document.form1.submit()"
               title="Switch light ON/OFF"
               onMouseover="window.status='Switch light ON/OFF'; return true;"
               onMouseout="window.status='Disch Systems&trade; -- Visualization Example of TP-UART Interface';
                   return true;"><img src="./pics/switch.gif" height="14" width="14" alt=""></a>
            <br><br>
            <small>
            <!-- Show light condition as text -->
            Light condition: <?php echo($L1Text); ?>
            <br>
            <!-- Show room temperature -->
            Room temperature: <?php echo($temperature); ?> &deg;C
            <br>
            <!-- Show statistics with 'uptime' -->
            Statistics: <?php
                $command
="uptime";
                unset(
$retarray); unset($status);
                
$the_call = exec($command, $retarray, $ret);
                
$status=split("m ", $retarray[0]);
                print (
$status[1]);
            
?>
            </small>
        </form>
        <br>
        &nbsp;
    </center>
    </td>
  </tr>
</table>
<form action="dps_requests.php" method="get" name="ReSubmitForm">
    <script type="text/javascript"><!--
        function ReSubmit(){document.ReSubmitForm.submit();} //-->
    </script>
    <noscript>
        You should enable JavaScript to have this page working properly.
    </noscript>
    <script type="text/javascript"><!--
        window.setTimeout("ReSubmit()",1000); //-->
    </script>
</form>
</body>
</html>