|
@@ -4,7 +4,6 @@ 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;
|
|
@@ -220,7 +219,7 @@ public class CommSendService {
|
|
|
return;
|
|
|
}
|
|
|
if (Sim.State.DISABLE.equals(s.getSimState())) {
|
|
|
- l.warn("sim DISABLE sim = {}", s);
|
|
|
+ l.warn("sim DISABLE,模拟器被禁用,sim = {}", s);
|
|
|
return;
|
|
|
}
|
|
|
if (StringUtils.isBlank(s.getSimType()) || StringUtils.isBlank(s.getSimNum())) {
|
|
@@ -232,7 +231,7 @@ public class CommSendService {
|
|
|
SimMsg smR = send(smS, s, RETRY_COUNT_0, SLEEP_SHORT);
|
|
|
if (StringUtils.isNotBlank(smR.getReceiveMsg())) {
|
|
|
l.info("isNotBlank");
|
|
|
- failCountClearOne(s.getSimId());
|
|
|
+ commFailCountClearOne(s.getSimId());
|
|
|
}
|
|
|
simReceiveService.checkOneSimState(smR, s);
|
|
|
}
|
|
@@ -259,7 +258,7 @@ public class CommSendService {
|
|
|
* @param re
|
|
|
*/
|
|
|
public void clearOneSimAllFaultByExam(RealExam re) {
|
|
|
- l.info("清除exam = {}", re);
|
|
|
+ l.info("clearOneSimAllFaultByExam = {}", re);
|
|
|
// check
|
|
|
|
|
|
// 更新Exam状态。
|
|
@@ -350,7 +349,8 @@ public class CommSendService {
|
|
|
* @param f
|
|
|
*/
|
|
|
public void clearOneSimOneFault(Sim s, RealExamFault reF, Fault f) {
|
|
|
- l.info("清除One故障:getSimNum = {},fault.getName = {}", s.getSimNum(), f.getName());
|
|
|
+ l.info("clearOneSimOneFault 清除One故障:getSimNum = {},getBindHardwareMsg = {},fault.getName = {}",
|
|
|
+ s.getSimNum(), f.getBindHardwareMsg(), f.getName());
|
|
|
// check todo:
|
|
|
|
|
|
// step1
|
|
@@ -449,6 +449,56 @@ public class CommSendService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查读取。
|
|
|
+ *
|
|
|
+ * @param s
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public AjaxResult readOneSimAllFaultCheck(Sim s) {
|
|
|
+ Fault q = new Fault();
|
|
|
+ q.setFaultType(Fault.Type.REAL_GZBW);
|
|
|
+ q.setSimType(s.getSimType());
|
|
|
+ List<Fault> list = faultService.selectFaultList(q);
|
|
|
+ List<Fault> listNG = new ArrayList<>();
|
|
|
+ for (Fault f : list) {
|
|
|
+ AjaxResult ar = readOneSimOneFaultCheck(s, f);
|
|
|
+ if (ar.isError()) {
|
|
|
+ listNG.add(f);
|
|
|
+ l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;");
|
|
|
+ } else {
|
|
|
+ l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]安装ok;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (listNG.isEmpty()) {
|
|
|
+ return AjaxResult.success("所有故障部位检查没有问题。");
|
|
|
+ }
|
|
|
+ StringBuilder sbNG = new StringBuilder();
|
|
|
+ for (Fault f : listNG) {
|
|
|
+ sbNG.append("[" + f.getReplaceName() + "]零件异常;<br>");
|
|
|
+ }
|
|
|
+ sbNG.append("请检查后重新开始考试!");
|
|
|
+ return AjaxResult.error(sbNG.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查读取。
|
|
|
+ *
|
|
|
+ * @param s
|
|
|
+ * @param f
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public AjaxResult readOneSimOneFaultCheck(Sim s, Fault f) {
|
|
|
+ SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(s.getSimNum(), f.getBindHardwareMsg());
|
|
|
+ SimMsg sm2 = send(sm1, s, RETRY_COUNT_CHECK_ONE_FAULT, SLEEP_LONG);
|
|
|
+ return simReceiveService.getOneFaultCheck(sm2, s, f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 第一次读取,作为出题值。
|
|
|
+ *
|
|
|
+ * @param re
|
|
|
+ */
|
|
|
public void readOneSimAllFaultFirstTime(RealExam re) {
|
|
|
List<RealExamFault> list = realExamFaultService.listAllType2(re.getExamId());
|
|
|
for (RealExamFault ref : list) {
|
|
@@ -458,12 +508,19 @@ public class CommSendService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 第一次读取,作为出题值。
|
|
|
+ *
|
|
|
+ * @param s
|
|
|
+ * @param ref
|
|
|
+ * @param f
|
|
|
+ */
|
|
|
public void readOneSimOneFaultFirstTime(Sim s, RealExamFault ref, Fault f) {
|
|
|
// 读取一次当前电阻代表值作为出题值。
|
|
|
- SimMsg smB1 = commBuildService.buildSendMsgReadFaultResistance(s.getSimNum(), f.getBindHardwareMsg());
|
|
|
- SimMsg smB2 = send(smB1, s, RETRY_COUNT_WRITE_ONE_FAULT, SLEEP_LONG);
|
|
|
+ SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(s.getSimNum(), f.getBindHardwareMsg());
|
|
|
+ SimMsg sm2 = send(sm1, s, RETRY_COUNT_WRITE_ONE_FAULT, SLEEP_LONG);
|
|
|
if (ref != null) {
|
|
|
- simReceiveService.setFaultQuestionValue(smB2, s, ref, f);
|
|
|
+ simReceiveService.setFaultQuestionValue(sm2, s, ref, f);
|
|
|
} else {
|
|
|
l.info("ref is null");
|
|
|
}
|
|
@@ -579,10 +636,10 @@ public class CommSendService {
|
|
|
} catch (InterruptedException | IOException e) { // SocketTimeoutException
|
|
|
e.printStackTrace();
|
|
|
// 失败计数
|
|
|
- boolean limit = failCountAdd1(Objects.requireNonNull(s).getSimId());
|
|
|
+ boolean limit = commFailCountAdd1(Objects.requireNonNull(s).getSimId());
|
|
|
if (limit) {
|
|
|
- simService.updateSimStateBySimId(s.getSimId(), Sim.State.SIM_OFFLINE);
|
|
|
- failCountClearOne(s.getSimId());
|
|
|
+ simService.updateSimStateBySimId(s.getSimId(), Sim.State.OFFLINE);
|
|
|
+ commFailCountClearOne(s.getSimId());
|
|
|
}
|
|
|
// 先考虑一台模拟器演示。
|
|
|
// 进行重试 start
|
|
@@ -643,7 +700,7 @@ public class CommSendService {
|
|
|
l.info("openSocket cachedSocket is not ok!new socket!");
|
|
|
cachedSocket = new Socket(config.getRs485Ip(), config.getRs485Port());
|
|
|
cachedSocket.setSoTimeout(SOCKET_TIME_OUT);
|
|
|
- failCountClearAll();
|
|
|
+ commFailCountClearAll();
|
|
|
} else {
|
|
|
l.info("openSocket cachedSocket is ok!");
|
|
|
}
|
|
@@ -680,7 +737,7 @@ public class CommSendService {
|
|
|
return AjaxResult.success("closeSocket IOException");
|
|
|
} finally {
|
|
|
cachedSocket = null;
|
|
|
- failCountClearAll();
|
|
|
+ commFailCountClearAll();
|
|
|
}
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
@@ -712,7 +769,7 @@ public class CommSendService {
|
|
|
* @param simId
|
|
|
* @return true超过通信失败次数限制
|
|
|
*/
|
|
|
- private boolean failCountAdd1(long simId) {
|
|
|
+ private boolean commFailCountAdd1(long simId) {
|
|
|
l.info("map.containsKey(simId) = {}", map.containsKey(simId));
|
|
|
if (map.containsKey(simId)) {
|
|
|
map.put(simId, map.get(simId) + 1);
|
|
@@ -722,11 +779,11 @@ public class CommSendService {
|
|
|
return (map.get(simId) >= OFFLINE_LIMIT);
|
|
|
}
|
|
|
|
|
|
- private void failCountClearOne(long simId) {
|
|
|
+ private void commFailCountClearOne(long simId) {
|
|
|
map.remove(simId);
|
|
|
}
|
|
|
|
|
|
- private void failCountClearAll() {
|
|
|
+ private void commFailCountClearAll() {
|
|
|
map.clear();
|
|
|
}
|
|
|
|