sittner / linuxcnc-ethercat

LinuxCNC EtherCAT HAL driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

generic driver - 8/16 bit signed floats require cast before return not to loose the signal

plopes9000 opened this issue · comments

Here is the fix:

hal_s32_t lcec_generic_read_s32(uint8_t *pd, lcec_generic_pin_t *hal_data) {
int i, offset;
hal_s32_t sval;
if (hal_data->pdo_bp == 0 && hal_data->bitOffset == 0) {
switch (hal_data->bitLength) {
case 8:
return EC_READ_S8(&pd[hal_data->pdo_os]);
case 16:
return EC_READ_S16(&pd[hal_data->pdo_os]);
case 32:
return EC_READ_S32(&pd[hal_data->pdo_os]);
}
}

offset = ((hal_data->pdo_os << 3) | (hal_data->pdo_bp & 0x07)) + hal_data->bitOffset;
for (sval=0, i=0; i < hal_data->bitLength; i++, offset++) {
if (EC_READ_BIT(&pd[offset >> 3], offset & 0x07)) {
sval |= (1 << i);
}
}

switch (hal_data->bitLength) {
case 8:
return (int8_t)sval;
case 16:
return (int16_t)sval;
}

return sval;
}