分类 V2X 下的文章

“车联网(Vehicle-to-everything):汽车和其他相关设备的通讯。车联网(Vehicle-to-everything)简称V2X,是将汽车和其他车辆或是可能影响汽车的设备所进行的通信。车联网是包括其他种类通信的汽车通信系统,其他的通信有V2I(汽车对基础设施、汽车对道路系统)、V2N(汽车对网络)、V2V(汽车对汽车)、V2P(汽车对行人)、V2D(汽车对设备)。”

journalctl usage..
journalctl 用法
journalctl 查看所有日志,基本上就是狂刷

journalctl --no-pager 等于 cat syslog.txt的效果。

journalctl -k

 查看内核日志(不显示应用日志)

加上--no-pager参数就直接输出到标准输出了。

journalctl -k --no-pager 

Jul 29 17:38:47 systemd[1]: systemd-journald.service: Unit entered failed state.
Jul 29 17:38:47 systemd[1]: systemd-journald.service: Failed with result 'signal'.
Jul 29 17:38:47 systemd[1]: systemd-journald.service: Service has no hold-off time, scheduling restart.
Jul 29 17:38:47 systemd[1]: Stopped Flush Journal to Persistent Storage.
Jul 29 17:38:47 systemd[1]: Stopping Flush Journal to Persistent Storage...
Jul 29 17:38:47 systemd[1]: Stopped Journal Service.
Jul 29 17:38:47 systemd[1]: Starting Journal Service...
Jul 29 17:38:47 systemd[1]: Started Journal Service.

查看系统本次启动的日志,基本上就是刷屏了。

journalctl -b
journalctl -b --no-pager 

查看指定程序的日志

journalctl /usr/sbin/sshd --no-pager

Jul 30 10:00:24 sshd[14609]: error: AuthorizedKeysCommand path is not absolute
Jul 30 10:00:24 sshd[14609]: Authentication refused: bad ownership or modes for directory /home/root
Jul 30 10:00:24 sshd[14609]: error: AuthorizedKeysCommand path is not absolute
Jul 30 10:00:24 sshd[14609]: Authentication refused: bad ownership or modes for directory /home/root
Jul 30 10:00:26 sshd[14609]: Accepted password for root from 192.168.5.64 port 52218 ssh2
Jul 30 10:00:26 sshd[14614]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Jul 30 10:00:26 sshd[14614]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Jul 30 10:56:45 sshd[16413]: error: AuthorizedKeysCommand path is not absolute
Jul 30 10:56:45 sshd[16413]: Authentication refused: bad ownership or modes for directory /home/root
Jul 30 10:56:45 sshd[16413]: error: AuthorizedKeysCommand path is not absolute
Jul 30 10:56:45 sshd[16413]: Authentication refused: bad ownership or modes for directory /home/root
Jul 30 10:56:47 sshd[16413]: Accepted password for root from 192.168.5.64 port 55484 ssh2
Jul 30 10:56:47 sshd[16418]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Jul 30 10:56:47 sshd[16418]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Jul 30 11:01:29 sshd[16585]: error: AuthorizedKeysCommand path is not absolute
Jul 30 11:01:29 sshd[16585]: error: AuthorizedKeysCommand path is not absolute
Jul 30 11:01:29 sshd[16585]: Accepted publickey for root from 192.168.5.64 port 55624 ssh2: RSA SHA256:Qji+sVx09n43QcM300pHJiiPWi4KzqulAMkLAaf1vXM
Jul 30 11:01:29 sshd[16587]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Jul 30 11:01:29 sshd[16587]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Jul 30 11:22:15 sshd[17223]: Accepted password for root from 192.168.5.44 port 64448 ssh2
Jul 30 11:22:15 sshd[17228]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Jul 30 11:22:15 sshd[17228]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Jul 30 11:33:52 sshd[17582]: Accepted password for root from 192.168.5.44 port 65228 ssh2
Jul 30 11:36:11 sshd[17696]: Accepted password for root from 192.168.5.44 port 65341 ssh2

journalctl /usr/bin/cv2x-daemon --no-pager

