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.
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
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
|
|
}
|
|
*/
|
|
|