libmodbus
libmodbus copied to clipboard
first try of a patch to enable sniffing on serial lines
This is my first try to introduce a function for sniffing on a serial line.
I get compiling errors I can't resolve. Could you help me?
.libs/modbus-data.o:(.data.rel.local+0x0): multiple definition of `ucl_msg_type'
.libs/modbus.o:(.data.rel.local+0x0): first defined here
.libs/modbus-rtu.o:(.data.rel.local+0x0): multiple definition of `ucl_msg_type'
.libs/modbus.o:/tmp/libmodbus/src/modbus.c:45: first defined here
.libs/modbus-tcp.o:(.data.rel.local+0x0): multiple definition of `ucl_msg_type'
.libs/modbus.o:/tmp/libmodbus/src/modbus.c:45: first defined here
collect2: error: ld returned 1 exit status
Makefile:447: recipe for target 'libmodbus.la' failed
make[2]: *** [libmodbus.la] Error 1
Makefile:500: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
Makefile:386: recipe for target 'all' failed
make: *** [all] Error 2
Could someone please review and tell me if it's worth working further on it?
Thanks and best regards
This patch introduces a dependency on stpcpy! I develop under linux, maybe windows reacts different.
Do I have to renew the pull request after my latest change?
No, small, incremental fix-changes are good and will be squashed when merged. Big changes are better to be squashed by yourself and push-forced onto your branch. This Pull-Request will automatically update in this case.
It seems you are using a different email address for your git-configuration than here on github. Better is to use the same one or the add your git-address to your github account.
Github is currently not able to see that Lars Täuber and gitaeuber are the same person.
OK, thanks. I hope next commit I'll do has the correct setting.
Maybe I should explain how my function works:
modbus_rtu_sniff_msg(modbus_t *ctx, int16_t *cnt, void (*handle_over_ucl)(char *ucl, int16_t *cnt))
- waits for pause between two messages
- repeat {
** read a complete message (up to 256 byte length, or till a pause of 3,5 bytes length is recognized, what ever comes first)
** parses this message to UCL
** call
handle_over_ucl
with the generated \0-terminated char* of the UCL-encoded msg as a parameter (should be a very fast function to not miss the start of the next message) ** if (cnt > 0) then decrease by one - } until cnt is 0 ( if (cnt < 0) do endlessly)
To do it this way I copied the error handling after select
from modbus.c. Therefore I had to remove the static from _sleep_response_timeout
and make it public in modbus-private.h
.
I also added a message_type
of UNKNOWN
, because while start parsing it is impossible to know wether it is a request or response for modbus on a serial line.
I hope this helps reading my patch.
Is this approach the right way to support serial sniffing? Or should it look different? I ask because I want to know whether it is worth working on it.
Now seeing how you are trying to output (ucl) the frames I'm not sure whether sniffing with the help of this library is the right approach. Wouldn't it be more appropriate to use a serial-bus-sniffer and add support for modbus to wireshark?
Or do you consider using the functions and tools of this library is mandatory to achieve analyzing modus-serial-bus traffic?
I don't think it is mandatory to use the functions of this library to achieve analyzing the traffic.
Maybe I should write a standalone tool for the command line that could added to a /tool to libmodbus?
What do you think about reducing modbus_rtu_sniff_msg to only receive and print messages - not parsing them? That function has the only purpose to recognize the pause timeouts between the messages. One message per line.
I'm unsure if it is a good idea to have a function called after reception of a complete message.