iec104协议导包错误优化
This commit is contained in:
parent
f3015b6a6f
commit
1bf9a2d40a
@ -10,6 +10,7 @@ import com.yfd.platform.component.iec104.message.MessageDetail;
|
||||
import com.yfd.platform.component.iec104.message.MessageInfo;
|
||||
import com.yfd.platform.component.iec104.server.master.BootNettyClientChannel;
|
||||
import com.yfd.platform.component.iec104.server.master.BootNettyClientChannelCache;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
import com.yfd.platform.modules.auxcontrol.domain.DeviceSignal;
|
||||
import com.yfd.platform.modules.auxcontrol.domain.GatewayDevice;
|
||||
import com.yfd.platform.modules.auxcontrol.domain.MeterDevice;
|
||||
@ -101,7 +102,7 @@ public class IIEC104Service {
|
||||
// 发送序号
|
||||
short send = 0;
|
||||
//控制欲
|
||||
byte[] control = com.ydl.iec.util.Iec104Util.getIcontrol(accept, send);
|
||||
byte[] control = Iec104Util.getIcontrol(accept, send);
|
||||
//类型标识 2D
|
||||
TypeIdentifierEnum typeIdentifierEnum = null;
|
||||
// 消息地址 总召唤地址为0
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.yfd.platform.component.iec104.client;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.message.MessageDetail;
|
||||
import com.yfd.platform.component.iec104.message.MessageInfo;
|
||||
import com.yfd.platform.component.iec104.server.handler.ChannelHandler;
|
||||
import com.yfd.platform.component.iec104.server.handler.DataHandler;
|
||||
import com.yfd.platform.component.iec104.server.master.BootNettyClientChannel;
|
||||
import com.yfd.platform.component.iec104.server.master.BootNettyClientChannelCache;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.modules.auxcontrol.service.IDeviceSignalService;
|
||||
import com.yfd.platform.modules.auxcontrol.service.IDeviceWorkDataService;
|
||||
import com.yfd.platform.modules.auxcontrol.service.IGatewayDeviceService;
|
||||
|
@ -7,8 +7,8 @@ import com.yfd.platform.component.iec104.message.MessageInfo;
|
||||
import com.yfd.platform.component.iec104.enums.QualifiersEnum;
|
||||
import com.yfd.platform.component.iec104.enums.TypeIdentifierEnum;
|
||||
import com.yfd.platform.component.iec104.enums.UControlEnum;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -2,7 +2,7 @@ package com.yfd.platform.component.iec104.core;
|
||||
|
||||
import com.yfd.platform.component.iec104.common.Iec104Constant;
|
||||
import com.yfd.platform.component.iec104.message.MessageDetail;
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
import com.yfd.platform.component.utils.OptimizedThreadPool;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.yfd.platform.component.iec104.core;
|
||||
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.yfd.platform.component.iec104.message.MessageDetail;
|
||||
import com.yfd.platform.component.iec104.message.MessageInfo;
|
||||
import com.yfd.platform.component.iec104.enums.QualifiersEnum;
|
||||
import com.yfd.platform.component.iec104.enums.TypeIdentifierEnum;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -4,8 +4,8 @@ import com.yfd.platform.component.iec104.enums.QualifiersEnum;
|
||||
import com.yfd.platform.component.iec104.enums.TypeIdentifierEnum;
|
||||
import com.yfd.platform.component.iec104.message.MessageDetail;
|
||||
import com.yfd.platform.component.iec104.message.MessageInfo;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.yfd.platform.component.iec104.message;
|
||||
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.yfd.platform.component.iec104.enums.QualifiersEnum;
|
||||
import com.yfd.platform.component.iec104.enums.TypeIdentifierEnum;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -3,9 +3,8 @@ package com.yfd.platform.component.iec104.server.handler;
|
||||
import com.yfd.platform.component.iec104.common.Iec104Constant;
|
||||
import com.yfd.platform.component.iec104.server.master.BootNettyClientChannel;
|
||||
import com.yfd.platform.component.iec104.server.master.BootNettyClientChannelCache;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
@ -39,7 +38,7 @@ public class Check104Handler extends ChannelInboundHandlerAdapter {
|
||||
result.readBytes(bytes);
|
||||
BootNettyClientChannel Channel= BootNettyClientChannelCache.get(ctx.channel().id().asShortText());
|
||||
String slave_ip= Channel.getCode();
|
||||
LOGGER.info( String.format("接收到从站[%s]发送的报文: %s", slave_ip,ByteUtil.byteArrayToHexString(bytes) ));
|
||||
LOGGER.info( String.format("接收到从站[%s]发送的报文: %s", slave_ip, ByteUtil.byteArrayToHexString(bytes) ));
|
||||
if (bytes.length < Iec104Constant.APCI_LENGTH || bytes[0] != Iec104Constant.HEAD_DATA) {
|
||||
LOGGER.error("报文无效");
|
||||
ReferenceCountUtil.release(result);
|
||||
|
@ -1,16 +1,14 @@
|
||||
package com.yfd.platform.component.iec104.server.handler;
|
||||
|
||||
import com.yfd.platform.component.iec104.core.Iec104ThreadLocal;
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
|
||||
import com.yfd.platform.component.iec104.core.Decoder104;
|
||||
import com.yfd.platform.component.iec104.core.Iec104ThreadLocal;
|
||||
import com.yfd.platform.component.iec104.message.MessageDetail;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -2,10 +2,10 @@ package com.yfd.platform.component.iec104.server.handler;
|
||||
|
||||
|
||||
import com.yfd.platform.component.iec104.core.Iec104ThreadLocal;
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.yfd.platform.component.iec104.core.Encoder104;
|
||||
import com.yfd.platform.component.iec104.message.MessageDetail;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
@ -35,7 +35,7 @@ public class DataEncoder extends MessageToByteEncoder<MessageDetail> {
|
||||
}
|
||||
bytes[10] = terminalAddressBytes[0];
|
||||
bytes[11] = terminalAddressBytes[1];
|
||||
String hexString=ByteUtil.byteArrayToHexString(bytes);
|
||||
String hexString= ByteUtil.byteArrayToHexString(bytes);
|
||||
log.info(hexString);
|
||||
out.writeBytes(bytes);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.yfd.platform.component.iec104.server.handler;
|
||||
|
||||
import com.yfd.platform.component.iec104.common.Iec104Constant;
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
@ -4,8 +4,8 @@ import com.yfd.platform.component.iec104.core.Iec104ThreadLocal;
|
||||
import com.yfd.platform.component.iec104.enums.UControlEnum;
|
||||
import com.yfd.platform.component.iec104.server.master.BootNettyClientChannel;
|
||||
import com.yfd.platform.component.iec104.server.master.BootNettyClientChannelCache;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.yfd.platform.component.iec104.server.slave.handler;
|
||||
|
||||
import com.yfd.platform.component.iec104.common.BasicInstruction104;
|
||||
import com.ydl.iec.util.Iec104Util;
|
||||
import com.yfd.platform.component.iec104.enums.UControlEnum;
|
||||
import com.ydl.iec.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.ByteUtil;
|
||||
import com.yfd.platform.component.iec104.util.Iec104Util;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
@ -1,25 +1,25 @@
|
||||
package com.ydl.iec.util;
|
||||
package com.yfd.platform.component.iec104.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @ClassName: ByteUtil
|
||||
* @Description: byte 工具类
|
||||
* @author YDL
|
||||
*
|
||||
* @ClassName: ByteUtil
|
||||
* @Description: byte 工具类
|
||||
* @author YDL
|
||||
* @date 2020年5月13日
|
||||
*/
|
||||
public class ByteUtil {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: intToByteArray
|
||||
* @Description: int 转换成 byte数组
|
||||
*
|
||||
* @Title: intToByteArray
|
||||
* @Description: int 转换成 byte数组
|
||||
* @param @param i
|
||||
* @param @return
|
||||
* @return byte[]
|
||||
* @param @return
|
||||
* @return byte[]
|
||||
* @throws
|
||||
*/
|
||||
public static byte[] intToByteArray(int i) {
|
||||
@ -30,13 +30,13 @@ public class ByteUtil {
|
||||
result[3] = (byte) (i & 0xFF);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Title: shortToByteArray
|
||||
* @Description: short 转换成 byte[]
|
||||
* @Title: shortToByteArray
|
||||
* @Description: short 转换成 byte[]
|
||||
* @param @param val
|
||||
* @param @return
|
||||
* @return byte[]
|
||||
* @param @return
|
||||
* @return byte[]
|
||||
* @throws
|
||||
*/
|
||||
public static byte[] shortToByteArray(short val) {
|
||||
@ -45,14 +45,14 @@ public class ByteUtil {
|
||||
b[1] = (byte) (val & 0xff);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: byteArrayToInt
|
||||
*
|
||||
* @Title: byteArrayToInt
|
||||
* @Description: byte[] 转换成 int
|
||||
* @param @param bytes
|
||||
* @param @return
|
||||
* @return int
|
||||
* @param @return
|
||||
* @return int
|
||||
* @throws
|
||||
*/
|
||||
public static int byteArrayToInt(byte[] bytes) {
|
||||
@ -63,14 +63,14 @@ public class ByteUtil {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: byteArrayToShort
|
||||
* @Description: byte[] 转换成short
|
||||
*
|
||||
* @Title: byteArrayToShort
|
||||
* @Description: byte[] 转换成short
|
||||
* @param @param bytes
|
||||
* @param @return
|
||||
* @return short
|
||||
* @param @return
|
||||
* @return short
|
||||
* @throws
|
||||
*/
|
||||
public static short byteArrayToShort(byte[] bytes) {
|
||||
@ -81,15 +81,15 @@ public class ByteUtil {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @Title: listToBytes
|
||||
// * @Description: TODO
|
||||
// *
|
||||
// * @Title: listToBytes
|
||||
// * @Description: TODO
|
||||
// * @param @param byteList
|
||||
// * @param @return
|
||||
// * @return byte[]
|
||||
// * @param @return
|
||||
// * @return byte[]
|
||||
// * @throws
|
||||
// */
|
||||
// public static byte[] listToBytes(List<Byte> byteList) {
|
||||
@ -100,40 +100,40 @@ public class ByteUtil {
|
||||
// }
|
||||
// return bytes;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: date2HByte
|
||||
*
|
||||
* @Title: date2HByte
|
||||
* @Description: 日期转换成 CP56Time2a
|
||||
* @param @param date
|
||||
* @param @return
|
||||
* @return byte[]
|
||||
* @param @return
|
||||
* @return byte[]
|
||||
* @throws
|
||||
*/
|
||||
public static byte[] date2Hbyte(Date date) {
|
||||
ByteArrayOutputStream bOutput = new ByteArrayOutputStream();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
// 毫秒需要转换成两个字节其中 低位在前高位在后
|
||||
// 毫秒需要转换成两个字节其中 低位在前高位在后
|
||||
// 先转换成short
|
||||
int millisecond = calendar.get(Calendar.SECOND) * 1000 + calendar.get(Calendar.MILLISECOND);
|
||||
|
||||
|
||||
// 默认的高位在前
|
||||
byte[] millisecondByte = intToByteArray(millisecond);
|
||||
bOutput.write((byte) millisecondByte[3]);
|
||||
bOutput.write((byte) millisecondByte[2]);
|
||||
|
||||
// 分钟 只占6个比特位 需要把前两位置为零
|
||||
|
||||
// 分钟 只占6个比特位 需要把前两位置为零
|
||||
bOutput.write((byte) calendar.get(Calendar.MINUTE));
|
||||
// 小时需要把前三位置零
|
||||
bOutput.write((byte) calendar.get(Calendar.HOUR_OF_DAY));
|
||||
// 星期日的时候 week 是0
|
||||
// 星期日的时候 week 是0
|
||||
int week = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
if (week == Calendar.SUNDAY) {
|
||||
week = 7;
|
||||
} else {
|
||||
week--;
|
||||
}
|
||||
}
|
||||
// 前三个字节是 星期 因此需要将星期向左移5位 后五个字节是日期 需要将两个数字相加 相加之前需要先将前三位置零
|
||||
bOutput.write((byte) (week << 5) + (calendar.get(Calendar.DAY_OF_MONTH)));
|
||||
// 前四字节置零
|
||||
@ -141,15 +141,15 @@ public class ByteUtil {
|
||||
bOutput.write((byte) (calendar.get(Calendar.YEAR) - 2000));
|
||||
return bOutput.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: date2HByte
|
||||
*
|
||||
* @Title: date2HByte
|
||||
* @Description:CP56Time2a转换成 时间
|
||||
* @param @param date
|
||||
* @param @return
|
||||
* @return byte[]
|
||||
* @param @return
|
||||
* @return byte[]
|
||||
* @throws
|
||||
*/
|
||||
public static Date byte2Hdate(byte[] dataByte) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.ydl.iec.util;
|
||||
package com.yfd.platform.component.iec104.util;
|
||||
|
||||
import com.yfd.platform.component.iec104.message.MessageDetail;
|
||||
import com.yfd.platform.component.iec104.enums.TypeIdentifierEnum;
|
||||
|
Loading…
Reference in New Issue
Block a user