Skip to main content
Mathias Zviedris
Associate II
September 18, 2017
Question

Parsing ETH/RS232<->CAN

  • September 18, 2017
  • 3 replies
  • 1040 views
Posted on September 18, 2017 at 16:31

Hi community,

i have following situation:

PC <--- ETH or RS232 ----> STM32F107 < ----CAN---- > STM32F105 with external power module

I want to parse the ascii message (example K01NC|200) to a smaller protocol what i can send via CAN-Bus at once (max 8 Byte). Maybe to '0xA3' . 

When the STM32F105 has the work finished the work, a echo should be send back to the pc. So the F107 has to translate the echo from the F105 ('0xA3' to '

K01NC|200') and send it back to the pc.

Is there any parser what is already finished and can manage that ?

There are to many commands, so that i dont want to check via switch/case....

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    September 18, 2017
    Posted on September 18, 2017 at 16:40

    switch/case can compile quite efficiently.

    Consider using a table, with function pointers, using the first character to index into it.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Mathias Zviedris
    Associate II
    September 18, 2017
    Posted on September 18, 2017 at 17:04

    I agree with you, but there a nearly 60 commands... und i have to translate it in two ways and i dont want to write a parser from ETH-->CAN and another from CAN-->ETH.

    If i want to implement a new command, then i have to change everything in both parsers.

    Tesla DeLorean
    Guru
    September 18, 2017
    Posted on September 18, 2017 at 17:16

    Then build one table and have software generate others.

    If you are matching strings, then build a table of them, sort them, and then do a binary search, and have that drop out an index. Should result in the minimum number of comparisons.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..