2023-10-12 17:46:43 +08:00
|
|
|
package repository
|
|
|
|
|
|
|
|
type IBP struct {
|
|
|
|
Spk *IBPRefMap
|
|
|
|
Emp *IBPRefMap
|
|
|
|
}
|
|
|
|
|
2023-10-17 15:05:13 +08:00
|
|
|
func NewIBP() *IBP {
|
2023-10-12 17:46:43 +08:00
|
|
|
return &IBP{
|
|
|
|
Spk: &IBPRefMap{
|
|
|
|
buttonMap: make(map[string]*Button),
|
|
|
|
relayMap: make(map[string]*Relay),
|
|
|
|
alarmMap: make(map[string]*Alarm),
|
2023-10-17 17:47:19 +08:00
|
|
|
lightMap: make(map[string]*Light),
|
2023-10-12 17:46:43 +08:00
|
|
|
},
|
|
|
|
Emp: &IBPRefMap{
|
|
|
|
buttonMap: make(map[string]*Button),
|
|
|
|
relayMap: make(map[string]*Relay),
|
|
|
|
alarmMap: make(map[string]*Alarm),
|
2023-10-17 17:47:19 +08:00
|
|
|
lightMap: make(map[string]*Light),
|
2023-10-12 17:46:43 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type IBPRefMap struct {
|
|
|
|
buttonMap map[string]*Button
|
|
|
|
relayMap map[string]*Relay
|
|
|
|
alarmMap map[string]*Alarm
|
2023-10-17 17:47:19 +08:00
|
|
|
lightMap map[string]*Light
|
2023-10-12 17:46:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) AddButton(btn *Button) {
|
|
|
|
ibp.buttonMap[btn.Id()] = btn
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) AddRelay(relay *Relay) {
|
|
|
|
ibp.relayMap[relay.Id()] = relay
|
|
|
|
}
|
|
|
|
|
2023-10-17 17:47:19 +08:00
|
|
|
func (ibp *IBPRefMap) AddLight(light *Light) {
|
|
|
|
ibp.lightMap[light.Id()] = light
|
|
|
|
}
|
|
|
|
|
2023-10-12 17:46:43 +08:00
|
|
|
func (ibp *IBPRefMap) AddAlarm(fmq *Alarm) {
|
|
|
|
ibp.alarmMap[fmq.Id()] = fmq
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) Buttons() []*Button {
|
|
|
|
var buttons []*Button
|
|
|
|
for _, b := range ibp.buttonMap {
|
|
|
|
buttons = append(buttons, b)
|
|
|
|
}
|
|
|
|
return buttons
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) Relays() []*Relay {
|
|
|
|
var relays []*Relay
|
|
|
|
for _, b := range ibp.relayMap {
|
|
|
|
relays = append(relays, b)
|
|
|
|
}
|
|
|
|
return relays
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ibp *IBPRefMap) Alarms() []*Alarm {
|
|
|
|
var alarms []*Alarm
|
|
|
|
for _, b := range ibp.alarmMap {
|
|
|
|
alarms = append(alarms, b)
|
|
|
|
}
|
|
|
|
return alarms
|
|
|
|
}
|
2023-10-17 17:47:19 +08:00
|
|
|
|
|
|
|
func (ibp *IBPRefMap) Lights() []*Light {
|
|
|
|
var lights []*Light
|
|
|
|
for _, b := range ibp.lightMap {
|
|
|
|
lights = append(lights, b)
|
|
|
|
}
|
|
|
|
return lights
|
|
|
|
}
|