package com.ld.igds.protocol.zldz.analysis;
|
|
import com.ld.igds.common.CoreSerService;
|
import com.ld.igds.constant.BizType;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.constant.RedisConst;
|
import com.ld.igds.grain.dto.GrainSerCableData;
|
import com.ld.igds.io.notify.NotifyWebInvoker;
|
import com.ld.igds.io.constant.OrderRespEnum;
|
import com.ld.igds.io.request.GrainSerConfRequest;
|
import com.ld.igds.models.DeviceSer;
|
import com.ld.igds.protocol.zldz.analysis.message.ReMessage;
|
import com.ld.igds.protocol.zldz.command.BaseRemoteImpl;
|
import com.ld.igds.protocol.zldz.command.builder.CommandBuilder8829;
|
import com.ld.igds.protocol.zldz.command.message.Message;
|
import com.ld.igds.protocol.zldz.task.CommandReSendService;
|
import com.ld.igds.protocol.zldz.util.ServerUtils;
|
import com.ld.igds.util.BytesUtil;
|
import com.ld.igds.util.RedisUtil;
|
import com.ld.igds.view.manager.TempManager;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author vince
|
*/
|
@Slf4j
|
@Component(AnalysisConf.BEAN_ID)
|
public class AnalysisConf extends BaseRemoteImpl {
|
|
public static final String BEAN_ID = "zldz.analysisConf";
|
|
@Autowired
|
private NotifyWebInvoker notifyWebInvoker;
|
|
@Autowired
|
private CoreSerService serService;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private TempManager thManager;
|
|
@Autowired
|
private CommandReSendService commandReSendService;
|
|
/**
|
* 解析分机配置信息
|
*
|
* @param message
|
* @param ser
|
*/
|
public void analysis8816(ReMessage message, DeviceSer ser) {
|
|
log.debug("分机---->>>平台:消息类型=8816----{}-{}.{}", ser.getCompanyId(),
|
ser.getIp(), ser.getPort());
|
|
// 清除缓存
|
commandReSendService.cleanKey(message.getCompanyId(), message.getIp(),
|
message.getPort(), ServerUtils.MSG_TYPE_8816);
|
|
// 清楚初始化登陆的解析
|
commandReSendService.cleanKey(ServerUtils.DEFAULT_COMPANY,
|
message.getIp(), message.getPort(), ServerUtils.MSG_TYPE_8816);
|
|
ser.setStatus(Constant.YN_Y);
|
|
String content = message.getBody().getContent();
|
|
// 读写标志
|
int start = 0, len = 1;
|
String temp = content.substring(start * 2, start * 2 + len * 2);
|
int readTag = BytesUtil.hexToInt(temp);
|
|
// 设备ID,全局唯一
|
start = 1;
|
len = 2;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
|
// 网络ID
|
start = 3;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
|
// 信道
|
start = 4;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
|
// 速率
|
start = 5;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
|
// 层数
|
start = 6;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
ser.setCableZ(BytesUtil.hexToInt(temp));
|
|
// 行数
|
start = 7;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
ser.setCableY(BytesUtil.hexToInt(temp));
|
|
// 列数
|
start = 8;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
ser.setCableX(BytesUtil.hexToInt(temp));
|
|
// 电缆制式
|
start = 9;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
ser.setCableFormat("0" + BytesUtil.hexToInt(temp));
|
|
// 电缆类型
|
start = 10;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
ser.setCableType("0" + BytesUtil.hexToInt(temp));
|
|
// 供电模式
|
start = 11;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
ser.setPowerModel("0" + BytesUtil.hexToInt(temp));
|
|
String msg = ser.getName() + " 远程获取配置成功,请刷新数据查看!";
|
|
// 组织编码
|
start = 12;
|
temp = content.substring(start * 2);
|
if (readTag == 1) {// 表示写的成功返回
|
ser.setOrgId(ser.getCompanyId());
|
msg = ser.getName() + " 远程写入成功,请刷新数据查看!";
|
} else {
|
ser.setOrgId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + "");
|
}
|
|
if (null == ser.getSn()) {
|
ser.setSn(ser.getId());
|
}
|
ser.setIp(message.getIp());
|
ser.setPort(message.getPort());
|
|
// 开始列默认=1
|
if (ser.getCableStart() == 0) {
|
ser.setCableStart(1);
|
}
|
|
log.info("分机---->>>平台:分机配置解析完成----{}-{}-{}-{},更新到服服务器",
|
ser.getCompanyId(), ser.getIp(), ser.getPort(), ser.getName());
|
serService.updateSerById(ser);
|
|
// 更新会话信息
|
super.updateSession(ser.getIp(), ser.getPort(), ser.getCompanyId());
|
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(),
|
OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg);
|
|
//分机上线进行一次温湿度采集
|
thManager.checkThBySer(ser.getCompanyId(), ser.getId());
|
}
|
|
/**
|
* 电缆初始化成功
|
*
|
* @param reMessage
|
* @param ser
|
*/
|
public void analysis8822(ReMessage reMessage, DeviceSer ser) {
|
log.debug("-----------analysis8822------------{}-{}.{}",
|
ser.getCompanyId(), ser.getIp(), ser.getPort());
|
|
// 清除缓存
|
commandReSendService.cleanKey(reMessage.getCompanyId(),
|
reMessage.getIp(), reMessage.getPort(),
|
ServerUtils.MSG_TYPE_8822);
|
|
String msg = ser.getName() + " 初始化电缆完成!!";
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(),
|
OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg);
|
}
|
|
/**
|
* 电缆修改返回,
|
*
|
* @param reMessage
|
* @param ser
|
*/
|
public void analysis8826(ReMessage reMessage, DeviceSer ser) {
|
log.debug("-----------analysis8826------------{}-{}.{}",
|
ser.getCompanyId(), ser.getIp(), ser.getPort());
|
|
// 清除缓存
|
commandReSendService.cleanKey(reMessage.getCompanyId(),
|
reMessage.getIp(), reMessage.getPort(),
|
ServerUtils.MSG_TYPE_8826);
|
|
String msg = ser.getName() + " 电缆修改操作完成";
|
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(),
|
OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg);
|
}
|
|
/**
|
* 通道电缆获取返回,分机返回收到命令信息,实际返回值在8829中说明
|
*
|
* @param reMessage
|
* @param ser
|
*/
|
public void analysis8825(ReMessage reMessage, DeviceSer ser) {
|
|
log.debug("-----------analysis8825------------{}-{}.{}",
|
ser.getCompanyId(), ser.getIp(), ser.getPort());
|
|
// 清除缓存
|
commandReSendService.cleanKey(reMessage.getCompanyId(),
|
reMessage.getIp(), reMessage.getPort(),
|
ServerUtils.MSG_TYPE_8825);
|
|
String msg = ser.getName() + " 读取通道电缆开始返回";
|
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(),
|
OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg);
|
|
}
|
|
/**
|
* 终端发送通道电缆数据给后台,分机主动推送
|
*
|
* @param reMessage
|
* @param ser
|
*/
|
@SuppressWarnings("unchecked")
|
public void analysis1129(ReMessage reMessage, DeviceSer ser) {
|
|
// 开始解析
|
String content = reMessage.getBody().getContent();
|
|
// 通道号
|
int start = 0, len = 1;
|
String temp = content.substring(start * 2, start * 2 + len * 2);
|
int passCode = BytesUtil.hexToInt(temp);
|
|
// 点序号,按照返回顺序填写从1开始
|
start = 1;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
int iotNum = BytesUtil.hexToInt(temp);
|
|
// 总包数
|
start = 2;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
int sumPacket = BytesUtil.hexToInt(temp);
|
|
// 当前包
|
start = 3;
|
len = 1;
|
temp = content.substring(start * 2, start * 2 + len * 2);
|
int curPacket = BytesUtil.hexToInt(temp);
|
|
// -----------后端通知终端收到信息----------------------//
|
GrainSerConfRequest request = new GrainSerConfRequest();
|
request.setSerId(ser.getId());
|
request.setBizType(BizType.SYS.getCode());
|
request.setIp(ser.getIp());
|
request.setPort(ser.getPort());
|
request.setCompanyId(ser.getCompanyId());
|
request.setValue1(curPacket);
|
|
Message message = CommandBuilder8829.getInstance()
|
.buildMessage(request);
|
log.info("平台------>>>分机:" + request.getSerName() + "后台收到电缆数据应答="
|
+ message.toString());
|
// 发送命令
|
send(request.getIp(), request.getPort(), message.getByteMsg());
|
|
// -----------后端通知终端收到信息 EDN----------------------//
|
|
log.info("分机------>>>平台:返回电缆信息,分机={},当前包:{},信息={}", ser.getName(),
|
curPacket, content);
|
|
// 详细信息,每长度5为一组数据
|
start = 4;
|
temp = content.substring(start * 2);
|
|
String redisKey = RedisConst.buildKey(ser.getCompanyId(),
|
RedisConst.KEY_TEMP_PREFIX, "CABLE_DATA_" + ser.getId() + "_"
|
+ passCode);
|
|
List<GrainSerCableData> dataList = null;
|
if (curPacket != 1) {
|
dataList = (List<GrainSerCableData>) redisUtil.get(redisKey);
|
}
|
if (null == dataList)
|
dataList = new ArrayList<>();
|
|
GrainSerCableData data;
|
|
String str1 = temp.substring(0, 160);// 温度点 40个
|
String str2 = temp.substring(160, 400);// 1个根号,1个点号,1个配置,功能40组
|
String temp1, temp2;
|
for (int i = 0; i < 40; i++) {
|
data = new GrainSerCableData();
|
data.setPassCode(passCode);
|
data.setIotNum(i + 1);
|
data.setReceiveDate(new Date());
|
//data.setPointIndex(dataList.size() + i + 1);
|
|
// 温度
|
temp1 = str1.substring(i * 4, i * 4 + 4);
|
data.setTemp(BytesUtil.hexToInt(BytesUtil.tran_LH(temp1)) / 10.0);
|
|
//根号
|
temp2 = str2.substring(i * 6, i * 6 + 6);
|
data.setRootIndex(BytesUtil.hexToInt(temp2.substring(0, 2)));
|
|
//点号
|
data.setPointIndex(BytesUtil.hexToInt(temp2.substring(2, 4)));
|
|
//配置
|
data.setConf(temp2.substring(4, 6));
|
|
dataList.add(data);
|
}
|
|
// 存放緩存
|
redisUtil.set(redisKey, dataList, 5 * 60);
|
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(),
|
OrderRespEnum.MSG_SUCCESS, BizType.SYS, "系统收到电缆配置信息,请手动刷新,分机="
|
+ ser.getName() + ",通道=" + passCode + ",总包="
|
+ sumPacket + ",当前包=" + curPacket);
|
}
|
|
/**
|
* 电缆汇总应答
|
*
|
* @param reMessage
|
* @param ser
|
*/
|
public void analysis8823(ReMessage reMessage, DeviceSer ser) {
|
// 开始解析
|
String content = reMessage.getBody().getContent();
|
|
// 动态拼接对象
|
List<GrainSerCableData> dataList = new ArrayList<GrainSerCableData>();
|
String tempStr;
|
GrainSerCableData cableData;
|
for (int i = 0; i < content.length() / 4; i++) {
|
tempStr = content.substring(i * 4, i * 4 + 4);
|
cableData = new GrainSerCableData();
|
cableData.setPassCode(i + 1);
|
cableData.setReceiveDate(new Date());
|
cableData.setIotNum(BytesUtil.hexToInt(tempStr.substring(0, 2)));
|
cableData.setIotErrNum(BytesUtil.hexToInt(tempStr.substring(2, 4)));
|
|
dataList.add(cableData);
|
}
|
|
String redisKey = RedisConst.buildKey(ser.getCompanyId(),
|
RedisConst.KEY_TEMP_PREFIX, "CABLE_DATA_" + ser.getId());
|
|
// 存放緩存
|
redisUtil.set(redisKey, dataList, 5 * 60);
|
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(),
|
OrderRespEnum.MSG_SUCCESS, BizType.SYS,
|
"系统收到电缆汇总信息,请手动更新查看,返回信息:分机=" + ser.getName());
|
}
|
}
|