-
Notifications
You must be signed in to change notification settings - Fork 44
Decode a file with asn1c
Matt S edited this page Sep 29, 2017
·
11 revisions
Using the asn1c compiler tool, decode an UPER encoded BasicSafetyMessage file.
git clone https://github.com/vlm/asn1c.git
cd asn1c
test -f configure || autoreconf -iv
./configure
make
make check
make install
asn1c -v #verify it installed
For this example you will need J2735_201603DA.asn
and SEMI_v2.3.0_070616.asn
asn1c -gen-OER -gen-PER -fcompound-names -pdu=BasicSafetyMessage J2735_201603DA.asn SEMI_v2.3.0_070616.asn
-
-gen-OER
generates OER encoder/decoders -
-gen-PER
generates [U]PER encoder/decoders -
-fcompound-names
resolves the name conflicts presented by the J2735 schema
Copy and paste the following code into a file such as main.c
:
Note that this program was taken from the sample decoder file in Lev Walkin's user guide.
#include <stdio.h>
#include <sys/types.h>
#include "BasicSafetyMessage.h" /* Basic safety message J2735 ASN.1 type */
int main(int ac, char **av) {
char buf[1024]; /* Temporary buffer */
asn_dec_rval_t rval; /* Decoder return value */
BasicSafetyMessage_t *bsm = 0; /* Type to decode. Note this 01! */
FILE *fp; /* Input file handler */
size_t size; /* Number of bytes read */
char *filename; /* Input file name */
/* Require a single filename argument */
if(ac != 2) {
fprintf(stderr, "Usage: %s <file.ber>\n", av[0]);
exit(1);
} else {
filename = av[1];
}
/* Open input file as read-only binary */
fp = fopen(filename, "rb");
if(!fp) {
perror(filename);
exit(1);
}
/* Read up to the buffer size */
size = fread(buf, 1, sizeof(buf), fp);
fclose(fp);
if(!size) {
fprintf(stderr, "%s: Empty or broken\n", filename);
exit(1);
}
/* Decode the input buffer as basic safety message type */
rval = per_decode(0, &asn_DEF_BasicSafetyMessage, (void **)&bsm, buf, size);
if(rval.code != RC_OK) {
fprintf(stderr, "%s: Broken bsm encoding at byte %ld\n", filename,
(long)rval.consumed);
exit(1);
}
/* Print the decoded basic safety message type as XML */
xer_fprint(stdout, &asn_DEF_BasicSafetyMessage, bsm);
return 0; /* Decoding finished successfully */
}
Note: this step may not be necessary for all compilers.
Make a script to replace the C include statements' <>
with ""
:
bracketReplacer.sh
#/bin/bash
find ./asn/ \
-name '*.[ch]' \
-exec \
sed -i '/^#include[[:blank:]]/ s/<\([^>]*\)>/"\1"/g' "{}" \
\;
(This script will not work on OSX unless you have installed the gnu-sed
tool)
make -f Makefile.am.sample
./progname bsm.uper
If it works, the BSM will be decoded and printed to standard out in XML format:
<BasicSafetyMessage>
<coreData>
<msgCnt>102</msgCnt>
<id>BE A1 00 00</id>
<secMark>36799</secMark>
<lat>411641851</lat>
<long>-1048434230</long>
<elev>18969</elev>
<accuracy>
<semiMajor>255</semiMajor>
<semiMinor>255</semiMinor>
<orientation>65535</orientation>
</accuracy>
<transmission><unavailable/></transmission>
<speed>0</speed>
<heading>25681</heading>
<angle>127</angle>
<accelSet>
<long>2001</long>
<lat>2001</lat>
<vert>-127</vert>
<yaw>0</yaw>
</accelSet>
<brakes>
<wheelBrakes>
10000
</wheelBrakes>
<traction><unavailable/></traction>
<abs><unavailable/></abs>
<scs><unavailable/></scs>
<brakeBoost><unavailable/></brakeBoost>
<auxBrakes><unavailable/></auxBrakes>
</brakes>
<size>
<width>0</width>
<length>0</length>
</size>
</coreData>
<partII>
<PartIIcontent>
<partII-Id>0</partII-Id>
<partII-Value>
<VehicleSafetyExtensions>
<pathHistory>
<crumbData>
<PathHistoryPoint>
<latOffset>35</latOffset>
<lonOffset>131071</lonOffset>
<elevationOffset>95</elevationOffset>
<timeOffset>3320</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>740</latOffset>
<lonOffset>131071</lonOffset>
<elevationOffset>46</elevationOffset>
<timeOffset>4460</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>944</latOffset>
<lonOffset>51</lonOffset>
<elevationOffset>35</elevationOffset>
<timeOffset>4930</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>1826</latOffset>
<lonOffset>637</lonOffset>
<elevationOffset>2047</elevationOffset>
<timeOffset>7170</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>1313</latOffset>
<lonOffset>606</lonOffset>
<elevationOffset>2047</elevationOffset>
<timeOffset>8020</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>1535</latOffset>
<lonOffset>748</lonOffset>
<elevationOffset>2047</elevationOffset>
<timeOffset>9290</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>1650</latOffset>
<lonOffset>1171</lonOffset>
<elevationOffset>2047</elevationOffset>
<timeOffset>12640</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>1363</latOffset>
<lonOffset>1000</lonOffset>
<elevationOffset>2047</elevationOffset>
<timeOffset>13610</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>1196</latOffset>
<lonOffset>1028</lonOffset>
<elevationOffset>2047</elevationOffset>
<timeOffset>14190</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>1111</latOffset>
<lonOffset>980</lonOffset>
<elevationOffset>2047</elevationOffset>
<timeOffset>14300</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>131071</latOffset>
<lonOffset>95</lonOffset>
<elevationOffset>2047</elevationOffset>
<timeOffset>34800</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>131071</latOffset>
<lonOffset>131071</lonOffset>
<elevationOffset>126</elevationOffset>
<timeOffset>43780</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>131071</latOffset>
<lonOffset>131071</lonOffset>
<elevationOffset>115</elevationOffset>
<timeOffset>46820</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>131071</latOffset>
<lonOffset>131071</lonOffset>
<elevationOffset>100</elevationOffset>
<timeOffset>47400</timeOffset>
</PathHistoryPoint>
<PathHistoryPoint>
<latOffset>131071</latOffset>
<lonOffset>70</lonOffset>
<elevationOffset>102</elevationOffset>
<timeOffset>48130</timeOffset>
</PathHistoryPoint>
</crumbData>
</pathHistory>
<pathPrediction>
<radiusOfCurve>32767</radiusOfCurve>
<confidence>0</confidence>
</pathPrediction>
</VehicleSafetyExtensions>
</partII-Value>
</PartIIcontent>
</partII>
</BasicSafetyMessage>
- Decode a file with asn1c
- Deposit BSM to S3
- Docker fix for SSL issues due to corporate network
- Docker management
- ECDSA Primer
- Filter BSMs through PPM module
- Geofence Filtering for PPM
- Import BSMs from RSU log file
- Import TIMs from RSU log file
- jpo security svcs Integration
- Link host directory to Docker directory
- Migrating from SDW websocket depositor to SDW Depositor Submodule
- ODE Release Deployment
- ODE Release Preparation
- Prepare a fresh Ubuntu instance for ODE installation
- Process for Handling Bugs (Code Defects)
- Run the ODE using the ASN codec module
- Query RSU for set TIMs
- Schema Version 6 Change Notice
- Signed Message File Import
- TIM REST Endpoint Changes
- Using the .env configuration file
- Using the ODE test harness
- Delete TIM on RSU test
- Event Logger Test
- Import Decode and Deliver BSM Test
- Manage SNMP Test
- Sending PDM to RSU Test
- Sending TIM to RSU Test
- Submit_TIM_To_SDW Test
- Log File Changes (schemaVersion=4)
- Receive BSMs over UDP
- Receive ISD via UDP and deposit to SDC
- Receive VSD via UDP and deposit to SDC
- Run the crypto test vectors code with ODE team's OSS encoder
- SchemaVersion 5 Change Notice