From b2500a8eb6665ce6efe0a7d954b6f101af83d7ec Mon Sep 17 00:00:00 2001
From: 554325746@qq.com <554325746@qq.com>
Date: 星期三, 25 三月 2020 11:31:41 +0800
Subject: [PATCH] debug
---
common/helper.go | 196 ++++++++++++++----------------------------------
1 files changed, 59 insertions(+), 137 deletions(-)
diff --git a/common/helper.go b/common/helper.go
index 0e016c3..9734eb9 100644
--- a/common/helper.go
+++ b/common/helper.go
@@ -1,174 +1,96 @@
package common
import (
- "context"
- "encoding/json"
- "fmt"
- "io/ioutil"
- "strconv"
- "time"
+ "context"
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "strconv"
+ "time"
- "basic.com/libgowrapper/sdkstruct.git"
- "basic.com/pubsub/protomsg.git"
- "basic.com/valib/deliver.git"
- "github.com/gogo/protobuf/proto"
+ "basic.com/pubsub/protomsg.git"
+ "github.com/gogo/protobuf/proto"
)
-
-const mode = deliver.PushPull
// GetIpcAddress get ipc
func GetIpcAddress(shm bool, id string) string {
- if shm {
- return id
- }
- return `ipc:///tmp/` + id + `.ipc`
+ if shm {
+ return id
+ }
+ return `ipc:///tmp/` + id + `.ipc`
}
// SubConfig sub
type SubConfig struct {
- SoFile string `json:"so_file_path"`
- Env string `json:"runtime"`
- Param map[string]string `json:"param"`
+ SoFile string `json:"so_file_path"`
+ Env string `json:"runtime"`
+ Param map[string]string `json:"param"`
}
// SdkConfig sdk
type SdkConfig struct {
- SoFile string `json:"so_file_path"`
- Env string `json:"runtime"`
- Param map[string]string `json:"param"`
- Sub *SubConfig `json:"sub"`
+ SoFile string `json:"so_file_path"`
+ Env string `json:"runtime"`
+ Param map[string]string `json:"param"`
+ Sub *SubConfig `json:"sub"`
}
// ReadConfig conf
func ReadConfig(file string) (SdkConfig, error) {
- data, err := ioutil.ReadFile(file)
- if err != nil {
- return SdkConfig{}, fmt.Errorf("READ SDK CONFIG FILE %s ERROR", file)
- }
+ data, err := ioutil.ReadFile(file)
+ if err != nil {
+ return SdkConfig{}, fmt.Errorf("READ SDK CONFIG FILE %s ERROR", file)
+ }
- //璇诲彇鐨勬暟鎹负json鏍煎紡锛岄渶瑕佽繘琛岃В鐮�
- var v SdkConfig
- err = json.Unmarshal(data, &v)
+ //璇诲彇鐨勬暟鎹负json鏍煎紡锛岄渶瑕佽繘琛岃В鐮�
+ var v SdkConfig
+ err = json.Unmarshal(data, &v)
- return v, err
+ return v, err
}
// Atoi atoi
func Atoi(s string) int {
- i, _ := strconv.Atoi(s)
- return i
+ i, _ := strconv.Atoi(s)
+ return i
}
// UnserilizeProto un
func UnserilizeProto(ctx context.Context, data <-chan []byte, out chan<- protomsg.SdkMessage, fn func(...interface{})) {
- for {
- select {
- case <-ctx.Done():
- return
- case d := <-data:
- if len(d) < 100 {
- continue
- }
- msg := protomsg.SdkMessage{}
- if err := proto.Unmarshal(d, &msg); err != nil {
- fn(err, " msg 澶勭悊寮傚父")
- continue
- }
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ case d := <-data:
+ if len(d) < 100 {
+ continue
+ }
+ msg := protomsg.SdkMessage{}
+ if err := proto.Unmarshal(d, &msg); err != nil {
+ fn("UnserilizeProto Unmarshal msg 澶勭悊寮傚父 Error:", err)
+ continue
+ }
- out <- msg
+ out <- msg
- default:
- time.Sleep(10 * time.Millisecond)
- }
- }
-}
-
-// Msg2MsgSDK msg->msgsdk
-func Msg2MsgSDK(msg protomsg.SdkMessage) *sdkstruct.MsgSDK {
-
- d, err := proto.Marshal(&msg)
- if err != nil {
- return nil
- }
-
- index, count := int(msg.Tasklab.Index), len(msg.Tasklab.Sdkinfos)
- if index >= count {
- return &sdkstruct.MsgSDK{
- MsgData: d,
- SdkCount: count,
- SdkIndex: index,
- SdkDataLen: 0,
- }
- }
-
- return &sdkstruct.MsgSDK{
- MsgData: d,
- SdkCount: count,
- SdkIndex: index,
- SdkDataLen: len(d),
- }
-}
-
-// EjectResult eject
-func EjectResult(res []byte, msg protomsg.SdkMessage, out chan<- sdkstruct.MsgSDK) {
-
- if res == nil {
- s := Msg2MsgSDK(msg)
- if s == nil {
- return
- }
- out <- *s
- return
- }
-
- msg.Tasklab.Sdkinfos[int(msg.Tasklab.Index)].Sdkdata = res
-
- s := Msg2MsgSDK(msg)
- if s == nil {
- return
- }
- out <- *s
-}
-
-/////////////////////////////////////////////////////////////
-
-// ValidRemoteMessage valid or not
-func ValidRemoteMessage(msg protomsg.SdkMessage, fnName string, fn func(...interface{})) bool {
- if msg.Tasklab == nil {
- fn(fnName, " recieve msg nil")
- return false
- }
-
- sdkLen := len(msg.Tasklab.Sdkinfos)
- if sdkLen == 0 {
- fn(fnName, " has no sdk info")
- return false
- }
-
- curIndex := int(msg.Tasklab.Index)
- if curIndex < 0 || curIndex >= sdkLen {
- fn(fnName, " tasklab index ", curIndex, " error")
- return false
- }
- if msg.Tasklab.Sdkinfos[curIndex].Sdktype != fnName {
- fn(fnName, " is different from ", msg.Tasklab.Sdkinfos[curIndex].Sdktype)
- return false
- }
- return true
+ default:
+ time.Sleep(10 * time.Millisecond)
+ }
+ }
}
// UnpackImage unpack
func UnpackImage(msg protomsg.SdkMessage, fnName string, fn func(...interface{})) *protomsg.Image {
- // 鍙嶅簭鍒楀寲鏁版嵁寰楀埌sdk鍏ュ弬
- i := &protomsg.Image{}
- err := proto.Unmarshal(msg.Data, i)
- if err != nil {
- fn(fnName, " protobuf decode CameraImage error: ", err.Error())
- return nil
- }
- if i.Data == nil {
- fn(fnName, " protomsg.Image data null")
- return nil
- }
- return i
+ // 鍙嶅簭鍒楀寲鏁版嵁寰楀埌sdk鍏ュ弬
+ i := &protomsg.Image{}
+ err := proto.Unmarshal(msg.Data, i)
+ if err != nil {
+ fn(fnName, " protobuf Unmarshal decode CameraImage error: ", err.Error())
+ return nil
+ }
+ if i.Data == nil {
+ fn(fnName, " protomsg.Image data null")
+ return nil
+ }
+ return i
}
--
Gitblit v1.8.0