Commit 58426bc8aa73732fd6ca287fcce15b00984453fc
1 parent
31b6fecd
Declare some args with const
Showing
2 changed files
with
13 additions
and
12 deletions
modbus/modbus.c
| @@ -733,7 +733,7 @@ static int response_exception(modbus_param_t *mb_param, sft_t *sft, | @@ -733,7 +733,7 @@ static int response_exception(modbus_param_t *mb_param, sft_t *sft, | ||
| 733 | If an error occurs, this function construct the response | 733 | If an error occurs, this function construct the response |
| 734 | accordingly. | 734 | accordingly. |
| 735 | */ | 735 | */ |
| 736 | -void modbus_manage_query(modbus_param_t *mb_param, uint8_t *query, | 736 | +void modbus_manage_query(modbus_param_t *mb_param, const uint8_t *query, |
| 737 | int query_length, modbus_mapping_t *mb_mapping) | 737 | int query_length, modbus_mapping_t *mb_mapping) |
| 738 | { | 738 | { |
| 739 | int offset = mb_param->header_length; | 739 | int offset = mb_param->header_length; |
| @@ -1171,7 +1171,7 @@ int preset_single_register(modbus_param_t *mb_param, int slave, | @@ -1171,7 +1171,7 @@ int preset_single_register(modbus_param_t *mb_param, int slave, | ||
| 1171 | /* Sets/resets the coils in the slave from an array in argument */ | 1171 | /* Sets/resets the coils in the slave from an array in argument */ |
| 1172 | int force_multiple_coils(modbus_param_t *mb_param, int slave, | 1172 | int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1173 | int start_addr, int nb, | 1173 | int start_addr, int nb, |
| 1174 | - uint8_t *data_src) | 1174 | + const uint8_t *data_src) |
| 1175 | { | 1175 | { |
| 1176 | int i; | 1176 | int i; |
| 1177 | int byte_count; | 1177 | int byte_count; |
| @@ -1223,7 +1223,8 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave, | @@ -1223,7 +1223,8 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave, | ||
| 1223 | 1223 | ||
| 1224 | /* Copies the values in the slave from the array given in argument */ | 1224 | /* Copies the values in the slave from the array given in argument */ |
| 1225 | int preset_multiple_registers(modbus_param_t *mb_param, int slave, | 1225 | int preset_multiple_registers(modbus_param_t *mb_param, int slave, |
| 1226 | - int start_addr, int nb, uint16_t *data_src) | 1226 | + int start_addr, int nb, |
| 1227 | + const uint16_t *data_src) | ||
| 1227 | { | 1228 | { |
| 1228 | int i; | 1229 | int i; |
| 1229 | int query_length; | 1230 | int query_length; |
| @@ -1305,8 +1306,8 @@ int report_slave_id(modbus_param_t *mb_param, int slave, | @@ -1305,8 +1306,8 @@ int report_slave_id(modbus_param_t *mb_param, int slave, | ||
| 1305 | - data_bits: 5, 6, 7, 8 | 1306 | - data_bits: 5, 6, 7, 8 |
| 1306 | - stop_bits: 1, 2 | 1307 | - stop_bits: 1, 2 |
| 1307 | */ | 1308 | */ |
| 1308 | -void modbus_init_rtu(modbus_param_t *mb_param, char *device, | ||
| 1309 | - int baud, char *parity, int data_bit, | 1309 | +void modbus_init_rtu(modbus_param_t *mb_param, const char *device, |
| 1310 | + int baud, const char *parity, int data_bit, | ||
| 1310 | int stop_bit) | 1311 | int stop_bit) |
| 1311 | { | 1312 | { |
| 1312 | memset(mb_param, 0, sizeof(modbus_param_t)); | 1313 | memset(mb_param, 0, sizeof(modbus_param_t)); |
| @@ -1330,7 +1331,7 @@ void modbus_init_rtu(modbus_param_t *mb_param, char *device, | @@ -1330,7 +1331,7 @@ void modbus_init_rtu(modbus_param_t *mb_param, char *device, | ||
| 1330 | to 1024 because it's not necessary to be root to use this port | 1331 | to 1024 because it's not necessary to be root to use this port |
| 1331 | number. | 1332 | number. |
| 1332 | */ | 1333 | */ |
| 1333 | -void modbus_init_tcp(modbus_param_t *mb_param, char *ip, int port) | 1334 | +void modbus_init_tcp(modbus_param_t *mb_param, const char *ip, int port) |
| 1334 | { | 1335 | { |
| 1335 | memset(mb_param, 0, sizeof(modbus_param_t)); | 1336 | memset(mb_param, 0, sizeof(modbus_param_t)); |
| 1336 | strncpy(mb_param->ip, ip, sizeof(char)*16); | 1337 | strncpy(mb_param->ip, ip, sizeof(char)*16); |
modbus/modbus.h
| @@ -197,11 +197,11 @@ int preset_single_register(modbus_param_t *mb_param, int slave, | @@ -197,11 +197,11 @@ int preset_single_register(modbus_param_t *mb_param, int slave, | ||
| 197 | 197 | ||
| 198 | /* Sets/resets the coils in the slave from an array in argument */ | 198 | /* Sets/resets the coils in the slave from an array in argument */ |
| 199 | int force_multiple_coils(modbus_param_t *mb_param, int slave, | 199 | int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 200 | - int start_addr, int nb, uint8_t *data); | 200 | + int start_addr, int nb, const uint8_t *data); |
| 201 | 201 | ||
| 202 | /* Copies the values in the slave from the array given in argument */ | 202 | /* Copies the values in the slave from the array given in argument */ |
| 203 | int preset_multiple_registers(modbus_param_t *mb_param, int slave, | 203 | int preset_multiple_registers(modbus_param_t *mb_param, int slave, |
| 204 | - int start_addr, int nb, uint16_t *data); | 204 | + int start_addr, int nb, const uint16_t *data); |
| 205 | 205 | ||
| 206 | /* Returns the slave id! */ | 206 | /* Returns the slave id! */ |
| 207 | int report_slave_id(modbus_param_t *mb_param, int slave, uint8_t *dest); | 207 | int report_slave_id(modbus_param_t *mb_param, int slave, uint8_t *dest); |
| @@ -213,8 +213,8 @@ int report_slave_id(modbus_param_t *mb_param, int slave, uint8_t *dest); | @@ -213,8 +213,8 @@ int report_slave_id(modbus_param_t *mb_param, int slave, uint8_t *dest); | ||
| 213 | - data_bits: 5, 6, 7, 8 | 213 | - data_bits: 5, 6, 7, 8 |
| 214 | - stop_bits: 1, 2 | 214 | - stop_bits: 1, 2 |
| 215 | */ | 215 | */ |
| 216 | -void modbus_init_rtu(modbus_param_t *mb_param, char *device, | ||
| 217 | - int baud, char *parity, int data_bit, | 216 | +void modbus_init_rtu(modbus_param_t *mb_param, const char *device, |
| 217 | + int baud, const char *parity, int data_bit, | ||
| 218 | int stop_bit); | 218 | int stop_bit); |
| 219 | 219 | ||
| 220 | /* Initializes the modbus_param_t structure for TCP. | 220 | /* Initializes the modbus_param_t structure for TCP. |
| @@ -226,7 +226,7 @@ void modbus_init_rtu(modbus_param_t *mb_param, char *device, | @@ -226,7 +226,7 @@ void modbus_init_rtu(modbus_param_t *mb_param, char *device, | ||
| 226 | to 1024 because it's not necessary to be root to use this port | 226 | to 1024 because it's not necessary to be root to use this port |
| 227 | number. | 227 | number. |
| 228 | */ | 228 | */ |
| 229 | -void modbus_init_tcp(modbus_param_t *mb_param, char *ip_address, int port); | 229 | +void modbus_init_tcp(modbus_param_t *mb_param, const char *ip_address, int port); |
| 230 | 230 | ||
| 231 | /* By default, the error handling mode used is RECONNECT_ON_ERROR. | 231 | /* By default, the error handling mode used is RECONNECT_ON_ERROR. |
| 232 | 232 | ||
| @@ -280,7 +280,7 @@ int modbus_listen(modbus_param_t *mb_param, uint8_t *query, int *query_length); | @@ -280,7 +280,7 @@ int modbus_listen(modbus_param_t *mb_param, uint8_t *query, int *query_length); | ||
| 280 | If an error occurs, this function construct the response | 280 | If an error occurs, this function construct the response |
| 281 | accordingly. | 281 | accordingly. |
| 282 | */ | 282 | */ |
| 283 | -void modbus_manage_query(modbus_param_t *mb_param, uint8_t *query, | 283 | +void modbus_manage_query(modbus_param_t *mb_param, const uint8_t *query, |
| 284 | int query_length, modbus_mapping_t *mb_mapping); | 284 | int query_length, modbus_mapping_t *mb_mapping); |
| 285 | 285 | ||
| 286 | 286 |