Skip to content

Commit

Permalink
FIX: interpret analog input values as int16
Browse files Browse the repository at this point in the history
Both signed and unsigned representations behave like a signed 16-bit
integer. In the case of unsigned, the value is limited to the range
0-32767, the former is limited to -32768-32767. As such, treating the
values from the terminal as int16 (and thus sign extending them when
assigning to RVAL) is the correct way of doing things.

This does not handle the MSB representation properly however. That will
require more work down the line if we ever decide to support it. For
now, users will need to use the unsigned or signed representations for
the data to be correctly read.
  • Loading branch information
JJL772 committed Jul 17, 2024
1 parent 8f8a6d2 commit c88ad08
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ek9000App/src/devEL3XXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct EL30XXStandardInputPDO_t {
uint8_t _r2 : 6; // Last bit in this align is Sync error for EL31XX
uint8_t txpdo_state : 1;
uint8_t txpdo_toggle : 1;
uint16_t value;
int16_t value; // Must be signed to accommodate bipolar terminals. Unsigned representation still defines range as 0-32767, so this is safe.
};
#pragma pack()

Expand Down Expand Up @@ -339,7 +339,7 @@ struct EL331XInputPDO_t {
uint8_t error : 1;
uint8_t txpdo_state : 1;
uint8_t txpdo_toggle : 1;
uint16_t value;
int16_t value;
};

struct EL3314_0010_InputPDO_t {
Expand All @@ -351,7 +351,7 @@ struct EL3314_0010_InputPDO_t {
uint8_t txpdo_state : 1;
uint8_t txpdo_toggle : 1;
uint8_t padding1 : 7; // Pad it out to byte boundary
uint16_t value;
int16_t value;
};
#pragma pack()

Expand Down

0 comments on commit c88ad08

Please sign in to comment.