Assign sequential pod IDs from the master with NVS-stable bindings.
Replaces MAC-byte self-IDs with master allocation (1–255), slave preferred-ID reconnect, debug reset via UART/UI, and rate-limited ASSIGN to avoid ESP-NOW NO_MEM storms. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"powerpod/gotool/pb"
|
||||
)
|
||||
|
||||
func runClientsResetIds(sp *serialPort) error {
|
||||
resp, err := sp.resetClientIdMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !resp.GetSuccess() {
|
||||
return fmt.Errorf("client id map reset rejected")
|
||||
}
|
||||
fmt.Println("client id map cleared (master map + live registry; online slaves notified)")
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeClientIdMapResetPayload(payload []byte) (*pb.ClientIdMapResetResponse, error) {
|
||||
if len(payload) < 2 {
|
||||
return nil, fmt.Errorf("short client id map reset response")
|
||||
}
|
||||
if payload[0] != byte(pb.MessageType_CLIENT_ID_MAP_RESET) {
|
||||
return nil, fmt.Errorf("unexpected command id 0x%02x (want 0x%02x)",
|
||||
payload[0], byte(pb.MessageType_CLIENT_ID_MAP_RESET))
|
||||
}
|
||||
var respMsg pb.UartMessage
|
||||
if err := proto.Unmarshal(payload[1:], &respMsg); err != nil {
|
||||
return nil, fmt.Errorf("decode: %w", err)
|
||||
}
|
||||
r := respMsg.GetClientIdMapResetResponse()
|
||||
if r == nil {
|
||||
return nil, fmt.Errorf("missing client_id_map_reset_response")
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (s *serialPort) resetClientIdMap() (*pb.ClientIdMapResetResponse, error) {
|
||||
payload, err := s.exchange(byte(pb.MessageType_CLIENT_ID_MAP_RESET), "CLIENT_ID_MAP_RESET")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return decodeClientIdMapResetPayload(payload)
|
||||
}
|
||||
|
||||
func (m *managedSerial) resetClientIdMap() (*pb.ClientIdMapResetResponse, error) {
|
||||
payload, err := m.exchange(byte(pb.MessageType_CLIENT_ID_MAP_RESET), "CLIENT_ID_MAP_RESET")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return decodeClientIdMapResetPayload(payload)
|
||||
}
|
||||
Reference in New Issue
Block a user