Преглед на файлове

动液面采集基础框架调整

chenwen преди 1 година
родител
ревизия
bfe4f721e9
променени са 29 файла, в които са добавени 961 реда и са изтрити 63 реда
  1. 0 27
      src/main/java/com/hb/proj/allconfig/ApplicationContextProvider.java
  2. 1 1
      src/main/java/com/hb/proj/api/controller/APIController.java
  3. 1 1
      src/main/java/com/hb/proj/gather/process/DataAlarmDetector.java
  4. 1 1
      src/main/java/com/hb/proj/gather/process/DataTransConfig.java
  5. 1 1
      src/main/java/com/hb/proj/gather/process/DataTransRepSingleTask.java
  6. 1 1
      src/main/java/com/hb/proj/gather/process/DataTransRepTask.java
  7. 1 1
      src/main/java/com/hb/proj/gather/process/DataTransUtils.java
  8. 2 0
      src/main/java/com/hb/proj/gather/protocol/ChannelGroupMgr.java
  9. 4 4
      src/main/java/com/hb/proj/gather/protocol/GatherRespParser.java
  10. 110 0
      src/main/java/com/hb/proj/gather/protocol/GatherRespParserFacade.java
  11. 252 2
      src/main/java/com/hb/proj/gather/protocol/ZLOpdProtCMDEnum.java
  12. 2 2
      src/main/java/com/hb/proj/gather/protocol/ZLOpdProtHandler.java
  13. 3 3
      src/main/java/com/hb/proj/gather/protocol/parser/DataPieceDiagramBox.java
  14. 119 0
      src/main/java/com/hb/proj/gather/protocol/parser/DataPieceLiquidBox.java
  15. 6 2
      src/main/java/com/hb/proj/gather/protocol/parser/DataPieceSingleBox.java
  16. 82 0
      src/main/java/com/hb/proj/gather/protocol/parser/DiagramParser.java
  17. 110 0
      src/main/java/com/hb/proj/gather/protocol/parser/LiquidParser.java
  18. 83 0
      src/main/java/com/hb/proj/gather/protocol/parser/SingleParser.java
  19. 6 1
      src/main/java/com/hb/proj/gather/scheduler/DataAssembler.java
  20. 113 0
      src/main/java/com/hb/proj/gather/scheduler/GatherLiquidTask.java
  21. 1 1
      src/main/java/com/hb/proj/gather/scheduler/GatherMultiTask.java
  22. 15 2
      src/main/java/com/hb/proj/gather/scheduler/GatherScheduler.java
  23. 1 1
      src/main/java/com/hb/proj/gather/scheduler/GatherSingleTask.java
  24. 1 1
      src/main/java/com/hb/proj/gather/scheduler/GatherTask.java
  25. 3 2
      src/main/java/com/hb/proj/gather/scheduler/GatherTaskExecutor.java
  26. 1 3
      src/main/java/com/hb/proj/gather/server/MyChannelInitializer.java
  27. 2 2
      src/main/java/com/hb/proj/gather/server/NettyGatherRunner.java
  28. 1 1
      src/main/java/com/hb/proj/gather/server/NettyGatherServer.java
  29. 38 3
      src/main/java/com/hb/proj/gather/utils/Crc16Utils.java

+ 0 - 27
src/main/java/com/hb/proj/allconfig/ApplicationContextProvider.java

@@ -1,27 +0,0 @@
-package com.hb.proj.allconfig;
-
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.stereotype.Component;
-
-@Component
-public class ApplicationContextProvider implements ApplicationContextAware  {
-
-	private  static ApplicationContext applicationContextObj=null;
-	@Override
-	public void setApplicationContext(ApplicationContext applicationContext)
-			throws BeansException {
-		
-		applicationContextObj=applicationContext;
-	}
-
-	public static <T> T  getBean(String beanName,Class<T> beanClass){
-		return applicationContextObj.getBean(beanName, beanClass);
-	}
-	
-	public static Object getBean(String beanName){
-		return applicationContextObj.getBean(beanName);
-	}
-
-}

+ 1 - 1
src/main/java/com/hb/proj/api/controller/APIController.java

@@ -6,7 +6,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.hb.proj.gather.business.DataTransConfig;
+import com.hb.proj.gather.process.DataTransConfig;
 import com.hb.proj.gather.protocol.ChannelGroupMgr;
 import com.hb.proj.gather.protocol.ZLOpdProtCMDEnum;
 import com.hb.proj.gather.utils.ByteUtils;

+ 1 - 1
src/main/java/com/hb/proj/gather/business/DataAlarmDetector.java → src/main/java/com/hb/proj/gather/process/DataAlarmDetector.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.process;
 
 import java.util.ArrayList;
 import java.util.List;

+ 1 - 1
src/main/java/com/hb/proj/gather/business/DataTransConfig.java → src/main/java/com/hb/proj/gather/process/DataTransConfig.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.process;
 
 import java.util.ArrayList;
 import java.util.List;

+ 1 - 1
src/main/java/com/hb/proj/gather/business/DataTransRepSingleTask.java → src/main/java/com/hb/proj/gather/process/DataTransRepSingleTask.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.process;
 
 import java.util.HashMap;
 import java.util.List;

+ 1 - 1
src/main/java/com/hb/proj/gather/business/DataTransRepTask.java → src/main/java/com/hb/proj/gather/process/DataTransRepTask.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.process;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

+ 1 - 1
src/main/java/com/hb/proj/gather/business/DataTransUtils.java → src/main/java/com/hb/proj/gather/process/DataTransUtils.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.process;
 
 import java.text.DecimalFormat;
 import java.util.ArrayList;

+ 2 - 0
src/main/java/com/hb/proj/gather/protocol/ChannelGroupMgr.java

