modify and add new fields for drivers

This commit is contained in:
Adrian Zuercher
2025-07-29 12:05:03 +02:00
parent 2d6db85b8c
commit eabac1b11b
5 changed files with 110 additions and 23 deletions

31
models/bus.go Normal file
View File

@@ -0,0 +1,31 @@
package models
import "slices"
// bus model
type Bus struct {
Name string `json:"name,omitemtpy"`
Address []uint `json:"address,omitemtpy"` // address of bus
Topic *Topic `json:"topic,omitemtpy"` // address of bus
}
func (b *Bus) AddAddress(address uint) {
if !slices.Contains(b.Address, address) {
b.Address = append(b.Address, address)
slices.Sort(b.Address)
}
}
func (b *Bus) AddSubscription(sub string) {
if b.Topic == nil {
b.Topic = &Topic{}
}
b.Topic.AddSubscription(sub)
}
func (b *Bus) AddPublish(pub string) {
if b.Topic == nil {
b.Topic = &Topic{}
}
b.Topic.AddPublish(pub)
}