基本上就够用了。

按可执行文件的路径过滤
如果在参数中指定某个可执行文件(二进制文件或脚本文件),则 journalctl 会显示与该可执行文件相关的全部条目。比如可以显示 /usr/lib/systemd/systemd 程序产生的日志:

$ sudo journalctl /usr/lib/systemd/systemd

也可以显示 /usr/bin/bash 程序产生的日志:

$ sudo journalctl /usr/bin/bash

用json输出略吊。。

journalctl /usr/sbin/sshd --no-pager -o json

{ "__CURSOR" : "s=1f967cdb38644934b6add6dca6147120;i=ab550;b=81a1ae5398824daea9b502bf3ddfc092;m=2488403b14;t=5c84eebbadaf5;x=3e575c4f570ffd13", "__REALTIME_TIMESTAMP" : "1627616171449077", "__MONOTONIC_TIMESTAMP" : "156904733460", "_BOOT_ID" : "81a1ae5398824daea9b502bf3ddfc092", "_TRANSPORT" : "syslog", "_UID" : "0", "_GID" : "0", "_CAP_EFFECTIVE" : "3fffffffff", "_MACHINE_ID" : "df9d1eef11ee45fd92b407191b390e56", "_HOSTNAME" : "imx6qsabresd", "PRIORITY" : "6", "SYSLOG_FACILITY" : "4", "SYSLOG_IDENTIFIER" : "sshd", "_COMM" : "sshd", "_EXE" : "/usr/sbin/sshd", "_CMDLINE" : "sshd: root [priv]", "_SYSTEMD_SLICE" : "system-sshd.slice", "SYSLOG_PID" : "17696", "MESSAGE" : "Accepted password for root from 192.168.5.44 port 65341 ssh2", "_PID" : "17696", "_SYSTEMD_CGROUP" : "/system.slice/system-sshd.slice/sshd@57-192.168.5.242:22-192.168.5.44:65341.service", "_SYSTEMD_UNIT" : "sshd@57-192.168.5.242:22-192.168.5.44:65341.service", "_SOURCE_REALTIME_TIMESTAMP" : "1627616171448199" }

journalctl /usr/sbin/sshd --no-pager -o json-pretty

{

"__CURSOR" : "s=1f967cdb38644934b6add6dca6147120;i=ab550;b=81a1ae5398824daea9b502bf3ddfc092;m=2488403b14;t=5c84eebbadaf5;x=3e575c4f570ffd13",
"__REALTIME_TIMESTAMP" : "1627616171449077",
"__MONOTONIC_TIMESTAMP" : "156904733460",
"_BOOT_ID" : "81a1ae5398824daea9b502bf3ddfc092",
"_TRANSPORT" : "syslog",
"_UID" : "0",
"_GID" : "0",
"_CAP_EFFECTIVE" : "3fffffffff",
"_MACHINE_ID" : "df9d1eef11ee45fd92b407191b390e56",
"_HOSTNAME" : "imx6qsabresd",
"PRIORITY" : "6",
"SYSLOG_FACILITY" : "4",
"SYSLOG_IDENTIFIER" : "sshd",
"_COMM" : "sshd",
"_EXE" : "/usr/sbin/sshd",
"_CMDLINE" : "sshd: root [priv]",
"_SYSTEMD_SLICE" : "system-sshd.slice",
"SYSLOG_PID" : "17696",
"MESSAGE" : "Accepted password for root from 192.168.5.44 port 65341 ssh2",
"_PID" : "17696",
"_SYSTEMD_CGROUP" : "/system.slice/system-sshd.slice/sshd@57-192.168.5.242:22-192.168.5.44:65341.service",
"_SYSTEMD_UNIT" : "sshd@57-192.168.5.242:22-192.168.5.44:65341.service",
"_SOURCE_REALTIME_TIMESTAMP" : "1627616171448199"

}

查看了一下帮助文件,支持的格式还不少。

 -o --output=STRING       Change journal output mode (short, short-iso,
                                    short-precise, short-monotonic, verbose,
                                    export, json, json-pretty, json-sse, cat)
                               