@@ -33,6 +33,8 @@ public class ChannelGroupMgr {
 	
 	public  static final AttributeKey<Long> ATTR_KEY_PRE_TIME=AttributeKey.valueOf("pre_time");  //上一指令时间,检测是否超时发送指令
 	
+	public  static final AttributeKey<Boolean> ATTR_KEY_RECEIVED=AttributeKey.valueOf("received"); //是否完整收到回复数据
+	
 	public static void add(Channel channel,String serial) {
 		logger.info("增加客户端通道:{}",serial);
 		channel.attr(ATTR_KEY_SERIAL).set(serial);

+ 4 - 4
src/main/java/com/hb/proj/gather/protocol/GatherRespParser.java

@@ -8,12 +8,12 @@ import java.util.Map;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.hb.proj.gather.business.DataAssembler;
-import com.hb.proj.gather.business.DataTransRepSingleTask;
-import com.hb.proj.gather.business.DataTransRepTask;
-import com.hb.proj.gather.business.GatherTaskExecutor;
 import com.hb.proj.gather.model.DiagramPO;
 import com.hb.proj.gather.model.SingleCombPO;
+import com.hb.proj.gather.process.DataTransRepSingleTask;
+import com.hb.proj.gather.process.DataTransRepTask;
+import com.hb.proj.gather.scheduler.DataAssembler;
+import com.hb.proj.gather.scheduler.GatherTaskExecutor;
 
 import io.netty.buffer.ByteBuf;
 

+ 110 - 0
src/main/java/com/hb/proj/gather/protocol/GatherRespParserFacade.java

@@ -0,0 +1,110 @@
+package com.hb.proj.gather.protocol;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hb.proj.gather.protocol.parser.LiquidParser;
+
+import io.netty.buffer.ByteBuf;
+
+/**
+ * 协议解析统一类,针对不同指令由其它相关类实现解析
+ * @author cwen
+ *
+ */
+public class GatherRespParserFacade {
+
+	private final static  Logger logger = LoggerFactory.getLogger(GatherRespParserFacade.class);
+	
+	private final static  Map<String,Method> parserClsMapping=new HashMap<>();
+	
+	/**
+	 * 数据解析入口
+	 * @param byteBuf  原始返回数据
+	 * @param startIndex  解析开始索引
+	 * @param dataLen 可以通过数据字节数明确解析器(前提:同一通道内各采集数据长度要不一样)
+	 * @param cmdEnum 可以通过指令对象明确解析器(目前采用方式)
+	 * @param serial   设备号
+	 */
+	public static void parse(ByteBuf byteBuf ,int startIndex,int dataLen,String cmdName,String serial) {
+		logger.info("parse:{}",cmdName);
+		ZLOpdProtCMDEnum cmdEnum=ZLOpdProtCMDEnum.valueOf(cmdName);
+		
+		if(cmdName.startsWith("LIQUID")) {
+			LiquidParser.parse(byteBuf, startIndex, dataLen, cmdEnum, serial);
+		}
+		
+		/**
+		Method parseMethd=getParseMethod(cmdName);
+		if(parseMethd==null) {
+			logger.error("无法加载或不存在解析器及解析方法,取消解析");
+			return;
+		}
+		
+		try {
+			parseMethd.invoke(null, byteBuf,startIndex,dataLen,cmdEnum,serial);
+		} catch (Exception e) {
+			e.printStackTrace();
+			logger.error("解析器解析数据出错:{}",e.getMessage());
+		} */
+	}
+	
+	
+	/**
+	 * 专为功图点数检测解析
+	 * @param byteBuf
+	 * @param startIndex
+	 * @param dataLen
+	 * @return
+	 */
+	public static short parseDiagramPoint(ByteBuf byteBuf ,int startIndex) {
+		byteBuf.readerIndex(startIndex);
+		return byteBuf.readShort();
+	}
+	
+	
+	/**
+	 * 基于cmdname的格式化加载对应解析器方法(cmdName的前缀+Parser)
+	 * @param cmd
+	 * @return
+	 */
+	private static Method  getParseMethod(String cmd){
+		try {
+			if(!parserClsMapping.containsKey(cmd)) {
+				String clsName=(cmd.split("_"))[0].toLowerCase();
+				clsName=clsName.substring(0,1).toUpperCase()+clsName.substring(1)+"Parser";
+				Class<?> cls=loadParseClass(clsName);
+				if(cls!=null) {
+					parserClsMapping.put(cmd, cls.getDeclaredMethod("parse"));
+				}
+			}
+			
+			return parserClsMapping.get(cmd);
+		}
+		catch(NoSuchMethodException e) {
+			e.printStackTrace();
+			return null;
+		}
+		
+		
+		
+	}
+	
+	/**
+	 * 加载具体解析器class对象
+	 */
+	private static Class<?> loadParseClass(String parserClsName) {
+		try {
+			Class<?> cls=Class.forName("com.hb.proj.gather.protocol.parser."+parserClsName);
+			return cls;
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+			logger.error("未找到协议解析器{}",parserClsName);
+			return null;
+		}
+	}
+}

+ 252 - 2
src/main/java/com/hb/proj/gather/protocol/ZLOpdProtCMDEnum.java

@@ -134,8 +134,258 @@ public enum ZLOpdProtCMDEnum {
 			new byte[] {0x01, 0x03, 0x07, (byte)0x88, 0x00, 0x48,       (byte)0xc4, (byte)0xa2},  
 			0x90,  
 			2,
-			new String[]{"chartpower_3"})
-	;
+			new String[]{"chartpower_3"}),
+	
+	
+	//18-9 动液面其它参数采集(测量时间、音速、测量深度、套压) 01 03 18 00 00 09
+	LIQUID_OTHER(
+			 new byte[] {0x01, 0x03, 0x18, 0x00, 0x00, 0x09,       (byte)0x83, 0x6c}, 
+			 0x12,
+			 2,
+			 new String[]{"test_time_yy","test_time_mm","test_time_dd","test_time_hr","test_time_mi","test_time_ss","sound_speed","test_depth","casing_pre"}
+			),
+	
+	//250-125 动液面曲线数据(1/40)
+	LIQUID_SERIAL_1(
+			 new byte[] {0x01,0x03,0x18,0x10,0x00,0x7d,(byte)0x82,(byte)0x8e}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_1"}
+			),
+	LIQUID_SERIAL_2(
+			 new byte[] {0x01,0x03,0x18,(byte)0x8D,0x00,0x7d,0x13,0x60}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_2"}
+			),
+	LIQUID_SERIAL_3(
+			 new byte[] {0x01,0x03,0x19,0x0A,0x00,0x7d,(byte)0xa2,(byte)0xb5}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_3"}
+			),
+	LIQUID_SERIAL_4(
+			 new byte[] {0x01,0x03,0x19,(byte)0x87,0x00,0x7d,0x32,(byte)0x9e}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_4"}
+			),
+	LIQUID_SERIAL_5(
+			 new byte[] {0x01,0x03,0x1A,0x04,0x00,0x7d,(byte)0xc3,0x32}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_5"}
+			),
+	LIQUID_SERIAL_6(
+			 new byte[] {0x01,0x03,0x1A,(byte)0x81,0x00,0x7d,(byte)0xd2,(byte)0xdb}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_6"}
+			),
+	LIQUID_SERIAL_7(
+			 new byte[] {0x01,0x03,0x1A,(byte)0xFE,0x00,0x7d,(byte)0xe3,0x03}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_7"}
+			),
+	LIQUID_SERIAL_8(
+			 new byte[] {0x01,0x03,0x1B,0x7B,0x00,0x7d,(byte)0xf3,0x16}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_8"}
+			),
+	LIQUID_SERIAL_9(
+			 new byte[] {0x01,0x03,0x1B,(byte)0xF8,0x00,0x7d}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_9"}
+			),
+	LIQUID_SERIAL_10(
+			 new byte[] {0x01,0x03,0x1C,0x75,0x00,0x7d,(byte)0x93,(byte)0xa1}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_10"}
+			),
+	LIQUID_SERIAL_11(
+			 new byte[] {0x01,0x03,0x1C,(byte)0xF2,0x00,0x7d,0x23,(byte)0x88}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_11"}
+			),
+	LIQUID_SERIAL_12(
+			 new byte[] {0x01,0x03,0x1D,0x6F,0x00,0x7d,(byte)0xb3,(byte)0x9a}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_12"}
+			),
+	LIQUID_SERIAL_13(
+			 new byte[] {0x01,0x03,0x1D,(byte)0xEC,0x00,0x7d,0x42,0x72}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_13"}
+			),
+	LIQUID_SERIAL_14(
+			 new byte[] {0x01,0x03,0x1E,0x69,0x00,0x7d,0x53,(byte)0xdf}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_14"}
+			),
+	LIQUID_SERIAL_15(
+			 new byte[] {0x01,0x03,0x1E,(byte)0xE6,0x00,0x7d,0x62,0x34}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_15"}
+			),
+	LIQUID_SERIAL_16(
+			 new byte[] {0x01,0x03,0x1F,0x63,0x00,0x7d,0x72,0x21}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_16"}
+			),
+	LIQUID_SERIAL_17(
+			 new byte[] {0x01,0x03,0x1F,(byte)0xE0,0x00,0x7d,(byte)0x83,(byte)0xc9}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_17"}
+			),
+	LIQUID_SERIAL_18(
+			 new byte[] {0x01,0x03,0x20,0x5D,0x00,0x7d,0x1f,(byte)0xf9}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_18"}
+			),
+	LIQUID_SERIAL_19(
+			 new byte[] {0x01,0x03,0x20,(byte)0xDA,0x00,0x7d,(byte)0xaf,(byte)0xd0}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_19"}
+			),
+	LIQUID_SERIAL_20(
+			 new byte[] {0x01,0x03,0x21,0x57,0x00,0x7d,0x3e,0x07}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_20"}
+			),
+	LIQUID_SERIAL_21(
+			 new byte[] {0x01,0x03,0x21,(byte)0xD4,0x00,0x7d,(byte)0xcf,(byte)0xef}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_21"}
+			),
+	LIQUID_SERIAL_22(
+			 new byte[] {0x01,0x03,0x22,0x51,0x00,0x7d,(byte)0xde,0x42}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_22"}
+			),
+	LIQUID_SERIAL_23(
+			 new byte[] {0x01,0x03,0x22,(byte)0xCE,0x00,0x7d,(byte)0xee,0x6c}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_23"}
+			),
+	LIQUID_SERIAL_24(
+			 new byte[] {0x01,0x03,0x23,0x4B,0x00,0x7d,(byte)0xfe,0x79}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_24"}
+			),
+	LIQUID_SERIAL_25(
+			 new byte[] {0x01,0x03,0x23,(byte)0xC8,0x00,0x7d,0x0f,(byte)0x91}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_25"}
+			),
+	LIQUID_SERIAL_26(
+			 new byte[] {0x01,0x03,0x24,0x45,0x00,0x7d,(byte)0x9e,(byte)0xce}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_26"}
+			),
+	LIQUID_SERIAL_27(
+			 new byte[] {0x01,0x03,0x24,(byte)0xC2,0x00,0x7d,0x2e,(byte)0xe7}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_27"}
+			),
+	LIQUID_SERIAL_28(
+			 new byte[] {0x01,0x03,0x25,0x3F,0x00,0x7d,(byte)0xbe,(byte)0xeb}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_28"}
+			),
+	LIQUID_SERIAL_29(
+			 new byte[] {0x01,0x03,0x25,(byte)0xBC,0x00,0x7d,0x4f,0x03}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_29"}
+			),
+	LIQUID_SERIAL_30(
+			 new byte[] {0x01,0x03,0x26,0x39,0x00,0x7d,0x5e,(byte)0xae}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_30"}
+			),
+	LIQUID_SERIAL_31(
+			 new byte[] {0x01,0x03,0x26,(byte)0xB6,0x00,0x7d,0x6f,0x45}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_31"}
+			),
+	LIQUID_SERIAL_32(
+			 new byte[] {0x01,0x03,0x27,0x33,0x00,0x7d,0x7f,0x50}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_32"}
+			),
+	LIQUID_SERIAL_33(
+			 new byte[] {0x01,0x03,0x27,(byte)0xB0,0x00,0x7d,(byte)0x8e,(byte)0xb8}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_33"}
+			),
+	LIQUID_SERIAL_34(
+			 new byte[] {0x01,0x03,0x28,0x2D,0x00,0x7d,0x1c,0x42}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_34"}
+			),
+	LIQUID_SERIAL_35(
+			 new byte[] {0x01,0x03,0x28,(byte)0xAA,0x00,0x7d,(byte)0xac,0x6b}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_35"}
+			),
+	LIQUID_SERIAL_36(
+			 new byte[] {0x01,0x03,0x29,0x27,0x00,0x7d,0x3d,(byte)0xbc}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_36"}
+			),
+	LIQUID_SERIAL_37(
+			 new byte[] {0x01,0x03,0x29,(byte)0xA4,0x00,0x7d,(byte)0xcc,0x54}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_37"}
+			),
+	LIQUID_SERIAL_38(
+			 new byte[] {0x01,0x03,0x2A,0x21,0x00,0x7d,(byte)0xdd,(byte)0xf9}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_38"}
+			),
+	LIQUID_SERIAL_39(
+			 new byte[] {0x01,0x03,0x2A,(byte)0x9E,0x00,0x7d,(byte)0xec,0x1d}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_39"}
+			),
+	LIQUID_SERIAL_40(
+			 new byte[] {0x01,0x03,0x2B,0x1B,0x00,0x7d,(byte)0xfc,0x08}, 
+			 0xfa,
+			 1,
+			 new String[] {"serial_40"}
+			);
 	
 	private byte[]  cmd;  //读取指令 最后字节CRC16
 	

+ 2 - 2
src/main/java/com/hb/proj/gather/protocol/ZLOpdProtHandler.java

@@ -100,13 +100,13 @@ public class ZLOpdProtHandler extends ChannelInboundHandlerAdapter {
 					logger.info("解析指令{}返回消息",cmd);
 					
 					if("DIAGRAM_POINT_COUNT".equalsIgnoreCase(cmd)) {  //如果是功图点数检测,还需要明确结果
-						short pcount=GatherRespParser.parseDiagramPoint(byteBuf,headBtyCount);
+						short pcount=GatherRespParserFacade.parseDiagramPoint(byteBuf,headBtyCount);
 						logger.warn("功图点数{}",pcount);
 						ctx.channel().attr(ChannelGroupMgr.ATTR_KEY_DIAGRAM_READY).set(pcount==250);
 					}
 					else{
 						String serial=ctx.channel().attr(ChannelGroupMgr.ATTR_KEY_SERIAL).get();
-						GatherRespParser.parse(byteBuf,headBtyCount,datalen,cmd,serial);
+						GatherRespParserFacade.parse(byteBuf,headBtyCount,datalen,cmd,serial);
 					}
 					
 					ctx.channel().notifyAll(); //已经收到回复消息,通知指令发送进程可以继续,同步块或者同步方法执行完后才释放锁

+ 3 - 3
src/main/java/com/hb/proj/gather/business/DataPieceDiagramBox.java → src/main/java/com/hb/proj/gather/protocol/parser/DataPieceDiagramBox.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.protocol.parser;
 
 import java.util.HashMap;
 import java.util.List;
@@ -18,14 +18,14 @@ public class DataPieceDiagramBox {
 	
 	private String channelSerial; //通道编号
 	
+	private Map<String,List<Float>>  pieceMap=new HashMap<String,List<Float>>(12);
+	
 	
 	public DataPieceDiagramBox(String channelSerial) {
 		this.channelSerial=channelSerial;
 	}
 	
 	
-	private Map<String,List<Float>>  pieceMap=new HashMap<String,List<Float>>(12);
-	
 	public DiagramPO put(String pieceName,List<Float> pieceDatas) {
 		pieceMap.put(pieceName, pieceDatas);
 		if(pieceName.startsWith("chartload")) {

+ 119 - 0
src/main/java/com/hb/proj/gather/protocol/parser/DataPieceLiquidBox.java

@@ -0,0 +1,119 @@
+package com.hb.proj.gather.protocol.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class DataPieceLiquidBox {
+
+	private int gatherNum;  //采集批次号
+	
+	private String channelSerial; //通道编号
+	
+	private String testTime;  //测量时间
+	
+	private Short soundSpeed;  //音速   cm/s
+	
+	private Short testDepth; // 测量深度  0.1米
+	
+	private Short casingPre; // 当前套压  kpa
+	
+	
+	private List<Integer>  pieceSerial=new ArrayList<>(10000);  //接箍序列(高字节),动液面序列(低字节) 分别对应奇数位,偶数位
+	
+	public DataPieceLiquidBox(String channelSerial) {
+		this.channelSerial=channelSerial;
+	}
+	
+	public void putSerial(List<Integer> serial) {
+		this.pieceSerial.addAll(serial);
+	}
+	
+	public void putOther(Map<String,Short> gatherOther) {
+		this.testTime="20"+String.format("%2d", gatherOther.get("test_time_yy"))+
+				"-"+String.format("%2d", gatherOther.get("test_time_mm"))+
+				"-"+String.format("%2d", gatherOther.get("test_time_dd"))+
+				" "+String.format("%2d", gatherOther.get("test_time_hr"))+
+				":"+String.format("%2d", gatherOther.get("test_time_mi"))+
+				":"+String.format("%2d", gatherOther.get("test_time_ss"));
+		
+		this.soundSpeed=gatherOther.get("sound_speed");
+		this.testDepth=gatherOther.get("test_depth");
+		this.casingPre=gatherOther.get("casing_pre");
+		
+	}
+	
+	
+	public String getTimeStr(Map<String,Short> dataMap,String key) {
+		return String.format("%2d", dataMap.get(key));
+	}
+	
+	public void clear() {
+		pieceSerial.clear();
+	}
+
+
+	public int getGatherNum() {
+		return gatherNum;
+	}
+
+
+	public void setGatherNum(int gatherNum) {
+		this.gatherNum = gatherNum;
+	}
+
+
+	public String getChannelSerial() {
+		return channelSerial;
+	}
+
+
+	public void setChannelSerial(String channelSerial) {
+		this.channelSerial = channelSerial;
+	}
+
+	public String getTestTime() {
+		return testTime;
+	}
+
+	public void setTestTime(String testTime) {
+		this.testTime = testTime;
+	}
+
+	public Short getSoundSpeed() {
+		return soundSpeed;
+	}
+
+	public void setSoundSpeed(Short soundSpeed) {
+		this.soundSpeed = soundSpeed;
+	}
+
+	public Short getTestDepth() {
+		return testDepth;
+	}
+
+	public void setTestDepth(Short testDepth) {
+		this.testDepth = testDepth;
+	}
+
+	public Short getCasingPre() {
+		return casingPre;
+	}
+
+	public void setCasingPre(Short casingPre) {
+		this.casingPre = casingPre;
+	}
+
+	public List<Integer> getPieceSerial() {
+		return pieceSerial;
+	}
+
+	public void setPieceSerial(List<Integer> pieceSerial) {
+		this.pieceSerial = pieceSerial;
+	}
+
+
+	
+
+	
+}

+ 6 - 2
src/main/java/com/hb/proj/gather/business/DataPieceSingleBox.java → src/main/java/com/hb/proj/gather/protocol/parser/DataPieceSingleBox.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.protocol.parser;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -19,7 +19,7 @@ public class DataPieceSingleBox {
 	
 	private String channelSerial; //通道编号
 	
-	private Map<String,Float>  pieceMap=new HashMap<String,Float>(20);
+	private Map<String,Float>  pieceMap=new HashMap<>(20);
 	
 	public DataPieceSingleBox(String channelSerial) {
 		this.channelSerial=channelSerial;
@@ -60,6 +60,10 @@ public class DataPieceSingleBox {
 		return true;
 	}
 	
+	public void  clear() {
+		pieceMap.clear();
+	}
+	
 
 	public int getGatherNum() {
 		return gatherNum;

+ 82 - 0
src/main/java/com/hb/proj/gather/protocol/parser/DiagramParser.java

@@ -0,0 +1,82 @@
+package com.hb.proj.gather.protocol.parser;
+
+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.model.DiagramPO;
+import com.hb.proj.gather.process.DataTransRepTask;
+import com.hb.proj.gather.protocol.ZLOpdProtCMDEnum;
+import com.hb.proj.gather.scheduler.GatherTaskExecutor;
+
+import io.netty.buffer.ByteBuf;
+
+/**
+ * 功图解析器
+ * @author cwen
+ *
+ */
+public class DiagramParser {
+
+	private final static  Logger logger = LoggerFactory.getLogger(DiagramParser.class);
+	
+	private static Map<String,DataPieceDiagramBox> diagramPkgs=new HashMap<String,DataPieceDiagramBox>(100);
+	
+	
+	/**
+	 * 解析数据并进行后续数据处理
+	 * @param byteBuf
+	 * @param startIndex
+	 * @param dataLen
+	 * @param cmdEnum
+	 * @param serial
+	 */
+	public static void parse(ByteBuf byteBuf ,int startIndex,int dataLen,ZLOpdProtCMDEnum cmdEnum,String serial) {
+		 List<Float> datas=parseShort2Float(byteBuf,startIndex,dataLen);
+		 DiagramPO po=putPieceData(serial,(cmdEnum.getParamCodes())[0], datas);
+		 if(po!=null) {
+			 GatherTaskExecutor.execute(new DataTransRepTask(po)); 
+		 }
+	}
+	
+	/**
+	 * 解析消息中的数据部分 每个数据项 2字节
+	 * @param byteBuf
+	 * @param startIndex
+	 * @param dataLen
+	 * @return
+	 */
+	public static List<Float> parseShort2Float(ByteBuf byteBuf ,int startIndex,int dataLen) {
+		byteBuf.readerIndex(startIndex);
+		List<Float> rtns=new ArrayList<Float>();
+		while(true) {
+			rtns.add(byteBuf.readShort()+0.0f); //顺序读取,readIndex 自动后移
+			if(byteBuf.readerIndex()>=(startIndex+dataLen)) {
+				break;
+			}
+		}
+		logger.info("数据解析完:{}",rtns);
+		return rtns;
+		
+		
+	}
+	
+	/**
+	 * 放入功图片段数据,符合组装要求时返回组装好的功图对象
+	 * @param channelSerial
+	 * @param pieceName
+	 * @param pieceDatas
+	 * @return
+	 */
+	public  static DiagramPO putPieceData(String channelSerial,String pieceName,List<Float> pieceDatas) {
+		//logger.info("接收功图片段数据:{},{}",channelSerial,pieceName);
+		if(!diagramPkgs.containsKey(channelSerial)) {
+			diagramPkgs.put(channelSerial, new DataPieceDiagramBox(channelSerial));
+		}
+		return diagramPkgs.get(channelSerial).put(pieceName,pieceDatas);
+	}
+}

+ 110 - 0
src/main/java/com/hb/proj/gather/protocol/parser/LiquidParser.java

@@ -0,0 +1,110 @@
+package com.hb.proj.gather.protocol.parser;
+
+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.protocol.ZLOpdProtCMDEnum;
+
+import io.netty.buffer.ByteBuf;
+
+public class LiquidParser {
+
+	private final static  Logger logger = LoggerFactory.getLogger(LiquidParser.class);
+	
+	private static Map<String,DataPieceLiquidBox> pkgs=new HashMap<>(100);
+	
+	
+	/**
+	 * 解析数据并进行后续数据处理
+	 * 数据入库前先检测该测量时间是否已经在库里,只有不存在才进行后面的采集
+	 * @param byteBuf
+	 * @param startIndex
+	 * @param dataLen
+	 * @param cmdEnum
+	 * @param serial
+	 */
+	public static void parse(ByteBuf byteBuf ,int startIndex,int dataLen,ZLOpdProtCMDEnum cmdEnum,String serial) {
+		if(cmdEnum.name().startsWith("LIQUID_OTHER")) {
+			Map<String,Short> dataMap=parseOther(byteBuf,startIndex,dataLen,cmdEnum.getParamCodes());
+			
+		}
+		else if(cmdEnum.name().startsWith("LIQUID_CURVE")) {
+			List<Integer>  dataSerial=parseSerial(byteBuf,startIndex,dataLen);
+		}
+		
+	}
+	
+	
+	/**
+	 * 解析动液面单值数据(测量时间、音速、套压)
+	 * @param byteBuf
+	 * @param startIndex
+	 * @param dataLen
+	 * @param paramCodes
+	 * @return
+	 */
+	private static Map<String,Short> parseOther(ByteBuf byteBuf ,int startIndex,int dataLen,String[] paramCodes) {
+		byteBuf.readerIndex(startIndex);
+		Map<String,Short> rtnData=new HashMap<>(paramCodes.length);
+		int i=0;
+		while(true) {
+			rtnData.put(paramCodes[i++],byteBuf.readShort() );   //顺序读取,readIndex 自动后移
+			if(i>=paramCodes.length || byteBuf.readerIndex()>=(startIndex+dataLen)) {
+				break;
+			}
+		}
+		logger.info("数据解析完:{}",rtnData);
+		return rtnData;
+	}
+	
+	/**
+	 * 解析动液面测量数据
+	 * @param byteBuf
+	 * @param startIndex
+	 * @param dataLen
+	 * @return
+	 */
+	private static List<Integer> parseSerial(ByteBuf byteBuf ,int startIndex,int dataLen) {
+		byteBuf.readerIndex(startIndex);
+		List<Integer> serial=new ArrayList<>(dataLen);
+		while(true) {
+			serial.add(byteBuf.readByte()+0); //顺序读取,readIndex 自动后移
+			if(byteBuf.readerIndex()>=(startIndex+dataLen)) {
+				break;
+			}
+		}
+		logger.info("数据解析完,曲线序列:{}",serial);
+		
+		return serial;
+		
+		
+	}
+	
+	
+	/**
+	 * 放入片段数据,符合组装要求时返回组装好的动液面对象(动液面其它数据:测量时间、音速、测量深度、套压)
+	 * @param channelSerial
+	 * @param pieceData
+	 */
+	private static void putPieceOther(String channelSerial,Map<String,Short> pieceData) {
+		if(!pkgs.containsKey(channelSerial)) {
+			pkgs.put(channelSerial, new DataPieceLiquidBox(channelSerial));
+		}
+		pkgs.get(channelSerial).putOther(pieceData);
+	}
+	
+	/**
+	 * 放入片段数据,符合组装要求时返回组装好的动液面对象(曲线数据,)
+	 */
+	private static void putPieceSerial(String channelSerial,List<Integer> pieceData) {
+		if(!pkgs.containsKey(channelSerial)) {
+			pkgs.put(channelSerial, new DataPieceLiquidBox(channelSerial));
+		}
+		pkgs.get(channelSerial).putSerial(pieceData);
+	}
+}

+ 83 - 0
src/main/java/com/hb/proj/gather/protocol/parser/SingleParser.java

@@ -0,0 +1,83 @@
+package com.hb.proj.gather.protocol.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hb.proj.gather.model.SingleCombPO;
+import com.hb.proj.gather.process.DataTransRepSingleTask;
+import com.hb.proj.gather.protocol.ZLOpdProtCMDEnum;
+import com.hb.proj.gather.scheduler.GatherTaskExecutor;
+
+import io.netty.buffer.ByteBuf;
+
+/**
+ * 单值解析器
+ * @author cwen
+ *
+ */
+public class SingleParser {
+	
+	private final static  Logger logger = LoggerFactory.getLogger(SingleParser.class);
+	
+	//单值采集组装容器
+	private static Map<String,DataPieceSingleBox> singlePkgs=new HashMap<>(100);
+
+	/**
+	 * 解析数据并进行后续数据处理
+	 * @param byteBuf
+	 * @param startIndex
+	 * @param dataLen
+	 * @param cmdEnum
+	 * @param serial
+	 */
+	public static void parse(ByteBuf byteBuf ,int startIndex,int dataLen,ZLOpdProtCMDEnum cmdEnum,String serial) {
+		 Map<String,Float> dataMap=parseFloat(byteBuf,startIndex,dataLen,cmdEnum.getParamCodes());
+		 SingleCombPO po=putPieceData(serial, dataMap);
+		 if(po!=null) {
+			 GatherTaskExecutor.execute(new DataTransRepSingleTask(po)); 
+		 }
+	}
+	
+	
+	
+	
+	/**
+	 * 解析消息中的数据部分 每个数据项 4字节
+	 * @param byteBuf
+	 * @param  startIndex 数据区开始索引
+	 * @param  dataLen  数据区长度
+	 * @param  paramCodes  数据项编码
+	 */
+	public static Map<String,Float> parseFloat(ByteBuf byteBuf ,int startIndex,int dataLen,String[] paramCodes) {
+		byteBuf.readerIndex(startIndex);
+		Map<String,Float> rtnData=new HashMap<String,Float>(paramCodes.length);
+		int i=0;
+		while(true) {
+			rtnData.put(paramCodes[i++],byteBuf.readFloat() );   //顺序读取,readIndex 自动后移
+			if(i>=paramCodes.length || byteBuf.readerIndex()>=(startIndex+dataLen)) {
+				break;
+			}
+		}
+		logger.info("数据解析完:{}",rtnData);
+		return rtnData;
+		
+		
+	}
+	
+	/**
+	 * 放入单值片段数据,符合组装要求时返回组装好的单值对象
+	 * @param channelSerial
+	 * @param pieceData
+	 * @return
+	 */
+	public  static SingleCombPO putPieceData(String channelSerial,Map<String,Float> pieceData) {
+		//logger.info("接收单值片段数据:{},{}",channelSerial,pieceData);
+		if(!singlePkgs.containsKey(channelSerial)) {
+			singlePkgs.put(channelSerial, new DataPieceSingleBox(channelSerial));
+		}
+		return singlePkgs.get(channelSerial).putAll(pieceData);
+	}
+}

+ 6 - 1
src/main/java/com/hb/proj/gather/business/DataAssembler.java → src/main/java/com/hb/proj/gather/scheduler/DataAssembler.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.scheduler;
 
 import java.util.HashMap;
 import java.util.List;
@@ -9,6 +9,10 @@ import org.slf4j.LoggerFactory;
 
 import com.hb.proj.gather.model.DiagramPO;
 import com.hb.proj.gather.model.SingleCombPO;
+import com.hb.proj.gather.process.DataTransRepSingleTask;
+import com.hb.proj.gather.process.DataTransRepTask;
+import com.hb.proj.gather.protocol.parser.DataPieceDiagramBox;
+import com.hb.proj.gather.protocol.parser.DataPieceSingleBox;
 
 /**
  * 采集数据组装器(将分批采集的数据组装成完整数据,特别是功图数据)
@@ -43,6 +47,7 @@ public class DataAssembler extends Thread{
 	}
 
 	@Override
+	@Deprecated
 	public void run() {
 		logger.info("开始数据组装检测");
 		DataPieceDiagramBox  diaPiece=null;

+ 113 - 0
src/main/java/com/hb/proj/gather/scheduler/GatherLiquidTask.java

@@ -0,0 +1,113 @@
+package com.hb.proj.gather.scheduler;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hb.proj.gather.protocol.ChannelGroupMgr;
+import com.hb.proj.gather.protocol.ZLOpdProtCMDEnum;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.channel.Channel;
+
+/**
+ * 动液面采集任务  具体执行采集任务,下发采集指令   
+ * @author cwen
+ *
+ */
+public class GatherLiquidTask implements Runnable {
+	
+	private final static  Logger logger = LoggerFactory.getLogger(GatherLiquidTask.class);
+
+	private Channel  channel;
+	
+	private long cmdTimeout=25*1000; //指令等待回复超时时间 
+	
+	private int timeoutCount=0;  //超时发送指令次数
+	
+	public GatherLiquidTask(Channel channel) {
+		this.channel=channel;
+	}
+	
+	/**
+	 * 约2-5s采集完
+	 */
+	@Override
+	public void run() {
+		logger.info("动液面采集开始...");
+		
+		List<ZLOpdProtCMDEnum> cmds=new ArrayList<>(41);
+		cmds.add(ZLOpdProtCMDEnum.LIQUID_OTHER);
+		for(int i=1;i<41;i++) {
+			cmds.add(ZLOpdProtCMDEnum.valueOf("LIQUID_SERIAL_"+i));
+		}
+		
+		try {
+			ByteBufAllocator alloc=channel.alloc(); 
+			ByteBuf byteBuf=null;
+			
+			synchronized(channel) {
+				for(ZLOpdProtCMDEnum cmd : cmds) {
+					
+					if(needCloseChannel()) {
+						ChannelGroupMgr.disconnect(channel);
+						logger.error("设备多次未对指令及时响应,准备关闭连接,等待重连");
+						return;
+					}
+					
+					byteBuf=alloc.directBuffer();
+					byteBuf.writeBytes(cmd.getCmd());
+					channel.writeAndFlush(byteBuf);
+					
+					channel.attr(ChannelGroupMgr.ATTR_KEY_CMD).set(cmd.name());
+					channel.attr(ChannelGroupMgr.ATTR_KEY_PRE_TIME).set((new Date()).getTime());
+					logger.info("发送完指令:{}",cmd.name());
+					
+					channel.wait(cmdTimeout);  //等待接收返回数据后继续,最多等待cmdTimeout,此处释放锁,回复还未收到就被多值任务获得锁并发指令,会导致两个指令间隔很短
+				
+					/*
+					 * if(!channel.attr(ChannelGroupMgr.ATTR_KEY_RECEIVED).get()) { //如果是超时等待后执行
+					 * logger.info("动液面采集:{}超时未回复,取消此次任务",cmd.name()); return; }
+					 */
+				}
+				
+			}
+		}
+		catch (InterruptedException e) {
+			e.printStackTrace();
+			logger.error("定时采集出现异常:{}",e.getMessage());
+		} 
+		
+		
+		
+		
+
+	}
+	
+	private boolean needCloseChannel() {
+		Long pre=channel.attr(ChannelGroupMgr.ATTR_KEY_PRE_TIME).get();
+		if(pre==null||pre==0) {
+			return false;
+		}
+		boolean isTimeout= ((new Date()).getTime()-pre.longValue())>(cmdTimeout-1000);
+		
+		
+		if(!isTimeout) {
+			timeoutCount=0;  //有一次不超时就清空超时次数
+		}
+		else {
+			timeoutCount+=1;  //记录一次任务中连续超时次数
+		}
+		
+		return timeoutCount>1;  //多次超时(2次及以上)需要关闭通道,等待重连
+		
+		
+		
+	}
+	
+
+}

+ 1 - 1
src/main/java/com/hb/proj/gather/business/GatherMultiTask.java → src/main/java/com/hb/proj/gather/scheduler/GatherMultiTask.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.scheduler;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

+ 15 - 2
src/main/java/com/hb/proj/gather/business/GatherScheduler.java → src/main/java/com/hb/proj/gather/scheduler/GatherScheduler.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.scheduler;
 
 import java.util.Iterator;
 
@@ -37,7 +37,7 @@ public class GatherScheduler {
 	/**
 	 * 单值1分钟执行一次采集,首次等待1分钟,等待服务启动,设备连接上
 	 */
-	@Scheduled(fixedRate=60*1000,initialDelay= 60000)  //每分钟执行一次
+	//@Scheduled(fixedRate=60*1000,initialDelay= 60000)  //每分钟执行一次
 	public void startSingleGather() {
 		logger.info("定时采集启动...");
 		scheNum+=1;
@@ -65,4 +65,17 @@ public class GatherScheduler {
 			GatherTaskExecutor.execute(new GatherMultiTask(channel));
 		}
 	}
+	
+	
+	@Scheduled(fixedRate = 60 * 60 * 1000,initialDelay= 30000)  
+	public void startLiquidGather() {
+			logger.info("动液面定时采集启动...");
+			Iterator<Channel> iterator=ChannelGroupMgr.iterator();
+			Channel channel=null;
+			while(iterator.hasNext()) {
+				channel=iterator.next();
+				GatherTaskExecutor.execute(new GatherLiquidTask(channel));
+			}
+	}
+	
 }

+ 1 - 1
src/main/java/com/hb/proj/gather/business/GatherSingleTask.java → src/main/java/com/hb/proj/gather/scheduler/GatherSingleTask.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.scheduler;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

+ 1 - 1
src/main/java/com/hb/proj/gather/business/GatherTask.java → src/main/java/com/hb/proj/gather/scheduler/GatherTask.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.scheduler;
 
 import java.util.Date;
 

+ 3 - 2
src/main/java/com/hb/proj/gather/business/GatherTaskExecutor.java → src/main/java/com/hb/proj/gather/scheduler/GatherTaskExecutor.java

@@ -1,4 +1,4 @@
-package com.hb.proj.gather.business;
+package com.hb.proj.gather.scheduler;
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -19,8 +19,9 @@ public class GatherTaskExecutor {
 			
 	private static final ExecutorService  executor=new ThreadPoolExecutor(5,30,30,TimeUnit.MINUTES,new LinkedBlockingQueue<Runnable>(20),new ThreadPoolExecutor.CallerRunsPolicy());
 	
+	 //execute 只能执行无返回结果的任务,submit 可以返回结果Feture,任务有两种:runnable,callable
 	public static void execute(Runnable task){
-		executor.submit(task);   //execute 只能执行无返回结果的任务,submit 可以返回结果Feture,任务有两种:runnable,callable
+		executor.submit(task);  
 	}
 	
 	public static void shutdown() {

+ 1 - 3
src/main/java/com/hb/proj/gather/server/MyChannelInitializer.java

@@ -27,9 +27,7 @@ public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
 				.addLast(new IdleStateHandler(100,0,0,TimeUnit.SECONDS))  //100秒无读操作约三次心跳时间
 				.addLast(new ZlA11MsgDecoder())
 				.addLast(new ZLOpdProtHandler());
-				//发送的数据时行文字编码
-                //.addLast("encoder", new StringEncoder(StandardCharsets.UTF_8))
-			    //.addLast(new GatherProtocolHandler());
+				
 	}
 
 }

+ 2 - 2
src/main/java/com/hb/proj/gather/server/NettyGatherRunner.java

@@ -8,7 +8,7 @@ import org.springframework.boot.ApplicationRunner;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
-import com.hb.proj.gather.business.DataTransConfig;
+import com.hb.proj.gather.process.DataTransConfig;
 
 @Component
 @Order(1)
@@ -26,7 +26,7 @@ public class NettyGatherRunner implements ApplicationRunner {
 			
 			//(new DataAssembler()).start();
 			DataTransConfig.init();
-			nettyGatherServer.start(9610);
+			nettyGatherServer.start(9603);
 			
 		}).start();
 		

+ 1 - 1
src/main/java/com/hb/proj/gather/server/NettyGatherServer.java

@@ -4,7 +4,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
-import com.hb.proj.gather.business.GatherTaskExecutor;
+import com.hb.proj.gather.scheduler.GatherTaskExecutor;
 
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.Channel;

+ 38 - 3
src/main/java/com/hb/proj/gather/utils/Crc16Utils.java

@@ -1,5 +1,8 @@
 package com.hb.proj.gather.utils;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class Crc16Utils {
 
 	/**
@@ -64,8 +67,40 @@ public class Crc16Utils {
     public static void main(String[] args) {
        // int[] data = new int[]{0x01, 0x03, 0x03, 0xd7, 0x00, 0x01};
        // System.out.println(Crc16Utils.crc16(data));
-        
-        byte[] data2 = {0x01, 0x03, 0x03, (byte)0xd7, 0x00, 0x01};
-        System.out.println(Crc16Utils.getCRC(data2));
+    	String[] addrs= {"1810","188D","190A","1987","1A04","1A81","1AFE","1B7B","1BF8","1C75","1CF2","1D6F","1DEC","1E69","1EE6","1F63","1FE0","205D","20DA","2157","21D4","2251","22CE","234B","23C8","2445","24C2","253F","25BC","2639","26B6","2733","27B0","282D","28AA","2927","29A4","2A21","2A9E","2B1B"};
+        int[]  cmds=null;
+        int ad1=0,ad2=0;
+        String s1,s2=null,crc=null;
+        String cmdstr=null;
+    	for(String adr : addrs) {
+    		
+    		ad1=Integer.parseInt(adr.substring(0,2),16);
+    		ad2=Integer.parseInt(adr.substring(2,4),16);
+    		cmds=new int[] {0x01,0x03,ad1,ad2,0x00,0x7d};
+    		crc=Crc16Utils.crc16(cmds);
+    		
+    		
+    		System.out.println(crc);
+    		
+    		s1=(ad1>0x7f?"(byte)0x":"0x")+adr.substring(0,2);
+    		s2=(ad2>0x7f?"(byte)0x":"0x")+adr.substring(2,4);
+    		
+    		cmdstr="0x01,0x03,"+s1+","+s2+",0x00,0x7d";
+    		
+    		if(crc.length()>3) {
+    			ad1=Integer.parseInt(crc.substring(0,2),16);
+        		ad2=Integer.parseInt(crc.substring(2,4),16);
+        		
+        		s1=(ad1>0x7f?"(byte)0x":"0x")+crc.substring(0,2);
+        		s2=(ad2>0x7f?"(byte)0x":"0x")+crc.substring(2,4);
+        		
+        		cmdstr+=","+s1+","+s2;
+    		}
+    		
+    		
+    		System.out.println(cmdstr);
+    	}
+       
+       // System.out.println(Integer.toHexString(Crc16Utils.getCRC(data2)));
     }
 }