Fix ESP-NOW unicast by using sender MAC in client registry.
Register slaves from recv src_addr instead of protobuf mac bytes, add ESPNOW_UNICAST_TEST for path verification, restore unicast deadzone, and expose unicast-test in goTool. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"powerpod/gotool/pb"
|
||||
)
|
||||
|
||||
func runUnicastTest(sp *serialPort, args []string) error {
|
||||
fs := flag.NewFlagSet("unicast-test", flag.ExitOnError)
|
||||
clientID := fs.Uint("client", 0, "slave client id from `clients`")
|
||||
seq := fs.Uint("seq", 1, "test sequence number")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if *clientID == 0 {
|
||||
return fmt.Errorf("client id required (see `gotool clients`)")
|
||||
}
|
||||
|
||||
req := &pb.EspNowUnicastTestRequest{
|
||||
ClientId: uint32(*clientID),
|
||||
Seq: uint32(*seq),
|
||||
}
|
||||
msg := &pb.UartMessage{
|
||||
Type: pb.MessageType_ESPNOW_UNICAST_TEST,
|
||||
Payload: &pb.UartMessage_EspnowUnicastTestRequest{
|
||||
EspnowUnicastTestRequest: req,
|
||||
},
|
||||
}
|
||||
body, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("encode request: %w", err)
|
||||
}
|
||||
|
||||
payload := append([]byte{byte(pb.MessageType_ESPNOW_UNICAST_TEST)}, body...)
|
||||
respPayload, err := sp.exchangePayload(payload, "ESPNOW_UNICAST_TEST")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var respMsg pb.UartMessage
|
||||
if err := proto.Unmarshal(respPayload[1:], &respMsg); err != nil {
|
||||
return fmt.Errorf("decode response: %w", err)
|
||||
}
|
||||
|
||||
r := respMsg.GetEspnowUnicastTestResponse()
|
||||
if r == nil {
|
||||
return fmt.Errorf("response missing espnow_unicast_test_response")
|
||||
}
|
||||
|
||||
fmt.Printf("unicast test sent: success=%v seq=%d\n", r.GetSuccess(), r.GetSeq())
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user