2
2
import ipaddress
3
3
import logging
4
4
5
+ from someipy import ServiceBuilder , EventGroup , TransportLayerProtocol , SomeIpMessage
5
6
from someipy .service_discovery import construct_service_discovery
6
7
from someipy .client_service_instance import construct_client_service_instance
7
8
from someipy .logging import set_someipy_log_level
11
12
SD_PORT = 30490
12
13
INTERFACE_IP = "127.0.0.1"
13
14
14
- SAMPLE_EVENTGROUP_ID = 20
15
+ SAMPLE_SERVICE_ID = 0x1234
16
+ SAMPLE_INSTANCE_ID = 0x5678
17
+ SAMPLE_EVENTGROUP_ID = 0x0321
18
+ SAMPLE_EVENT_ID = 0x0123
15
19
16
20
17
- def temperature_callback (payload : bytes ) -> None :
18
- print (f"Received { len (payload )} bytes." )
19
- temperature_msg = TemparatureMsg ().deserialize (payload )
21
+ def temperature_callback (someip_message : SomeIpMessage ) -> None :
22
+ print (f"Received { len (someip_message . payload )} bytes." )
23
+ temperature_msg = TemparatureMsg ().deserialize (someip_message . payload )
20
24
print (temperature_msg )
21
25
22
26
@@ -37,14 +41,24 @@ async def main():
37
41
# and port to which the events are sent to and the client will listen to
38
42
# 3. The ServiceDiscoveryProtocol object has to be passed as well, so the ClientServiceInstance can offer his service to
39
43
# other ECUs
44
+ temperature_eventgroup = EventGroup (
45
+ id = SAMPLE_EVENTGROUP_ID , event_ids = [SAMPLE_EVENT_ID ]
46
+ )
47
+ temperature_service = (
48
+ ServiceBuilder ()
49
+ .with_service_id (SAMPLE_SERVICE_ID )
50
+ .with_major_version (1 )
51
+ .with_eventgroup (temperature_eventgroup )
52
+ .build ()
53
+ )
54
+
40
55
service_instance_temperature = await construct_client_service_instance (
41
- service_id = 1 ,
42
- instance_id = 1000 ,
43
- major_version = 1 ,
44
- minor_version = 0 ,
56
+ service = temperature_service ,
57
+ instance_id = SAMPLE_INSTANCE_ID ,
45
58
endpoint = (ipaddress .IPv4Address (INTERFACE_IP ), 3002 ),
46
59
ttl = 5 ,
47
60
sd_sender = service_discovery ,
61
+ protocol = TransportLayerProtocol .UDP
48
62
)
49
63
50
64
# It's possible to optionally register a callback function which will be called when an event from the
0 commit comments