This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
internal:can-tcpsockets-parsing [2018/02/05 10:14] – preisig | app-notes:can-tcpsockets-parsing [2019/07/03 08:00] – ↷ Page moved from internal:can-tcpsockets-parsing to app-notes:can-tcpsockets-parsing juraschek | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== How To - Forward CAN Frames | + | ====== How To - Forward CAN frames |
The following document describes two examples on how to work with CAN frames on a Netmodule router. Aside of the basic setup, forwarding CAN traffic over TCP sockets as well as simple CAN frame parsing are covered. | The following document describes two examples on how to work with CAN frames on a Netmodule router. Aside of the basic setup, forwarding CAN traffic over TCP sockets as well as simple CAN frame parsing are covered. | ||
- | ===== Test environment | + | ===== Environment setup ===== |
- | {{: | + | {{: |
- | The above graphic illustrates how the test environment was built and what data gets transmitted. First to be able to simulate a CAN bus in a local environment Peak Systems | + | The above graphic illustrates how the test environment was setup and what data gets transmitted. First to be able to simulate a CAN bus in a local environment |
===== Setup the CAN Interface on the Router ===== | ===== Setup the CAN Interface on the Router ===== | ||
Line 13: | Line 13: | ||
===== Peaksystem PCAN-FMS Simulator ===== | ===== Peaksystem PCAN-FMS Simulator ===== | ||
- | As mentioned in the introduction Peaksystems PCAN-FMS simluator is used to generate CAN Frames. The software is easy to use and allows a good starting point for local development. | + | As mentioned in the introduction Peaksystems PCAN-FMS simluator is used to generate CAN frames. The software is easy to use and allows a good starting point for local development. |
{{: | {{: | ||
===== Incoming RAW CAN Frames on the Router: ===== | ===== Incoming RAW CAN Frames on the Router: ===== | ||
- | The first and most simple test on the router | + | The first and most simple test on the router |
+ | |||
+ | By default, candump provides the following information: | ||
{{: | {{: | ||
Interface, CAN Identifier, DLC and DATA | Interface, CAN Identifier, DLC and DATA | ||
- | ===== Transmit | + | ===== Forward |
- | To show a possible use of forwarding CAN Frames over Ethernet can-tcp-broadcast.are provides a TCP Client | + | To show a possible use of forwarding CAN Frames over Ethernet can-tcp-broadcast.are provides a TCP client |
The function start_can() sets required attributes to the can interface and sets up a raw socket descriptor that is used in the main part of the script. Additionally filtering of CAN Identifiers is possible via nb_can_setfilter() to specify which CAN frames shall be filtered out and which shall be passed to upper layers. | The function start_can() sets required attributes to the can interface and sets up a raw socket descriptor that is used in the main part of the script. Additionally filtering of CAN Identifiers is possible via nb_can_setfilter() to specify which CAN frames shall be filtered out and which shall be passed to upper layers. | ||
+ | |||
+ | //Please be aware// that extended use of filtering or processing on the router itself may affect the overall processing power. An advice would be, to do data processing on a more powerful backend according to ones needs. | ||
+ | |||
<code c from can-tcp-broadcast.are> | <code c from can-tcp-broadcast.are> | ||
Line 57: | Line 63: | ||
- | Within the main loop receiving CAN messages is done with nb_can_recvmsg() which returns CAN Frames | + | Within the main loop receiving CAN messages is done with nb_can_recvmsg() which returns CAN frames |
+ | |||
+ | * CAN_EFF_FLAG --- EFF/SFF is set in the MSB | ||
+ | * CAN_RTR_FLAG --- remote transmission request | ||
+ | * CAN_ERR_FLAG --- error frame | ||
+ | * CAN_SFF_MASK --- standard frame format (SFF) | ||
+ | * CAN_EFF_MASK --- extended frame format (EFF) | ||
+ | * CAN_ERR_MASK --- omit EFF , RTR , ERR flags | ||
+ | |||
+ | |||
+ | Since FMS uses the extended frame format | ||
<code c from can-tcp-broadcast.are> | <code c from can-tcp-broadcast.are> | ||
Line 78: | Line 94: | ||
</ | </ | ||
- | On the receiving end SocketTest listens on TCP port 2000 and displays the CAN Frames: | + | On the receiving end SocketTest listens on TCP port 2000 and displays the raw CAN frames: |
{{: | {{: | ||
- | |||
- | This way data processing could be done on a more powerful backend according to ones needs. Please be sure to check the load of the router to assure normal operation of the device. | ||
- | |||
===== Simple CAN Frame parsing (simple-can-parser.are) ===== | ===== Simple CAN Frame parsing (simple-can-parser.are) ===== | ||
An additional test was made to show a simple way of parsing CAN Frames. The example is based on checking for a specific PGN (parameter group number) and then get a SPN (supect parameter name) to display its value in human readable format which then gets logged in a file. | An additional test was made to show a simple way of parsing CAN Frames. The example is based on checking for a specific PGN (parameter group number) and then get a SPN (supect parameter name) to display its value in human readable format which then gets logged in a file. | ||
The example used was “Wheel based speed”, SPN=84 PGN=0x00FEF1 (Cruise Control/ | The example used was “Wheel based speed”, SPN=84 PGN=0x00FEF1 (Cruise Control/ | ||
- | {{: | + | {{: |
<code c from simple-can-parser.are> | <code c from simple-can-parser.are> | ||
Line 111: | Line 125: | ||
</ | </ | ||
- | ===== Resources & SDK Scripts ===== | + | ===== SDK Scripts ===== |
- | The folllowing tools and ressources where used: | + | |
- | + | ||
- | * [[https:// | + | |
- | * [[https:// | + | |
- | * [[https:// | + | |
Below the used arena scripts (can-tcp-broadcast.are & simple-can-parser.are) are listed completly. | Below the used arena scripts (can-tcp-broadcast.are & simple-can-parser.are) are listed completly. | ||