package com.northglass.service.message;
|
|
import java.util.Date;
|
import java.util.List;
|
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.northglass.constants.ShelfTaskType;
|
import com.northglass.constants.StateConstants.LoadMachineRackState;
|
import com.northglass.constants.StateConstants.LoadMachineTaskState;
|
import com.northglass.constants.StateConstants.ShelfRankState;
|
import com.northglass.constants.StateConstants.ShelfTaskState;
|
import com.northglass.entity.LoadMachine;
|
import com.northglass.entity.LoadMachineRack;
|
import com.northglass.entity.LoadMachineTask;
|
import com.northglass.entity.MeasureMachine;
|
import com.northglass.entity.OptPattern;
|
import com.northglass.entity.RawPackage;
|
import com.northglass.entity.ShelfRank;
|
import com.northglass.entity.ShelfTask;
|
import com.northglass.repository.LoadMachineRackDao;
|
import com.northglass.repository.LoadMachineTaskDao;
|
import com.northglass.repository.OptPatternDao;
|
import com.northglass.repository.RawPackageDao;
|
import com.northglass.repository.ShelfTaskDao;
|
import com.northglass.service.loadmachine.LoadMachineService;
|
import com.northglass.service.shelf.ShelfService;
|
import com.northglass.service.shelfrank.ShelfRankService;
|
import com.northglass.util.HexUtil;
|
|
@Component
|
@Transactional
|
public class MeasureMachineMessageProcessor extends AbstractMessageProcessor {
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(MeasureMachineMessageProcessor.class);
|
@Autowired
|
private LoadMachineService loadMachineService;
|
|
@Autowired
|
private ShelfService shelfService;
|
|
@Autowired
|
private ShelfRankService shelfRankService;
|
|
@Autowired
|
private RawPackageDao rawPackageDao;
|
|
@Autowired
|
private OptPatternDao optPatternDao;
|
|
@Autowired
|
private LoadMachineTaskDao loadMachineTaskDao;
|
|
@Autowired
|
private ShelfTaskDao shelfTaskDao;
|
|
@Autowired
|
private LoadMachineRackDao loadMachineRackDao;
|
|
private boolean sendingGlass = false;
|
|
private OptPattern waitoptPattern = null;
|
|
private LoadMachineRack loadMachineRackTwo = null;
|
|
private RawPackage currentRawPackageTwo = null;
|
|
private ShelfRank shelfRank = null;
|
|
// 请求信号
|
private static final int TASK_ASK_START = 18;
|
private static final int TASK_ASK_END = 21;
|
// 请求ID
|
private static final int TASK_ASK_TD_START = 22;
|
private static final int TASK_ASK_ID_END = 25;
|
|
// 任务汇报字
|
private static final int TASK_FINISH_PLC_START = 38;
|
private static final int TASK_FINISH_PLC_END = 41;
|
|
// 任务汇报ID
|
private static final int TASK_FINISH_PLC_ID_START = 42;
|
private static final int TASK_FINISH_PLC_ID_END = 45;
|
|
// 任务发送字
|
private static final int TASK_MES_START = 58;
|
private static final int TASK_MES_END = 61;
|
|
// 任务确认字
|
private static final int TASK_SURE_START = 98;
|
private static final int TASK_SURE_END = 101;
|
|
// 任务报警字
|
private static final int TASK_WARN_START = 138;
|
private static final int TASK_WARN_END = 141;
|
|
// 完成步骤
|
private static final int FINISH_STEP_START = 178;
|
private static final int FINISH_STEP_END = 181;
|
|
/**
|
* 解析16进制消息,转译为描述信息
|
*
|
* @param messageHex
|
* @return
|
*/
|
public String parse(String messageHex) {
|
LOGGER.trace("> Start parse");
|
|
if (messageHex.length() < 84) {
|
return "无效消息:" + messageHex;
|
}
|
|
String startSign = messageHex.substring(START_SIGN_START, START_SIGN_END + 1);
|
if (!startSign.equals("3c5354413e")) {
|
return "无效消息:" + messageHex;
|
}
|
|
StringBuffer messageDescription = new StringBuffer();
|
|
// 消息长度
|
messageDescription.append(parseInt(messageHex, MESSAGE_LENGTH_START, MESSAGE_LENGTH_END, "消息长度"));
|
|
// 订单编号
|
messageDescription.append(parseString(messageHex, ORDER_NUMBER_START, ORDER_NUMBER_END, "订单编号"));
|
|
// 功能号
|
messageDescription.append(parseString(messageHex, FUNCTION_NUMBER_START, FUNCTION_NUMBER_END, "功能号"));
|
|
// 加密方式
|
messageDescription.append(parseString(messageHex, ENCRYPT_START, ENCRYPT_END, "加密方式"));
|
|
// 发送时刻
|
messageDescription.append(parseTime(messageHex, SEND_TIME_START, SEND_TIME_END, "发送时刻"));
|
|
// 解析数据区
|
messageDescription.append(parseData(messageHex));
|
|
// LOGGER.trace("> End parse");
|
return messageDescription.toString();
|
}
|
|
private String parseData(String messageHex) {
|
return "无法解析数据区";
|
}
|
|
public String generateReturnMessage(String sendMessageHex, MeasureMachine measureMachine) {
|
LOGGER.debug("收到测量台的信息:" + sendMessageHex);
|
if (sendMessageHex.length() == 24) {
|
String string = sendMessageHex.substring(8, 15);
|
if (string.equals("00060010")) {
|
LOGGER.debug("上次消息发送成功!");
|
return "";
|
} else {
|
LOGGER.debug("上次消息发送失败!");
|
return "";
|
}
|
} else if (sendMessageHex.length() == 198) {
|
// 请求信号
|
String taskAsk = sendMessageHex.substring(TASK_ASK_START, TASK_ASK_END + 1);
|
// 请求ID
|
String taskIdAsk = sendMessageHex.substring(TASK_ASK_TD_START, TASK_ASK_ID_END + 1);
|
// 任务汇报字
|
String taskFinish = sendMessageHex.substring(TASK_FINISH_PLC_START, TASK_FINISH_PLC_END + 1);
|
// 任务汇报字ID
|
String taskFinishId = sendMessageHex.substring(TASK_FINISH_PLC_ID_START, TASK_FINISH_PLC_ID_END + 1);
|
// 任务发送字
|
String taskMes = sendMessageHex.substring(TASK_MES_START, TASK_MES_END + 1);
|
// 任务确认字
|
String taskSure = sendMessageHex.substring(TASK_SURE_START, TASK_SURE_END + 1);
|
// 任务报警字
|
String taskWarning = sendMessageHex.substring(TASK_WARN_START, TASK_WARN_END + 1);
|
// 完成步骤
|
String finishStep = sendMessageHex.substring(FINISH_STEP_START, FINISH_STEP_END + 1);
|
LOGGER.debug("请求信号:" + taskAsk + "| 请求ID:" + taskIdAsk + "| 任务汇报字:" + taskFinish + "| 任务汇报字ID:"
|
+ taskFinishId + "| 任务发送字:" + taskMes + "| 任务确认字:" + taskSure + "| 任务报警字:" + taskWarning + "| 完成步骤:"
|
+ finishStep);
|
// LOGGER.debug("请求ID:"+taskIdAsk);
|
// LOGGER.debug("任务汇报字:"+taskFinish);
|
// LOGGER.debug("任务汇报字ID:"+taskFinishId);
|
// LOGGER.debug("任务发送字:"+taskMes);
|
// LOGGER.debug("任务确认字:"+taskSure);
|
// LOGGER.debug("任务报警字:"+taskWarning);
|
// LOGGER.debug("完成步骤:"+finishStep);
|
// 获取上片机正在执行的任务
|
// 收到请求
|
//测量台结束产生我们需要的数据
|
if (taskFinish.equals("0001")) {
|
|
} else if (taskFinish.equals("0000")) {
|
|
}
|
|
return "";
|
} else {
|
LOGGER.debug("接收的信息和设置的不一致,请查找原因,长度为:" + sendMessageHex.length());
|
return "";
|
}
|
}
|
|
/**
|
* 消息发送
|
*
|
* @param task
|
* @return
|
*/
|
private String sendMessage(String senddate, String address) {
|
String Herd = "0010" + address;
|
int length = senddate.length() / 4;
|
String dates = Herd + HexUtil.intTo2ByteHex(length) + HexUtil.intTo1ByteHex(length * 2) + senddate;
|
int lengths = dates.length() / 2;
|
String date = "00000000" + HexUtil.intTo2ByteHex(lengths) + dates;
|
LOGGER.debug("发送信息内容:" + date);
|
return date;
|
}
|
}
|