build script tweaks and fixes to TUI client. Succesfully displays only changed device info

main
Keegan 3 years ago
parent 602c515205
commit 588ecc8275

@ -1,14 +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 -czvf pireactor.tar.gz -C bin reactor_linux_arm64
tar -czvf bbreactor.tar.gz -C bin reactor_linux_arm
tar -czvf server.tar.gz -C bin server_linux_amd64
tar -czvf tui.tar.gz -C bin tui_linux_amd64 tui_linux_arm tui_linux_arm64
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

@ -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)

@ -111,15 +111,10 @@ func (r *ReactorManager) Monitor(conn *grpc.ClientConn) {
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
}
}

@ -2,7 +2,7 @@ package server
import (
"sync"
"fmt"
_ "fmt"
"FRMS/internal/pkg/logging"
)
// allows for multiple readers/writers
@ -52,9 +52,9 @@ func NewStatusMonitor(t string, id uint32, sys *SystemViewer) *StatusMonitor {
} else {
// tui status monitor
sbuf := NewBuffer()
sm.ReactorChan, sbuf["Reactor"] = sys.AddListener(id,0)
//sm.ReactorChan, sbuf["Reactor"] = sys.AddListener(id,0)
sm.DevBuf = &devbuf{Buf:sbuf} // makes it easier to work with
go sm.Listen(sm.ReactorChan)
go sm.UpdateListener(id,0)
}
return sm
}
@ -70,7 +70,7 @@ func (s *StatusMonitor) GenerateIds() {
func (s *StatusMonitor) Send(d *DeviceInfo, dtype string) {
d.TransactionId = <-s.TransactionId
logging.Debug(logging.DClient,"SYS 01 Updating %s Info (%s, %s)", d.Type, d.Status, d.Data)
logging.Debug(logging.DClient,"SYS 01 Sending update for: %s (%s)", d.Type, d.Status)
if dtype == "Reactor" {
s.ReactorChan <-d
} else {
@ -83,6 +83,9 @@ func (s *StatusMonitor) GetBuffer() []*DeviceInfo {
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
@ -98,16 +101,18 @@ func (s *StatusMonitor) UpdateListener(tid, reactorId uint32) {
defer s.DevBuf.Unlock()
// clearing proper buffer
if reactorId == 0 {
s.DevBuf.Buf["Reactors"] = make(map[uint32]*DeviceInfo)
s.ReactorChan, s.DevBuf.Buf["Reactors"] = s.SystemViewer.AddListener(tid, reactorId)
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 {
s.DevBuf.Buf["Devices"] = make(map[uint32]*DeviceInfo) // clearing old devices
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["Devices"] = s.SystemViewer.AddListener(tid, reactorId)
s.DevChan, s.DevBuf.Buf["Device"] = s.SystemViewer.AddListener(tid, reactorId)
go s.Listen(s.DevChan)
}
}
@ -115,19 +120,19 @@ func (s *StatusMonitor) UpdateListener(tid, reactorId uint32) {
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
fmt.Printf("Old: %v,\nNew: %v \n", dev, d)
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
fmt.Printf("Old: %v,\nNew: %v \n", dev, d)
}
}
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 {
fmt.Printf("%v out of date\n",d)
logging.Debug(logging.DClient,"Dev out of date!")
}
}
@ -157,7 +162,6 @@ type listeners struct {
type lischan struct {
sync.WaitGroup
WaitChan chan struct{}
StatusChan chan *DeviceInfo
}
@ -167,6 +171,11 @@ 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}
@ -186,15 +195,14 @@ func (s *InfoStream) AddSender() chan *DeviceInfo {
}
func (s *InfoStream) Listen() {
for {
deviceInfo := <-s.Stream
for deviceInfo := range s.Stream {
go s.Update(deviceInfo)
go s.Echo(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
@ -222,14 +230,15 @@ func (s *InfoStream) AddListener(id uint32, ch chan *DeviceInfo) map[uint32]*Dev
// if i get a memory leak ill eat my shoe
s.listeners.Lock()
defer s.listeners.Unlock()
if lis, ok := s.listeners.Listeners[id]; ok {
if _, ok := s.listeners.Listeners[id]; ok {
// exists
go lis.Exit()
delete(s.listeners.Listeners,id)
go s.RemoveListener(id)
}
s.listeners.Listeners[id] = &lischan{StatusChan:ch}
s.Layout.RLock()
defer s.Layout.RUnlock()
s.listeners.Listeners[id] = NewLisChan(ch)
logging.Debug(logging.DClient,"SYS 01 Getting Devices")
//s.Layout.RLock()
//defer s.Layout.RUnlock()
logging.Debug(logging.DClient,"SYS 01 Returning Devices %v", s.Layout.Devs)
return s.Layout.Devs
}
@ -237,26 +246,14 @@ func (l *listeners) RemoveListener(id uint32) {
l.Lock()
defer l.Unlock()
if lis, ok := l.Listeners[id]; ok {
go func(){
lis.Wait()
close(lis.WaitChan)
}()
go lis.Exit()
delete(l.Listeners,id)
go func(ls *lischan){
ls.Wait()
close(ls.StatusChan)
}(lis)
}
}
func (l *lischan) Exit() {
for {
select {
case <-l.WaitChan:
close(l.StatusChan)
break;
case <-l.StatusChan:
// dump buffer
}
}
}
// status buffer maintaince
type SystemViewer struct {
@ -309,7 +306,7 @@ func (s *SystemViewer) AddListener(id, rid uint32) (chan *DeviceInfo, map[uint32
}
}
func (s *SystemViewer) RemoveListener(tid, rid uint32) {
func (s *SystemViewer) RemoveListener(rid, tid uint32) {
// removes chan for specific tid and rid
s.DeviceStream.Lock()
defer s.DeviceStream.Unlock()

@ -123,6 +123,7 @@ func (t *TUIManager) GetDevices(ctx context.Context, req *pb.GetDevicesRequest)
devices := []*pb.Dev{}
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())
}
@ -131,7 +132,9 @@ func (t *TUIManager) GetDevices(ctx context.Context, req *pb.GetDevicesRequest)
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})
}
logging.Debug(logging.DClient,"TMA %v sending %v devices to client" ,t.Id, len(resp.Devices))
if len(resp.Devices) > 0 {
logging.Debug(logging.DClient,"TMA %v sending %v devices to client" ,t.Id, len(resp.Devices))
}
return resp, nil
}

@ -144,7 +144,7 @@ func NewDisplay(rc,dc chan uint32) *Display {
d := &Display{}
d.App = tview.NewApplication()
d.Flex = tview.NewFlex()
d.DeviceList = tview.NewList()
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() {
@ -188,6 +188,7 @@ func (d *Display) DisplayDevices(devs map[uint32]*Device) {
// 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 {
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() {

Loading…
Cancel
Save