building locally

main
KeeganForelight 2 years ago
parent e975cb984b
commit a1d161256a

Binary file not shown.

@ -9,17 +9,19 @@ type coordinator interface {
Start() error
}
func NewCoordinator(s string) coordinator {
func NewCoordinator(s string,ch chan error) coordinator {
// allows interface checking as opposed to calling directly
return reactor.NewCoordinator(s)
return reactor.NewCoordinator(s,ch)
}
func main() {
rlc := NewCoordinator("192.1.168.__:____") // host port
ch := make(chan error)
rlc := NewCoordinator("192.1.168.136:2000",ch) // host port
go rlc.Start()
fmt.Printf("Starting reactor")
for true {
// endless loop to keep main alive
fmt.Printf("Starting reactor\n")
err := <-ch
if err != nil {
fmt.Println(err)
}
}

Binary file not shown.

@ -2,46 +2,29 @@ package main
import (
"fmt"
"time"
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "FRMS/internal/pkg/grpc"
"FRMS/internal/pkg/server"
)
var Reactors = []string{"192.1.168.156","192.1.168.81"}
func main() {
// lets get this bread
for _, r := range Reactors {
go pingReactors(r)
}
type reactorListener interface {
Start()
GetIp() string
GetPort() int
}
for true {
time.Sleep(10 * time.Second)
}
func NewReactorListener(ch chan error) reactorListener {
return server.NewReactorListener(ch)
}
func pingReactors(id string) {
fmt.Println(id)
var opts []grpc.DialOption
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.Dial(id+":2000",opts...)
func main() {
// lets get this bread
// all we need to do is call the reactor coordinator and thats it
ch := make(chan error)
rl := NewReactorListener(ch)
fmt.Printf("Starting Listener on %v:%v\n",rl.GetIp(),rl.GetPort())
go rl.Start()
err := <-ch // blocking to wait for any errors and keep alive otherwise
if err != nil {
fmt.Println(err)
}
defer conn.Close()
client := pb.NewMonitoringClient(conn)
for true{
resp, err := client.SensorStatusHandler(context.Background(), &pb.SensorStatusRequest{})
if err != nil {
fmt.Println(err)
}
fmt.Printf("Reactor %v active\n", resp.Id)
time.Sleep(3 * time.Second)
//fmt.Printf("ERROR: %v\n",err)
return
}
}

Binary file not shown.

@ -2,13 +2,15 @@ module FRMS
go 1.18
require (
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.27.1
)
require (
github.com/golang/protobuf v1.5.2 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
golang.org/x/text v0.3.3 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)

@ -41,6 +41,7 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
@ -88,6 +89,7 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
@ -104,8 +106,6 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=
google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 h1:TLkBREm4nIsEcexnCjgQd5GQWaHcqMzwQV0TX9pq8S0=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

@ -55,4 +55,3 @@ func (m *I2CMonitor) Connected() []int {
connected = append(connected, a)
}
return connected
}

@ -25,7 +25,7 @@ type SensorStatusRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *SensorStatusRequest) Reset() {
@ -60,11 +60,11 @@ func (*SensorStatusRequest) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_monitoring_proto_rawDescGZIP(), []int{0}
}
func (x *SensorStatusRequest) GetId() string {
func (x *SensorStatusRequest) GetId() uint32 {
if x != nil {
return x.Id
}
return ""
return 0
}
type SensorStatusResponse struct {
@ -72,8 +72,8 @@ type SensorStatusResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
SensorStatus []*SensorStatus `protobuf:"bytes,2,rep,name=sensorStatus,proto3" json:"sensorStatus,omitempty"`
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Sensors []*SensorStatus `protobuf:"bytes,2,rep,name=sensors,proto3" json:"sensors,omitempty"`
}
func (x *SensorStatusResponse) Reset() {
@ -108,16 +108,16 @@ func (*SensorStatusResponse) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_monitoring_proto_rawDescGZIP(), []int{1}
}
func (x *SensorStatusResponse) GetId() string {
func (x *SensorStatusResponse) GetId() uint32 {
if x != nil {
return x.Id
}
return ""
return 0
}
func (x *SensorStatusResponse) GetSensorStatus() []*SensorStatus {
func (x *SensorStatusResponse) GetSensors() []*SensorStatus {
if x != nil {
return x.SensorStatus
return x.Sensors
}
return nil
}
@ -192,26 +192,25 @@ var file_internal_pkg_grpc_monitoring_proto_rawDesc = []byte{
0x72, 0x70, 0x63, 0x2f, 0x6d, 0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x67, 0x72, 0x70, 0x63, 0x22, 0x25, 0x0a, 0x13, 0x53, 0x65,
0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69,
0x64, 0x22, 0x5e, 0x0a, 0x14, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75,
0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69,
0x64, 0x22, 0x54, 0x0a, 0x14, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75,
0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x36, 0x0a, 0x0c, 0x73, 0x65, 0x6e,
0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x12, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61,
0x74, 0x75, 0x73, 0x52, 0x0c, 0x73, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75,
0x73, 0x22, 0x4e, 0x0a, 0x0c, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75,
0x73, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61,
0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75,
0x73, 0x32, 0x5a, 0x0a, 0x0a, 0x6d, 0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x6e, 0x67, 0x12,
0x4c, 0x0a, 0x13, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x48,
0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x19, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x65,
0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x1a, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53,
0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x13, 0x5a,
0x11, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x67, 0x72,
0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x2c, 0x0a, 0x07, 0x73, 0x65, 0x6e,
0x73, 0x6f, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x67, 0x72, 0x70,
0x63, 0x2e, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x07,
0x73, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x73, 0x22, 0x4e, 0x0a, 0x0c, 0x53, 0x65, 0x6e, 0x73, 0x6f,
0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x74,
0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12,
0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52,
0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x32, 0x5a, 0x0a, 0x0a, 0x6d, 0x6f, 0x6e, 0x69, 0x74,
0x6f, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x4c, 0x0a, 0x13, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53,
0x74, 0x61, 0x74, 0x75, 0x73, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x19, 0x2e, 0x67,
0x72, 0x70, 0x63, 0x2e, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x53,
0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x42, 0x13, 0x5a, 0x11, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f,
0x70, 0x6b, 0x67, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -233,7 +232,7 @@ var file_internal_pkg_grpc_monitoring_proto_goTypes = []interface{}{
(*SensorStatus)(nil), // 2: grpc.SensorStatus
}
var file_internal_pkg_grpc_monitoring_proto_depIdxs = []int32{
2, // 0: grpc.SensorStatusResponse.sensorStatus:type_name -> grpc.SensorStatus
2, // 0: grpc.SensorStatusResponse.sensors:type_name -> grpc.SensorStatus
0, // 1: grpc.monitoring.SensorStatusHandler:input_type -> grpc.SensorStatusRequest
1, // 2: grpc.monitoring.SensorStatusHandler:output_type -> grpc.SensorStatusResponse
2, // [2:3] is the sub-list for method output_type

@ -8,12 +8,12 @@ service monitoring {
}
message SensorStatusRequest {
string id = 1;
uint32 id = 1;
}
message SensorStatusResponse {
string id = 1;
repeated SensorStatus sensorStatus = 2;
uint32 id = 1;
repeated SensorStatus sensors = 2;
}
message SensorStatus {

@ -0,0 +1,243 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.6.1
// source: internal/pkg/grpc/server.proto
package grpc
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type ReactorDiscoveryRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id uint32 `protobuf:"varint,1,opt,name=Id,proto3" json:"Id,omitempty"`
Ip string `protobuf:"bytes,2,opt,name=Ip,proto3" json:"Ip,omitempty"`
Port int32 `protobuf:"varint,3,opt,name=Port,proto3" json:"Port,omitempty"`
Model string `protobuf:"bytes,4,opt,name=Model,proto3" json:"Model,omitempty"`
}
func (x *ReactorDiscoveryRequest) Reset() {
*x = ReactorDiscoveryRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_pkg_grpc_server_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ReactorDiscoveryRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ReactorDiscoveryRequest) ProtoMessage() {}
func (x *ReactorDiscoveryRequest) ProtoReflect() protoreflect.Message {
mi := &file_internal_pkg_grpc_server_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ReactorDiscoveryRequest.ProtoReflect.Descriptor instead.
func (*ReactorDiscoveryRequest) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_server_proto_rawDescGZIP(), []int{0}
}
func (x *ReactorDiscoveryRequest) GetId() uint32 {
if x != nil {
return x.Id
}
return 0
}
func (x *ReactorDiscoveryRequest) GetIp() string {
if x != nil {
return x.Ip
}
return ""
}
func (x *ReactorDiscoveryRequest) GetPort() int32 {
if x != nil {
return x.Port
}
return 0
}
func (x *ReactorDiscoveryRequest) GetModel() string {
if x != nil {
return x.Model
}
return ""
}
type ReactorDiscoveryResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Success bool `protobuf:"varint,1,opt,name=Success,proto3" json:"Success,omitempty"`
}
func (x *ReactorDiscoveryResponse) Reset() {
*x = ReactorDiscoveryResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_pkg_grpc_server_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ReactorDiscoveryResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ReactorDiscoveryResponse) ProtoMessage() {}
func (x *ReactorDiscoveryResponse) ProtoReflect() protoreflect.Message {
mi := &file_internal_pkg_grpc_server_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ReactorDiscoveryResponse.ProtoReflect.Descriptor instead.
func (*ReactorDiscoveryResponse) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_server_proto_rawDescGZIP(), []int{1}
}
func (x *ReactorDiscoveryResponse) GetSuccess() bool {
if x != nil {
return x.Success
}
return false
}
var File_internal_pkg_grpc_server_proto protoreflect.FileDescriptor
var file_internal_pkg_grpc_server_proto_rawDesc = []byte{
0x0a, 0x1e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x67,
0x72, 0x70, 0x63, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x12, 0x04, 0x67, 0x72, 0x70, 0x63, 0x22, 0x63, 0x0a, 0x17, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f,
0x72, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x49,
0x64, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49,
0x70, 0x12, 0x12, 0x0a, 0x04, 0x50, 0x6f, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52,
0x04, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x18, 0x04,
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x22, 0x34, 0x0a, 0x18, 0x52,
0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65,
0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73,
0x73, 0x32, 0x65, 0x0a, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x12, 0x58,
0x0a, 0x17, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65,
0x72, 0x79, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x1d, 0x2e, 0x67, 0x72, 0x70, 0x63,
0x2e, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72,
0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e,
0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x13, 0x5a, 0x11, 0x69, 0x6e, 0x74, 0x65,
0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_internal_pkg_grpc_server_proto_rawDescOnce sync.Once
file_internal_pkg_grpc_server_proto_rawDescData = file_internal_pkg_grpc_server_proto_rawDesc
)
func file_internal_pkg_grpc_server_proto_rawDescGZIP() []byte {
file_internal_pkg_grpc_server_proto_rawDescOnce.Do(func() {
file_internal_pkg_grpc_server_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_pkg_grpc_server_proto_rawDescData)
})
return file_internal_pkg_grpc_server_proto_rawDescData
}
var file_internal_pkg_grpc_server_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_internal_pkg_grpc_server_proto_goTypes = []interface{}{
(*ReactorDiscoveryRequest)(nil), // 0: grpc.ReactorDiscoveryRequest
(*ReactorDiscoveryResponse)(nil), // 1: grpc.ReactorDiscoveryResponse
}
var file_internal_pkg_grpc_server_proto_depIdxs = []int32{
0, // 0: grpc.handshake.ReactorDiscoveryHandler:input_type -> grpc.ReactorDiscoveryRequest
1, // 1: grpc.handshake.ReactorDiscoveryHandler:output_type -> grpc.ReactorDiscoveryResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_internal_pkg_grpc_server_proto_init() }
func file_internal_pkg_grpc_server_proto_init() {
if File_internal_pkg_grpc_server_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_internal_pkg_grpc_server_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ReactorDiscoveryRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_internal_pkg_grpc_server_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ReactorDiscoveryResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_internal_pkg_grpc_server_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_internal_pkg_grpc_server_proto_goTypes,
DependencyIndexes: file_internal_pkg_grpc_server_proto_depIdxs,
MessageInfos: file_internal_pkg_grpc_server_proto_msgTypes,
}.Build()
File_internal_pkg_grpc_server_proto = out.File
file_internal_pkg_grpc_server_proto_rawDesc = nil
file_internal_pkg_grpc_server_proto_goTypes = nil
file_internal_pkg_grpc_server_proto_depIdxs = nil
}

@ -3,17 +3,17 @@ package grpc;
option go_package = "internal/pkg/grpc";
service discovery {
rpc ReactorDiscoveryHandler(ReactorInfoRequest) returns (SuccessResponse);
service handshake {
rpc ReactorDiscoveryHandler(ReactorDiscoveryRequest) returns (ReactorDiscoveryResponse);
}
message ReactorInfoRequest {
string Id = 1;
uint32 Ip = 2;
message ReactorDiscoveryRequest {
uint32 Id = 1;
string Ip = 2;
int32 Port = 3;
string Model = 4;
}
message ServerResponse {
string Id = 1;
bool Success = 2;
message ReactorDiscoveryResponse {
bool Success = 1;
}

@ -0,0 +1,105 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.6.1
// source: internal/pkg/grpc/server.proto
package grpc
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// HandshakeClient is the client API for Handshake service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type HandshakeClient interface {
ReactorDiscoveryHandler(ctx context.Context, in *ReactorDiscoveryRequest, opts ...grpc.CallOption) (*ReactorDiscoveryResponse, error)
}
type handshakeClient struct {
cc grpc.ClientConnInterface
}
func NewHandshakeClient(cc grpc.ClientConnInterface) HandshakeClient {
return &handshakeClient{cc}
}
func (c *handshakeClient) ReactorDiscoveryHandler(ctx context.Context, in *ReactorDiscoveryRequest, opts ...grpc.CallOption) (*ReactorDiscoveryResponse, error) {
out := new(ReactorDiscoveryResponse)
err := c.cc.Invoke(ctx, "/grpc.handshake/ReactorDiscoveryHandler", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// HandshakeServer is the server API for Handshake service.
// All implementations must embed UnimplementedHandshakeServer
// for forward compatibility
type HandshakeServer interface {
ReactorDiscoveryHandler(context.Context, *ReactorDiscoveryRequest) (*ReactorDiscoveryResponse, error)
mustEmbedUnimplementedHandshakeServer()
}
// UnimplementedHandshakeServer must be embedded to have forward compatible implementations.
type UnimplementedHandshakeServer struct {
}
func (UnimplementedHandshakeServer) ReactorDiscoveryHandler(context.Context, *ReactorDiscoveryRequest) (*ReactorDiscoveryResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ReactorDiscoveryHandler not implemented")
}
func (UnimplementedHandshakeServer) mustEmbedUnimplementedHandshakeServer() {}
// UnsafeHandshakeServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to HandshakeServer will
// result in compilation errors.
type UnsafeHandshakeServer interface {
mustEmbedUnimplementedHandshakeServer()
}
func RegisterHandshakeServer(s grpc.ServiceRegistrar, srv HandshakeServer) {
s.RegisterService(&Handshake_ServiceDesc, srv)
}
func _Handshake_ReactorDiscoveryHandler_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReactorDiscoveryRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HandshakeServer).ReactorDiscoveryHandler(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpc.handshake/ReactorDiscoveryHandler",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HandshakeServer).ReactorDiscoveryHandler(ctx, req.(*ReactorDiscoveryRequest))
}
return interceptor(ctx, in, info, handler)
}
// Handshake_ServiceDesc is the grpc.ServiceDesc for Handshake service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Handshake_ServiceDesc = grpc.ServiceDesc{
ServiceName: "grpc.handshake",
HandlerType: (*HandshakeServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "ReactorDiscoveryHandler",
Handler: _Handshake_ReactorDiscoveryHandler_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "internal/pkg/grpc/server.proto",
}

@ -4,14 +4,24 @@ package reactor
import (
"fmt"
"sync"
"net"
"FRMS/internal/pkg/system"
"FRMS/internal/pkg/I2C"
"FRMS/internal/pkg/sensor"
"errors"
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "FRMS/internal/pkg/grpc"
)
type Hardware interface {
GetIp() string
GetId() uint32
GetBus() int
GetModel() string
GetPort() int
}
type I2CMonitor interface {
@ -22,24 +32,30 @@ 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
Sensors map[int]SensorManager
Err chan error
mu sync.Mutex
pb.UnimplementedMonitoringServer
}
//type SensorManager interface {
// Start()
//}
type SensorManager interface {
Start()
GetStatus() bool
GetType() string
}
func NewSensorManager(addr int) SensorManager {
return sensor.NewSensorManager(addr)
}
func NewCoordinator(s string) *Coordinator {
return &Coordinator{Server:s}
func NewCoordinator(s string,ch chan error) *Coordinator {
return &Coordinator{Server:s,Err:ch}
}
func NewI2CMonitor(b int) I2CMonitor {
return I2C.NewMonitor(b)
}
//func NewSensorManager() SensorManager {
//return sensor.NewManager()
//}
func NewHWMonitor() Hardware {
return system.NewHWMonitor()
}
@ -51,25 +67,67 @@ func (c *Coordinator) Start() error {
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.Register()
c.mu.Lock() // lock to finish setting up devices
defer c.mu.Unlock()
c.I2C = NewI2CMonitor(c.HW.GetBus())
devs := c.I2C.Connected()
c.Sensors = make(map[int]SensorManager)
for _,d := range devs {
// create a goroutine for each active sensor
//sm := NewSensorManager(d)
//go sm.Start()
sm := NewSensorManager(d)
c.Sensors[d] = sm
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
var opts []grpc.DialOption
opts = append(opts,grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.Dial(c.Server,opts...)
if err != nil {
return err
}
defer conn.Close()
client := pb.NewHandshakeClient(conn)
req := &pb.ReactorDiscoveryRequest{Id:c.HW.GetId(),Ip:c.HW.GetIp(),Port:int32(2000),Model:c.HW.GetModel()}
resp, err := client.ReactorDiscoveryHandler(context.Background(), req)
if err != nil {
return err
}
if resp.GetSuccess() {
fmt.Println("Central server reached")
return nil
} else {
return errors.New("Failed to reach central server!")
}
}
func (c *Coordinator) Register() error {
fmt.Printf("Listing for pings on %v:%v\n",c.HW.GetIp(),c.HW.GetPort())
lis, err := net.Listen("tcp", fmt.Sprintf("%v:%v",c.HW.GetIp(),c.HW.GetPort()))
if err != nil {
return err
}
grpcServer := grpc.NewServer()
pb.RegisterMonitoringServer(grpcServer, c)
go grpcServer.Serve(lis)
return nil
}
func (c *Coordinator) SensorStatusHandler(ctx context.Context, ping *pb.SensorStatusRequest) (*pb.SensorStatusResponse,error) {
c.mu.Lock()
defer c.mu.Unlock()
var sensors []*pb.SensorStatus
resp := &pb.SensorStatusResponse{Id:c.HW.GetId(),Sensors:sensors}
for a, s := range c.Sensors {
resp.Sensors = append(resp.Sensors,&pb.SensorStatus{Addr:int32(a), Type:s.GetType(), Status:s.GetStatus()})
}
return resp, nil
}

@ -1,9 +1,42 @@
package sensor
import (
"sync"
)
type Manager struct {
Addr int
Type string
Status bool
//I2C I2CMonitor
mu sync.Mutex
}
//type I2CMonitor interface {
//}
func (m *Manager) GetStatus() bool{
m.mu.Lock()
defer m.mu.Unlock()
return m.Status
}
func (m *Manager) GetType() string{
m.mu.Lock()
defer m.mu.Unlock()
return m.Type
}
func NewSensorManager(addr int) *Manager {
return &Manager{Addr:addr}
}
func (m *Manager) Start() {
types := map[int]string{97:"DO Sensor",99:"pH Sensor",102:"RTD Sensor"}
m.Type = types[m.Addr]
m.Status = true
}

@ -2,8 +2,77 @@ package server
import (
"fmt"
"sync"
"net"
"context"
"google.golang.org/grpc"
pb "FRMS/internal/pkg/grpc"
)
// 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
type ReactorListener struct { // exporting for easy use in the short term
Reactor map[uint32]*ReactorCoordinator
Ip string
Port int
Err chan error
mu sync.Mutex
pb.UnimplementedHandshakeServer
}
func NewReactorListener(ch chan error) *ReactorListener {
m := make(map[uint32]*ReactorCoordinator)
ip := "192.1.168.136"
port := 2000
return &ReactorListener{Err:ch, Reactor:m, Port:port, Ip:ip}
}
func (r *ReactorListener) GetIp() string {
r.mu.Lock()
defer r.mu.Unlock()
return r.Ip
}
func (r *ReactorListener) GetPort() int {
r.mu.Lock()
defer r.mu.Unlock()
return r.Port
}
func (r *ReactorListener) Start() {
// start grpc server and implement reciever
err := r.Register()
if err != nil {
r.Err <- err
}
// reactor listener started and grpc library will execute listener
fmt.Printf("Started listener on %v:%v\n",r.Ip,r.Port)
}
func (r *ReactorListener) Register() error {
// creates a gRPC service and binds it to our handler
lis, err := net.Listen("tcp", fmt.Sprintf("%v:%v",r.Ip,r.Port))
if err != nil {
return err
}
grpcServer := grpc.NewServer()
pb.RegisterHandshakeServer(grpcServer, r)
go grpcServer.Serve(lis)
return nil
}
func (r *ReactorListener) ReactorDiscoveryHandler(ctx context.Context, ping *pb.ReactorDiscoveryRequest) (*pb.ReactorDiscoveryResponse, error) {
// incoming reactor ping need to spawn coord
r.mu.Lock()
rc, ok := r.Reactor[ping.GetId()]
fmt.Printf("Reactor %v has connected from addr %v and provided port %v\n",ping.GetId(),ping.GetIp(),ping.GetPort())
// if reactor exists
if ok {
go rc.Start()
} else {
rc := NewReactorCoordinator(r,ping.GetIp(),ping.GetModel(),int(ping.GetPort()),ping.GetId())
go rc.Start()
r.Reactor[ping.GetId()] = rc
}
return &pb.ReactorDiscoveryResponse{Success:true}, nil
}

@ -2,6 +2,71 @@ package server
import (
"fmt"
"time"
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "FRMS/internal/pkg/grpc"
)
// this package will implement a reactor coordinator and associated go routines
type ReactorCoordinator struct {
Server *ReactorListener // embedding parent listener to call methods
Ip string
Port int
Id uint32
Model string
MaxAttempts int
}
func NewReactorCoordinator(s *ReactorListener, ip, model string, port int, id uint32) *ReactorCoordinator {
return &ReactorCoordinator{Server: s, Ip: ip, Port: port, Id: id, Model: model,MaxAttempts:3}
}
func(r *ReactorCoordinator) Start() {
// establish connection with reactor and start pinging at set intervals
var opts []grpc.DialOption
opts = append(opts,grpc.WithTransportCredentials(insecure.NewCredentials()))
go r.Monitor(opts)
}
func (r *ReactorCoordinator) Exit() {
// exit function to eventually allow saving to configs
fmt.Printf("Reactor %v exiting", r.Id)
}
func (r *ReactorCoordinator) Monitor(opts []grpc.DialOption) {
retry := 0
conn, err := grpc.Dial(fmt.Sprintf("%v:%v",r.Ip,r.Port),opts...)
if err != nil {
r.Server.Err <-err
}
defer conn.Close()
client := pb.NewMonitoringClient(conn)
for true {
req := &pb.SensorStatusRequest{Id:r.Id}
//time.Sleep(5*time.Second)
resp, err := client.SensorStatusHandler(context.Background(),req)
fmt.Println(resp,err)
ok := true
if err != nil {
ok = false
r.Server.Err <-err
}
if ok {
fmt.Printf("Reactor %v at %v has %v devices connected:\n %v\n",r.Model, r.Ip, len(resp.GetSensors()), resp.GetSensors())
retry = 0
} else if retry >= r.MaxAttempts {
// ran out of attempts to connect; killing
fmt.Printf("Reactor %v at %v Down! Exiting Coordinator",r.Id,r.Ip)
r.Exit()
return
}else {
retry++
fmt.Printf("Reactor %v at %v ping failed, retrying %v time(s)",r.Model,r.Ip, r.MaxAttempts-retry)
}
time.Sleep(10 * time.Second)
}
}

@ -26,11 +26,13 @@ type HWMonitor struct {
Ip string
Id uint32
Bus int
Model string
Port int
mu sync.Mutex
}
func NewHWMonitor() *HWMonitor {
h := &HWMonitor{}
h := &HWMonitor{Port:2000}
err := h.Start()
if err != nil {
fmt.Println("hw setup failed " + fmt.Sprint(err))
@ -38,6 +40,12 @@ func NewHWMonitor() *HWMonitor {
return h
}
func (h *HWMonitor) GetPort() int {
h.mu.Lock()
defer h.mu.Unlock()
return h.Port
}
func (h *HWMonitor) GetIp() string {
h.mu.Lock()
defer h.mu.Unlock()
@ -56,6 +64,12 @@ func (h *HWMonitor) GetBus() int {
return h.Bus
}
func (h *HWMonitor) GetModel() string{
h.mu.Lock()
defer h.mu.Unlock()
return h.Model
}
func (h *HWMonitor) Start() error {
// responsible for filling out struct
h.mu.Lock()
@ -90,6 +104,7 @@ func (h *HWMonitor) Start() error {
b := res[2].String()
b = strings.Trim(b," \n")
h.Model = b
h.Bus = bus[b]
return nil
}

24
notes

@ -52,4 +52,28 @@ message Sensor {
sensors := [string]q
6/23 TODO:
X- BBB mem fix
- 32 gig for the main but where to put the OS?
- obv in EMMC but how to init sd card? (probably dev tree :( )
Y- Server side impl
Y - Need a struct for the RC
X - Should we store and load configs based on IDs? (efficiency of this vs performance increases i.e. bandwidth vs storage)
Y/X - Who should kill the RC and how do we know its dead? (Garbage collection to the rescue hopefully)
X- UPDATE PRES
- Add bottle necks for each part in that section
- I2C: 128 addrs and ~90 bytes/s per device at 128 devs optimally
- BB: Hardware is upgradeable even customizable ;)
- Server: Its overkill as is, can benchmark with a rudementary go overload once its completed
- Sensor configs
- how to store sensor info efficiently and searchably lol
- who needs to know what the sensor is? (Just the SM? Even the SM?)
X- TUI
- pls this would be so sick
TODO: 6-24
Y - Pres stuff from yesterday + python gRPC abstraction
Y - RPI flash
- Add resiliance to coordinator process (aka error handley blech)

Loading…
Cancel
Save