Skip to content

Commit

Permalink
Merge pull request #28 from miqelm/no_delta_sys_time_format
Browse files Browse the repository at this point in the history
Added nodelta option, added possibility to specify system time format
  • Loading branch information
tbird20d authored Feb 15, 2019
2 parents 7c4ea61 + e099178 commit d50b295
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions grabserial
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ options:
-T, --systime Print system time for each line received. The time
is the absolute local time when the first character
of each line is received by %s
-F, --timeformat=<val> Specifies system time format for each received line
e.g.
-F \"%%Y-%%m-%%d %%H:%%M%%S.%%f\"
(default \"%%H:%%M:%%S.%%f\")
-m, --match=<pat> Specify a regular expression pattern to match to
set a base time. Time values for lines after the
line matching the pattern will be relative to
Expand All @@ -138,6 +142,7 @@ options:
-V, --version Show version number and exit
-S, --skip Skip sanity checking of the serial device.
May be needed for some devices.
-n, --nodelta Skip printing delta between read lines.
--crtonewline Promote a carriage return to be treated as a
newline
Expand Down Expand Up @@ -208,7 +213,7 @@ def grab(arglist, outputfd=sys.stdout):
try:
opts, args = getopt.getopt(
arglist,
"hli:d:b:B:w:p:s:xrfc:taTm:e:o:QvVq:S", [
"hli:d:b:B:w:p:s:xrfc:taTF:m:e:o:QvVq:nS", [
"help",
"launchtime",
"instantpat=",
Expand All @@ -224,13 +229,15 @@ def grab(arglist, outputfd=sys.stdout):
"time",
"again",
"systime",
"timeformat=",
"match=",
"endtime=",
"output=",
"quiet",
"verbose",
"version",
"quitpat=",
"nodelta",
"skip",
"crtonewline",
])
Expand Down Expand Up @@ -266,6 +273,8 @@ def grab(arglist, outputfd=sys.stdout):
cr_to_nl = 0
restart = False
quiet = False
systime_format = "%H:%M:%S.%f"
use_delta = True

for opt, arg in opts:
if opt in ["-h", "--help"]:
Expand Down Expand Up @@ -331,6 +340,8 @@ def grab(arglist, outputfd=sys.stdout):
if opt in ["-T", "--systime"]:
show_time = 0
show_systime = 1
if opt in ["-F", "--timeformat"]:
systime_format = arg
if opt in ["-m", "--match"]:
basepat = arg
if opt in ["-i", "--instantpat"]:
Expand Down Expand Up @@ -362,8 +373,10 @@ def grab(arglist, outputfd=sys.stdout):
print("grabserial version %d.%d.%d" % VERSION)
sd.close()
sys.exit(0)
if opt in ["-S"]:
if opt in ["-S", "--skip"]:
skip_device_check = 1
if opt in ["-n", "--nodelta"]:
use_delta = False
if opt in ["--crtonewline"]:
cr_to_nl = 1

Expand Down Expand Up @@ -497,10 +510,13 @@ def grab(arglist, outputfd=sys.stdout):

if show_systime and newline:
linetime = time.time()
linetimestr = datetime.datetime.now().strftime("%H:%M:%S.%f")
linetimestr = datetime.datetime.now().strftime(systime_format)
elapsed = linetime-basetime
delta = elapsed-prev1
msg = "[%s %2.6f] " % (linetimestr, delta)
if use_delta:
delta = elapsed-prev1
msg = "[%s %2.6f] " % (linetimestr, delta)
else:
msg = "[%s] " % (linetimestr)
if not quiet:
outputfd.write(msg)
if out:
Expand Down

0 comments on commit d50b295

Please sign in to comment.