Переглянути джерело

add:新网关,双人对抗

zzf 11 місяців тому
батько
коміт
d8ed72952a

+ 34 - 1
api/gateway/gateway.go

@@ -15,6 +15,7 @@ import (
 	"github.com/gin-gonic/gin"
 	log "github.com/sirupsen/logrus"
 	"io/ioutil"
+	"os"
 	"strconv"
 	"strings"
 	"time"
@@ -591,6 +592,38 @@ func WriteDataEmq(c *gin.Context) {
 // @Success 200 {string} string "ok"
 // @Router /v2/gateway/find [get]
 func FindGateway(c *gin.Context) {
-	response.Success("查询网关设备完成", global.GatewayList, c)
+	marshal, err := json.Marshal(global.GatewayList)
+	if err != nil {
+		return
+	}
+	response.Success("查询网关设备完成", marshal, c)
+	return
+}
+
+// SetGatewayMac
+// PingExample confrontation-training
+// @Summary 保存网关MAC
+// @Schemes
+// @Description 保存网关MAC-脑电写入指令
+// @Tags 设备管理
+// @Param mac body string true "mac:网关MAC地址 "
+// @Accept json
+// @Produce json
+// @Success 200 {string} string "ok"
+// @Router /v2/gateway/set [post]
+func SetGatewayMac(c *gin.Context) {
+	var param gateway.GatewayInfo
+	c.ShouldBindJSON(&param)
+	file, err := os.OpenFile("./config/application.yaml", os.O_APPEND, 0666)
+	if err != nil {
+		response.Failed("读取配置文件失败", c)
+		return
+	}
+	_, err = file.Write([]byte(param.Mac))
+	if err != nil {
+		response.Failed("写入配置文件失败", c)
+		return
+	}
+	response.Success("网关信息保存成功,请重启软件!", "", c)
 	return
 }

+ 1 - 6
config/application.yaml

@@ -60,9 +60,4 @@ emq:
   - MIND
   - BW-ECG
 #  gatewayMac: EE3870DA24C4
-  gatewayMac: FC33BC55470E
-
-#  [{"cmd":"AT+FLT=","total":"2"},{"t":"0","d":"MIND"},{"t":"0","d":"BW-ECG"}]
-
-
-
+  gatewayMac: FC33BC55470E

+ 57 - 0
docs/docs.go

@@ -808,6 +808,63 @@ const docTemplate = `{
                     }
                 }
             }
+        },
+        "/v2/gateway/find": {
+            "get": {
+                "description": "查询可能是蓝牙网关的设备",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "查询可能是蓝牙网关的设备",
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v2/gateway/set": {
+            "post": {
+                "description": "保存网关MAC-脑电写入指令",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "保存网关MAC",
+                "parameters": [
+                    {
+                        "description": "mac:网关MAC地址 ",
+                        "name": "mac",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
         }
     }
 }`

+ 57 - 0
docs/swagger.json

@@ -799,6 +799,63 @@
                     }
                 }
             }
+        },
+        "/v2/gateway/find": {
+            "get": {
+                "description": "查询可能是蓝牙网关的设备",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "查询可能是蓝牙网关的设备",
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
+        "/v2/gateway/set": {
+            "post": {
+                "description": "保存网关MAC-脑电写入指令",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "设备管理"
+                ],
+                "summary": "保存网关MAC",
+                "parameters": [
+                    {
+                        "description": "mac:网关MAC地址 ",
+                        "name": "mac",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
         }
     }
 }

+ 37 - 0
docs/swagger.yaml

@@ -518,4 +518,41 @@ paths:
       summary: 写入数据-脑电写入指令
       tags:
       - 设备管理
+  /v2/gateway/find:
+    get:
+      consumes:
+      - application/json
+      description: 查询可能是蓝牙网关的设备
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 查询可能是蓝牙网关的设备
+      tags:
+      - 设备管理
+  /v2/gateway/set:
+    post:
+      consumes:
+      - application/json
+      description: 保存网关MAC-脑电写入指令
+      parameters:
+      - description: 'mac:网关MAC地址 '
+        in: body
+        name: mac
+        required: true
+        schema:
+          type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 保存网关MAC
+      tags:
+      - 设备管理
 swagger: "2.0"

+ 1 - 1
initialize/findGateway.go

@@ -32,6 +32,6 @@ func FindGateway() {
 }
 func must(action string, err error) {
 	if err != nil {
-		panic("failed to " + action + ": " + err.Error())
+		global.Log4J.Info("failed to " + action + ": " + err.Error())
 	}
 }

+ 1 - 0
initialize/router.go

@@ -84,6 +84,7 @@ func Router() {
 
 	gate := v2.Group("/gateway")
 	gate.GET("/find", gateway.FindGateway)
+	gate.POST("/set/", gateway.SetGatewayMac)
 	//初始化SSE
 
 	//