added more standard server structs, in process of making system only send new info

main
KeeganForelight 2 years ago
parent 12cd29ba18
commit 5cd34e89b6

@ -8,14 +8,12 @@ import (
"FRMS/internal/pkg/server"
)
type reactorListener interface {
type listener interface {
Start()
GetIp() string
GetPort() int
}
func NewReactorListener(s string,ch chan error) (reactorListener, error) {
return server.NewReactorListener(s, ch)
func NewListener(s string,ch chan error) (listener, error) {
return server.NewListener(s, ch)
}
func main() {
@ -32,11 +30,11 @@ func main() {
}
ifconfig := string(flag.Arg(0))
ch := make(chan error)
rl, err := NewReactorListener(ifconfig,ch)
l, err := NewListener(ifconfig,ch)
if err != nil {
log.Fatal(err)
}
go rl.Start()
go l.Start()
err = <-ch // blocking to wait for any errors and keep alive otherwise
if err != nil {
//fmt.Printf("ERROR: %v\n",err)

Binary file not shown.

@ -20,7 +20,7 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type SensorStatusRequest struct {
type ReactorStatusRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -28,8 +28,8 @@ type SensorStatusRequest struct {
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *SensorStatusRequest) Reset() {
*x = SensorStatusRequest{}
func (x *ReactorStatusRequest) Reset() {
*x = ReactorStatusRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_pkg_grpc_monitoring_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -37,13 +37,13 @@ func (x *SensorStatusRequest) Reset() {
}
}
func (x *SensorStatusRequest) String() string {
func (x *ReactorStatusRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SensorStatusRequest) ProtoMessage() {}
func (*ReactorStatusRequest) ProtoMessage() {}
func (x *SensorStatusRequest) ProtoReflect() protoreflect.Message {
func (x *ReactorStatusRequest) ProtoReflect() protoreflect.Message {
mi := &file_internal_pkg_grpc_monitoring_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -55,29 +55,29 @@ func (x *SensorStatusRequest) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use SensorStatusRequest.ProtoReflect.Descriptor instead.
func (*SensorStatusRequest) Descriptor() ([]byte, []int) {
// Deprecated: Use ReactorStatusRequest.ProtoReflect.Descriptor instead.
func (*ReactorStatusRequest) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_monitoring_proto_rawDescGZIP(), []int{0}
}
func (x *SensorStatusRequest) GetId() uint32 {
func (x *ReactorStatusRequest) GetId() uint32 {
if x != nil {
return x.Id
}
return 0
}
type SensorStatusResponse struct {
type ReactorStatusResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Sensors []*SensorStatus `protobuf:"bytes,2,rep,name=sensors,proto3" json:"sensors,omitempty"`
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Devices []*Device `protobuf:"bytes,2,rep,name=devices,proto3" json:"devices,omitempty"`
}
func (x *SensorStatusResponse) Reset() {
*x = SensorStatusResponse{}
func (x *ReactorStatusResponse) Reset() {
*x = ReactorStatusResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_pkg_grpc_monitoring_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -85,13 +85,13 @@ func (x *SensorStatusResponse) Reset() {
}
}
func (x *SensorStatusResponse) String() string {
func (x *ReactorStatusResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SensorStatusResponse) ProtoMessage() {}
func (*ReactorStatusResponse) ProtoMessage() {}
func (x *SensorStatusResponse) ProtoReflect() protoreflect.Message {
func (x *ReactorStatusResponse) ProtoReflect() protoreflect.Message {
mi := &file_internal_pkg_grpc_monitoring_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -103,26 +103,26 @@ func (x *SensorStatusResponse) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use SensorStatusResponse.ProtoReflect.Descriptor instead.
func (*SensorStatusResponse) Descriptor() ([]byte, []int) {
// Deprecated: Use ReactorStatusResponse.ProtoReflect.Descriptor instead.
func (*ReactorStatusResponse) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_monitoring_proto_rawDescGZIP(), []int{1}
}
func (x *SensorStatusResponse) GetId() uint32 {
func (x *ReactorStatusResponse) GetId() uint32 {
if x != nil {
return x.Id
}
return 0
}
func (x *SensorStatusResponse) GetSensors() []*SensorStatus {
func (x *ReactorStatusResponse) GetDevices() []*Device {
if x != nil {
return x.Sensors
return x.Devices
}
return nil
}
type SensorStatus struct {
type Device struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -132,8 +132,8 @@ type SensorStatus struct {
Status string `protobuf:"bytes,3,opt,name=status,proto3" json:"status,omitempty"`
}
func (x *SensorStatus) Reset() {
*x = SensorStatus{}
func (x *Device) Reset() {
*x = Device{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_pkg_grpc_monitoring_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -141,13 +141,13 @@ func (x *SensorStatus) Reset() {
}
}
func (x *SensorStatus) String() string {
func (x *Device) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SensorStatus) ProtoMessage() {}
func (*Device) ProtoMessage() {}
func (x *SensorStatus) ProtoReflect() protoreflect.Message {
func (x *Device) ProtoReflect() protoreflect.Message {
mi := &file_internal_pkg_grpc_monitoring_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -159,26 +159,26 @@ func (x *SensorStatus) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use SensorStatus.ProtoReflect.Descriptor instead.
func (*SensorStatus) Descriptor() ([]byte, []int) {
// Deprecated: Use Device.ProtoReflect.Descriptor instead.
func (*Device) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_monitoring_proto_rawDescGZIP(), []int{2}
}
func (x *SensorStatus) GetAddr() int32 {
func (x *Device) GetAddr() int32 {
if x != nil {
return x.Addr
}
return 0
}
func (x *SensorStatus) GetType() string {
func (x *Device) GetType() string {
if x != nil {
return x.Type
}
return ""
}
func (x *SensorStatus) GetStatus() string {
func (x *Device) GetStatus() string {
if x != nil {
return x.Status
}
@ -190,27 +190,27 @@ var File_internal_pkg_grpc_monitoring_proto protoreflect.FileDescriptor
var file_internal_pkg_grpc_monitoring_proto_rawDesc = []byte{
0x0a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x67,
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, 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, 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, 0x09, 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,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x67, 0x72, 0x70, 0x63, 0x22, 0x26, 0x0a, 0x14, 0x52, 0x65,
0x61, 0x63, 0x74, 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, 0x0d, 0x52, 0x02,
0x69, 0x64, 0x22, 0x4f, 0x0a, 0x15, 0x52, 0x65, 0x61, 0x63, 0x74, 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, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x26, 0x0a, 0x07, 0x64,
0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x67,
0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x52, 0x07, 0x64, 0x65, 0x76, 0x69,
0x63, 0x65, 0x73, 0x22, 0x48, 0x0a, 0x06, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 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, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x32, 0x5d, 0x0a,
0x0a, 0x6d, 0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x4f, 0x0a, 0x14, 0x52,
0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x48, 0x61, 0x6e, 0x64,
0x6c, 0x65, 0x72, 0x12, 0x1a, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x65, 0x61, 0x63, 0x74,
0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1b, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x65, 0x61, 0x63, 0x74, 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 (
@ -227,14 +227,14 @@ func file_internal_pkg_grpc_monitoring_proto_rawDescGZIP() []byte {
var file_internal_pkg_grpc_monitoring_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_internal_pkg_grpc_monitoring_proto_goTypes = []interface{}{
(*SensorStatusRequest)(nil), // 0: grpc.SensorStatusRequest
(*SensorStatusResponse)(nil), // 1: grpc.SensorStatusResponse
(*SensorStatus)(nil), // 2: grpc.SensorStatus
(*ReactorStatusRequest)(nil), // 0: grpc.ReactorStatusRequest
(*ReactorStatusResponse)(nil), // 1: grpc.ReactorStatusResponse
(*Device)(nil), // 2: grpc.Device
}
var file_internal_pkg_grpc_monitoring_proto_depIdxs = []int32{
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, // 0: grpc.ReactorStatusResponse.devices:type_name -> grpc.Device
0, // 1: grpc.monitoring.ReactorStatusHandler:input_type -> grpc.ReactorStatusRequest
1, // 2: grpc.monitoring.ReactorStatusHandler:output_type -> grpc.ReactorStatusResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
@ -249,7 +249,7 @@ func file_internal_pkg_grpc_monitoring_proto_init() {
}
if !protoimpl.UnsafeEnabled {
file_internal_pkg_grpc_monitoring_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SensorStatusRequest); i {
switch v := v.(*ReactorStatusRequest); i {
case 0:
return &v.state
case 1:
@ -261,7 +261,7 @@ func file_internal_pkg_grpc_monitoring_proto_init() {
}
}
file_internal_pkg_grpc_monitoring_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SensorStatusResponse); i {
switch v := v.(*ReactorStatusResponse); i {
case 0:
return &v.state
case 1:
@ -273,7 +273,7 @@ func file_internal_pkg_grpc_monitoring_proto_init() {
}
}
file_internal_pkg_grpc_monitoring_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SensorStatus); i {
switch v := v.(*Device); i {
case 0:
return &v.state
case 1:

@ -4,19 +4,19 @@ package grpc;
option go_package = "internal/pkg/grpc";
service monitoring {
rpc SensorStatusHandler(SensorStatusRequest) returns (SensorStatusResponse);
rpc ReactorStatusHandler(ReactorStatusRequest) returns (ReactorStatusResponse);
}
message SensorStatusRequest {
message ReactorStatusRequest {
uint32 id = 1;
}
message SensorStatusResponse {
message ReactorStatusResponse {
uint32 id = 1;
repeated SensorStatus sensors = 2;
repeated Device devices = 2;
}
message SensorStatus {
message Device {
int32 addr = 1;
string type = 2;
string status = 3;

@ -22,7 +22,7 @@ const _ = grpc.SupportPackageIsVersion7
//
// 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 MonitoringClient interface {
SensorStatusHandler(ctx context.Context, in *SensorStatusRequest, opts ...grpc.CallOption) (*SensorStatusResponse, error)
ReactorStatusHandler(ctx context.Context, in *ReactorStatusRequest, opts ...grpc.CallOption) (*ReactorStatusResponse, error)
}
type monitoringClient struct {
@ -33,9 +33,9 @@ func NewMonitoringClient(cc grpc.ClientConnInterface) MonitoringClient {
return &monitoringClient{cc}
}
func (c *monitoringClient) SensorStatusHandler(ctx context.Context, in *SensorStatusRequest, opts ...grpc.CallOption) (*SensorStatusResponse, error) {
out := new(SensorStatusResponse)
err := c.cc.Invoke(ctx, "/grpc.monitoring/SensorStatusHandler", in, out, opts...)
func (c *monitoringClient) ReactorStatusHandler(ctx context.Context, in *ReactorStatusRequest, opts ...grpc.CallOption) (*ReactorStatusResponse, error) {
out := new(ReactorStatusResponse)
err := c.cc.Invoke(ctx, "/grpc.monitoring/ReactorStatusHandler", in, out, opts...)
if err != nil {
return nil, err
}
@ -46,7 +46,7 @@ func (c *monitoringClient) SensorStatusHandler(ctx context.Context, in *SensorSt
// All implementations must embed UnimplementedMonitoringServer
// for forward compatibility
type MonitoringServer interface {
SensorStatusHandler(context.Context, *SensorStatusRequest) (*SensorStatusResponse, error)
ReactorStatusHandler(context.Context, *ReactorStatusRequest) (*ReactorStatusResponse, error)
mustEmbedUnimplementedMonitoringServer()
}
@ -54,8 +54,8 @@ type MonitoringServer interface {
type UnimplementedMonitoringServer struct {
}
func (UnimplementedMonitoringServer) SensorStatusHandler(context.Context, *SensorStatusRequest) (*SensorStatusResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SensorStatusHandler not implemented")
func (UnimplementedMonitoringServer) ReactorStatusHandler(context.Context, *ReactorStatusRequest) (*ReactorStatusResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ReactorStatusHandler not implemented")
}
func (UnimplementedMonitoringServer) mustEmbedUnimplementedMonitoringServer() {}
@ -70,20 +70,20 @@ func RegisterMonitoringServer(s grpc.ServiceRegistrar, srv MonitoringServer) {
s.RegisterService(&Monitoring_ServiceDesc, srv)
}
func _Monitoring_SensorStatusHandler_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SensorStatusRequest)
func _Monitoring_ReactorStatusHandler_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReactorStatusRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MonitoringServer).SensorStatusHandler(ctx, in)
return srv.(MonitoringServer).ReactorStatusHandler(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpc.monitoring/SensorStatusHandler",
FullMethod: "/grpc.monitoring/ReactorStatusHandler",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MonitoringServer).SensorStatusHandler(ctx, req.(*SensorStatusRequest))
return srv.(MonitoringServer).ReactorStatusHandler(ctx, req.(*ReactorStatusRequest))
}
return interceptor(ctx, in, info, handler)
}
@ -96,8 +96,8 @@ var Monitoring_ServiceDesc = grpc.ServiceDesc{
HandlerType: (*MonitoringServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "SensorStatusHandler",
Handler: _Monitoring_SensorStatusHandler_Handler,
MethodName: "ReactorStatusHandler",
Handler: _Monitoring_ReactorStatusHandler_Handler,
},
},
Streams: []grpc.StreamDesc{},

@ -20,19 +20,20 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type ReactorDiscoveryRequest struct {
type ClientDiscoveryRequest 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"`
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"`
ClientType string `protobuf:"bytes,5,opt,name=ClientType,proto3" json:"ClientType,omitempty"`
}
func (x *ReactorDiscoveryRequest) Reset() {
*x = ReactorDiscoveryRequest{}
func (x *ClientDiscoveryRequest) Reset() {
*x = ClientDiscoveryRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_pkg_grpc_server_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -40,13 +41,13 @@ func (x *ReactorDiscoveryRequest) Reset() {
}
}
func (x *ReactorDiscoveryRequest) String() string {
func (x *ClientDiscoveryRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ReactorDiscoveryRequest) ProtoMessage() {}
func (*ClientDiscoveryRequest) ProtoMessage() {}
func (x *ReactorDiscoveryRequest) ProtoReflect() protoreflect.Message {
func (x *ClientDiscoveryRequest) ProtoReflect() protoreflect.Message {
mi := &file_internal_pkg_grpc_server_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -58,40 +59,47 @@ func (x *ReactorDiscoveryRequest) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use ReactorDiscoveryRequest.ProtoReflect.Descriptor instead.
func (*ReactorDiscoveryRequest) Descriptor() ([]byte, []int) {
// Deprecated: Use ClientDiscoveryRequest.ProtoReflect.Descriptor instead.
func (*ClientDiscoveryRequest) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_server_proto_rawDescGZIP(), []int{0}
}
func (x *ReactorDiscoveryRequest) GetId() uint32 {
func (x *ClientDiscoveryRequest) GetId() uint32 {
if x != nil {
return x.Id
}
return 0
}
func (x *ReactorDiscoveryRequest) GetIp() string {
func (x *ClientDiscoveryRequest) GetIp() string {
if x != nil {
return x.Ip
}
return ""
}
func (x *ReactorDiscoveryRequest) GetPort() int32 {
func (x *ClientDiscoveryRequest) GetPort() int32 {
if x != nil {
return x.Port
}
return 0
}
func (x *ReactorDiscoveryRequest) GetModel() string {
func (x *ClientDiscoveryRequest) GetModel() string {
if x != nil {
return x.Model
}
return ""
}
type ReactorDiscoveryResponse struct {
func (x *ClientDiscoveryRequest) GetClientType() string {
if x != nil {
return x.ClientType
}
return ""
}
type ClientDiscoveryResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -99,8 +107,8 @@ type ReactorDiscoveryResponse struct {
Success bool `protobuf:"varint,1,opt,name=Success,proto3" json:"Success,omitempty"`
}
func (x *ReactorDiscoveryResponse) Reset() {
*x = ReactorDiscoveryResponse{}
func (x *ClientDiscoveryResponse) Reset() {
*x = ClientDiscoveryResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_pkg_grpc_server_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -108,13 +116,13 @@ func (x *ReactorDiscoveryResponse) Reset() {
}
}
func (x *ReactorDiscoveryResponse) String() string {
func (x *ClientDiscoveryResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ReactorDiscoveryResponse) ProtoMessage() {}
func (*ClientDiscoveryResponse) ProtoMessage() {}
func (x *ReactorDiscoveryResponse) ProtoReflect() protoreflect.Message {
func (x *ClientDiscoveryResponse) ProtoReflect() protoreflect.Message {
mi := &file_internal_pkg_grpc_server_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -126,12 +134,12 @@ func (x *ReactorDiscoveryResponse) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use ReactorDiscoveryResponse.ProtoReflect.Descriptor instead.
func (*ReactorDiscoveryResponse) Descriptor() ([]byte, []int) {
// Deprecated: Use ClientDiscoveryResponse.ProtoReflect.Descriptor instead.
func (*ClientDiscoveryResponse) Descriptor() ([]byte, []int) {
return file_internal_pkg_grpc_server_proto_rawDescGZIP(), []int{1}
}
func (x *ReactorDiscoveryResponse) GetSuccess() bool {
func (x *ClientDiscoveryResponse) GetSuccess() bool {
if x != nil {
return x.Success
}
@ -143,25 +151,27 @@ 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,
0x12, 0x04, 0x67, 0x72, 0x70, 0x63, 0x22, 0x82, 0x01, 0x0a, 0x16, 0x43, 0x6c, 0x69, 0x65, 0x6e,
0x74, 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,
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x1e, 0x0a, 0x0a, 0x43,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0a, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x22, 0x33, 0x0a, 0x17, 0x43,
0x6c, 0x69, 0x65, 0x6e, 0x74, 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, 0x62, 0x0a, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x12, 0x55, 0x0a,
0x16, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79,
0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x43,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6c, 0x69,
0x65, 0x6e, 0x74, 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 (
@ -178,12 +188,12 @@ func file_internal_pkg_grpc_server_proto_rawDescGZIP() []byte {
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
(*ClientDiscoveryRequest)(nil), // 0: grpc.ClientDiscoveryRequest
(*ClientDiscoveryResponse)(nil), // 1: grpc.ClientDiscoveryResponse
}
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
0, // 0: grpc.handshake.ClientDiscoveryHandler:input_type -> grpc.ClientDiscoveryRequest
1, // 1: grpc.handshake.ClientDiscoveryHandler:output_type -> grpc.ClientDiscoveryResponse
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
@ -198,7 +208,7 @@ func file_internal_pkg_grpc_server_proto_init() {
}
if !protoimpl.UnsafeEnabled {
file_internal_pkg_grpc_server_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ReactorDiscoveryRequest); i {
switch v := v.(*ClientDiscoveryRequest); i {
case 0:
return &v.state
case 1:
@ -210,7 +220,7 @@ func file_internal_pkg_grpc_server_proto_init() {
}
}
file_internal_pkg_grpc_server_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ReactorDiscoveryResponse); i {
switch v := v.(*ClientDiscoveryResponse); i {
case 0:
return &v.state
case 1:

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

@ -22,7 +22,7 @@ const _ = grpc.SupportPackageIsVersion7
//
// 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)
ClientDiscoveryHandler(ctx context.Context, in *ClientDiscoveryRequest, opts ...grpc.CallOption) (*ClientDiscoveryResponse, error)
}
type handshakeClient struct {
@ -33,9 +33,9 @@ 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...)
func (c *handshakeClient) ClientDiscoveryHandler(ctx context.Context, in *ClientDiscoveryRequest, opts ...grpc.CallOption) (*ClientDiscoveryResponse, error) {
out := new(ClientDiscoveryResponse)
err := c.cc.Invoke(ctx, "/grpc.handshake/ClientDiscoveryHandler", in, out, opts...)
if err != nil {
return nil, err
}
@ -46,7 +46,7 @@ func (c *handshakeClient) ReactorDiscoveryHandler(ctx context.Context, in *React
// All implementations must embed UnimplementedHandshakeServer
// for forward compatibility
type HandshakeServer interface {
ReactorDiscoveryHandler(context.Context, *ReactorDiscoveryRequest) (*ReactorDiscoveryResponse, error)
ClientDiscoveryHandler(context.Context, *ClientDiscoveryRequest) (*ClientDiscoveryResponse, error)
mustEmbedUnimplementedHandshakeServer()
}
@ -54,8 +54,8 @@ type HandshakeServer interface {
type UnimplementedHandshakeServer struct {
}
func (UnimplementedHandshakeServer) ReactorDiscoveryHandler(context.Context, *ReactorDiscoveryRequest) (*ReactorDiscoveryResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ReactorDiscoveryHandler not implemented")
func (UnimplementedHandshakeServer) ClientDiscoveryHandler(context.Context, *ClientDiscoveryRequest) (*ClientDiscoveryResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ClientDiscoveryHandler not implemented")
}
func (UnimplementedHandshakeServer) mustEmbedUnimplementedHandshakeServer() {}
@ -70,20 +70,20 @@ 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)
func _Handshake_ClientDiscoveryHandler_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ClientDiscoveryRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HandshakeServer).ReactorDiscoveryHandler(ctx, in)
return srv.(HandshakeServer).ClientDiscoveryHandler(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpc.handshake/ReactorDiscoveryHandler",
FullMethod: "/grpc.handshake/ClientDiscoveryHandler",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HandshakeServer).ReactorDiscoveryHandler(ctx, req.(*ReactorDiscoveryRequest))
return srv.(HandshakeServer).ClientDiscoveryHandler(ctx, req.(*ClientDiscoveryRequest))
}
return interceptor(ctx, in, info, handler)
}
@ -96,8 +96,8 @@ var Handshake_ServiceDesc = grpc.ServiceDesc{
HandlerType: (*HandshakeServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "ReactorDiscoveryHandler",
Handler: _Handshake_ReactorDiscoveryHandler_Handler,
MethodName: "ClientDiscoveryHandler",
Handler: _Handshake_ClientDiscoveryHandler_Handler,
},
},
Streams: []grpc.StreamDesc{},

@ -6,43 +6,68 @@ import (
"fmt"
"sync"
"net"
"time"
"math"
"FRMS/internal/pkg/system"
"FRMS/internal/pkg/I2C"
"FRMS/internal/pkg/sensor"
"errors"
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
"google.golang.org/grpc/credentials/insecure"
pb "FRMS/internal/pkg/grpc"
)
type Hardware interface {
GetId() uint32
GetIp() string
GetBus() int
GetModel() string
GetPort() int
}
// Coordinator == Reactor Level Coordinator
type Coordinator struct {
ServerIp string
ServerPort int
HW Hardware
*server
*hwinfo
Connected <-chan int
I2CMonitor I2Cmonitor
Sensors *SensorManagers // struct for fine grain locking
Err chan error
mu sync.Mutex
PendingChanges pc
Active active
pb.UnimplementedMonitoringServer
}
type pc struct {
[]//some type of sensor
sync.Mutex
}
type active struct {
bool
int
sync.Mutex
}
type server struct {
// store central server endpoint
Ip string
Port int
}
type hwinfo struct {
// store reactor info
Ip string
Port int
Model string
Type string
Bus int
Id uint32
}
type SensorManagers struct {
Managers map[int]SensorManager
mu sync.Mutex
}
type SensorManager interface {
GetStatus() string
GetStatus() uint32
GetType() string
}
@ -56,15 +81,28 @@ func NewSensorManager(addr int,m I2Cmonitor) (SensorManager, error) {
}
func NewCoordinator(ip string,port int,ch chan error) *Coordinator {
serv := &server{Ip:ip,Port:port}
sen := new(SensorManagers)
sen.Managers = make(map[int]SensorManager)
return &Coordinator{ServerIp:ip,ServerPort:port,Err:ch,Sensors:sen}
c := &Coordinator{Err:ch,Sensors:sen}
c.server = serv
c.hwinfo = &hwinfo{}
c.Type = "reactor" // explicit for client stuff
return c
}
func NewI2CMonitor(c chan<- int, b int) (I2Cmonitor, error) {
return I2C.NewMonitor(c,b)
}
type Hardware interface {
GetId() uint32
GetIp() string
GetBus() int
GetModel() string
GetPort() int
}
func GetHWInfo() (Hardware, error) {
return system.NewHWinfo()
}
@ -72,20 +110,24 @@ func GetHWInfo() (Hardware, error) {
func (c *Coordinator) Start() error {
// should discover hwinfo and sensors on its own
// now setting up sensor managers
hw, err := GetHWInfo()
hw, err := GetHWInfo() // locking provided by struct is only useful on init
if err != nil {
return err
}
c.HW = hw
// setting up hw stuff
c.hwinfo.Ip = hw.GetIp() //get should prevent empty data
c.hwinfo.Port = hw.GetPort()
c.Id = hw.GetId()
c.Model = hw.GetModel()
c.Bus = hw.GetBus()
con := make(chan int)
c.Connected = con
monitor, err := NewI2CMonitor(con,c.HW.GetBus())
if err != nil {
if c.I2CMonitor, err = NewI2CMonitor(con,c.Bus); err != nil {
return err
}
c.I2CMonitor = monitor
fmt.Printf("Reactor at IP addr %v using I2C bus %v\n",c.HW.GetIp(),c.HW.GetBus())
err = c.EstablishConnection()
fmt.Printf("Reactor at IP addr %v using I2C bus %v\n",c.hwinfo.Ip,c.hwinfo.Bus)
err = c.Connect()
for err != nil {
fmt.Printf("Connection failed: %v \n Retrying!\n",err)
}
@ -98,11 +140,11 @@ func (c *Coordinator) Monitor() {
// function to automatically create and destroy sm
for {
addr := <-c.Connected
go c.Connect(addr)
go c.SensorConnect(addr)
}
}
func (c *Coordinator) Connect(addr int) {
func (c *Coordinator) SensorConnect(addr int) {
c.Sensors.mu.Lock()
defer c.Sensors.mu.Unlock()
_, exists := c.Sensors.Managers[addr]
@ -116,18 +158,34 @@ func (c *Coordinator) Connect(addr int) {
} // ignoring case of existing sm eventually will have to check for alive
}
func (c *Coordinator) EstablishConnection() error {
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(fmt.Sprintf("%v:%v",c.ServerIp,c.ServerPort),opts...)
if err != nil {
return err
var conn *grpc.ClientConn
var err error
for {
conn, err = grpc.Dial(fmt.Sprintf("%v:%v",c.server.Ip,c.server.Port),opts...)
code := status.Code(err)
if code != 0 { // != OK
if code == (5 | 14) { // service temp down
to := c.Timeout()
if to == 0 {
err = errors.New("Failed to connect to central server")
return err
}
fmt.Printf("Server currently unavailable, retrying in %v ms", to)
time.Sleep(time.Duration(to) * time.Millisecond)
} else {
return err
}
}
break;
}
defer conn.Close()
client := pb.NewHandshakeClient(conn)
req := &pb.ReactorDiscoveryRequest{Id:c.HW.GetId(),Ip:c.HW.GetIp(),Port:int32(c.HW.GetPort()),Model:c.HW.GetModel()}
resp, err := client.ReactorDiscoveryHandler(context.Background(), req)
req := &pb.ClientDiscoveryRequest{Id:c.Id,Ip:c.hwinfo.Ip,Port:int32(c.hwinfo.Port),Model:c.Model,ClientType:c.Type}
resp, err := client.ClientDiscoveryHandler(context.Background(), req)
if err != nil {
return err
}
@ -140,8 +198,8 @@ func (c *Coordinator) EstablishConnection() error {
}
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()))
fmt.Printf("Listening for pings on %v:%v\n",c.hwinfo.Ip,c.hwinfo.Port)
lis, err := net.Listen("tcp", fmt.Sprintf("%v:%v",c.hwinfo.Ip,c.hwinfo.Port))
if err != nil {
return err
}
@ -152,13 +210,26 @@ func (c *Coordinator) Register() error {
}
// sensor status stuff
func (c *Coordinator) SensorStatusHandler(ctx context.Context, ping *pb.SensorStatusRequest) (*pb.SensorStatusResponse,error) {
c.Sensors.mu.Lock()
defer c.Sensors.mu.Unlock()
var sensors []*pb.SensorStatus
resp := &pb.SensorStatusResponse{Id:c.HW.GetId(),Sensors:sensors}
for a, s := range c.Sensors.Managers {
resp.Sensors = append(resp.Sensors,&pb.SensorStatus{Addr:int32(a), Type:s.GetType(), Status:s.GetStatus()})
func (c *Coordinator) ReactorStatusHandler(ctx context.Context, ping *pb.ReactorStatusRequest) (*pb.ReactorStatusResponse,error) {
// handler returns reactor id and any changes in devices
chng := c.PendingChanges() // returns map[int]sensor
var devs []*pb.Device
resp := &pb.ReactorStatusResponse{Id:c.Id,Devices:devs}
for a, s := range chng {
resp.Devices = append(resp.Devices,&pb.Device{Addr:int32(a), Type:s.GetType(), Status:s.GetStatus()})
}
return resp, nil
}
func (c *Coordinator) Timeout() int {
c.Active.Lock()
defer c.Active.Unlock()
if c.Active.int < 9 {
v := int(5 * math.Pow(float64(2), float64(c.Active.int)))
c.Active.int +=1
return v
} else {
//excedded retries
return 0
}
}

@ -2,7 +2,7 @@ package sensor
import (
"sync"
"fmt"
_ "fmt"
_ "FRMS/internal/pkg/I2C"
)
@ -35,10 +35,10 @@ type SensorInfo struct {
mu sync.Mutex
}
func (s *SensorInfo) GetStatus() string{
func (s *SensorInfo) GetStatus() uint32{
s.mu.Lock()
defer s.mu.Unlock()
return fmt.Sprint(s.Status)
return uint32(s.Status)
}
func (s *SensorInfo) GetType() string{
@ -63,7 +63,7 @@ func (m *Manager) Start() {
m.Sensor = &SensorInfo{Type:types[m.Addr]}
}
func (m *Manager) GetStatus() string {
func (m *Manager) GetStatus() uint32 {
b := m.I2CMonitor.GetStatus(m.Addr)
m.Sensor.Update(b)
return m.Sensor.GetStatus()

@ -0,0 +1,66 @@
package server
import (
"fmt"
"sync"
"log"
)
// this package creates coordinators responsible for keeping track of active clients and invoking managers
type Coordinator struct {
Type string // ["reactor","tui"]
IncomingClients <-chan *Client
Managers
Err chan error
}
type Managers struct {
Directory map[uint32](chan<- bool)
sync.Mutex
}
func NewCoordinator(t string,ch chan *Client, err chan error) *Coordinator {
return &Coordinator{Type: t,IncomingClients: ch,Err:err}
}
func FindNewManager(c *Client,ch chan bool, err chan error) {
switch c.Type {
case "reactor":
NewReactorManager(c,ch,err)
case "tui":
NewTUIManager(c,ch,err)
default:
log.Fatal(fmt.Sprintf("ERROR %v NOT FOUND",c.Type))
}
}
func (c *Coordinator) Start() {
// on start we need to create channel listener
// on each new connection we want to check its id against our mapping
go c.Listen()
}
func (c *Coordinator) Listen() {
for {
cl := <-c.IncomingClients
go c.ClientHandler(cl)
}
}
func (c *Coordinator) ClientHandler(cl *Client) {
// (creates and) notifies manager of client connection
c.Managers.Lock()
defer c.Managers.Unlock()
if m, exists := c.Managers.Directory[cl.Id]; exists {
// manager in memory
m <-true
} else {
// create channel and manager
ch := make(chan bool)
FindNewManager(cl, ch,c.Err)
c.Managers.Directory[cl.Id] = ch
// will block until manager is ready
ch <-true
}
}

@ -0,0 +1,110 @@
package server
import (
"fmt"
"net"
"log"
"sync"
"context"
"FRMS/internal/pkg/system"
"google.golang.org/grpc"
pb "FRMS/internal/pkg/grpc"
)
// the goal here is to set up a gRPC server to respond to client pings with their IP and to establish a new manager for that specific client
// going to rename shit to be more general
type Listener struct { // exporting for easy use in the short term
// Reactor map[uint32]*ReactorManager this will go in eventual "coordinator" struct
Ip string
Port int
*Coordinators
Err chan error
pb.UnimplementedHandshakeServer
}
type Coordinators struct {
Channel map[string](chan<- *Client)
sync.Mutex
}
type Client struct {
Ip string
Port int
Id uint32
Model string
Type string
}
func NewClient(ip, model, t string, port int, id uint32) *Client {
return &Client{Ip:ip,Port:port,Id:id,Model:model,Type:t}
}
func GetIp(e string) (string, error) {
return system.GetIp(e)
}
func NewListener(ifconfig string,ch chan error) (*Listener, error) {
//m := make(map[uint32]*ReactorManager)
var ip string
var err error
if ip, err = GetIp(ifconfig); err != nil {
return &Listener{}, err
}
m := make(map[string](chan<- *Client))
c := &Coordinators{Channel:m}
l := &Listener{Ip:ip,Err:ch}
l.Coordinators = c
return l, nil
}
func (l *Listener) Start() {
// start grpc server and implement reciever
if err := l.Register(); err != nil {
l.Err <- err
}
// listener started and grpc handler registered
fmt.Printf("Started listener on %v:%v\n",l.Ip,l.Port)
}
func (l *Listener) Register() error {
// creates a gRPC service and binds it to our handler
lis, err := net.Listen("tcp", fmt.Sprintf("%v:0",l.Ip)) // by binding to :0 we should get assigned an empty port
if err != nil {
return err
}
l.Port = lis.Addr().(*net.TCPAddr).Port // getting the port we were assigned
grpcServer := grpc.NewServer()
pb.RegisterHandshakeServer(grpcServer, l)
go grpcServer.Serve(lis)
return nil
}
func (l *Listener) ClientDiscoveryHandler(ctx context.Context, ping *pb.ClientDiscoveryRequest) (*pb.ClientDiscoveryResponse, error) {
// incoming reactor ping need to spawn coord
c := NewClient(ping.GetIp(),ping.GetModel(),ping.GetClientType(),int(ping.GetPort()),ping.GetId())
fmt.Printf("%v Client %v has connected from %v:%v\n",c.Type,c.Id,c.Ip,c.Port)
go l.ConnectClient(c)
// we dont handle any actual logic about the creation so we just respon true if the request was received
return &pb.ClientDiscoveryResponse{Success:true}, nil
}
func (l *Listener) ConnectClient(c *Client){
// send to reactor coordinator for ease
l.Coordinators.Lock()
defer l.Coordinators.Unlock()
switch c.Type {
case "reactor","tui":
if ch, exists := l.Coordinators.Channel[c.Type]; exists {
ch <-c
} else {
ch := make(chan *Client)
newC := NewCoordinator(c.Type, ch, l.Err)
go newC.Start()
l.Coordinators.Channel[c.Type] = ch
ch <-c
}
default:
log.Fatal("Error! client %v not supported!",c.Type)
}
}

@ -0,0 +1,135 @@
package server
import (
"fmt"
"time"
"math"
"sync"
"errors"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
"google.golang.org/grpc/credentials/insecure"
)
// this package will implement a boilerplate manager
// manager connects to client on start and returns the gRPC connection to make gRPC clients
type Manager struct {
*Client // gives access to c.Ip c.Id etc
Hb time.Duration
Active active
Err chan error
}
type active struct{
sync.Mutex
bool
int
}
func NewManager(c *Client, err chan error) *Manager {
hb := time.Duration(5) //hb to
m := &Manager{Hb:hb,Err:err}
m.Client = c
return m
}
func (m *Manager) Start() {
// establish connection with client and start pinging at set intervals
if !m.Activate() {
// manager already running
m.Err <-errors.New("Manager already running!")
} // if we get here, manager is atomically activated and we can ensure start wont run again
}
func (m *Manager) Exit() {
// exit function to eventually allow saving to configs
if !m.Deactivate() {
m.Err <-errors.New("Manager already disabled!")
}
fmt.Printf("Manager %v exiting", m.Id)
}
// reactor manager atomic operations
func (m *Manager) IsActive() bool {
m.Active.Lock()
defer m.Active.Unlock()
return m.Active.bool
}
func (m *Manager) Activate() bool {
m.Active.Lock()
defer m.Active.Unlock()
alive := m.Active.bool
if alive {
return false
} else {
m.Active.bool = true
m.Active.int = 0
return m.Active.bool
}
}
func (m *Manager) Deactivate() bool {
m.Active.Lock()
defer m.Active.Unlock()
alive := m.Active.bool
if alive {
m.Active.bool = false
return true
} else {
return m.Active.bool
}
}
// connection stuff
func (m *Manager) Timeout() int {
// keeps track of and generates timeout [0-1.2s) over span of ~2.5s
// returns 0 on TO elapse
m.Active.Lock()
defer m.Active.Unlock()
if m.Active.int < 9 {
v := int(5 * math.Pow(float64(2), float64(m.Active.int)))
m.Active.int += 1
return v
} else {
// exceeded retries
return 0
}
}
func (m *Manager) Connect() *grpc.ClientConn{
// establish initial gRPC connection with client
var opts []grpc.DialOption
var conn *grpc.ClientConn
opts = append(opts,grpc.WithTransportCredentials(insecure.NewCredentials()))
for {
if !m.IsActive() {
fmt.Printf("Aborting connection attempt\n")
return &grpc.ClientConn{}
}
var err error
conn, err = grpc.Dial(fmt.Sprintf("%v:%v",m.Ip,m.Port),opts...)
// begin error handling
code := status.Code(err)
if code != 0 { // != OK
if code == (5 | 14) { // == unavailable or not found
to := m.Timeout()
if to == 0 {
fmt.Printf("Client not responding, exiting...\n")
m.Exit()
return&grpc.ClientConn{}
}
fmt.Printf("gRPC endpoint currently unavailable, retrying in %v ms",to)
time.Sleep(time.Duration(to) * time.Millisecond)
} else {
fmt.Printf("ERR GRPC: %v\n",code)
m.Err <-err
}
}
break;
}
return conn
}

@ -3,33 +3,19 @@ package server
import (
"fmt"
"time"
"math"
"context"
"sync"
"errors"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
"google.golang.org/grpc/credentials/insecure"
pb "FRMS/internal/pkg/grpc"
)
// this package will implement a reactor coordinator and associated go routines
type ReactorManager struct {
Server *ReactorListener // embedding parent listener to call methods
Ip string
Port int
Id uint32
Model string
Hb time.Duration
*Manager
Devs *Devices
Active active
}
type active struct{
sync.Mutex
bool
int
ClientConnections <-chan bool
}
type Devices struct {
@ -37,132 +23,44 @@ type Devices struct {
D map[int]Device
}
type Device interface {
GetStatus() uint32
PrintStatus() string
GetType() string
}
func NewReactorManager(s *ReactorListener, ip, model string, port int, id uint32) *ReactorManager {
func NewReactorManager(c *Client,ch chan bool,err chan error) {
d := new(Devices)
return &ReactorManager{Server: s, Ip: ip, Port: port, Id: id, Model: model,Devs:d,Hb:time.Duration(5)}
}
func(r *ReactorManager) Start() {
// establish connection with reactor and start pinging at set intervals
if !r.Activate() {
// reactor already running
r.Server.Err <-errors.New("Reactor already running!")
} // if we get here, reactor is atomically activated and we can ensure start wont run again
go r.Connect()
}
func (r *ReactorManager) Exit() {
// exit function to eventually allow saving to configs
if !r.Deactivate() {
r.Server.Err <-errors.New("Reactor already disabled!")
}
fmt.Printf("Reactor %v exiting", r.Id)
}
// reactor manager atomic operations
func (r *ReactorManager) IsActive() bool {
r.Active.Lock()
defer r.Active.Unlock()
return r.Active.bool
}
func (r *ReactorManager) Activate() bool {
r.Active.Lock()
defer r.Active.Unlock()
alive := r.Active.bool
if alive {
return false
} else {
r.Active.bool = true
r.Active.int = 0
return r.Active.bool
}
r := &ReactorManager{Devs:d,ClientConnections:ch}
r.Manager = NewManager(c, err)
go r.Listen()
}
func (r *ReactorManager) Deactivate() bool {
r.Active.Lock()
defer r.Active.Unlock()
alive := r.Active.bool
if alive {
r.Active.bool = false
return true
} else {
return r.Active.bool
}
}
// connection stuff
func (r *ReactorManager) Timeout() int {
// keeps track of and generates timeout [0-1.2s) over span of ~2.5s
// returns 0 on TO elapse
r.Active.Lock()
defer r.Active.Unlock()
if r.Active.int < 9 {
v := int(5 * math.Pow(float64(2), float64(r.Active.int)))
r.Active.int += 1
return v
} else {
// exceeded retries
return 0
}
}
func (r *ReactorManager) Connect() {
// establish initial gRPC connection with reactor
var opts []grpc.DialOption
var conn *grpc.ClientConn
opts = append(opts,grpc.WithTransportCredentials(insecure.NewCredentials()))
func (r *ReactorManager) Listen() {
for {
if !r.IsActive() {
fmt.Printf("Aborting connection attempt\n")
return
c := <-r.ClientConnections
if c {
r.Start()
} else {
r.Exit()
}
var err error
conn, err = grpc.Dial(fmt.Sprintf("%v:%v",r.Ip,r.Port),opts...)
// begin error handling
code := status.Code(err)
if code != 0 { // != OK
if code == (5 | 14) { // == unavailable or not found
to := r.Timeout()
if to == 0 {
fmt.Printf("Reactor not responding, exiting...\n")
r.Exit()
return
}
fmt.Printf("gRPC endpoint currently unavailable, retrying in %v ms",to)
time.Sleep(time.Duration(to) * time.Millisecond)
} else {
fmt.Printf("ERR GRPC: %v\n",code)
r.Server.Err <-err
}
} // lmao this is why it always exits
break;
}
client := pb.NewMonitoringClient(conn)
go r.Monitor(conn, client)
}
func (r *ReactorManager) Monitor(conn *grpc.ClientConn, client pb.MonitoringClient) {
func (r *ReactorManager) Start() {
r.Manager.Start()
conn := r.Connect()
go r.Monitor(conn)
}
func (r *ReactorManager) Monitor(conn *grpc.ClientConn) {
defer conn.Close()
client := pb.NewMonitoringClient(conn)
for r.IsActive() {
req := &pb.SensorStatusRequest{Id:r.Id}
resp, err := client.SensorStatusHandler(context.Background(),req)
req := &pb.ReactorStatusRequest{Id:r.Id}
resp, err := client.ReactorStatusHandler(context.Background(),req)
code := status.Code(err)
if code != 0 { // if != OK
fmt.Printf("Reactor %v down! Exiting manager...", r.Id)
r.Exit()
}
for _,v := range resp.GetSensors() {
fmt.Printf("%v is %v at %x\n",v.GetType(),v.GetStatus(),v.GetAddr())
}
//for _,v := range resp.GetDevices() {
// TODO changed sensors
//}
fmt.Printf("Reactor %v online\n", resp.GetId())
time.Sleep(r.Hb * time.Second) // time between sensor pings
}

@ -0,0 +1,80 @@
package server
import (
"fmt"
"time"
"sync"
)
// implement tui specific manager to be called for each client conn
type TUIManager struct {
*Manager // embedded manager for access to methods and client
Sys *KnownReactors
ClientConnections <-chan bool
Err chan error
Hb time.Duration
}
type KnownReactors struct {
Reactors map[uint32]*Reactor
sync.Mutex
}
type Reactor struct {
Devices map[string]*Device
}
type Device struct {
Status DeviceStatus
Type string
Addr int
}
type DeviceStatus uint32
const (
READY DeviceStatus = iota
ACTIVE
DISABLED
)
func (d DeviceStatus) String() string {
return [...]string{"Ready","Active","Disabled"}[d]
}
func (d Device) String() string {
return fmt.Sprintf("%v is %v at %x",d.Type,d.Status,d.Addr)
}
type DeviceManager interface{
// GetStatus() uint32 UNSUPPORTED: arguable memory benifit but until we support 100s of sensors across 10s of tui clients im not implementing it
PrintSatus() string
GetType() string
}
func NewTUIManager(c *Client,ch chan bool, err chan error) {
k := new(KnownReactors)
m := NewManager(c, err)
hb := time.Duration(5)
t := &TUIManager{Hb: hb,Sys: k,Err: err, ClientConnections: ch}
t.Manager = m
go t.Listen()
}
func (t *TUIManager) Listen() {
for {
c := <-t.ClientConnections
if c {
t.Start()
} else {
t.Exit()
}
}
}
func (t *TUIManager) Start() {
t.Manager.Start()
//conn := t.Conn()
//go t.Monitor(conn)
}

113
notes

@ -195,4 +195,115 @@ Coordinator
- rm for reactor/sensor status
- implements
- sender of system status for TUI
TODO 6/29
- refactoring
- creating general listener and then a coordinator for reactor/tui that uses listener to field incoming requests
- change update loops for status to only send new data or empty messages for pings
- tui
- creating coordinator/manager for TUI clients
- create update loop for tui clients
- grpc to tui client with updates and hb
- drawfunc loops over change buffer
- on disconnect should display static terminal with offline warning
- Listener Struct
- needs to know
- IP
- Port
- needs to be able to
- respond to incoming gRPC
- create corrisponding manager // taken care of in the actual handler
- relies on
- grpc for the endpoint stuff
- manager impl
- implements
- listener for main func
- manager generator essentially
coordinator should be seperate ***
- new coordinator struct
- listener sends new connections to coordinator who appends to internal registery and reacts
- needs to know
- incoming:
- ip
- port
- client type?
- needs to be able to
- wait for incoming connections
- create a new manager for the client
- update internal directory
- remove entries ?? (tui -> reactor)
- implements
- manager creation
- connection handling
- client hb
- relies on
- manager impl
- listener call?
alright complete redesign
server acts as singular listener
routes all requests to a central coordiantor
this calls cooresponding client coordinator which then initiates managers etc
now redesinging sensor info
new fmt
1) have a seperate long running coordinator routine responsible for a "changed" list of sensors
2) on reactor status request:
a) send the changed list
b) if the send was acknowledged purge the change list
* both must be atomic
new rlc struct
- needs to know
- sensors connected
- changes in sensors
- how to establish connection to central server
- needs to be able to
- track changes in its system layout
- atomically relay these to the cc
- depends on
- I2C sensor info
- implements
- reactor sensor change tracking
new general coord
What does it need to do?
- Needs to respond to incoming clients from listener
- what does this mean?
- needs to link a client to a manager
- this is the whole high level idea
- can everything else be abstracted away? Why not?
- how to link? Channel? Shared Memory?
- channel is probably the best choice here
- structure:
managers
[uint32] : chan<- bool
10292133 : chan<- bool
- how to use?
- when a client connects we search to see if a channel exits
- if it does we just send "true" down the channel to signal that the client connected
- if we dont we create a channel and a manager and start the manager
- we then send true down the newly created channel
-Do we ever close the channel?
- shouldn't that would mean the program is done accepting connections (could be a useful behavior in the future)
- do we ever send false?
- no, not sure what that would signal.
- coordinator is specifically only designed to create/notify managers of a client connection
formally, New Coordinator:
- needs to know
- client type
- needs to be able to
- either notify or create and notify a manager on client connection
- handle concurrency
- relies on
- listener to send incoming clients
- manager to implement actual manager
- implements
- manager activation and memory

Loading…
Cancel
Save