zhangmeng
2019-12-23 f3d1415f01b6db394cb31d232662cd6db204fd5f
update;
3个文件已添加
8个文件已修改
176 ■■■■ 已修改文件
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/master/master.go 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
go.mod 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcomm/db.go 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcomm/go.mod 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcomm/make.sh 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libgowrapper/face @ d30dfa 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
libgowrapper/humantrack @ 4c0bbb 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
libgowrapper/vehicle @ e28bf7 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
libgowrapper/yolo @ 578175 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -8,3 +8,4 @@
data/
runtime/
libs/
libcomm.so
app/master/master.go
@@ -5,7 +5,6 @@
    "analysis/logo"
    "analysis/util"
    "context"
    "io/ioutil"
    "basic.com/libgowrapper/sdkstruct.git"
)
@@ -17,36 +16,12 @@
}
// Run run
func Run(ctx context.Context, configPath string) bool {
func Run(ctx context.Context, configPath, soFile string) bool {
    reaper(ctx)
    rPath := configPath
    configFile := configPath
    var fetcher *Fetcher
    fs, _ := ioutil.ReadDir(rPath)
    for _, file := range fs {
        if !file.IsDir() {
            if rPath[len(rPath)-1] != '/' {
                configFile = rPath + "/" + file.Name()
            } else {
                configFile = rPath + file.Name()
            }
            cfg, err := app.ReadConfig(configFile)
            if err != nil {
                logo.Errorln("Run Fetcher Master Read From File: ", configFile, " Config Error: ", err)
                continue
            }
            fetcher = NewFetcher(cfg.SoFile)
            if fetcher == nil {
                logo.Errorln("New Fetcher Load so File Funcs Error From File: ", cfg.SoFile)
                continue
            }
        }
    }
    fetcher := NewFetcher(soFile)
    if fetcher == nil {
        logo.Errorln("!!!!!!Read All So File, But Can't Init DB Fetcher")
        logo.Errorln("New Fetcher Load so File Funcs Error From File: ", soFile)
        return false
    }
go.mod
@@ -8,5 +8,4 @@
    github.com/amoghe/distillog v0.0.0-20180726233512-ae382b35b717
    github.com/natefinch/lumberjack v2.0.0+incompatible
    github.com/spf13/viper v1.6.1
    golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
)
libcomm/db.go
New file
@@ -0,0 +1,109 @@
package main
import (
    "fmt"
    "strconv"
    "basic.com/dbapi.git"
    "basic.com/libgowrapper/sdkstruct.git"
    "basic.com/pubsub/cache.git/shardmap"
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/gopherdiscovery.git"
    "github.com/gogo/protobuf/proto"
)
const (
    prefixTASKSDKRULE = "TASKSDKRULE_"
)
var cMap *shardmap.ShardMap
// InitDBAPI init dbapi
func InitDBAPI(ip string, httpPort, heartBeatPort, dataPort int, log func(...interface{})) {
    dbapi.Init(ip, httpPort)
    var initchan = make(chan bool)
    go InitCache(initchan, ip, heartBeatPort, dataPort)
    log("db init done!", <-initchan)
}
// TaskInfos get camera infos from sqlite db
func TaskInfos() []protomsg.TaskSdkInfo {
    tAPI := dbapi.TaskApi{}
    tasks := tAPI.FindAll()
    return tasks
}
// SDKInfo get sdk
func SDKInfo() []sdkstruct.SDKInfo {
    sAPI := dbapi.SdkApi{}
    s := sAPI.FindAllSdkRun()
    var sdks []sdkstruct.SDKInfo
    for _, v := range s {
        sdks = append(sdks, sdkstruct.SDKInfo{
            IpcID:   v.IpcId,
            SdkType: v.SdkType,
        })
    }
    return sdks
}
// InitCache cache
func InitCache(initChan chan bool, dbIP string, surveyPort int, pubSubPort int) {
    cMap = shardmap.New(uint8(32))
    urlSurvey := "tcp://" + dbIP + ":" + strconv.Itoa(surveyPort)
    urlPubSub := "tcp://" + dbIP + ":" + strconv.Itoa(pubSubPort)
    client, _ := gopherdiscovery.ClientWithSub(urlSurvey, urlPubSub, "analysisProc")
    recvMsg := client.HeartBeatMsg()
    fmt.Println(<-recvMsg)
    initCacheData(initChan)
    peers, _ := client.Peers()
    for b := range peers {
        fmt.Println("peerMsg:", b)
        updateData(b)
    }
}
func initCacheData(initChan chan bool) {
    initTaskSdkRule()
    initChan <- true
}
func initTaskSdkRule() {
    var api dbapi.TaskSdkRuleApi
    b, rules := api.FindAllTaskSdkRules()
    if b {
        if rules != nil {
            for _, tRule := range rules {
                cMap.Set(prefixTASKSDKRULE+tRule.TaskId, tRule.SdkRules)
            }
        }
    }
}
func updateData(b []byte) {
    newUpdateMsg := &protomsg.DbChangeMessage{}
    if err := proto.Unmarshal(b, newUpdateMsg); err != nil {
        fmt.Println("dbChangeMsg unmarshal err:", err)
        return
    }
    switch newUpdateMsg.Table {
    case protomsg.TableChanged_T_TaskSdkRule:
        initTaskSdkRule()
    default:
    }
}
// GetTaskSdkRules rules
func GetTaskSdkRules(taskID string) []*protomsg.SdkRuleSet {
    r, b := cMap.Get(prefixTASKSDKRULE + taskID)
    if b {
        return r.([]*protomsg.SdkRuleSet)
    }
    return nil
}
libcomm/go.mod
New file
@@ -0,0 +1,19 @@
module comm
go 1.12
require (
    basic.com/dbapi.git v0.0.0-20191216030028-03153c1f1f30
    basic.com/libgowrapper/sdkstruct.git v0.0.0-20191220011601-e0b3d1f0183c
    basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48
    basic.com/pubsub/protomsg.git v0.0.0-20191219033725-b95da65535d0
    basic.com/valib/gopherdiscovery.git v0.0.0-20190605034340-15d89d8b4e28
    github.com/ajg/form v1.5.1 // indirect
    github.com/gogo/protobuf v1.3.1
    golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
    golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
    golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
    google.golang.org/grpc v1.26.0 // indirect
    honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
    nanomsg.org/go-mangos v1.4.0 // indirect
)
libcomm/make.sh
New file
@@ -0,0 +1,5 @@
#!/bin/bash
go build -buildmode=plugin -o libcomm.so -a
mv libcomm.so ..
libgowrapper/face
@@ -1 +1 @@
Subproject commit a79283f652e78fb8591a8af69f973055f9730c9d
Subproject commit d30dfa5952c21e88210004a6341a16eb0ee68e2e
libgowrapper/humantrack
@@ -1 +1 @@
Subproject commit eb177ba4a1f61e268dacb77d065d88cb70441d1a
Subproject commit 4c0bbb853bef9103167f4d7d4a08b9b2ce30bd6b
libgowrapper/vehicle
@@ -1 +1 @@
Subproject commit c4ec8a5f30cb29dc407472d244a537973b7d3567
Subproject commit e28bf7df5c319218e5633e0ebd9bdcc9ec84b97a
libgowrapper/yolo
@@ -1 +1 @@
Subproject commit 2e1584a6d6d185d8ed950a60f97532c3eb14aa6a
Subproject commit 578175fa42aece999fc70143535d3ebb6dfbca3f
main.go
@@ -114,7 +114,7 @@
    ret := false
    if role == roleMaster {
        setParamters()
        ret = master.Run(ctx, configPath)
        ret = master.Run(ctx, configPath, "./libcomm.so")
    } else if role == roleSlave {
        ret = slave.Run(ctx, configPath, runType, id, gpu, shm)