1212from 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,19 +269,38 @@ 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 message .seq
275+ return int . from_bytes ( message .seq , byteorder = 'big' )
276276
277- def sdls_reset_ctr (self , spi : int ):
277+ def sdls_set_ctr (self , spi : int , new_seq : int ):
278278 """
279- Reset the sequence counter associated with a given `spi` (Security Parameter Index) on this link.
279+ Set the sequence counter associated with a given `spi` (Security Parameter Index) on this link to `new_seq` .
280280 """
281- self .ctx .delete_proto (f"/sdls/{ self ._instance } /{ self ._link } /{ spi } /seq" )
281+ 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 )
282284
283285 def sdls_set_key (self , spi : int , key : bytes ):
284286 """
285287 Update the `key` associated with a given `spi` (Security Parameter Index) on this link.
286288 """
287- self .ctx .put_proto (f"/sdls/{ self ._instance } /{ self ._link } /{ spi } /key" , data = key )
289+ self .ctx .put_proto (f'/sdls/{ self ._instance } /{ self ._link } /{ spi } /key' , data = key )
290+
291+ def sdls_set_spi (self , vc_id : int , spi : int ):
292+ """
293+ Update the `spi` used for SDLS on the VC `vc_id` on this link.
294+ """
295+ body = sdls_pb2 .SetSpiRequestBody ()
296+ body .spi = spi
297+ self .ctx .put_proto (f'/sdls/{ self ._instance } /{ self ._link } /{ vc_id } /spi' , data = body .SerializeToString ())
298+
299+ def sdls_set_spis (self , vc_id : int , spis : list [int ]):
300+ """
301+ Update the `spis` used for SDLS on the VC `vc_id` on this link.
302+ Only valid for incoming links (i.e., downlink).
303+ """
304+ body = sdls_pb2 .SetSpisRequestBody ()
305+ body .spis [:] = spis
306+ self .ctx .put_proto (f'/sdls/{ self ._instance } /{ self ._link } /{ vc_id } /spis' , data = body .SerializeToString ())
0 commit comments