以下日志来自windows终端仿真器TeraTerm。我想通过以下方式从Linux中的ttyUSB0获取日志。
[Thu Apr 14 15:08:14.410 2016] Load U-Boot from eMMC/NAND Flash
[Thu Apr 14 15:08:14.410 2016] eMMC/NAND copy from 0x030A0000 to 0x49FB0000 (len:262144).
[Thu Apr 14 15:08:14.456 2016] Done.
[Thu Apr 14 15:08:14.456 2016]
[Thu Apr 14 15:08:14.456 2016]
[Thu Apr 14 15:08:14.456 2016] U-Boot 1.2.0 (Sep 2 2013 - 13:31:42)Puma6 - PSPU-Boot 2.0.0.24
[Thu Apr 14 15:08:14.503 2016]
[Thu Apr 14 15:08:14.503 2016] DRAM: 128 MB
[Thu Apr 14 15:08:14.503 2016] *** Warning - Unsupported Flash detected, flash is unusable
[Thu Apr 14 15:08:14.503 2016]
我找到了this document,但当终端空闲时,它会给出时间戳。
-- 0:ttyUSB2 -- time-stamp -- 2016-04-15 17:23:13 --
-- 0:ttyUSB2 -- time-stamp -- 2016-04-15 17:23:53 --
发布于 2019-09-26 19:09:11
您可以使用awk来做到这一点。我有数据通过串口传过来。最初的输出(使用/dev/ttyUSB0)如下所示。
Sending struct (10 bytes) ...
A: -0.06.
Sending struct (10 bytes) ...
A: -0.05.
Sending struct (10 bytes) ...
A: -0.06.
Sending struct (10 bytes) ...
A: -0.05.
在使用下面的命令之后,我得到了timestaps。
awk '{ print strftime("[%a %b %d %H:%M:%S.%f %y]"), $0; }' /dev/ttyUSB0 > /home/captain/ttyUSB0_v11.txt &
输出如下所示。
[Thu Sep 26 12:01:03.%f 19]
[Thu Sep 26 12:01:03.%f 19] Transmitting at 868 Mhz...
[Thu Sep 26 12:01:03.%f 19]
[Thu Sep 26 12:01:03.%f 19] SPI Flash Init OK ... UniqueID (MAC): A: -0.06.
[Thu Sep 26 12:01:03.%f 19]
[Thu Sep 26 12:01:03.%f 19] Sending struct (10 bytes) ...
[Thu Sep 26 12:01:03.%f 19]
[Thu Sep 26 12:01:04.%f 19] A: -0.05.
[Thu Sep 26 12:01:04.%f 19]
[Thu Sep 26 12:01:04.%f 19] Sending struct (10 bytes) ...
[Thu Sep 26 12:01:04.%f 19]
[Thu Sep 26 12:01:05.%f 19] A: -0.06.
[Thu Sep 26 12:01:05.%f 19]
[Thu Sep 26 12:01:06.%f 19] Sending struct (10 bytes) ...
[Thu Sep 26 12:01:06.%f 19]
[Thu Sep 26 12:01:07.%f 19] A: -0.06.
[Thu Sep 26 12:01:07.%f 19]
[Thu Sep 26 12:01:07.%f 19] Sending struct (10 bytes) ...
[Thu Sep 26 12:01:07.%f 19]
[Thu Sep 26 12:01:08.%f 19] A: -0.06.
[Thu Sep 26 12:01:08.%f 19]
[Thu Sep 26 12:01:08.%f 19] Sending struct (10 bytes) ...
[Thu Sep 26 12:01:08.%f 19]
[Thu Sep 26 12:01:09.%f 19] A: -0.05.
由于某种奇怪的原因,毫秒(%f)不起作用。但如果它非常重要,你应该能够弄清楚。
干杯
OS- Ubuntu14.04
串行设备- Moteino (Arduino)
https://stackoverflow.com/questions/36737144
复制相似问题