Added golangci linting and improved what was required

This commit is contained in:
Nicholas Thompson
2019-03-07 19:04:15 +02:00
committed by ncthompson
parent 206159cdea
commit 2456f45836
15 changed files with 244 additions and 255 deletions

71
mk2if/mockmk2.go Normal file
View File

@@ -0,0 +1,71 @@
package mk2if
import (
"fmt"
"time"
)
type mock struct {
c chan *Mk2Info
}
func NewMk2Mock() Mk2If {
tmp := &mock{
c: make(chan *Mk2Info, 1),
}
go tmp.genMockValues()
return tmp
}
func genBaseLeds(state LEDstate) map[Led]LEDstate {
return map[Led]LEDstate{
LedMain: state,
LedAbsorption: state,
LedBulk: state,
LedFloat: state,
LedInverter: state,
LedOverload: state,
LedLowBattery: state,
LedTemperature: state,
}
}
func (m *mock) C() chan *Mk2Info {
return m.c
}
func (m *mock) Close() {
}
func (m *mock) genMockValues() {
mult := 1.0
ledState := LedOff
for {
input := &Mk2Info{
OutCurrent: 2.0 * mult,
InCurrent: 2.3 * mult,
OutVoltage: 230.0 * mult,
InVoltage: 230.1 * mult,
BatVoltage: 25 * mult,
BatCurrent: -10 * mult,
InFrequency: 50 * mult,
OutFrequency: 50 * mult,
ChargeState: 1 * mult,
Errors: nil,
Timestamp: time.Now(),
Valid: true,
LEDs: genBaseLeds(ledState),
}
ledState = (ledState + 1) % 3
mult = mult - 0.1
if mult < 0 {
mult = 1.0
}
fmt.Printf("Sending\n")
m.c <- input
time.Sleep(1 * time.Second)
}
}