-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcmd.go
More file actions
45 lines (33 loc) · 811 Bytes
/
cmd.go
File metadata and controls
45 lines (33 loc) · 811 Bytes
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
package atem
import (
"fmt"
)
type AtemCmd struct {
Name string
Body []byte
Header []byte
}
func newCmd(Name string, Body []byte) *AtemCmd {
return &AtemCmd{Name: Name, Body: Body}
}
func parseCmd(msg []byte) *AtemCmd {
return &AtemCmd{Name: string(msg[4:8]), Body: msg[8:]}
}
func (ac *AtemCmd) length() uint16 {
return uint16(len(ac.Body) + 8)
}
func (ac *AtemCmd) string() string {
return fmt.Sprintf("Command:\t[%s]\t%d", ac.Name, ac.Body)
}
func (ac *AtemCmd) toBytes() []byte {
var result []byte
// Set length
result = append(result, []byte{uint8(ac.length() >> 8), uint8(ac.length() & 0xFF)}...)
// Set header
result = append(result, []byte{0, 0}...)
// Set cmd
result = append(result, []byte(ac.Name)...)
// Add body
result = append(result, ac.Body...)
return result
}