Merge branch 'tui_networking' into dev

Got TUI into a working state with efficent logging, adding it back to dev branch before starting database changes
main
KeeganForelight 2 years ago
commit 6e3da1588c

@ -1,12 +1,24 @@
#!/bin/bash
echo "Purging old builds"
rm -v bin/* 2>/dev/null
echo "Removing Logs"
rm -v bin/log/* 2>/dev/null
echo "Building reactor binaries"
env GOOS=linux GOARCH=arm GOARM=7 go build -o bin/reactor_linux_arm cmd/reactor/main.go
env GOOS=linux GOARCH=arm64 go build -o bin/reactor_linux_arm64 cmd/reactor/main.go
echo "Building tui binaries"
env GOOS=linux GOARCH=arm GOARM=7 go build -o bin/tui_linux_arm cmd/tui/main.go
env GOOS=linux GOARCH=arm64 go build -o bin/tui_linux_arm64 cmd/tui/main.go
env GOOS=linux GOARCH=amd64 go build -o bin/tui_linux_amd64 cmd/tui/main.go
echo "Building server binary"
env GOOS=linux GOARCH=amd64 go build -o bin/server_linux_amd64 cmd/server/main.go
tar -czf pireactor.tar.gz bin/reactor_linux_arm64
tar -czf bbreactor.tar.gz bin/reactor_linux_arm
tar -czf tui.tar.gz bin/tui_linux_amd64
tar -czf server.tar.gz bin/server_linux_amd64
echo "Compressing binaries for distrubution"
tar -czf pireactor.tar.gz -C bin reactor_linux_arm64
tar -czf bbreactor.tar.gz -C bin reactor_linux_arm
tar -czf server.tar.gz -C bin server_linux_amd64
tar -czf tui.tar.gz -C bin tui_linux_amd64 tui_linux_arm tui_linux_arm64

@ -6,7 +6,6 @@ import (
_ "fmt"
_ "log"
"os/exec"
"os/user"
"bytes"
"strings"
"sync"

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc-gen-go v1.28.0
// protoc v3.6.1
// source: internal/pkg/grpc/management.proto
@ -27,6 +27,7 @@ type GetDevicesRequest struct {
ClientId uint32 `protobuf:"varint,1,opt,name=clientId,proto3" json:"clientId,omitempty"`
ReactorId uint32 `protobuf:"varint,2,opt,name=reactorId,proto3" json:"reactorId,omitempty"` // if unspecified, don't return any devs
Refresh bool `protobuf:"varint,3,opt,name=refresh,proto3" json:"refresh,omitempty"`
}
func (x *GetDevicesRequest) Reset() {
@ -75,6 +76,13 @@ func (x *GetDevicesRequest) GetReactorId() uint32 {
return 0
}
func (x *GetDevicesRequest) GetRefresh() bool {
if x != nil {
return x.Refresh
}
return false
}
type GetDevicesResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -474,71 +482,73 @@ var File_internal_pkg_grpc_management_proto protoreflect.FileDescriptor
var file_internal_pkg_grpc_management_proto_rawDesc = []byte{
0x0a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x67,
0x72, 0x70, 0x63, 0x2f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x67, 0x72, 0x70, 0x63, 0x22, 0x4d, 0x0a, 0x11, 0x47, 0x65,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x67, 0x72, 0x70, 0x63, 0x22, 0x67, 0x0a, 0x11, 0x47, 0x65,
0x74, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72,
0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09,
0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x22, 0x73, 0x0a, 0x12, 0x47, 0x65, 0x74,
0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72,
0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09,
0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x07, 0x64, 0x65, 0x76,
0x69, 0x63, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x67, 0x72, 0x70,
0x63, 0x2e, 0x44, 0x65, 0x76, 0x52, 0x07, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x22, 0x50,
0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74,
0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74,
0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64,
0x22, 0x6b, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f,
0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69,
0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x66,
0x72, 0x65, 0x73, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x72, 0x65, 0x66, 0x72,
0x65, 0x73, 0x68, 0x22, 0x73, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65,
0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69,
0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69,
0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72,
0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f,
0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x03,
0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x70, 0x0a,
0x1a, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x65,
0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x63,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x63,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74,
0x6f, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x61, 0x63,
0x74, 0x6f, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x76, 0x41, 0x64, 0x64, 0x72,
0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x64, 0x65, 0x76, 0x41, 0x64, 0x64, 0x72, 0x22,
0x8b, 0x01, 0x0a, 0x1b, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f,
0x72, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72,
0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09,
0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x76,
0x41, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x64, 0x65, 0x76, 0x41,
0x64, 0x64, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x04,
0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x6b, 0x0a,
0x03, 0x44, 0x65, 0x76, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x02, 0x69, 0x64, 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,
0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x05, 0x20,
0x01, 0x28, 0x0d, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x32, 0xf3, 0x01, 0x0a, 0x0a, 0x6d,
0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x3f, 0x0a, 0x0a, 0x47, 0x65, 0x74,
0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x17, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x47,
0x65, 0x74, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x18, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x48, 0x0a, 0x0d, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x1a, 0x2e, 0x67, 0x72,
0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44,
0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5a, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65,
0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x12, 0x20, 0x2e, 0x67, 0x72,
0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72,
0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e,
0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74,
0x6f, 0x72, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 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, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x07, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x03,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x76, 0x52,
0x07, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x22, 0x50, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65,
0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09,
0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52,
0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x22, 0x6b, 0x0a, 0x15, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12,
0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a,
0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07,
0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x70, 0x0a, 0x1a, 0x44, 0x65, 0x6c, 0x65, 0x74,
0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49,
0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x18, 0x02,
0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x12,
0x18, 0x0a, 0x07, 0x64, 0x65, 0x76, 0x41, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05,
0x52, 0x07, 0x64, 0x65, 0x76, 0x41, 0x64, 0x64, 0x72, 0x22, 0x8b, 0x01, 0x0a, 0x1b, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6c, 0x69,
0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x63, 0x6c, 0x69,
0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72,
0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x61, 0x63, 0x74, 0x6f,
0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x76, 0x41, 0x64, 0x64, 0x72, 0x18, 0x03,
0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x64, 0x65, 0x76, 0x41, 0x64, 0x64, 0x72, 0x12, 0x18, 0x0a,
0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07,
0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x6b, 0x0a, 0x03, 0x44, 0x65, 0x76, 0x12, 0x0e,
0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 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, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61,
0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14,
0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x69,
0x6e, 0x64, 0x65, 0x78, 0x32, 0xf3, 0x01, 0x0a, 0x0a, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d,
0x65, 0x6e, 0x74, 0x12, 0x3f, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65,
0x73, 0x12, 0x17, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x76, 0x69,
0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x67, 0x72, 0x70,
0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x48, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65,
0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x1a, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x1b, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52,
0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5a,
0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44,
0x65, 0x76, 0x69, 0x63, 0x65, 0x12, 0x20, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44,
0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x44, 0x65, 0x76, 0x69,
0x63, 0x65, 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 (

@ -12,6 +12,7 @@ service management {
message GetDevicesRequest {
uint32 clientId = 1;
uint32 reactorId = 2; // if unspecified, don't return any devs
bool refresh = 3;
}
message GetDevicesResponse {

@ -9,6 +9,13 @@ import (
"strconv"
)
func getLogType() string {
if t, ok := os.LookupEnv("LOGTYPE"); ok {
return t
}
return "DEFAULT"
}
func getVerbosity() int {
v := os.Getenv("VERBOSE")
level := 0
@ -16,7 +23,7 @@ func getVerbosity() int {
var err error
level, err = strconv.Atoi(v)
if err != nil {
log.Fatalf("Invalid Vverboity %v", v)
log.Fatalf("Invalid Verbosity %v", v)
}
}
return level
@ -39,6 +46,7 @@ var debugStart time.Time
var debugVerbosity int
func init() {
debugVerbosity = getVerbosity()
debugStart = time.Now()
if debugVerbosity > 0 {
@ -50,8 +58,9 @@ func init() {
os.Exit(1)
}
}
filename := time.Now().Format("01-02T15:04:05")
filename += ".log"
logtype := getLogType() // start with "REACTOR" etc
timestamp := time.Now().Format("Tue 15:04:05")
filename := fmt.Sprintf("%s %s.log", logtype, timestamp)
f, err := os.OpenFile(path+filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
if err != nil {
log.Fatal(err)

@ -60,7 +60,8 @@ func (l *Listener) Start() {
go l.Sys.Start()
// listener started and grpc handler registered
logging.Debug(logging.DStart,"Started listener on %v:%v\n",l.Ip,l.Port)
fmt.Printf("=========================\n PORT: %v\n=========================\n",l.Port)
fmt.Printf("==========================\n IP: %v\n",l.Ip)
fmt.Printf("==========================\n PORT: %v\n==========================\n",l.Port)
}
func (l *Listener) Register() error {
@ -98,7 +99,7 @@ func (l *Listener) TUIClientDiscoveryHandler(ctx context.Context, ping *pb.TUICl
var ok bool
coord, ok = l.Coordinators["tui"]
if !ok {
logging.Debug(logging.DSpawn,"CCO 01 Created RCO")
logging.Debug(logging.DSpawn,"CCO 01 Created TCO")
coord = NewTUICoordinator(l.Ip, l.Sys, l.Err)
l.Coordinators["tui"] = coord
coord.Start()

@ -18,7 +18,6 @@ import (
type ReactorManager struct {
*Manager
StatusMon *StatusMonitor
DevsMon *StatusMonitor
*devstatus
}
@ -32,17 +31,14 @@ func NewReactorManager(c *Client,sys *SystemViewer,err chan error) GeneralManage
di := make(map[uint32]*DeviceInfo)
r.devstatus = &devstatus{Devs:di}
r.Manager = NewManager(err)
r.StatusMon = sys.AddReactorSender()
r.DevsMon = sys.AddDeviceSender(c.Id)
r.StatusMon = NewStatusMonitor("Reactor",c.Id,sys)
return r
}
func (r *ReactorManager) Start(cl *Client) {
r.Manager.Start(cl)
logging.Debug(logging.DStart,"RMA %v starting", r.Id)
go r.StatusMon.Start()
go r.DevsMon.Start()
go r.StatusMon.Send(&DeviceInfo{Id:r.Id,Type:"Reactor",Status:"[green]ONLINE[white]"})
go r.StatusMon.Send(&DeviceInfo{Id:r.Id,Type:"Reactor",Status:"[green]ONLINE[white]"},"Reactor")
conn := r.Connect()
empty := &grpc.ClientConn{}
if conn != empty {
@ -53,7 +49,7 @@ func (r *ReactorManager) Start(cl *Client) {
func (r *ReactorManager) Exit() {
r.Manager.Exit()
logging.Debug(logging.DExit, "RMA %v exiting", r.Id)
go r.StatusMon.Send(&DeviceInfo{Id:r.Id,Type:"Reactor",Status:"[red]OFFLINE[white]",Data:fmt.Sprintf("Last Seen %v",time.Now().Format("Mon at 03:04:05pm MST"))})
go r.StatusMon.Send(&DeviceInfo{Id:r.Id,Type:"Reactor",Status:"[red]OFFLINE[white]",Data:fmt.Sprintf("Last Seen %v",time.Now().Format("Mon at 03:04:05pm MST"))},"Reactor")
}
func (r *ReactorManager) GetPort() int {
@ -109,21 +105,16 @@ func (r *ReactorManager) Monitor(conn *grpc.ClientConn) {
newd := d
newd.Status = "[yellow]UNKOWN[white]"
r.Devs[newd.Id] = newd
go r.DevsMon.Send(newd)
go r.StatusMon.Send(newd,"Device")
}
r.devstatus.Unlock()
r.Exit()
break;
}
//r.devstatus.Lock()
for _,v := range resp.GetDevices() {
d := &DeviceInfo{Id:uint32(v.GetAddr()),Type:v.GetType(),Status:v.GetStatus(),Data:v.GetData()}
go r.UpdateDevice(d)
//go r.DevsMon.Send(d)
//r.Devs[d.Id] = d
}
//r.devstatus.Unlock()
logging.Debug(logging.DPing, "RMA %v Reactor Reached", r.Id)
time.Sleep(r.Hb) // time between sensor pings
}
}
@ -134,10 +125,10 @@ func (r *ReactorManager) UpdateDevice(d *DeviceInfo) {
if olddev, ok := r.Devs[d.Id]; !ok {
// new device
r.Devs[d.Id] = d
go r.DevsMon.Send(d)
go r.StatusMon.Send(d,"Device")
} else if olddev.Status != d.Status || olddev.Data != d.Data {
// dev status or data has changed
r.Devs[d.Id] = d
go r.DevsMon.Send(d)
go r.StatusMon.Send(d,"Device")
}
}

@ -5,8 +5,6 @@ import (
_ "fmt"
"FRMS/internal/pkg/logging"
)
// package will create and maintain a concurrent system structure
// allows for multiple readers/writers
type DeviceInfo struct {
Id uint32
@ -17,18 +15,154 @@ type DeviceInfo struct {
TransactionId uint32
}
func NewStatusMonitor(ch chan *DeviceInfo) *StatusMonitor {
type StatusMonitor struct {
// allows for embedding into managers
TransactionId chan uint32 // monotonically increases to track outdated reqs
DevChan chan *DeviceInfo // channel for device status
ReactorChan chan *DeviceInfo // channel for reactor status
*SystemViewer
DevBuf *devbuf
sync.Mutex
}
type devbuf struct {
ReactorId uint32 // reactor we are looking at, if any
Buf map[string]map[uint32]*DeviceInfo // convienent way to store/seperate device data
sync.Mutex
}
func NewBuffer() map[string]map[uint32]*DeviceInfo {
rbuf := make(map[uint32]*DeviceInfo)
dbuf := make(map[uint32]*DeviceInfo)
sbuf := make(map[string]map[uint32]*DeviceInfo)
sbuf["Reactor"] = rbuf
sbuf["Device"] = dbuf
return sbuf
}
func NewStatusMonitor(t string, id uint32, sys *SystemViewer) *StatusMonitor {
tid := make(chan uint32)
sm := &StatusMonitor{StatusChan:ch,TransactionId:tid}
sm := &StatusMonitor{TransactionId:tid}
sm.SystemViewer = sys
if t == "Reactor" {
// reactor status monitor
sm.ReactorChan = sys.AddReactorSender()
sm.DevChan = sys.AddDeviceSender(id)
go sm.GenerateIds()
} else {
// tui status monitor
sbuf := NewBuffer()
//sm.ReactorChan, sbuf["Reactor"] = sys.AddListener(id,0)
sm.DevBuf = &devbuf{Buf:sbuf} // makes it easier to work with
go sm.UpdateListener(id,0)
}
return sm
}
func (s *StatusMonitor) GenerateIds() {
var id uint32
id = 0
for {
s.TransactionId <-id
id += 1
}
}
func (s *StatusMonitor) Send(d *DeviceInfo, dtype string) {
d.TransactionId = <-s.TransactionId
logging.Debug(logging.DClient,"SYS 01 Sending update for: %s (%s)", d.Type, d.Status)
if dtype == "Reactor" {
s.ReactorChan <-d
} else {
s.DevChan <-d
}
}
func (s *StatusMonitor) GetBuffer() []*DeviceInfo {
// also clears buffer
s.DevBuf.Lock()
defer s.DevBuf.Unlock()
res := []*DeviceInfo{}
if len(s.DevBuf.Buf["Reactor"]) != 0 || len(s.DevBuf.Buf["Device"]) != 0 {
logging.Debug(logging.DClient,"Clearing buff %v", s.DevBuf.Buf)
}
for _, devs := range s.DevBuf.Buf {
for _, dev := range devs {
// loops over reactors then devices
res = append(res,dev)
}
}
s.DevBuf.Buf = NewBuffer() // clearing old buffer
return res
}
func (s *StatusMonitor) UpdateListener(tid, reactorId uint32) {
s.DevBuf.Lock()
defer s.DevBuf.Unlock()
// clearing proper buffer
if reactorId == 0 {
logging.Debug(logging.DClient,"SYS 01 Adding %v as reactor listener", tid)
s.DevBuf.Buf["Reactor"] = make(map[uint32]*DeviceInfo)
s.ReactorChan, s.DevBuf.Buf["Reactor"] = s.SystemViewer.AddListener(tid, reactorId)
go s.Listen(s.ReactorChan)
} else {
logging.Debug(logging.DClient,"SYS 01 Adding %v as reactor %v listener", tid, reactorId)
s.DevBuf.Buf["Device"] = make(map[uint32]*DeviceInfo) // clearing old devices
if s.DevBuf.ReactorId != reactorId && s.DevBuf.ReactorId != 0{
go s.SystemViewer.RemoveListener(s.DevBuf.ReactorId, tid)
}
s.DevBuf.ReactorId = reactorId
s.DevChan, s.DevBuf.Buf["Device"] = s.SystemViewer.AddListener(tid, reactorId)
go s.Listen(s.DevChan)
}
}
func (s *StatusMonitor) UpdateBuffer(d *DeviceInfo, dtype string, ch chan *DeviceInfo) {
s.DevBuf.Lock()
defer s.DevBuf.Unlock()
logging.Debug(logging.DClient,"SYS 01 Dev %v update requested", d)
if dev, exists := s.DevBuf.Buf[dtype][d.Id]; exists {
// already a device in the buffer
if dev.TransactionId > d.TransactionId {
logging.Debug(logging.DClient,"SYS 01 Update Processed. Old: %v, New: %v \n", dev, d)
d = dev // not sure if i can do this lol
}
}
if ch == s.ReactorChan || ch == s.DevChan {
// hacky way to check if the device came from a listener of a current channel
s.DevBuf.Buf[dtype][d.Id] = d
} else {
logging.Debug(logging.DClient,"Dev out of date!")
}
}
func (s *StatusMonitor) Listen(ch chan *DeviceInfo) {
for dev := range ch {
if dev.Type == "Reactor" {
go s.UpdateBuffer(dev,"Reactor", ch)
} else {
go s.UpdateBuffer(dev, "Device", ch)
}
}
}
type InfoStream struct {
// base stream for any reactor/device
// NewSender embedds the channel to send updates on
// NewListener will add the statusmon to the list of devs to echo to
Stream chan *DeviceInfo
Layout *syslayout
*listeners
}
type listeners struct {
sync.RWMutex
Listeners map[uint32]*lischan
}
type lischan struct {
sync.WaitGroup
StatusChan chan *DeviceInfo
}
type syslayout struct {
@ -37,33 +171,38 @@ type syslayout struct {
sync.RWMutex
}
func NewLisChan(ch chan *DeviceInfo) *lischan {
l := &lischan{StatusChan:ch}
return l
}
func NewInfoStream() *InfoStream {
dch := make(chan *DeviceInfo)
s := &InfoStream{Stream:dch}
m := make(map[uint32]*DeviceInfo)
s.Layout = &syslayout{Devs:m}
s.listeners = &listeners{Listeners:make(map[uint32]*lischan)}
return s
}
func (s *InfoStream) Start() {
// consistency
go s.Listener()
go s.Listen()
}
// goal is to hook every new manager into the reactor status chan
func (s *InfoStream) AddSender() *StatusMonitor {
sm := NewStatusMonitor(s.Stream) // give the channel we monitor for incoming updates
return sm
func (s *InfoStream) AddSender() chan *DeviceInfo {
return s.Stream
}
func (s *InfoStream) Listener() {
for {
deviceInfo := <-s.Stream
func (s *InfoStream) Listen() {
for deviceInfo := range s.Stream {
go s.Update(deviceInfo)
}
}
func (s *InfoStream) Update(d *DeviceInfo) {
s.Layout.Lock()
defer s.Layout.Unlock()
if dev, ok := s.Layout.Devs[d.Id]; !ok {
d.Index = s.Layout.uint32
s.Layout.uint32 += 1
@ -74,56 +213,48 @@ func (s *InfoStream) Update(d *DeviceInfo) {
go s.Echo(d)
}
func (s *InfoStream) Echo(d *DeviceInfo) {
s.Listeners.RLock()
defer s.Listeners.RUnlock()
func (l *listeners) Echo(d *DeviceInfo) {
l.RLock()
defer l.RUnlock()
// read only lock
for _, lis := range s.Listeners {
go func(){
lis <-d
}()
for _, lis := range l.Listeners {
lis.Add(1)
go func(listener *lischan, dev *DeviceInfo){
defer listener.Done()
listener.StatusChan <-dev
}(lis,d)
}
}
func (s *InfoStream) AddListner(ch chan *DeviceInfo) {
s.Listeners.Lock()
defer s.Listeners.Unlock()
s.Listeners = append(s.Listeners, ch)
}
//func (s *InfoStream) GetLayout() map[uint32]*DeviceInfo {
func (s *InfoStream) AddListener(id uint32, ch chan *DeviceInfo) map[uint32]*DeviceInfo {
// if i get a memory leak ill eat my shoe
s.listeners.Lock()
defer s.listeners.Unlock()
if _, ok := s.listeners.Listeners[id]; ok {
// exists
go s.RemoveListener(id)
}
s.listeners.Listeners[id] = NewLisChan(ch)
logging.Debug(logging.DClient,"SYS 01 Getting Devices")
//s.Layout.RLock()
//defer s.Layout.RUnlock()
//return s.Layout.Devs
//}
// status buffer maintaince
type StatusMonitor struct {
// serve as base to embed in managers to send/receive device info
TransactionId chan uint32 // monotonically increases to track outdated reqs
StatusChan chan *DeviceInfo // sending reactor info in same fmt
logging.Debug(logging.DClient,"SYS 01 Returning Devices %v", s.Layout.Devs)
return s.Layout.Devs
}
func (s *StatusMonitor) Start() {
go s.GenerateIds()
}
func (s *StatusMonitor) GenerateIds() {
var id uint32
id = 0
for {
s.TransactionId <-id
id += 1
func (l *listeners) RemoveListener(id uint32) {
l.Lock()
defer l.Unlock()
if lis, ok := l.Listeners[id]; ok {
delete(l.Listeners,id)
go func(ls *lischan){
ls.Wait()
close(ls.StatusChan)
}(lis)
}
}
func (s *StatusMonitor) Send(d *DeviceInfo) {
d.TransactionId = <-s.TransactionId
logging.Debug(logging.DClient,"SYS 01 Updating %s Info (%s, %s)", d.Type, d.Status, d.Data)
s.StatusChan <-d
}
// now to tie it all together
// status buffer maintaince
type SystemViewer struct {
// stores system directory and provide methods to be embedded in managers
@ -148,11 +279,11 @@ func (s *SystemViewer) Start() {
go s.ReactorStream.Start()
}
func (s *SystemViewer) AddReactorSender() *StatusMonitor {
func (s *SystemViewer) AddReactorSender() chan *DeviceInfo {
return s.ReactorStream.AddSender()
}
func (s *SystemViewer) AddDeviceSender(reactorId uint32) *StatusMonitor {
func (s *SystemViewer) AddDeviceSender(reactorId uint32) chan *DeviceInfo {
s.DeviceStream.Lock()
defer s.DeviceStream.Unlock()
var ds *InfoStream
@ -165,23 +296,19 @@ func (s *SystemViewer) AddDeviceSender(reactorId uint32) *StatusMonitor {
return ds.AddSender()
}
func (s *SystemViewer) GetReactorStatus() map[uint32]DeviceInfo {
devs := s.ReactorStream.GetLayout()
ret := make(map[uint32]DeviceInfo)
for id, dev := range devs {
ret[id] = *dev
func (s *SystemViewer) AddListener(id, rid uint32) (chan *DeviceInfo, map[uint32]*DeviceInfo) {
// returns a listener for that chan
ch := make(chan *DeviceInfo)
if rid != 0 {
return ch, s.DeviceStream.Reactors[rid].AddListener(id, ch)
} else {
return ch, s.ReactorStream.AddListener(id, ch)
}
return ret //value instead of ptr
}
func (s *SystemViewer) GetDeviceStatus(reactorId uint32) map[uint32]DeviceInfo {
func (s *SystemViewer) RemoveListener(rid, tid uint32) {
// removes chan for specific tid and rid
s.DeviceStream.Lock()
ds := s.DeviceStream.Reactors[reactorId]
s.DeviceStream.Unlock()
devs := ds.GetLayout()
ret := make(map[uint32]DeviceInfo)
for id, dev := range devs {
ret[id] = *dev
}
return ret
defer s.DeviceStream.Unlock()
go s.DeviceStream.Reactors[rid].RemoveListener(tid)
}

@ -17,8 +17,8 @@ import (
type TUIManager struct {
*Manager // embedded manager for access to methods and client
Ip string
*SystemViewer
Port *port
StatusMon *StatusMonitor // use it for all devs coming in
Err chan error
*Timeout
*pb.UnimplementedManagementServer
@ -43,8 +43,8 @@ func NewTUIManager(ip string, c *Client, sys *SystemViewer, err chan error) Gene
alert := make(chan bool)
t.Timeout = &Timeout{Alert:alert,TO:time.Duration(2500*time.Millisecond)} // short time outs are fine because we will just rejoin
t.Manager = m
t.SystemViewer = sys
t.Ip = ip
t.StatusMon = NewStatusMonitor("TUI",c.Id,sys)
return t
}
@ -62,6 +62,7 @@ func (t *TUIManager) Exit() {
t.Manager.Exit()
logging.Debug(logging.DExit,"TMA %v exiting",t.Id)
}
func (t *Timeout) PingReset() {
t.Lock()
defer t.Unlock()
@ -106,7 +107,7 @@ func (t *TUIManager) Register() {
go func(ch chan int,p int) {
ch <-p
}(t.Port.Chan, t.Port.int)
logging.Debug(logging.DClient, "TMA %v reayd for client conn", t.Id)
logging.Debug(logging.DClient, "TMA %v ready for client conn", t.Id)
// up and running
}
@ -115,24 +116,25 @@ func (t *TUIManager) GetPort() int {
return port
}
// tui client requests and logic will be down here
func (t *TUIManager) GetDevices(ctx context.Context, req *pb.GetDevicesRequest) (*pb.GetDevicesResponse, error) {
go t.PingReset()
rid := req.GetReactorId()
devices := []*pb.Dev{}
resp := &pb.GetDevicesResponse{ClientId:t.Id,ReactorId:rid,Devices:devices}
reactors := t.SystemViewer.GetReactorStatus()
for _, v := range reactors {
resp.Devices = append(resp.Devices, &pb.Dev{Id:v.Id,Type:v.Type,Status:v.Status,Data:v.Data,Index:v.Index})
resp := &pb.GetDevicesResponse{ClientId:t.Id,Devices:devices}
if req.GetReactorId() > 0 || req.GetRefresh() {
logging.Debug(logging.DClient,"TMA %v client requested devs from %v",t.Id,req.GetReactorId())
resp.ReactorId = req.GetReactorId()
t.StatusMon.UpdateListener(t.Id, req.GetReactorId())
}
devs := t.StatusMon.GetBuffer() // always empty buffer
if rid != 0 {
// need reactor devices
devs := t.SystemViewer.GetDeviceStatus(rid)
for _, v := range devs {
resp.Devices = append(resp.Devices, &pb.Dev{Id:v.Id,Type:v.Type,Status:v.Status,Data:v.Data,Index:v.Index})
}
for _, v := range devs {
resp.Devices = append(resp.Devices, &pb.Dev{Id:v.Id,Type:v.Type,Status:v.Status,Data:v.Data,Index:v.Index})
}
if len(resp.Devices) > 0 {
logging.Debug(logging.DClient,"TMA %v sending %v devices to client" ,t.Id, len(resp.Devices))
}
logging.Debug(logging.DClient,"TMA %v sending devices to client" ,t.Id)
return resp, nil
}

@ -111,24 +111,21 @@ func (t *TUIClient) Connect() {
}
}
// going to redo this idk wtf i was thinking
// we just want a way to do two things
// a) get all devices when we first select a reactor
// b) ping the cs every 500ms-1s for updates and get back a list of devs that have changed
func (t *TUIClient) GetDevices(id ...uint32) (map[uint32]*Device, error) {
// returns
var rid uint32
if len(id) > 0 && id[0] != 0 {
rid = id[0]
req := &pb.GetDevicesRequest{ClientId:t.Id}
if len(id) > 0 {
if id[0] == 0 {
req.Refresh = true
} else {
req.ReactorId = id[0]
}
}
req := &pb.GetDevicesRequest{ClientId:t.Id,ReactorId:rid}
r := make(map[uint32]*Device)
client := pb.NewManagementClient(t.ClientConn)
resp, err := client.GetDevices(context.Background(), req)
if err != nil {
return r, nil
return r, err
}
for _, v := range resp.GetDevices() {
r[v.GetId()] = &Device{Type:v.GetType(),Status:v.GetStatus(),Id:v.GetId(),Data:v.GetData(),Index:v.GetIndex()}

@ -23,7 +23,6 @@ type Device struct {
type TUI struct {
*Display
//*LocalView
*TUIClient
SelectedReactor <-chan uint32
SelectedDevice <-chan uint32
@ -31,11 +30,7 @@ type TUI struct {
}
func NewTUI(ip string, port int, ifconfig string, ch chan error) *TUI {
//r := make(map[uint32]*Reactor)
t := &TUI{}
//l := new(LocalView)
//l.Reactors = r
//t.LocalView = l
t.Err = ch
client := NewTUIClient(ip, port, ifconfig)
t.TUIClient = client
@ -51,7 +46,6 @@ func (t *TUI) Start() {
go t.Monitor()
t.CreateDisplay()
t.Display.Start()
//go t.Refresh()
}
func (t *TUI) CreateDisplay() {
@ -61,7 +55,7 @@ func (t *TUI) CreateDisplay() {
t.SelectedReactor = rc
t.SelectedDevice = dc
t.Flex.AddItem(t.ReactorList,0,1,true).
AddItem(t.DevicePages,0,2,false)
AddItem(t.DeviceList,0,2,false)
}
func (t *TUI) Monitor() {
@ -82,11 +76,12 @@ func (t *TUI) Monitor() {
t.UpdateDevices(reactor)
})
logging.Debug(logging.DClient, "%v getting reactor devices", t.Id)
case <-t.SelectedDevice:
case dev := <-t.SelectedDevice:
logging.Debug(logging.DClient, "%v editing device %v", t.Id, dev)
// TODO
case <-timer:
// time to ping for status
logging.Debug(logging.DClient, "%v getting reactor status", t.Id)
logging.Debug(logging.DClient, "%v pinging for updates", t.Id)
t.App.QueueUpdateDraw(func() {
t.UpdateDevices()
})
@ -96,39 +91,42 @@ func (t *TUI) Monitor() {
func (t *TUI) UpdateDevices(r ...uint32) {
// get devices for the reactor and update the tui
var id uint32
// see if there is a page being displayed
if name, _ := t.Display.DevicePages.GetFrontPage(); name != "" {
if tmp, err := strconv.ParseUint(name, 10, 32); err != nil {
log.Fatal(err)
} else {
id = uint32(tmp)
}
}
// overwrite if called as a func
var devs map[uint32]*Device
var err error
if len(r) > 0 {
id = r[0]
// could be a reactor id or 1 for update reactors
if r[0] != 0 {
t.Display.DeviceList.Clear()
} else {
t.ReactorList.Clear()
t.ReactorList.AddItem("Refresh","Press (r) to refresh", 114, nil)
t.ReactorList.AddItem("Quit","Press (q) to quit",113,func() {
t.App.Stop()
os.Exit(0)
})
}
devs, err = t.TUIClient.GetDevices(r[0])
} else {
devs, err = t.TUIClient.GetDevices()
}
devs, err := t.TUIClient.GetDevices(id)
if err != nil {
log.Fatal(err)
}
if id != 0 {
// reactor specificed split devs
reactors := make(map[uint32]*Device)
devices := make(map[uint32]*Device)
for id, dev := range devs {
if dev.Type == "Reactor" {
reactors[id] = dev
} else {
devices[id] = dev
}
//if id != 0 {
// split based on type to simplify update
reactors := make(map[uint32]*Device)
devices := make(map[uint32]*Device)
for id, dev := range devs {
if dev.Type == "Reactor" {
reactors[id] = dev
} else {
devices[id] = dev
}
t.DisplayDevices(devices, id)
t.DisplayReactors(reactors)
} else {
t.DisplayReactors(devs)
}
t.DisplayDevices(devices)
t.DisplayReactors(reactors)
}
// display struct and logic
@ -136,8 +134,7 @@ type Display struct {
App *tview.Application
Flex *tview.Flex
ReactorList *tview.List
DevicePages *tview.Pages
DeviceList map[string]*tview.List
DeviceList *tview.List
SelectedReactor chan<- uint32
SelectedDevice chan<- uint32
sync.Mutex
@ -147,17 +144,17 @@ func NewDisplay(rc,dc chan uint32) *Display {
d := &Display{}
d.App = tview.NewApplication()
d.Flex = tview.NewFlex()
lists := make(map[string]*tview.List)
d.DeviceList = lists
d.ReactorList = tview.NewList()//.ShowSecondaryText(false)
d.DeviceList = tview.NewList().SetSelectedFocusOnly(true)
d.ReactorList = tview.NewList()
d.ReactorList.AddItem("Refresh","Press (r) to refresh manually", 114, nil)
d.ReactorList.AddItem("Quit","Press (q) to quit",113,func() {
d.App.Stop()
os.Exit(0)
})
d.DevicePages = tview.NewPages()
d.ReactorList.SetTitle("Reactors").SetBorder(true)
d.ReactorList.SetSelectedFunc(d.SelectReactor)
d.DevicePages.SetTitle("Devices").SetBorder(true)
d.DeviceList.SetTitle("Devices").SetBorder(true)
d.DeviceList.SetSelectedFunc(d.SelectDevice)
d.SelectedReactor = rc
d.SelectedDevice = dc
return d
@ -171,58 +168,64 @@ func (d *Display) Start() {
}
func (d *Display) DisplayReactors(r map[uint32]*Device) {
// function to display reactor list to table
//d.Lock()
//defer d.Unlock()
// locking may break the hell out of this gonna trust tview
// this func takes in a list of devices to update and loops over them
// works by padding list for entries not seen yet
for _, reactor := range r {
txt := fmt.Sprintf("%v %v", reactor.Id, reactor.Status)
if d.ReactorList.GetItemCount() > int(reactor.Index) + 1 {
d.ReactorList.RemoveItem(int(reactor.Index))
indx := int(reactor.Index)
for indx + 2 >= d.ReactorList.GetItemCount() {
// this prevent overwriting quit entry
d.ReactorList.InsertItem(-3,txt,reactor.Data,rune(47+d.ReactorList.GetItemCount()),nil)
}
if indx + 2 < d.ReactorList.GetItemCount() {
d.ReactorList.SetItemText(indx,txt,reactor.Data)
}
d.ReactorList.InsertItem(int(reactor.Index),txt,reactor.Data,rune(49+reactor.Index),nil)
}
}
func (d *Display) DisplayDevices(devs map[uint32]*Device, rid uint32) {
//d.Lock()
reactorPage := strconv.FormatUint(uint64(rid), 10)
var reactorList *tview.List
var ok bool
if reactorList, ok = d.DeviceList[reactorPage]; !ok {
reactorList = tview.NewList()//.ShowSecondaryText(false)
d.DeviceList[reactorPage] = reactorList
d.DevicePages.AddPage(reactorPage, reactorList, true, false)
}
//d.Unlock()
func (d *Display) DisplayDevices(devs map[uint32]*Device) {
// going to just clear every time as we reload new dev lists anyway
// going to clear on every reactor selection to simplify
// can probably just load from SM to save system resources on spam reloading
for _, dev := range devs {
txt := fmt.Sprintf("0x%x %v %v",dev.Id,dev.Status,dev.Type) // sensor alive at 0x0 data
if reactorList.GetItemCount() > int(dev.Index) {
reactorList.RemoveItem(int(dev.Index))
logging.Debug(logging.DClient,"Displaying device %v",dev)
txt := fmt.Sprintf("0x%x %v %v",dev.Id,dev.Status,dev.Type)
indx := int(dev.Index)
for indx >= d.DeviceList.GetItemCount() {
d.DeviceList.AddItem(txt,dev.Data,rune(49+d.DeviceList.GetItemCount()), nil)
}
if indx < d.DeviceList.GetItemCount() {
d.DeviceList.SetItemText(indx,txt,dev.Data)
}
reactorList.InsertItem(int(dev.Index),txt,dev.Data,0,nil)
}
d.DevicePages.SwitchToPage(reactorPage)
}
func (d *Display) SelectReactor(index int, main, data string, r rune) {
// called when reactor in list in selected
if main != "Quit" {
maintxt := strings.Split(main," ")
id := maintxt[0]
if id, err := strconv.ParseUint(id, 10, 32); err != nil {
log.Fatal(err)
if main == "Refresh" {
// TODO
} else {
d.SelectedReactor <-uint32(id)
maintxt := strings.Split(main," ")
id := maintxt[0]
if id, err := strconv.ParseUint(id, 10, 32); err != nil {
log.Fatal(err)
} else {
d.SelectedReactor <-uint32(id)
}
}
}
}
func (d *Display) SelectDevice(index int, main, id string, r rune) {
func (d *Display) SelectDevice(index int, main, data string, r rune) {
// called when device is selected in sub menu
if id, err := strconv.ParseUint(id, 10, 32); err != nil {
log.Fatal(err)
maintxt := strings.Split(main," ")
id := maintxt[0]
id = strings.Trim(id,"0x \n")
logging.Debug(logging.DClient,"Selected dev %v", id)
if id, err := strconv.ParseUint(id, 16, 32); err != nil {
logging.Debug(logging.DError, "Error parsing: %v", err)
os.Exit(1)
} else {
d.SelectedDevice <-uint32(id)
}

17
notes

@ -847,3 +847,20 @@ TUI - TUI Client
every debug message will be of format
topic, devcode: id
alright time to get this damn tui updating working
general implementation details
- libary card method
- only allow clients to checkout 1 device stream at a time (besides reactor stream obviously)
- close stream when call to open new one
- should we even store the reactor devices locally?
- or we could request when its selected and then let stream take care of itself
- simplifies a few things
- same setup for reactors/devices
- just call/create device listeners dynamically and reactor listeners at the start
- only check out reactor stream and 1 device stream at a time
- request for devices gets you the current state and adds your listener to the echo chain so that you recieve any updates
- need to ensure sends can complete even if the manager is dead
- close the channel?

@ -0,0 +1,42 @@
alright time to do this correctly because this is brutal
7/18
DM -> RLC -> RM -> Sys -> TM -> TC
this basic struct will guide us
Work backwards to start from what the TC wants and work to how to deliver
TC
- wants to know what the overall reactor status are and the associated device status on selection
- its OK if this is a bit out of date, but probably want a synchronized view between clients
- could be a performance hit but f it
TM
Needs to:
- provide up to date information about the reactors connected and know which reactor is selected and provide updates for it
Relies on
- Needs a central struct, 2 methods for data
- call on request to query for ir
- keep its own copy and empty its buffer on request
- this is probably the best route
So TM really needs an intermediate struct a sort of device buffer
- I like the thing we had before with the channels and embedding but it needs to be fleshed out
All of this resides on the server which we can use to our advantage
Lets flesh out the TM a bit more
TM sys struct
this struct will attach itself to a channel and buffer updates for that channel
has to have a few methods
- GetBuffer() returns any new entries and empties the buffer
- ListenTo(reactorID) starts listening to a reactor and returns any devices on that branch so the client can refresh its list
- Refresh() forces the client to get all reactors and devices if listening to any branch
NewSysMonitor() has to return struct and current client status to load fortui client
this client will be given to a TUI at creation
TUI can then call associated commands to get updates for the client
TM sys struct just relies on underlying sys implementation which seems to be working south of the RM so i am just going to work on this TM sys struct for now
Loading…
Cancel
Save