Skip to content

Commit 360c49f

Browse files
committed
add reset map
1 parent 9b297fe commit 360c49f

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

cmd/obstructionMapVideo/grpc.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ import (
1818
"github.com/pbnjay/pixfont"
1919
)
2020

21-
var (
22-
defaultDishAddress = "192.168.100.1:9200"
23-
grpcTimeout = 5 * time.Second
24-
GRPCAddrPort string
25-
Duration string
26-
DataDir string
27-
FPS int
28-
CreateVideo bool
29-
)
30-
3121
type Exporter struct {
3222
Conn *grpc.ClientConn
3323
Client device.DeviceClient
@@ -200,3 +190,17 @@ type StarlinkGetObstructionMapResponse struct {
200190
Cols int
201191
Data []byte
202192
}
193+
194+
func (e *Exporter) ResetDishObstructionMap() error {
195+
req := &device.Request{
196+
Request: &device.Request_DishClearObstructionMap{},
197+
}
198+
199+
ctx, cancel := context.WithTimeout(context.Background(), grpcTimeout)
200+
defer cancel()
201+
_, err := e.Client.Handle(ctx, req)
202+
if err != nil {
203+
return fmt.Errorf("gRPC ClearObstructionMap failed: %s", err.Error())
204+
}
205+
return nil
206+
}

cmd/obstructionMapVideo/main.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import (
1111
"time"
1212
)
1313

14+
var (
15+
defaultDishAddress = "192.168.100.1:9200"
16+
grpcTimeout = 5 * time.Second
17+
GRPCAddrPort string
18+
Duration string
19+
DataDir string
20+
FPS int
21+
CreateVideo bool
22+
Reset bool
23+
)
24+
1425
func getTimeString() string {
1526
return time.Now().UTC().Format("2006-01-02-15-04-05")
1627
}
@@ -39,6 +50,7 @@ func main() {
3950
flag.StringVar(&DataDir, "data_dir", "./obstructionMapData", "Directory to save the obstruction map frames")
4051
flag.IntVar(&FPS, "fps", 10, "Frames per second for the video")
4152
flag.BoolVar(&CreateVideo, "video", true, "Create video from obstruction map frames")
53+
flag.BoolVar(&Reset, "reset", false, "Reset the obstruction map every 15 seconds, at the 12nd, 27th, 42nd, and 57th second")
4254
flag.Parse()
4355

4456
if CreateVideo {
@@ -76,6 +88,22 @@ func main() {
7688
return
7789
}
7890

91+
if Reset {
92+
go func(grpcClient *Exporter) {
93+
for {
94+
now := time.Now()
95+
sec := now.Second()
96+
if sec == 12 || sec == 27 || sec == 42 || sec == 57 {
97+
log.Printf("Resetting obstruction map at second: %d\n", sec)
98+
if err := grpcClient.ResetDishObstructionMap(); err != nil {
99+
log.Println("Error resetting obstruction map: ", err)
100+
}
101+
}
102+
time.Sleep(time.Second)
103+
}
104+
}(grpcClient)
105+
}
106+
79107
timeNow := time.Now()
80108
timeEnd := timeNow.Add(durationSecond)
81109

@@ -99,7 +127,7 @@ func main() {
99127
log.Println("Error writing obstruction map: ", err)
100128
}
101129
f.Close()
102-
time.Sleep(time.Second * 1)
130+
time.Sleep(time.Millisecond * 500)
103131
}
104132

105133
if CreateVideo {

0 commit comments

Comments
 (0)