Skip to content

Commit 46bf66f

Browse files
committed
Refactor client service instance and add test for receiving events
1 parent 89e06bf commit 46bf66f

15 files changed

+429
-220
lines changed

article.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

example_apps/receive_events.py renamed to example_apps/receive_events_udp.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ipaddress
33
import logging
44

5+
from someipy import ServiceBuilder, EventGroup, TransportLayerProtocol, SomeIpMessage
56
from someipy.service_discovery import construct_service_discovery
67
from someipy.client_service_instance import construct_client_service_instance
78
from someipy.logging import set_someipy_log_level
@@ -11,12 +12,15 @@
1112
SD_PORT = 30490
1213
INTERFACE_IP = "127.0.0.1"
1314

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
1519

1620

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)
2024
print(temperature_msg)
2125

2226

@@ -37,14 +41,24 @@ async def main():
3741
# and port to which the events are sent to and the client will listen to
3842
# 3. The ServiceDiscoveryProtocol object has to be passed as well, so the ClientServiceInstance can offer his service to
3943
# 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+
4055
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,
4558
endpoint=(ipaddress.IPv4Address(INTERFACE_IP), 3002),
4659
ttl=5,
4760
sd_sender=service_discovery,
61+
protocol=TransportLayerProtocol.UDP
4862
)
4963

5064
# It's possible to optionally register a callback function which will be called when an event from the

example_apps/send_events_tcp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
import ipaddress
33
import logging
44

5-
from someipy import TransportLayerProtocol
6-
from someipy.service import ServiceBuilder, EventGroup
5+
from someipy import TransportLayerProtocol, ServiceBuilder, EventGroup, construct_server_service_instance
76
from someipy.service_discovery import construct_service_discovery
8-
from someipy.server_service_instance import construct_server_service_instance
97
from someipy.logging import set_someipy_log_level
108
from someipy.serialization import Uint8, Uint64, Float32
119
from temperature_msg import TemparatureMsg
@@ -83,7 +81,7 @@ async def main():
8381
try:
8482
# Either cyclically send events in an endless loop..
8583
while True:
86-
await asyncio.sleep(5)
84+
await asyncio.sleep(1)
8785
tmp_msg.timestamp = Uint64(tmp_msg.timestamp.value + 1)
8886
payload = tmp_msg.serialize()
8987
service_instance_temperature.send_event(

src/someipy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from ._internal.someip_sd_header import TransportLayerProtocol
22
from .server_service_instance import ServerServiceInstance, construct_server_service_instance
3-
from .service import Service, ServiceBuilder, EventGroup
3+
from .service import Service, ServiceBuilder, EventGroup
4+
from ._internal.someip_message import SomeIpMessage

0 commit comments

Comments
 (0)