用AI写一个解析CANoe的ASC日志软件-从文档开始

定义了三大类 LIN报文:文档详细规定了如何用文本记录各种 LIN 总线活动的信息记录.
-
报文事件:正常的 LIN 帧收发。
-
错误事件:传输错误、接收错误、同步错误、校验和错误等。
-
信息/状态事件:波特率变化、休眠/唤醒、调度表切换等。
-
正常报文事件
0.073973 Li 2d Tx 8 00 f0 f0 ff ff ff ff ff checksum = 70 header time = 40, full time = 130 SOF = 0.067195 BR = 19230 break = 937125 114062 EOH = 0.069266 EOB = 0.069789 0.070312 0.070835 0.071358 0.071881 0.072404 0.072927 0.073450 sim = 1 EOF = 0.073973 RBR = 19231 HBR = 19230.769231 HSO = 26000 RSO = 26000 CSM = enhanced

-
错误事件 1.传输错误(TransmErr) 触发条件:主节点发送帧头后,无任何从节点返回响应。 报文格式如下: <Time> <Channel> <ID> TransmErr (slave = <slaveid>, state = <state>) header time = <headertime>, full time = <fulltime> SOF = <startofframe> BR = <baudrate> break = <SyncBreak> <SyncDel> (subId = <NAD> <MessageId> <SupplierId>) EOH = <endofheader> HBR = <headerbaudrate> HSO = <stopbitoffsetinheader> CSM = <checksummodel>实际报文: 0.424674 Li 33 TransmErr header time = 40, full time = 166 SOF = 0.416054 BR = 19230 break = 937187 113250 EOH = 0.418122 HBR = 19230.769231 HSO = 26000 CSM = enhanced2.接收错误(RcvError) 触发条件:包含多种场景:同步间隔过短、同步字段错误、ID 奇偶错误、从节点非法字符、帧错误、数据不匹配、帧不完整等.
<Time> <Channel> (<ID> <DLC>) RcvError: <description> (char = <offendingbyte>) (slave = <slaveid>, state = <state>) StateReason = <StateReason> ShortError = <IsShortError> DlcTimeout = <IsDLCTimeout> HasDatabytes = <HasDatabytes> (<D0>...<D7>) SOF = <startofframe> BR = <baudrate> break = <SyncBreak> <SyncDel> (subId = <NAD> <MessageId> <SupplierId>) (EOH = <endofheader>) (EOB = <T0> … <T7>) RBR = <responsebaudrate> HBR = <headerbaudrate> HSO = <stopbitoffsetinheader> RSO = <stopbitoffsetinresponse> CSM = <checksummodel>
0.554673 Li 33 8 RcvError: timeout while waiting for checksum field StateReason = 0c ShortError = 0 DlcTimeout = 0 HasDatabytes = 1 05 00 00 00 00 ff ff ff SOF = 0.546052 BR = 19230 break = 937187 112437 EOH = 0.548121 EOB = 0.548644 0.549167 0.549690 0.550213 0.550736 0.551259 0.551782 0.552305 RBR = 19231 RSO = 26000 HBR = 19230.769231 HSO = 26000 CSM = enhanced
报文格式:
<Time> <Channel> SyncError <TimeInterval0>..<TimeInterval3> SOF = <startofframe> BR = <baudrate> break = <SyncBreak> <SyncDel>
实际报文:
2.022336 L2 SyncError 208 0 0 0 SOF = 2.021077 BR = 19230 break = 937125 113312
4.校验和错误(CSErr)
触发条件:从节点发送的响应帧结构完整,但校验和计算错误.
报文格式:
<Time> <Channel> <ID> CSErr <Dir> <DLC> <D0>...<D7> (slave = <slaveid>, state = <state>) checksum = <checksum> header time = <headertime>, full time = <fulltime> SOF = <startofframe> BR = <baudrate> break = <SyncBreak> <SyncDel> (subId = <NAD> <MessageId> <SupplierId>) EOH = <endofheader> EOB = <T0> … <T7> sim = <simulated> EOF = <endofframe> RBR = <responsebaudrate> HBR = <headerbaudrate> HSO = <stopbitoffsetinheader> RSO = <stopbitoffsetinresponse> CSM = <unknown|classic|enhanced|error>
实际报文:
0.462829 Li 33 CSErr Tx 8 05 00 00 00 00 ff ff ff checksum = 86 header time = 40, full time = 130 SOF = 0.456050 BR = 19230 break = 937187 114875 EOH = 0.458122 EOB = 0.458645 0.459168 0.459691 0.460214 0.460737 0.461260 0.461783 0.462306 sim = 1 EOF = 0.462829 RBR = 19231 HBR = 19230.769231 HSO = 26000 RSO = 26000 CSM = enhanced
5.尖峰事件(Spike)
触发条件:检测到总线上持续时间小于 1 位时间的显性干扰信号.
报文格式:
<Time> <Channel> Spike <Dir> <SpikeLength> microseconds SOF = <startofframe> BR = <baudrate>
实际报文:
5.990958 L2 Spike Rx 56 microseconds SOF = 5.990902 BR = 9615
-
LIN 睡眠 / 唤醒事件(LIN Sleep/Wakeup Events)
触发条件:LIN 硬件在唤醒 / 睡眠模式之间切换时生成
报文格式:
<Time> <Channel> SleepModeEvent <simulated> <descriptiontext><Time> <Channel> Unexpected wakeup: approx. <Width> us SOF = <startofframe> BR = <baudrate>
实际报文:
0.7772 Li SleepModeEvent 0 entering sleep mode due to sleep mode frame
0.892363 Li Unexpected wakeup: approx. 260 us SOF = 0.891843 BR = 19230
提取文档所有示例报文
向豆包/DeepSeek输入提取所有的示例报文到一个文件即可:

