|
@@ -1,9 +1,14 @@
|
|
|
package com.welampiot.controller;
|
|
|
|
|
|
import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.DevInfoEnum;
|
|
|
import com.welampiot.common.InterfaceResultEnum;
|
|
|
import com.welampiot.dto.EnvmonitorDTO;
|
|
|
+import com.welampiot.dto.WeatherRS485DevInfoDTO;
|
|
|
+import com.welampiot.dto.WifiDTO;
|
|
|
import com.welampiot.service.EnvmonitorService;
|
|
|
+import com.welampiot.service.WeatherRS485DevInfoService;
|
|
|
+import com.welampiot.service.WifiService;
|
|
|
import com.welampiot.utils.ToolUtils;
|
|
|
import com.welampiot.vo.EnvmonitorVO;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -14,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* ClassName: WeatherController
|
|
@@ -32,6 +38,10 @@ public class WeatherController {
|
|
|
private ToolUtils toolUtils;
|
|
|
@Autowired
|
|
|
private EnvmonitorService envmonitorService;
|
|
|
+ @Autowired
|
|
|
+ private WifiService wifiService;
|
|
|
+ @Autowired
|
|
|
+ private WeatherRS485DevInfoService weatherRS485DevInfoService;
|
|
|
|
|
|
/**
|
|
|
* 设置plc气象站开、关灯时间
|
|
@@ -78,4 +88,155 @@ public class WeatherController {
|
|
|
BeanUtils.copyProperties(envmonitorDTO,envmonitorVO);
|
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,envmonitorVO);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 气象站注册
|
|
|
+ * @param request 气象站id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/registerDev", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> registerDev(HttpServletRequest request) {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer id = (Integer) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ EnvmonitorDTO envmonitorDTO = envmonitorService.getEnvmonitorMpDataById(id);
|
|
|
+ Integer lampPoleId = envmonitorDTO.getLampPoleId();
|
|
|
+ WifiDTO wifiDTO = new WifiDTO();
|
|
|
+ wifiDTO.setLampPoleId(lampPoleId);
|
|
|
+ WifiDTO detailByDTO = wifiService.getDetailByDTO(wifiDTO);
|
|
|
+ Integer model = detailByDTO.getModel();
|
|
|
+ String top = "";
|
|
|
+ String chuanKou = "";
|
|
|
+ String ra = "";
|
|
|
+ if (model == 0){
|
|
|
+ top = "WEGW";
|
|
|
+ } else if (model == 1 || model == 5) {
|
|
|
+ top = "WEGW2";
|
|
|
+ }else {
|
|
|
+ top = "WEGW3";
|
|
|
+
|
|
|
+ String s = "00" + envmonitorDTO.getSerialPort();
|
|
|
+ chuanKou = s.substring(s.length()-2);
|
|
|
+ System.out.println(chuanKou);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (envmonitorDTO.getDevType() == 0){
|
|
|
+ DevInfoEnum[] values = DevInfoEnum.values();
|
|
|
+ String s1 = "00000000" + Integer.toHexString(9600);
|
|
|
+ if (model != 0) ra = s1.substring(s1.length()-8);
|
|
|
+ List<WeatherRS485DevInfoDTO> listByWeatherId = weatherRS485DevInfoService.getListByWeatherId(envmonitorDTO.getId());
|
|
|
+ for (WeatherRS485DevInfoDTO dto :listByWeatherId) {
|
|
|
+ String cmd = "";
|
|
|
+ String s2 = "0" + Integer.toHexString(dto.getAddress());
|
|
|
+ String address = s2.substring(s2.length()-2);
|
|
|
+ for (DevInfoEnum e :values) {
|
|
|
+ if (e.getId() == dto.getDevId()){
|
|
|
+ cmd = e.getCmd();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cmd = address+cmd;
|
|
|
+ cmd += toolUtils.getCRC(cmd);
|
|
|
+ String cmdT = cmd;
|
|
|
+
|
|
|
+ cmd = ra + cmd;
|
|
|
+ String s3 = "0" + Integer.toHexString(cmd.length() / 2);
|
|
|
+ String len = s3.substring(s3.length()-2);
|
|
|
+ String sendData = chuanKou+address+len+cmd;
|
|
|
+ String sendTopic = "/"+top+"/WriteIn/"+detailByDTO.getNum();
|
|
|
+ String backTopic = "/"+top+"/WriteOut/"+detailByDTO.getNum();
|
|
|
+ sendData = "11{\"D2\":\""+sendData+"\"}";
|
|
|
+ String s = toolUtils.sendMqttCmd(sendTopic, sendData, backTopic,10);
|
|
|
+ if (s != null){
|
|
|
+ sendTopic = "/"+top+"/TransIn/"+detailByDTO.getNum();
|
|
|
+ backTopic = "/"+top+"/TransOut/"+detailByDTO.getNum();
|
|
|
+ sendData = "0101"+chuanKou+cmdT;
|
|
|
+ s = toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(sendData), backTopic,10);
|
|
|
+ if (s != null){
|
|
|
+ String string = "02000000000000"+chuanKou+toolUtils.bytes2HexString(s.getBytes()).substring(4);
|
|
|
+ sendTopic = "/"+top+"/DataReport/"+detailByDTO.getNum();
|
|
|
+ backTopic = "/"+top+"/DataReport/"+detailByDTO.getNum();
|
|
|
+ toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(string), backTopic,0);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ Integer rate = envmonitorDTO.getRate();
|
|
|
+
|
|
|
+ if (model != 0) {
|
|
|
+ String s = "";
|
|
|
+ if (rate == 0){
|
|
|
+ s = "00000000" + Integer.toHexString(1200);
|
|
|
+ } else if (rate == 1) {
|
|
|
+ s = "00000000" + Integer.toHexString(2400);
|
|
|
+ } else if (rate == 2) {
|
|
|
+ s = "00000000" + Integer.toHexString(4800);
|
|
|
+ } else if (rate == 3) {
|
|
|
+ s = "00000000" + Integer.toHexString(9600);
|
|
|
+ } else if (rate == 4) {
|
|
|
+ s = "00000000" + Integer.toHexString(19200);
|
|
|
+ } else if (rate == 5) {
|
|
|
+ s = "00000000" + Integer.toHexString(38400);
|
|
|
+ } else if (rate == 6) {
|
|
|
+ s = "00000000" + Integer.toHexString(38400);
|
|
|
+ }
|
|
|
+ if (ra.length() == 0) ra = "00000000"+Integer.toHexString(9600);
|
|
|
+ ra = s.substring(s.length()-8);
|
|
|
+ }
|
|
|
+ String cmd = "";
|
|
|
+ String address = "";
|
|
|
+ if (envmonitorDTO.getDevType() == 1){
|
|
|
+ cmd = "010301f4000c";
|
|
|
+ address = "01";
|
|
|
+ }else if (envmonitorDTO.getDevType() == 2){
|
|
|
+ cmd = "010301f40008";
|
|
|
+ address = "01";
|
|
|
+ }else if (envmonitorDTO.getDevType() == 3){
|
|
|
+ cmd = "ff0300010012";
|
|
|
+ address = "ff";
|
|
|
+ }else if (envmonitorDTO.getDevType() == 5){
|
|
|
+ cmd = "300300000010";
|
|
|
+ address = "30";
|
|
|
+ }else if (envmonitorDTO.getDevType() == 7){
|
|
|
+ cmd = "01030000000E";
|
|
|
+ address = "01";
|
|
|
+ }else if (envmonitorDTO.getDevType() == 9){
|
|
|
+ return toolUtils.response(InterfaceResultEnum.DEVICE_NO_SUPPORT,version);
|
|
|
+ }else{
|
|
|
+ cmd = "010301f4000c";
|
|
|
+ address = "01";
|
|
|
+ }
|
|
|
+ cmd += toolUtils.getCRC(cmd);
|
|
|
+ String cmdT = cmd;
|
|
|
+ cmd = ra+cmd;
|
|
|
+ String s1 = "0" + Integer.toHexString(cmd.length() / 2);
|
|
|
+ String len = s1.substring(s1.length()-2);
|
|
|
+
|
|
|
+ String sendData = chuanKou+address+len+cmd;
|
|
|
+ String sendTopic = "/"+top+"/WriteIn/"+detailByDTO.getNum();
|
|
|
+ String backTopic = "/"+top+"/WriteOut/"+detailByDTO.getNum();
|
|
|
+ sendData = "01{\"D2\":\""+sendData+"\"}";
|
|
|
+ String s = toolUtils.sendMqttCmd(sendTopic, sendData, backTopic);
|
|
|
+ if (s != null){
|
|
|
+ sendTopic = "/"+top+"/TransIn/"+detailByDTO.getNum();
|
|
|
+ backTopic = "/"+top+"/TransOut/"+detailByDTO.getNum();
|
|
|
+ sendData = "0101"+chuanKou+cmdT;
|
|
|
+
|
|
|
+ s = toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(sendData), backTopic);
|
|
|
+ if (s != null){
|
|
|
+ String string = "02000000000000"+chuanKou+toolUtils.bytes2HexString(s.getBytes()).substring(4);
|
|
|
+ System.out.println(string);
|
|
|
+ sendTopic = "/"+top+"/DataReport/"+detailByDTO.getNum();
|
|
|
+ backTopic = "/"+top+"/DataReport/"+detailByDTO.getNum();
|
|
|
+ toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(string), backTopic,0);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
}
|