|
@@ -1,9 +1,11 @@
|
|
package com.ruoyi.sim.service.impl;
|
|
package com.ruoyi.sim.service.impl;
|
|
|
|
|
|
import com.ruoyi.sim.config.SimConfig;
|
|
import com.ruoyi.sim.config.SimConfig;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -16,14 +18,15 @@ import static com.ruoyi.sim.service.impl.IotService.Const.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 硬件通信
|
|
* 硬件通信
|
|
|
|
+ * send service.
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class IotService {
|
|
public class IotService {
|
|
|
|
|
|
interface Const {
|
|
interface Const {
|
|
|
|
|
|
- String IP = "127.0.0.1";
|
|
|
|
- int PORT = 9000;
|
|
|
|
|
|
+ String IP = "123.112.16.165";
|
|
|
|
+ int PORT = 8899;
|
|
/**
|
|
/**
|
|
* 报文长度
|
|
* 报文长度
|
|
*/
|
|
*/
|
|
@@ -45,21 +48,34 @@ public class IotService {
|
|
|
|
|
|
String CMD_DATA_PLACE_HOLDER = "00000000";
|
|
String CMD_DATA_PLACE_HOLDER = "00000000";
|
|
|
|
|
|
- String CMD_READ = "03";
|
|
|
|
-
|
|
|
|
- String CMD_GET_SIM_TYPE = "B1";
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 故障下发
|
|
|
|
+ */
|
|
String CMD_SET_FAULT = "01";
|
|
String CMD_SET_FAULT = "01";
|
|
-
|
|
|
|
- String CMD_READ_SIM_FAULT_STATE = "03";
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 故障清清除
|
|
|
|
+ */
|
|
String CMD_CLEAR_SIM_FAULT = "02";
|
|
String CMD_CLEAR_SIM_FAULT = "02";
|
|
|
|
+ /**
|
|
|
|
+ * 设备类型读取
|
|
|
|
+ */
|
|
|
|
+ String CMD_READ_SIM_TYPE = "03";
|
|
|
|
+ /**
|
|
|
|
+ * 状态读取
|
|
|
|
+ */
|
|
|
|
+ String CMD_READ_SIM_FAULT_RESISTANCE = "03";
|
|
|
|
+
|
|
|
|
+ String CMD_ID_GET_SN = "B1";
|
|
|
|
+ int LENGTH_2 = 2;
|
|
|
|
+ int LENGTH_8 = 8;
|
|
|
|
+ int LENGTH_20 = 20;
|
|
}
|
|
}
|
|
|
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(IotService.class);
|
|
|
|
|
|
+ private static final Logger l = LoggerFactory.getLogger(IotService.class);
|
|
|
|
|
|
private Socket cachedSocket = null;
|
|
private Socket cachedSocket = null;
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SimReceiveService simReceiveService;
|
|
@Autowired
|
|
@Autowired
|
|
private SimConfig sc;
|
|
private SimConfig sc;
|
|
|
|
|
|
@@ -78,92 +94,70 @@ public class IotService {
|
|
public void getSimType(final String simNum) {
|
|
public void getSimType(final String simNum) {
|
|
// todo:check
|
|
// todo:check
|
|
|
|
|
|
- //
|
|
|
|
- StringBuffer m = new StringBuffer();
|
|
|
|
- m.append(PREFIX);
|
|
|
|
- m.append(simNum);
|
|
|
|
- m.append(ORN_SEND);
|
|
|
|
- m.append(CMD_READ);
|
|
|
|
- m.append(CMD_GET_SIM_TYPE);
|
|
|
|
- m.append(CMD_DATA_PLACE_HOLDER);
|
|
|
|
- m.append(SUFFIX);
|
|
|
|
- final String sendMsg = m.toString();
|
|
|
|
- final String receiveMsg = send(sendMsg);
|
|
|
|
|
|
+ final String receiveMsg = send(buildSendMsg(simNum, CMD_READ_SIM_TYPE, CMD_ID_GET_SN));
|
|
|
|
+ simReceiveService.receiveMsg(receiveMsg);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 故障下发
|
|
* 故障下发
|
|
*
|
|
*
|
|
- * @param simNum 设备编号
|
|
|
|
- * @param faultType 故障类型
|
|
|
|
|
|
+ * @param simNum 设备编号
|
|
|
|
+ * @param bindHardwareMsg fault.bind_hardware_msg
|
|
*/
|
|
*/
|
|
- public void setFault(final String simNum, final String faultType) {
|
|
|
|
|
|
+ public void setFault(final String simNum, final String bindHardwareMsg) {
|
|
// todo:check
|
|
// todo:check
|
|
-
|
|
|
|
- //
|
|
|
|
- StringBuffer m = new StringBuffer();
|
|
|
|
- m.append(PREFIX);
|
|
|
|
- m.append(simNum);
|
|
|
|
- m.append(ORN_SEND);
|
|
|
|
- m.append(CMD_SET_FAULT);
|
|
|
|
- m.append(faultType);
|
|
|
|
- m.append(CMD_DATA_PLACE_HOLDER);
|
|
|
|
- m.append(SUFFIX);
|
|
|
|
- //
|
|
|
|
-
|
|
|
|
- //
|
|
|
|
- final String receiveMsg = send(m.toString());
|
|
|
|
- //
|
|
|
|
|
|
+ final String receiveMsg = send(buildSendMsg(simNum, CMD_SET_FAULT, bindHardwareMsg));
|
|
|
|
+ simReceiveService.receiveMsg(receiveMsg);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 状态读取
|
|
* 状态读取
|
|
*
|
|
*
|
|
- * @param simNum 设备编号
|
|
|
|
- * @param faultType 故障类型
|
|
|
|
|
|
+ * @param simNum 设备编号
|
|
|
|
+ * @param bindHardwareMsg fault.bind_hardware_msg
|
|
*/
|
|
*/
|
|
- public void getSimStatus(final String simNum, final String faultType) {
|
|
|
|
|
|
+ public void getSimStatus(final String simNum, final String bindHardwareMsg) {
|
|
// todo:check
|
|
// todo:check
|
|
-
|
|
|
|
- //
|
|
|
|
- StringBuffer m = new StringBuffer();
|
|
|
|
- m.append(PREFIX);
|
|
|
|
- m.append(simNum);
|
|
|
|
- m.append(ORN_SEND);
|
|
|
|
- m.append(CMD_READ_SIM_FAULT_STATE);
|
|
|
|
- m.append(faultType);
|
|
|
|
- m.append(CMD_DATA_PLACE_HOLDER);
|
|
|
|
- m.append(SUFFIX);
|
|
|
|
- //
|
|
|
|
-
|
|
|
|
- //
|
|
|
|
- final String receiveMsg = send(m.toString());
|
|
|
|
- //
|
|
|
|
|
|
+ final String receiveMsg = send(buildSendMsg(simNum, CMD_READ_SIM_FAULT_RESISTANCE, bindHardwareMsg));
|
|
|
|
+ simReceiveService.receiveMsg(receiveMsg);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 故障清清除
|
|
* 故障清清除
|
|
*
|
|
*
|
|
- * @param simNum 设备编号
|
|
|
|
- * @param faultType 故障类型
|
|
|
|
|
|
+ * @param simNum 设备编号
|
|
|
|
+ * @param bindHardwareMsg fault.bind_hardware_msg
|
|
*/
|
|
*/
|
|
- public void clearSimStatus(final String simNum, final String faultType) {
|
|
|
|
|
|
+ public void clearSimStatus(final String simNum, final String bindHardwareMsg) {
|
|
// todo:check
|
|
// todo:check
|
|
-
|
|
|
|
|
|
+ final String receiveMsg = send(buildSendMsg(simNum, CMD_CLEAR_SIM_FAULT, bindHardwareMsg));
|
|
//
|
|
//
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String buildSendMsg(final String simNum, final String cmd, final String cmdId) {
|
|
|
|
+ return buildSendMsg(simNum, cmd, cmdId, CMD_DATA_PLACE_HOLDER);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String buildSendMsg(final String simNum, final String cmd, final String cmdId, final String data) {
|
|
|
|
+ if (StringUtils.isEmpty(simNum) || StringUtils.isEmpty(cmd) || StringUtils.isEmpty(cmdId) || StringUtils.isEmpty(data)) {
|
|
|
|
+ throw new IllegalArgumentException("buildSendMsg isEmpty");
|
|
|
|
+ }
|
|
|
|
+ if (simNum.length() != LENGTH_2 || cmd.length() != LENGTH_2 || cmdId.length() != LENGTH_2 || data.length() != LENGTH_8) {
|
|
|
|
+ throw new IllegalArgumentException("buildSendMsg length error");
|
|
|
|
+ }
|
|
StringBuffer m = new StringBuffer();
|
|
StringBuffer m = new StringBuffer();
|
|
m.append(PREFIX);
|
|
m.append(PREFIX);
|
|
m.append(simNum);
|
|
m.append(simNum);
|
|
m.append(ORN_SEND);
|
|
m.append(ORN_SEND);
|
|
- m.append(CMD_CLEAR_SIM_FAULT);
|
|
|
|
- m.append(faultType);
|
|
|
|
- m.append(CMD_DATA_PLACE_HOLDER);
|
|
|
|
|
|
+ m.append(cmd);
|
|
|
|
+ m.append(cmdId);
|
|
|
|
+ m.append(data);
|
|
m.append(SUFFIX);
|
|
m.append(SUFFIX);
|
|
- //
|
|
|
|
-
|
|
|
|
- //
|
|
|
|
- final String receiveMsg = send(m.toString());
|
|
|
|
- //
|
|
|
|
|
|
+ final String mFinal = m.toString();
|
|
|
|
+ if (mFinal.length() != LENGTH_20) {
|
|
|
|
+ throw new IllegalArgumentException("buildSendMsg length error");
|
|
|
|
+ }
|
|
|
|
+ return mFinal;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -173,8 +167,7 @@ public class IotService {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public String send(final String sendMsg) {
|
|
public String send(final String sendMsg) {
|
|
- logger.info("sendMsg");
|
|
|
|
- logger.info(sendMsg);
|
|
|
|
|
|
+ l.info("sendMsg = " + sendMsg);
|
|
String receiveMsg = null;
|
|
String receiveMsg = null;
|
|
try {
|
|
try {
|
|
if (cachedSocket == null) {
|
|
if (cachedSocket == null) {
|
|
@@ -193,8 +186,7 @@ public class IotService {
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
- logger.info("receiveMsg");
|
|
|
|
- logger.info(receiveMsg);
|
|
|
|
|
|
+ l.info("receiveMsg = " + receiveMsg);
|
|
return receiveMsg;
|
|
return receiveMsg;
|
|
}
|
|
}
|
|
|
|
|