Skip to content
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

Exposed frameFD.flags (for bitrate switching) #106

Closed
wants to merge 0 commits into from

Conversation

wdim0
Copy link
Contributor

@wdim0 wdim0 commented Oct 9, 2022

Hi,

I've made an important modification that enables users of node-can to do bitrate switching for CAN-FD frames.
Until now it was impossible (nobody complained yet?) - there was no way how to perform bitrate switching (set BRS bit in CAN-FD frame).
Bitrate switching is one of the main points of "FD" = "Flexible Data-rate".

frameFD.flags in SendFD method is now filled from new "fd_flags" symbol (feel free to rename if you come up with better name).
In the original code, the frameFD.flags was hardcoded to 0. But we need to be able to influence bit 2..0 in this flags field in order to fully control the transmission behavior.

Let's see how official "cansend" tool handles it and see the meaning of the flags:

image
image

This is a FD frame without bitrate switching (captured during my initial testing)
image

And this is FD frame with bitrate switching after the modification. fd_flags / flags is set to 0x01 in the "caller" code.
(same data as above)
image

Anyway, thanks for node-can!

Have a nice day

Martin

@wdim0
Copy link
Contributor Author

wdim0 commented Oct 20, 2022

Anybody alive there? This modification is rather important.

@sebi2k1
Copy link
Owner

sebi2k1 commented Oct 20, 2022

Hi and thanks for the pull request. But the change can't work. You are reading the field an object which doesn't have the field. You have to extend socketcan.json:363.

Please also make sure the way you introduce it must be compatible with existing implementation and should cover error cases too.

@wdim0
Copy link
Contributor Author

wdim0 commented Oct 23, 2022

Hi @sebi2k1,

thank you for your answer.

Sebi, you write that it can't work, yet it DO WORK for me - tested. Please note that not all users of node-can use "DatabaseService" - some do call "sendFD(...)" directly.
For example this:
https://github.com/grodansparadis/node-red-contrib-socketcan
which is the only up-to-date implementation of CAN bus handling for Node-RED (other similar cannot even send FD frames).
So for "sendFD(...)" callers, my modification is enough - tested.

And to be fair with you, I don't feel to be familiar enough with DatabaseService to change the code there (yes, I could guess, but I cannot test) so better approach than ask to pull non-tested and possible buggy code is to hope that you are willing to fill in the missing things to complete it if needed.
I really think that flags should be somehow passed to this:
image
in
image
because without it, node-can cannot be used to send CAN-FD messages with bitrate switching set on (which is the point of "FD" = "Flexible Data-rate").

node-can is awesome and gives the Node.js the ability to handle CAN bus. It knows CAN-FD. Let's give it possibility to use it fully.

Thanks, sorry for possible additional work for you and have a nice day @sebi2k1

Martin

@juleq
Copy link
Contributor

juleq commented Oct 24, 2022

@wdim0 I think you are misunderstanding the answer of @sebi2k1. His point was not that hardcoding in flags on the native side does not work technically. His point was that this PR cannot be accepted since adding support requires implementing the passing of these flags from js to native. And that prior validation, error handling and testing is required.

To the tone: This is an open source project and as far as I understand that, you are not entitled to allocate the time @sebi2k1 can spent.

If you want it fast, you could get into it and flesh out the PR as required.

If you cannot do that yourself, maybe you can ask @sebi2k1 to add a "help wanted" tag. I think this is a wonderful and straightforward task to get into open source contribution.

My best regards.

@wdim0
Copy link
Contributor Author

wdim0 commented Oct 25, 2022

Hi @juleq,

I'm sorry if what I wrote left an impression of a bad tone. I don't want to offend anybody and I don't want to demand anybody's time. I'm really grateful for node-can and for what all the contributors of node-can have achieved.

I don't need it fast. I have what I need working already. I just wanted to share this IMHO important improvement with others - to give to the community, not just take.

But yes, my modification is not visible to "DatabaseService". If the PR would be accepted, it will not break anything, it's backward compatible, but it exposes the new fd_flags only to users of native side (users like for example https://github.com/grodansparadis/node-red-contrib-socketcan is), not to the "DatabaseService" users. Maybe somebody sometime (not just @sebi2k1) will pick it up later and implement it for "DatabaseService" when needed.
I cannot do the modifications you require (extend socketcan.js:363, error handling, ...), because I don't use it this way.
I cannot test it - I cannot guarantee the code then. I don't use the "DatabaseService" and .kcd ecosystem.

@sebi2k1 - I'm sorry if I offended you. Please accept my apology in that case.
If you think that giving to users of node-can a possibility to produce CAN-FD frames with bitrate switching is a good idea, could you please:

a) add a "help wanted" tag as @juleq suggests

or
b) accept the PR and at least users of native side will be able to use it for now. The PR will not break anything and it's backward compatible - tested. If the new fd_flags is not filled/touched, it will have the same value of 0, as is hardcoded in the current official version:

frameFD.flags = 0; // Flags not used in this function

If you don't see any point in possibility to be able to produce CAN-FD frames with bitrate switching, then please close/discard this PR.

Thank you, all the good to you and have a nice day

Martin

Copy link
Owner

@sebi2k1 sebi2k1 left a comment

Choose a reason for hiding this comment

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

I am fine with the change if we limit it do the RawChannel for now. Proper integration of KCD (if supported) can be separated.

The only remark I have is that the flags should not be passed as a bitfield which requires the caller to know/understand socket can kernel headers files. I'd prefer to pass the individual flags as e.g. bools.

@@ -375,13 +376,16 @@ class RawChannel : public Nan::ObjectWrap
CHECK_CONDITION(info[0]->IsObject(), "First argument must be an Object");
CHECK_CONDITION(hw->IsValid(), "Invalid channel!");
struct canfd_frame frameFD;
frameFD.flags = 0; // Flags not used in this function
//frameFD.flags = 0; // Flags not used in this function
Copy link
Owner

Choose a reason for hiding this comment

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

Either remove the line or keep. No dead code please.

src/rawchannel.cc Outdated Show resolved Hide resolved
@@ -64,7 +64,8 @@ using namespace v8;
#define rtr_symbol SYMBOL("rtr")
#define err_symbol SYMBOL("err")
#define data_symbol SYMBOL("data")
#define canfd_symbol SYMBOL("canfd")
#define canfd_symbol SYMBOL("canfd")
#define fdflags_symbol SYMBOL("fd_flags")
Copy link
Owner

Choose a reason for hiding this comment

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

Please reconsider the approach. The basic idea of this API is to hide any kernel headers, so instead of pass a bit field of fdflags, I'd prefer to provide the individual flags. E.g. if someone wanna use bitrate switch you might call send(brs: True) instead of send(fdflags:3).

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