不知道json-sse是什么东西,试试。

journalctl /usr/sbin/sshd --no-pager -o json-sse

data: { "__CURSOR" : "s=1f967cdb38644934b6add6dca6147120;i=ab550;b=81a1ae5398824daea9b502bf3ddfc092;m=2488403b14;t=5c84eebbadaf5;x=3e575c4f570ffd13", "__REALTIME_TIMESTAMP" : "1627616171449077", "__MONOTONIC_TIMESTAMP" : "156904733460", "_BOOT_ID" : "81a1ae5398824daea9b502bf3ddfc092", "_TRANSPORT" : "syslog", "_UID" : "0", "_GID" : "0", "_CAP_EFFECTIVE" : "3fffffffff", "_MACHINE_ID" : "df9d1eef11ee45fd92b407191b390e56", "_HOSTNAME" : "imx6qsabresd", "PRIORITY" : "6", "SYSLOG_FACILITY" : "4", "SYSLOG_IDENTIFIER" : "sshd", "_COMM" : "sshd", "_EXE" : "/usr/sbin/sshd", "_CMDLINE" : "sshd: root [priv]", "_SYSTEMD_SLICE" : "system-sshd.slice", "SYSLOG_PID" : "17696", "MESSAGE" : "Accepted password for root from 192.168.5.44 port 65341 ssh2", "_PID" : "17696", "_SYSTEMD_CGROUP" : "/system.slice/system-sshd.slice/sshd@57-192.168.5.242:22-192.168.5.44:65341.service", "_SYSTEMD_UNIT" : "sshd@57-192.168.5.242:22-192.168.5.44:65341.service", "_SOURCE_REALTIME_TIMESTAMP" : "1627616171448199"}

编译结果

./protoc --version

libprotoc 3.17.3

git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
mkdir x64
cd x64
../configure --prefix=$(pwd)/install
make
make install

运行编译好的程序

./install/bin/protoc --version

libprotoc 3.17.3
查看所有库文件

tree install/lib/

install/lib/
├── libprotobuf.a
├── libprotobuf.la
├── libprotobuf-lite.a
├── libprotobuf-lite.la
├── libprotobuf-lite.so -> libprotobuf-lite.so.28.0.3
├── libprotobuf-lite.so.28 -> libprotobuf-lite.so.28.0.3
├── libprotobuf-lite.so.28.0.3
├── libprotobuf.so -> libprotobuf.so.28.0.3
├── libprotobuf.so.28 -> libprotobuf.so.28.0.3
├── libprotobuf.so.28.0.3
├── libprotoc.a
├── libprotoc.la
├── libprotoc.so -> libprotoc.so.28.0.3
├── libprotoc.so.28 -> libprotoc.so.28.0.3
├── libprotoc.so.28.0.3
└── pkgconfig

├── protobuf-lite.pc
└── protobuf.pc

编译arm版本protobuf库

cd ../
mkdir arm
cd arm/
CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ ../configure --prefix=$(pwd)/install --host=arm-linux
make -j8
make install
file ./install/bin/protoc 

./install/bin/protoc: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=cea786b94a0b64b866983c8b4541df34e9cc7c1d, with debug_info, not stripped

protobuf/arm$ tree ./install/lib/

./install/lib/
├── libprotobuf.a
├── libprotobuf.la
├── libprotobuf-lite.a
├── libprotobuf-lite.la
├── libprotobuf-lite.so -> libprotobuf-lite.so.28.0.3
├── libprotobuf-lite.so.28 -> libprotobuf-lite.so.28.0.3
├── libprotobuf-lite.so.28.0.3
├── libprotobuf.so -> libprotobuf.so.28.0.3
├── libprotobuf.so.28 -> libprotobuf.so.28.0.3
├── libprotobuf.so.28.0.3
├── libprotoc.a
├── libprotoc.la
├── libprotoc.so -> libprotoc.so.28.0.3
├── libprotoc.so.28 -> libprotoc.so.28.0.3
├── libprotoc.so.28.0.3
└── pkgconfig

