Compare commits
No commits in common. "f9034ba53d9b201140e9e43dbe8f5b8faa21633a" and "86b35d3ead9a269f812b105d8a30a43c019da8bc" have entirely different histories.
f9034ba53d
...
86b35d3ead
86
main.go
Normal file
86
main.go
Normal file
@ -0,0 +1,86 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
basePath, _ = os.Getwd()
|
||||
protoFolder = filepath.Join(basePath, "rts-sim-testing-message", "protos")
|
||||
protocPath = filepath.Join(basePath, "rts-sim-testing-message", "protoc-23.1", "bin", "win64", "protoc")
|
||||
modulePrefix = "joylink.club/bj-rtsts-server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//先安装以下插件
|
||||
//go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||
|
||||
protoFiles := getProtoFiles()
|
||||
// 编译proto文件为Go文件
|
||||
if err := compileProto(protoFiles); err != nil {
|
||||
log.Fatalf("编译proto文件失败:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取指定文件夹下的所有proto文件的绝对路径
|
||||
func getProtoFiles() []string {
|
||||
var protoFiles []string
|
||||
err := filepath.WalkDir(protoFolder, func(path string, d fs.DirEntry, err error) error {
|
||||
if !d.IsDir() {
|
||||
protoFiles = append(protoFiles, path)
|
||||
}
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal("获取proto文件列表失败:", err)
|
||||
}
|
||||
return protoFiles
|
||||
}
|
||||
|
||||
// 编译proto文件为Go文件
|
||||
func compileProto(protoFiles []string) error {
|
||||
for _, fileName := range protoFiles {
|
||||
file, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scanner := bufio.NewScanner(file)
|
||||
var outPath string
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
if !strings.HasPrefix(text, "option go_package") {
|
||||
continue
|
||||
}
|
||||
start := strings.Index(text, modulePrefix)
|
||||
if start < 0 {
|
||||
break
|
||||
}
|
||||
start += len(modulePrefix)
|
||||
dir := "." + text[start:len(text)-2]
|
||||
err := os.MkdirAll(dir, fs.ModeDir)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("创建目录 %s 失败:%v", dir, err))
|
||||
}
|
||||
outPath = "paths=source_relative:" + dir
|
||||
break
|
||||
}
|
||||
if outPath == "" {
|
||||
outPath = "./"
|
||||
}
|
||||
cmd := exec.Command(protocPath, "-I="+protoFolder, "--go_out="+outPath, fileName)
|
||||
fmt.Println(cmd.String())
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -596,14 +596,6 @@ message StationQc {
|
||||
}
|
||||
}
|
||||
|
||||
// 车库门
|
||||
message CkmState {
|
||||
uint32 id = 1; //车库门的id
|
||||
bool mgj = 2; //车库门关闭继电器
|
||||
request.CkmParam param = 3; //屏蔽门设置的参数
|
||||
bool stateLoss = 4; //状态丢失
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//仿真运行时状态变化量,当前时刻与上一时刻比较得到
|
||||
@ -648,8 +640,6 @@ message AllDevicesStatus{
|
||||
repeated BaliseState baliseState = 12;
|
||||
// 车站联锁驱采状态
|
||||
StationQc stationQc = 13;
|
||||
// 车库门状态
|
||||
repeated CkmState ckmStates = 14;
|
||||
}
|
||||
|
||||
//服务器端向前端推送的设备状态信息
|
||||
|
Loading…
Reference in New Issue
Block a user