From da1fcf3dec9c1ee4a5250e7dcf6f2fe2ab4323db Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Wed, 29 Oct 2025 22:23:58 +0000 Subject: [PATCH] Fix of a very stoopid mistake --- peripheral/device.go | 2 +- peripheral/identificationPacket.go | 4 +--- peripheral/peripheral.go | 29 ++++++++++++++++++++--------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/peripheral/device.go b/peripheral/device.go index 277a5b0..4798294 100644 --- a/peripheral/device.go +++ b/peripheral/device.go @@ -57,7 +57,7 @@ func NewPeripheralDevice(port string) *PeripheralDevice { func (p *PeripheralDevice) Probe() error { err := p.WT.TurnOn() if err != nil { - return nil + return err } // Papers, please! diff --git a/peripheral/identificationPacket.go b/peripheral/identificationPacket.go index 538f512..b1b771c 100644 --- a/peripheral/identificationPacket.go +++ b/peripheral/identificationPacket.go @@ -13,15 +13,13 @@ type IdentificationPacket struct { } func (pkt *IdentificationPacket) Read(wt *WalkieTalkie) error { - fmt.Println("Reading framed data") - err := wt.ReadFramedData(binary.Size(IdentificationPacket{}), pkt) if err != nil { return err } if !pkt.Validate() { - return fmt.Errorf("invalid packet") + return fmt.Errorf("invalid data") } return nil diff --git a/peripheral/peripheral.go b/peripheral/peripheral.go index db99c4e..fa4e3fe 100644 --- a/peripheral/peripheral.go +++ b/peripheral/peripheral.go @@ -13,11 +13,13 @@ const ( ) type PeripheralDeviceClerk struct { - // Devices map[string]PeripheralDevice + Devices map[string]*PeripheralDevice } func NewPeripheralDeviceClerk() *PeripheralDeviceClerk { - return &PeripheralDeviceClerk{} + return &PeripheralDeviceClerk{ + Devices: make(map[string]*PeripheralDevice), + } } func (clerk *PeripheralDeviceClerk) listPorts() ([]string, error) { @@ -29,6 +31,10 @@ func (clerk *PeripheralDeviceClerk) listPorts() ([]string, error) { return ttyUSBs, nil } +func (clerk *PeripheralDeviceClerk) addDevice(dev *PeripheralDevice) { + clerk.Devices[string(dev.Name[:])] = dev +} + func (clerk *PeripheralDeviceClerk) FindDevices() error { ports, err := clerk.listPorts() if err != nil { @@ -37,17 +43,22 @@ func (clerk *PeripheralDeviceClerk) FindDevices() error { for _, p := range ports { newDevice := NewPeripheralDevice(p) - err := newDevice.Probe() - var msg string - if err == nil { - msg = string(newDevice.Name[:]) - } else { - msg = err.Error() + err := newDevice.Probe() + if err != nil { + fmt.Println(p, err.Error()) + continue } - fmt.Println(p, msg) + clerk.addDevice(newDevice) + fmt.Println(p, string(newDevice.Name[:])) } return nil } + +// func (c *PeripheralDeviceClerk) clerkBackgroundJob() { +// for { +// +// } +// }