HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
espnow_receiver.cpp File Reference

ESP-NOW receiver implementation for test unit with secure pairing. More...

#include "espnow_receiver.hpp"
#include "espnow_protocol.hpp"
#include "espnow_peer_store.hpp"
#include <cstring>
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_idf_pedantic_compat.hpp"
#include "esp_log.h"
Include dependency graph for espnow_receiver.cpp:

Classes

struct  RawMsg
 

Functions

static bool isZeroMac (const uint8_t mac[6])
 
static bool macEq (const uint8_t a[6], const uint8_t b[6])
 
static void tryAddEspNowPeer (const uint8_t mac[6])
 
static void setActiveUiMac (const uint8_t mac[6])
 
static void espnowRecvCb (const esp_now_recv_info_t *info, const uint8_t *data, int len)
 
static void espnowSendCb (const wifi_tx_info_t *info, esp_now_send_status_t status)
 
static void recvTask (void *)
 
static void handlePacket (const RawMsg &msg, const EspNowPacket &pkt, uint16_t recv_crc)
 
static void handlePairingRequest (const uint8_t *src_mac, const EspNowPacket &pkt)
 
static void handlePairingConfirm (const uint8_t *src_mac, const EspNowPacket &pkt)
 
static bool sendPacketTo (const uint8_t *dst_mac, MsgType type, const void *payload, uint8_t payload_len)
 
static bool sendPacketToUi (MsgType type, const void *payload, uint8_t payload_len)
 

Variables

static const char * TAG = "EspNowRx"
 
static QueueHandle_t s_proto_event_queue = nullptr
 
static uint8_t s_next_msg_id = 1
 
static SecuritySettings s_security {}
 Security settings with approved peer list.
 
static uint8_t s_active_ui_board_mac [6] = {0}
 Active UI board MAC for replies (most recent approved sender)
 
static QueueHandle_t s_raw_recv_queue = nullptr
 Receive queue from ISR to this module.
 
static volatile bool s_pairing_mode = false
 Pairing mode state.
 
static volatile TickType_t s_pairing_timeout_tick = 0
 
static bool s_awaiting_pairing_confirm = false
 Pending pairing state (waiting for confirm after sending response)
 
static uint8_t s_pending_requester_mac [6] = {0}
 
static uint8_t s_my_challenge [CHALLENGE_SIZE] = {0}
 
static TickType_t s_pairing_confirm_timeout = 0
 

Detailed Description

ESP-NOW receiver implementation for test unit with secure pairing.

Protocol compatible with esp32_remote_controller (6-byte header).

Features:

  • Pre-configured MAC address support (backward compatibility)
  • Secure pairing with HMAC mutual authentication
  • NVS-based approved peer storage
  • Message validation against approved peer list

Function Documentation

◆ espnowRecvCb()

static void espnowRecvCb ( const esp_now_recv_info_t * info,
const uint8_t * data,
int len )
static
Here is the caller graph for this function:

◆ espnowSendCb()

static void espnowSendCb ( const wifi_tx_info_t * info,
esp_now_send_status_t status )
static
Here is the caller graph for this function:

◆ handlePacket()

static void handlePacket ( const RawMsg & msg,
const EspNowPacket & pkt,
uint16_t recv_crc )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlePairingConfirm()

static void handlePairingConfirm ( const uint8_t * src_mac,
const EspNowPacket & pkt )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlePairingRequest()

static void handlePairingRequest ( const uint8_t * src_mac,
const EspNowPacket & pkt )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isZeroMac()

static bool isZeroMac ( const uint8_t mac[6])
static
Here is the caller graph for this function:

◆ macEq()

static bool macEq ( const uint8_t a[6],
const uint8_t b[6] )
static
Here is the caller graph for this function:

◆ recvTask()

static void recvTask ( void * arg)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendPacketTo()

static bool sendPacketTo ( const uint8_t * dst_mac,
MsgType type,
const void * payload,
uint8_t payload_len )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendPacketToUi()

static bool sendPacketToUi ( MsgType type,
const void * payload,
uint8_t payload_len )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setActiveUiMac()

static void setActiveUiMac ( const uint8_t mac[6])
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryAddEspNowPeer()

static void tryAddEspNowPeer ( const uint8_t mac[6])
static
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ s_active_ui_board_mac

uint8_t s_active_ui_board_mac[6] = {0}
static

Active UI board MAC for replies (most recent approved sender)

◆ s_awaiting_pairing_confirm

bool s_awaiting_pairing_confirm = false
static

Pending pairing state (waiting for confirm after sending response)

◆ s_my_challenge

uint8_t s_my_challenge[CHALLENGE_SIZE] = {0}
static

◆ s_next_msg_id

uint8_t s_next_msg_id = 1
static

◆ s_pairing_confirm_timeout

TickType_t s_pairing_confirm_timeout = 0
static

◆ s_pairing_mode

volatile bool s_pairing_mode = false
static

Pairing mode state.

◆ s_pairing_timeout_tick

volatile TickType_t s_pairing_timeout_tick = 0
static

◆ s_pending_requester_mac

uint8_t s_pending_requester_mac[6] = {0}
static

◆ s_proto_event_queue

QueueHandle_t s_proto_event_queue = nullptr
static

◆ s_raw_recv_queue

QueueHandle_t s_raw_recv_queue = nullptr
static

Receive queue from ISR to this module.

◆ s_security

SecuritySettings s_security {}
static

Security settings with approved peer list.

◆ TAG

const char* TAG = "EspNowRx"
static