Skip to content

Commit df316a0

Browse files
author
Alex Balgavy
committed
A bit of refactoring and comments
1 parent cd43829 commit df316a0

5 files changed

Lines changed: 372 additions & 456 deletions

File tree

yamcs-client/src/yamcs/client/links/client.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from yamcs.protobuf.sdls import sdls_pb2
1313

1414
__all__ = [
15-
'Cop1Subscription',
16-
'LinkClient',
15+
"Cop1Subscription",
16+
"LinkClient",
1717
]
1818

1919

@@ -92,7 +92,7 @@ def get_info(self) -> Link:
9292
"""
9393
Get info on this link.
9494
"""
95-
response = self.ctx.get_proto(f'/links/{self._instance}/{self._link}')
95+
response = self.ctx.get_proto(f"/links/{self._instance}/{self._link}")
9696
message = links_pb2.LinkInfo()
9797
message.ParseFromString(response.content)
9898
return Link(message)
@@ -102,15 +102,15 @@ def enable_link(self):
102102
Enables this link.
103103
"""
104104
req = links_pb2.EnableLinkRequest()
105-
url = f'/links/{self._instance}/{self._link}:enable'
105+
url = f"/links/{self._instance}/{self._link}:enable"
106106
self.ctx.post_proto(url, data=req.SerializeToString())
107107

108108
def disable_link(self):
109109
"""
110110
Disables this link.
111111
"""
112112
req = links_pb2.DisableLinkRequest()
113-
url = f'/links/{self._instance}/{self._link}:disable'
113+
url = f"/links/{self._instance}/{self._link}:disable"
114114
self.ctx.post_proto(url, data=req.SerializeToString())
115115

116116
def run_action(
@@ -132,7 +132,7 @@ def run_action(
132132
if message:
133133
req.message.update(message)
134134

135-
url = f'/links/{self._instance}/{self._link}/actions/{action}'
135+
url = f"/links/{self._instance}/{self._link}/actions/{action}"
136136
response = self.ctx.post_proto(url, data=req.message.SerializeToString())
137137
response_message = struct_pb2.Struct()
138138
response_message.ParseFromString(response.content)
@@ -142,7 +142,7 @@ def get_cop1_config(self) -> Cop1Config:
142142
"""
143143
Gets the COP1 configuration for a data link.
144144
"""
145-
response = self.ctx.get_proto(f'/cop1/{self._instance}/{self._link}/config')
145+
response = self.ctx.get_proto(f"/cop1/{self._instance}/{self._link}/config")
146146
message = cop1_pb2.Cop1Config()
147147
message.ParseFromString(response.content)
148148
return Cop1Config(message)
@@ -167,7 +167,7 @@ def update_cop1_config(
167167
if t1 is not None:
168168
req.t1 = int(round(1000 * t1))
169169

170-
url = f'/cop1/{self._instance}/{self._link}/config'
170+
url = f"/cop1/{self._instance}/{self._link}/config"
171171
response = self.ctx.patch_proto(url, data=req.SerializeToString())
172172

173173
message = cop1_pb2.Cop1Config()
@@ -183,7 +183,7 @@ def disable_cop1(self, bypass_all: bool = True):
183183
"""
184184
req = cop1_pb2.DisableRequest()
185185
req.setBypassAll = bypass_all
186-
url = f'/cop1/{self._instance}/{self._link}:disable'
186+
url = f"/cop1/{self._instance}/{self._link}:disable"
187187
self.ctx.post_proto(url, data=req.SerializeToString())
188188

