You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
3 years ago
|
package reactor
|
||
|
|
||
|
// file describes reactor level coordinator and associated implementation
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"FRMS/internal/pkg/system"
|
||
|
"FRMS/internal/pkg/I2C"
|
||
|
)
|
||
|
|
||
|
type Hardware interface {
|
||
|
GetIp() string
|
||
|
GetId() uint32
|
||
|
GetBus() int
|
||
|
}
|
||
|
|
||
|
type I2CMonitor interface {
|
||
|
Connected() []int
|
||
|
}
|
||
|
|
||
|
type Coordinator struct {
|
||
|
Server string
|
||
|
HW Hardware // object to keep track of reactor hw info
|
||
|
I2C I2CMonitor // I2C monitor to keep track of I2C devices
|
||
|
}
|
||
|
|
||
|
//type SensorManager interface {
|
||
|
// Start()
|
||
|
//}
|
||
|
|
||
|
func NewCoordinator(s string) *Coordinator {
|
||
|
return &Coordinator{Server:s}
|
||
|
}
|
||
|
|
||
|
func NewI2CMonitor(b int) I2CMonitor {
|
||
|
return I2C.NewMonitor(b)
|
||
|
}
|
||
|
|
||
|
//func NewSensorManager() SensorManager {
|
||
|
//return sensor.NewManager()
|
||
|
//}
|
||
|
|
||
|
func NewHWMonitor() Hardware {
|
||
|
return system.NewHWMonitor()
|
||
|
}
|
||
|
|
||
|
func (c *Coordinator) Start() error {
|
||
|
// should discover hwinfo and sensors on its own
|
||
|
// now setting up sensor managers
|
||
|
c.HW = NewHWMonitor()
|
||
|
fmt.Printf("Reactor at IP addr %v using I2C bus %v\n",c.HW.GetIp(),c.HW.GetBus())
|
||
|
response := c.Connect()
|
||
|
for response != nil {
|
||
|
// wait to set up the rest of the system until we get a connection
|
||
|
fmt.Println("Connection failed!")
|
||
|
response = c.Connect()
|
||
|
}
|
||
|
c.I2C = NewI2CMonitor(c.HW.GetBus())
|
||
|
devs := c.I2C.Connected()
|
||
|
for _,d := range devs {
|
||
|
// create a goroutine for each active sensor
|
||
|
//sm := NewSensorManager(d)
|
||
|
//go sm.Start()
|
||
|
fmt.Printf("Sensor Manager for addr %v Started!\n",d)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (c *Coordinator) Connect() error {
|
||
|
// function connects to central server and passes hwinfo
|
||
|
|
||
|
|
||
|
return nil
|
||
|
}
|