stillbox/pkg/talkgroups/talkgroup.go

56 lines
970 B
Go
Raw Normal View History

2024-11-03 08:09:49 -05:00
package talkgroups
import (
"fmt"
2024-11-03 09:45:51 -05:00
"dynatron.me/x/stillbox/pkg/database"
2024-11-03 08:09:49 -05:00
)
2024-11-03 09:45:51 -05:00
type Talkgroup struct {
database.Talkgroup
System database.System `json:"system"`
Learned bool `json:"learned"`
}
2024-11-03 08:09:49 -05:00
type ID struct {
System uint32 `json:"sys"`
Talkgroup uint32 `json:"tg"`
2024-11-03 08:09:49 -05:00
}
2024-11-04 11:15:24 -05:00
type IDs []ID
func (ids *IDs) Packed() []int64 {
r := make([]int64, len(*ids))
for i := range *ids {
r[i] = (*ids)[i].Pack()
}
return r
}
2024-11-03 08:09:49 -05:00
func TG[T int | uint | int64 | uint64 | int32 | uint32](sys, tgid T) ID {
return ID{
System: uint32(sys),
Talkgroup: uint32(tgid),
}
}
func (t ID) Pack() int64 {
// P25 system IDs are 12 bits, so we can fit them in a signed 8 byte int (int64, pg INT8)
return int64((int64(t.System) << 32) | int64(t.Talkgroup))
}
func (t ID) String() string {
return fmt.Sprintf("%d:%d", t.System, t.Talkgroup)
}
func PackedTGs(tg []ID) []int64 {
s := make([]int64, len(tg))
for i, v := range tg {
s[i] = v.Pack()
}
return s
}