定义ReleaseFeedWeightTask并注入依赖
This commit is contained in:
@@ -30,6 +30,9 @@ type Config struct {
|
||||
// Heartbeat 心跳配置
|
||||
Heartbeat HeartbeatConfig `yaml:"heartbeat"`
|
||||
|
||||
// ChirpStack ChirpStack API 配置
|
||||
ChirpStack ChirpStackConfig `yaml:"chirp_stack"`
|
||||
|
||||
// TaskConfig 任务调度配置
|
||||
Task TaskConfig `yaml:"task"`
|
||||
}
|
||||
@@ -112,6 +115,14 @@ type HeartbeatConfig struct {
|
||||
Concurrency int `yaml:"concurrency"`
|
||||
}
|
||||
|
||||
// ChirpStackConfig 代表 ChirpStack API 配置
|
||||
type ChirpStackConfig struct {
|
||||
APIHost string `yaml:"api_host"`
|
||||
APIToken string `yaml:"api_token"`
|
||||
FPort int `yaml:"fport"`
|
||||
APITimeout int `yaml:"api_timeout"`
|
||||
}
|
||||
|
||||
// TaskConfig 代表任务调度配置
|
||||
type TaskConfig struct {
|
||||
Interval int `yaml:"interval"`
|
||||
@@ -139,3 +150,8 @@ func (c *Config) Load(path string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GenerateAPIKey 用于补齐API Key作为请求头时缺失的部分
|
||||
func (c ChirpStackConfig) GenerateAPIKey() string {
|
||||
return "Bearer " + c.APIToken
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ const (
|
||||
type TaskType string
|
||||
|
||||
const (
|
||||
TaskPlanAnalysis TaskType = "plan_analysis" // 解析Plan的Task列表并添加到待执行队列的特殊任务
|
||||
TaskTypeWaiting TaskType = "waiting" // 等待任务
|
||||
TaskPlanAnalysis TaskType = "plan_analysis" // 解析Plan的Task列表并添加到待执行队列的特殊任务
|
||||
TaskTypeWaiting TaskType = "waiting" // 等待任务
|
||||
TaskTypeReleaseFeedWeight TaskType = "release_feed_weight" // 下料口释放指定重量任务
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -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