From dfe62588ca792d4a5eb3e2722675e7263aa46a4e Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期五, 29 十二月 2023 00:28:51 +0800
Subject: [PATCH] 吴家粮库协议解析-1

---
 src/main/java/com/fzzy/protocol/wujia/client/ClientHandler.java             |   65 +++++
 src/main/java/com/fzzy/protocol/wujia/package-info.java                     |    4 
 src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java         |  232 +++++++++++++++++++++
 src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java              |  147 +++++++++++++
 src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java                  |    1 
 src/main/java/com/fzzy/protocol/wujia/service/WujiaGatewayGrainService.java |  160 ++++++++++++++
 6 files changed, 609 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
index 22c4418..37b46fa 100644
--- a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
+++ b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
@@ -17,6 +17,7 @@
     GRAIN_FZZY_ZLDZ_WEB("GRAIN_FZZY_ZLDZ_WEB", "绮儏-FZZY-ZLDZ缃戝彛鍗忚"),
     GRAIN_YOUXIAN0_2023("GRAIN_YOUXIAN0_2023", "绮儏-娓镐粰涓诲簱鍗忚"),
     GRAIN_YOUXIAN1_2023("GRAIN_YOUXIAN1_2023", "绮儏-娓镐粰鍒嗗簱鍗忚"),
+    GRAIN_WUJIA_2023("GRAIN_WUJIA_2023", "绮儏-鍚村绮簱鍗忚"),
     DEVICE_WEIGHT_HTTP("DEVICE_WEIGHT_HTTP", "鍦扮-HTTP鍗忚"),
     DEVICE_WEIGHT_TCP_YH("DEVICE_WEIGHT_TCP_YH", "鍦扮-鑰�鍗嶵CP鍗忚"),
     DEVICE_IDCARD_HTTP("DEVICE_IDCARD_HTTP", "韬唤璇�-HTTP鍗忚"),
