Changed the naming of mk2if to mk2driver
This commit is contained in:
committed by
ncthompson
parent
9236d6fa86
commit
d02de285d9
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/diebietse/invertergui/frontend"
|
||||
"github.com/diebietse/invertergui/mk2if"
|
||||
"github.com/diebietse/invertergui/mk2driver"
|
||||
"github.com/diebietse/invertergui/webgui"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
@@ -16,7 +16,7 @@ func main() {
|
||||
addr := flag.String("addr", ":8080", "TCP address to listen on.")
|
||||
flag.Parse()
|
||||
|
||||
mk2 := mk2if.NewMk2Mock()
|
||||
mk2 := mk2driver.NewMk2Mock()
|
||||
gui := webgui.NewWebGui(mk2)
|
||||
|
||||
http.Handle("/", frontend.NewStatic())
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
|
||||
"github.com/diebietse/invertergui/mk2if"
|
||||
"github.com/tarm/serial"
|
||||
"github.com/diebietse/invertergui/mk2driver"
|
||||
"github.com/mikepb/go-serial"
|
||||
)
|
||||
|
||||
// Basic CLI to serve as example lib usage
|
||||
@@ -44,7 +46,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
defer p.Close()
|
||||
mk2, err := mk2if.NewMk2Connection(p)
|
||||
mk2, err := mk2driver.NewMk2Connection(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -67,7 +69,7 @@ mainloop:
|
||||
log.Printf("Closing connection")
|
||||
}
|
||||
|
||||
func PrintInfo(info *mk2if.Mk2Info) {
|
||||
func PrintInfo(info *mk2driver.Mk2Info) {
|
||||
out := fmt.Sprintf("Version: %v\n", info.Version)
|
||||
out += fmt.Sprintf("Bat Volt: %.2fV Bat Cur: %.2fA \n", info.BatVoltage, info.BatCurrent)
|
||||
out += fmt.Sprintf("In Volt: %.2fV In Cur: %.2fA In Freq %.2fHz\n", info.InVoltage, info.InCurrent, info.InFrequency)
|
||||
@@ -76,7 +78,7 @@ func PrintInfo(info *mk2if.Mk2Info) {
|
||||
out += fmt.Sprintf("Charge State: %.2f%%\n", info.ChargeState*100)
|
||||
out += "LEDs state:"
|
||||
for k, v := range info.LEDs {
|
||||
out += fmt.Sprintf(" %s %s", mk2if.LedNames[k], mk2if.StateNames[v])
|
||||
out += fmt.Sprintf(" %s %s", mk2driver.LedNames[k], mk2driver.StateNames[v])
|
||||
}
|
||||
|
||||
out += "\nErrors:"
|
||||
|
||||
@@ -38,7 +38,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/diebietse/invertergui/frontend"
|
||||
"github.com/diebietse/invertergui/mk2if"
|
||||
"github.com/diebietse/invertergui/mk2driver"
|
||||
"github.com/diebietse/invertergui/webgui"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/tarm/serial"
|
||||
@@ -73,7 +73,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
defer p.Close()
|
||||
mk2, err := mk2if.NewMk2Connection(p)
|
||||
mk2, err := mk2driver.NewMk2Connection(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mk2if
|
||||
package mk2driver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -26,7 +26,7 @@ type mk2Ser struct {
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
func NewMk2Connection(dev io.ReadWriter) (Mk2If, error) {
|
||||
func NewMk2Connection(dev io.ReadWriter) (Mk2, error) {
|
||||
mk2 := &mk2Ser{}
|
||||
mk2.p = dev
|
||||
mk2.info = &Mk2Info{}
|
||||
@@ -1,4 +1,4 @@
|
||||
package mk2if
|
||||
package mk2driver
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -72,7 +72,7 @@ type Mk2Info struct {
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
type Mk2If interface {
|
||||
type Mk2 interface {
|
||||
C() chan *Mk2Info
|
||||
Close()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package mk2if
|
||||
package mk2driver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,7 +9,7 @@ type mock struct {
|
||||
c chan *Mk2Info
|
||||
}
|
||||
|
||||
func NewMk2Mock() Mk2If {
|
||||
func NewMk2Mock() Mk2 {
|
||||
tmp := &mock{
|
||||
c: make(chan *Mk2Info, 1),
|
||||
}
|
||||
@@ -35,11 +35,11 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/diebietse/invertergui/mk2if"
|
||||
"github.com/diebietse/invertergui/mk2driver"
|
||||
)
|
||||
|
||||
type muninData struct {
|
||||
status mk2if.Mk2Info
|
||||
status mk2driver.Mk2Info
|
||||
timesUpdated int
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ freqout.label Out frequency (Hz)
|
||||
}
|
||||
|
||||
//Munin only samples once every 5 minutes so averages have to be calculated for some values.
|
||||
func calcMuninValues(muninDat *muninData, newStatus *mk2if.Mk2Info) {
|
||||
func calcMuninValues(muninDat *muninData, newStatus *mk2driver.Mk2Info) {
|
||||
muninDat.timesUpdated++
|
||||
muninVal := &muninDat.status
|
||||
muninVal.OutCurrent += newStatus.OutCurrent
|
||||
|
||||
@@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
package webgui
|
||||
|
||||
import (
|
||||
"github.com/diebietse/invertergui/mk2if"
|
||||
"github.com/diebietse/invertergui/mk2driver"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@@ -117,7 +117,7 @@ func newPrometheusUpdater() *prometheusUpdater {
|
||||
return tmp
|
||||
}
|
||||
|
||||
func (pu *prometheusUpdater) updatePrometheus(newStatus *mk2if.Mk2Info) {
|
||||
func (pu *prometheusUpdater) updatePrometheus(newStatus *mk2driver.Mk2Info) {
|
||||
s := newStatus
|
||||
pu.batteryVoltage.Set(s.BatVoltage)
|
||||
pu.batteryCharge.Set(newStatus.ChargeState * 100)
|
||||
|
||||
@@ -37,7 +37,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/diebietse/invertergui/mk2if"
|
||||
"github.com/diebietse/invertergui/mk2driver"
|
||||
"github.com/diebietse/invertergui/websocket"
|
||||
)
|
||||
|
||||
@@ -53,14 +53,14 @@ type WebGui struct {
|
||||
stopChan chan struct{}
|
||||
|
||||
muninRespChan chan muninData
|
||||
poller mk2if.Mk2If
|
||||
poller mk2driver.Mk2
|
||||
wg sync.WaitGroup
|
||||
hub *websocket.Hub
|
||||
|
||||
pu *prometheusUpdater
|
||||
}
|
||||
|
||||
func NewWebGui(source mk2if.Mk2If) *WebGui {
|
||||
func NewWebGui(source mk2driver.Mk2) *WebGui {
|
||||
w := new(WebGui)
|
||||
w.muninRespChan = make(chan muninData)
|
||||
w.stopChan = make(chan struct{})
|
||||
@@ -111,15 +111,15 @@ func (w *WebGui) ServeHub(rw http.ResponseWriter, r *http.Request) {
|
||||
w.hub.ServeHTTP(rw, r)
|
||||
}
|
||||
|
||||
func ledName(led mk2if.Led) string {
|
||||
name, ok := mk2if.LedNames[led]
|
||||
func ledName(led mk2driver.Led) string {
|
||||
name, ok := mk2driver.LedNames[led]
|
||||
if !ok {
|
||||
return "Unknown led"
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func buildTemplateInput(status *mk2if.Mk2Info) *templateInput {
|
||||
func buildTemplateInput(status *mk2driver.Mk2Info) *templateInput {
|
||||
outPower := status.OutVoltage * status.OutCurrent
|
||||
inPower := status.InCurrent * status.InVoltage
|
||||
|
||||
@@ -145,20 +145,20 @@ func buildTemplateInput(status *mk2if.Mk2Info) *templateInput {
|
||||
LedMap: map[string]string{},
|
||||
}
|
||||
for k, v := range status.LEDs {
|
||||
if k == mk2if.LedOverload || k == mk2if.LedTemperature || k == mk2if.LedLowBattery {
|
||||
if k == mk2driver.LedOverload || k == mk2driver.LedTemperature || k == mk2driver.LedLowBattery {
|
||||
switch v {
|
||||
case mk2if.LedOn:
|
||||
case mk2driver.LedOn:
|
||||
tmpInput.LedMap[ledName(k)] = LedRed
|
||||
case mk2if.LedBlink:
|
||||
case mk2driver.LedBlink:
|
||||
tmpInput.LedMap[ledName(k)] = BlinkRed
|
||||
default:
|
||||
tmpInput.LedMap[ledName(k)] = LedOff
|
||||
}
|
||||
} else {
|
||||
switch v {
|
||||
case mk2if.LedOn:
|
||||
case mk2driver.LedOn:
|
||||
tmpInput.LedMap[ledName(k)] = LedGreen
|
||||
case mk2if.LedBlink:
|
||||
case mk2driver.LedBlink:
|
||||
tmpInput.LedMap[ledName(k)] = BlinkGreen
|
||||
default:
|
||||
tmpInput.LedMap[ledName(k)] = LedOff
|
||||
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/diebietse/invertergui/mk2if"
|
||||
"github.com/diebietse/invertergui/mk2driver"
|
||||
)
|
||||
|
||||
func TestWebGui(t *testing.T) {
|
||||
@@ -45,14 +45,14 @@ func TestWebGui(t *testing.T) {
|
||||
}
|
||||
|
||||
type templateTest struct {
|
||||
input *mk2if.Mk2Info
|
||||
input *mk2driver.Mk2Info
|
||||
output *templateInput
|
||||
}
|
||||
|
||||
var fakenow = time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC)
|
||||
var templateInputTests = []templateTest{
|
||||
{
|
||||
input: &mk2if.Mk2Info{
|
||||
input: &mk2driver.Mk2Info{
|
||||
OutCurrent: 2.0,
|
||||
InCurrent: 2.3,
|
||||
OutVoltage: 230.0,
|
||||
@@ -62,7 +62,7 @@ var templateInputTests = []templateTest{
|
||||
InFrequency: 50,
|
||||
OutFrequency: 50,
|
||||
ChargeState: 1,
|
||||
LEDs: map[mk2if.Led]mk2if.LEDstate{mk2if.LedMain: mk2if.LedOn},
|
||||
LEDs: map[mk2driver.Led]mk2driver.LEDstate{mk2driver.LedMain: mk2driver.LedOn},
|
||||
Errors: nil,
|
||||
Timestamp: fakenow,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user