|
@@ -1,25 +1,37 @@
|
|
|
package com.hb.proj.gather.protocol;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import com.hb.proj.gather.business.DataAssembler;
|
|
|
+
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
|
public class GatherRespParser {
|
|
|
|
|
|
private final static Logger logger = LoggerFactory.getLogger(GatherRespParser.class);
|
|
|
|
|
|
-
|
|
|
- public static void parse(ByteBuf byteBuf ,int startIndex,int dataLen,String cmd) {
|
|
|
+ /**
|
|
|
+ * 数据解析入口
|
|
|
+ * @param byteBuf 接收的消息
|
|
|
+ * @param startIndex 解析开始索引
|
|
|
+ * @param dataLen 数据长度字节数
|
|
|
+ * @param cmd
|
|
|
+ * @param serial 设备编号
|
|
|
+ */
|
|
|
+ public static void parse(ByteBuf byteBuf ,int startIndex,int dataLen,String cmd,String serial) {
|
|
|
ZLOpdProtCMDEnum cmdEum=ZLOpdProtCMDEnum.valueOf(cmd);
|
|
|
if(cmdEum.getItemBytCount()==4) {
|
|
|
- parseFloat(byteBuf,startIndex,dataLen);
|
|
|
+ Map<String,Float> dataMap=parseFloat(byteBuf,startIndex,dataLen,cmdEum.getParamCodes());
|
|
|
}
|
|
|
- else if(cmdEum.getItemBytCount()==2) {
|
|
|
- parseShort(byteBuf,startIndex,dataLen);
|
|
|
+ else if(cmdEum.getItemBytCount()==2) { //默认为功图数据解析
|
|
|
+ List<Float> datas=parseShort2Float(byteBuf,startIndex,dataLen);
|
|
|
+ DataAssembler.putPieceData(serial,(cmdEum.getParamCodes())[0], datas);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -28,18 +40,20 @@ public class GatherRespParser {
|
|
|
* @param byteBuf
|
|
|
* @param startIndex 数据区开始索引
|
|
|
* @param dataLen 数据区长度
|
|
|
+ * @param paramCodes 数据项编码
|
|
|
*/
|
|
|
- public static List<Float> parseFloat(ByteBuf byteBuf ,int startIndex,int dataLen) {
|
|
|
+ public static Map<String,Float> parseFloat(ByteBuf byteBuf ,int startIndex,int dataLen,String[] paramCodes) {
|
|
|
byteBuf.readerIndex(startIndex);
|
|
|
- List<Float> rtns=new ArrayList<Float>();
|
|
|
+ Map<String,Float> rtnData=new HashMap<String,Float>(paramCodes.length);
|
|
|
+ int i=0;
|
|
|
while(true) {
|
|
|
- rtns.add(byteBuf.readFloat() ); //顺序读取,readIndex 自动后移
|
|
|
- if(byteBuf.readerIndex()>=(startIndex+dataLen)) {
|
|
|
+ rtnData.put(paramCodes[i++],byteBuf.readFloat() ); //顺序读取,readIndex 自动后移
|
|
|
+ if(i>=paramCodes.length || byteBuf.readerIndex()>=(startIndex+dataLen)) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- logger.info("数据解析完:{}",rtns);
|
|
|
- return rtns;
|
|
|
+ logger.info("数据解析完:{}",rtnData);
|
|
|
+ return rtnData;
|
|
|
|
|
|
|
|
|
}
|
|
@@ -52,11 +66,11 @@ public class GatherRespParser {
|
|
|
* @param dataLen
|
|
|
* @return
|
|
|
*/
|
|
|
- public static List<Short> parseShort(ByteBuf byteBuf ,int startIndex,int dataLen) {
|
|
|
+ public static List<Float> parseShort2Float(ByteBuf byteBuf ,int startIndex,int dataLen) {
|
|
|
byteBuf.readerIndex(startIndex);
|
|
|
- List<Short> rtns=new ArrayList<Short>();
|
|
|
+ List<Float> rtns=new ArrayList<Float>();
|
|
|
while(true) {
|
|
|
- rtns.add(byteBuf.readShort() ); //顺序读取,readIndex 自动后移
|
|
|
+ rtns.add(byteBuf.readShort()+0.0f); //顺序读取,readIndex 自动后移
|
|
|
if(byteBuf.readerIndex()>=(startIndex+dataLen)) {
|
|
|
break;
|
|
|
}
|