diff --git a/src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java
new file mode 100644
index 0000000..e5d8c2a
--- /dev/null
+++ b/src/main/java/com/fzzy/protocol/wujia/analysis/AnalysisService.java
@@ -0,0 +1,232 @@
+package com.fzzy.protocol.wujia.analysis;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fzzy.api.data.GatewayDeviceType;
+import com.fzzy.api.utils.BytesUtil;
+import com.fzzy.api.utils.NumberUtil;
+import com.fzzy.gateway.GatewayUtils;
+import com.fzzy.gateway.api.GatewayDeviceReportService;
+import com.fzzy.gateway.api.GatewayRemoteManager;
+import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.data.WeatherWebDto;
+import com.fzzy.gateway.entity.GatewayDevice;
+import com.fzzy.gateway.hx2023.ScConstant;
+import com.fzzy.gateway.hx2023.data.*;
+import com.fzzy.protocol.ProtocolUtils;
+import com.fzzy.protocol.bhzn.cmd.ReMessageBuilder;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+@Slf4j
+@Component(AnalysisService.BEAN_ID)
+public class AnalysisService {
+
+    public static final String BEAN_ID = "wujia.analysisService";
+
+
+    @Resource
+    private GatewayRemoteManager gatewayRemoteManager;
+
+
+    /**
+     * 绮儏鎺ョ嚎
+     *
+     * @param address
+     * @param port
+     * @param strMsg
+     */
+    public void analysis(InetAddress address, int port, String strMsg) {
+
+        if (strMsg.startsWith("FE")) {
+
+            //DO NOTHING
+        } else {
+            this.analysisGrainStep1(address, strMsg);
+        }
+    }
+
+    /**
+     * 绮儏瑙f瀽
+     * X1 data1L data1H data2L data2H data3L data3H鈥︹�︹�atanL datanH DATA1H DATA1L DATA2H DATA2L AA BB CC
+     * X1---鍙戦�佺殑搴忓彿  AA BB CC----缁撴潫鏍囧織
+     * DATA1H DATA1L----浠撳唴婀垮害
+     * DATA2H DATA2L----浠撳唴娓╁害
+     * data1L data1H-----18B20杩斿洖娓╁害
+     * 娉ㄦ剰锛氱伯娓╄繑鍥炴暟鎹珮浣嶅湪鍚庯紝浣庝綅鍦ㄥ墠锛岃浆鎹负鍗佽繘鍒跺悗涔樹互0.0625锛屽緱鍒板疄闄呮俯搴﹀��
+     * 浠撴俯婀垮害楂樹綅鍦ㄥ墠锛屼綆浣嶅湪鍚庯紝杞崲涓哄崄杩涘埗鍚庝箻浠�0.1寰楀埌瀹為檯娓╂箍搴﹀��
+     *
+     * @param strMsg
+     */
+    private void analysisGrainStep1(InetAddress address, String strMsg) {
+        int start = 0;
+        int len = 1 * 2;
+        String tag = strMsg.substring(start, start + 2);
+        int depotIdSys = BytesUtil.hexToInt(tag);
+
+        BaseReqData reqData = ProtocolUtils.getSyncReq(depotIdSys + "");
+
+        if (null == reqData) {
+            log.error("---------娌℃湁鑾峰彇鍒拌姹備俊鎭紝涓嶆墽琛岃В鏋�------{}", address);
+            return;
+        }
+
+        //浠撳唴婀垮害
+        start = 1 * 2;
+        len = 2 * 2;
+        tag = strMsg.substring(start, start + len);
+        double hIn = BytesUtil.hexToInt(tag) * 0.1;
+
+        //浠撳唴娓╁害
+        start = 3 * 2;
+        len = 2 * 2;
+        tag = strMsg.substring(start, start + len);
+        double tIn = BytesUtil.hexToInt(tag) * 0.1;
+
+        GatewayDevice device = reqData.getDevice();
+
+        String[] attCable = device.getCableRule().split("-");
+        int cableZ = Integer.valueOf(attCable[0]);
+        int cableY = Integer.valueOf(attCable[1]);
+        int cableX = Integer.valueOf(attCable[2]);
+        log.info("z={},x={},y={}", cableZ, cableX, cableY);
+
+        int sumNum = cableZ * cableY * cableX;
+        //绮俯淇℃伅
+        start = 5 * 2;
+        len = 2 * 2;
+        List<Double> points = new ArrayList<>();
+        double temp = 0.0;
+        for (int i = 0; i < sumNum; i++) {
+            start = start + i * 2 * 2;
+            tag = strMsg.substring(start, start + len);
+            temp = BytesUtil.hexToInt(BytesUtil.tran_LH(tag)) * 0.0625;
+            temp = NumberUtil.keepPrecision(temp, 1);
+            points.add(temp);
+        }
+
+        //鎵ц灏佽瑙f瀽
+        analysisGrainStep2(reqData, cableZ, cableY, cableX, points, hIn, tIn);
+    }
+
+    private void analysisGrainStep2(BaseReqData reqData, int cableZ, int cableY, int cableX, List<Double> points, double hIn, double tIn) {
+        GatewayDevice device = reqData.getDevice();
+        //鏁版嵁灏佽
+        GrainData grain = new GrainData();
+        grain.setMessageId(ScConstant.getMessageId());
+        grain.setDeviceId(device.getDeviceId());
+        grain.setTimestamp(System.currentTimeMillis() + "");
+
+        ClientHeaders headers = new ClientHeaders();
+        headers.setDeviceName(device.getDeviceName());
+        headers.setProductId(device.getProductId());
+        headers.setOrgId(device.getOrgId());
+        headers.setMsgId(reqData.getMessageId());
+        grain.setHeaders(headers);
+
+
+        GrainOutPut outPut = new GrainOutPut();
+
+
+        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum = cableX * cableY * cableZ;
+
+        List<GrainTemp> temperature = new ArrayList<>();
+        //鏍瑰彿
+        int cableNum = 1, position = 0;
+
+        double curTemp;
+        int x = 0, y = 0, z = 0;
+        for (int i = 0; i < points.size(); i++) {
+            curTemp = points.get(i);
+            position = i;
+            z = i % cableZ + 1;
+            x = i / (cableZ * cableY);
+            y = x * (cableZ * cableY);
+            y = (i - y) / cableZ;
+            //鏍瑰彿
+            cableNum = (i / cableZ) + 1;
+
+            temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + ""));
+
+            sumT += curTemp;
+            if (curTemp > max) {
+                max = curTemp;
+            }
+            if (curTemp < min) {
+                min = curTemp;
+            }
+        }
+
+        if (sumNum == 0) {
+            sumNum = 1;
+            log.warn("---褰撳墠绮儏閲囬泦寮傚父--");
+        }
+        //杩囨护姣旇緝鐢ㄧ殑鏈�澶ф渶灏忓��
+        if (max == ReMessageBuilder.MAX_TEMP) {
+            max = 0.0;
+        }
+        if (min == ReMessageBuilder.MIN_TEMP) {
+            min = 0.0;
+        }
+
+        outPut.setTemperature(temperature);
+        outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + "");
+        outPut.setMinTemperature(min + "");
+        outPut.setMaxTemperature(min + "");
+        List<GrainTH> ths = new ArrayList<>();
+
+
+        ths.add(new GrainTH(tIn + "", hIn + "", "1"));
+        outPut.setTemperatureAndhumidity(ths);
+        grain.setOutput(JSONObject.toJSONString(outPut));
+
+        GatewayDevice gatewayDeviceWeather = GatewayUtils.getCacheByDeviceTypeOne(GatewayDeviceType.TYPE_09.getCode());
+
+        //绯荤粺姘旇薄绔欎俊鎭�
+        WeatherWebDto weather = WeatherWebDto.contextMap.get("default");
+
+        //姘旇薄淇℃伅
+        GrainWeather weatherStation = new GrainWeather();
+        weatherStation.setMessageId(ScConstant.getMessageId());
+        weatherStation.setMessgeId(weatherStation.getMessageId());
+
+        if (null != gatewayDeviceWeather) {
+            weatherStation.setId(gatewayDeviceWeather.getDeviceId());
+        } else {
+            weatherStation.setId(device.getDeviceId());
+        }
+        weatherStation.setAirPressure(weather.getPressure());
+        weatherStation.setHumidity(weather.getHumidity());
+        weatherStation.setPm(weather.getAir_pm25());
+        weatherStation.setRadiation("0");
+        weatherStation.setRainfallAmount(weather.getWea());
+        weatherStation.setTemperature(weather.getTem());
+        weatherStation.setWindDirection(weather.getWin());
+        weatherStation.setWindPower(weather.getWin_meter());
+        weatherStation.setWindSpeed(weather.getWin_speed());
+
+        grain.setWeatherStation(JSONObject.toJSONString(weatherStation));
+
+        //灏佽濂界殑鏁版嵁
+        log.info("---绮儏淇℃伅灏佽瀹屾垚-寮�濮嬫墽琛屾帹閫�");
+
+        reqData.setData(JSONObject.toJSONString(grain));
+
+        doPushGrain(reqData);
+    }
+
+    private void doPushGrain(BaseReqData reqData) {
+
+        GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol());
+        if (null == reportService) {
+            log.error("------------绮儏鎺ㄩ�佸け璐ワ紝绯荤粺涓嶅瓨鍦ㄥ綋鍓嶅崗璁墽琛岀被----{}", reqData.getDevice().getDeviceName());
+            return;
+        }
+
+        reportService.reportGrainData(reqData);
+    }
+}
diff --git a/src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java b/src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java
new file mode 100644
index 0000000..3e6b01e
--- /dev/null
+++ b/src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java
@@ -0,0 +1,147 @@
+package com.fzzy.protocol.wujia.client;
+
+import com.fzzy.api.utils.BytesUtil;
+import com.ld.io.api.InvokeResult;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.*;
+import io.netty.channel.oio.OioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.oio.OioSocketChannel;
+import io.netty.handler.codec.bytes.ByteArrayDecoder;
+import io.netty.handler.codec.bytes.ByteArrayEncoder;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 閫氳鍗忚
+ */
+@Slf4j
+public class ClientEngine implements Runnable {
+
+    /**
+     * 瀹㈡埛绔ā寮忓垱寤虹殑杩炴帴閫氶亾
+     */
+    public static Map<String, Channel> clientChannelMap = new HashMap<>();
+
+
+    private String host;
+    private int port;
+    private Channel defaultChannel;
+
+
+    public ClientEngine(String host, int port) {
+        this.host = host;
+        this.port = port;
+    }
+
+    public void start() {
+        Thread thread = new Thread(this);
+        thread.start();
+    }
+
+    @Override
+    public void run() {
+        try {
+            startClient();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void startClient() throws Exception {
+
+        EventLoopGroup group = new OioEventLoopGroup();
+        Bootstrap b = new Bootstrap();
+        //榛樿闀胯繛鎺�
+        b.option(ChannelOption.SO_KEEPALIVE, true);
+        b.group(group).channel(OioSocketChannel.class)
+                .handler(new ChannelInitializer<SocketChannel>() {
+                    @Override
+                    protected void initChannel(SocketChannel ch)
+                            throws Exception {
+                        ChannelPipeline p = ch.pipeline();
+                        // 瀛楃涓茶В鐮� 鍜� 缂栫爜
+                        p.addLast("decoder", new ByteArrayDecoder());
+                        p.addLast("encoder", new ByteArrayEncoder());
+                        // 鑷繁鐨勯�昏緫Handler
+                        p.addLast("handler", new ClientHandler());
+                    }
+                });
+
+        // 鍙戣捣寮傛杩炴帴璇锋眰锛岀粦瀹氳繛鎺ョ鍙e拰host淇℃伅
+        ChannelFuture channelFuture = b.connect(host, port);
+        this.defaultChannel = channelFuture.channel();
+        // channelFuture.channel().closeFuture().sync();
+
+        this.add2ChannelMap(host, defaultChannel);
+
+        channelFuture.addListener(new ChannelFutureListener() {
+            @Override
+            public void operationComplete(ChannelFuture arg0) throws Exception {
+                if (channelFuture.isSuccess()) {
+                    log.info("-----IP={},杩炴帴鎴愬姛", host);
+                } else {
+                    log.info("-----IP={},杩炴帴澶辫触锛岃嚜鍔ㄥ叧闂嚎绋�", host);
+                    channelFuture.cause().printStackTrace();
+                    group.shutdownGracefully(); // 鍏抽棴绾跨▼缁�
+                }
+            }
+        });
+    }
+
+    public InvokeResult send(byte[] array) throws InterruptedException {
+
+        if (null == defaultChannel) {
+            return InvokeResult.SOCKET_NOT_CREATE;
+        }
+        if (!defaultChannel.isActive()) {
+            return InvokeResult.CHANNEL_CLOSED;
+        }
+
+        defaultChannel.writeAndFlush(Unpooled.copiedBuffer(array)).sync();
+
+        return InvokeResult.SUCCESS;
+    }
+
+
+    public Channel getChannel() {
+        return defaultChannel;
+    }
+
+    public static void add2ChannelMap(String key, Channel channel) {
+        clientChannelMap.put(key, channel);
+    }
+
+    /**
+     * 濡傛灉
+     *
+     * @param key
+     * @return
+     */
+    public static Channel getChannel(String key) {
+        Channel channel = clientChannelMap.get(key);
+        if (null == channel) return null;
+        if (channel.isActive()) {
+            return channel;
+        } else {
+            channel.close();
+        }
+        return null;
+    }
+
+    public static InvokeResult send2(String hex, Channel channel) throws InterruptedException {
+        if (null == channel) {
+            return InvokeResult.SOCKET_NOT_CREATE;
+        }
+        if (!channel.isActive()) {
+            return InvokeResult.CHANNEL_CLOSED;
+        }
+        channel.writeAndFlush(Unpooled.copiedBuffer(BytesUtil.hexStrToBytes(hex))).sync();
+        return InvokeResult.SUCCESS;
+    }
+
+
+}
diff --git a/src/main/java/com/fzzy/protocol/wujia/client/ClientHandler.java b/src/main/java/com/fzzy/protocol/wujia/client/ClientHandler.java
new file mode 100644
index 0000000..1f87e38
--- /dev/null
+++ b/src/main/java/com/fzzy/protocol/wujia/client/ClientHandler.java
@@ -0,0 +1,65 @@
+package com.fzzy.protocol.wujia.client;
+
+import com.fzzy.api.utils.BytesUtil;
+import com.fzzy.api.utils.SpringUtil;
+import com.fzzy.protocol.wujia.analysis.AnalysisService;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import lombok.extern.slf4j.Slf4j;
+
+import java.net.InetSocketAddress;
+
+
+@Slf4j
+public class ClientHandler extends SimpleChannelInboundHandler<Object> {
+
+    private AnalysisService analysisService;
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) {
+        InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel()
+                .remoteAddress();
+
+        log.info("杩炴帴缁堟垚鍔燂紝IP={},port={}", socketAddress.getAddress()
+                .getHostAddress(), socketAddress.getPort());
+    }
+
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+        super.channelInactive(ctx);
+
+        InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
+
+        log.info("杩炴帴缁堢鎺夌嚎锛孖P={},port={}", socketAddress.getAddress(), socketAddress.getPort());
+
+
+    }
+
+    @Override
+    public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
+        byte[] bytes = (byte[]) msg;
+
+        InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
+
+        String strMsg = BytesUtil.bytesToString(bytes);
+
+        log.info("缁堢杩斿洖淇℃伅锛孖P={},port={}锛宮sg={}", socketAddress.getAddress(), socketAddress.getPort(), strMsg);
+
+        if (null == analysisService) {
+            analysisService = SpringUtil.getBean(AnalysisService.class);
+        }
+
+       try{
+           analysisService.analysis(socketAddress.getAddress(), socketAddress.getPort(), strMsg);
+       }catch (Exception e){
+           log.error(e.getMessage(),e);
+       }
+
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        ctx.close();
+    }
+
+}
diff --git a/src/main/java/com/fzzy/protocol/wujia/package-info.java b/src/main/java/com/fzzy/protocol/wujia/package-info.java
new file mode 100644
index 0000000..0d44dd6
--- /dev/null
+++ b/src/main/java/com/fzzy/protocol/wujia/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * 鍚村绮簱2023
+ */
+package com.fzzy.protocol.wujia;
\ No newline at end of file
diff --git a/src/main/java/com/fzzy/protocol/wujia/service/WujiaGatewayGrainService.java b/src/main/java/com/fzzy/protocol/wujia/service/WujiaGatewayGrainService.java
new file mode 100644
index 0000000..2196a8e
--- /dev/null
+++ b/src/main/java/com/fzzy/protocol/wujia/service/WujiaGatewayGrainService.java
@@ -0,0 +1,160 @@
+package com.fzzy.protocol.wujia.service;
+
+import com.fzzy.api.data.GatewayDeviceProtocol;
+import com.fzzy.gateway.api.GatewaySyncGranService;
+import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.entity.GatewayDevice;
+import com.fzzy.protocol.ProtocolUtils;
+import com.fzzy.protocol.youxian0.client.ClientEngine;
+import com.ld.io.api.InvokeResult;
+import io.netty.channel.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 绮儏閲囬泦鍏ュ彛
+ */
+@Slf4j
+@Component
+public class WujiaGatewayGrainService implements GatewaySyncGranService {
+
+
+    @Override
+    public String getGrainProtocol() {
+        return GatewayDeviceProtocol.GRAIN_WUJIA_2023.getCode();
+    }
+
+
+    /**
+     * 浠撳簱鍛戒护
+     */
+    public static Map<String, String> depotGrainCmdMap = new HashMap<>();
+
+
+    static {
+        depotGrainCmdMap.put("KEY_1", "FC0101010314030100BDDB");
+        depotGrainCmdMap.put("KEY_2", "FC0102040318030200BDDB");
+        depotGrainCmdMap.put("KEY_3", "FC0203010318040100BDDB");
+        depotGrainCmdMap.put("KEY_4", "FC0304010318040100BDDB");
+        depotGrainCmdMap.put("KEY_5", "FC0305040318040200BDDB");
+        depotGrainCmdMap.put("KEY_6", "FC0406010210030100BDDB");
+        depotGrainCmdMap.put("KEY_7", "FC0407030314030200BDDB");
+        depotGrainCmdMap.put("KEY_8", "FC0408060314030300BDDB");
+        depotGrainCmdMap.put("KEY_9", "FC050901042A040100BDDB");
+        depotGrainCmdMap.put("KEY_10", "FC050A010324040100BDDB");
+        depotGrainCmdMap.put("KEY_11", "FC060B04042A040200BDDB");
+    }
+
+    /**
+     * 1浠擄細 FC 01 01 01 03 14 03 01 00 BD DB
+     * 2浠擄細 FC 01 02 04 03 18 03 02 00 BD DB
+     * 3浠擄細 FC 02 03 01 03 18 04 01 00 BD DB
+     * 4浠擄細 FC 03 04 01 03 18 04 01 00 BD DB
+     * 5浠擄細 FC 03 05 04 03 18 04 02 00 BD DB
+     * 6浠擄細 FC 04 06 01 02 10 03 01 00 BD DB
+     * 7浠擄細 FC 04 07 03 03 14 03 02 00 BD DB
+     * 8浠擄細 FC 04 08 06 03 14 03 03 00 BD DB
+     * 9浠擄細 FC 05 09 01 04 2A 04 01 00 BD DB
+     * 10浠擄細FC 05 0A 01 03 24 04 01 00 BD DB
+     * 11浠擄細FC 06 0B 04 04 2A 04 02 00 BD DB
+     *
+     * @param reqData
+     * @return
+     */
+    @Override
+    public synchronized BaseResp syncGrain(BaseReqData reqData) {
+
+        BaseResp resp = new BaseResp();
+
+        GatewayDevice device = reqData.getDevice();
+
+        if (null == device) {
+            resp.setCode(500);
+            resp.setMsg("绯荤粺鏈幏鍙栧埌涓嬭杩炴帴璁惧淇℃伅锛屾棤娉曟墽琛�");
+            log.error("----------------绯荤粺鏈幏鍙栧埌涓嬭杩炴帴璁惧淇℃伅,鏃犳硶鎵ц---------");
+            return resp;
+        }
+        try {
+            //Step 璇锋眰淇℃伅鏀惧叆鍐呭瓨
+            ProtocolUtils.addSyncReq2Map(device.getDepotIdSys(), reqData);
+
+            String hexStr = buildGrainCmd(device);
+
+            Channel channel = null;
+            if (null == channel) {
+                ClientEngine clientEngine = new ClientEngine(device.getIp(), device.getPort());
+                clientEngine.start();
+                Thread.sleep(300);
+                channel = clientEngine.getChannel();
+            }
+
+            InvokeResult message = ClientEngine.send2(hexStr, channel);
+
+            log.error("骞冲彴------>>>>涓绘帶锛氬彂閫佺伯鎯呮娴嬪懡浠�-{}---{}", message, hexStr);
+
+            // 灏佽杩斿洖淇℃伅
+            if (!InvokeResult.SUCCESS.getCode().equals(message.getCode())) {
+                log.error("骞冲彴------>>>>鎺у埗鏌滐細鍙戦�佺伯鎯呮娴嬪懡浠�-澶辫触{}", message.getMessage());
+                resp.setCode(500);
+                resp.setMsg("骞冲彴------>>>>鎺у埗鏌滐細鍙戦�佺伯鎯呮娴嬪懡浠�-澶辫触锛�" + message.getMessage());
+            }
+        } catch (
+                Exception e) {
+            log.error("绮儏妫�娴嬪紓甯革細{}", e);
+            resp.setCode(500);
+            resp.setMsg("骞冲彴------>>>>鎺у埗鏌滐細鍙戦�佺伯鎯呮娴嬪懡浠わ細" + e.getMessage());
+            return resp;
+        }
+        return resp;
+    }
+
+    @Override
+    public BaseResp syncGrainTh(BaseReqData reqData) {
+
+        BaseResp resp = new BaseResp();
+        return resp;
+    }
+
+    /**
+     * 鐢熸垚绮儏閲囬泦鍛戒护
+     *
+     * @param device
+     * @return
+     */
+    private String buildGrainCmd(GatewayDevice device) {
+
+        String key = "KEY_" + device.getDepotIdSys();
+
+        return depotGrainCmdMap.get(key);
+
+    }
+
+    @Override
+    public BaseResp syncConf(BaseReqData reqData) {
+        return new BaseResp();
+    }
+
+    @Override
+    public BaseResp writeConf(BaseReqData reqData) {
+        return new BaseResp();
+    }
+
+    @Override
+    public BaseResp initCable(BaseReqData reqData) {
+        return new BaseResp();
+    }
+
+    @Override
+    public BaseResp disconnect(BaseReqData reqData) {
+        return new BaseResp();
+    }
+
+    @Override
+    public BaseResp transparent(BaseReqData reqData) {
+        return new BaseResp();
+    }
+}

--
Gitblit v1.9.3