|
@@ -3,12 +3,8 @@ package config
|
|
|
import (
|
|
|
"cicv-data-closedloop/common/config/c_log"
|
|
|
"cicv-data-closedloop/common/util"
|
|
|
- "encoding/json"
|
|
|
"errors"
|
|
|
- "fmt"
|
|
|
- "github.com/gorilla/websocket"
|
|
|
"gopkg.in/yaml.v3"
|
|
|
- "net/url"
|
|
|
"os"
|
|
|
"strings"
|
|
|
"sync"
|
|
@@ -88,24 +84,24 @@ type cloudConfig struct {
|
|
|
Monitor MonitorStruct `yaml:"monitor"`
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-type Request struct {
|
|
|
- Type string `json:"type"`
|
|
|
- UUID string `json:"uuid"`
|
|
|
- CommandID string `json:"commandId"`
|
|
|
- Parameter interface{} `json:"parameter"`
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-type Response struct {
|
|
|
- CommandID string `json:"commandId"`
|
|
|
- ErrorCode string `json:"errorCode"`
|
|
|
- Results map[string]string `json:"results"`
|
|
|
- Status string `json:"status"`
|
|
|
- Time int64 `json:"time"`
|
|
|
- Type string `json:"type"`
|
|
|
- UUID string `json:"uuid"`
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
var (
|
|
|
CloudConfig cloudConfig
|
|
@@ -269,51 +265,51 @@ func getSnCode() (string, error) {
|
|
|
return snCode, nil
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func SendWebsocketRequest(serverURL, path string, request Request) (string, error) {
|
|
|
-
|
|
|
- u := url.URL{Scheme: "ws", Host: serverURL, Path: path}
|
|
|
-
|
|
|
-
|
|
|
- dialer := websocket.Dialer{
|
|
|
- ReadBufferSize: 1024,
|
|
|
- WriteBufferSize: 1024,
|
|
|
-
|
|
|
- HandshakeTimeout: 5 * time.Second,
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- conn, _, err := dialer.Dial(u.String(), nil)
|
|
|
- if err != nil {
|
|
|
- return "", fmt.Errorf("dial: %w", err)
|
|
|
- }
|
|
|
- defer conn.Close()
|
|
|
-
|
|
|
-
|
|
|
- requestJSON, err := json.Marshal(request)
|
|
|
- if err != nil {
|
|
|
- return "", fmt.Errorf("marshal request: %w", err)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- err = conn.WriteMessage(websocket.TextMessage, requestJSON)
|
|
|
- if err != nil {
|
|
|
- return "", fmt.Errorf("write: %w", err)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- _, responseBytes, err := conn.ReadMessage()
|
|
|
- if err != nil {
|
|
|
- return "", fmt.Errorf("read: %w", err)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- var response Response
|
|
|
- err = json.Unmarshal(responseBytes, &response)
|
|
|
- if err != nil {
|
|
|
- return "", fmt.Errorf("unmarshal response: %w", err)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return response.Results["sn"], nil
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|