2017-09-18 07:31 AM
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....
2017-09-18 07:40 AM
switch/case can compile quite efficiently.
Consider using a table, with function pointers, using the first character to index into it.
2017-09-18 10:04 AM
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.
2017-09-18 10:16 AM
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.