1
1
import asyncio
2
2
from typing import Tuple
3
3
4
- from someipy ._internal .tcp_client_manager import TcpClientManager , TcpClientProtocol
5
4
from someipy .service import Service
6
5
6
+ from someipy ._internal .tcp_client_manager import TcpClientManager , TcpClientProtocol
7
7
from someipy ._internal .message_types import MessageType , ReturnCode
8
8
from someipy ._internal .someip_sd_builder import (
9
9
build_subscribe_eventgroup_ack_entry ,
24
24
ServiceDiscoveryObserver ,
25
25
ServiceDiscoverySender ,
26
26
)
27
-
28
27
from someipy ._internal .simple_timer import SimplePeriodicTimer
29
28
from someipy ._internal .utils import (
30
29
create_udp_socket ,
43
42
44
43
45
44
class ServerServiceInstance (ServiceDiscoveryObserver ):
46
- service : Service
47
- instance_id : int
48
- endpoint : EndpointType
49
- protocol : TransportLayerProtocol
50
- someip_endpoint : SomeipEndpoint
51
- ttl : int
52
- sd_sender : ServiceDiscoverySender
53
- cyclic_offer_delay_ms : int
54
-
55
- subscribers : Subscribers
56
- offer_timer : SimplePeriodicTimer
45
+ """AI is creating summary for ServerServiceInstance
46
+
47
+ Args:
48
+ ServiceDiscoveryObserver ([type]): [description]
49
+
50
+ Returns:
51
+ [type]: [description]
52
+ """
53
+
54
+ _service : Service
55
+ _instance_id : int
56
+ _endpoint : EndpointType
57
+ _protocol : TransportLayerProtocol
58
+ _someip_endpoint : SomeipEndpoint
59
+ _ttl : int
60
+ _sd_sender : ServiceDiscoverySender
61
+ _cyclic_offer_delay_ms : int
62
+
63
+ _subscribers : Subscribers
64
+ _offer_timer : SimplePeriodicTimer
57
65
58
66
def __init__ (
59
67
self ,
@@ -66,24 +74,24 @@ def __init__(
66
74
sd_sender = None ,
67
75
cyclic_offer_delay_ms = 2000 ,
68
76
):
69
- self .service = service
70
- self .instance_id = instance_id
71
- self .endpoint = endpoint
72
- self .protocol = protocol
73
- self .someip_endpoint = someip_endpoint
74
- self .ttl = ttl
75
- self .sd_sender = sd_sender
76
- self .cyclic_offer_delay_ms = cyclic_offer_delay_ms
77
-
78
- self .subscribers = Subscribers ()
79
- self .offer_timer = None
77
+ self ._service = service
78
+ self ._instance_id = instance_id
79
+ self ._endpoint = endpoint
80
+ self ._protocol = protocol
81
+ self ._someip_endpoint = someip_endpoint
82
+ self ._ttl = ttl
83
+ self ._sd_sender = sd_sender
84
+ self ._cyclic_offer_delay_ms = cyclic_offer_delay_ms
85
+
86
+ self ._subscribers = Subscribers ()
87
+ self ._offer_timer = None
80
88
81
89
def send_event (self , event_group_id : int , event_id : int , payload : bytes ) -> None :
82
- self .subscribers .update ()
90
+ self ._subscribers .update ()
83
91
84
92
length = 8 + len (payload )
85
93
someip_header = SomeIpHeader (
86
- service_id = self .service .id ,
94
+ service_id = self ._service .id ,
87
95
method_id = event_id ,
88
96
length = length ,
89
97
client_id = 0x00 , # TODO
@@ -93,16 +101,13 @@ def send_event(self, event_group_id: int, event_id: int, payload: bytes) -> None
93
101
message_type = MessageType .NOTIFICATION .value ,
94
102
return_code = 0x00 ,
95
103
)
96
- _logger .debug (
97
- f"Send event for instance 0x{ self .instance_id :04X} , service: 0x{ self .service .id :04X} "
98
- )
99
104
100
- for sub in self .subscribers .subscribers :
105
+ for sub in self ._subscribers .subscribers :
101
106
if sub .eventgroup_id == event_group_id :
102
107
_logger .debug (
103
- f"Send event for instance 0x{ self .instance_id :04X} , service: 0x{ self .service .id :04X} to { sub .endpoint [0 ]} :{ sub .endpoint [1 ]} "
108
+ f"Send event for instance 0x{ self ._instance_id :04X} , service: 0x{ self ._service .id :04X} to { sub .endpoint [0 ]} :{ sub .endpoint [1 ]} "
104
109
)
105
- self .someip_endpoint .sendto (
110
+ self ._someip_endpoint .sendto (
106
111
someip_header .to_buffer () + payload ,
107
112
endpoint_to_str_int_tuple (sub .endpoint ),
108
113
)
@@ -148,12 +153,12 @@ def send_response():
148
153
149
154
if not success :
150
155
_logger .debug (
151
- f"Return ERROR message type to { addr } for service and instance ID: 0x{ self .service_id :04X} / 0x{ self .instance_id :04X} "
156
+ f"Return ERROR message type to { addr } for service and instance ID: 0x{ self .service_id :04X} / 0x{ self ._instance_id :04X} "
152
157
)
153
158
header_to_return .message_type = MessageType .ERROR .value
154
159
else :
155
160
_logger .debug (
156
- f"Return RESPONSE message type to { addr } for service and instance ID: 0x{ self .service_id :04X} / 0x{ self .instance_id :04X} "
161
+ f"Return RESPONSE message type to { addr } for service and instance ID: 0x{ self .service_id :04X} / 0x{ self ._instance_id :04X} "
157
162
)
158
163
header_to_return .message_type = MessageType .RESPONSE .value
159
164
@@ -182,17 +187,17 @@ def subscribe_eventgroup_update(
182
187
# an Eventgroup of a Service Instance.
183
188
# TODO: enable major version check
184
189
if (
185
- sd_event_group .sd_entry .service_id == self .service .id
186
- and sd_event_group .sd_entry .instance_id == self .instance_id
187
- and sd_event_group .eventgroup_id in self .service .eventgroupids
190
+ sd_event_group .sd_entry .service_id == self ._service .id
191
+ and sd_event_group .sd_entry .instance_id == self ._instance_id
192
+ and sd_event_group .eventgroup_id in self ._service .eventgroupids
188
193
):
189
194
(
190
195
session_id ,
191
196
reboot_flag ,
192
- ) = self .sd_sender .get_unicast_session_handler ().update_session ()
197
+ ) = self ._sd_sender .get_unicast_session_handler ().update_session ()
193
198
194
199
_logger .debug (
195
- f"Send Subscribe ACK for instance 0x{ self .instance_id :04X} , service: 0x{ self .service .id :04X} , TTL: { sd_event_group .sd_entry .ttl } "
200
+ f"Send Subscribe ACK for instance 0x{ self ._instance_id :04X} , service: 0x{ self ._service .id :04X} , TTL: { sd_event_group .sd_entry .ttl } "
196
201
)
197
202
ack_entry = build_subscribe_eventgroup_ack_entry (
198
203
service_id = sd_event_group .sd_entry .service_id ,
@@ -205,12 +210,12 @@ def subscribe_eventgroup_update(
205
210
entry = ack_entry , session_id = session_id , reboot_flag = reboot_flag
206
211
)
207
212
208
- self .sd_sender .send_unicast (
213
+ self ._sd_sender .send_unicast (
209
214
buffer = header_output .to_buffer (),
210
215
dest_ip = ipv4_endpoint_option .ipv4_address ,
211
216
)
212
217
213
- self .subscribers .add_subscriber (
218
+ self ._subscribers .add_subscriber (
214
219
EventGroupSubscriber (
215
220
eventgroup_id = sd_event_group .eventgroup_id ,
216
221
endpoint = (
@@ -230,40 +235,40 @@ def offer_timer_callback(self):
230
235
(
231
236
session_id ,
232
237
reboot_flag ,
233
- ) = self .sd_sender .get_multicast_session_handler ().update_session ()
238
+ ) = self ._sd_sender .get_multicast_session_handler ().update_session ()
234
239
235
240
_logger .debug (
236
- f"Offer service for instance 0x{ self .instance_id :04X} , service: 0x{ self .service .id :04X} , TTL: { self .ttl } , version: { self .service .major_version } .{ self .service .minor_version } , session ID: { session_id } "
241
+ f"Offer service for instance 0x{ self ._instance_id :04X} , service: 0x{ self ._service .id :04X} , TTL: { self ._ttl } , version: { self ._service .major_version } .{ self ._service .minor_version } , session ID: { session_id } "
237
242
)
238
243
239
244
service_to_offer = SdService (
240
- service_id = self .service .id ,
241
- instance_id = self .instance_id ,
245
+ service_id = self ._service .id ,
246
+ instance_id = self ._instance_id ,
242
247
major_version = 1 ,
243
248
minor_version = 0 ,
244
- ttl = self .ttl ,
245
- endpoint = self .endpoint ,
246
- protocol = self .protocol ,
249
+ ttl = self ._ttl ,
250
+ endpoint = self ._endpoint ,
251
+ protocol = self ._protocol ,
247
252
)
248
253
sd_header = build_offer_service_sd_header (
249
254
service_to_offer , session_id , reboot_flag
250
255
)
251
- self .sd_sender .send_multicast (sd_header .to_buffer ())
256
+ self ._sd_sender .send_multicast (sd_header .to_buffer ())
252
257
253
258
def start_offer (self ):
254
- self .offer_timer = SimplePeriodicTimer (
255
- self .cyclic_offer_delay_ms / 1000.0 , self .offer_timer_callback
259
+ self ._offer_timer = SimplePeriodicTimer (
260
+ self ._cyclic_offer_delay_ms / 1000.0 , self .offer_timer_callback
256
261
)
257
- self .offer_timer .start ()
262
+ self ._offer_timer .start ()
258
263
259
264
async def stop_offer (self ):
260
265
_logger .debug (
261
- f"Stop offer for instance 0x{ self .instance_id :04X} , service: 0x{ self .service .id :04X} "
266
+ f"Stop offer for instance 0x{ self ._instance_id :04X} , service: 0x{ self ._service .id :04X} "
262
267
)
263
268
264
- if self .offer_timer is not None :
265
- self .offer_timer .stop ()
266
- await self .offer_timer .task
269
+ if self ._offer_timer is not None :
270
+ self ._offer_timer .stop ()
271
+ await self ._offer_timer .task
267
272
# TODO: send out a stop offer sd message before stopping the timer
268
273
269
274
0 commit comments