logger fixes on cdashdisplay device implementation
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"esdi/logger"
|
||||
esdi "esdi/oldEsdi"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func liveTelemetryCmdAction(cmd *cobra.Command, args []string) {
|
||||
log := logger.GetInstance()
|
||||
|
||||
ddPort, _ := cmd.Flags().GetString("port")
|
||||
outputFile, _ := cmd.Flags().GetString("out")
|
||||
sessionFile, _ := cmd.Flags().GetString("session")
|
||||
|
||||
log.Printf("Called `live`:\nPort: '%s'\nOutFile: '%s'\n", ddPort, outputFile)
|
||||
// log.Printf("Called `live`:\nPort: '%s'\nOutFile: '%s'\n", ddPort, outputFile)
|
||||
|
||||
esdi.RunLiveTelemetry(ddPort, outputFile, sessionFile)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"esdi/logger"
|
||||
esdi "esdi/oldEsdi"
|
||||
|
||||
// "github.com/ESilva15/goirsdk"
|
||||
@@ -10,14 +9,14 @@ import (
|
||||
)
|
||||
|
||||
func offlineTelemetryCmdAction(cmd *cobra.Command, args []string) {
|
||||
log := logger.GetInstance()
|
||||
// log := logger.GetInstance()
|
||||
|
||||
ddPort, _ := cmd.Flags().GetString("port")
|
||||
inFile, _ := cmd.Flags().GetString("in")
|
||||
outFile, _ := cmd.Flags().GetString("out")
|
||||
sessionFile, _ := cmd.Flags().GetString("session")
|
||||
|
||||
log.Printf("Called `offline`:\nPort: '%s'\nSource: '%s'\nOutFile: '%s'\n", ddPort, inFile, outFile)
|
||||
// log.Printf("Called `offline`:\nPort: '%s'\nSource: '%s'\nOutFile: '%s'\n", ddPort, inFile, outFile)
|
||||
|
||||
esdi.RunOfflineTelemetry(ddPort, inFile, outFile, sessionFile)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package cdashdisplay
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"esdi/peripheral/communication"
|
||||
"esdi/peripheral/communication/packets"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/tarm/serial"
|
||||
portp "go.bug.st/serial"
|
||||
@@ -46,11 +48,11 @@ func findDisplayPort() (*communication.WalkieTalkie, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pLogger.Info(fmt.Sprintf("Looking into %v", ports))
|
||||
slog.Info(fmt.Sprintf("Looking into %v", ports))
|
||||
|
||||
var wt *communication.WalkieTalkie
|
||||
for _, port := range ports {
|
||||
pLogger.Info(fmt.Sprintf("Trying port %s", port))
|
||||
slog.Info(fmt.Sprintf("Trying port %s", port))
|
||||
|
||||
wt = &communication.WalkieTalkie{
|
||||
Cfg: &serial.Config{
|
||||
@@ -60,7 +62,7 @@ func findDisplayPort() (*communication.WalkieTalkie, error) {
|
||||
},
|
||||
}
|
||||
|
||||
pLogger.Info(fmt.Sprintf("Started probing port %s", port))
|
||||
slog.Info(fmt.Sprintf("Started probing port %s", port))
|
||||
|
||||
probeResult := make(chan error, 1)
|
||||
|
||||
@@ -76,14 +78,14 @@ func findDisplayPort() (*communication.WalkieTalkie, error) {
|
||||
err = fmt.Errorf("probe completely hung/timed out: %s", port)
|
||||
}
|
||||
|
||||
pLogger.Info(fmt.Sprintf("Finished probing port %s", port))
|
||||
slog.Info(fmt.Sprintf("Finished probing port %s", port))
|
||||
|
||||
if err == nil {
|
||||
pLogger.Info(fmt.Sprintf("Success probing port %s: %+v", port, err))
|
||||
slog.Info(fmt.Sprintf("Success probing port %s: %+v", port, err))
|
||||
break
|
||||
}
|
||||
|
||||
pLogger.Info(fmt.Sprintf("wasn't port %s", port))
|
||||
slog.Info(fmt.Sprintf("wasn't port %s", port))
|
||||
wt = nil
|
||||
}
|
||||
|
||||
@@ -91,6 +93,6 @@ func findDisplayPort() (*communication.WalkieTalkie, error) {
|
||||
return nil, fmt.Errorf("couldn't find cdashdisplay")
|
||||
}
|
||||
|
||||
pLogger.Info(fmt.Sprintf("found cdashdisplay on port: %s", wt.Cfg.Name))
|
||||
slog.Info(fmt.Sprintf("found cdashdisplay on port: %s", wt.Cfg.Name))
|
||||
return wt, nil
|
||||
}
|
||||
|
||||
@@ -19,13 +19,6 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// TODO: remove this logger. It should be on the device struct
|
||||
var pLogger *slog.Logger
|
||||
|
||||
func SetLogger(l *slog.Logger) {
|
||||
pLogger = l
|
||||
}
|
||||
|
||||
// I have to move this to some kind of configuration place
|
||||
const (
|
||||
layoutsDir = "./layouts/"
|
||||
@@ -118,11 +111,11 @@ type CDashDisplay struct {
|
||||
}
|
||||
|
||||
// Connect will try to find and connect to the CDashDisplay
|
||||
func Discover() (*CDashDisplay, error) {
|
||||
func NewCDashDisplay() (*CDashDisplay, error) {
|
||||
// Look for the port
|
||||
p, err := findDisplayPort()
|
||||
if err != nil {
|
||||
pLogger.Info("failed to find cdashdisplay port: %s", err.Error())
|
||||
slog.Info("failed to find cdashdisplay port: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -150,7 +143,7 @@ func (d *CDashDisplay) CreateWindow(win *DesktopUIWindow) (*DesktopUIWindow, err
|
||||
|
||||
win.UIData.IDX = wID.ID
|
||||
|
||||
pLogger.Info(fmt.Sprintf("Recived ID message: %v", wID))
|
||||
slog.Info(fmt.Sprintf("Recived ID message: %v", wID))
|
||||
|
||||
d.State.Layout.AddWindow(win)
|
||||
|
||||
@@ -178,9 +171,9 @@ func (d *CDashDisplay) UpdateWindow(win *DesktopUIWindow) error {
|
||||
// I get it and update it in the controller
|
||||
// I send the pointer here
|
||||
// -> it should be the same pointer then right?
|
||||
pLogger.Debug(fmt.Sprintf("PreUpdate ID: %p", win))
|
||||
slog.Debug(fmt.Sprintf("PreUpdate ID: %p", win))
|
||||
d.State.Layout.Windows[win.UIData.IDX] = win
|
||||
pLogger.Debug(fmt.Sprintf("PostUpdate ID: %p", win))
|
||||
slog.Debug(fmt.Sprintf("PostUpdate ID: %p", win))
|
||||
// Yeah, same address as suspected
|
||||
// I can't think about it right now. I'll think about that tomorrow
|
||||
|
||||
@@ -213,7 +206,7 @@ func (d *CDashDisplay) DestroyWindow(wID int16) error {
|
||||
}
|
||||
|
||||
func (d *CDashDisplay) updateWindowDimensions(win *UIWindow, packet UpdateDimsPacket) error {
|
||||
pLogger.Debug(fmt.Sprintf("UPDATE: %v", packet))
|
||||
slog.Debug(fmt.Sprintf("UPDATE: %v", packet))
|
||||
|
||||
bytes, err := helper.StructToBytes(packet)
|
||||
if err != nil {
|
||||
@@ -227,9 +220,9 @@ func (d *CDashDisplay) updateWindowDimensions(win *UIWindow, packet UpdateDimsPa
|
||||
}
|
||||
|
||||
// Nothing bad happened afaik
|
||||
pLogger.Debug(fmt.Sprintf("cur dims: %v", win.Dims))
|
||||
slog.Debug(fmt.Sprintf("cur dims: %v", win.Dims))
|
||||
win.Dims = packet.Dims
|
||||
pLogger.Debug(fmt.Sprintf("new dims: %v", win.Dims))
|
||||
slog.Debug(fmt.Sprintf("new dims: %v", win.Dims))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -345,18 +338,18 @@ func (d *CDashDisplay) LoadLayout(layoutName string) error {
|
||||
func (d *CDashDisplay) UnloadLayout() error {
|
||||
var err error
|
||||
for _, w := range d.State.Layout.Windows {
|
||||
pLogger.Debug(fmt.Sprintf("= Removing %d ==============================================",
|
||||
slog.Debug(fmt.Sprintf("= Removing %d ==============================================",
|
||||
w.UIData.IDX))
|
||||
|
||||
err = d.DestroyWindow(w.UIData.IDX)
|
||||
time.Sleep(75 * time.Millisecond)
|
||||
if err != nil {
|
||||
pLogger.Error(fmt.Sprintf("failed to destroy window: %+v", err))
|
||||
slog.Error(fmt.Sprintf("failed to destroy window: %+v", err))
|
||||
// NOTE: Add a way to handle multiple errors ?
|
||||
return err
|
||||
}
|
||||
|
||||
pLogger.Debug(fmt.Sprintf("= Removing %d ==============================================",
|
||||
slog.Debug(fmt.Sprintf("= Removing %d ==============================================",
|
||||
w.UIData.IDX))
|
||||
}
|
||||
|
||||
@@ -378,7 +371,7 @@ func (d *CDashDisplay) SendData(data *telemetry.TelemetryData) {
|
||||
curStr += fmt.Sprintf("%02x ", byte)
|
||||
|
||||
if byteCount == 8 {
|
||||
// pLogger.Debug(curStr)
|
||||
// slog.Debug(curStr)
|
||||
curStr = ""
|
||||
byteCount = 0
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cdashdisplay
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
type LayoutTree struct {
|
||||
Windows map[int16]*DesktopUIWindow `yaml:"Windows"`
|
||||
@@ -13,13 +16,13 @@ func NewLayoutTree() *LayoutTree {
|
||||
}
|
||||
|
||||
func (l *LayoutTree) AddWindow(w *DesktopUIWindow) {
|
||||
pLogger.Debug(fmt.Sprintf("adding window '%d' - %v", w.UIData.IDX))
|
||||
slog.Debug(fmt.Sprintf("adding window '%d' - %v", w.UIData.IDX))
|
||||
l.Windows[w.UIData.IDX] = w
|
||||
pLogger.Debug(fmt.Sprintf("new map - %v", l.Windows))
|
||||
slog.Debug(fmt.Sprintf("new map - %v", l.Windows))
|
||||
}
|
||||
|
||||
func (l *LayoutTree) RemoveWindow(idx int16) {
|
||||
pLogger.Debug(fmt.Sprintf("removing window '%d'", idx))
|
||||
slog.Debug(fmt.Sprintf("removing window '%d'", idx))
|
||||
delete(l.Windows, idx)
|
||||
pLogger.Debug(fmt.Sprintf("new map - %v", l.Windows))
|
||||
slog.Debug(fmt.Sprintf("new map - %v", l.Windows))
|
||||
}
|
||||
|
||||
+7
-24
@@ -2,8 +2,6 @@
|
||||
package devices
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"esdi/devices/cdashdisplay"
|
||||
"esdi/devices/uidevice"
|
||||
"esdi/peripheral"
|
||||
@@ -35,26 +33,11 @@ func DiscoverUIDevice() (peripheral.Peripheral, error) {
|
||||
}
|
||||
|
||||
func DiscoverCDashDisplay() (peripheral.Peripheral, error) {
|
||||
// // Find CDashDisplay
|
||||
// {
|
||||
// ds.Messages <- "looking for " + cdashdisplay.Name + "...\n"
|
||||
// ds.Logger.Info("Looking for " + cdashdisplay.Name)
|
||||
//
|
||||
// cdashdisplay.SetLogger(ds.Logger.With("[device]", cdashdisplay.Name))
|
||||
//
|
||||
// // Create a cdashdisplay
|
||||
// display, err := cdashdisplay.Discover()
|
||||
// if err == nil {
|
||||
// ds.Devices[cdashdisplay.Name] = display
|
||||
// ds.Logger.Info("found " + cdashdisplay.Name + " on: " + display.WT.Cfg.Name)
|
||||
// ds.Messages <- "found " + cdashdisplay.Name + " on: " + display.WT.Cfg.Name + "\n"
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// ds.Logger.Info("didn't find " + cdashdisplay.Name)
|
||||
// ds.Messages <- "didn't find " + cdashdisplay.Name + "\n"
|
||||
// // No CDashDisplay available for one reason or another, so we don't set the
|
||||
// // key
|
||||
// }
|
||||
return nil, errors.New("not implemented yet")
|
||||
// Create a cdashdisplay
|
||||
display, err := cdashdisplay.NewCDashDisplay()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return display, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user