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