function dptSelectEncode($dpt, $value, $inverse = false) { $All_DPT = All_DPT(); $type = substr($dpt, 0, strpos($dpt, '.')); $data = null; switch ($type) { case "1": if ($value != 0 && $value != 1) { $ValeurDpt = $All_DPT["Boolean"][$dpt][Valeurs]; $value = array_search($value, $ValeurDpt); } if ($inverse) { if ($value == 0) { $value = 1; } else { $value = 0; } } $data = $value; break; case "2": $data = $value; break; case "3": $ctrl = 1; if ($value > 0) { $stepCode = abs($value) & 0x7; } $data = $ctrl << 3 | $stepCode; break; case "5": switch ($dpt) { case "5.001": $data = round(intval($value) * 255 / 100); break; case "5.003": $data = round(intval($value) * 255 / 360); break; case "5.004": $data = round(intval($value) * 255); break; } break; case "6": if ($value < 0) { $value = (abs($value) ^ 0xff) + 1; } # twos complement $data = array($value); break; case "7": $data = array($value); break; case "8": /* if data >= 0x8000: data = -((data - 1) ^ 0xffff) # invert twos complement else: data = data if self._dpt is self.DPT_DeltaTime10Msec: value = data * 10. elif self._dpt is self.DPT_DeltaTime100Msec: value =data * 100. elif self._dpt is self.DPT_Percent_V16: value = data / 100. else: value = data*/ $data = array($value); break; case "9": if ($value < 0) { $sign = 1; $value = -$value; } else { $sign = 0; } $value = $value * 100.0; $exp = 0; while ($value > 2047) { $exp++; $value = $value / 2; } if ($sign) { $value = -$value; } $value = $value & 0x7ff; $data = array($sign << 7 | ($exp & 0xf) << 3 | $value >> 8 & 0x7, $value & 0xff); break; case "10": $value = new DateTime($value); $wDay = $value->format('N'); $hour = $value->format('H'); $min = $value->format('i'); $sec = $value->format('s'); $data = array($wDay << 5 | $hour, $min, $sec); break; case "11": $value = new DateTime($value); $day = $value->format('d'); $month = $value->format('m'); $year = $value->format('y'); $data = array($day, $month, $year); break; case "12": $data = array($value); break; case "13": if ($value < 0) { $value = (abs($value) ^ 4294967295.0) + 1; } # twos complement /* if self._dpt is self.DPT_Value_FlowRate_m3h: $data = int(round($value * 10000.)) else*/ $data = array($value >> 24 & 0xff, $value >> 16 & 0xff, $value >> 8 & 0xff, $value & 0xff); break; case "14": $value = unpack("L", pack("f", $value)); $data = array($value[1] >> 24 & 0xff, $value[1] >> 16 & 0xff, $value[1] >> 8 & 0xff, $value[1] & 0xff); break; case "16": /*data = 0x00 for shift in range(104, -1, -8): data |= value[13 - shift / 8] << shift*/ $data = array($value); break; case "17": /*ctrl = value[0] scene = value[1] data = ctrl << 7 | scene*/ $data = array($value); break; case "19": $value = new DateTime($value); $wDay = $value->format('N'); $hour = $value->format('H'); $min = $value->format('i'); $sec = $value->format('s'); $day = $value->format('d'); $month = $value->format('m'); $year = $value->format('Y') - 1900; $data = array($year, $month, $day, $wDay << 5 | $hour, $min, $sec, 0, 0); break; case "20": if ($dpt != "20.xxx") { $ValeurDpt = $All_DPT["8BitEncAbsValue"][$dpt]["Valeurs"]; $value = array_search($value, $ValeurDpt); } $data = array($value); break; } return $data; }
function getDptUnite($dpt) { $All_DPT = All_DPT(); while ($Type = current($All_DPT)) { while ($Dpt = current($Type)) { if ($dpt == key($Type)) { return $Dpt["Unite"]; } next($Type); } next($All_DPT); } return; }
public function getAllDpt() { header("Content-type: text/json"); echo json_encode(All_DPT(), JSON_NUMERIC_CHECK); }