th7/core/th7.go

76 lines
1.3 KiB
Go
Raw Normal View History

2022-11-12 14:20:29 +00:00
package core
import (
2022-11-12 22:43:16 +00:00
"errors"
2022-11-12 14:20:29 +00:00
"sync"
2022-11-12 16:22:55 +00:00
"th7/data/config"
2022-11-12 14:20:29 +00:00
"th7/data/core"
"th7/ports"
)
type TH7Adapter struct {
pcbPort ports.PCBPort
mu sync.Mutex
2022-11-12 22:43:16 +00:00
data []core.Channel
lookup map[int]int
table core.Ratio
2022-11-12 14:20:29 +00:00
}
2022-11-12 16:22:55 +00:00
func NewTH7Adapter(pcbPort ports.PCBPort, cfg config.Config) *TH7Adapter {
2022-11-12 14:20:29 +00:00
var adapter TH7Adapter
adapter.pcbPort = pcbPort
2022-11-12 22:43:16 +00:00
adapter.lookup = make(map[int]int)
adapter.data = make([]core.Channel, 0)
for idx, elem := range cfg.Channels {
var channel core.Channel
channel.Id = elem.Id
adapter.lookup[channel.Id] = idx
adapter.data = append(adapter.data, channel)
}
2022-11-12 14:20:29 +00:00
return &adapter
}
func (t *TH7Adapter) GetChannel(id int) (core.Channel, error) {
t.mu.Lock()
defer t.mu.Unlock()
2022-11-12 22:43:16 +00:00
if val, ok := t.lookup[id]; ok {
return t.data[val], nil
}
return core.Channel{}, errors.New("specified channel not configured")
2022-11-12 14:20:29 +00:00
}
2022-11-12 22:43:16 +00:00
func (t *TH7Adapter) GetChannels() ([]core.Channel, error) {
2022-11-12 14:20:29 +00:00
t.mu.Lock()
defer t.mu.Unlock()
2022-11-12 22:43:16 +00:00
return t.data, nil
2022-11-12 14:20:29 +00:00
}
func (t *TH7Adapter) GetVref() float64 {
t.mu.Lock()
defer t.mu.Unlock()
2022-11-12 22:43:16 +00:00
return t.table.Vref
2022-11-12 14:20:29 +00:00
}
func (t *TH7Adapter) GetVadj() float64 {
t.mu.Lock()
defer t.mu.Unlock()
2022-11-12 22:43:16 +00:00
return t.table.Vadj
2022-11-12 14:20:29 +00:00
}
func (t *TH7Adapter) GetPivdd() float64 {
t.mu.Lock()
defer t.mu.Unlock()
2022-11-12 22:43:16 +00:00
return t.table.Pivdd
2022-11-12 14:20:29 +00:00
}