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 bucket: test
token: "" token: ""
name: Beaglebone Black name: Beaglebone Black
"2062445129":
devices:
"97":
name: DO Sensor
"99":
name: pH Sensor
"102":
name: RTD Sensor
server: server:
name: Rack Server name: Rack Server
ports: ports:

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

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

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