Skip to main content

Module protocol

Module protocol 

Source
Expand description

Typed commands, decoded notifications, and chessboard values. Typed values and codecs for the Chessnut Move byte protocol.

Applications normally construct a Command and consume BoardEvent values through a session in the transport module. Transport implementers can use decode_position_notification and decode_response_notification when they need direct access to the protocol codecs.

Board positions use canonical A1-to-H8 indexing through Square, while encoding and decoding preserve the Move board’s reversed wire order.

§Examples

Consumers can handle decoded events without depending on a particular Bluetooth library:

use chessnut_move::protocol::{
    BoardEvent, File, Rank, Square,
};

fn occupied(event: BoardEvent, square: Square) -> Option<bool> {
    match event {
        BoardEvent::PositionChanged(position) => {
            Some(position.piece_at(square).is_some())
        }
        BoardEvent::BatteryStatus(_) | BoardEvent::PieceStatus(_) => None,
    }
}

let e4 = Square::new(File::E, Rank::Four);

Structs§

BatteryStatus
Charging state and battery percentage reported by the board.
Command
An encoded command ready to write to the board’s command characteristic.
LedPattern
LED colors for all 64 squares in canonical A1-to-H8 order.
NotificationTooShortError
Reports that a notification does not contain its complete required payload.
ParseSquareError
Reports that a string is not exactly one valid file and one valid rank.
Piece
A chess piece described by its color and kind.
PieceStatus
Status records for every physical piece tracked by the board.
Position
Piece occupancy for all 64 squares.
Square
A chessboard square stored in canonical A1-to-H8 order.
TrackedPieceStatus
Status reported for one tracked physical chess piece.

Enums§

AutoMoveMode
Selects how an automatic movement reacts to user interaction.
BatteryStatusError
Reports an invalid field in a board battery response.
BoardEvent
A decoded board-state or status notification.
Color
Side to which a chess piece belongs.
DecodePositionNotificationError
Reports why a position notification could not be decoded.
DecodeResponseNotificationError
Reports why a command-response notification could not be decoded.
File
A chessboard file from A through H.
LedColor
A color supported by a Chessnut Move square LED.
PieceKind
Chess role of a piece.
PieceStatusError
Reports an invalid field in a piece status response.
Rank
A chessboard rank from one through eight.
WriteKind
Selects the GATT write operation required by a Command.

Constants§

BOARD_STATE_LENGTH
Number of packed bytes used to encode all 64 board squares.
MAX_COMMAND_LEN
Maximum number of bytes in a command, defined by the Move’s public API surface.
SQUARE_COUNT
Number of squares on a chessboard.
TRACKED_PIECE_COUNT
Number of physical piece records in a tracked-piece response.

Functions§

decode_position_notification
Decodes a position notification emitted by the position characteristic.
decode_response_notification
Decodes a battery or tracked-piece response notification.