├── protobuf-lite.pc
└── protobuf.pc

使用git 直接git clone github的库,不会报googletest 相关的警告,自动下载好了。如果自己在github.com protobuf release哪儿下载的放在,编译时候会报一个没有googletest的警告。好烦。。

configure: WARNING: no configuration information is in third_party/googletest

wget下载:

wget http://lionet.info/soft/asn1c-0.9.28.tar.gz

下载其他版本,可以直接进入http://lionet.info/soft/ 查看
asn1c.png
解压:tar xvf asn1c-0.9.28.tar.gz

进入源码目录:cd asn1c-0.9.28
配置:./configure
编译:make
安装:make install

asn1c工具安装好了,可以通过运行 asn1c -h 查看用法

生成c代码
ls *.asn
BSM.asn DefPosition.asn Map.asn PAM.asn RSC.asn RTCM.asn TestMsg.asn VehEmgExt.asn VehStatus.asn
DefAcceleration.asn DefPositionOffset.asn MsgDayII.asn Platooning.asn RSI.asn SensorSharing.asn VehBrake.asn VehSafetyExt.asn VIR.asn
DefMotion.asn DefTime.asn MsgFrame.asn PSM.asn RSM.asn SignalPhaseAndTiming.asn VehClass.asn VehSize.asn VPM.asn

asn1c -S /usr/local/share/asn1c -fcompound-names -fskeletons-copy -gen-PER -gen-OER -pdu=auto *.asn

asn1c -h

-fcompound-names Disambiguate C's struct NAME's inside top-level types
-S <dir> Directory with support (skeleton?) files

                    (Default is "/usr/local/share/asn1c")

-pdu={all|auto|Type} Generate PDU table (discover PDUs automatically)

注意: 如果不加-f compound-names,后续c代码编译时,会报很多枚举重定义错误。-fskeleton-copy是会从
-S指定的目录中,拷贝asn基础类型解码文件,为了不存在依赖必须加上。 不加-pdu=auto的话,不会产生pdu_colletion.c文件,这个文件中定义了所有的消息PDU。

make -f converter-example.mk 

cc -DASN_PDU_COLLECTION -I. -o converter-example.o -c converter-example.c
cc -DASN_PDU_COLLECTION -I. -o pdu_collection.o -c pdu_collection.c
cc -DASN_PDU_COLLECTION -I. -o converter-example converter-example.o pdu_collection.o libasncodec.a -lm

./converter-example -p list

Available PDU types:
MessageFrame

命令行编解码

./converter-example -p MessageFrame -ixer MessageFrame.xml 

<MessageFrame>
    <msgFrameExt>
        <messageId>13</messageId>
        <value>
            <VehIntentionAndRequest>
                <msgCnt>0</msgCnt>
                <id>00 00 00 00 00 06 D6 13</id>
                <secMark>110</secMark>
                <refPos>
                    <lat>416955100</lat>
                    <long>1234521700</long>
                    <elevation>5454</elevation>
                </refPos>
                <intAndReq>
                </intAndReq>
            </VehIntentionAndRequest>
        </value>
    </msgFrameExt>
</MessageFrame>

ACME 可能是这个的缩写(Autonomous and Connected Mobility Evaluation)
This is default tool that comes with the LTE-V2X Development Platform
(OBU/RSU) to interface with LTE-V2X RSU/OBU. It enables sending and receiving of raw
application layer byte arrays.

常规用法

发:

acme -G 127.0.0.1

收:

acme -G 127.0.0.1 -R

其他:
//Receives and displays all received packets.

acme -RV

//same as above but dumps the hex content.

acme -RVd    

//Will setup 2 SPS flows ala J2945/1

acme -VV -o1 -r300 -M500 -a -r200 -I100 -M100 -o1 

//Sends GNSS data and tunnel mode info as trusted, time confidence level 3, position confidence level 5

acme -gT t:3:5  

//Setup SPS flow with pool id 1

acme -VV -o1 -r300 -M500 -j1 

帮助

acme -h

