Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
esanté-mobilité
RM42 log parser
Commits
ea92ae66
Commit
ea92ae66
authored
Jan 09, 2022
by
Jean-Marie Favreau
Browse files
Mise en forme et option nombre
parent
5542941f
Changes
1
Hide whitespace changes
Inline
Side-by-side
dat2csv.py
View file @
ea92ae66
...
...
@@ -5,11 +5,13 @@
import
argparse
from
construct
import
*
import
sys
from
datetime
import
datetime
parser
=
argparse
.
ArgumentParser
(
description
=
"Convert RM42 (UKK) binary log files to CSV format."
)
parser
.
add_argument
(
'input'
,
metavar
=
"INPUT"
,
type
=
str
,
help
=
'Input file (.dat format)'
)
parser
.
add_argument
(
'output'
,
metavar
=
"OUTPUT"
,
type
=
str
,
help
=
'Output file (.csv format)'
)
parser
.
add_argument
(
'-n'
,
help
=
"Store timestamp with a number"
,
action
=
'store_true'
)
args
=
parser
.
parse_args
()
...
...
@@ -25,6 +27,8 @@ print("Input:", input_file)
print
(
"Output:"
,
output_file
)
number
=
args
.
n
encoding
=
Int16sl
...
...
@@ -51,11 +55,15 @@ with open(input_file, 'rb') as f_input:
hour
=
binToHexUKK
(
result
.
hour
)
minutes
=
binToHexUKK
(
result
.
minutes
)
seconds
=
binToHexUKK
(
result
.
seconds
)
if
year
!=
2000
or
month
!=
0
or
day
!=
0
or
hour
!=
0
or
minutes
!=
0
or
seconds
!=
0
:
if
(
year
!=
2000
or
month
!=
0
or
day
!=
0
or
hour
!=
0
or
minutes
!=
0
or
seconds
!=
0
)
and
month
<=
12
and
month
>=
1
:
for
entry
in
result
.
entries
:
entry_csv
=
';'
.
join
([
str
(
e
)
for
e
in
entry
])
print
(
'{:02d}/{:02d}/{:04d} {:02d}:{:02d}:{:02d};{:s}'
.
format
(
day
,
month
,
year
,
hour
,
minutes
,
seconds
,
entry_csv
),
file
=
f_output
)
if
number
:
nb
=
datetime
(
year
,
month
,
day
,
hour
,
minutes
,
seconds
,
0
).
timestamp
()
print
(
'{:f};{:s}'
.
format
(
nb
,
entry_csv
),
file
=
f_output
)
else
:
print
(
'{:02d}/{:02d}/{:04d} {:02d}:{:02d}:{:02d};{:s}'
.
format
(
day
,
month
,
year
,
hour
,
minutes
,
seconds
,
entry_csv
),
file
=
f_output
)
else
:
print
(
"skip wrong entry"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment