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:
simon 2026-05-18 23:15:03 +02:00
parent ee38ce551a
commit 241e82b35b
20 changed files with 585 additions and 102 deletions

View File

@ -24,9 +24,16 @@ go run . -port /dev/ttyUSB0 clients
|---------|--------------|-------------|
| `version` | `0x03` | Prints `version` and `git_hash` from firmware |
| `clients` | `0x04` | Lists slaves registered on the master via ESP-NOW |
| `unicast-test` | `0x07` | Sends ESP-NOW unicast test to one slave (`-client`, `-seq`) |
`clients` requires slaves to have responded to master discover broadcasts first.
```bash
go run . -port /dev/ttyUSB0 unicast-test -client 16 -seq 42
```
On success the slave serial log should show `UNICAST TEST OK from master … seq=42`.
Example output:
```

56
goTool/cmd_unicast.go Normal file
View File

@ -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
}

View File

@ -14,7 +14,8 @@ func usage() {
fmt.Fprintf(os.Stderr, "commands:\n")
fmt.Fprintf(os.Stderr, " version firmware version and git hash\n")
fmt.Fprintf(os.Stderr, " clients registered ESP-NOW slaves on the master\n")
fmt.Fprintf(os.Stderr, " deadzone get/set accelerometer deadzone (LSB)\n\n")
fmt.Fprintf(os.Stderr, " deadzone get/set accelerometer deadzone (LSB)\n")
fmt.Fprintf(os.Stderr, " unicast-test send ESP-NOW unicast test to one slave\n\n")
flag.PrintDefaults()
}
@ -44,6 +45,8 @@ func main() {
runErr = runClients(sp)
case "deadzone", "accel-deadzone":
runErr = runDeadzone(sp, flag.Args()[1:])
case "unicast-test", "unicast_test":
runErr = runUnicastTest(sp, flag.Args()[1:])
default:
fmt.Fprintf(os.Stderr, "unknown command %q\n\n", cmd)
usage()

View File

@ -24,18 +24,19 @@ const (
type MessageType int32
const (
MessageType_UNKNOWN MessageType = 0
MessageType_ACK MessageType = 1
MessageType_ECHO MessageType = 2
MessageType_VERSION MessageType = 3
MessageType_CLIENT_INFO MessageType = 4
MessageType_CLIENT_INPUT MessageType = 5
MessageType_ACCEL_DEADZONE MessageType = 6
MessageType_OTA_START MessageType = 16
MessageType_OTA_PAYLOAD MessageType = 17
MessageType_OTA_END MessageType = 18
MessageType_OTA_STATUS MessageType = 19
MessageType_OTA_START_ESPNOW MessageType = 20
MessageType_UNKNOWN MessageType = 0
MessageType_ACK MessageType = 1
MessageType_ECHO MessageType = 2
MessageType_VERSION MessageType = 3
MessageType_CLIENT_INFO MessageType = 4
MessageType_CLIENT_INPUT MessageType = 5
MessageType_ACCEL_DEADZONE MessageType = 6
MessageType_ESPNOW_UNICAST_TEST MessageType = 7
MessageType_OTA_START MessageType = 16
MessageType_OTA_PAYLOAD MessageType = 17
MessageType_OTA_END MessageType = 18
MessageType_OTA_STATUS MessageType = 19
MessageType_OTA_START_ESPNOW MessageType = 20
)
// Enum value maps for MessageType.
@ -48,6 +49,7 @@ var (
4: "CLIENT_INFO",
5: "CLIENT_INPUT",
6: "ACCEL_DEADZONE",
7: "ESPNOW_UNICAST_TEST",
16: "OTA_START",
17: "OTA_PAYLOAD",
18: "OTA_END",
@ -55,18 +57,19 @@ var (
20: "OTA_START_ESPNOW",
}
MessageType_value = map[string]int32{
"UNKNOWN": 0,
"ACK": 1,
"ECHO": 2,
"VERSION": 3,
"CLIENT_INFO": 4,
"CLIENT_INPUT": 5,
"ACCEL_DEADZONE": 6,
"OTA_START": 16,
"OTA_PAYLOAD": 17,
"OTA_END": 18,
"OTA_STATUS": 19,
"OTA_START_ESPNOW": 20,
"UNKNOWN": 0,
"ACK": 1,
"ECHO": 2,
"VERSION": 3,
"CLIENT_INFO": 4,
"CLIENT_INPUT": 5,
"ACCEL_DEADZONE": 6,
"ESPNOW_UNICAST_TEST": 7,
"OTA_START": 16,
"OTA_PAYLOAD": 17,
"OTA_END": 18,
"OTA_STATUS": 19,
"OTA_START_ESPNOW": 20,
}
)
@ -113,6 +116,8 @@ type UartMessage struct {
// *UartMessage_OtaStatus
// *UartMessage_AccelDeadzoneRequest
// *UartMessage_AccelDeadzoneResponse
// *UartMessage_EspnowUnicastTestRequest
// *UartMessage_EspnowUnicastTestResponse
Payload isUartMessage_Payload `protobuf_oneof:"payload"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@ -261,6 +266,24 @@ func (x *UartMessage) GetAccelDeadzoneResponse() *AccelDeadzoneResponse {
return nil
}
func (x *UartMessage) GetEspnowUnicastTestRequest() *EspNowUnicastTestRequest {
if x != nil {
if x, ok := x.Payload.(*UartMessage_EspnowUnicastTestRequest); ok {
return x.EspnowUnicastTestRequest
}
}
return nil
}
func (x *UartMessage) GetEspnowUnicastTestResponse() *EspNowUnicastTestResponse {
if x != nil {
if x, ok := x.Payload.(*UartMessage_EspnowUnicastTestResponse); ok {
return x.EspnowUnicastTestResponse
}
}
return nil
}
type isUartMessage_Payload interface {
isUartMessage_Payload()
}
@ -309,6 +332,14 @@ type UartMessage_AccelDeadzoneResponse struct {
AccelDeadzoneResponse *AccelDeadzoneResponse `protobuf:"bytes,12,opt,name=accel_deadzone_response,json=accelDeadzoneResponse,proto3,oneof"`
}
type UartMessage_EspnowUnicastTestRequest struct {
EspnowUnicastTestRequest *EspNowUnicastTestRequest `protobuf:"bytes,13,opt,name=espnow_unicast_test_request,json=espnowUnicastTestRequest,proto3,oneof"`
}
type UartMessage_EspnowUnicastTestResponse struct {
EspnowUnicastTestResponse *EspNowUnicastTestResponse `protobuf:"bytes,14,opt,name=espnow_unicast_test_response,json=espnowUnicastTestResponse,proto3,oneof"`
}
func (*UartMessage_AckPayload) isUartMessage_Payload() {}
func (*UartMessage_EchoPayload) isUartMessage_Payload() {}
@ -331,6 +362,10 @@ func (*UartMessage_AccelDeadzoneRequest) isUartMessage_Payload() {}
func (*UartMessage_AccelDeadzoneResponse) isUartMessage_Payload() {}
func (*UartMessage_EspnowUnicastTestRequest) isUartMessage_Payload() {}
func (*UartMessage_EspnowUnicastTestResponse) isUartMessage_Payload() {}
type Ack struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
@ -850,6 +885,110 @@ func (x *AccelDeadzoneResponse) GetSlavesUpdated() uint32 {
return 0
}
type EspNowUnicastTestRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
Seq uint32 `protobuf:"varint,2,opt,name=seq,proto3" json:"seq,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *EspNowUnicastTestRequest) Reset() {
*x = EspNowUnicastTestRequest{}
mi := &file_uart_messages_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *EspNowUnicastTestRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EspNowUnicastTestRequest) ProtoMessage() {}
func (x *EspNowUnicastTestRequest) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[10]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use EspNowUnicastTestRequest.ProtoReflect.Descriptor instead.
func (*EspNowUnicastTestRequest) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{10}
}
func (x *EspNowUnicastTestRequest) GetClientId() uint32 {
if x != nil {
return x.ClientId
}
return 0
}
func (x *EspNowUnicastTestRequest) GetSeq() uint32 {
if x != nil {
return x.Seq
}
return 0
}
type EspNowUnicastTestResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
Seq uint32 `protobuf:"varint,2,opt,name=seq,proto3" json:"seq,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *EspNowUnicastTestResponse) Reset() {
*x = EspNowUnicastTestResponse{}
mi := &file_uart_messages_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *EspNowUnicastTestResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EspNowUnicastTestResponse) ProtoMessage() {}
func (x *EspNowUnicastTestResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[11]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use EspNowUnicastTestResponse.ProtoReflect.Descriptor instead.
func (*EspNowUnicastTestResponse) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{11}
}
func (x *EspNowUnicastTestResponse) GetSuccess() bool {
if x != nil {
return x.Success
}
return false
}
func (x *EspNowUnicastTestResponse) GetSeq() uint32 {
if x != nil {
return x.Seq
}
return 0
}
type OtaStartPayload struct {
state protoimpl.MessageState `protogen:"open.v1"`
TotalSize uint32 `protobuf:"varint,1,opt,name=total_size,json=totalSize,proto3" json:"total_size,omitempty"`
@ -860,7 +999,7 @@ type OtaStartPayload struct {
func (x *OtaStartPayload) Reset() {
*x = OtaStartPayload{}
mi := &file_uart_messages_proto_msgTypes[10]
mi := &file_uart_messages_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -872,7 +1011,7 @@ func (x *OtaStartPayload) String() string {
func (*OtaStartPayload) ProtoMessage() {}
func (x *OtaStartPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[10]
mi := &file_uart_messages_proto_msgTypes[12]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -885,7 +1024,7 @@ func (x *OtaStartPayload) ProtoReflect() protoreflect.Message {
// Deprecated: Use OtaStartPayload.ProtoReflect.Descriptor instead.
func (*OtaStartPayload) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{10}
return file_uart_messages_proto_rawDescGZIP(), []int{12}
}
func (x *OtaStartPayload) GetTotalSize() uint32 {
@ -913,7 +1052,7 @@ type OtaPayload struct {
func (x *OtaPayload) Reset() {
*x = OtaPayload{}
mi := &file_uart_messages_proto_msgTypes[11]
mi := &file_uart_messages_proto_msgTypes[13]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -925,7 +1064,7 @@ func (x *OtaPayload) String() string {
func (*OtaPayload) ProtoMessage() {}
func (x *OtaPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[11]
mi := &file_uart_messages_proto_msgTypes[13]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -938,7 +1077,7 @@ func (x *OtaPayload) ProtoReflect() protoreflect.Message {
// Deprecated: Use OtaPayload.ProtoReflect.Descriptor instead.
func (*OtaPayload) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{11}
return file_uart_messages_proto_rawDescGZIP(), []int{13}
}
func (x *OtaPayload) GetBlockId() uint32 {
@ -971,7 +1110,7 @@ type OtaEndPayload struct {
func (x *OtaEndPayload) Reset() {
*x = OtaEndPayload{}
mi := &file_uart_messages_proto_msgTypes[12]
mi := &file_uart_messages_proto_msgTypes[14]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -983,7 +1122,7 @@ func (x *OtaEndPayload) String() string {
func (*OtaEndPayload) ProtoMessage() {}
func (x *OtaEndPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[12]
mi := &file_uart_messages_proto_msgTypes[14]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -996,7 +1135,7 @@ func (x *OtaEndPayload) ProtoReflect() protoreflect.Message {
// Deprecated: Use OtaEndPayload.ProtoReflect.Descriptor instead.
func (*OtaEndPayload) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{12}
return file_uart_messages_proto_rawDescGZIP(), []int{14}
}
func (x *OtaEndPayload) GetStatus() uint32 {
@ -1015,7 +1154,7 @@ type OtaStatusPayload struct {
func (x *OtaStatusPayload) Reset() {
*x = OtaStatusPayload{}
mi := &file_uart_messages_proto_msgTypes[13]
mi := &file_uart_messages_proto_msgTypes[15]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1027,7 +1166,7 @@ func (x *OtaStatusPayload) String() string {
func (*OtaStatusPayload) ProtoMessage() {}
func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[13]
mi := &file_uart_messages_proto_msgTypes[15]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1040,7 +1179,7 @@ func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message {
// Deprecated: Use OtaStatusPayload.ProtoReflect.Descriptor instead.
func (*OtaStatusPayload) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{13}
return file_uart_messages_proto_rawDescGZIP(), []int{15}
}
func (x *OtaStatusPayload) GetStatus() uint32 {
@ -1054,7 +1193,7 @@ var File_uart_messages_proto protoreflect.FileDescriptor
const file_uart_messages_proto_rawDesc = "" +
"\n" +
"\x13uart_messages.proto\x12\x04alox\"\x87\x06\n" +
"\x13uart_messages.proto\x12\x04alox\"\xcc\a\n" +
"\vUartMessage\x12%\n" +
"\x04type\x18\x01 \x01(\x0e2\x11.alox.MessageTypeR\x04type\x12,\n" +
"\vack_payload\x18\x02 \x01(\v2\t.alox.AckH\x00R\n" +
@ -1071,7 +1210,9 @@ const file_uart_messages_proto_rawDesc = "" +
"ota_status\x18\n" +
" \x01(\v2\x16.alox.OtaStatusPayloadH\x00R\totaStatus\x12R\n" +
"\x16accel_deadzone_request\x18\v \x01(\v2\x1a.alox.AccelDeadzoneRequestH\x00R\x14accelDeadzoneRequest\x12U\n" +
"\x17accel_deadzone_response\x18\f \x01(\v2\x1b.alox.AccelDeadzoneResponseH\x00R\x15accelDeadzoneResponseB\t\n" +
"\x17accel_deadzone_response\x18\f \x01(\v2\x1b.alox.AccelDeadzoneResponseH\x00R\x15accelDeadzoneResponse\x12_\n" +
"\x1bespnow_unicast_test_request\x18\r \x01(\v2\x1e.alox.EspNowUnicastTestRequestH\x00R\x18espnowUnicastTestRequest\x12b\n" +
"\x1cespnow_unicast_test_response\x18\x0e \x01(\v2\x1f.alox.EspNowUnicastTestResponseH\x00R\x19espnowUnicastTestResponseB\t\n" +
"\apayload\"\x05\n" +
"\x03Ack\"!\n" +
"\vEchoPayload\x12\x12\n" +
@ -1107,7 +1248,13 @@ const file_uart_messages_proto_rawDesc = "" +
"\bdeadzone\x18\x01 \x01(\rR\bdeadzone\x12\x1b\n" +
"\tclient_id\x18\x02 \x01(\rR\bclientId\x12\x18\n" +
"\asuccess\x18\x03 \x01(\bR\asuccess\x12%\n" +
"\x0eslaves_updated\x18\x04 \x01(\rR\rslavesUpdated\"O\n" +
"\x0eslaves_updated\x18\x04 \x01(\rR\rslavesUpdated\"I\n" +
"\x18EspNowUnicastTestRequest\x12\x1b\n" +
"\tclient_id\x18\x01 \x01(\rR\bclientId\x12\x10\n" +
"\x03seq\x18\x02 \x01(\rR\x03seq\"G\n" +
"\x19EspNowUnicastTestResponse\x12\x18\n" +
"\asuccess\x18\x01 \x01(\bR\asuccess\x12\x10\n" +
"\x03seq\x18\x02 \x01(\rR\x03seq\"O\n" +
"\x0fOtaStartPayload\x12\x1d\n" +
"\n" +
"total_size\x18\x01 \x01(\rR\ttotalSize\x12\x1d\n" +
@ -1121,7 +1268,7 @@ const file_uart_messages_proto_rawDesc = "" +
"\rOtaEndPayload\x12\x16\n" +
"\x06status\x18\x01 \x01(\rR\x06status\"*\n" +
"\x10OtaStatusPayload\x12\x16\n" +
"\x06status\x18\x01 \x01(\rR\x06status*\xc4\x01\n" +
"\x06status\x18\x01 \x01(\rR\x06status*\xdd\x01\n" +
"\vMessageType\x12\v\n" +
"\aUNKNOWN\x10\x00\x12\a\n" +
"\x03ACK\x10\x01\x12\b\n" +
@ -1129,7 +1276,8 @@ const file_uart_messages_proto_rawDesc = "" +
"\aVERSION\x10\x03\x12\x0f\n" +
"\vCLIENT_INFO\x10\x04\x12\x10\n" +
"\fCLIENT_INPUT\x10\x05\x12\x12\n" +
"\x0eACCEL_DEADZONE\x10\x06\x12\r\n" +
"\x0eACCEL_DEADZONE\x10\x06\x12\x17\n" +
"\x13ESPNOW_UNICAST_TEST\x10\a\x12\r\n" +
"\tOTA_START\x10\x10\x12\x0f\n" +
"\vOTA_PAYLOAD\x10\x11\x12\v\n" +
"\aOTA_END\x10\x12\x12\x0e\n" +
@ -1150,23 +1298,25 @@ func file_uart_messages_proto_rawDescGZIP() []byte {
}
var file_uart_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 14)
var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 16)
var file_uart_messages_proto_goTypes = []any{
(MessageType)(0), // 0: alox.MessageType
(*UartMessage)(nil), // 1: alox.UartMessage
(*Ack)(nil), // 2: alox.Ack
(*EchoPayload)(nil), // 3: alox.EchoPayload
(*VersionResponse)(nil), // 4: alox.VersionResponse
(*ClientInfo)(nil), // 5: alox.ClientInfo
(*ClientInfoResponse)(nil), // 6: alox.ClientInfoResponse
(*ClientInput)(nil), // 7: alox.ClientInput
(*ClientInputResponse)(nil), // 8: alox.ClientInputResponse
(*AccelDeadzoneRequest)(nil), // 9: alox.AccelDeadzoneRequest
(*AccelDeadzoneResponse)(nil), // 10: alox.AccelDeadzoneResponse
(*OtaStartPayload)(nil), // 11: alox.OtaStartPayload
(*OtaPayload)(nil), // 12: alox.OtaPayload
(*OtaEndPayload)(nil), // 13: alox.OtaEndPayload
(*OtaStatusPayload)(nil), // 14: alox.OtaStatusPayload
(MessageType)(0), // 0: alox.MessageType
(*UartMessage)(nil), // 1: alox.UartMessage
(*Ack)(nil), // 2: alox.Ack
(*EchoPayload)(nil), // 3: alox.EchoPayload
(*VersionResponse)(nil), // 4: alox.VersionResponse
(*ClientInfo)(nil), // 5: alox.ClientInfo
(*ClientInfoResponse)(nil), // 6: alox.ClientInfoResponse
(*ClientInput)(nil), // 7: alox.ClientInput
(*ClientInputResponse)(nil), // 8: alox.ClientInputResponse
(*AccelDeadzoneRequest)(nil), // 9: alox.AccelDeadzoneRequest
(*AccelDeadzoneResponse)(nil), // 10: alox.AccelDeadzoneResponse
(*EspNowUnicastTestRequest)(nil), // 11: alox.EspNowUnicastTestRequest
(*EspNowUnicastTestResponse)(nil), // 12: alox.EspNowUnicastTestResponse
(*OtaStartPayload)(nil), // 13: alox.OtaStartPayload
(*OtaPayload)(nil), // 14: alox.OtaPayload
(*OtaEndPayload)(nil), // 15: alox.OtaEndPayload
(*OtaStatusPayload)(nil), // 16: alox.OtaStatusPayload
}
var file_uart_messages_proto_depIdxs = []int32{
0, // 0: alox.UartMessage.type:type_name -> alox.MessageType
@ -1175,19 +1325,21 @@ var file_uart_messages_proto_depIdxs = []int32{
4, // 3: alox.UartMessage.version_response:type_name -> alox.VersionResponse
6, // 4: alox.UartMessage.client_info_response:type_name -> alox.ClientInfoResponse
8, // 5: alox.UartMessage.client_input_response:type_name -> alox.ClientInputResponse
11, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload
12, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload
13, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload
14, // 9: alox.UartMessage.ota_status:type_name -> alox.OtaStatusPayload
13, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload
14, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload
15, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload
16, // 9: alox.UartMessage.ota_status:type_name -> alox.OtaStatusPayload
9, // 10: alox.UartMessage.accel_deadzone_request:type_name -> alox.AccelDeadzoneRequest
10, // 11: alox.UartMessage.accel_deadzone_response:type_name -> alox.AccelDeadzoneResponse
5, // 12: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo
7, // 13: alox.ClientInputResponse.clients:type_name -> alox.ClientInput
14, // [14:14] is the sub-list for method output_type
14, // [14:14] is the sub-list for method input_type
14, // [14:14] is the sub-list for extension type_name
14, // [14:14] is the sub-list for extension extendee
0, // [0:14] is the sub-list for field type_name
11, // 12: alox.UartMessage.espnow_unicast_test_request:type_name -> alox.EspNowUnicastTestRequest
12, // 13: alox.UartMessage.espnow_unicast_test_response:type_name -> alox.EspNowUnicastTestResponse
5, // 14: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo
7, // 15: alox.ClientInputResponse.clients:type_name -> alox.ClientInput
16, // [16:16] is the sub-list for method output_type
16, // [16:16] is the sub-list for method input_type
16, // [16:16] is the sub-list for extension type_name
16, // [16:16] is the sub-list for extension extendee
0, // [0:16] is the sub-list for field type_name
}
func init() { file_uart_messages_proto_init() }
@ -1207,6 +1359,8 @@ func file_uart_messages_proto_init() {
(*UartMessage_OtaStatus)(nil),
(*UartMessage_AccelDeadzoneRequest)(nil),
(*UartMessage_AccelDeadzoneResponse)(nil),
(*UartMessage_EspnowUnicastTestRequest)(nil),
(*UartMessage_EspnowUnicastTestResponse)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -1214,7 +1368,7 @@ func file_uart_messages_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_uart_messages_proto_rawDesc), len(file_uart_messages_proto_rawDesc)),
NumEnums: 1,
NumMessages: 14,
NumMessages: 16,
NumExtensions: 0,
NumServices: 0,
},

View File

@ -17,6 +17,7 @@ idf_component_register(
"cmd_version.c"
"cmd_client_info.c"
"cmd_accel_deadzone.c"
"cmd_espnow_unicast_test.c"
"client_registry.c"
"esp_now_comm.c"
"esp_now_proto.c"

View File

@ -186,10 +186,20 @@ Filters BMA456 logs: a new accel line is emitted only when any axis changes by m
| `write` | `false` = read, `true` = write |
| `deadzone` | Threshold in LSB (write) |
| `client_id` | `0` = local sensor on this node; `>0` = slave id (master) |
| `all_clients` | Master: ESP-NOW push to every registered slave |
| `all_clients` | Master: ESP-NOW unicast to every registered slave |
**Response:** `accel_deadzone_response` with applied `deadzone`, `success`, and `slaves_updated` (ESP-NOW count).
### ESPNOW_UNICAST_TEST command
Minimal master→slave ESP-NOW unicast check (no BMA456). Use this before debugging `ACCEL_DEADZONE` unicast.
**Request:** framed `07` + `espnow_unicast_test_request` (`client_id`, `seq`).
**Response:** `espnow_unicast_test_response` (`success`, `seq`).
**Firmware logs:** master `unicast TEST to … seq=N`; slave `UNICAST TEST OK from master … seq=N`.
### CLIENT_INFO command
**Request:** framed payload `04` only (`MessageType.CLIENT_INFO`).
@ -208,7 +218,9 @@ Fields per client: `id`, `mac`, `version`, `available`, `used`, `last_ping`, `la
| `client_registry_check_timeouts(timeout_ms)` | Mark stale clients inactive (master monitor task) |
| `client_registry_count()` / `client_registry_at(i)` | Iterate for UART encoding |
Slaves register when the master receives `SLAVE_INFO` on the matching network; `HEARTBEAT` keeps them marked available.
Slaves register when the master receives `SLAVE_INFO` on the matching network; `HEARTBEAT` keeps them marked available. The registry **MAC is always the ESP-NOW source address** (`recv_info.src_addr`), not the optional `mac` bytes in the protobuf (used only on the wire for debugging).
`slave_id` is the senders WiFi STA address last octet (`mac[5]`); it can collide across devices — use `gotool clients` and match the full MAC.
## Host tool (`goTool/`)

View File

@ -45,6 +45,22 @@ static client_slot_t *find_slot(const uint8_t mac[CLIENT_MAC_LEN]) {
return NULL;
}
static void evict_stale_id(uint32_t id, const uint8_t mac[CLIENT_MAC_LEN]) {
for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
if (!s_clients[i].active || s_clients[i].info.id != id) {
continue;
}
if (mac_equal(s_clients[i].info.mac, mac)) {
continue;
}
char old_mac[18];
mac_to_str(s_clients[i].info.mac, old_mac, sizeof(old_mac));
ESP_LOGW(TAG, "dropping stale id=%lu mac=%s (now %02x:…:%02x)", (unsigned long)id,
old_mac, mac[0], mac[5]);
s_clients[i].active = false;
}
}
static client_slot_t *alloc_slot(const uint8_t mac[CLIENT_MAC_LEN],
bool *out_is_new) {
client_slot_t *slot = find_slot(mac);
@ -98,6 +114,7 @@ esp_err_t client_registry_upsert(const uint8_t mac[CLIENT_MAC_LEN], uint32_t id,
slot->info.used = used;
slot->info.last_ping_at = ts;
slot->info.last_success_ping_at = ts;
evict_stale_id(id, mac);
if (out_is_new != NULL) {
*out_is_new = is_new;
@ -130,6 +147,7 @@ esp_err_t client_registry_heartbeat(const uint8_t mac[CLIENT_MAC_LEN],
slot->info.available = true;
slot->info.last_ping_at = ts;
slot->info.last_success_ping_at = ts;
evict_stale_id(id, mac);
if (out_is_new != NULL) {
*out_is_new = is_new;

View File

@ -38,7 +38,7 @@ static esp_err_t push_deadzone_to_slave(const client_info_t *client,
return err;
}
return esp_now_comm_send_accel_deadzone(client->id, deadzone);
return esp_now_comm_send_accel_deadzone(client->mac, client->id, deadzone);
}
static void handle_accel_deadzone(const uint8_t *data, size_t len) {
@ -69,16 +69,26 @@ static void handle_accel_deadzone(const uint8_t *data, size_t len) {
if (req.write) {
if (req.all_clients) {
size_t n = client_registry_set_accel_deadzone_all(req.deadzone);
esp_err_t send_err = esp_now_comm_send_accel_deadzone(0, req.deadzone);
uint32_t sent = 0;
for (size_t i = 0; i < client_registry_count(); i++) {
const client_info_t *client = client_registry_at(i);
if (client == NULL) {
continue;
}
if (esp_now_comm_send_accel_deadzone(client->mac, client->id,
req.deadzone) == ESP_OK) {
sent++;
}
}
if (bma456_is_ready()) {
bma456_set_accel_deadzone(req.deadzone);
}
ESP_LOGI(TAG, "set deadzone %lu broadcast (registry %u)",
(unsigned long)req.deadzone, (unsigned)n);
send_response(req.deadzone, 0, send_err == ESP_OK || bma456_is_ready(),
send_err == ESP_OK ? (uint32_t)n : 0);
ESP_LOGI(TAG, "set deadzone %lu via unicast to %u/%u slaves",
(unsigned long)req.deadzone, (unsigned)sent, (unsigned)n);
send_response(req.deadzone, 0, sent > 0 || bma456_is_ready(), sent);
return;
}

View File

@ -0,0 +1,66 @@
#include "client_registry.h"
#include "cmd_espnow_unicast_test.h"
#include "cmd_handler.h"
#include "esp_log.h"
#include "esp_now_comm.h"
#include "pb_decode.h"
#include "uart_messages.pb.h"
#include "uart_proto.h"
static const char *TAG = "[UNICAST_TEST]";
static void send_response(bool success, uint32_t seq) {
alox_UartMessage response = alox_UartMessage_init_zero;
response.type = alox_MessageType_ESPNOW_UNICAST_TEST;
response.which_payload = alox_UartMessage_espnow_unicast_test_response_tag;
response.payload.espnow_unicast_test_response.success = success;
response.payload.espnow_unicast_test_response.seq = seq;
if (uart_send_uart_message(&response) != ESP_OK) {
ESP_LOGE(TAG, "failed to send response");
}
}
static void handle_espnow_unicast_test(const uint8_t *data, size_t len) {
alox_UartMessage uart_msg = alox_UartMessage_init_zero;
alox_EspNowUnicastTestRequest req = alox_EspNowUnicastTestRequest_init_zero;
bool have_request = false;
if (len > 0) {
pb_istream_t stream = pb_istream_from_buffer(data, len);
if (!pb_decode(&stream, alox_UartMessage_fields, &uart_msg)) {
ESP_LOGW(TAG, "decode failed");
send_response(false, 0);
return;
}
if (uart_msg.which_payload ==
alox_UartMessage_espnow_unicast_test_request_tag) {
req = uart_msg.payload.espnow_unicast_test_request;
have_request = true;
}
}
if (!have_request || req.client_id == 0) {
ESP_LOGW(TAG, "need client_id in request");
send_response(false, 0);
return;
}
const client_info_t *client = client_registry_find_by_id(req.client_id);
if (client == NULL) {
ESP_LOGW(TAG, "client id %lu not in registry",
(unsigned long)req.client_id);
send_response(false, req.seq);
return;
}
esp_err_t err = esp_now_comm_send_unicast_test(client->mac, req.seq);
send_response(err == ESP_OK, req.seq);
}
void cmd_espnow_unicast_test_register(void) {
if (msg_register_handler(alox_MessageType_ESPNOW_UNICAST_TEST,
handle_espnow_unicast_test) != ESP_OK) {
ESP_LOGE(TAG, "register failed");
}
}

View File

@ -0,0 +1,6 @@
#ifndef CMD_ESPNOW_UNICAST_TEST_H
#define CMD_ESPNOW_UNICAST_TEST_H
void cmd_espnow_unicast_test_register(void);
#endif

View File

@ -28,6 +28,8 @@ static const char *message_type_name(uint16_t id) {
return "CLIENT_INPUT";
case alox_MessageType_ACCEL_DEADZONE:
return "ACCEL_DEADZONE";
case alox_MessageType_ESPNOW_UNICAST_TEST:
return "ESPNOW_UNICAST_TEST";
case alox_MessageType_OTA_START:
return "OTA_START";
case alox_MessageType_OTA_PAYLOAD:

View File

@ -110,7 +110,8 @@ static esp_err_t send_message(const uint8_t *dest_mac,
return err;
}
static esp_err_t send_accel_deadzone(uint32_t client_id, uint32_t deadzone) {
static esp_err_t send_accel_deadzone(const uint8_t *dest_mac, uint32_t client_id,
uint32_t deadzone) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
msg.type = alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE;
@ -118,22 +119,50 @@ static esp_err_t send_accel_deadzone(uint32_t client_id, uint32_t deadzone) {
msg.payload.accel_deadzone.deadzone = deadzone;
msg.payload.accel_deadzone.client_id = client_id;
return send_message(ESPNOW_BCAST, &msg);
return send_message(dest_mac, &msg);
}
esp_err_t esp_now_comm_send_accel_deadzone(uint32_t client_id, uint32_t deadzone) {
if (!s_config.master) {
static esp_err_t send_unicast_test(const uint8_t *dest_mac, uint32_t seq) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
msg.type = alox_EspNowMessageType_ESPNOW_UNICAST_TEST;
msg.which_payload = alox_EspNowMessage_unicast_test_tag;
msg.payload.unicast_test.seq = seq;
return send_message(dest_mac, &msg);
}
esp_err_t esp_now_comm_send_unicast_test(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t seq) {
if (mac == NULL || !s_config.master) {
return ESP_ERR_INVALID_STATE;
}
esp_err_t err = send_accel_deadzone(client_id, deadzone);
char mac_str[18];
mac_to_str(mac, mac_str, sizeof(mac_str));
esp_err_t err = send_unicast_test(mac, seq);
if (err == ESP_OK) {
ESP_LOGI(TAG,
"broadcast SET_ACCEL_DEADZONE deadzone=%lu client_id=%lu%s",
(unsigned long)deadzone, (unsigned long)client_id,
client_id == 0 ? " (all slaves)" : "");
ESP_LOGI(TAG, "unicast TEST to %s seq=%lu", mac_str, (unsigned long)seq);
} else {
ESP_LOGW(TAG, "broadcast SET_ACCEL_DEADZONE failed: %s",
ESP_LOGW(TAG, "unicast TEST to %s failed: %s", mac_str, esp_err_to_name(err));
}
return err;
}
esp_err_t esp_now_comm_send_accel_deadzone(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t client_id, uint32_t deadzone) {
if (mac == NULL || !s_config.master) {
return ESP_ERR_INVALID_STATE;
}
char mac_str[18];
mac_to_str(mac, mac_str, sizeof(mac_str));
esp_err_t err = send_accel_deadzone(mac, client_id, deadzone);
if (err == ESP_OK) {
ESP_LOGI(TAG, "unicast SET_ACCEL_DEADZONE to %s: deadzone=%lu client_id=%lu",
mac_str, (unsigned long)deadzone, (unsigned long)client_id);
} else {
ESP_LOGW(TAG, "unicast SET_ACCEL_DEADZONE to %s failed: %s", mac_str,
esp_err_to_name(err));
}
return err;
@ -163,6 +192,15 @@ static void slave_reset_join(void) {
s_last_discover_ms = 0;
}
static void handle_slave_unicast_test(const uint8_t *master_mac,
const alox_EspNowUnicastTest *test) {
char mac_str[18];
mac_to_str(master_mac, mac_str, sizeof(mac_str));
ESP_LOGI(TAG, "UNICAST TEST OK from master %s seq=%lu (joined=%d)",
mac_str, (unsigned long)test->seq, (int)s_slave_joined);
}
static void handle_slave_accel_deadzone(const uint8_t *master_mac,
const alox_EspNowAccelDeadzone *cfg) {
uint32_t my_id = s_own_mac[5];
@ -192,6 +230,8 @@ static void handle_client_presence(const alox_EspNowSlavePresence *presence,
return;
}
ensure_peer(mac);
bool is_new = false;
bool reactivated = false;
esp_err_t err = client_registry_heartbeat(
@ -309,10 +349,17 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
return;
}
if (s_slave_joined && mac_equal(info->src_addr, s_master_mac)) {
ensure_peer(info->src_addr);
}
switch (msg.which_payload) {
case alox_EspNowMessage_discover_tag:
handle_discover(info->src_addr, &msg.payload.discover);
break;
case alox_EspNowMessage_unicast_test_tag:
handle_slave_unicast_test(info->src_addr, &msg.payload.unicast_test);
break;
case alox_EspNowMessage_accel_deadzone_tag:
handle_slave_accel_deadzone(info->src_addr, &msg.payload.accel_deadzone);
break;
@ -325,17 +372,17 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
}
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
uint8_t peer_mac[CLIENT_MAC_LEN];
if (esp_now_proto_decode_with_mac(data, (size_t)len, &msg, peer_mac) !=
ESP_OK) {
if (esp_now_proto_decode(data, (size_t)len, &msg) != ESP_OK) {
ESP_LOGW(TAG, "master: ESP-NOW decode failed (%d bytes)", len);
return;
}
const alox_EspNowSlavePresence *presence = esp_now_proto_get_presence(&msg);
if (presence != NULL) {
handle_client_presence(presence, peer_mac);
/* Registry key is the ESP-NOW sender MAC, not the optional protobuf mac field. */
ensure_peer(info->src_addr);
handle_client_presence(presence, info->src_addr);
}
}
@ -382,6 +429,7 @@ static esp_err_t init_wifi_stack(uint8_t channel) {
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
ESP_ERROR_CHECK(esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE));
return ESP_OK;

View File

@ -7,10 +7,12 @@
esp_err_t esp_now_comm_init(const app_config_t *config);
/**
* Master: broadcast accel deadzone (same path as DISCOVER).
* client_id 0 = all slaves; otherwise only the slave with that id applies it.
*/
esp_err_t esp_now_comm_send_accel_deadzone(uint32_t client_id, uint32_t deadzone);
/** Master: unicast accel deadzone to one slave (client_id is echoed for filtering). */
esp_err_t esp_now_comm_send_accel_deadzone(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t client_id, uint32_t deadzone);
/** Master: send minimal unicast test payload to verify master→slave path. */
esp_err_t esp_now_comm_send_unicast_test(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t seq);
#endif

View File

@ -1,6 +1,7 @@
#include "app_config.h"
#include "cmd_handler.h"
#include "cmd_accel_deadzone.h"
#include "cmd_espnow_unicast_test.h"
#include "cmd_client_info.h"
#include "cmd_version.h"
#include "esp_now_comm.h"
@ -146,6 +147,7 @@ void app_main(void) {
cmd_version_register();
cmd_client_info_register();
cmd_accel_deadzone_register();
cmd_espnow_unicast_test_register();
}
uint8_t current_digit = 10;

View File

@ -6,6 +6,9 @@
#error Regenerate this file with the current version of nanopb generator.
#endif
PB_BIND(alox_EspNowUnicastTest, alox_EspNowUnicastTest, AUTO)
PB_BIND(alox_EspNowDiscover, alox_EspNowDiscover, AUTO)

View File

@ -15,10 +15,15 @@ typedef enum _alox_EspNowMessageType {
alox_EspNowMessageType_ESPNOW_DISCOVER = 1,
alox_EspNowMessageType_ESPNOW_SLAVE_INFO = 2,
alox_EspNowMessageType_ESPNOW_HEARTBEAT = 3,
alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE = 4
alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE = 4,
alox_EspNowMessageType_ESPNOW_UNICAST_TEST = 5
} alox_EspNowMessageType;
/* Struct definitions */
typedef struct _alox_EspNowUnicastTest {
uint32_t seq;
} alox_EspNowUnicastTest;
typedef struct _alox_EspNowDiscover {
uint32_t network;
} alox_EspNowDiscover;
@ -45,6 +50,7 @@ typedef struct _alox_EspNowMessage {
alox_EspNowSlavePresence slave_info;
alox_EspNowSlavePresence heartbeat;
alox_EspNowAccelDeadzone accel_deadzone;
alox_EspNowUnicastTest unicast_test;
} payload;
} alox_EspNowMessage;
@ -55,8 +61,9 @@ extern "C" {
/* Helper constants for enums */
#define _alox_EspNowMessageType_MIN alox_EspNowMessageType_ESPNOW_UNKNOWN
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_SET_ACCEL_DEADZONE+1))
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_UNICAST_TEST
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_UNICAST_TEST+1))
@ -65,16 +72,19 @@ extern "C" {
/* Initializer values for message structs */
#define alox_EspNowUnicastTest_init_default {0}
#define alox_EspNowDiscover_init_default {0}
#define alox_EspNowSlavePresence_init_default {0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_EspNowAccelDeadzone_init_default {0, 0}
#define alox_EspNowMessage_init_default {_alox_EspNowMessageType_MIN, 0, {alox_EspNowDiscover_init_default}}
#define alox_EspNowUnicastTest_init_zero {0}
#define alox_EspNowDiscover_init_zero {0}
#define alox_EspNowSlavePresence_init_zero {0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_EspNowAccelDeadzone_init_zero {0, 0}
#define alox_EspNowMessage_init_zero {_alox_EspNowMessageType_MIN, 0, {alox_EspNowDiscover_init_zero}}
/* Field tags (for use in manual encoding/decoding) */
#define alox_EspNowUnicastTest_seq_tag 1
#define alox_EspNowDiscover_network_tag 1
#define alox_EspNowSlavePresence_network_tag 1
#define alox_EspNowSlavePresence_mac_tag 2
@ -89,8 +99,14 @@ extern "C" {
#define alox_EspNowMessage_slave_info_tag 3
#define alox_EspNowMessage_heartbeat_tag 4
#define alox_EspNowMessage_accel_deadzone_tag 5
#define alox_EspNowMessage_unicast_test_tag 6
/* Struct field encoding specification for nanopb */
#define alox_EspNowUnicastTest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, seq, 1)
#define alox_EspNowUnicastTest_CALLBACK NULL
#define alox_EspNowUnicastTest_DEFAULT NULL
#define alox_EspNowDiscover_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, network, 1)
#define alox_EspNowDiscover_CALLBACK NULL
@ -117,20 +133,24 @@ X(a, STATIC, SINGULAR, UENUM, type, 1) \
X(a, STATIC, ONEOF, MESSAGE, (payload,discover,payload.discover), 2) \
X(a, STATIC, ONEOF, MESSAGE, (payload,slave_info,payload.slave_info), 3) \
X(a, STATIC, ONEOF, MESSAGE, (payload,heartbeat,payload.heartbeat), 4) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone,payload.accel_deadzone), 5)
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone,payload.accel_deadzone), 5) \
X(a, STATIC, ONEOF, MESSAGE, (payload,unicast_test,payload.unicast_test), 6)
#define alox_EspNowMessage_CALLBACK NULL
#define alox_EspNowMessage_DEFAULT NULL
#define alox_EspNowMessage_payload_discover_MSGTYPE alox_EspNowDiscover
#define alox_EspNowMessage_payload_slave_info_MSGTYPE alox_EspNowSlavePresence
#define alox_EspNowMessage_payload_heartbeat_MSGTYPE alox_EspNowSlavePresence
#define alox_EspNowMessage_payload_accel_deadzone_MSGTYPE alox_EspNowAccelDeadzone
#define alox_EspNowMessage_payload_unicast_test_MSGTYPE alox_EspNowUnicastTest
extern const pb_msgdesc_t alox_EspNowUnicastTest_msg;
extern const pb_msgdesc_t alox_EspNowDiscover_msg;
extern const pb_msgdesc_t alox_EspNowSlavePresence_msg;
extern const pb_msgdesc_t alox_EspNowAccelDeadzone_msg;
extern const pb_msgdesc_t alox_EspNowMessage_msg;
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define alox_EspNowUnicastTest_fields &alox_EspNowUnicastTest_msg
#define alox_EspNowDiscover_fields &alox_EspNowDiscover_msg
#define alox_EspNowSlavePresence_fields &alox_EspNowSlavePresence_msg
#define alox_EspNowAccelDeadzone_fields &alox_EspNowAccelDeadzone_msg
@ -142,6 +162,7 @@ extern const pb_msgdesc_t alox_EspNowMessage_msg;
#define ALOX_MAIN_PROTO_ESP_NOW_MESSAGES_PB_H_MAX_SIZE alox_EspNowAccelDeadzone_size
#define alox_EspNowAccelDeadzone_size 12
#define alox_EspNowDiscover_size 6
#define alox_EspNowUnicastTest_size 6
#ifdef __cplusplus
} /* extern "C" */

View File

@ -8,6 +8,11 @@ enum EspNowMessageType {
ESPNOW_SLAVE_INFO = 2;
ESPNOW_HEARTBEAT = 3;
ESPNOW_SET_ACCEL_DEADZONE = 4;
ESPNOW_UNICAST_TEST = 5;
}
message EspNowUnicastTest {
uint32 seq = 1;
}
message EspNowDiscover {
@ -35,5 +40,6 @@ message EspNowMessage {
EspNowSlavePresence slave_info = 3;
EspNowSlavePresence heartbeat = 4;
EspNowAccelDeadzone accel_deadzone = 5;
EspNowUnicastTest unicast_test = 6;
}
}

View File

@ -36,6 +36,12 @@ PB_BIND(alox_AccelDeadzoneRequest, alox_AccelDeadzoneRequest, AUTO)
PB_BIND(alox_AccelDeadzoneResponse, alox_AccelDeadzoneResponse, AUTO)
PB_BIND(alox_EspNowUnicastTestRequest, alox_EspNowUnicastTestRequest, AUTO)
PB_BIND(alox_EspNowUnicastTestResponse, alox_EspNowUnicastTestResponse, AUTO)
PB_BIND(alox_OtaStartPayload, alox_OtaStartPayload, AUTO)

View File

@ -18,6 +18,7 @@ typedef enum _alox_MessageType {
alox_MessageType_CLIENT_INFO = 4,
alox_MessageType_CLIENT_INPUT = 5,
alox_MessageType_ACCEL_DEADZONE = 6,
alox_MessageType_ESPNOW_UNICAST_TEST = 7,
alox_MessageType_OTA_START = 16,
alox_MessageType_OTA_PAYLOAD = 17,
alox_MessageType_OTA_END = 18,
@ -81,6 +82,16 @@ typedef struct _alox_AccelDeadzoneResponse {
uint32_t slaves_updated;
} alox_AccelDeadzoneResponse;
typedef struct _alox_EspNowUnicastTestRequest {
uint32_t client_id;
uint32_t seq;
} alox_EspNowUnicastTestRequest;
typedef struct _alox_EspNowUnicastTestResponse {
bool success;
uint32_t seq;
} alox_EspNowUnicastTestResponse;
typedef struct _alox_OtaStartPayload {
uint32_t total_size;
uint32_t block_size;
@ -115,6 +126,8 @@ typedef struct _alox_UartMessage {
alox_OtaStatusPayload ota_status;
alox_AccelDeadzoneRequest accel_deadzone_request;
alox_AccelDeadzoneResponse accel_deadzone_response;
alox_EspNowUnicastTestRequest espnow_unicast_test_request;
alox_EspNowUnicastTestResponse espnow_unicast_test_response;
} payload;
} alox_UartMessage;
@ -144,6 +157,8 @@ extern "C" {
/* Initializer values for message structs */
#define alox_UartMessage_init_default {_alox_MessageType_MIN, 0, {alox_Ack_init_default}}
#define alox_Ack_init_default {0}
@ -155,6 +170,8 @@ extern "C" {
#define alox_ClientInputResponse_init_default {{{NULL}, NULL}}
#define alox_AccelDeadzoneRequest_init_default {0, 0, 0, 0}
#define alox_AccelDeadzoneResponse_init_default {0, 0, 0, 0}
#define alox_EspNowUnicastTestRequest_init_default {0, 0}
#define alox_EspNowUnicastTestResponse_init_default {0, 0}
#define alox_OtaStartPayload_init_default {0, 0}
#define alox_OtaPayload_init_default {0, 0, {{NULL}, NULL}}
#define alox_OtaEndPayload_init_default {0}
@ -169,6 +186,8 @@ extern "C" {
#define alox_ClientInputResponse_init_zero {{{NULL}, NULL}}
#define alox_AccelDeadzoneRequest_init_zero {0, 0, 0, 0}
#define alox_AccelDeadzoneResponse_init_zero {0, 0, 0, 0}
#define alox_EspNowUnicastTestRequest_init_zero {0, 0}
#define alox_EspNowUnicastTestResponse_init_zero {0, 0}
#define alox_OtaStartPayload_init_zero {0, 0}
#define alox_OtaPayload_init_zero {0, 0, {{NULL}, NULL}}
#define alox_OtaEndPayload_init_zero {0}
@ -199,6 +218,10 @@ extern "C" {
#define alox_AccelDeadzoneResponse_client_id_tag 2
#define alox_AccelDeadzoneResponse_success_tag 3
#define alox_AccelDeadzoneResponse_slaves_updated_tag 4
#define alox_EspNowUnicastTestRequest_client_id_tag 1
#define alox_EspNowUnicastTestRequest_seq_tag 2
#define alox_EspNowUnicastTestResponse_success_tag 1
#define alox_EspNowUnicastTestResponse_seq_tag 2
#define alox_OtaStartPayload_total_size_tag 1
#define alox_OtaStartPayload_block_size_tag 2
#define alox_OtaPayload_block_id_tag 1
@ -218,6 +241,8 @@ extern "C" {
#define alox_UartMessage_ota_status_tag 10
#define alox_UartMessage_accel_deadzone_request_tag 11
#define alox_UartMessage_accel_deadzone_response_tag 12
#define alox_UartMessage_espnow_unicast_test_request_tag 13
#define alox_UartMessage_espnow_unicast_test_response_tag 14
/* Struct field encoding specification for nanopb */
#define alox_UartMessage_FIELDLIST(X, a) \
@ -232,7 +257,9 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,ota_payload,payload.ota_payload),
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_end,payload.ota_end), 9) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_status,payload.ota_status), 10) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone_request,payload.accel_deadzone_request), 11) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone_response,payload.accel_deadzone_response), 12)
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone_response,payload.accel_deadzone_response), 12) \
X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_unicast_test_request,payload.espnow_unicast_test_request), 13) \
X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_unicast_test_response,payload.espnow_unicast_test_response), 14)
#define alox_UartMessage_CALLBACK NULL
#define alox_UartMessage_DEFAULT NULL
#define alox_UartMessage_payload_ack_payload_MSGTYPE alox_Ack
@ -246,6 +273,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,accel_deadzone_response,payload.acce
#define alox_UartMessage_payload_ota_status_MSGTYPE alox_OtaStatusPayload
#define alox_UartMessage_payload_accel_deadzone_request_MSGTYPE alox_AccelDeadzoneRequest
#define alox_UartMessage_payload_accel_deadzone_response_MSGTYPE alox_AccelDeadzoneResponse
#define alox_UartMessage_payload_espnow_unicast_test_request_MSGTYPE alox_EspNowUnicastTestRequest
#define alox_UartMessage_payload_espnow_unicast_test_response_MSGTYPE alox_EspNowUnicastTestResponse
#define alox_Ack_FIELDLIST(X, a) \
@ -310,6 +339,18 @@ X(a, STATIC, SINGULAR, UINT32, slaves_updated, 4)
#define alox_AccelDeadzoneResponse_CALLBACK NULL
#define alox_AccelDeadzoneResponse_DEFAULT NULL
#define alox_EspNowUnicastTestRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
X(a, STATIC, SINGULAR, UINT32, seq, 2)
#define alox_EspNowUnicastTestRequest_CALLBACK NULL
#define alox_EspNowUnicastTestRequest_DEFAULT NULL
#define alox_EspNowUnicastTestResponse_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, BOOL, success, 1) \
X(a, STATIC, SINGULAR, UINT32, seq, 2)
#define alox_EspNowUnicastTestResponse_CALLBACK NULL
#define alox_EspNowUnicastTestResponse_DEFAULT NULL
#define alox_OtaStartPayload_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, total_size, 1) \
X(a, STATIC, SINGULAR, UINT32, block_size, 2)
@ -343,6 +384,8 @@ extern const pb_msgdesc_t alox_ClientInput_msg;
extern const pb_msgdesc_t alox_ClientInputResponse_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneRequest_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneResponse_msg;
extern const pb_msgdesc_t alox_EspNowUnicastTestRequest_msg;
extern const pb_msgdesc_t alox_EspNowUnicastTestResponse_msg;
extern const pb_msgdesc_t alox_OtaStartPayload_msg;
extern const pb_msgdesc_t alox_OtaPayload_msg;
extern const pb_msgdesc_t alox_OtaEndPayload_msg;
@ -359,6 +402,8 @@ extern const pb_msgdesc_t alox_OtaStatusPayload_msg;
#define alox_ClientInputResponse_fields &alox_ClientInputResponse_msg
#define alox_AccelDeadzoneRequest_fields &alox_AccelDeadzoneRequest_msg
#define alox_AccelDeadzoneResponse_fields &alox_AccelDeadzoneResponse_msg
#define alox_EspNowUnicastTestRequest_fields &alox_EspNowUnicastTestRequest_msg
#define alox_EspNowUnicastTestResponse_fields &alox_EspNowUnicastTestResponse_msg
#define alox_OtaStartPayload_fields &alox_OtaStartPayload_msg
#define alox_OtaPayload_fields &alox_OtaPayload_msg
#define alox_OtaEndPayload_fields &alox_OtaEndPayload_msg
@ -377,6 +422,8 @@ extern const pb_msgdesc_t alox_OtaStatusPayload_msg;
#define alox_AccelDeadzoneResponse_size 20
#define alox_Ack_size 0
#define alox_ClientInput_size 22
#define alox_EspNowUnicastTestRequest_size 12
#define alox_EspNowUnicastTestResponse_size 8
#define alox_OtaEndPayload_size 6
#define alox_OtaStartPayload_size 12
#define alox_OtaStatusPayload_size 6

View File

@ -10,6 +10,7 @@ enum MessageType {
CLIENT_INFO = 4;
CLIENT_INPUT = 5;
ACCEL_DEADZONE = 6;
ESPNOW_UNICAST_TEST = 7;
OTA_START = 16;
OTA_PAYLOAD = 17;
OTA_END = 18;
@ -31,6 +32,8 @@ message UartMessage {
OtaStatusPayload ota_status = 10;
AccelDeadzoneRequest accel_deadzone_request = 11;
AccelDeadzoneResponse accel_deadzone_response = 12;
EspNowUnicastTestRequest espnow_unicast_test_request = 13;
EspNowUnicastTestResponse espnow_unicast_test_response = 14;
}
}
@ -87,6 +90,16 @@ message AccelDeadzoneResponse {
uint32 slaves_updated = 4;
}
message EspNowUnicastTestRequest {
uint32 client_id = 1;
uint32 seq = 2;
}
message EspNowUnicastTestResponse {
bool success = 1;
uint32 seq = 2;
}
message OtaStartPayload {
uint32 total_size = 1;
uint32 block_size = 2;