virtual board works

This commit is contained in:
2019-10-27 22:51:00 +01:00
parent fb819a71c4
commit f781e24028
4 changed files with 39 additions and 40 deletions

View File

@@ -78,8 +78,8 @@ func (b *Board) PowerStatus(num uint) (bool, error) {
} }
val, ok := b.dummyValue[num] val, ok := b.dummyValue[num]
if !ok { if !ok {
b.dummyValue[num] = true b.dummyValue[num] = false
val = true val = false
} }
log.Printf("status %v:%v", num, val) log.Printf("status %v:%v", num, val)
return val, nil return val, nil

View File

@@ -4,12 +4,12 @@ package main
type Boardlink struct { type Boardlink struct {
BoardID string `json:"boardid"` BoardID string `json:"boardid"`
Channel uint `json:"channel"` Channel uint `json:"channel"`
board Board board *Board
} }
// Board def // Board def
func (bl Boardlink) Board() Board { func (bl Boardlink) Board() *Board {
if bl.board.ID == "" { if bl.board == nil {
for i := range TheConfig.Boards { for i := range TheConfig.Boards {
if TheConfig.Boards[i].ID == bl.BoardID { if TheConfig.Boards[i].ID == bl.BoardID {
bl.board = TheConfig.Boards[i] bl.board = TheConfig.Boards[i]

View File

@@ -9,7 +9,7 @@ import (
type Configuration struct { type Configuration struct {
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
Outlets map[(uint)]Outlet `json:"outlets"` Outlets map[(uint)]Outlet `json:"outlets"`
Boards []Board `json:"boards"` Boards []*Board `json:"boards"`
MQTT MQTTConfig `json:"mqtt"` MQTT MQTTConfig `json:"mqtt"`
} }

View File

@@ -1,6 +1,34 @@
package main package main
func createMockConfig() Configuration { func createMockConfig() Configuration {
b1 := new(Board)
b1.ID = "47e41dc9-4a14-4b79-8644-d7442a15cb50"
b1.Name = "Virtual IO"
b1.Type = BoardTypeDummy
b1.ChannelCount = 40
b2 := new(Board)
b2.ID = "6561df75-bf93-43f5-82ac-9b3dda081961"
b2.Name = "Internal GPIO"
b2.Type = BoardTypeGPIO
b2.ChannelCount = 40
b3 := new(Board)
b3.Bus = 1
b3.Address = 0x29
b3.ID = "79690164-214f-41b0-93f9-e910dd54f323"
b3.Name = "bordo1"
b3.Type = BoardTypeI2CGPIO
b3.ChannelCount = 8
b4 := new(Board)
b4.Bus = 1
b4.Address = 0x27
b4.ID = "93f446d8-59e4-4abd-8bf7-e31cd80bc713"
b4.Name = "bordo2"
b4.Type = BoardTypeI2CADC
b4.ChannelCount = 4
return Configuration{ return Configuration{
Hostname: "maramao", Hostname: "maramao",
MQTT: MQTTConfig{ MQTT: MQTTConfig{
@@ -13,47 +41,18 @@ func createMockConfig() Configuration {
Topic: "openpdu/ok", Topic: "openpdu/ok",
HomeAssistant: true, HomeAssistant: true,
}, },
Boards: []Board{ Boards: []*Board{b1, b2, b3, b4},
Board{
ID: "47e41dc9-4a14-4b79-8644-d7442a15cb50",
Name: "Virtual IO",
Type: BoardTypeDummy,
ChannelCount: 40,
},
Board{
ID: "6561df75-bf93-43f5-82ac-9b3dda081961",
Name: "Internal GPIO",
Type: BoardTypeGPIO,
ChannelCount: 40,
},
Board{
Bus: 1,
Address: 0x29,
ID: "79690164-214f-41b0-93f9-e910dd54f323",
Name: "bordo1",
Type: BoardTypeI2CGPIO,
ChannelCount: 8,
},
Board{
Bus: 1,
Address: 0x27,
ID: "93f446d8-59e4-4abd-8bf7-e31cd80bc713",
Name: "bordo2",
Type: BoardTypeI2CADC,
ChannelCount: 4,
},
},
Outlets: map[(uint)]Outlet{ Outlets: map[(uint)]Outlet{
0: Outlet{ 0: Outlet{
Name: "uscita 0", Name: "uscita 0",
Location: "port 1 dx", Location: "port 1 dx",
HasPowerMeter: true, HasPowerMeter: true,
Command: Boardlink{ Command: Boardlink{
BoardID: "79690164-214f-41b0-93f9-e910dd54f323", BoardID: b1.ID,
Channel: 0, Channel: 0,
}, },
PowerMeter: Boardlink{ PowerMeter: Boardlink{
BoardID: "93f446d8-59e4-4abd-8bf7-e31cd80bc713", BoardID: b4.ID,
Channel: 0, Channel: 0,
}, },
}, },
@@ -62,11 +61,11 @@ func createMockConfig() Configuration {
Location: "port 1 sx", Location: "port 1 sx",
HasPowerMeter: true, HasPowerMeter: true,
Command: Boardlink{ Command: Boardlink{
BoardID: "79690164-214f-41b0-93f9-e910dd54f323", BoardID: b1.ID,
Channel: 1, Channel: 1,
}, },
PowerMeter: Boardlink{ PowerMeter: Boardlink{
BoardID: "93f446d8-59e4-4abd-8bf7-e31cd80bc713", BoardID: b4.ID,
Channel: 1, Channel: 1,
}, },
}, },