Пример #1
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function setProperty($id, $value)
 {
     $prop = SQLSelectOne("SELECT * FROM knxproperties WHERE ID='" . $id . "' AND CAN_WRITE=1");
     if (!$prop['ID']) {
         return false;
     }
     if (!$this->connection) {
         echo "Connecting";
         $this->connect(0);
     }
     $prop['DATA_VALUE'] = $value;
     switch ($prop['DATA_TYPE']) {
         case "small":
             $encoded = $value;
             break;
         case "p1":
             if ($value < 0) {
                 $value = 0;
             }
             if ($value > 100) {
                 $value = 100;
             }
             $value = (int) ($value * 255 / 100 + 0.5);
             $encoded = array($value & 0xff);
             break;
         case "b1":
             $encoded = array($value & 0xff);
             break;
         case "b2":
             $encoded = array($value >> 8 & 0xff, $value & 0xff);
             break;
         case "f2":
             $encoded = f2_encode($value);
             break;
     }
     if (is_array($encoded)) {
         $prop['DATA_RAW'] = implode(',', $encoded);
     } else {
         $prop['DATA_RAW'] = $encoded;
     }
     $prop['UPDATED'] = date('Y-m-d H:i:s');
     SQLUpdate('knxproperties', $prop);
     $res = groupwrite($this->connection, $prop['ADDRESS'], $encoded);
     return $res;
 }
Пример #2
0
    switch ($typ) {
        case "small":
            $res = groupswrite($con, $addr, $value);
            break;
        case "p1":
            if ($value < 0) {
                $value = 0;
            }
            if ($value > 100) {
                $value = 100;
            }
            $value = (int) ($value * 255 / 100 + 0.5);
            $res = groupwrite($con, $addr, array($value & 0xff));
            break;
        case "b1":
            $res = groupwrite($con, $addr, array($value & 0xff));
            break;
        case "b2":
            $res = groupwrite($con, $addr, array($value >> 8 & 0xff, $value & 0xff));
            break;
        case "f2":
            $res = groupwrite($con, $addr, f2_encode($value));
            break;
    }
    if ($res == -1) {
        printf("<div class='result'>sending of %s to %s failed</div>", htmlentities($value), htmlentities($addr));
    } else {
        printf("<div class='result'>sent %s to %s </div>", htmlentities($value), htmlentities($addr));
    }
}
html_end();
Пример #3
0
/**
* Title
*
* Description
*
* @access public
*/
function knxwrite($con, $addr, $value, $typ)
{
    $res = -1;
    switch ($typ) {
        case "small":
            $res = groupswrite($con, $addr, $value);
            break;
        case "p1":
            if ($value < 0) {
                $value = 0;
            }
            if ($value > 100) {
                $value = 100;
            }
            $value = (int) ($value * 255 / 100 + 0.5);
            $res = groupwrite($con, $addr, array($value & 0xff));
            break;
        case "b1":
            $res = groupwrite($con, $addr, array($value & 0xff));
            break;
        case "b2":
            $res = groupwrite($con, $addr, array($value >> 8 & 0xff, $value & 0xff));
            break;
        case "f2":
            $res = groupwrite($con, $addr, f2_encode($value));
            break;
    }
    return $res;
}