init: tianyan-edge edge agent with Ascend NPU inference backend
- 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>
This commit is contained in:
54
internal/control/heartbeat.go
Normal file
54
internal/control/heartbeat.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"tianyan-edge/internal/config"
|
||||
)
|
||||
|
||||
type Heartbeat struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
func NewHeartbeat(cfg *config.Config) *Heartbeat {
|
||||
return &Heartbeat{cfg: cfg}
|
||||
}
|
||||
|
||||
func (h *Heartbeat) Run(ctx context.Context) {
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
h.send(client)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Heartbeat) send(client *http.Client) {
|
||||
payload := map[string]any{
|
||||
"edge_id": h.cfg.EdgeID,
|
||||
"version": h.cfg.Version,
|
||||
"ts": float64(time.Now().UnixMilli()) / 1000.0,
|
||||
}
|
||||
body, _ := json.Marshal(payload)
|
||||
url := fmt.Sprintf("%s/api/v1/edge/heartbeat", h.cfg.CloudURL)
|
||||
req, _ := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "Bearer "+h.cfg.EdgeToken)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Printf("heartbeat: %v", err)
|
||||
return
|
||||
}
|
||||
resp.Body.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user