python libs和脚本,用于漂亮地打印j1939日志

pretty-j1939的Python项目详细描述


pretty_j1939

python3 libs和脚本,用于漂亮地打印J1939 candump日志

这个包裹可以:

  1. 漂亮的J1939打印流量捕获在坎杜普日志和
  2. 将J1939数字附件(Excel)文件转换为JSON结构,以在上面使用

一些漂亮的打印示例

格式化的内容(每行一个)在candump数据旁边:

$ pretty_j1939.py --candata=true --format=true --link=true --transport=true example.candump.txt | head
(1543509533.000838) can0 10FDA300#FFFF07FFFFFFFFFF ;{;"DA": "All(255)",
                                                   ;"PGN": "EEC6(64931)",
                                                   ;"SA": "Engine #1(  0)",
                                                   ;"Engine Variable Geometry Turbocharger Actuator #1": "2.8000000000000003 [%]";}(1543509533.000915) can0 18FEE000#FFFFFFFFB05C6800 ;{;"DA": "All(255)",
                                                   ;"PGN": "VD(65248)",
                                                   ;"SA": "Engine #1(  0)",

坎杜普数据旁边的单行内容:

$ pretty_j1939.py --candata=true --format=false --link=true --transport=true example.candump.txt | head
(1543509533.000838) can0 10FDA300#FFFF07FFFFFFFFFF ;{"SA":"Engine #1(  0)","DA":"All(255)","PGN":"EEC6(64931)","Engine Variable Geometry Turbocharger Actuator #1":"2.8000000000000003 [%]"}(1543509533.000915) can0 18FEE000#FFFFFFFFB05C6800 ;{"SA":"Engine #1(  0)","DA":"All(255)","PGN":"VD(65248)","Total Vehicle Distance":"854934.0 [m]"}(1543509533.000991) can0 08FE6E0B#0000000000000000 ;{"SA":"Brakes - System Controller( 11)","DA":"All(255)","PGN":"HRW(65134)","Front Axle, Left Wheel Speed":"0.0 [kph]","Front axle, right wheel speed":"0.0 [kph]","Rear axle, left wheel speed":"0.0 [kph]","Rear axle, right wheel speed":"0.0 [kph]"}(1543509533.001070) can0 18FDB255#FFFFFFFF0100FFFF ;{"SA":"Diesel Particulate Filter Controller( 85)","DA":"All(255)","PGN":"AT1IMG(64946)","Aftertreatment 1 Diesel Particulate Filter Differential Pressure":"0.1 [kPa]"}(1543509533.001145) can0 0CF00400#207D87481400F087 ;{"SA":"Engine #1(  0)","DA":"All(255)","PGN":"EEC1(61444)","Engine Torque Mode":"2 (Unknown)","Actual Engine - Percent Torque (Fractional)":"0.0 [%]","Driver's Demand Engine - Percent Torque":"0 [%]","Actual Engine - Percent Torque":"10 [%]","Engine Speed":"649.0 [rpm]","Source Address of Controlling Device for Engine Control":"0 [SA]","Engine Demand - Percent Torque":"10 [%]"}(1543509533.001220) can0 18FF4500#6D00FA00FF00006A ;{"SA":"Engine #1(  0)","DA":"All(255)","PGN":"PropB_45(65349)","Manufacturer Defined Usage (PropB_PDU2)":"0x6d00fa00ff00006a"}(1543509533.001297) can0 18FEDF00#82FFFFFF7DE70300 ;{"SA":"Engine #1(  0)","DA":"All(255)","PGN":"EEC3(65247)","Nominal Friction - Percent Torque":"5 [%]","Estimated Engine Parasitic Losses - Percent Torque":"0 [%]","Aftertreatment 1 Exhaust Gas Mass Flow Rate":"199.8 [kg/h]","Aftertreatment 1 Intake Dew Point":"0 (00 - Not exceeded the dew point)","Aftertreatment 1 Exhaust Dew Point":"0 (00 - Not exceeded the dew point)","Aftertreatment 2 Intake Dew Point":"0 (00 - Not exceeded the dew point)","Aftertreatment 2 Exhaust Dew Point":"0 (00 - Not exceeded the dew point)"}(1543509533.001372) can0 1CFE9200#FFFFFFFFFFFFFFFF ;{"SA":"Engine #1(  0)","DA":"All(255)","PGN":"EI1(65170)"}(1543509533.001447) can0 18F00131#FFFFFF3F00FFFFFF ;{"SA":"Cab Controller - Primary( 49)","DA":"All(255)","PGN":"EBC1(61441)","Accelerator Interlock Switch":"0 (00 - Off)","Engine Retarder Selection":"0.0 [%]"}(1543509533.001528) can0 18FEF131#F7FFFF07CCFFFFFF ;{"SA":"Cab Controller - Primary( 49)","DA":"All(255)","PGN":"CCVS1(65265)","Cruise Control Pause Switch":"1 (01 - On)","Cruise Control Active":"0 (00 - Cruise control switched off)","Cruise Control Enable Switch":"0 (00 - Cruise control disabled)","Brake Switch":"1 (01 - Brake pedal depressed)","Cruise Control Coast (Decelerate) Switch":"0 (00 - Cruise control activator not in the position \"coast\")","Cruise Control Accelerate Switch":"0 (00 - Cruise control activator not in the position \"accelerate\")"}

