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

ESP-NOW communication protocol for fatigue tester. More...

#include <cstdint>
#include <cstring>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "esp_idf_pedantic_compat.hpp"
#include "esp_log.h"
#include "espnow_security.hpp"
Include dependency graph for espnow_protocol.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BoundsResultPayload
 Payload for BOUNDS_RESULT. More...
 
struct  EspNowHeader
 ESP-NOW packet header (wire format) - 6 bytes. More...
 
struct  EspNowPacket
 Full packet representation (header + max payload + CRC field). More...
 
struct  ConfigPayload
 Payload for CONFIG_SET / CONFIG_RESPONSE. More...
 
struct  ConfigAckPayload
 Payload for CONFIG_ACK. More...
 
struct  CommandPayload
 Payload for COMMAND message. More...
 
struct  StatusPayload
 Payload for STATUS_UPDATE. More...
 
struct  ErrorPayload
 Payload for ERROR. More...
 
struct  TestUnitSettings
 Test unit settings - synchronized with test machine via ESP-NOW. More...
 
struct  UISettings
 UI board settings - stored locally, never synchronized with test unit. More...
 
struct  Settings
 Complete settings structure containing both test unit and UI settings. More...
 
struct  ProtoEvent
 Protocol event structure pushed through FreeRTOS queues. More...
 

Enumerations

enum class  MsgType : uint8_t {
  DeviceDiscovery = 1 , DeviceInfo , ConfigRequest , ConfigResponse ,
  ConfigSet , ConfigAck , Command , CommandAck ,
  StatusUpdate , Error , ErrorClear , TestComplete ,
  BoundsResult = 13 , PairingRequest = 20 , PairingResponse = 21 , PairingConfirm = 22 ,
  PairingReject = 23 , Unpair = 24
}
 Wire-level message type identifiers. More...
 
enum class  TestState : uint8_t {
  Idle = 0 , Running , Paused , Completed ,
  Error
}
 Protocol-visible test states encoded in STATUS_UPDATE. More...
 
enum class  CommandId : uint8_t {
  Start = 1 , Pause = 2 , Resume = 3 , Stop = 4 ,
  RunBoundsFinding = 5 , SetManualBounds = 6 , ManualBoundsStart = 7 , ManualBoundsArmPlaced = 8 ,
  ManualBoundsJog = 9 , ManualBoundsConfirm = 10 , ManualBoundsCancel = 11 , ManualBoundsReZero = 12 ,
  StartWithManualBounds = 13 , StartWithManualRealign = 14
}
 Command IDs for COMMAND message type. More...
 
enum class  ProtoEventType {
  ConfigRequest , ConfigSet , CommandStart , CommandPause ,
  CommandResume , CommandStop , CommandRunBoundsFinding , CommandSetManualBounds ,
  CommandManualBoundsStart , CommandManualBoundsArmPlaced , CommandManualBoundsJog , CommandManualBoundsConfirm ,
  CommandManualBoundsCancel , CommandManualBoundsReZero , CommandStartWithManualBounds , CommandStartWithManualRealign ,
  ConfigUpdated , ConfigApplyOk , ConfigApplyFail , Started ,
  Paused , Resumed , Stopped , Status ,
  ErrorEvent , TestCompleted , PairingRequest , PairingComplete ,
  PairingFailed , PeerUnpaired
}
 Higher-level events emitted by the protocol layer. More...
 

Functions

uint16_t Crc16Ccitt (const uint8_t *data, size_t len) noexcept
 Compute CRC16-CCITT (poly 0x1021, init 0xFFFF).
 

Variables

static constexpr uint8_t ESPNOW_SYNC_BYTE = 0xAA
 
static constexpr uint8_t ESPNOW_PROTOCOL_VERSION = 1
 
static constexpr uint8_t DEVICE_ID_FATIGUE_TESTER = 1
 
static constexpr size_t ESPNOW_MAX_PAYLOAD = 200
 
static constexpr uint8_t WIFI_CHANNEL = 1
 
static constexpr uint8_t UI_BOARD_MAC [6] = { 0xB0, 0x81, 0x84, 0x96, 0x90, 0x10 }
 

Detailed Description

ESP-NOW communication protocol for fatigue tester.

Protocol compatible with esp32_remote_controller. Uses 6-byte header with version and device_id fields.

Defines message types, packet structures, and protocol handlers for communication between UI board (remote controller) and test unit.

