| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- <?php
- namespace App\Service\Device;
- use App\Jobs\PushDeviceJob;
- use App\Service\Service;
- class DeviceCommonService extends Service
- {
- public $deviceList = [
- //腹带抛光机
- ///HC/STWDL/WriteRealtimeData/WDL2
- ['type' => 'FDPGJ', 'id' => 'FDPGJ', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'WXM', 'id' => 'WXM1', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'STWDL', 'id' => 'WDL2', 'cmd' => '00 00 00 00 00 06 01 02 00 00 00 0A'],
- ['type' => 'STWDL', 'id' => 'WDL3', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 32'],
- ['type' => 'GTPGJ', 'id' => 'GTPG1', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'GTPGJ', 'id' => 'GTPG2', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'GTPGJ', 'id' => 'GTPG3', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'GTPGJ', 'id' => 'GTPG4', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'GTPGJ', 'id' => 'GTPG5', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'GTPGJ', 'id' => 'GTPG6', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'GTPGJ', 'id' => 'GTPG7', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'GTPGJ', 'id' => 'GTPG8', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 07'],
- ['type' => 'BLJ', 'id' => 'BL1', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ1', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ2', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ3', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ4', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ5', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ6', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ7', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ8', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ9', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'QZJ', 'id' => 'QZ10', 'cmd' => '00 00 00 00 00 06 01 03 00 00 00 09'],
- ['type' => 'CGJ', 'id' => 'CG1', 'cmd' => '00 03 00 00 00 06 01 03 A4 04 00 01'],
- ['type' => 'CGJ', 'id' => 'CG1', 'cmd' => '00 09 00 00 00 06 01 02 60 05 00 01'],
- ['type' => 'CGJ', 'id' => 'CG1', 'cmd' => '00 0A 00 00 00 06 01 02 60 06 00 01'],
- // 以后增加更多设备...
- ];
- public function dealDevice($type, $message, callable $logger = null)
- {
- $message = str_replace(" ", "", $message);
- $return = '';
- switch ($type) {
- case "FDPGJ":
- $return = $this->FDPGJ($message, $type);
- break;
- case "WXM1":
- $return = $this->WXM1($message, $type);
- break;
- case "GTPG1":
- case "GTPG2":
- case "GTPG3":
- case "GTPG4":
- case "GTPG5":
- case "GTPG6":
- case "GTPG7":
- case "GTPG8":
- $return = $this->GTPG($message, $type);
- break;
- case "BL1":
- $return = $this->BLJ($message, $type);
- break;
- case "QZ1":
- case "QZ2":
- case "QZ3":
- case "QZ4":
- case "QZ5":
- case "QZ6":
- case "QZ7":
- case "QZ8":
- case "QZ9":
- case "QZ10":
- $return = $this->QZ($message, $type);
- break;
- case "CG1":
- $return = $this->CG($message, $type);
- break;
- case "WDL3":
- $return = $this->WDL($message, $type);
- break;
- default:
- break;
- }
- if (!empty($return)) {
- $data = [
- "data" => [
- "deviceId" => "",
- "dataPoints" => [
- ],
- ],
- "type" => "dataPoint"
- ];
- foreach ($return as $v) {
- if(empty($data['data']['deviceId'])) $data['data']['deviceId'] = $v['code'];
- $data['data']['dataPoints'][] = [
- "dataPointId" => $v['type'],
- "value" => $v['value'],
- ];
- }
- dispatch((new PushDeviceJob($data)))->onQueue('device_hc');
- //拼装结构
- if (isset($data)) {
- $logger("设备 {$type} 处理完成,数据:" . json_encode($data));
- }
- }
- }
- public function WDL($message, $type)
- {
- //0000 0000 0067 0103 64
- //0255 0288 02a2 02a2 028f 0247 0022 0000 0000 0079 0087 008e 0086 0022 0000 0000 0000 0000 0002 0002 0002 0002 0002 0002 0000 0002 0002 0002 0002 0001 0000 0000
- //0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
- //运行状态、运行时间(分)、停止时间(分)、下压次数、下压频率(速度),次/分
- if (strlen($message) > 100) {
- $list = $this->dealMessage($message, [0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]);
- $dispatch = [
- [
- 'code' => $type,
- "type" => '_0',
- "value" => $list[0],
- ], [
- 'code' => $type,
- "type" => '_1',
- "value" => $list[1],
- ], [
- 'code' => $type,
- "type" => '_2',
- "value" => $list[2],
- ], [
- 'code' => $type,
- "type" => '_3',
- "value" => $list[3],
- ], [
- 'code' => $type,
- "type" => '_4',
- "value" => $list[4],
- ], [
- 'code' => $type,
- "type" => '_5',
- "value" => $list[5],
- ], [
- 'code' => $type,
- "type" => '_6',
- "value" => $list[6],
- ], [
- 'code' => $type,
- "type" => '_9',
- "value" => $list[9],
- ], [
- 'code' => $type,
- "type" => '_10',
- "value" => $list[10],
- ], [
- 'code' => $type,
- "type" => '_11',
- "value" => $list[11],
- ], [
- 'code' => $type,
- "type" => '_12',
- "value" => $list[12],
- ], [
- 'code' => $type,
- "type" => '_20',
- "value" => $list[20],
- ]
- ];
- return $dispatch;
- }
- }
- //车沟机
- public function CG($message, $type)
- {
- $code = substr($message, 3, 1);
- //0004 0000 0005 0103 02 3a98
- if (strlen($message) > 10) {
- //进刀长度\进刀速度\退刀速度\产量计数\产量设定\急停\主机热继电器\料斗热继电器\气压报警\车沟马达启动(运行信号)\报警
- $dispatch = [];
- switch ($code) {
- case "3":
- $list = $this->dealMessage($message, [4]);
- $value = hexdec($list[0]);
- $num = 3;
- break;
- case "9":
- $list = $this->dealMessage($message, [2]);
- $value = hexdec($list[0]);
- $num = 9;
- break;
- case "a":
- $list = $this->dealMessage($message, [2]);
- $value = hexdec($list[0]);
- $num = 10;
- break;
- default:
- break;
- }
- if (isset($value)) {
- $dispatch[] = [
- 'code' => $type,
- "type" => '_' . $num,
- "value" => $value,
- ];
- }
- return $dispatch;
- }
- }
- //切轴机
- public function QZ($message, $type)
- {
- //0000 0000 0015 01 03 12 0001 00000370 00000326 00020b3d 000001e0
- //运行状态、运行时间(分)、停止时间(分)、下压次数、下压频率(速度),次/分
- if (strlen($message) > 50) {
- $list = $this->dealMessage($message, [4, 8, 8, 8, 8]);
- $run_state = hexdec($list[0]);
- $run_time = hexdec($list[1]);
- $stop_time = hexdec($list[2]);
- $run_num = hexdec($list[3]);
- $run_frequency = hexdec($list[4]);
- $dispatch = [
- [
- 'code' => $type,
- "type" => '_0',
- "value" => $run_state,
- ], [
- 'code' => $type,
- "type" => '_1',
- "value" => $run_time,
- ], [
- 'code' => $type,
- "type" => '_2',
- "value" => $stop_time,
- ], [
- 'code' => $type,
- "type" => '_3',
- "value" => $run_num,
- ], [
- 'code' => $type,
- "type" => '_4',
- "value" => $run_frequency,
- ],
- ];
- return $dispatch;
- }
- }
- //编链机
- public function BLJ($message, $type)
- {
- //0000 0000 0015 0103 12 0000 00000000 00000036 00000011 00000000
- //运行状态、运行时间(分)、停止时间(分)、下压次数、下压频率(速度),次/分
- if (strlen($message) > 50) {
- $list = $this->dealMessage($message, [4, 8, 8, 8, 8]);
- $run_state = hexdec($list[0]);
- $run_time = hexdec($list[1]);
- $stop_time = hexdec($list[2]);
- $run_num = hexdec($list[3]);
- $run_frequency = hexdec($list[4]);
- $dispatch = [
- [
- 'code' => $type,
- "type" => '_0',
- "value" => $run_state,
- ], [
- 'code' => $type,
- "type" => '_1',
- "value" => $run_time,
- ], [
- 'code' => $type,
- "type" => '_2',
- "value" => $stop_time,
- ], [
- 'code' => $type,
- "type" => '_3',
- "value" => $run_num,
- ], [
- 'code' => $type,
- "type" => '_4',
- "value" => $run_frequency,
- ],
- ];
- return $dispatch;
- }
- }
- //滚筒抛光机
- public function GTPG($message, $type)
- {
- //0000 0000 0011 01 03 0e 0001 0000004b 00000355 00000007
- //运行状态、运行时间(分)、停止时间(分)、运行次数
- if (strlen($message) > 40) {
- $list = $this->dealMessage($message, [4, 8, 8, 8]);
- $run_state = hexdec($list[0]);
- $run_time = hexdec($list[1]);
- $stop_time = hexdec($list[2]);
- $run_num = hexdec($list[3]);
- $dispatch = [
- [
- 'code' => $type,
- "type" => '_0',
- "value" => $run_state,
- ], [
- 'code' => $type,
- "type" => '_1',
- "value" => $run_time,
- ], [
- 'code' => $type,
- "type" => '_2',
- "value" => $stop_time,
- ], [
- 'code' => $type,
- "type" => '_3',
- "value" => $run_num,
- ],
- ];
- return $dispatch;
- }
- }
- //无芯磨机
- public function WXM1($message, $type)
- {
- //0000 0000 0015 01 03 12 0001 00000153 00000244 00000003 00000000
- //00000000001101030e0001000006e7000003e20000000a
- //运行状态、运行时间(分)、停止时间(分)、运行次数
- if (strlen($message) > 40) {
- $list = $this->dealMessage($message, [4, 8, 8, 8]);
- $run_state = hexdec($list[0]);
- $run_time = hexdec($list[1]);
- $stop_time = hexdec($list[2]);
- $run_num = hexdec($list[3]);
- $dispatch = [
- [
- 'code' => $type,
- "type" => '_0',
- "value" => $run_state,
- ], [
- 'code' => $type,
- "type" => '_1',
- "value" => $run_time,
- ], [
- 'code' => $type,
- "type" => '_2',
- "value" => $stop_time,
- ], [
- 'code' => $type,
- "type" => '_3',
- "value" => $run_num,
- ],
- ];
- return $dispatch;
- }
- }
- //腹带抛光机
- public function FDPGJ($message, $type)
- {
- //0000 0000 0015 01 03 12 0000 00000000 000003d7 00000000 00000000
- //运行状态、运行时间(分)、停止时间(分)、运行次数
- if (strlen($message) > 40) {
- $list = $this->dealMessage($message, [4, 8, 8, 8]);
- $run_state = hexdec($list[0]);
- $run_time = hexdec($list[1]);
- $stop_time = hexdec($list[2]);
- $run_num = hexdec($list[3]);
- $dispatch = [
- [
- "code" => $type,
- "type" => '_0',
- "value" => $run_state,
- ], [
- "type" => $type . '_1',
- "value" => $run_time,
- ], [
- "type" => $type . '_2',
- "value" => $stop_time,
- ], [
- "type" => $type . '_3',
- "value" => $run_num,
- ],
- ];
- return $dispatch;
- }
- }
- public function dealMessage($message, $list)
- {
- $message = substr($message, 18);
- $return = [];
- foreach ($list as $v) {
- $return[] = substr($message, 0, $v);
- $message = substr($message, $v);
- }
- return $return;
- }
- public function disPatch($data){
- }
- }
|