DESKTOP-9JTA2JJ\HP 5 年之前
父節點
當前提交
cf9fc3ae2b
共有 2 個文件被更改,包括 13 次插入134 次删除
  1. 5 5
      api/application/config/response.php
  2. 8 129
      api/application/controllers/Lampcontrol.php

+ 5 - 5
api/application/config/response.php

@@ -179,12 +179,12 @@ $config['response_en']['0007'] = "Missing necessary parameters";
 $config['response_en']['0008'] = "Server connection failure";
 $config['response_en']['0009'] = "Database update failed";
 $config['response_en']['0010'] = "Command failure";
-$config['response_en']['0011'] = "Delete failure";
-$config['response_en']['0012'] = "Upload failure";
+$config['response_en']['0011'] = "No authority";
+$config['response_en']['0012'] = "cannot find file";
 $config['response_en']['0013'] = "No authority";
-$config['response_en']['0014'] = 'The command is timed out, please try again later.';
-$config['response_en']['0015'] = 'Oversize Upload Files';
-$config['response_en']['0016'] = 'Error uploading file type';
+$config['response_en']['0014'] = 'Parameter error';
+$config['response_en']['0015'] = 'Upload failed';
+$config['response_en']['0016'] = 'The command is timed out, please try again later.';
 //登录 0100-0199
 $config['response_en']['0100'] = 'User name or password cannot be empty';
 $config['response_en']['0101'] = 'Wrong user name or password';

+ 8 - 129
api/application/controllers/Lampcontrol.php

