我该怎么办printf型调试通过速度较慢的CAN总线 - 用遥控器上的工具,而不是嵌入式系统常量字符串 [英] How can I do printf style debugging over a slow CAN bus - with constant strings on the remote tool, not the embedded system

查看:158
本文介绍了我该怎么办printf型调试通过速度较慢的CAN总线 - 用遥控器上的工具,而不是嵌入式系统常量字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的嵌入式系统(在C codeD)上,我有很多当远程工具迷上了那个可以显示信息到PC的系统所执行的调试辅助打印报表。这些帮助理解的一般的系统状态,但随着消息要通过慢速CAN总线,相信它们可以堵塞管子和引起其它问题,试图得到任何有用的数据记录下来。

Currently, on my embedded system (coded in C), I have a lot of debug-assistive print statements which are executed when a remote tool is hooked up to the system that can display the messages to a PC. These help to understand the general system status, but as the messages are going over a slow CAN bus, I believe they may be clogging the tubes and causing other problems with trying to get any useful data logged.

它的基本精神是:

这就像一个printf,但最终在被从嵌入式系统发送到该工具通过CAN总线一种特殊的消息格式。为此,我可以与发送一个唯一的ID后跟只有可变参数(即ARGC / argv的)特殊的调试信息替换这个通用的打印信息。我想知道,如果是去了解它的正确方法,或者如果有妙法我已经错过了,或者别的东西我都没有想到的。

It's like a printf, but ultimately in a special message format that gets sent from the embedded system to the tool over the CAN bus. For this purpose, I can replace this generic print message with special debugging messages that send it a unique ID followed by only the variable parameters (i.e. the argc/argv). I am wondering if that is the right way to go about it, or if there is a magic bullet I've missed, or something else I haven't thought of.

所以,我发现这个问题,它开出以及我的目的:

So, I found this question which starts out well for my purposes:

<一个href=\"http://stackoverflow.com/questions/6912406/printf-debugging-library-using-string-table-de$c$cr-ring\">printf()德codeR环QUOT;使用字符串表&QUOT调试库

但我没有使它容易,因为一个printf的约束。我可以保持对远程工具的侧弦的表(因为它是一个Windows可执行文件,因此没有为code尺寸有限)。我负责这个code的唯一的人,将preFER,试图减仓code尺寸以及CAN总线流量,同时调试。

But I do not have the constraint of making it as easy as a printf. I can maintain a table of strings on the remote tool's side (since it's a Windows executable and therefore not as code size limited). I am the sole person responsible for this code and would prefer to try and lighten up the code size as well as the CAN bus traffic while debugging.

我现在的想法是这样的:

My current thoughts are thus:

printf("[%d] User command: answer call\n", (int)job);

这成为

debug(dbgUSER_COMMAND_ANSWER_CALL, job);

dbgUSER_COMMAND_ANSWER_CALL 是可能的调试信息的枚举的一部分

dbgUSER_COMMAND_ANSWER_CALL being part of an enum of possible debug messages

和远程端有类似

switch(messagetype)
{
case dbgUSER_COMMAND_ANSWER_CALL:
    /* retrieve an integer from the data portion of the message and put it into a variable */
    printf("[%d] User command: answer call\n", (int)avariable);
}

这是比较直接,这将是美妙的,如果我的所有邮件中传出了那相同的格式。地方变得棘手,虽然是在那里我的一些陈述有要打印的字符串不属于常数(该设备的名称,例如)。

That's relatively straightforward and it would be fantastic if all my messages came in that same format. Where it gets tricky, though, is where some of my statements have to print strings which are not constant (the name of the device, for example).

printf("[%d] %02X:%02X:%02X:%02X:%02X:%02X (%s)\n", /* a bunch of parameters here */);

所以,我应该让这个调试消息的内容是:1)消息类型的第一个参数,2)的长度,3)的参数,4)的下一个参数的长度,5)的参数,等等等等

So, should I make it so that the contents of the debug message are 1) the message type, 2) length of the first parameter, 3) the parameter, 4) length of the next parameter, 5) the parameter, so on and so forth

还是我忽略了一些比较明显或容易?

Or have I overlooked something more obvious or easy?

感谢

推荐答案

我假设你使用CAN,因为这是你已经拥有你的设备的连接。你还没有真正提供有关诊断需要足够的信息,但我可以给我们做什么,我的工作的例子。我们使用自定义生成工具,通过我们的来源建立一个字符串表梳理。我们code使用是这样的:

I'm assuming you use CAN because that's the connection you already have to your device. You haven't really provided enough information about your diagnostic needs, but I can give an example of what we do where I work. We use a custom build tool to comb through our sources building up a string table. Our code uses something like:

        log( LOGH(T0722T),                        //"Position"
             LOG_DOT_HEX_VALUE(i),
             LOG_TEXT(T0178T),                    //"Id"
             LOG_DOT_VALUE(uniqueId % 10000),
             0 );

这会记录一些数据,这可能是德coded到:

This would record some data which could be decoded into:

&LT;&时间戳GT; ^ h Position.00B Id.0235

<timestamp> H Position.00B Id.0235

我们允许使用T0000T的有工具查找(或生成)一个唯一的号码我们。该工具建立了使用TxxxxT号码为编译的枚举和包含字符串的有序列表的文件。每次构建产生一个枚举编号相匹配的字符串表。该系统还关系到用于生成国际化字符串的数据库系统,但是这不是你的问题真正相关。

We allow use of T0000T to have the tool lookup (or generate) a unique number for us. The tool builds up an enum using the TxxxxT numbers for the compiler, and a file containing the ordered list of strings. Every build generates a string table which matches the enum numbering. This system also ties into a database system used for generating internationalized strings, but that's not really relevant to your question.

每个元素是一个短的(16比特)。我们允许值12位,并使用高4位的类型和标志信息。是EN codeD数据字符串ID;它是一个信号(高/低),或者只是一个事件;它是一个值;它是十进制,十六进制,base64url;级联(与preceding项),或单独的。

Each element is a short (16 bits). We allow 12 bits for values and use the high 4 bits for type and flag info. Is the encoded data a string id; Is it a signal (High/Low) or just an event; Is it a value; Is it decimal, hexidecimal, base64url; concatenated (with the preceding item) or separate.

我们的,如果需要查询记录在一个大的环形缓冲区的数据。这使得该系统在不干扰运行,但如果一个问题指出,可以提取数据。这当然是可以不断地发送数据,而如果这是需要的,我建议限制任何一个消息到一个单独的CAN有效载荷(这是8个字​​节假设你只使用一个ID)。如果适当地连接codeD(假定接收端产生的时间戳)我上面提供的消息可以适合一个CAN报文。

We record data in a large ring buffer for querying if needed. This allows the system to run without interference but the data can be extracted if a problem is noted. It is certainly possible to constantly send the data, and if that's desired I'd suggest limiting any one message to a single CAN payload (that's 8 bytes assuming you only use a single ID). The message I provided above would fit in one CAN message if properly encoded (assuming the receiving side created the timestamps).

我们确实有包括任意数据(ASCII或十六进制)的能力,但我从来没有使用它。它通常是在日志precious空间的浪费。日志总是在嵌入式环境的平衡。

We do have the ability to include arbitrary data (ASCII or Hexadecimal), but I never use it. It's usually a waste of precious space in the logs. Logging is always a balance in embedded environments.

这篇关于我该怎么办printf型调试通过速度较慢的CAN总线 - 用遥控器上的工具,而不是嵌入式系统常量字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