stillbox/pkg/talkgroups/talkgroup.go

64 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-11-03 08:09:49 -05:00
package talkgroups
import (
"fmt"
"strconv"
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"`
}
func (t Talkgroup) String() string {
if t.System.Name == "" {
t.System.Name = strconv.Itoa(int(t.Talkgroup.TGID))
}
if t.Talkgroup.Name != nil || t.Talkgroup.TGGroup != nil || t.Talkgroup.AlphaTag != nil {
return t.System.Name + " " + t.Talkgroup.String()
}
2024-11-13 09:24:11 -05:00
return fmt.Sprintf("%s:%d", t.System.Name, int(t.Talkgroup.TGID))
2024-11-07 23:17:16 -05:00
}
type Metadata map[string]interface{}
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
2024-11-15 10:37:58 -05:00
func (t IDs) Tuples() database.TGTuples {
sys := make([]uint32, len(t))
tg := make([]uint32, len(t))
for i := range t {
sys[i] = t[i].System
tg[i] = t[i].Talkgroup
2024-11-04 11:15:24 -05:00
}
2024-11-15 10:37:58 -05:00
return database.TGTuples{sys, tg}
2024-11-04 11:15:24 -05:00
}
2024-11-07 12:53:20 -05:00
type intId interface {
int | uint | int64 | uint64 | int32 | uint32
}
func TG[T intId, U intId](sys T, tgid U) ID {
2024-11-03 08:09:49 -05:00
return ID{
System: uint32(sys),
Talkgroup: uint32(tgid),
}
}
func (t ID) String() string {
return fmt.Sprintf("%d:%d", t.System, t.Talkgroup)
}