更新proto

This commit is contained in:
2025-10-07 16:14:47 +08:00
parent 759caadb21
commit b611f132f1
4 changed files with 179 additions and 186 deletions

View File

@@ -2,17 +2,11 @@ syntax = "proto3";
package device;
import "google/protobuf/any.proto";
// import "google/protobuf/any.proto"; // REMOVED: Not suitable for embedded systems.
option go_package = "internal/domain/device/proto";
// --- 通用指令结构 ---
// 指令类型
enum MethodType {
INSTRUCTION = 0; // 下发指令
COLLECT = 1; // 批量采集
}
// --- Concrete Command & Data Structures ---
// 平台生成的原始485指令单片机直接发送到总线
message Raw485Command {
@@ -20,25 +14,15 @@ message Raw485Command {
bytes command_bytes = 2; // 原始485指令的字节数组
}
// 指令 (所有空中数据都会被包装在这里面)
// data字段现在可以包含 Raw485Command表示平台生成的原始485指令。
message Instruction {
MethodType method = 1;
google.protobuf.Any data = 2; // 可以是 Switch, Raw485Command 等
}
// --- 批量采集相关结构 ---
// BatchCollectCommand
// 用于在平台内部构建一个完整的、包含所有元数据的批量采集任务。
// 这个消息本身不会被发送到设备。
// 一个完整的、包含所有元数据的批量采集任务。
message BatchCollectCommand {
string correlation_id = 1; // 用于关联请求和响应的唯一ID
repeated CollectTask tasks = 2; // 采集任务列表
}
// CollectTask
// 定义了单个采集任务的“意图”。现在直接包含平台生成的原始485指令并带上总线号。
// 定义了单个采集任务的“意图”。
message CollectTask {
Raw485Command command = 2; // 平台生成的原始485指令
}
@@ -48,4 +32,20 @@ message CollectTask {
message CollectResult {
string correlation_id = 1; // 从下行指令中原样返回的关联ID
repeated float values = 2; // 按预定顺序排列的采集值
}
}
// --- Main Downlink Instruction Wrapper ---
// 指令 (所有从平台下发到设备的数据都应该被包装在这里面)
// 使用 oneof 来替代 google.protobuf.Any这是嵌入式环境下的标准做法。
// 它高效、类型安全,且只解码一次。
message Instruction {
oneof payload {
Raw485Command raw_485_command = 1;
BatchCollectCommand batch_collect_command = 2;
CollectResult collect_result = 3; // ADDED用于上行数据
// 如果未来有其他指令类型,比如开关控制,可以直接在这里添加
// SwitchCommand switch_command = 3;
}
}