Skip to content

modbus-debug #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions modbus_rtu.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,30 @@

*/


#include <stdio.h>
#include <string.h>

#include "hal.h"
#if MODBUS_DEBUG
#include "stream.h"
static void log_modbus_frame(const char *label,
const uint8_t *data,
uint8_t len)
{
char buf[64];
size_t n = (size_t)snprintf(buf, sizeof(buf), "%s:", label);
hal.stream.write(buf);

for(uint_fast8_t i = 0; i < len; i++) {
snprintf(buf, sizeof(buf), " %02X", data[i]);
hal.stream.write(buf);
}

hal.stream.write(ASCII_EOL);
}
#endif
#include "report.h"
#include "platform.h"
#include "protocol.h"
#include "settings.h"
Expand Down Expand Up @@ -152,6 +172,9 @@ static void tx_message (volatile queue_entry_t *msg)
rx_timeout = modbus.rx_timeout;

stream.flush_rx_buffer();
#if MODBUS_DEBUG
log_modbus_frame("TX", (const uint8_t *)msg->msg.adu, msg->msg.tx_length);
#endif
stream.write((char *)((queue_entry_t *)msg)->msg.adu, ((queue_entry_t *)msg)->msg.tx_length);
}

Expand Down Expand Up @@ -243,6 +266,9 @@ static void modbus_poll (void *data)
}
}

#if MODBUS_DEBUG
log_modbus_frame("RX", (const uint8_t *)((queue_entry_t *)packet)->msg.adu, rx_len);
#endif
if((state = packet->async ? ModBus_Silent : ModBus_GotReply) == ModBus_Silent) {
if(packet->callbacks.on_rx_packet) {
packet->msg.rx_length = rx_len;
Expand Down