将示例报文丢给AI
之所以用示例报文,是因为包含的测试用例比较全面。接下来只需要告诉AI:C++解析测试报文,思考过程如下:

思考过程考虑了到每一种类型的帧的解析,还是挺不错的.
核心代码如下:
bool parseMessageLine(const std::string& line, std::vector<LINMessage>& messages) {std::regex msgRegex(R"(^([\d.]+)\s+(Li|L\d)\s+([0-9a-fA-F]{2})\s+(Tx|Rx)\s+(\d+)\s+([0-9a-fA-F\s]+)\s+checksum\s*=\s*([0-9a-fA-F]+))");std::smatch match;if (std::regex_search(line, match, msgRegex)) {LINMessage msg;msg.timestamp = std::stod(match[1]);msg.channel = match[2];std::string idStr = match[3];msg.id = std::stoi(idStr, nullptr, 16);msg.direction = match[4];msg.dlc = std::stoi(match[5]);std::string dataStr = match[6];std::istringstream dataStream(dataStr);unsigned int byte;while (dataStream >> std::hex >> byte) {msg.data.push_back(static_cast<unsigned char>(byte));}msg.attributes["checksum"] = match[7];extractAttributes(line, msg.attributes);messages.push_back(msg);return true;}return false;}bool parseErrorLine(const std::string& line, std::vector<LINError>& errors) {std::regex patterns[] = {std::regex(R"(^([\d.]+)\s+(Li|L\d)\s+\w+\s+TransmErr)"),std::regex(R"(^([\d.]+)\s+(Li|L\d)\s+\w+\s+\d+\s+RcvError)"),std::regex(R"(^([\d.]+)\s+(L\d)\s+SyncError)"),std::regex(R"(^([\d.]+)\s+(Li|L\d)\s+\w+\s+CSErr)"),std::regex(R"(^([\d.]+)\s+(L\d)\s+Spike)"),std::regex(R"(^([\d.]+)\s+(Li)\s+Dominant\s+signal)")};
当然也可以指定AI用其他的编程语言,如使用前端编程,界面漂亮还免安装.

夜雨聆风