building locally
parent
c013330b81
commit
e975cb984b
Binary file not shown.
@ -1,13 +0,0 @@
|
||||
package api
|
||||
|
||||
import "time"
|
||||
|
||||
type Reactor struct {
|
||||
ID string
|
||||
Sensors []Sensor
|
||||
}
|
||||
|
||||
type Sensor struct {
|
||||
id string
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
syntax = "proto3";
|
||||
package grpc;
|
||||
|
||||
option go_package = "internal/pkg/grpc";
|
||||
|
||||
service discovery {
|
||||
rpc ReactorDiscoveryHandler(ReactorInfoRequest) returns (SuccessResponse);
|
||||
}
|
||||
|
||||
message ReactorInfoRequest {
|
||||
string Id = 1;
|
||||
uint32 Ip = 2;
|
||||
int32 Port = 3;
|
||||
}
|
||||
|
||||
message ServerResponse {
|
||||
string Id = 1;
|
||||
bool Success = 2;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package reactor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"FRMS/internal/pkg/I2C"
|
||||
)
|
||||
|
||||
type Coordinator struct {
|
||||
Id string
|
||||
Port int
|
||||
}
|
||||
|
||||
|
||||
func Start(id string, port, bus int) error {
|
||||
// start a gRPC server to respond to pings from central server
|
||||
//fmt.Printf("Starting gRPC server on %v:%v\n",c.Id,c.Port)
|
||||
//lis, err := net.Listen("tcp",fmt.Sprintf("%v:%v",c.Id,c.Port))
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
|
||||
//grpcServer := grpc.NewServer()
|
||||
//pb.RegisterCoordinatorServer(grpcServer, newServer())
|
||||
|
||||
//go grpcServer.Serve(lis)
|
||||
// now setting up sensor managers
|
||||
c := &Coordinator{Id:id,Port:port}
|
||||
activeDevices := I2C.Start(c.Id,c.Port,bus) //returns list of active sensor addr and starts I2C monitoring software
|
||||
for _,v := range activeDevices {
|
||||
// create a goroutine for each active sensor
|
||||
//go sensor.NewManager(v)
|
||||
fmt.Printf("Sensor at addr %v initialized\n",v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// grpc stuff
|
||||
/*
|
||||
func newServer() *coordinatorServer {
|
||||
return &coordinatorServer{}
|
||||
}
|
||||
|
||||
type coordinatorServer struct {
|
||||
pb.UnimplementedCoordinatorServer
|
||||
id string
|
||||
}
|
||||
|
||||
func (s *coordinatorServer) PingHandler(ctx context.Context, ping *pb.PingRequest) (*pb.PingResponse, error){
|
||||
now := time.Now()
|
||||
fmt.Printf("Ping from server recieved at time %v\n", now.Format("15:04:05"))
|
||||
return &pb.PingResponse{Id: s.id}, nil
|
||||
}
|
||||
*/
|
||||
|
@ -0,0 +1,75 @@
|
||||
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
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// the goal here is to set up a gRPC handler to respond to reactor pings with their IP and to establish a new coordinator for that specific reactor
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// this package will implement a reactor coordinator and associated go routines
|
@ -0,0 +1,95 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"os/exec"
|
||||
"bytes"
|
||||
"hash/fnv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// this package serves to add in wrappers for system commands to get hwinfo from the board
|
||||
// this package does not actually use the hwinfo command, but rather gathers hardware info from a variety of commands
|
||||
|
||||
// command for model :
|
||||
// lshw -C system 2>/dev/null | head -n 1
|
||||
// command for ip && mac address :
|
||||
// ifconfig eth0 | awk '/inet |ether / {print $2}'
|
||||
|
||||
// can combine and dump into file using
|
||||
// lshw -C system 2>/dev/null | head -n 1 > hwinfo.txt && ifconfig eth0 | awk '/inet |ether / {print $2}' >> hwinfo.txt
|
||||
// *** will just replace info in file everytime
|
||||
|
||||
|
||||
type HWMonitor struct {
|
||||
Ip string
|
||||
Id uint32
|
||||
Bus int
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewHWMonitor() *HWMonitor {
|
||||
h := &HWMonitor{}
|
||||
err := h.Start()
|
||||
if err != nil {
|
||||
fmt.Println("hw setup failed " + fmt.Sprint(err))
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *HWMonitor) GetIp() string {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
return h.Ip
|
||||
}
|
||||
|
||||
func (h *HWMonitor) GetId() uint32 {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
return h.Id
|
||||
}
|
||||
|
||||
func (h *HWMonitor) GetBus() int {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
return h.Bus
|
||||
}
|
||||
|
||||
func (h *HWMonitor) Start() error {
|
||||
// responsible for filling out struct
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock() // want to ensure we get all values before the RLC reads
|
||||
bus := map[string]int{"raspberrypi":1,"beaglebone":2} // eventually will replace this with a config file
|
||||
|
||||
ipcmd := "ifconfig eth0 | awk '/inet / {print $2}'"
|
||||
maccmd := "ifconfig eth0 | awk '/ether / {print $2}'"
|
||||
devcmd := "lshw -C system 2>/dev/null | head -n 1"
|
||||
|
||||
res := [3]bytes.Buffer{}
|
||||
var stderr bytes.Buffer
|
||||
cmds := []string{ipcmd,maccmd,devcmd}
|
||||
for i,c := range cmds {
|
||||
cmd := exec.Command("bash","-c",c)
|
||||
cmd.Stdout = &res[i]
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprint(err)+": "+stderr.String())
|
||||
return err
|
||||
}
|
||||
}
|
||||
// formatting
|
||||
ip := res[0].String()
|
||||
ip = strings.Trim(ip," \n")
|
||||
h.Ip = ip
|
||||
|
||||
hash := fnv.New32a()
|
||||
hash.Write(res[1].Bytes())
|
||||
h.Id = hash.Sum32()
|
||||
|
||||
b := res[2].String()
|
||||
b = strings.Trim(b," \n")
|
||||
h.Bus = bus[b]
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue