Browse Source

104召唤报文格式调试修改

songwenbin 2 years ago
parent
commit
efc5b650ae

+ 1 - 0
gddlly/src/main/java/com/gyee/edge/gddlly/Bootstrap.java

@@ -18,6 +18,7 @@ import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
+import java.util.Date;
 import java.util.Map;
 
 @Slf4j

+ 2 - 1
gddlly/src/main/java/com/gyee/edge/gddlly/config/Point.java

@@ -20,6 +20,7 @@ public class Point {
     // 如果value变化,将consumed置为false;
     private boolean consumed;
 
-    private Date lastUpdateTime;
+    //此处赋初始值,主要是为了防止redis中不存在点表中的点,空值引起后续数据转换错误!
+    private Date lastUpdateTime = new Date(0);
 
 }

+ 2 - 2
gddlly/src/main/java/com/gyee/edge/gddlly/iec104/Iec104Session.java

@@ -198,9 +198,10 @@ public class Iec104Session {
             int firstMsgAddr = allPoints.get(0).getPointAddr();
             msg104.setMessageAddress(firstMsgAddr);
         }
-
+       // log.info(allPoints.get(0).getPoint() + allPoints.get(0).getValue());
         for(int i=0;i<allPoints.size();i++) {
             Point point = allPoints.get(i);
+
             if (!isContinous && point.isConsumed())
                 continue;
 
@@ -262,7 +263,6 @@ public class Iec104Session {
     }
 
     private synchronized void sendMessage(Iec104Message msg) {
-
         msg.setSendSeq(sendSeq++);
         log.info("send message:" + msg.getSendSeq() + ", address = " + msg.getMessageAddress()
                 + ",type= " + msg.getTypeIdentifier()) ;

+ 10 - 2
gddlly/src/main/java/com/gyee/edge/gddlly/iec104/handler/Iec104Encoder.java

@@ -22,7 +22,15 @@ public class Iec104Encoder extends MessageToByteEncoder<Iec104Message> {
 	
 	@Override
 	protected void encode(ChannelHandlerContext ctx, Iec104Message msg, ByteBuf out) throws Exception {
-		byte[] bytes = Encoder104.encoder(msg);
+		try {
+			byte[] bytes = Encoder104.encoder(msg);
+			out.writeBytes(bytes);
+		} catch (Exception e) {
+//			log.error(e.getMessage());
+//			e.printStackTrace();
+			throw e;
+		}
+
 //		if(bytes.length > 6) {
 //			short accept = Iec104ThreadLocal.getControlPool().getAccept();
 //			short send = Iec104ThreadLocal.getControlPool().getSend();
@@ -38,7 +46,7 @@ public class Iec104Encoder extends MessageToByteEncoder<Iec104Message> {
 //			log.info(ByteUtil.byteArrayToHexString(bytes));
 //		}
 
-		out.writeBytes(bytes);
+
 	}
 
 }

+ 8 - 2
gddlly/src/main/java/com/gyee/edge/gddlly/redis/RedisDataService.java

@@ -43,6 +43,10 @@ public class RedisDataService {
                 double value = Double.valueOf(vs.substring(1, vs.lastIndexOf("\"")));
 
                 point.setLastUpdateTime(new Date(time));
+                if (point.getLastUpdateTime() == null) {
+                    log.error("数据日期格式错误!" + vls);
+                    point.setLastUpdateTime(new Date());
+                }
                 if (point.getValue() != value ) {
                     point.setConsumed(false);
                     point.setValue(value);
@@ -106,8 +110,10 @@ public class RedisDataService {
                     point.setLastUpdateTime(new Date(time));
                 }
 
-                if (point.getLastUpdateTime() == null)
-                    point.setLastUpdateTime(new Date(time));
+//                if (point.getLastUpdateTime() == null)
+//                    point.setLastUpdateTime(new Date(time));
+
+
 
             }
         } catch (Exception e){