Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-osc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrew Haigh
python-osc
Commits
f56b9c12
Commit
f56b9c12
authored
9 years ago
by
nik
Browse files
Options
Downloads
Patches
Plain Diff
changed implementation of ntp timestamp conversion
Ported from the OSC (scosc?) implementation ...
parent
b735de81
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pythonosc/parsing/ntp.py
+11
-11
11 additions, 11 deletions
pythonosc/parsing/ntp.py
pythonosc/parsing/osc_types.py
+1
-1
1 addition, 1 deletion
pythonosc/parsing/osc_types.py
with
12 additions
and
12 deletions
pythonosc/parsing/ntp.py
+
11
−
11
View file @
f56b9c12
...
...
@@ -5,6 +5,9 @@ import struct
import
time
JAN_1970
=
2208988800
SECS_TO_PICOS
=
4294967296
# 63 zero bits followed by a one in the least signifigant bit is a special
# case meaning "immediately."
IMMEDIATELY
=
struct
.
pack
(
'
>q
'
,
1
)
...
...
@@ -26,15 +29,12 @@ def ntp_to_system_time(date):
"""
return
date
-
_NTP_DELTA
def
system_time_to_ntp
(
date
):
"""
Convert a system time to a NTP time datagram.
"""
since 1970 => since 1900 64b OSC
"""
sec_1970
=
int
(
date
)
sec_1900
=
sec_1970
+
JAN_1970
System time is reprensented by seconds since the epoch in UTC.
"""
try
:
ntp
=
date
+
_NTP_DELTA
except
TypeError
as
ve
:
raise
NtpError
(
'
Invalud date: {}
'
.
format
(
ve
))
num_secs
,
fraction
=
str
(
ntp
).
split
(
'
.
'
)
return
struct
.
pack
(
'
>I
'
,
int
(
num_secs
))
+
struct
.
pack
(
'
>I
'
,
int
(
fraction
))
sec_frac
=
float
(
date
-
sec_1970
)
picos
=
int
(
sec_frac
*
SECS_TO_PICOS
)
return
struct
.
pack
(
'
>I
'
,
int
(
sec_1900
))
+
struct
.
pack
(
'
>I
'
,
picos
)
This diff is collapsed.
Click to expand it.
pythonosc/parsing/osc_types.py
+
1
−
1
View file @
f56b9c12
...
...
@@ -112,7 +112,7 @@ def get_int(dgram, start_index):
if
len
(
dgram
[
start_index
:])
<
_INT_DGRAM_LEN
:
raise
ParseError
(
'
Datagram is too short
'
)
return
(
struct
.
unpack
(
'
>
i
'
,
struct
.
unpack
(
'
>
I
'
,
dgram
[
start_index
:
start_index
+
_INT_DGRAM_LEN
])[
0
],
start_index
+
_INT_DGRAM_LEN
)
except
(
struct
.
error
,
TypeError
)
as
e
:
...
...
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