linuxcnc-ethercat icon indicating copy to clipboard operation
linuxcnc-ethercat copied to clipboard

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

Open plopes9000 opened this issue 3 years ago • 0 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; }

plopes9000 avatar Mar 19 '21 14:03 plopes9000