debevv / nanoMODBUS

A compact MODBUS RTU/TCP C library for embedded/microcontrollers
MIT License
234 stars 47 forks source link

Make internal buffer size configurable #20

Open lammermann opened 1 year ago

lammermann commented 1 year ago

I use this library in a constraint embedded environment, where I need a smaller buffer size to run it. Would you consider accepting this change to make the buffer size configurable by the user?

Greetings Benjamin

debevv commented 1 year ago

Hi, thanks for your contribution. The are some things you should check:

lammermann commented 1 year ago

Hi, thanks for your contribution. The are some things you should check:

* The code in the PR does not build. There should be a typo in the define name

Sorry that I was so sloppy with the first patch. I fixed the typo now.

* `NMBS_INTERAL_MAX_REGISTER_QUANTITY` size may not be correct for both TCP and RTU transports. Please check the standard

I tried to fix it according to the modbus spec. As modbus tcp needs more bytes than rtu I used it's size to be safe in both cases. However I recognized that some tests are failing now as they check that a quantity bigger than 125 fails with an error message. What is the reason for the hard coded 125 limit? I see two solutions here: Either reducing the default value of NMBS_INTERNAL_BUFFER_SIZE to 257. Or to change the tests. What do you prefer?

* Please format the code using the provided .clang-tidy file

I ran clang-tidy nanomodbus.c nanomodbus.h but it did not reformat anything. The only complaints it had were about using memset but those are not connected to the code I changed. I never used clang-tidy before so it's possible I did not use it correctly.

Greetings, Benjamin