Commit 8d1493f9752a25a1c388969462c030e3b5f2ed92

Authored by Stéphane Raimbault
1 parent 4d75c35b

Reduce the number of defines about maximum values for status and registers.

1 1 Features
  2 +* check the count, eg. read_holding_registers (MAX_STATUS, etc)
2 3 * args in command line (master/slave)
3 4 * broadcasting
4 5 * slave must listen only request sent for him
... ... @@ -7,4 +8,4 @@ Cleanups
7 8 * t_id in param_msqg
8 9  
9 10 Documentation
10   -* README with a example to test the library
  11 +* README with an example to test the library
... ...
modbus/modbus.c
... ... @@ -998,9 +998,10 @@ int read_holding_registers(modbus_param_t *mb_param, int slave,
998 998 {
999 999 int status;
1000 1000  
1001   - if (count > MAX_READ_HOLD_REGS) {
1002   - printf("WARNING Too many holding registers requested\n");
1003   - count = MAX_READ_HOLD_REGS;
  1001 + if (count > MAX_REGISTERS) {
  1002 + printf("WARNING Too many holding registers requested (%d > %d)\n",
  1003 + count, MAX_REGISTERS);
  1004 + count = MAX_REGISTERS;
1004 1005 }
1005 1006  
1006 1007 status = read_registers(mb_param, slave, FC_READ_HOLDING_REGISTERS,
... ... @@ -1015,9 +1016,10 @@ int read_input_registers(modbus_param_t *mb_param, int slave,
1015 1016 {
1016 1017 int status;
1017 1018  
1018   - if (count > MAX_READ_INPUT_REGS) {
1019   - printf("WARNING Too many input registers requested\n");
1020   - count = MAX_READ_INPUT_REGS;
  1019 + if (count > MAX_REGISTERS) {
  1020 + printf("WARNING Too many input registers requested (%d > %d)\n",
  1021 + count, MAX_REGISTERS);
  1022 + count = MAX_REGISTERS;
1021 1023 }
1022 1024  
1023 1025 status = read_registers(mb_param, slave, FC_READ_INPUT_REGISTERS,
... ... @@ -1123,9 +1125,10 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave,
1123 1125  
1124 1126 uint8_t query[MAX_MESSAGE_LENGTH];
1125 1127  
1126   - if (nb_points > MAX_WRITE_COILS) {
1127   - printf("WARNING Writing to too many coils\n");
1128   - nb_points = MAX_WRITE_COILS;
  1128 + if (nb_points > MAX_STATUS) {
  1129 + printf("WARNING Writing to too many coils (%d > %d)\n",
  1130 + nb_points, MAX_STATUS);
  1131 + nb_points = MAX_STATUS;
1129 1132 }
1130 1133  
1131 1134 query_length = build_query_basis(mb_param, slave, FC_FORCE_MULTIPLE_COILS,
... ... @@ -1171,9 +1174,10 @@ int preset_multiple_registers(modbus_param_t *mb_param, int slave,
1171 1174  
1172 1175 uint8_t query[MAX_MESSAGE_LENGTH];
1173 1176  
1174   - if (nb_points > MAX_WRITE_REGS) {
1175   - printf("WARNING Trying to write to too many registers\n");
1176   - nb_points = MAX_WRITE_REGS;
  1177 + if (nb_points > MAX_REGISTERS) {
  1178 + printf("WARNING Trying to write to too many registers (%d > %d)\n",
  1179 + nb_points, MAX_REGISTERS);
  1180 + nb_points = MAX_REGISTERS;
1177 1181 }
1178 1182  
1179 1183 query_length = build_query_basis(mb_param, slave,
... ...
modbus/modbus.h
... ... @@ -44,11 +44,8 @@ extern "C" {
44 44  
45 45 #define MAX_MESSAGE_LENGTH 256
46 46  
47   -#define MAX_READ_STATUS 800
48   -#define MAX_READ_HOLD_REGS 100
49   -#define MAX_READ_INPUT_REGS 100
50   -#define MAX_WRITE_COILS 800
51   -#define MAX_WRITE_REGS 100
  47 +#define MAX_STATUS 800
  48 +#define MAX_REGISTERS 100
52 49  
53 50 #define REPORT_SLAVE_ID_LENGTH 75
54 51  
... ...