189189
def initialize_cop1(
@@ -212,22 +212,22 @@ def initialize_cop1(
212212
if v_r is not None:
213213
req.vR = v_r
214214

215-
url = f'/cop1/{self._instance}/{self._link}:initialize'
215+
url = f"/cop1/{self._instance}/{self._link}:initialize"
216216
self.ctx.post_proto(url, data=req.SerializeToString())
217217

218218
def resume_cop1(self):
219219
"""
220220
Resume COP1.
221221
"""
222222
req = cop1_pb2.ResumeRequest()
223-
url = f'/cop1/{self._instance}/{self._link}:resume'
223+
url = f"/cop1/{self._instance}/{self._link}:resume"
224224
self.ctx.post_proto(url, data=req.SerializeToString())
225225

226226
def get_cop1_status(self) -> Cop1Status:
227227
"""
228228
Retrieve the COP1 status.
229229
"""
230-
response = self.ctx.get_proto(f'/cop1/{self._instance}/{self._link}/status')
230+
response = self.ctx.get_proto(f"/cop1/{self._instance}/{self._link}/status")
231231
message = cop1_pb2.Cop1Status()
232232
message.ParseFromString(response.content)
233233
return Cop1Status(message)
@@ -251,7 +251,7 @@ def create_cop1_subscription(self, on_data: Callable[[Cop1Status], None], timeou
251251
options.instance = self._instance
252252
options.link = self._link
253253

254-
manager = WebSocketSubscriptionManager(self.ctx, topic='cop1', options=options)
254+
manager = WebSocketSubscriptionManager(self.ctx, topic="cop1", options=options)
255255

256256
# Represent subscription as a future
257257
subscription = Cop1Subscription(manager)
@@ -269,32 +269,33 @@ def sdls_get_ctr(self, spi: int) -> int:
269269
"""
270270
Get the sequence counter associated with a given `spi` (Security Parameter Index) on this link.
271271
"""
272-
response = self.ctx.get_proto(f'/sdls/{self._instance}/{self._link}/{spi}/seq')
272+
response = self.ctx.get_proto(f"/sdls/{self._instance}/{self._link}/{spi}/seq")
273273
message = sdls_pb2.GetSeqCtrResponse()
274274
message.ParseFromString(response.content)
275-
return int.from_bytes(message.seq, byteorder='big')
275+
return int.from_bytes(message.seq, byteorder="big")
276276

277277
def sdls_set_ctr(self, spi: int, new_seq: int):
278278
"""
279279
Set the sequence counter associated with a given `spi` (Security Parameter Index) on this link to `new_seq`.
280280
"""
281+
body = sdls_pb2.SetSeqCtrRequestBody()
281282
byte_length = (new_seq.bit_length() + 7) // 8
282-
seq_bytes = new_seq.to_bytes(byte_length, byteorder='big')
283-
self.ctx.put_proto(f'/sdls/{self._instance}/{self._link}/{spi}/seq', data=seq_bytes)
283+
body.seq = new_seq.to_bytes(byte_length, byteorder="big")
284+
self.ctx.put_proto(f"/sdls/{self._instance}/{self._link}/{spi}/seq", data=body.SerializeToString())
284285

285286
def sdls_set_key(self, spi: int, key: bytes):
286287
"""
287288
Update the `key` associated with a given `spi` (Security Parameter Index) on this link.
288289
"""
289-
self.ctx.put_proto(f'/sdls/{self._instance}/{self._link}/{spi}/key', data=key)
290+
self.ctx.put_proto(f"/sdls/{self._instance}/{self._link}/{spi}/key", data=key)
290291

291292
def sdls_set_spi(self, vc_id: int, spi: int):
292293
"""
293294
Update the `spi` used for SDLS on the VC `vc_id` on this link.
294295
"""
295296
body = sdls_pb2.SetSpiRequestBody()
296297
body.spi = spi
297-
self.ctx.put_proto(f'/sdls/{self._instance}/{self._link}/{vc_id}/spi', data=body.SerializeToString())
298+
self.ctx.put_proto(f"/sdls/{self._instance}/{self._link}/{vc_id}/spi", data=body.SerializeToString())
298299

299300
def sdls_set_spis(self, vc_id: int, spis: list[int]):
300301
"""
@@ -303,4 +304,4 @@ def sdls_set_spis(self, vc_id: int, spis: list[int]):
303304
"""
304305
body = sdls_pb2.SetSpisRequestBody()
305306
body.spis[:] = spis
306-
self.ctx.put_proto(f'/sdls/{self._instance}/{self._link}/{vc_id}/spis', data=body.SerializeToString())
307+
self.ctx.put_proto(f"/sdls/{self._instance}/{self._link}/{vc_id}/spis", data=body.SerializeToString())

yamcs-client/src/yamcs/protobuf/mdb/mdb_pb2.py

Lines changed: 176 additions & 271 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)