From b748c7ff3ed7d401c8caeaecd3d4ec719ae27ee2 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Wed, 20 Mar 2024 14:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E8=BD=A6?= =?UTF-8?q?=E5=BA=93=E9=97=A8=E5=8F=8A=E8=BD=A6=E5=BA=93=E9=97=A8=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E7=9B=92=E6=93=8D=E4=BD=9C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 86 ++++++++++++++++++++++++++++++ protos/request.proto | 39 ++++++++++++++ protos/stationLayoutGraphics.proto | 9 ++++ 3 files changed, 134 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..3f78414 --- /dev/null +++ b/main.go @@ -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 +} diff --git a/protos/request.proto b/protos/request.proto index 740c2af..5d08efd 100644 --- a/protos/request.proto +++ b/protos/request.proto @@ -227,3 +227,42 @@ enum DriverType{ ONE_END = 0; TWO_END = 1; } + + +message CkmOperationReq { + string simulationId = 1; + int32 mapId = 2; + uint32 deviceId = 3; //设备id(车库门id) + Ckm.Operation operation = 4; //车库门操作 + CkmParam param = 5; //车库门参数,在operation为SetParams时有效 +} + +message Ckm { + enum Operation { + Undefined= 0; + SetParams = 1; + } + enum Force { + F_NONE = 0; //无强制 + F_KM = 1; //强制开门 + F_GM = 2; //强制关门 + } + enum Fault { + FA_NONE = 0; //无故障 + FA_State_Loss = 1; //状态丢失 + } +} + +message CkmParam { + Ckm.Force force = 1; + Ckm.Fault fault = 2; +} + +//车库门控制盒操作请求 +message CkmBoxOperationReq { + string simulationId = 1; + int32 mapId = 2; + uint32 ckmBoxId = 3; + string buttonCode = 4; + bool down = 5; //按下/抬起 +} diff --git a/protos/stationLayoutGraphics.proto b/protos/stationLayoutGraphics.proto index 6629991..6faebc0 100644 --- a/protos/stationLayoutGraphics.proto +++ b/protos/stationLayoutGraphics.proto @@ -55,6 +55,7 @@ message RtssGraphicStorage { repeated CarWashing carWashings = 45; // 洗车机 repeated GarageDoor garageDoors = 46; // 车库门 repeated FloodGate floodGates = 47; // 防淹门 + repeated GarageDoorBox garageDoorBoxes = 48; //车库门Psl开启按钮 } message Canvas { @@ -722,3 +723,11 @@ message OtherLine { repeated string oldids = 2; // 设备id列表 repeated uint32 ids = 3; // 设备id列表 } + +//车库门控制盒 +message GarageDoorBox { + CommonInfo common = 1; + string code = 2; + string refPslMapCode = 3; // 关联的Psl地图的code(名称) + uint32 refGarageDoorId = 4; // 关联的车库门的id +} \ No newline at end of file