Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CCS
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Mecina
CCS
Commits
d81fcd34
Commit
d81fcd34
authored
1 year ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
add script for modifying packet timestamps
parent
e9393d83
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Ccs/scripts/mod_pkt_times.py
+71
-0
71 additions, 0 deletions
Ccs/scripts/mod_pkt_times.py
with
71 additions
and
0 deletions
Ccs/scripts/mod_pkt_times.py
0 → 100644
+
71
−
0
View file @
d81fcd34
#!/usr/bin/env python3
"""
Add offset to PUS packet timestamps for data stored in a binary file (SMILE)
"""
import
os
def
run
(
fn
,
toff
=
None
,
outfile
=
None
):
with
open
(
fn
,
'
rb
'
)
as
fd
:
pkts
=
cfl
.
extract_pus
(
fd
)
# calculate offset from file's mtime and last packet timestamp if toff is not given
if
toff
is
None
:
print
(
'
Calculating time offset from file modification time and last TM packet timestamp...
'
)
idx
=
-
1
pkt_time
=
None
while
abs
(
idx
)
<=
len
(
pkts
):
if
not
(
pkts
[
idx
][
0
]
>>
4
)
&
1
:
pkt_time
=
int
.
from_bytes
(
pkts
[
idx
][
10
:
14
],
'
big
'
)
break
if
pkt_time
is
None
:
print
(
'
No TM packet found for reference
'
)
return
toff
=
int
(
os
.
path
.
getmtime
(
fn
))
-
pkt_time
print
(
'
TOFF =
'
,
toff
)
if
outfile
is
None
:
outfile
=
fn
+
'
.tmod
'
with
open
(
outfile
,
'
wb
'
)
as
fd
:
for
pkt
in
pkts
:
# check if pkt is TC
if
(
pkt
[
0
]
>>
4
)
&
1
:
fd
.
write
(
pkt
)
else
:
fd
.
write
(
mod_time
(
pkt
,
toff
))
print
(
'
Modified packets written to {}.
'
.
format
(
os
.
path
.
abspath
(
outfile
)))
def
mod_time
(
pkt
,
ofs
):
nw
=
pkt
[:
10
]
+
(
int
.
from_bytes
(
pkt
[
10
:
14
],
'
big
'
)
+
ofs
).
to_bytes
(
4
,
'
big
'
)
+
pkt
[
14
:
-
2
]
return
nw
+
cfl
.
crc
(
nw
).
to_bytes
(
2
,
'
big
'
)
filename
=
'
301123_LFT_cold_phase2_minus117_tcs
'
offset
=
1234567
# run(filename, toff=offset)
if
__name__
==
'
__main__
'
:
import
sys
import
confignator
cfg
=
confignator
.
get_config
()
sys
.
path
.
append
(
cfg
[
'
paths
'
][
'
ccs
'
])
import
ccs_function_lib
as
cfl
filename
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
2
:
offset
=
int
(
sys
.
argv
[
2
])
else
:
offset
=
None
run
(
filename
,
toff
=
offset
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment