Skip to content

:XGM# response is truncated and loses its # terminator on OAM, OATControl can't connect #294

Description

@ZigorewsLike

On an OpenAstroMount (OAM) build, OATControl fails to connect: it times out on the :XGM# (get mount hardware info) command. Root cause is that the hardware-info response is longer than the 64-byte MeadeResponse buffer, so the string is truncated and the trailing # delimiter is never written. OATControl waits for a #-delimited response that never completes.

Environment

  • Firmware: v1.13.20 (develop)
  • OATControl: V1.2.1.0 (latest)
  • Mount: OAM (OpenAstroMount)
  • Board: MKS Gen L V2.1 (BOARD_AVR_MKS_GEN_L_V21)
  • Drivers: TMC2209 standalone (RA/DEC/AZ/ALT), NEW_STEPPER_LIB
  • No display, no GPS, no focuser, no end switches, no autohoming sensors

OATControl log:

SERIAL: [:GVP#] Received response 'OpenAstroMount'
SERIAL: [:GVN#] Received response 'v1.13.20'
SERIAL: [:XGM#] Expecting #-delimited response for Command, waiting...
SERIAL: [:XGM#] Failed to receive response to command. (timeout)
MOUNT: Hardware is        (empty)

:GVP# and :GVN# work, but :XGM# times out and connection cannot complete.

Root cause

:XGM# is handled in src/core/meade/MeadeParserExtra.cpp:

if (startsWith(leafInput, "M")) {
    fillFramedTextResponse(r, h.onGetMountHardwareInfo());
    return;
}

fillFramedTextResponse writes the text and then the terminator (src/core/meade/MeadeParserHelpers.cpp):

void fillFramedTextResponse(MeadeResponse &r, const char *text) {
    writeText(r, text);
    writeTerminator(r);   // writeChar(r, '#')
}

void writeChar(MeadeResponse &r, char c) {
    const size_t n = r.length();
    if (n + 1 >= r.capacity()) { return; }   // silently drops the char when full
    ...
}

The buffer is only 64 bytes (src/core/meade/MeadeParser.hpp):

static constexpr size_t Capacity = 64;

On this OAM config, onGetMountHardwareInfo() returns a 110-character string:

Mega,NEMA|16|3600,NEMA|16|3600,NO_GPS,AUTO_AZ_ALT,NO_GYRO,NO_LCD,NO_INFO_DISP,NO_FOC,NO_HSAH,NO_HSAV,NO_ENDSW,

writeText fills the 64-byte buffer (stored content is truncated at 63 chars, mid-token - e.g. NO_LCD becomes NO_LC), then writeTerminator's writeChar('#') hits n + 1 >= capacity and is silently dropped. The wire response has no #, so OATControl never sees the end of the response and times out.

Observed in a serial terminal - truncated response, no #:

Mega,NEMA|16|3600,NEMA|16|3600,NO_GPS,AUTO_AZ_ALT,NO_GYRO,NO_LC

Fix verified

Increasing MeadeResponse::Capacity to 128 resolves it. Full, correctly terminated response:

Mega,NEMA|16|3600,NEMA|16|3600,NO_GPS,AUTO_AZ_ALT,NO_GYRO,NO_LCD,NO_INFO_DISP,NO_FOC,NO_HSAH,NO_HSAV,NO_ENDSW,#

OATControl then connects normally.

Suggested fix

  • Increase MeadeResponse::Capacity to comfortably hold the longest possible :XGM# response (128 is enough today; the full OAM string is 110 chars + #).
  • Consider making writeChar/writeTerminator reserve one byte so the terminator is never silently dropped on overflow (a truncated-but-#-terminated response is far easier to diagnose than a missing terminator), or have fillFramedTextResponse guarantee room for the #.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions