76 lines
1.3 KiB
Go
76 lines
1.3 KiB
Go
package core
|
|
|
|
import (
|
|
"errors"
|
|
"sync"
|
|
"th7/data/config"
|
|
"th7/data/core"
|
|
"th7/ports"
|
|
)
|
|
|
|
type TH7Adapter struct {
|
|
pcbPort ports.PCBPort
|
|
mu sync.Mutex
|
|
data []core.Channel
|
|
lookup map[int]int
|
|
table core.Ratio
|
|
}
|
|
|
|
func NewTH7Adapter(pcbPort ports.PCBPort, cfg config.Config) *TH7Adapter {
|
|
|
|
var adapter TH7Adapter
|
|
|
|
adapter.pcbPort = pcbPort
|
|
|
|
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)
|
|
}
|
|
|
|
return &adapter
|
|
}
|
|
|
|
func (t *TH7Adapter) GetChannel(id int) (core.Channel, error) {
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
|
|
if val, ok := t.lookup[id]; ok {
|
|
return t.data[val], nil
|
|
}
|
|
|
|
return core.Channel{}, errors.New("specified channel not configured")
|
|
}
|
|
|
|
func (t *TH7Adapter) GetChannels() ([]core.Channel, error) {
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
|
|
return t.data, nil
|
|
}
|
|
|
|
func (t *TH7Adapter) GetVref() float64 {
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
|
|
return t.table.Vref
|
|
}
|
|
|
|
func (t *TH7Adapter) GetVadj() float64 {
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
|
|
return t.table.Vadj
|
|
}
|
|
|
|
func (t *TH7Adapter) GetPivdd() float64 {
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
|
|
return t.table.Pivdd
|
|
}
|