@@ -424,7 +424,7 @@ class Lampcontrol extends Base_Controller {
         $list = $this->Lamp_model->get_list(['id'=>$ids],'address');
         foreach ($list as $v) {
 
-            send_cmd('18',$v['address'],'','0000000000','0100',0);
+            $this->send_cmd('18',$v['address'],'','0000000000','0100',0);
 
         }
         sleep(2);
@@ -1062,7 +1062,7 @@ class Lampcontrol extends Base_Controller {
 
         $lampData = $this->Lamp_model->getData(array('id'=>$lampid),'projectid,address,number');
 
-        $res = send_cmd('12',$lampData['address'],$sendData);
+        $res = $this->send_cmd('12',$lampData['address'],$sendData);
 
         if (!empty($res)) {
             $msg = unpack('H*', $res['msg'])[1];
@@ -1181,7 +1181,7 @@ class Lampcontrol extends Base_Controller {
             $sendData .= $word;
         }
 
-        $res = send_cmd('10',$lampData['address'],$sendData);
+        $res = $this->send_cmd('10',$lampData['address'],$sendData);
 
         
         if (!empty($res)) {
@@ -1365,128 +1365,6 @@ class Lampcontrol extends Base_Controller {
         exit(json_result('0000', $this->response['0000'], array("id" => $lampId)));
     }
 
-    // 获取负载参数设置
-    public function load_setting() {
-        $lamp_id = $this->input->post('lamp_id', true);
-        if (empty($lamp_id)) {
-            exit(json_result('0400', $this->response['0400'], array()));
-        }
-
-        $lampData = $this->Lamp_model->getOne($lamp_id,'N.status,N.protocoltype,L.protocoltype as lampprotocoltype,L.address,L.number,N.deviceid');
-
-        $cmd = '{"cmd_type":"get_load_setting_cmd","cmd_id":'.$lamp_id.',"broadcast":0}';
-        
-        if (($lampData['protocoltype'] == 4 || $lampData['protocoltype'] == 6) && $lampData['lampprotocoltype'] == 0) {
-            $address = '';
-            if (mb_strlen($lampData['address']) >= 8) {
-                $address = mb_substr($lampData['address'], -8);
-            }else{
-                $address = '00000000';
-            }
-            $sendData = $address.'0304001014';
-            
-            if ($lampData['protocoltype'] == 4) {
-                $res = lampMqttCmd('/IDCOL/CmdInput/'.$lampData['address'],'/IDCOL/CmdOutput/'.$lampData['address'],pack('H*','0001'.$sendData));
-            }else{
-                device_cmd($lampData['deviceid'],pack('H*',$sendData));
-                $cmd = '{"type":"cmd","deviceId":"'.$lampData['address'].'"}';
-                $info = send_lorawan_915($cmd);
-                $res = array();
-                if (!empty($info)) {
-                    $info = json_decode($info,true);
-                    if ($info && $info['res'] == 0) $res['msg'] = $info['resInfo'];
-                }
-            }
-            
-            if (empty($res)) {
-                exit(json_result('0016', $this->response['0016']));
-            }else{
-                $msg1 = $res['msg'];
-                // 数据校验
-                $msg = mb_substr($msg1, 10);
-                $t = 0;
-                for ($i=0; $i < mb_strlen($msg) / 2 - 1; $i++) {
-                    $s = mb_substr($msg, $i*2,2);
-                    $t += base_convert($s, 16, 10);
-                }
-                $t = base_convert($t, 10, 16);
-                if (mb_strlen($t) > 2) {
-                    $t = mb_substr($t, -2);
-                }elseif($t <= 1){
-                    $t = '0'.$t;
-                }
-                if ($t == mb_substr($msg, -2)) {  
-                    $data = array();
-                    $dataStr = mb_substr($msg1, 16);
-                    $data['workmode']         = base_convert(mb_substr($dataStr, 0,2), 16, 10);
-                    $data['worktimefirst']    = base_convert(mb_substr($dataStr, 2,2), 16, 10);
-                    $data['workpowerfirst']   = base_convert(mb_substr($dataStr, 4,2), 16, 10);
-                    $data['worktimesencond']  = base_convert(mb_substr($dataStr, 6,2), 16, 10);
-                    $data['workpowersencond'] = base_convert(mb_substr($dataStr, 8,2), 16, 10);
-                    $data['worktimethird']    = base_convert(mb_substr($dataStr, 10,2), 16, 10);
-                    $data['workpowerthird']   = base_convert(mb_substr($dataStr, 12,2), 16, 10);
-                    $data['worktimeforth']    = base_convert(mb_substr($dataStr, 14,2), 16, 10);
-                    $data['workpowerforth']   = base_convert(mb_substr($dataStr, 16,2), 16, 10);
-                    $data['delaytime']        = base_convert(mb_substr($dataStr, 18,2), 16, 10);
-                    $data['voptically']       = round(base_convert(mb_substr($dataStr, 20,4), 16, 10)/10,1);
-                    $data['ledloadcurrent']   = round(base_convert(mb_substr($dataStr, 24,4), 16, 10),2);
-                    $data['powercmd']         = base_convert(mb_substr($dataStr, 28,2), 16, 10);
-                    $data['switchfeature']    = base_convert(mb_substr($dataStr, 30,2), 16, 10);
-                    exit(json_result('0000', $this->response['0000'], $data));
-                }else{
-                    exit(json_result('0010', $this->response['0010']));
-                }
-            }
-            
-        }
-        if (isset($lampData['protocoltype']) && $lampData['protocoltype'] != 0) {
-            $cmdret = send_cmd($cmd,1,30,$lampData['protocoltype']);
-            if ($cmdret === false) {
-                sleep(1);
-                $cmdret = send_cmd($cmd,1,30,$lampData['protocoltype']);
-            }
-        }else{
-            $cmdret = send_cmd($cmd,0,30,$lampData['protocoltype']);
-            if ($cmdret === false) {
-                sleep(1);
-                $cmdret = send_cmd($cmd,0,30,$lampData['protocoltype']);
-            }
-        }
-        if (empty($cmdret)) exit(json_result('0016',$this->response['0016']));
-        $r = json_decode($cmdret, true);
-        if ($r['result'] == false) {
-            $version = $this->session->userdata('version');
-            if (empty($version)) {
-                $msg = empty($r['msg']) ? '未知错误' : transfer_error_tips($r['msg']);
-            }else{
-                $msg = empty($r['msg']) ? 'Unknown error' : $r['msg'];
-            }
-            exit(json_result('other', $msg));
-        }
-        $res = $this->Load_model->get_data_by_filter(['relateid'=>$lamp_id,'cmdtype'=>0]);
-        if (empty($res)) {
-            $update['workmode']         = '0';
-            $update['worktimefirst']    = '4';
-            $update['workpowerfirst']   = '80';
-            $update['worktimesencond']  = '1';
-            $update['workpowersencond'] = '40';
-            $update['worktimethird']    = '8';
-            $update['workpowerthird']   = '30';
-            $update['worktimeforth']    = '0';
-            $update['workpowerforth']   = '30';
-            $update['voptically']       = '5';
-            $update['delaytime']        = '1';
-            $update['ledloadcurrent']   = '330';
-            $update['powercmd']         = '1';
-            $update['switchfeature']    = '1';
-            $res = $update;
-        }
-        unset($res['id']);
-        unset($res['updatetime']);
-        $data = $res;
-        
-        exit(json_result('0000', $this->response['0000'], $data));
-    }
 
     private function format_date_en($date){
         $h = floor($date/3600);
@@ -1565,7 +1443,7 @@ class Lampcontrol extends Base_Controller {
         }
         $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number');
 
-        $res = send_cmd('93',$lampData['address'],'');
+        $res = $this->send_cmd('93',$lampData['address'],'');
 
             
         if (empty($res)) {
@@ -1637,12 +1515,13 @@ class Lampcontrol extends Base_Controller {
             exit(json_result('0400', $this->response['0400'], array()));
         }
 
-        $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number');
+        $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number,projectid');
 
-        $res = send_cmd('91',$lampData['address'],'');
+        $res = $this->send_cmd('91',$lampData['address'],'');
 
         
-        $lampData = $this->Lamp_model->getData(array('id'=>$lampid),'projectid,address,number');
+        // $lampData = $this->Lamp_model->getData(array('id'=>$lamp_id),'projectid,address,number');
+        // var_dump($res);
         if (!empty($res)) {
             $info = unpack('H*', $res['msg'])[1];
             $data['system_voltage']                 = base_convert(substr($info, 18,2), 16, 10);  // 电池电压