|
@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.sim.config.SimConfig;
|
|
|
import com.ruoyi.sim.domain.*;
|
|
|
+import com.ruoyi.sim.util.CRC16Modbus;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.slf4j.Logger;
|
|
@@ -258,6 +259,7 @@ public class CommSendService {
|
|
|
* @param re
|
|
|
*/
|
|
|
public void clearOneSimAllFaultByExam(RealExam re) {
|
|
|
+ l.info("清除exam = {}", re);
|
|
|
// check
|
|
|
|
|
|
// 更新Exam状态。
|
|
@@ -266,11 +268,14 @@ public class CommSendService {
|
|
|
}
|
|
|
//
|
|
|
List<RealExamFault> list = realExamFaultService.listAllType2InitStateByExamId(re.getExamId());
|
|
|
+ if (list != null) {
|
|
|
+ l.info("清除exam list = {}", list.size());
|
|
|
+ }
|
|
|
list.forEach(ref -> {
|
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
|
if (faultService.isDisable(f.getFaultId())) {
|
|
|
- l.warn("故障 {} -Disable", f.getName());
|
|
|
- return;
|
|
|
+ l.warn("故障 {} -被禁用", f.getName());
|
|
|
+ throw new IllegalArgumentException("故障被禁用");
|
|
|
}
|
|
|
Sim s = simService.selectSimBySimId(re.getSimId());
|
|
|
// check
|
|
@@ -328,11 +333,11 @@ public class CommSendService {
|
|
|
* debug清除所有故障
|
|
|
*
|
|
|
* @param simNum
|
|
|
- * @param simType
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<SimMsg> debugClearAllFault(final String simNum, String simType) {
|
|
|
+ public List<SimMsg> debugClearAllFault(final String simNum) {
|
|
|
List<SimMsg> list = new ArrayList<>();
|
|
|
+ String simType = simService.uniqueBySimNum(simNum).getSimType();
|
|
|
for (String b : getGZBWBySimType(simType)) {
|
|
|
list.add(debugClearOneFault(simNum, b));
|
|
|
}
|
|
@@ -384,12 +389,12 @@ public class CommSendService {
|
|
|
* debug下发所有故障
|
|
|
*
|
|
|
* @param simNum
|
|
|
- * @param simType
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public List<SimMsg> debugWriteAllFault(final String simNum, String simType) {
|
|
|
+ public List<SimMsg> debugWriteAllFault(final String simNum) {
|
|
|
List<SimMsg> list = new ArrayList<>();
|
|
|
+ String simType = simService.uniqueBySimNum(simNum).getSimType();
|
|
|
for (String b : getGZBWBySimType(simType)) {
|
|
|
list.add(debugWriteOneFault(simNum, b));
|
|
|
}
|
|
@@ -481,12 +486,12 @@ public class CommSendService {
|
|
|
* debug读取全部故障位置数据
|
|
|
*
|
|
|
* @param simNum
|
|
|
- * @param simType
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public List<SimMsg> debugReadAllFaultResistance(final String simNum, final String simType) {
|
|
|
+ public List<SimMsg> debugReadAllFaultResistance(final String simNum) {
|
|
|
List<SimMsg> list = new ArrayList<>();
|
|
|
+ String simType = simService.uniqueBySimNum(simNum).getSimType();
|
|
|
for (String b : getGZBWBySimType(simType)) {
|
|
|
list.add(debugReadOneFaultResistance(simNum, b));
|
|
|
}
|
|
@@ -579,23 +584,38 @@ public class CommSendService {
|
|
|
simService.updateSimStateBySimId(s.getSimId(), Sim.State.SIM_OFFLINE);
|
|
|
failCountClearOne(s.getSimId());
|
|
|
}
|
|
|
- // 进行重试
|
|
|
// 先考虑一台模拟器演示。
|
|
|
+ // 进行重试 start
|
|
|
if (sm.getRetryCount() == RETRY_COUNT_0) {
|
|
|
- l.warn("####RetryTotalCount不重试#### = {}", sm);
|
|
|
+ l.warn("####RetryTotalCount不重试RETRY_COUNT_0#### = {}", sm);
|
|
|
return sm;
|
|
|
}
|
|
|
if (sm.getRetryCount() < retryTotalCount) {
|
|
|
sm.retryCountPlus1();
|
|
|
send(sm, s, retryTotalCount, sleep);
|
|
|
- } else {
|
|
|
l.warn("####RetryTotalCount重试#### = {}", sm);
|
|
|
+ } else {
|
|
|
+ l.warn("####RetryTotalCount达到重试上限#### = {}", sm);
|
|
|
}
|
|
|
+ // 进行重试 end
|
|
|
}
|
|
|
return sm;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * todo:
|
|
|
+ *
|
|
|
+ * @param sm
|
|
|
+ * @param s
|
|
|
+ * @param retryTotalCount
|
|
|
+ * @param sleep
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public SimMsg sendRetry(final SimMsg sm, final Sim s, final int retryTotalCount, final long sleep) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* cachedSocket is ok
|
|
|
*
|
|
|
* @return
|
|
@@ -665,24 +685,6 @@ public class CommSendService {
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
- public byte[] hexStrToByteArrs(String hexString) {
|
|
|
-// if (StringUtils.isEmpty(hexString)) {
|
|
|
-// return null;
|
|
|
-// }
|
|
|
- hexString = hexString.replaceAll(" ", "");
|
|
|
- int len = hexString.length();
|
|
|
- int index = 0;
|
|
|
-
|
|
|
- byte[] bytes = new byte[len / 2];
|
|
|
-
|
|
|
- while (index < len) {
|
|
|
- String sub = hexString.substring(index, index + 2);
|
|
|
- bytes[index / 2] = (byte) Integer.parseInt(sub, 16);
|
|
|
- index += 2;
|
|
|
- }
|
|
|
- return bytes;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 等同于ping命令。
|
|
|
*
|
|
@@ -694,7 +696,7 @@ public class CommSendService {
|
|
|
InetAddress ia = null;
|
|
|
try {
|
|
|
ia = InetAddress.getByName(ipV4);
|
|
|
- return ia.isReachable(2000);
|
|
|
+ return ia.isReachable(2048);
|
|
|
} catch (UnknownHostException e) {
|
|
|
e.printStackTrace();
|
|
|
return false;
|
|
@@ -727,4 +729,56 @@ public class CommSendService {
|
|
|
private void failCountClearAll() {
|
|
|
map.clear();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * https://mvnrepository.com/artifact/com.infiniteautomation/modbus4j/3.0.3
|
|
|
+ */
|
|
|
+ public void test02() {
|
|
|
+ byte[] data = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02}; // 示例数据
|
|
|
+ // int crc = ModbusUtils.calculateCRC(data);
|
|
|
+ // System.out.println("CRC-16/MODBUS 校验值: " + Integer.toHexString(crc));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static byte[] hexStrToByteArrs(String hexString) {
|
|
|
+// if (StringUtils.isEmpty(hexString)) {
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+ hexString = hexString.replaceAll(" ", "");
|
|
|
+ int len = hexString.length();
|
|
|
+ int index = 0;
|
|
|
+
|
|
|
+ byte[] bytes = new byte[len / 2];
|
|
|
+
|
|
|
+ while (index < len) {
|
|
|
+ String sub = hexString.substring(index, index + 2);
|
|
|
+ bytes[index / 2] = (byte) Integer.parseInt(sub, 16);
|
|
|
+ index += 2;
|
|
|
+ }
|
|
|
+ return bytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String logBytesToString(byte[] bytes) {
|
|
|
+ if (bytes == null || bytes.length == 0) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ StringBuffer sbHex = new StringBuffer();
|
|
|
+ byte[] buffer = new byte[bytes.length];
|
|
|
+ for (int i = 0; i < bytes.length; i++) {
|
|
|
+ sbHex.append(String.format("%02X", buffer[i]));
|
|
|
+ }
|
|
|
+ return sbHex.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String bytesToHexV2(byte[] bytes) {
|
|
|
+ StringBuilder hexString = new StringBuilder();
|
|
|
+ for (byte b : bytes) {
|
|
|
+ String hex = Integer.toHexString(0xFF & b); // 将字节转换为十六进制字符串
|
|
|
+ if (hex.length() == 1) {
|
|
|
+ hexString.append('0'); // 如果是单个字符,补零
|
|
|
+ }
|
|
|
+ hexString.append(hex);
|
|
|
+ }
|
|
|
+ return hexString.toString();
|
|
|
+ }
|
|
|
}
|