Added an ID to the devices

This commit is contained in:
2025-10-29 22:57:21 +00:00
parent da1fcf3dec
commit b2c0e35f51
4 changed files with 42 additions and 7 deletions
+4 -2
View File
@@ -36,7 +36,8 @@ func (s PeripheralDeviceState) String() string {
type PeripheralDevice struct {
State PeripheralDeviceState
CommState CommState
Name [32]byte
ID uint8
Name string
WT *WalkieTalkie
}
@@ -93,7 +94,8 @@ func (p *PeripheralDevice) ToConnectedIdling() {
}
func (p *PeripheralDevice) Merge(packet *IdentificationPacket) {
p.Name = packet.Name
p.Name = string(packet.Name[:])
p.ID = packet.DeviceID
}
func (p *PeripheralDevice) Disconnect() error {
+4
View File
@@ -7,6 +7,7 @@ import (
type IdentificationPacket struct {
StartMarker byte
DeviceID uint8
PktType PacketType
Name [32]byte
EndMarker byte
@@ -33,6 +34,9 @@ func (pkt *IdentificationPacket) Validate() bool {
fmt.Println(pkt.EndMarker)
fmt.Println("↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑")
// Change this to return an error and add a validation against available
// device ids
if pkt.StartMarker != startOfText ||
pkt.EndMarker != endOfText {
return false
+18 -1
View File
@@ -13,6 +13,7 @@ const (
)
type PeripheralDeviceClerk struct {
// mu sync.RWMutex
Devices map[string]*PeripheralDevice
}
@@ -54,11 +55,27 @@ func (clerk *PeripheralDeviceClerk) FindDevices() error {
fmt.Println(p, string(newDevice.Name[:]))
}
// go clerk.clerkBackgroundJob()
return nil
}
func (clerk *PeripheralDeviceClerk) ListDevices() error {
for _, d := range clerk.Devices {
fmt.Printf("[%d] %s\n", d.ID, d.Name)
}
return nil
}
// func (c *PeripheralDeviceClerk) clerkBackgroundJob() {
// for {
//
// c.mu.RLock()
// for _, d := range c.Devices {
// // Check the state of the device
// if d.CommState == CommIdle {
// }
// }
// c.mu.Unlock()
// }
// }