From 3a0e72a5c8433f8184587e419922cb5eef33af0e Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Tue, 30 Sep 2025 00:01:51 +0800 Subject: [PATCH] proto --- .../app/service/device/proto/device.pb.go | 38 ++++++++++++++----- .../app/service/device/proto/device.proto | 12 +++--- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/internal/app/service/device/proto/device.pb.go b/internal/app/service/device/proto/device.pb.go index 15c168a..68d3cd6 100644 --- a/internal/app/service/device/proto/device.pb.go +++ b/internal/app/service/device/proto/device.pb.go @@ -72,7 +72,8 @@ func (MethodType) EnumDescriptor() ([]byte, []int) { // 平台生成的原始485指令,单片机直接发送到总线 type Raw485Command struct { state protoimpl.MessageState `protogen:"open.v1"` - CommandBytes []byte `protobuf:"bytes,1,opt,name=command_bytes,json=commandBytes,proto3" json:"command_bytes,omitempty"` // 原始485指令的字节数组 + BusNumber int32 `protobuf:"varint,1,opt,name=bus_number,json=busNumber,proto3" json:"bus_number,omitempty"` // 总线号,用于指示单片机将指令发送到哪个总线 + CommandBytes []byte `protobuf:"bytes,2,opt,name=command_bytes,json=commandBytes,proto3" json:"command_bytes,omitempty"` // 原始485指令的字节数组 unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -107,6 +108,13 @@ func (*Raw485Command) Descriptor() ([]byte, []int) { return file_device_proto_rawDescGZIP(), []int{0} } +func (x *Raw485Command) GetBusNumber() int32 { + if x != nil { + return x.BusNumber + } + return 0 +} + func (x *Raw485Command) GetCommandBytes() []byte { if x != nil { return x.CommandBytes @@ -224,10 +232,11 @@ func (x *BatchCollectCommand) GetTasks() []*CollectTask { } // CollectTask -// 定义了单个采集任务的“意图”。现在直接包含平台生成的原始485指令。 +// 定义了单个采集任务的“意图”。现在直接包含平台生成的原始485指令,并带上总线号。 type CollectTask struct { state protoimpl.MessageState `protogen:"open.v1"` - Command *Raw485Command `protobuf:"bytes,1,opt,name=command,proto3" json:"command,omitempty"` // 平台生成的原始485指令 + BusNumber int32 `protobuf:"varint,1,opt,name=bus_number,json=busNumber,proto3" json:"bus_number,omitempty"` // 总线号,用于指示单片机将指令发送到哪个总线 + Command *Raw485Command `protobuf:"bytes,2,opt,name=command,proto3" json:"command,omitempty"` // 平台生成的原始485指令 unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -262,6 +271,13 @@ func (*CollectTask) Descriptor() ([]byte, []int) { return file_device_proto_rawDescGZIP(), []int{3} } +func (x *CollectTask) GetBusNumber() int32 { + if x != nil { + return x.BusNumber + } + return 0 +} + func (x *CollectTask) GetCommand() *Raw485Command { if x != nil { return x.Command @@ -327,17 +343,21 @@ var File_device_proto protoreflect.FileDescriptor const file_device_proto_rawDesc = "" + "\n" + - "\fdevice.proto\x12\x06device\x1a\x19google/protobuf/any.proto\"4\n" + - "\rRaw485Command\x12#\n" + - "\rcommand_bytes\x18\x01 \x01(\fR\fcommandBytes\"c\n" + + "\fdevice.proto\x12\x06device\x1a\x19google/protobuf/any.proto\"S\n" + + "\rRaw485Command\x12\x1d\n" + + "\n" + + "bus_number\x18\x01 \x01(\x05R\tbusNumber\x12#\n" + + "\rcommand_bytes\x18\x02 \x01(\fR\fcommandBytes\"c\n" + "\vInstruction\x12*\n" + "\x06method\x18\x01 \x01(\x0e2\x12.device.MethodTypeR\x06method\x12(\n" + "\x04data\x18\x02 \x01(\v2\x14.google.protobuf.AnyR\x04data\"g\n" + "\x13BatchCollectCommand\x12%\n" + "\x0ecorrelation_id\x18\x01 \x01(\tR\rcorrelationId\x12)\n" + - "\x05tasks\x18\x02 \x03(\v2\x13.device.CollectTaskR\x05tasks\">\n" + - "\vCollectTask\x12/\n" + - "\acommand\x18\x01 \x01(\v2\x15.device.Raw485CommandR\acommand\"N\n" + + "\x05tasks\x18\x02 \x03(\v2\x13.device.CollectTaskR\x05tasks\"]\n" + + "\vCollectTask\x12\x1d\n" + + "\n" + + "bus_number\x18\x01 \x01(\x05R\tbusNumber\x12/\n" + + "\acommand\x18\x02 \x01(\v2\x15.device.Raw485CommandR\acommand\"N\n" + "\rCollectResult\x12%\n" + "\x0ecorrelation_id\x18\x01 \x01(\tR\rcorrelationId\x12\x16\n" + "\x06values\x18\x02 \x03(\x02R\x06values**\n" + diff --git a/internal/app/service/device/proto/device.proto b/internal/app/service/device/proto/device.proto index d9cb6a9..539f9ae 100644 --- a/internal/app/service/device/proto/device.proto +++ b/internal/app/service/device/proto/device.proto @@ -16,7 +16,8 @@ enum MethodType { // 平台生成的原始485指令,单片机直接发送到总线 message Raw485Command { - bytes command_bytes = 1; // 原始485指令的字节数组 + int32 bus_number = 1; // 总线号,用于指示单片机将指令发送到哪个总线 + bytes command_bytes = 2; // 原始485指令的字节数组 } // 指令 (所有空中数据都会被包装在这里面) @@ -32,19 +33,20 @@ message Instruction { // 用于在平台内部构建一个完整的、包含所有元数据的批量采集任务。 // 这个消息本身不会被发送到设备。 message BatchCollectCommand { - string correlation_id = 1; // 用于关联请求和响应的唯一ID + string correlation_id = 1; // 用于关联请求和响应的唯一ID repeated CollectTask tasks = 2; // 采集任务列表 } // CollectTask -// 定义了单个采集任务的“意图”。现在直接包含平台生成的原始485指令。 +// 定义了单个采集任务的“意图”。现在直接包含平台生成的原始485指令,并带上总线号。 message CollectTask { - Raw485Command command = 1; // 平台生成的原始485指令 + int32 bus_number = 1; // 总线号,用于指示单片机将指令发送到哪个总线 + Raw485Command command = 2; // 平台生成的原始485指令 } // CollectResult // 这是设备响应的、极致精简的数据包。 message CollectResult { - string correlation_id = 1; // 从下行指令中原样返回的关联ID + string correlation_id = 1; // 从下行指令中原样返回的关联ID repeated float values = 2; // 按预定顺序排列的采集值 } \ No newline at end of file