| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.simRtu202404.tcpClient.upData; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V202404.ProtocolConstantV206V202404; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V202404.parse.global.GlCreate; | 
|---|
|  |  |  | import com.dy.common.util.ByteUtil; | 
|---|
|  |  |  | import org.apache.mina.core.session.IoSession; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Author: liurunyu | 
|---|
|  |  |  | * @Date: 2025/02/26 11:10 | 
|---|
|  |  |  | * @Description | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public class UpData { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected static IoSession session ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static Object synObj = new Object() ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void setSession(IoSession session){ | 
|---|
|  |  |  | UpData.session = session ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected static void upSend(byte[] bs) throws Exception{ | 
|---|
|  |  |  | synchronized (synObj){ | 
|---|
|  |  |  | session.write(bs) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected static byte[] creatHead(String rtuAddr, String code, byte ctrl)throws Exception { | 
|---|
|  |  |  | byte[] bsHead = new byte[ProtocolConstantV206V202404.lenHead2Code] ; | 
|---|
|  |  |  | byte index = 0 ; | 
|---|
|  |  |  | bsHead[index] = ProtocolConstantV206V202404.P_Head_Byte ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | bsHead[index] = 0 ;//帧长度 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | bsHead[index] = ProtocolConstantV206V202404.P_Head_Byte ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | bsHead[index] = ctrl; //控制域功能码 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | GlCreate.createRtuAddr(rtuAddr, bsHead, index); | 
|---|
|  |  |  | index += 8 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ByteUtil.hex2Bytes(code, bsHead, index) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return bsHead ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|