stillbox/pkg/talkgroups/talkgroup.go

50 lines
892 B
Go

package talkgroups
import (
"fmt"
"dynatron.me/x/stillbox/pkg/database"
)
type Talkgroup struct {
database.Talkgroup
System database.System `json:"system"`
Learned bool `json:"learned"`
}
type ID struct {
System uint32 `json:"sys"`
Talkgroup uint32 `json:"tg"`
}
type IDs []ID
func (ids *IDs) Packed() []int64 {
r := make([]int64, len(*ids))
for i := range *ids {
r[i] = (*ids)[i].Pack()
}
return r
}
type intId interface {
int | uint | int64 | uint64 | int32 | uint32
}
func TG[T intId, U intId](sys T, tgid U) 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)
}