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

RTR is not returned #33

Open
csBlueChip opened this issue Mar 5, 2018 · 0 comments
Open

RTR is not returned #33

csBlueChip opened this issue Mar 5, 2018 · 0 comments

Comments

@csBlueChip
Copy link
Contributor

https://forum.macchina.cc/t/can-library-does-not-return-rtr-solved/610

I notice due_can declares a variable in which to hold RTR, but that variable is never populated.
This bug exists in (as far as I can tell) every version of the library.

I have patched the (6 month old) version of the library (as linked from the M2 Git repo), but it is not obvious how to properly fork/pullRq/submit the patch
...I have not yet patched the write function but...
...If you want to know if a CAN device is requesting data, here's the patch:

  • Open C:\Users\YourUserName\AppData\Local\Arduino15\packages\macchina\hardware\sam\0.2.1\libraries\due_can\due_can.cpp
    ...If you're not using Windows - you're just going to have to go hunting for that file - sorry.

  • Search for the string "fid" [Family ID] ...there's only one occurence of this string in this file:
    rxframe->fid = m_pCan->CAN_MB[uc_index].CAN_MFID;

  • Just after/before/near ^that^, line add this line:
    rxframe->rtr = (m_pCan->CAN_MB[uc_index].CAN_MSR & CAN_MSR_MRTR) ? 1 : 0 ;

  • That's it, you can now identify Remote Transmit Request packets with something like:
    if (frame.rtr) rtrHandler(frame) ;

  • If you like diff files, enjoy this:

--- C:\original\due_can.cpp	2018-03-03 15:35:22.000000000 -0000
+++ C:\rtr_fix\due_can.cpp	2018-03-03 15:38:02.000000000 -0000
@@ -1026,12 +1026,13 @@
 		rxframe->id = (ul_id  >> CAN_MID_MIDvA_Pos) & 0x7ffu;
 		rxframe->extended = false;
 	}
 	rxframe->fid = m_pCan->CAN_MB[uc_index].CAN_MFID;
 	rxframe->length = (ul_status & CAN_MSR_MDLC_Msk) >> CAN_MSR_MDLC_Pos;
     rxframe->time   = (ul_status & CAN_MSR_MTIMESTAMP_Msk);
+    rxframe->rtr    = (m_pCan->CAN_MB[uc_index].CAN_MSR & CAN_MSR_MRTR) ? 1 : 0;
     ul_datal = m_pCan->CAN_MB[uc_index].CAN_MDL;
 	ul_datah = m_pCan->CAN_MB[uc_index].CAN_MDH;
 
 	rxframe->data.high = ul_datah;
 	rxframe->data.low = ul_datal;```
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

No branches or pull requests

1 participant