From 3b967aa449f0c3beee4f0e5bb20e50cf33dbf581 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Fri, 17 Oct 2025 10:44:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yml | 2 +- internal/domain/device/general_device_service.go | 3 ++- internal/infra/models/device_template.go | 10 +++++----- .../lora/lora_mesh_uart_passthrough_transport.go | 2 ++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/config.yml b/config.yml index 0820e69..ea5b45c 100644 --- a/config.yml +++ b/config.yml @@ -12,7 +12,7 @@ server: # 日志配置 log: - level: "info" # 日志级别: "debug", "info", "warn", "error", "dpanic", "panic", "fatal" + level: "debug" # 日志级别: "debug", "info", "warn", "error", "dpanic", "panic", "fatal" format: "console" # 日志格式: "console" 或 "json" enable_file: true # 是否启用文件日志 file_path: "./app_logs/app.log" # 日志文件路径 diff --git a/internal/domain/device/general_device_service.go b/internal/domain/device/general_device_service.go index 480ab98..342d9d2 100644 --- a/internal/domain/device/general_device_service.go +++ b/internal/domain/device/general_device_service.go @@ -179,6 +179,7 @@ func (g *GeneralDeviceService) Collect(regionalControllerID uint, devicesToColle g.logger.Warnf("跳过设备 %d,因生成Modbus RTU读取指令失败: %v", dev.ID, err) continue } + g.logger.Debugf("生成485指令: %v", modbusCommandBytes) // 构建 Raw485Command,包含总线号 raw485Cmd := &proto.Raw485Command{ @@ -229,7 +230,7 @@ func (g *GeneralDeviceService) Collect(regionalControllerID uint, devicesToColle g.logger.Errorf("序列化采集指令失败 (CorrelationID: %s): %v", correlationID, err) return err } - + g.logger.Infof("构造空中载荷成功: networkID: %v, payload: %v", networkID, instruction) if _, err := g.comm.Send(networkID, payload); err != nil { g.logger.DPanicf("待采集请求 (CorrelationID: %s) 已创建,但发送到设备失败: %v。数据可能不一致!", correlationID, err) return err diff --git a/internal/infra/models/device_template.go b/internal/infra/models/device_template.go index ceb49e4..7b65e77 100644 --- a/internal/infra/models/device_template.go +++ b/internal/infra/models/device_template.go @@ -32,9 +32,9 @@ type ValueDescriptor struct { // SwitchCommands 定义了开关类指令所需的Modbus参数 type SwitchCommands struct { - // ModbusStartAddress 记录Modbus寄存器的起始地址,用于生成指令。 + // ModbusStartAddress 记录Modbus寄存器的起始地址,用于生成指令。(一般是第三到四字节) ModbusStartAddress uint16 `json:"modbus_start_address"` - // ModbusQuantity 记录Modbus寄存器的数量,对于开关通常为1。 + // ModbusQuantity 记录Modbus寄存器的数量,对于开关通常为1。(一般是五到六字节) ModbusQuantity uint16 `json:"modbus_quantity"` } @@ -49,11 +49,11 @@ func (sc *SwitchCommands) SelfCheck() error { // SensorCommands 定义了传感器读取指令所需的Modbus参数 type SensorCommands struct { - // ModbusFunctionCode 记录Modbus功能码,例如 ReadHoldingRegisters。 + // ModbusFunctionCode 记录Modbus功能码,例如 ReadHoldingRegisters。(一般是第二字节) ModbusFunctionCode command_generater.ModbusFunctionCode `json:"modbus_function_code"` - // ModbusStartAddress 记录Modbus寄存器的起始地址,用于生成指令。 + // ModbusStartAddress 记录Modbus寄存器的起始地址,用于生成指令。(一般是第三到四字节) ModbusStartAddress uint16 `json:"modbus_start_address"` - // ModbusQuantity 记录Modbus寄存器的数量,用于生成指令。 + // ModbusQuantity 记录Modbus寄存器的数量,用于生成指令。(一般是五到六字节) ModbusQuantity uint16 `json:"modbus_quantity"` } diff --git a/internal/infra/transport/lora/lora_mesh_uart_passthrough_transport.go b/internal/infra/transport/lora/lora_mesh_uart_passthrough_transport.go index 3514634..df9e7dc 100644 --- a/internal/infra/transport/lora/lora_mesh_uart_passthrough_transport.go +++ b/internal/infra/transport/lora/lora_mesh_uart_passthrough_transport.go @@ -206,6 +206,7 @@ func (t *LoRaMeshUartPassthroughTransport) workerLoop() { t.runIdleState() case stateReceiving: t.runReceivingState() + default: } } } @@ -256,6 +257,7 @@ func (t *LoRaMeshUartPassthroughTransport) executeSend(req *sendRequest) (*trans frame.WriteByte(currentChunk) // 当前包序号 frame.Write(chunk) // 数据块 + t.logger.Infof("构建LoRa数据包: %v", frame.Bytes()) _, err := t.port.Write(frame.Bytes()) if err != nil { return nil, fmt.Errorf("写入串口失败: %w", err)