Fixed bugs, working on server side

main
KeeganForelight 2 years ago
parent 4ab69cb503
commit 1180a8a575

BIN
debian

Binary file not shown.

@ -9,6 +9,14 @@ reactors:
bucket: test
token: ""
name: Beaglebone Black
"2062445129":
devices:
"97":
name: DO Sensor
"99":
name: pH Sensor
"102":
name: RTD Sensor
server:
name: Rack Server
ports:

@ -28,7 +28,6 @@ func New(maxCon int) *Manager {
c := &Connection{MaxAttempts: maxCon}
m := &Manager{
Connection: c,
Active: 0,
}
return m

@ -45,12 +45,17 @@ func NewCentralCoordinator(config *viper.Viper, ch chan error) *CentralCoordinat
ch <- err
}
rc, err := NewReactorCoordinator(ch)
rc, err := NewReactorCoordinator(config, ch)
if err != nil {
ch <- err
}
config.UnmarshalKey("server.ports", rc) // get reactor port
c := &CentralCoordinator{Err: ch, Config: config, Database: db, ReactorCoordinator: rc}
c := &CentralCoordinator{
Err: ch,
Config: config,
Database: db,
ReactorCoordinator: rc,
}
// grab config settings
if err = config.UnmarshalKey("server", c); err != nil {
ch <- err
@ -114,13 +119,14 @@ type ReactorCoordinator struct {
}
type ReactorManagers struct {
Config *viper.Viper
Directory map[int]*ReactorManager
sync.RWMutex
}
func NewReactorCoordinator(errCh chan error) (*ReactorCoordinator, error) {
func NewReactorCoordinator(config *viper.Viper, errCh chan error) (*ReactorCoordinator, error) {
rmap := make(map[int]*ReactorManager)
rm := &ReactorManagers{Directory: rmap}
rm := &ReactorManagers{Directory: rmap, Config: config}
c := &ReactorCoordinator{Err: errCh, ReactorManagers: rm}
return c, nil
}
@ -144,7 +150,7 @@ func (m *ReactorManagers) GetReactorManager(id int) (*ReactorManager, error) {
rm, exists := m.Directory[id]
if !exists {
return &ReactorManager{ID: id}, errors.New(fmt.Sprintf("No manager for reactor %d!", id))
return &ReactorManager{}, errors.New(fmt.Sprintf("No manager for reactor %d!", id))
}
return rm, nil
}
@ -160,7 +166,7 @@ func (m *ReactorManagers) UpdateReactorManager(cl *Client, errCh chan error) err
if !exists {
logging.Debug(logging.DClient, "RCO creating manager for reactor client %v", cl.Id)
// creating
rm = NewReactorManager(errCh)
rm = NewReactorManager(cl, m.Config, errCh)
// starting
if err = rm.Start(); err != nil {
return err

@ -35,25 +35,26 @@ type ReactorManager struct {
// StatusMon *StatusMonitor putting on pause
*ReactorDevices
Config *viper.Viper // config to update
ID int
Err chan error
}
type ReactorDevices struct {
// device struct
ID int
Devices map[int]DeviceManager
sync.RWMutex
}
func NewReactorManager(errCh chan error) *ReactorManager {
func NewReactorManager(cl *Client, config *viper.Viper, errCh chan error) *ReactorManager {
// making managers
m := NewManager(6)
dm := make(map[int]DeviceManager)
rd := &ReactorDevices{Devices: dm}
cm := NewClientManager(cl)
r := &ReactorManager{
Manager: m,
ClientManager: cm,
ReactorDevices: rd,
Config: config,
Err: errCh,
}
return r
@ -76,7 +77,7 @@ func (r *ReactorManager) Exit() error {
func (r *ReactorManager) ReactorStatusHandler(ctx context.Context, req *pb.ReactorStatusPing) (*pb.ReactorStatusResponse, error) {
// function client will call to update reactor information
//go r.PingReset()
fmt.Printf("Recieved ping from %v!\n", req.GetId())
fmt.Printf("Recieved ping from %d!\n", req.GetId())
// update devices/sensors
go r.UpdateDevices(req.GetDevices())
@ -109,7 +110,8 @@ func (r *ReactorManager) UpdateDevices(devs []*pb.Device) {
//fmt.Println(dm)
} else {
// not found
go r.AddDevice(dev, r.ID, r.Config, r.Err)
go r.AddDevice(dev, r.Id, r.Config, r.Err)
fmt.Printf("ID %d\n", r.Id)
}
}
}

Loading…
Cancel
Save