Skip to content

Commit b230d9c

Browse files
authored
Add cooldown option for file uplink (#272)
* Add cooldown to FileUplinker * Extend timeout * Bump default file cooldown to 500ms * Make cooldown a CLI argument * Add 'cooldown' to spelling expect list * Change default file uplink cooldown to 0 * Change default cooldown value in uplinker constructor Updated cooldown parameter default value from 0.5 to 0.0.
1 parent d3c3687 commit b230d9c

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

.github/actions/spelling/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ combuffer
6868
commandsi
6969
configs
7070
Consolas
71+
cooldown
7172
creatingdocsetswithdoxygen
7273
csum
7374
ctx

src/fprime_gds/common/files/uplinker.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class FileUplinker(fprime_gds.common.handlers.DataHandler):
149149

150150
CHUNK_SIZE = 256
151151

152-
def __init__(self, file_encoder, chunk=CHUNK_SIZE, timeout=20):
152+
def __init__(self, file_encoder, chunk=CHUNK_SIZE, timeout=20, cooldown=0.0):
153153
"""
154154
Constructor to build the file uplinker.
155155
"""
@@ -163,6 +163,7 @@ def __init__(self, file_encoder, chunk=CHUNK_SIZE, timeout=20):
163163
self.__expected = []
164164
self.__timeout = Timeout()
165165
self.__timeout.setup(self.timeout, timeout)
166+
self.cooldown = cooldown
166167

167168
def enqueue(self, filepath, destination=None):
168169
"""
@@ -273,6 +274,7 @@ def data_callback(self, data, sender=None):
273274
# Ignore handshakes not for us
274275
if not self.valid_handshake(data):
275276
return
277+
276278
# If it is an end-wait or a cancel state, respond without reading next chunk
277279
if self.state == FileStates.END_WAIT:
278280
self.active.state = (
@@ -286,6 +288,7 @@ def data_callback(self, data, sender=None):
286288
self.send(CancelPacketData(self.get_next_sequence()))
287289
self.finish()
288290
return
291+
time.sleep(self.cooldown)
289292
# Read next chunk of data. b'' means the file is empty
290293
outgoing = self.active.read(self.chunk)
291294
if outgoing == b"":

src/fprime_gds/common/pipeline/files.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self):
2525
self.__downlinker = None
2626

2727
def setup_file_handling(
28-
self, down_store, file_encoder, file_decoder, distributor, log_dir
28+
self, down_store, file_encoder, file_decoder, distributor, log_dir, cooldown=0.5
2929
):
3030
"""
3131
Sets up the file handling (uplink and downlink) from a pair of encoders and decoders.
@@ -36,8 +36,9 @@ def setup_file_handling(
3636
:param file_decoder: file decoder for downlink
3737
:param distributor: data distributor to register handshaking to
3838
:param log_dir: log directory to output downlink logs
39+
:param cooldown: cooldown period between uplink packets
3940
"""
40-
self.__uplinker = fprime_gds.common.files.uplinker.FileUplinker(file_encoder)
41+
self.__uplinker = fprime_gds.common.files.uplinker.FileUplinker(file_encoder, cooldown=cooldown)
4142
self.__downlinker = fprime_gds.common.files.downlinker.FileDownlinker(
4243
down_store, log_dir=log_dir
4344
)

src/fprime_gds/common/pipeline/standard.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def setup(
6262
file_store,
6363
logging_prefix=None,
6464
data_logging_enabled=True,
65+
cooldown=0.5,
6566
):
6667
"""
6768
Setup the standard pipeline for moving data from the middleware layer through the GDS layers using the standard
@@ -72,6 +73,7 @@ def setup(
7273
:param file_store: uplink/downlink storage directory
7374
:param logging_prefix: logging prefix. Defaults to not logging at all.
7475
:param packet_spec: location of packetized telemetry XML specification.
76+
:param cooldown: cooldown period between file uplink packets
7577
"""
7678
self.distributor = fprime_gds.common.distributor.distributor.Distributor()
7779
self.client_socket = self.__transport_type()
@@ -96,6 +98,7 @@ def setup(
9698
self.coders.file_decoder,
9799
self.distributor,
98100
logging_prefix,
101+
cooldown=cooldown,
99102
)
100103
# Register distributor to client socket
101104
self.client_socket.register(self.distributor)

src/fprime_gds/executables/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,14 @@ def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
10831083
"type": str,
10841084
"help": "Directory to save command sequence binaries, on the remote FSW. Default: %(default)s",
10851085
},
1086+
("--file-uplink-cooldown",): {
1087+
"dest": "file_uplink_cooldown",
1088+
"action": "store",
1089+
"default": 0,
1090+
"required": False,
1091+
"type": float,
1092+
"help": "Cooldown period between file uplink packets. Default: %(default)s S",
1093+
},
10861094
}
10871095

10881096
def handle_arguments(self, args, **kwargs):
@@ -1121,6 +1129,7 @@ def pipeline_factory(args_ns, pipeline=None) -> StandardPipeline:
11211129
"file_store": args_ns.files_storage_directory,
11221130
"logging_prefix": args_ns.logs,
11231131
"data_logging_enabled": not args_ns.disable_data_logging,
1132+
"cooldown": args_ns.file_uplink_cooldown,
11241133
}
11251134
pipeline = pipeline if pipeline else StandardPipeline()
11261135
pipeline.transport_implementation = args_ns.connection_transport

0 commit comments

Comments
 (0)