Skip to content

Commit

Permalink
Fix LIBMODBUS_VERSION_HEX encoding (closes stephane#345)
Browse files Browse the repository at this point in the history
The result of LIBMODBUS_VERSION_HEX is left-shifted by an extra
factor of 8 bits.

For example, current implementation for version 1.2.3 would be
encoded like 0x01020300 instead of 0x010203.
  • Loading branch information
Giovanni Frigo authored and stephane committed Sep 7, 2016
1 parent 4b723c6 commit e86901b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/modbus-version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
*/
#define LIBMODBUS_VERSION_STRING "@LIBMODBUS_VERSION@"

/* Numerically encoded version, like 0x010203 */
#define LIBMODBUS_VERSION_HEX ((LIBMODBUS_VERSION_MAJOR << 24) | \
(LIBMODBUS_VERSION_MINOR << 16) | \
(LIBMODBUS_VERSION_MICRO << 8))
/* Numerically encoded version, eg. v1.2.3 is 0x010203 */
#define LIBMODBUS_VERSION_HEX ((LIBMODBUS_VERSION_MAJOR << 16) | \
(LIBMODBUS_VERSION_MINOR << 8) | \
(LIBMODBUS_VERSION_MICRO << 0))

/* Evaluates to True if the version is greater than @major, @minor and @micro
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

int main(void)
{
printf("Compiled with libmodbus version %s (%08X)\n", LIBMODBUS_VERSION_STRING, LIBMODBUS_VERSION_HEX);
printf("Compiled with libmodbus version %s (%06X)\n", LIBMODBUS_VERSION_STRING, LIBMODBUS_VERSION_HEX);
printf("Linked with libmodbus version %d.%d.%d\n",
libmodbus_version_major, libmodbus_version_minor, libmodbus_version_micro);

Expand Down

0 comments on commit e86901b

Please sign in to comment.