Просмотр исходного кода

电网光功率102传输协议实现

songwenbin 1 год назад
Родитель
Сommit
e147f0604e

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

@@ -262,7 +262,7 @@ public class Iec104Session {
                 //todo:考虑实现确认S帧
 
                 //重置point列表缓存,消息地址,其它内容不变
-                if (i < allPoints.size()-1) {
+                if (i <= allPoints.size()-1) {
                     pointList = new ArrayList<>();
                     msg104 = createNewMessage(isContinous,pointType);
                     if (isContinous)

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

@@ -31,8 +31,8 @@ public class Iec104Encoder extends MessageToByteEncoder<Iec104Message> {
 			}
 
 		} catch (Exception e) {
-//			log.error(e.getMessage());
-//			e.printStackTrace();
+			log.error(e.getMessage());
+			e.printStackTrace();
 			throw e;
 		}
 

+ 12 - 3
gdnxfgs/src/main/java/com/gyee/edge/gddlly/iec104/handler/Iec104ServerHandler.java

@@ -15,20 +15,29 @@ import java.util.concurrent.ConcurrentHashMap;
 @Slf4j
 public class Iec104ServerHandler extends SimpleChannelInboundHandler<Iec104Message> {
 
-	private Map<String, Iec104Session> sessionMap = new ConcurrentHashMap<>();
+	private static Map<String, Iec104Session> sessionMap = new ConcurrentHashMap<>();
 
 	
 	@Override
 	public void channelActive(ChannelHandlerContext ctx) throws Exception {
+
+		int counter = sessionMap.size();
+		if (counter > 100) {
+			ctx.close();
+			log.warn("连接数达到上限!");
+			return;
+		}
+
 		// 注册Session
 		Iec104Session session = new Iec104Session(ctx);
 		if (sessionMap.containsKey(session.getId())) {
+			log.info("这种情况应该不会出现!");
 			sessionMap.get(session.getId()).stop();
 		}
 
 		sessionMap.put(session.getId(), session);
-		log.info("建立新连接,sessionid = " + session.getId());
-		log.info("当前连接数:" + sessionMap.keySet().size());
+		log.info("建立新连接,sessionid = " + session.getId() + ", total = " + sessionMap.size());
+		//log.info("当前连接数:" + sessionMap.keySet().size());
 	}
 
 	@Override

+ 1 - 1
gdnxfgs/src/main/java/com/gyee/edge/gddlly/redis/RedisDataService.java

@@ -138,7 +138,7 @@ public class RedisDataService {
                     double value = Double.valueOf(mp.get("value")).doubleValue();
                     if (point.getValue() != value) {
                         point.setConsumed(false);
-                        log.info("*#$ point:" + point.getPoint() + "changed!");
+//                        log.info("*#$ point:" + point.getPoint() + "changed!");
                         point.setValue(value);
                         point.setLastUpdateTime(new Date(time));
                     }