-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensors.go
53 lines (42 loc) · 1.13 KB
/
sensors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package roomba_api
import (
"fmt"
)
type SensorRequest struct {
Port string `json:"port_name"`
PacketId byte `json:"packet_id"`
}
type SensorResponse struct {
Value []byte `json:"value"`
}
type SensorListRequest struct {
Port string `json:"port_name"`
PacketIds []byte `json:"packet_ids"`
}
type SensorListResponse struct {
Values [][]byte `json:"values"`
}
func (server RoombaServer) Sensor(req SensorRequest, resp *SensorResponse) error {
conn, ok := server.Connections[req.Port]
if !ok {
return fmt.Errorf("connection not found: %s", req.Port)
}
sensor_data, err := conn.Roomba.Sensors(req.PacketId)
if err != nil {
return fmt.Errorf("error reading sensor packet: " + err.Error())
}
resp.Value = sensor_data
return nil
}
func (server RoombaServer) SensorList(req *SensorListRequest, resp *SensorListResponse) error {
conn, ok := server.Connections[req.Port]
if !ok {
return fmt.Errorf("connection not found: %s", req.Port)
}
sensor_data, err := conn.Roomba.QueryList(req.PacketIds)
if err != nil {
return fmt.Errorf("error reading sensors data: " + err.Error())
}
resp.Values = sensor_data
return nil
}