Example #1
0
function fetchstats($con, $addr, $age)
{
    $res = cacheread($con, $addr, $age);
    if ($res[1] == -1) {
        printf("EIBD not usable");
        return false;
    }
    if ($res[1] == -2) {
        printf("not readable");
        return false;
    }
    if ($res[1] == -3) {
        printf("unknown status");
        return false;
    }
    return array_slice($res, 2);
}
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function getProperty($id)
 {
     $prop = SQLSelectOne("SELECT * FROM knxproperties WHERE ID='" . $id . "' AND CAN_READ=1");
     if (!$prop['ID']) {
         return false;
     }
     if (!$this->connection) {
         $this->connect(0);
     }
     if ($this->connection) {
         $res = cacheread($this->connection, $prop['ADDRESS'], 0);
         //var_dump($res);
         // $res[0] - addr
         // $res[1] - from
         if (isset($res[2])) {
             $data = array();
             $total = count($res);
             for ($i = 2; $i < $total; $i++) {
                 $data[] = (int) $res[$i];
             }
             $old_value = $prop['DATA_VALUE'];
             if ($prop['DATA_TYPE'] == 'small') {
                 $prop['DATA_VALUE'] = $data[0];
             } elseif ($prop['DATA_TYPE'] == 'p1') {
                 $prop['DATA_VALUE'] = round($data[0] * 100 / 255, 2);
             } elseif ($prop['DATA_TYPE'] == 'f2') {
                 $prop['DATA_VALUE'] = f2_decode($data);
                 // TO-DO: OTHER TYPES!!!
             } elseif ($prop['DATA_TYPE'] == 'b1') {
             } elseif ($prop['DATA_TYPE'] == 'b2') {
             }
             $prop['DATA_RAW'] = implode(',', $data);
             $prop['UPDATED'] = date('Y-m-d H:i:s');
             print_r($prop);
             SQLUpdate('knxproperties', $prop);
             if ($prop['LINKED_OBJECT'] && $prop['LINKED_PROPERTY']) {
                 setGlobal($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_PROPERTY'], $prop['DATA_VALUE'], array($this->name => '0'));
             }
             if ($prop['LINKED_OBJECT'] && $prop['LINKED_METHOD'] && $prop['DATA_VALUE'] != $old_value) {
                 $params = array();
                 $params['VALUE'] = $prop['DATA_VALUE'];
                 callMethod($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_METHOD'], $params);
             }
         }
     }
 }