Usage: acme [-i <interface>] ... 
  A generic test tool used as either a packet sender(default), reciver(-R) or echo (-e)
  can also optionally be used as a UDP -> PC5 proxy or vice-versa

  Defaults: interface=rmnet_data1, no dump, SPS TX, v2x_id=1, sps_port=2500 event_port=2600 UEID=1 dest_ip=ff02::1:9000
-A              ASCII dump packet data after sequence#
-a              Additional SPS/Event Flow Pair. Subsequent -E,-I,-r -o flow params will apply to new reservation
-b<interval sec>  Reporting interval for receive stats, set to 0 to disable, use default interval if not specified
-C              Config File Path to set IP Address and Interface
-d              dump raw packet
-D <dest ip6>   Destination IPV6 address[ Default=ff02::1]
-p <dest port>  port number that the destination traffic is sent to.[Default=9000]
-e              Echo Mode. Re-TX each received message (via event port)
-E              Event flow mode instead of SPS
-F              Use event port of SPS flow registration
-g              Include GNSS data, velocity, and heading in packets if possible
-G <IP addr>    IP address of the kinematics server
-s <sps_port>   SPS port#.  Overrides the default of 2500. +1 for each added flow
-t <evt_port>   Event driven port# .  Overrides the default of 2600 +1 for each added flow.
-i <if_name>    Interface name as found in listing by ifconfig
-I <milliseconds> interval for generating packets & any initial SPS reservation flow
-u <microseconds> Alternative to -I, microseconds for finer control.
-N <nanoseconds>  Alternative to -I, nanosecond interval.
-j <tx_pool_id> TX Pool ID
-J <latitude,longitude,altitude> Override GNSS data with given values.
-k <qty>        Quit after <qty> packets received or transmitted
-l <bytes [bytes] ... >   List of Payload Lengths in bytes, at least one length required
                          specify multiple payloads. TX  will send one packet of each lengths in sequence.
                           maximum number of length sequence 1000 different lengths.
-M <millsec>    Specify reservation in milliseconds, multiple allowed when used with -a for multi-flow.
-m <filename>   Log file, Machine readable of each Tx/Rx packet.
-o <priority>   Traffic ID (typically between 0-2)
-P <V2X ID>     V2X session ID to be used
-q              Quiet
-r <res size>   Reservation size for SPS flow in bytes
-R              RECEIVE mode, default is TX
-S <seq#>       optional sequence number to start on.
-T <UE info>    Enable TX tunnel mode. 
                Format <t|m>/(Optional)<alt_time_s>:<time_conf>:<pos_conf>
                Send L2 ID, time confidence, and position confidence in packets.
                If <time_conf> == 0, acme will use time confidence reported from modem.
                If <pos_conf> == 0, acme will compute position confidence from GNSS fix.
                Acme will switch from t/m and vice versa every <alt_time_s> seconds
-w <RV timeout ms>,<Update period ms>
                Enable RX tunnel mode.
                Send trusted / malicious ID updates with data received from RVs.
                RV is removed from update list <RV timeout>(ms) after last RX.
                Trusted UE info update msg sent every <Update period>(ms)
-U <UEID>       1 Byte UE Identifier, prepended on TX payload, default=1, give each Tx a unique ID
-W <peak_tx_power>,<mcs_index>,<retx_setting>,<tx_pool_id>
                Peak TX pwr in dbm
                Retransmit policy: 0 = disabled, 1 = enabled, and 2 = don't care
-V              Increase verbosity level +1 for each -V, default=0
-Z              Use syslog instead of stdout for SDK debug/info/errors

直接上代码了

#pragma pack(1)
struct _st_v2x_testingdata
{
    int len;
    uint8_t cmd;
    uint8_t data_type;
    char ID[8];
    uint64_t sign_verify_time;
    uint8_t sign_verify_result;
    uint64_t send_receive_time;
    int32_t AID;
    int32_t CBR;
    int32_t msgCnt;
    uint64_t secMark;
    uint32_t speed;
    uint32_t longitude;
    uint32_t latitude;
    int32_t heading;
    char dsmp_payload[0];
};
#pragma pack()