0

I want to reduce the amount of bytes sent on the UART from Log strings. The idea is to replace the static strings of all the logs with index numbers and the Log module will send only the string index number and the parameters. From there, an application on the PC (that is connected though UART) using a file that contains all of the LOG strings and their indexes will create the correct string and print it.

How can I do that ?

cchapman
  • 3,269
  • 10
  • 50
  • 68
Samer.M
  • 121
  • 2
  • 10
  • Surely you already have message references in your embedded code, rather than hard coded string literals for each situation? If so, isn't transmitting their reference easier than transmitting their description text? But if not, it is time to convert your code so that you work with message references and not actual messages. Then when code space gets tight, you can move the message text to FLASH or to banked ROM etc. – Weather Vane Feb 04 '16 at 16:32
  • 2
    Possible duplicate of [Embedded console log optimization](http://stackoverflow.com/questions/25440962/embedded-console-log-optimization) – Ross Feb 04 '16 at 18:01
  • You have just described how you can do it - what don't you understand about your own solution? – Clifford Feb 04 '16 at 22:19

1 Answers1

0

What you want to do is to convert your log string into tokens. You have to create a dictionary that translates strings/string parts into tokens and the sender and receiver must have this dictionary. When you send your string, define a single escape character that is followed by a token and make sure that this escape code is nowhere else in your normal log strings.

In the sender, you must scan your strings before sending for string parts that are in your dictionary and then just send the escape code and the token. Everything else that is not found in your dictionary is transferred normally.

On the receiver side, your can simply decode this using the same dictionary.

By the way: this is the way a (very simple) compressor works. You also can use an LZW compressor algorithm, which maybe has even better results (but be sure not to clear the translation tables after each transmission!).

ul90
  • 762
  • 3
  • 8
  • I am not convinced that LZW compression will be successful on a MPU with limited resources. – Weather Vane Feb 04 '16 at 19:20
  • It depends on the MPU and on the maximum word size selection for the algorithm (and - of course - the amount of available ram is important for the dictionary). A long long long time ago, i implemented a LZW algorithm on a C64 and it worked. – ul90 Feb 04 '16 at 19:29
  • Yes, on a Commodore 64. But long long long long long ago ;-) – ul90 Feb 04 '16 at 19:38
  • how do i create this dictionary in an automatic way that is transparent to the programmer ? – Samer.M Feb 05 '16 at 08:23
  • It depends a little bit on the MCU you are using, the available memory and the type of strings you want to send. In general there are 2 different ways: static dictionary generated from source code (before compiling using a simple parser that extracts the strings and generates a source code file itself), and a dynamic dictionary generated while sending (in this case, the dictionary is build in RAM and your log protocol must include a command that defines a new dictionary entry so that the receiver can build the same dictionary). – ul90 Feb 05 '16 at 11:48