// =============================================================================
//  protocols/nmea0183_parser.h -- $PARP sentence parser
// =============================================================================
//
//  Parses incoming $PARP sentences from UART2 RX (USB-IN ports).
//  Validates checksum before returning any data.
// =============================================================================

#pragma once

#include <cstdint>
#include <cstdbool>

namespace arconcentrador::protocols {

struct ParpCommand {
    char    cmd[16];         ///< e.g. "ENGAGE", "SETHEADING", "REQCMD"
    float   value;           ///< numeric parameter (heading degrees, etc.)
    uint8_t station_id;      ///< 1-4
    bool    valid;           ///< false if checksum failed or format invalid
};

/// Parse one null-terminated NMEA sentence (including the leading '$').
/// Returns a ParpCommand with valid=true on success.
ParpCommand parp_parse(const char* sentence);

/// Compute NMEA XOR checksum of content between '$' and '*'.
uint8_t nmea_checksum(const char* sentence);

/// Append one character to the internal line buffer.
/// When a complete sentence (\n) arrives, calls parp_parse and stores result.
/// Returns true if a complete sentence was parsed this call.
bool parp_feed(char c, ParpCommand& out);

}  // namespace arconcentrador::protocols
