From 603b30fd35c44c24ed0b644f56022a91219b21ca Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Sun, 4 Oct 2026 21:10:36 +0800 Subject: [PATCH] hostmot2: use the H entry's pins for two-part sserial encoders LBP_ENCODER_L entries get no HAL pins, but the two-part Fanuc encoder reassembly fell through into the encoder body with whichever entry completed the pair. When a format lists the H part before the L part the body ran on the L entry's pins and dereferenced handles that were never created. Redirect the body to the matching LBP_ENCODER_H entry's pin set, and refuse the pair with an error when no H entry exists. --- src/hal/drivers/mesa-hostmot2/sserial.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/hal/drivers/mesa-hostmot2/sserial.c b/src/hal/drivers/mesa-hostmot2/sserial.c index d0030a214f3..f5d079b95b0 100644 --- a/src/hal/drivers/mesa-hostmot2/sserial.c +++ b/src/hal/drivers/mesa-hostmot2/sserial.c @@ -1866,6 +1866,25 @@ int hm2_sserial_read_pins(hm2_sserial_remote_t *chan){ if ( ! (h_flag && l_flag)){ break; } + if (conf->DataType == LBP_ENCODER_L) { + // LBP_ENCODER_L entries have no pins; the encoder body + // below must run on the matching LBP_ENCODER_H entry's + // pin set regardless of which entry completes the pair. + int e; + for (e = 0; e < chan->num_confs; e++){ + if (chan->confs[e].DataType == LBP_ENCODER_H){ + pin = &chan->pins[e]; + break; + } + } + if (e == chan->num_confs){ + HM2_ERR_NO_LL("sserial read: LBP_ENCODER_L with no matching LBP_ENCODER_H (name: ""%s"")\n", + conf->NameString); + h_flag = 0; l_flag = 0; + buff_store = 0; + break; + } + } buff = buff_store; /* Fallthrough */ case LBP_ENCODER: