tongshanglei 1 일 전
부모
커밋
c095195aaa
1개의 변경된 파일41개의 추가작업 그리고 6개의 파일을 삭제
  1. 41 6
      task_script/PUMP_MQTT_PUBLISH.php

+ 41 - 6
task_script/PUMP_MQTT_PUBLISH.php

@@ -359,6 +359,9 @@ class MQTT_TYPE {/*对应从1开始*/
     //双向
     public static $SET_SAMPLE_PERIOD = 't';                          /*20*/
     public static $GET_SAMPLE_PERIOD = 'u';
+    //双向 压力补偿值
+    public static $SET_COMPENS_VALUE = 'v';
+    public static $GET_COMPENS_VALUE = 'w';
 }
 
 define("ALTER_SEP", ",");
@@ -382,7 +385,7 @@ function buildMqttData($mqttType, $msgId/*整数 0-4294967295*/, $data) {
     $MIN = 0;
     $MAX = 39.99;
     $ALERT_LEN = 6;//值最大
-
+    $DECIMAL_LEN = 2;//小数点后几位
     $bin = pack("C1N1", ord($mqttType), $msgId/*time()*/ /*这个时间大小端和设备端相反*/);
 
     if ($mqttType == MQTT_TYPE::$SUB_ALARM) {
@@ -413,6 +416,14 @@ function buildMqttData($mqttType, $msgId/*整数 0-4294967295*/, $data) {
         if ($data['lower'] == '') {
             $data['lower'] = ' ';//要有个空格
         } else {
+            if (!is_string($data['lower'])) {
+                rlog("err lower must be string" . $data['lower']);
+                return false;
+            }
+            if (countDecimalPlaces($data['lower']) > $DECIMAL_LEN) {
+                rlog("err lower decimal too long " . $data['lower']);
+                return false;
+            }
             if (!preg_match('/^-?\d+(\.\d+)?$/', $data['lower'])) {
                 rlog("err lower " . $data['lower']);
                 return false;
@@ -424,6 +435,15 @@ function buildMqttData($mqttType, $msgId/*整数 0-4294967295*/, $data) {
             }
         }
         if (!empty($data['upper'])) {
+            if (!is_string($data['upper'])) {
+                rlog("err lower must be string" . $data['upper']);
+                return false;
+            }
+            if (countDecimalPlaces($data['upper']) > $DECIMAL_LEN) {
+                rlog("err upper decimal too long " . $data['upper']);
+                return false;
+            }
+
             if (!preg_match('/^-?\d+(\.\d+)?$/', $data['upper'])) {
                 rlog("err upper " . $data['upper']);
                 return false;
@@ -439,6 +459,7 @@ function buildMqttData($mqttType, $msgId/*整数 0-4294967295*/, $data) {
         $buff = $data['lower'] . ALTER_SEP . $data['upper'];/*1.236,10.256*/
         $bin = $bin . $buff . chr(0);//补零 设备解析是以为\0结尾
     } else if ($mqttType == MQTT_TYPE::$GET_ALARM) {
+
     } else if ($mqttType == MQTT_TYPE::$SET_DAMPING_TIME) {
         $num = floatval($data);
         if ($num < 0.00 || $num > 60.00) {
@@ -449,15 +470,27 @@ function buildMqttData($mqttType, $msgId/*整数 0-4294967295*/, $data) {
         $buff = $data;/*0.00-60.00*/
         $bin = $bin . $buff . chr(0);//补零 设备解析是以为\0结尾
     } else if ($mqttType == MQTT_TYPE::$GET_DAMPING_TIME) {
-    }else if ($mqttType == MQTT_TYPE::$PUB_CALIBRATION_ZERO) {
-    }else if ($mqttType == MQTT_TYPE::$SET_SAMPLE_PERIOD) {
+    } else if ($mqttType == MQTT_TYPE::$PUB_CALIBRATION_ZERO) {
+        if ($data != null) {
+            //下发补偿值
+            $buff = trim($data);
+            if (strlen($buff) == 0) {
+                rlog("err CALIBRATION val empty" . $data);
+                return false;
+            }
+            $bin = $bin . $buff . chr(0);//补零 设备解析是以为\0结尾
+        } else {
+            //校准0值
+            $bin = $bin . chr(0);
+        }
+    } else if ($mqttType == MQTT_TYPE::$SET_SAMPLE_PERIOD) {
         $num = intval($data);
-        if ($num < 0 || $num > 100) {
-            rlog("err damping time " . $data);
+        if ($num < 1 || $num > 50) {
+            rlog("err sample rate " . $data);
             return false;
         }
 
-        $buff = $data;/*0.00-60.00*/
+        $buff = $data;
         $bin = $bin . $buff . chr(0);//补零 设备解析是以为\0结尾
     } else if ($mqttType == MQTT_TYPE::$GET_SAMPLE_PERIOD) {
 
@@ -493,6 +526,8 @@ while (1) {
         $sendData = buildMqttData(MQTT_TYPE::$GET_ALARM, $config_json['msgId'], null);
     }elseif($data['type']=='calibration'){
         $sendData = buildMqttData(MQTT_TYPE::$PUB_CALIBRATION_ZERO, $config_json['msgId'], null);
+    }elseif($data['type']=='set_compens'){
+        $sendData = buildMqttData(MQTT_TYPE::$PUB_CALIBRATION_ZERO, $config_json['msgId'], $config_json['compensVal']);
     }elseif($data['type']=='set_damping'){
         $sendData = buildMqttData(MQTT_TYPE::$SET_DAMPING_TIME, $config_json['msgId'], $config_json['damping_time']);
     }elseif($data['type']=='get_damping'){