只格式化了传输SPN的内容。

$ pretty_j1939.py --candata=false --format=true --link=false --transport=true example.candump.txt |head
{"Transport PGN": "AT1HI1(64920)",
    "Aftertreatment 1 Total Fuel Used": "227.5 [liters]",
    "Aftertreatment 1 DPF Average Time Between Active Regenerations": "173933 [Seconds]",
    "Aftertreatment 1 DPF Average Distance Between Active Regenerations": "1460.5 [m]"}{"Transport PGN": "AT1HI1(64920)",
    "Aftertreatment 1 Total Fuel Used": "227.5 [liters]",
    "Aftertreatment 1 DPF Average Time Between Active Regenerations": "173933 [Seconds]",

如何

首先,获取数字附件的副本,有关详细信息,请参见https://www.sae.org/standards/content/j1939da_201907/

然后,使用create_j1939db-json.py脚本将数字附件转换为json文件,例如

create_j1939db-json.py -f tmp/J1939DA_201611.xls -w tmp/J1939DA_201611.json

将生成的JSON文件放在工作目录中的J1939db.json,并使用漂亮的打印脚本,例如

pretty_j1939.py example.candump.txt

脚本(以及它构建的pretty_j1939/parse.py中的describer)具有不同级别的 在坎杜普日志中描述J1939流量时可用的详细信息:

usage: pretty_j1939.py [-h][--candata [CANDATA]][--pgn [PGN]][--spn [SPN]][--transport [TRANSPORT]][--link [LINK]][--include-na [INCLUDE_NA]][--format [FORMAT]]
                       candump

pretty-printing J1939 candump logs

positional arguments:
  candump               candump log

optional arguments:
  -h, --help            show this help message and exit
  --candata [CANDATA]   print input can data
  --pgn [PGN]           print source/destination/type description
  --spn [SPN]           print signals description
  --transport [TRANSPORT]
                        print details of transport-layer streams found
  --link [LINK]         print details of link-layer frames found
  --include-na [INCLUDE_NA]
                        inlude not-available (0xff) SPN values
  --format [FORMAT]     format each structure (otherwise single-line)

安装

pip3 install pretty_j1939

关于数字附件源的说明

您需要从sae获得一个j1939数字附件,才能创建一个json文件,供pretty_j1939.py使用。 https://www.sae.org/standards/content/j1939da_201907/了解详细信息。

有多个版本;在购买数字附件时,需要考虑以下几点注意事项。

  • 201611数字附件中定义的SPN比201311数字附件少;在某些情况下 DA开始将“技术”SPN(如DMS)迁移到其他文档并从DA中移出
  • 201311数字附件中有几个漏洞,而create_j1939db-json.py有解决方法
  • create_j1939db-json.py还可以通过提供多个excel表来处理从isobus.net导出的XLS 作为输入(带有多个-f参数);但是,isobus.net定义几乎省略了所有商用车 spns和pgns,因此生成的J1939db.json文件在检查来自商业的candump捕获时可能没有很大用处 车辆。

未来工作

  • 将此功能移植到python-j1939python-can项目
  • 支持不连续的SPN字段
  • 基于公共信息的默认json数据库(内容有限)
  • 支持未编码在数字附件中的J1939方面(无论何时),例如地址声明、DMS

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Jgit对于给定的存储库,我们如何确定新提交的列表,以及每个提交来自哪个分支?   从MS Access数据库添加java ComboBoxItem   如何禁止Java列表中不同类的实例?   java在没有Web的JAXR上使用Shiro过滤器。xml   由于java原因,无法在Ubuntu上安装Netbeans 8.2。awt。未找到恐怖和辅助技术   java JUnit对RuntimeException的处理(特别是)   java空集合在Apache CXF服务(JAXWS)中被转换为null   java CannotAcquireLockException问题   sql如何在数据库中对(Java)枚举建模(使用SQL92)   安卓在Java中获取友好url后面的文件名   java如何访问数组名以获取列表?   javascript Java Nashorn longBitsToDouble   java控制台<init>错误   java将一个LinkedList追加/连接到另一个LinkedList的最有效方式是什么?   Java for正在跳过的循环   java帮助创建带有动画的复杂Swing GUI   java Android编辑文本。setHint在片段中不工作