- Go main process: stream ingestor, infer client, event uploader, heartbeat, config agent, OTA agent - Python inference server rewritten to use CANN ACL (acl module) replacing ultralytics/PyTorch; supports YOLOv8 raw and YOLOv10 NMS-free output formats via OUTPUT_FORMAT env var - systemd services for edge-agent and edge-infer - build/install/package scripts targeting arm64 Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package control
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
|
|
"tianyan-edge/internal/config"
|
|
)
|
|
|
|
type ConfigAgent struct {
|
|
cfg *config.Config
|
|
}
|
|
|
|
func NewConfigAgent(cfg *config.Config) *ConfigAgent {
|
|
return &ConfigAgent{cfg: cfg}
|
|
}
|
|
|
|
func (a *ConfigAgent) Run(ctx context.Context) {
|
|
client := &http.Client{Timeout: 5 * time.Second}
|
|
ticker := time.NewTicker(60 * time.Second)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
a.pull(client)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (a *ConfigAgent) pull(client *http.Client) {
|
|
url := fmt.Sprintf("%s/api/v1/edge/config?edge_id=%s", a.cfg.CloudURL, a.cfg.EdgeID)
|
|
req, _ := http.NewRequest(http.MethodGet, url, nil)
|
|
req.Header.Set("Authorization", "Bearer "+a.cfg.EdgeToken)
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
log.Printf("config pull: %v", err)
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != 200 {
|
|
return
|
|
}
|
|
var data map[string]any
|
|
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
|
return
|
|
}
|
|
if v, ok := data["infer_fps"].(float64); ok && int(v) > 0 {
|
|
a.cfg.InferFPS = int(v)
|
|
}
|
|
if v, ok := data["conf_threshold"].(float64); ok {
|
|
a.cfg.ConfThreshold = v
|
|
}
|
|
}
|