Skip to content

Commit 456d256

Browse files
author
Jonathan Diamond
committed
Pull in changes from internal development.
1 parent c558420 commit 456d256

8 files changed

+243
-155
lines changed

bin/config_message_rate.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'udp2': InterfaceID(TransportType.UDP, 2),
2323
'tcp1': InterfaceID(TransportType.TCP, 1),
2424
'tcp2': InterfaceID(TransportType.TCP, 2),
25+
'tcp3': InterfaceID(TransportType.TCP, 3),
2526
'file': InterfaceID(TransportType.FILE, 1),
2627
'unix1': InterfaceID(TransportType.UNIX, 1),
2728
'unix2': InterfaceID(TransportType.UNIX, 2),

bin/p1_convert_user_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pathlib import Path
99
from typing import Type
1010

11-
import construct # For ignoring wrapper class in DeepDiff
11+
import construct # For ignoring wrapper class in DeepDiff
1212
from deepdiff import DeepDiff
1313
from fusion_engine_client.messages.configuration import (
1414
ConfigurationSource, DataType, DataVersion, PlatformStorageDataMessage,

firmware_tools/lg69t/firmware_tool.py

+175-140
Large diffs are not rendered by default.

p1_runner/data_source.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ClientConnection:
2121
logger = logging.getLogger('point_one.data_source')
2222

2323

24-
RESPONSE_TIMEOUT = 5
24+
RESPONSE_TIMEOUT = 5.0
2525
RX_BYTE_TIMEOUT = 0.1
2626
MAX_DATA_BUFFER_SIZE = 10 * 1024 * 1024
2727
DATA_BUFFER_DROP_SIZE = 1 * 1024 * 1024
@@ -205,11 +205,13 @@ def read(self, size: int, timeout=RESPONSE_TIMEOUT) -> bytes:
205205
if self.rx_thread is None:
206206
raise RuntimeError('Reading DeviceInterface without calling "start_rx_thread".')
207207
data = b''
208-
start_time = time.time()
209-
while size > 0 and time.time() - start_time < timeout:
208+
start_time = time.monotonic()
209+
now = start_time
210+
while size > 0 and now - start_time <= timeout:
210211
logger.trace(f'Buffered {len(self.data_buffer)} B.')
211212
if not self.data_event.wait(RX_BYTE_TIMEOUT):
212213
logger.debug('Timed out waiting for byte to be added to buffer.')
214+
now = time.monotonic()
213215
continue
214216
self.data_lock.acquire()
215217

@@ -224,6 +226,7 @@ def read(self, size: int, timeout=RESPONSE_TIMEOUT) -> bytes:
224226
size = 0
225227

226228
self.data_lock.release()
229+
now = time.monotonic()
227230
if self.rx_log:
228231
self.rx_log.write(data)
229232
return data

p1_runner/device_interface.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from fusion_engine_client.messages import *
55
from fusion_engine_client.parsers import (FusionEngineDecoder,
66
FusionEngineEncoder)
7+
from fusion_engine_client.parsers.decoder import MessageWithBytesTuple
78

89
import p1_runner.trace as logging
910
from p1_runner.data_source import RESPONSE_TIMEOUT, DataSource
@@ -135,6 +136,17 @@ def wait_for_reboot(self, data_stop_timeout=REBOOT_MAX_START_TIME, data_restart_
135136

136137
return reboot_started and reboot_finished
137138

139+
def wait_for_any_fe_message(self, response_timeout=RESPONSE_TIMEOUT) -> List[MessageWithBytesTuple]:
140+
start_time = time.time()
141+
while time.time() - start_time < response_timeout:
142+
msgs = self.fe_decoder.on_data(self.data_source.read(1, response_timeout))
143+
if len(msgs) > 0:
144+
return msgs # type: ignore
145+
return []
146+
147+
def poll_messages(self, read_buffer_size=MAX_FE_MSG_SIZE, response_timeout=0.0) -> List[MessageWithBytesTuple]:
148+
return self.fe_decoder.on_data(self.data_source.read(read_buffer_size, response_timeout)) # type: ignore
149+
138150
def wait_for_message(self, msg_type, response_timeout=RESPONSE_TIMEOUT):
139151
if isinstance(msg_type, MessageType):
140152
return self._wait_for_fe_message(msg_type, response_timeout)
@@ -144,7 +156,7 @@ def wait_for_message(self, msg_type, response_timeout=RESPONSE_TIMEOUT):
144156
def _wait_for_fe_message(self, msg_type, response_timeout):
145157
start_time = time.time()
146158
while True:
147-
msgs = self.fe_decoder.on_data(self.data_source.read(1))
159+
msgs = self.fe_decoder.on_data(self.data_source.read(1, response_timeout))
148160
for msg in msgs:
149161
if msg[0].message_type == msg_type:
150162
logger.debug('Response: %s', str(msg[1]))

p1_runner/device_type.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import re
12
from enum import Enum, auto
2-
from typing import Optional
3+
from typing import Dict, Optional
34

45

56
class DeviceType(Enum):
67
UNKNOWN = auto()
78

9+
ATLAS = auto()
810
LG69T_AM = auto()
911
LG69T_AP = auto()
1012
LG69T_AH = auto()
1113
LG69T_AJ = auto()
12-
ATLAS = auto()
1314

1415
BEAM2K = auto()
1516
DJI_MAVIC = auto()
@@ -26,6 +27,17 @@ def is_lg69t(self) -> bool:
2627
def device_uses_unframed_logs(self) -> bool:
2728
return self.is_lg69t() or self is DeviceType.LC29H
2829

30+
def is_gnss_only(self) -> bool:
31+
return self in (DeviceType.LG69T_AM,)
32+
33+
@classmethod
34+
def mapping_device_to_regex(cls) -> Dict['DeviceType', str]:
35+
return {
36+
DeviceType.ATLAS: 'v[0-9]*.*',
37+
DeviceType.LG69T_AM: 'lg69t-am-v[0-9]*.*',
38+
DeviceType.LG69T_AP: 'lg69t-ap-v[0-9]*.*',
39+
}
40+
2941
@classmethod
3042
def from_string(cls, name: Optional[str]) -> 'DeviceType':
3143
if name is not None:
@@ -35,3 +47,13 @@ def from_string(cls, name: Optional[str]) -> 'DeviceType':
3547
pass
3648

3749
return DeviceType.UNKNOWN
50+
51+
@classmethod
52+
def get_build_type_from_version(cls, version_str) -> Optional['DeviceType']:
53+
mapping = cls.mapping_device_to_regex()
54+
for key, val in mapping.items():
55+
r = fr'{val}'
56+
if re.match(r, version_str):
57+
return key
58+
59+
return None

p1_runner/log_manager.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
import uuid
99
from datetime import datetime, timezone
10+
from typing import Optional
1011

1112
from . import trace as logging
1213
from .log_manifest import DeviceType, LogManifest
@@ -20,7 +21,7 @@ class LogManager(threading.Thread):
2021

2122
def __init__(
2223
self, device_id, device_type='UNKNOWN', logs_base_dir='/logs', files=None, log_extension='.raw',
23-
create_symlink=True, log_created_cmd=None, log_timestamps=True):
24+
create_symlink=True, log_created_cmd=None, log_timestamps=True, directory_to_reuse: Optional[str] = None):
2425
super().__init__(name='log_manager')
2526

2627
self.device_id = device_id
@@ -29,11 +30,13 @@ def __init__(
2930
self.create_symlink = create_symlink
3031
self.log_created_cmd = log_created_cmd
3132
self.data_filename = 'input' + log_extension
33+
self.directory_to_reuse = directory_to_reuse
3234

3335
self.log_guid = None
3436
self.creation_time = None
3537
self.sequence_num = None
3638
self.log_dir = None
39+
self.timestamp_path = None
3740
self.log_timestamps = log_timestamps
3841
self.start_time = time.time()
3942
self.last_timestamp = time.time()
@@ -54,14 +57,19 @@ def get_abs_file_path(self, relative_path):
5457
else:
5558
return os.path.join(self.log_dir, relative_path)
5659

57-
def start(self):
58-
self.logger.debug('Starting log manager.')
60+
def create_log_dir(self):
61+
if self.directory_to_reuse:
62+
self.log_dir = self.directory_to_reuse
63+
if not os.path.exists(self.log_dir):
64+
raise IOError("Log directory '%s' doesn't exists." % self.log_dir)
65+
else:
66+
return
5967

6068
self.log_guid = str(uuid.uuid4()).replace('-', '')
6169
self.creation_time = datetime.now(tz=timezone.utc)
70+
6271
self.log_dir = os.path.join(self.logs_base_dir, self.creation_time.strftime('%Y-%m-%d'), self.device_id,
6372
self.log_guid)
64-
6573
if os.path.exists(self.log_dir):
6674
raise IOError("Log directory '%s' already exists." % self.log_dir)
6775
else:
@@ -93,6 +101,10 @@ def start(self):
93101

94102
self._create_manifest()
95103

104+
def start(self):
105+
self.logger.debug('Starting log manager.')
106+
if self.log_dir is None:
107+
self.create_log_dir()
96108
super().start()
97109

98110
def stop(self):
@@ -114,9 +126,9 @@ def run(self):
114126
self.logger.debug("Opening bin file '%s'." % path)
115127
timestamp_file = None
116128
if self.log_timestamps:
117-
timestamp_path = os.path.join(self.log_dir, self.data_filename + '.timestamps')
118-
self.logger.debug("Opening timestamp file '%s'." % timestamp_path)
119-
timestamp_file = open(timestamp_path, 'wb')
129+
self.timestamp_path = os.path.join(self.log_dir, self.data_filename + '.timestamps')
130+
self.logger.debug("Opening timestamp file '%s'." % self.timestamp_path)
131+
timestamp_file = open(self.timestamp_path, 'wb')
120132
with open(path, 'wb') as bin_file:
121133
if self.log_created_cmd is not None:
122134
try:
@@ -165,6 +177,8 @@ def _create_manifest(self):
165177
manifest.device_type = self.device_type if self.device_type is not None else 'UNKNOWN'
166178

167179
manifest.channels.append(self.data_filename)
180+
if self.timestamp_path:
181+
manifest.channels.append(self.timestamp_path)
168182
manifest.channels.extend(self.files)
169183
manifest.channels.sort()
170184

p1_runner/ntrip_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import traceback
88
from datetime import datetime, timezone
99
from functools import reduce
10+
from typing import Iterable
1011

1112
import ntripstreams
1213
from serial import SerialException
@@ -54,7 +55,7 @@ def set_data_callback(self, callback):
5455
def is_connected(self):
5556
return self.connected
5657

57-
def send_position(self, lla_deg: list, time: datetime = None):
58+
def send_position(self, lla_deg: Iterable[float], time: datetime = None):
5859
if not self.connected:
5960
self.logger.trace('Not connected. Ignoring position update. [%.8f, %.8f, %.2f]' % tuple(lla_deg))
6061
return False

0 commit comments

Comments
 (0)