eric2013 发表于 2023-8-4 01:23:28

制作个简易的H7-TOOL CANFD助手区分不同ID,在不同窗口展示的脚本

【问题描述】

比如目标板发送了两种ID,0x111和0x222,正常情况下,TOOL的接收情况是这样的:



我们希望在窗口0和窗口1分别显示ID 0x111和0x222的数据,TOOL的上位机支持16个窗口,从窗口0到窗口15:



【实现方法】

当前TOOL自动的脚本已经支持了,在软件包目录:



比如打开文件STM32_V7_CANFD_decoder.lua,解释如下,大家可以根据需要修改:



TOOL上位机加载此脚本:



动态效果如下:




当前支持16个窗口,大家可以根据需要添加:

------------------------------------------------------------------
-- 空解码器。 记事本可编辑,txt后缀实际就是lua脚本文件
------------------------------------------------------------------

--分窗标志定义
WIN_0 = 0x0001
WIN_1 = 0x0002
WIN_2 = 0x0004
WIN_3 = 0x0008
WIN_4 = 0x0010
WIN_5 = 0x0020
WIN_6 = 0x0040
WIN_7 = 0x0080
WIN_8 =0x0100
WIN_9 =0x0200
WIN_10 = 0x0400
WIN_11 = 0x0800
WIN_12 = 0x1000
WIN_13 = 0x2000
WIN_14 = 0x4000
WIN_15 = 0x8000

--CAN 解码函数,返回的字符串将展示到数据窗口
--id 帧ID
--std_ext 0表示标准帧, 1表示扩展帧
--data_remote 0表示数据帧, 1表示远程帧
--datalen 数据长度,字节
--data_bin 二进制数据
--函数返回: ret1解码字符串 , ret2分窗控制字, 波形数据字符串
function can_decoder(id, std_ext, data_remote, datalen, data_bin)
      local ret1 = ""                --返回值1 解码显示结果
      local ret2 = 0          --返回值2 分窗标志
      local str_wave = ""      

      --逻辑与 and,逻辑或 or,不等于 ~=
      if (id == 0x07E8) then
                ret2 = ret2 | WIN_0
      elseif (id == 0x07DF) then
                ret2 = ret2 | WIN_1
      elseif (id == 0x0002) then
                ret2 = ret2 | WIN_2
      elseif (id == 0x0003) then
                ret2 = ret2 | WIN_3
      elseif (id == 0x0004) then
                ret2 = ret2 | WIN_4
      elseif (id == 0x0005) then
                ret2 = ret2 | WIN_5
      elseif (id == 0x0006) then
                ret2 = ret2 | WIN_6
      elseif (id == 0x0007) then
                ret2 = ret2 | WIN_7
      elseif (id == 0x0008) then
                ret2 = ret2 | WIN_8
      elseif (id == 0x0009) then
                ret2 = ret2 | WIN_9
      elseif (id == 0x000A) then
                ret2 = ret2 | WIN_10
      elseif (id == 0x000B) then
                ret2 = ret2 | WIN_11
      elseif (id == 0x000C) then
                ret2 = ret2 | WIN_12
      elseif (id == 0x000D) then
                ret2 = ret2 | WIN_13
      elseif (id == 0x000E) then
                ret2 = ret2 | WIN_14
      elseif (id == 0x000F) then
                ret2 = ret2 | WIN_15      
      end

      return ret1, ret2, str_wave
end


nnqtdf 发表于 2023-8-4 09:02:23

逗号分隔又去掉了?

eric2013 发表于 2023-8-4 10:08:50

nnqtdf 发表于 2023-8-4 09:02
逗号分隔又去掉了?

逗号还在,楼主位是临时贴了个之前版本的图。

eric2013 发表于 2023-8-4 11:23:53

更新完毕。
页: [1]
查看完整版本: 制作个简易的H7-TOOL CANFD助手区分不同ID,在不同窗口展示的脚本