Y_ANXI 2 anni fa
parent
commit
f7cefceb61

+ 0 - 0
fd5a18f983da4b56b4c9226cebf77b40-tcp47961231801883/.lck


+ 10 - 6
src/main/java/com/yunfei/adapter/accept/MqttSubscriber.java

@@ -26,6 +26,7 @@ public class MqttSubscriber implements MqttCallback {
     private HashMap<String, String> map = new HashMap<>();
     private HashMap<String, String> map = new HashMap<>();
 
 
 
 
+    //声明了监听的队列(初始化监听队列)
     @PostConstruct
     @PostConstruct
     public void init() throws MqttException {
     public void init() throws MqttException {
          String[] topic = {
          String[] topic = {
@@ -50,22 +51,25 @@ public class MqttSubscriber implements MqttCallback {
     }
     }
 
 
     @Override
     @Override
+    /**
+     * 实际接收消息
+     */
     public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
     public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
         try {
         try {
             String[] split = s.split("/");
             String[] split = s.split("/");
-            String deviceId = split[2];
-            String product = split[1];
+            String deviceId = split[2]; //从Mqtt topic上取设备编号
+            String product = split[1]; //从Mqtt topic上取产品编号
             JSONObject obj = JSON.parseObject(new String(mqttMessage.getPayload(), StandardCharsets.UTF_8));
             JSONObject obj = JSON.parseObject(new String(mqttMessage.getPayload(), StandardCharsets.UTF_8));
             obj.put("deviceId", deviceId);
             obj.put("deviceId", deviceId);
-            if (!obj.containsKey("functionId")) {
+            if (!obj.containsKey("functionId")) { //根据方法id动态加载方法
                 return;
                 return;
             }
             }
-            if (map.get(product) != null) {
+            if (map.get(product) != null) {  //从配置项中根据产品获取对应的适配器
                 Object bean = beanInit.getBean(map.get(product));
                 Object bean = beanInit.getBean(map.get(product));
                 Method[] declaredMethods = bean.getClass().getDeclaredMethods();
                 Method[] declaredMethods = bean.getClass().getDeclaredMethods();
                 for (Method declaredMethod : declaredMethods) {
                 for (Method declaredMethod : declaredMethods) {
-                    if (declaredMethod.getName().equals(obj.get("functionId"))) {
-                        declaredMethod.setAccessible(true);
+                    if (declaredMethod.getName().equals(obj.get("functionId"))) { //根据MQTT传过来来的方法名 加载方法
+                        declaredMethod.setAccessible(true); //将访问修饰符设置为public
                         declaredMethod.invoke(bean, new String(mqttMessage.getPayload(), StandardCharsets.UTF_8));
                         declaredMethod.invoke(bean, new String(mqttMessage.getPayload(), StandardCharsets.UTF_8));
                     }
                     }
                 }
                 }

+ 1 - 0
src/main/java/com/yunfei/adapter/accept/NhhFunction.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 
 
 import java.util.HashMap;
 import java.util.HashMap;
 
 
+//农哈哈
 public class NhhFunction {
 public class NhhFunction {
 
 
     public void NHHJp(JSONObject obj) {
     public void NHHJp(JSONObject obj) {

+ 2 - 0
src/main/java/com/yunfei/adapter/accept/UniagroFunction.java

@@ -9,11 +9,13 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.HashMap;
 
 
+//指针 转盘
 @Component
 @Component
 @Function(name = "uniagro")
 @Function(name = "uniagro")
 public class UniagroFunction {
 public class UniagroFunction {
     @Resource
     @Resource
     private UniagroHttp uniagroHttp;
     private UniagroHttp uniagroHttp;
+
     @Function
     @Function
     public void buttonCommand(String msg) {
     public void buttonCommand(String msg) {
         JSONObject obj = JSON.parseObject(msg);
         JSONObject obj = JSON.parseObject(msg);

+ 3 - 0
src/main/java/com/yunfei/adapter/http/uniagro/runner/ScheduledTasks.java

@@ -33,6 +33,9 @@ public class ScheduledTasks {
     int i = 0;
     int i = 0;
 
 
     @Scheduled(fixedRate = 20000)
     @Scheduled(fixedRate = 20000)
+    /**
+     * 轮询http接口查询设备状态 转发给MQTT(毅飞)
+     */
     public void performTask() {
     public void performTask() {
         i++;
         i++;
         for (Pair<String, String> device : deviceIds) {
         for (Pair<String, String> device : deviceIds) {

+ 14 - 0
src/main/java/com/yunfei/adapter/tcp/qj/JqSdSjHandle.java

@@ -26,12 +26,21 @@ public class JqSdSjHandle {
      * @param channelContext
      * @param channelContext
      */
      */
     public static void JqSDSJHandle(Packet packet, ChannelContext channelContext) throws MqttException {
     public static void JqSDSJHandle(Packet packet, ChannelContext channelContext) throws MqttException {
+        /**
+         * 固定写法 取出命令json串
+         */
         MqttPublisher bean = StaticMethodGetBean.getBean(MqttPublisher.class);
         MqttPublisher bean = StaticMethodGetBean.getBean(MqttPublisher.class);
         DefPacket defPackage = (DefPacket) packet;
         DefPacket defPackage = (DefPacket) packet;
         byte[] body = defPackage.getBody();
         byte[] body = defPackage.getBody();
         byte[] resultArray = Arrays.copyOfRange(body, 0, defPackage.getLen());
         byte[] resultArray = Arrays.copyOfRange(body, 0, defPackage.getLen());
         String str = new String(resultArray, StandardCharsets.US_ASCII);
         String str = new String(resultArray, StandardCharsets.US_ASCII);
+
+
         System.err.println(str);
         System.err.println(str);
+
+        /**
+         * 取出json中的frame(帧类型)
+         */
         JSONObject jsonObject = JSON.parseObject(str);
         JSONObject jsonObject = JSON.parseObject(str);
         if (!jsonObject.containsKey("frame")) {
         if (!jsonObject.containsKey("frame")) {
             if (jsonObject.containsKey("rssi")) {
             if (jsonObject.containsKey("rssi")) {
@@ -44,14 +53,19 @@ public class JqSdSjHandle {
             return;
             return;
         }
         }
         String frame = jsonObject.getString("frame");
         String frame = jsonObject.getString("frame");
+
+
         switch (frame) {
         switch (frame) {
             case "reg":
             case "reg":
                 TioUtil.send(channelContext, register(jsonObject));
                 TioUtil.send(channelContext, register(jsonObject));
                 return;
                 return;
             case "login":
             case "login":
+                //将设备注册号与 通道绑定
                 Tio.bindUser(channelContext, jsonObject.getString("reg_sn"));
                 Tio.bindUser(channelContext, jsonObject.getString("reg_sn"));
+                //通过通道 发送给具体的某个设备登录响应
                 TioUtil.send(channelContext, login(jsonObject.getString("reg_sn"), jsonObject.get("pak_sn")));
                 TioUtil.send(channelContext, login(jsonObject.getString("reg_sn"), jsonObject.get("pak_sn")));
                 return;
                 return;
+
             case "device":
             case "device":
                 bean.publish("/JQSDSJ/" + channelContext.userid + "/property/report", paramsToInputs(jsonObject).toJSONString());
                 bean.publish("/JQSDSJ/" + channelContext.userid + "/property/report", paramsToInputs(jsonObject).toJSONString());
                 return;
                 return;

+ 1 - 5
src/main/java/com/yunfei/adapter/tcpclient/JSSFClientFactory.java

@@ -1,10 +1,6 @@
 package com.yunfei.adapter.tcpclient;
 package com.yunfei.adapter.tcpclient;
 
 
 
 
-import com.alibaba.fastjson.JSONObject;
-import com.yunfei.adapter.tcp.DefPacket;
-import com.yunfei.adapter.tcp.TcpGroup;
-import org.checkerframework.checker.units.qual.C;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
@@ -15,9 +11,9 @@ import org.tio.core.Node;
 
 
 import java.io.IOException;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map;
 
 
+//江苏水肥连接工厂
 @Component
 @Component
 public class JSSFClientFactory implements ApplicationRunner {
 public class JSSFClientFactory implements ApplicationRunner {
     public static  Map<String, ClientTioConfig> map = new HashMap<String, ClientTioConfig>() {{
     public static  Map<String, ClientTioConfig> map = new HashMap<String, ClientTioConfig>() {{

+ 1 - 0
src/main/java/com/yunfei/adapter/tcpclient/JSSFClientHandle.java

@@ -15,6 +15,7 @@ import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.*;
 
 
+//江苏水肥客户端处理器
 public class JSSFClientHandle implements ClientAioHandler {
 public class JSSFClientHandle implements ClientAioHandler {
     private String userId;
     private String userId;
 
 

+ 1 - 0
src/main/java/com/yunfei/adapter/tcpclient/JSSFClientListener.java

@@ -9,6 +9,7 @@ import org.tio.core.intf.Packet;
 
 
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
 
 
+//江苏水肥客户端监听器
 public class JSSFClientListener implements ClientAioListener {
 public class JSSFClientListener implements ClientAioListener {
 
 
     private String userId;
     private String userId;

+ 1 - 0
src/main/java/com/yunfei/adapter/tcpclient/JSSFScanner.java

@@ -16,6 +16,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.*;
 
 
 @Component
 @Component
+//江苏水肥扫描器(心跳扫描)
 public class JSSFScanner {
 public class JSSFScanner {
     @Resource
     @Resource
     private MqttPublisher mqttPublisher;
     private MqttPublisher mqttPublisher;

+ 2 - 0
src/main/resources/application.yml

@@ -0,0 +1,2 @@
+server:
+  port: 8086