Skip to content

Conversation

@donghoonpark
Copy link
Contributor

@donghoonpark donghoonpark commented Nov 8, 2025

Like in #105, a custom flush function can help reduce the blocking time of the read API, especially when using an intermediate buffer with DMA. I’ll also update my embedded example if this pull request is accepted.

This PR also includes the following minor changes:

  • __suseconds_t is not available on Apple arm64, so I added an alias for it.
  • Added a launch.json configuration to debug the tests directly in VS Code using the cppdbg debugger.
  • Edited tests/nanomodbus_test.c to pass clang-format ci step

I've already ran tests and checked all passed.

void nmbs_platform_conf_create(nmbs_platform_conf* platform_conf) {
memset(platform_conf, 0, sizeof(nmbs_platform_conf));
platform_conf->crc_calc = nmbs_crc_calc;
platform_conf->flush = flush;
Copy link

@taraskornuta taraskornuta Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a similar thing, but I try to keep original code
It makes nmbs->platform.flush an optional

static void flush(nmbs_t* nmbs) {
    if (nmbs->platform.flush) {
        nmbs->platform.flush(nmbs->platform.arg);
    } else {
        nmbs->platform.read(nmbs->msg.buf, sizeof(nmbs->msg.buf), 0, nmbs->platform.arg);
    }
}

@donghoonpark
Copy link
Contributor Author

@debevv Could you please check this PR?

@debevv
Copy link
Owner

debevv commented Jan 9, 2026

Hi, sorry for the absence.
@donghoonpark why does it return int now? Maybe to communicate the bytes discarded? If yes, are we sure all users will be able to get this information from the underlying system?

The rest seems all ok

@donghoonpark
Copy link
Contributor Author

My intention was exactly same as you mentioned in embedded system.
When it comes to os including posix, windows do not give the information about the count of dropped bytes but gives success/fail flags. As it also a int type, I thought that it would be better to keep the return type as int.
Just let me know the way you preferred and I'll revise it. Or you can change the type to void before merge. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants