实验说明
目的
通过已有的V2X通讯中的ASN.1文件,借助ossasn1工具,生成C语言的编解码代码。
思路
- 购买/试用ossasn1工具;
- 下载ASN.1文件,这里以V2X标准文件为例;
- 使用ossasn1工具生成对应的编解码工具;
- 编写测试用例,进行基本的encode、decode演示;
实验过程
试用ossasn1工具
提交完成后,会收到一封邮件。邮件标题类似OSS Nokalva Trial Software: Links for Product, License Key, and Documentation,其中包括了软件下载链接、license以及安装方法,其实就是对
ossasn1_linux64_trial_v11_ossinfoctrial_88175Z.zip
和ossasn1_linux64_trial_v11.zip
这连个文件解压;按照方法解压软件和license;解压完成,目录大致如下:
#ossasn1软件目录 caeri@caeri ~/lzp/ossasn1/download/ossasn1 . └── linux-x86-64.trial └── 11.3.1 ├── asn1dflt.linux-amd64 ├── bin ├── doc ├── include ├── lib └── samples #ossasn1 license位置 caeri@caeri ~/lzp/ossasn1/download % ls asn1studio ossasn1 ossasn1_linux64_trial_v11_ossinfoctrial_88175Z.zip ossasn1_linux64_trial_v11.zip ossinfoctrial Trial_Agreement_7000359.4.txt
下载ASN.1文件
- 在这里,可以下载到V2X的ASN.1文件;
使用ossasn1工具生成对应的编解码工具
首先,需要export环境变量,加载license;
cd /home/caeri/lzp/ossasn1/download/ossasn1/linux-x86-64.trial/11.3.1/bin export OSSINFOTRIAL=/home/caeri/lzp/ossasn1/download/
新建测试文件夹
day2
,并上传ASN.1文件;caeri@caeri ~/lzp/ossasn1/download/ossasn1/linux-x86-64.trial/11.3.1/bin/day2 % ls ltev-csae-157-2020-defs.asn
执行如下指令,编译。这里为了防止生成的字符与系统冲突,添加了前缀
-prefix asn_
;../asn1 -c ../../asn1dflt.linux-amd64 -json -uper -der -xer -toed -prefix asn_ ltev-csae-157-2020-defs.asn
编译完成后,效果如下:
caeri@caeri ~/lzp/ossasn1/download/ossasn1/linux-x86-64.trial/11.3.1/bin/day2 % ../asn1 -c ../../asn1dflt.linux-amd64 -json -uper -der -xer -toed -prefix asn_ ltev-csae-157-2020-defs.asn OSS ASN.1 Compiler Version 11.3.1 Copyright (C) 2024 OSS Nokalva, Inc. All rights reserved. This product is licensed for use by "lzp (Trial)", License "88175Z". C0043I: 0 error messages, 0 warning messages and 0 informatory messages issued. caeri@caeri ~/lzp/ossasn1/download/ossasn1/linux-x86-64.trial/11.3.1/bin/day2 % ls ltev-csae-157-2020-defs.asn ltev-csae-157-2020-defs.c ltev-csae-157-2020-defs.h
编写测试用例,进行基本的encode、decode演示;
接下来,我们创建工程,用来演示基本的编解码操作。
下载demo代码
git clone https://github.com/mdxz2048/ossasn_basic_demo.git
通过make编译一下,
caeri@caeri ...11.3.1/bin/v2x % make gcc -Wall -I. -L. -g -I/home/caeri/lzp/ossasn1/download/ossasn1/linux-x86-64.trial/11.3.1/include -c -DOSSPRINT -o demo.o demo.c gcc -static -Wl,--no-as-needed -o demo demo.o ltev-csae-157-2020-defs.o /home/caeri/lzp/ossasn1/download/ossasn1/linux-x86-64.trial/11.3.1/lib/libasn1code.a -lm -ldl
执行demo,会看到编码的RTCM数据和解码的数据
caeri@caeri ...11.3.1/bin/v2x % ./demo Encoded RTCM Corrections (UPER): 3023800101A11E300D800101810203E9820401020304300D800101810203EA820405060708 value RTCMcorrections ::= { msgCnt 1, corrections { { rev reserved, rtcmID 1001, payload '01020304'H }, { rev reserved, rtcmID 1002, payload '05060708'H } } } Decoded ASN.1 Data: value RTCMcorrections ::= { msgCnt 1, corrections { { rev reserved, rtcmID 1001, payload '01020304'H }, { rev reserved, rtcmID 1002, payload '05060708'H } } }
至此,完成了整个ossasn1试用的演示。