90 lines
1.5 KiB
Go
90 lines
1.5 KiB
Go
package th7
|
|
|
|
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
|
|
cfg config.Config
|
|
run bool
|
|
}
|
|
|
|
func NewTH7Adapter(pcbPort ports.PCBPort, cfg config.Config) *TH7Adapter {
|
|
|
|
var adapter TH7Adapter
|
|
|
|
adapter.pcbPort = pcbPort
|
|
adapter.cfg = cfg
|
|
adapter.run = true
|
|
|
|
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)
|
|
}
|
|
|
|
go startCacheService(&adapter)
|
|
|
|
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 {
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
|
|
return t.data
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// Ratio table
|
|
func (t *TH7Adapter) GetRatio() core.Ratio {
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
|
|
return t.table
|
|
}
|