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
449edbc8
Commit
449edbc8
authored
Jan 07, 2022
by
Jean-Marie Favreau
Browse files
First working evrsion
parent
2ac7fefc
Changes
1
Hide whitespace changes
Inline
Side-by-side
dat2csv.py
0 → 100755
View file @
449edbc8
#!/usr/bin/env python3
# coding: utf-8
import
argparse
from
construct
import
*
import
sys
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)'
)
args
=
parser
.
parse_args
()
def
binToHexUKK
(
val
):
big
=
int
(
val
/
16
)
little
=
val
%
16
return
big
*
10
+
little
input_file
=
args
.
input
.
strip
()
output_file
=
args
.
output
.
strip
()
print
(
"Input:"
,
input_file
)
print
(
"Output:"
,
output_file
)
encoding
=
Int16sl
d_1sec
=
Struct
(
"aaaa"
/
Int16ub
,
"day"
/
Int8ub
,
"month"
/
Int8ub
,
"year"
/
Int8ub
,
"hour"
/
Int8ub
,
"minutes"
/
Int8ub
,
"seconds"
/
Int8ub
,
"entries"
/
Array
(
84
,
Array
(
3
,
encoding
)))
original_stdout
=
sys
.
stdout
with
open
(
input_file
,
'rb'
)
as
f_input
:
with
open
(
output_file
,
'w'
)
as
f_output
:
print
(
"timestamp;X_ax;Y_ax;Z_ax"
,
file
=
f_output
)
while
f_input
:
try
:
result
=
d_1sec
.
parse_stream
(
f_input
)
year
=
2000
+
binToHexUKK
(
result
.
year
)
month
=
binToHexUKK
(
result
.
month
)
day
=
binToHexUKK
(
result
.
day
)
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
:
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
)
else
:
print
(
"skip wrong entry"
)
except
:
print
(
"Skip end of file"
)
break
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