定义ReleaseFeedWeightTask并注入依赖
This commit is contained in:
@@ -3,6 +3,7 @@ package lora
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/config"
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/logs"
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
|
||||
@@ -14,26 +15,11 @@ import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/transport/lora/chirp_stack_proto/client"
|
||||
)
|
||||
|
||||
// ChirpStackConfig 保存连接到 ChirpStack API 所需的配置。
|
||||
type ChirpStackConfig struct {
|
||||
// ServerAddress 是 ChirpStack API 服务器的地址,例如 "localhost:8080"。
|
||||
ServerAddress string
|
||||
// APIKey 是用于认证的 API 密钥。
|
||||
APIKey string
|
||||
// LoRaWAN 端口, 需要和设备一致
|
||||
Fport int64
|
||||
}
|
||||
|
||||
// GenerateAPIKey 用于补齐API Key作为请求头时缺失的部分
|
||||
func (c ChirpStackConfig) GenerateAPIKey() string {
|
||||
return "Bearer " + c.APIKey
|
||||
}
|
||||
|
||||
// ChirpStackTransport 是一个客户端,用于封装与 ChirpStack REST API 的交互。
|
||||
type ChirpStackTransport struct {
|
||||
client *client.ChirpStackRESTAPI
|
||||
authInfo runtime.ClientAuthInfoWriter
|
||||
config ChirpStackConfig
|
||||
config config.ChirpStackConfig
|
||||
|
||||
deviceCommandLogRepo repository.DeviceCommandLogRepository
|
||||
deviceRepo repository.DeviceRepository
|
||||
@@ -43,14 +29,14 @@ type ChirpStackTransport struct {
|
||||
|
||||
// NewChirpStackTransport 创建一个新的通信实例,用于与 ChirpStack 通信。
|
||||
func NewChirpStackTransport(
|
||||
config ChirpStackConfig,
|
||||
config config.ChirpStackConfig,
|
||||
logger *logs.Logger,
|
||||
deviceCommandLogRepo repository.DeviceCommandLogRepository,
|
||||
deviceRepo repository.DeviceRepository,
|
||||
) *ChirpStackTransport {
|
||||
// 使用配置中的服务器地址创建一个 HTTP transport。
|
||||
// 它会使用生成的客户端中定义的默认 base path 和 schemes。
|
||||
transport := httptransport.New(config.ServerAddress, client.DefaultBasePath, client.DefaultSchemes)
|
||||
transport := httptransport.New(config.APIHost, client.DefaultBasePath, client.DefaultSchemes)
|
||||
|
||||
// 使用 transport 和默认的字符串格式化器,创建一个 API 主客户端。
|
||||
apiClient := client.New(transport, strfmt.Default)
|
||||
@@ -77,7 +63,7 @@ func (c *ChirpStackTransport) Send(address string, payload []byte) error {
|
||||
QueueItem: &device_service.DeviceServiceEnqueueParamsBodyQueueItem{
|
||||
Confirmed: true,
|
||||
Data: payload,
|
||||
FPort: c.config.Fport,
|
||||
FPort: int64(c.config.FPort),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user