Enumeration Type Documentation

◆ CommandId

enum class CommandId : uint8_t
strong

Command IDs for COMMAND message type.

Per coding standards: PascalCase for enum values.

Enumerator
Start 
Pause 
Resume 
Stop 
RunBoundsFinding 
SetManualBounds 
ManualBoundsStart 

Start manual bounds: disengage motor.

ManualBoundsArmPlaced 

Arm at left stop: engage motor, set reference.

ManualBoundsJog 

Jog to absolute position (float degrees)

ManualBoundsConfirm 

Confirm bounds (center_deg f32, local_gap_deg f32)

ManualBoundsCancel 

Cancel manual bounds finding.

ManualBoundsReZero 

Re-zero motor position at current location.

StartWithManualBounds 

Start test reusing cached manual bounds (center, gap, fix_offset)

StartWithManualRealign 

Start test after manual encoder realignment (skip hard-drive)

◆ MsgType

enum class MsgType : uint8_t
strong

Wire-level message type identifiers.

These values are serialized into EspNowHeader::type and must match the remote controller's espnow::MsgType enum exactly.

Per coding standards: PascalCase for enum values (state/error types).

Enumerator
DeviceDiscovery 
DeviceInfo 
ConfigRequest 
ConfigResponse 
ConfigSet 
ConfigAck 
Command 
CommandAck 
StatusUpdate 
Error 
ErrorClear 
TestComplete 
BoundsResult 
PairingRequest 

Initiate pairing (broadcast)

PairingResponse 

Response with HMAC proof.

PairingConfirm 

Final confirmation.

PairingReject 

Explicit rejection.

Unpair 

Remove a paired device.

◆ ProtoEventType

enum class ProtoEventType
strong

Higher-level events emitted by the protocol layer.

On the test-unit side, these events represent commands received from the UI board. On either side, these can also represent parsed status/response semantics.

Per coding standards: PascalCase for enum values (event types).

Enumerator
ConfigRequest 
ConfigSet 
CommandStart 
CommandPause 
CommandResume 
CommandStop 
CommandRunBoundsFinding 
CommandSetManualBounds 
CommandManualBoundsStart 
CommandManualBoundsArmPlaced 
CommandManualBoundsJog 
CommandManualBoundsConfirm 
CommandManualBoundsCancel 
CommandManualBoundsReZero 
CommandStartWithManualBounds 
CommandStartWithManualRealign 
ConfigUpdated 
ConfigApplyOk 
ConfigApplyFail 
Started 
Paused 
Resumed 
Stopped 
Status 
ErrorEvent 
TestCompleted 
PairingRequest 

Incoming pairing request (test unit receives)

PairingComplete 

Pairing completed successfully.

PairingFailed 

Pairing failed (rejected or timeout)

PeerUnpaired 

A peer was unpaired.

◆ TestState

enum class TestState : uint8_t
strong

Protocol-visible test states encoded in STATUS_UPDATE.

Per coding standards: PascalCase for enum values (state types).

Enumerator
Idle 
Running 
Paused 
Completed 
Error 

Function Documentation

◆ Crc16Ccitt()

uint16_t Crc16Ccitt ( const uint8_t * data,
size_t len )
inlinenoexcept

Compute CRC16-CCITT (poly 0x1021, init 0xFFFF).

Parameters
dataData buffer.
lenNumber of bytes to include.
Returns
Computed CRC16 value.
Here is the caller graph for this function:

Variable Documentation

◆ DEVICE_ID_FATIGUE_TESTER

constexpr uint8_t DEVICE_ID_FATIGUE_TESTER = 1
staticconstexpr

◆ ESPNOW_MAX_PAYLOAD

constexpr size_t ESPNOW_MAX_PAYLOAD = 200
staticconstexpr

◆ ESPNOW_PROTOCOL_VERSION

constexpr uint8_t ESPNOW_PROTOCOL_VERSION = 1
staticconstexpr

◆ ESPNOW_SYNC_BYTE

constexpr uint8_t ESPNOW_SYNC_BYTE = 0xAA
staticconstexpr

◆ UI_BOARD_MAC

constexpr uint8_t UI_BOARD_MAC[6] = { 0xB0, 0x81, 0x84, 0x96, 0x90, 0x10 }
staticconstexpr

◆ WIFI_CHANNEL

constexpr uint8_t WIFI_CHANNEL = 1
staticconstexpr