modify drivers
This commit is contained in:
@@ -4,28 +4,33 @@ 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
|
||||
Name string `json:"name,omitempty"`
|
||||
Address []uint `json:"address,omitempty"` // address of bus
|
||||
Topic *Topic `json:"topic,omitempty"` // address of bus
|
||||
}
|
||||
|
||||
func (b *Bus) AddAddress(address uint) {
|
||||
if !slices.Contains(b.Address, address) {
|
||||
b.Address = append(b.Address, address)
|
||||
func (b *Bus) AddAddress(address ...uint) {
|
||||
for _, a := range address {
|
||||
if slices.Contains(b.Address, a) {
|
||||
continue
|
||||
}
|
||||
b.Address = append(b.Address, a)
|
||||
slices.Sort(b.Address)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (b *Bus) AddSubscription(sub string) {
|
||||
func (b *Bus) AddSubscription(sub ...string) {
|
||||
if b.Topic == nil {
|
||||
b.Topic = &Topic{}
|
||||
}
|
||||
b.Topic.AddSubscription(sub)
|
||||
b.Topic.AddSubscription(sub...)
|
||||
}
|
||||
|
||||
func (b *Bus) AddPublish(pub string) {
|
||||
func (b *Bus) AddPublish(pub ...string) {
|
||||
if b.Topic == nil {
|
||||
b.Topic = &Topic{}
|
||||
}
|
||||
b.Topic.AddPublish(pub)
|
||||
b.Topic.AddPublish(pub...)
|
||||
}
|
||||
|
Reference in New Issue
Block a user