提供lora公共逻辑
This commit is contained in:
@@ -377,17 +377,40 @@ func initLora(
|
||||
var comm transport.Communicator
|
||||
var loraListener transport.Listener
|
||||
baseCtx := context.Background()
|
||||
|
||||
logger := logs.GetLogger(ctx)
|
||||
|
||||
// 1. 创建统一的业务处理器 (App层适配器)
|
||||
// 它实现了 infra 层的 transport.UpstreamHandler 接口
|
||||
upstreamHandler := listener.NewLoRaListener(
|
||||
baseCtx,
|
||||
repos.areaControllerRepo,
|
||||
repos.pendingCollectionRepo,
|
||||
repos.deviceRepo,
|
||||
repos.sensorDataRepo,
|
||||
repos.deviceCommandLogRepo,
|
||||
)
|
||||
|
||||
// 2. 根据配置初始化具体的传输层和监听器
|
||||
if cfg.Lora.Mode == config.LoraMode_LoRaWAN {
|
||||
logger.Info("当前运行模式: lora_wan。初始化 ChirpStack 监听器和传输层。")
|
||||
listenHandler = chirp_stack.NewChirpStackListener(logs.AddCompName(baseCtx, "ChirpStackListener"), repos.sensorDataRepo, repos.deviceRepo, repos.areaControllerRepo, repos.deviceCommandLogRepo, repos.pendingCollectionRepo)
|
||||
|
||||
// 2a. 创建 ChirpStack 的 Webhook 监听器 (infra),并注入 App 层的业务处理器
|
||||
listenHandler = chirp_stack.NewChirpStackListener(baseCtx, upstreamHandler)
|
||||
|
||||
// 2b. 创建 ChirpStack 的发送器 (infra)
|
||||
comm = lora.NewChirpStackTransport(logs.AddCompName(baseCtx, "ChirpStackTransport"), cfg.ChirpStack)
|
||||
|
||||
// 2c. LoRaWAN 模式下没有主动监听的 Listener,使用占位符
|
||||
loraListener = lora.NewPlaceholderTransport(logs.AddCompName(baseCtx, "PlaceholderTransport"))
|
||||
|
||||
} else {
|
||||
logger.Info("当前运行模式: lora_mesh。初始化 LoRa Mesh 传输层和占位符监听器。")
|
||||
|
||||
// 2a. LoRa Mesh 模式下没有 Webhook 监听器,使用占位符
|
||||
listenHandler = chirp_stack.NewPlaceholderListener(logs.AddCompName(baseCtx, "PlaceholderListener"))
|
||||
tp, err := lora.NewLoRaMeshUartPassthroughTransport(logs.AddCompName(baseCtx, "LoRaMeshTransport"), cfg.LoraMesh, repos.areaControllerRepo, repos.pendingCollectionRepo, repos.deviceRepo, repos.sensorDataRepo)
|
||||
|
||||
// 2b. 创建串口的传输工具 (infra),它同时实现了发送和监听,并注入 App 层的业务处理器
|
||||
tp, err := lora.NewLoRaMeshUartPassthroughTransport(baseCtx, cfg.LoraMesh, upstreamHandler)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("无法初始化 LoRa Mesh 模块: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user