优化日志
This commit is contained in:
@@ -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" # 日志文件路径
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user