|
@@ -59,16 +59,18 @@ import io.netty.handler.timeout.IdleStateEvent;
|
|
|
@Service("userHandler")
|
|
|
public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
public static final String CMD_STATUS = "01";//工作状态控制字;
|
|
|
- public static final String CMD_BUSY_PERIOD = "02";//工作忙状态周期
|
|
|
- public static final String CMD_IDLE_PERIOD = "03";//空闲状态周期
|
|
|
- public static final String CMD_TIME_FIX = "08";//网络时间校准
|
|
|
- public static final String CMD_NO_2G = "09";//NB切换2G阈值
|
|
|
- public static final String CMD_CLOSE_WTIME = "0C";//合模等待时间
|
|
|
- public static final String CMD_OPEN_WTIME = "0D";//开模等待时间1,单位1ms
|
|
|
- public static final String CMD_EEPROM = "0E";//重新上传EEPROM值
|
|
|
- public static final String CMD_WAITING_UPLOAD_TIME = "10";//待机上报时间
|
|
|
- public static final String CMD_COUNT = "12";//开合模总次数
|
|
|
- public static final String CMD_PURE_HEX = "100";//纯16进制指令,用户界面输入
|
|
|
+ public static final String CMD_BUSY_PERIOD = "02";//工作忙状态周期
|
|
|
+ public static final String CMD_IDLE_PERIOD = "03";//空闲状态周期
|
|
|
+ public static final String CMD_TIME_FIX = "08";//网络时间校准
|
|
|
+ public static final String CMD_NO_2G = "09";//NB切换2G阈值
|
|
|
+ public static final String CMD_DYNAMIC_ACCEL = "0A";//动态加速度阈值
|
|
|
+ public static final String CMD_STATIC_ACCEL = "0B";//静态加速度阈值
|
|
|
+ public static final String CMD_CLOSE_WTIME = "0C";//合模等待时间
|
|
|
+ public static final String CMD_OPEN_WTIME = "0D";//开模等待时间1,单位1ms
|
|
|
+ public static final String CMD_EEPROM = "0E";//重新上传EEPROM值
|
|
|
+ public static final String CMD_WAITING_UPLOAD_TIME = "10";//待机上报时间
|
|
|
+ public static final String CMD_COUNT = "12";//开合模总次数
|
|
|
+ public static final String CMD_PURE_HEX = "100";//纯16进制指令,用户界面输入
|
|
|
|
|
|
private static final Logger logger = Logger.getLogger(UserHandler.class);
|
|
|
|
|
@@ -118,7 +120,6 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
}
|
|
|
|
|
|
private String processMsg(String input) throws ParseException {
|
|
|
-// ScheduledExecutorService pool = Executors.newSingleThreadScheduledExecutor();
|
|
|
String ret = "FA AF 00 07 02 1e 78 1e 50 00 3C";
|
|
|
ret.replaceAll(" ", "");
|
|
|
logger.info("=====接收到======" + input);
|
|
@@ -130,16 +131,19 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
String deviceNum = "";
|
|
|
// 创建一个字符串集合用于存储由于粘包需要拆分后的报文
|
|
|
ret = input;
|
|
|
- //排重
|
|
|
+ //排重,1.5小时以内
|
|
|
RecDataLogExample logExp = new RecDataLogExample();
|
|
|
- logExp.createCriteria().andRecDataEqualTo(input);
|
|
|
- if (recDataLogMapper.countByExample(logExp) > 0) {
|
|
|
- logger.info("重复消息,不作处理!");
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ Date beforeDate = new Date();
|
|
|
+ beforeDate.setTime(beforeDate.getTime() - (long)1.5*3600*1000L);
|
|
|
+ logExp.createCriteria().andRecDataEqualTo(input).andIndateGreaterThan(beforeDate);
|
|
|
+ long duplicateCnt = recDataLogMapper.countByExample(logExp);
|
|
|
RecDataLog logItem = new RecDataLog();
|
|
|
logItem.setRecData(input);
|
|
|
recDataLogMapper.insertSelective(logItem);
|
|
|
+ if (duplicateCnt > 0) {
|
|
|
+ logger.info("重复消息,不作处理!");
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
List<String> strList = new ArrayList<>();
|
|
|
while (ret.length() > 0) {
|
|
|
String subStr = ret.substring(0,
|
|
@@ -241,11 +245,6 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
|
|
|
String crcStr = string.substring(string.length() - 4);
|
|
|
item.setCrcCode("" + reverseParseHex(crcStr));
|
|
|
- // 找寻上一条最新记录
|
|
|
- MouldHistoryExample mExp = new MouldHistoryExample();
|
|
|
- mExp.setOrderByClause("id desc limit 1");
|
|
|
- mExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo());
|
|
|
- List<MouldHistory> newList = mouldHistoryMapper.selectByExample(mExp);
|
|
|
// 存入数据库
|
|
|
mouldHistoryMapper.insertSelective(item);
|
|
|
// 模具开合记录
|
|
@@ -401,53 +400,52 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
List<EquipmentSendCommand> sendCommandLists = equipmentSendCommandMapper.selectByExample(escExample);
|
|
|
if(sendCommandLists.size()>0){
|
|
|
for (EquipmentSendCommand equipmentSendCommand : sendCommandLists) {
|
|
|
+ String pack = "";
|
|
|
+ String p = equipmentSendCommand.getParam();
|
|
|
switch (equipmentSendCommand.getCmd()) {
|
|
|
case CMD_STATUS:
|
|
|
+ if (p.length() == 1) {
|
|
|
+ p = "0" + p;
|
|
|
+ }
|
|
|
+ pack = getDownPackage(CMD_COUNT, "00 00 00 00 00 " + p);
|
|
|
break;
|
|
|
- case CMD_BUSY_PERIOD:
|
|
|
-
|
|
|
- break;
|
|
|
+ case CMD_BUSY_PERIOD://占10一位
|
|
|
case CMD_IDLE_PERIOD:
|
|
|
-
|
|
|
- break;
|
|
|
- case CMD_TIME_FIX:
|
|
|
-
|
|
|
- break;
|
|
|
case CMD_NO_2G:
|
|
|
-
|
|
|
- break;
|
|
|
- case CMD_CLOSE_WTIME:
|
|
|
-
|
|
|
+ case CMD_DYNAMIC_ACCEL:
|
|
|
+ case CMD_STATIC_ACCEL:
|
|
|
+ case CMD_WAITING_UPLOAD_TIME:
|
|
|
+ String hex = Integer.toHexString(Integer.parseInt(p));
|
|
|
+ if (hex.length() == 1) {
|
|
|
+ hex = "0" + hex;
|
|
|
+ }
|
|
|
+ pack = getDownPackage(CMD_COUNT, "00 00 00 00 00 " + hex);
|
|
|
break;
|
|
|
+ case CMD_CLOSE_WTIME://占9,10两位
|
|
|
case CMD_OPEN_WTIME:
|
|
|
-
|
|
|
- break;
|
|
|
- case CMD_EEPROM:
|
|
|
-
|
|
|
- break;
|
|
|
- case CMD_WAITING_UPLOAD_TIME:
|
|
|
-
|
|
|
+ hex = Integer.toHexString(Integer.parseInt(p));
|
|
|
+ for (int i=0;i<4-hex.length();i++) {
|
|
|
+ hex = "0" + hex;
|
|
|
+ }
|
|
|
+ pack = getDownPackage(CMD_COUNT, "00 00 00 00 " + hex.substring(2, 4) +" "+ hex.substring(0,2));
|
|
|
break;
|
|
|
- case CMD_COUNT:
|
|
|
- sendMsg(getDownPackage(CMD_COUNT, "00 00 00 00 00 00"));
|
|
|
- equipmentSendCommand.setIsSend(1);
|
|
|
- equipmentSendCommand.setSendTime(new Date());
|
|
|
- equipmentSendCommandMapper.updateByPrimaryKeySelective(equipmentSendCommand);
|
|
|
+ case CMD_COUNT://占7,8,9,10四位
|
|
|
+ hex = Integer.toHexString(Integer.parseInt(p));
|
|
|
+ for (int i=0;i<8-hex.length();i++) {
|
|
|
+ hex = "0" + hex;
|
|
|
+ }
|
|
|
+ hex = hex.substring(6,8) + " "+hex.substring(4,6) +" "+ hex.substring(2,4) +" "+ hex.substring(0,2);
|
|
|
+ pack = getDownPackage(CMD_COUNT, "00 00 " + hex);
|
|
|
break;
|
|
|
case CMD_PURE_HEX:
|
|
|
- String pack = equipmentSendCommand.getParam();
|
|
|
- System.out.println("下发16进制手动指令=="+pack);
|
|
|
- if (pack.contains(" ")) {
|
|
|
- pack = pack.replaceAll(" ", "");
|
|
|
- }
|
|
|
- sendMsg(pack);
|
|
|
- equipmentSendCommand.setIsSend(1);
|
|
|
- equipmentSendCommand.setSendTime(new Date());
|
|
|
- equipmentSendCommandMapper.updateByPrimaryKeySelective(equipmentSendCommand);
|
|
|
+ pack = equipmentSendCommand.getParam();
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ logger.info("下发16进制手动指令=="+pack);
|
|
|
+ sendMsg(pack);
|
|
|
+ equipmentSendCommand.setIsSend(1);
|
|
|
+ equipmentSendCommand.setSendTime(new Date());
|
|
|
+ equipmentSendCommandMapper.updateByPrimaryKeySelective(equipmentSendCommand);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -558,7 +556,6 @@ public class UserHandler extends SimpleChannelInboundHandler<String> {
|
|
|
|
|
|
private void handleModLogic(MouldHistory item, int avgTime, Integer thisOpenCount, Date lastOpenTime) {
|
|
|
logger.info("进了handleModLogic逻辑--");
|
|
|
- logger.info("item==>" + item);
|
|
|
TbMouldEquipmentExample meqExp = new TbMouldEquipmentExample();
|
|
|
meqExp.createCriteria().andEquipmentNoEqualTo(item.getEquipmentNo());
|
|
|
if (tbMouldEquipmentMapper.countByExample(meqExp) > 0) {
|