-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
398 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import asyncio | ||
import ipaddress | ||
import logging | ||
|
||
from someipy import TransportLayerProtocol | ||
from someipy.client_service_instance import MethodResult, construct_client_service_instance | ||
from someipy.service import ServiceBuilder | ||
from someipy.service_discovery import construct_service_discovery | ||
from someipy.logging import set_someipy_log_level | ||
from addition_method_parameters import Addends, Sum | ||
|
||
SD_MULTICAST_GROUP = "224.224.224.245" | ||
SD_PORT = 30490 | ||
INTERFACE_IP = "127.0.0.1" | ||
|
||
SAMPLE_SERVICE_ID = 0x1234 | ||
SAMPLE_INSTANCE_ID = 0x5678 | ||
SAMPLE_METHOD_ID = 0x0123 | ||
|
||
async def main(): | ||
|
||
# It's possible to configure the logging level of the someipy library, e.g. logging.INFO, logging.DEBUG, logging.WARN, .. | ||
set_someipy_log_level(logging.DEBUG) | ||
|
||
# Since the construction of the class ServiceDiscoveryProtocol is not trivial and would require an async __init__ function | ||
# use the construct_service_discovery function | ||
# The local interface IP address needs to be passed so that the src-address of all SD UDP packets is correctly set | ||
service_discovery = await construct_service_discovery(SD_MULTICAST_GROUP, SD_PORT, INTERFACE_IP) | ||
|
||
addition_service = ( | ||
ServiceBuilder() | ||
.with_service_id(SAMPLE_SERVICE_ID) | ||
.with_major_version(1) | ||
.build() | ||
) | ||
|
||
# For calling methods construct a ClientServiceInstance | ||
client_instance_addition = await construct_client_service_instance( | ||
service=addition_service, | ||
instance_id=SAMPLE_INSTANCE_ID, | ||
endpoint=(ipaddress.IPv4Address(INTERFACE_IP), 3002), | ||
ttl=5, | ||
sd_sender=service_discovery, | ||
protocol=TransportLayerProtocol.UDP | ||
) | ||
|
||
# The service instance has to be attached always to the ServiceDiscoveryProtocol object, so that the service instance | ||
# is notified by the ServiceDiscoveryProtocol about e.g. subscriptions or offers from other ECUs | ||
service_discovery.attach(client_instance_addition) | ||
|
||
try: | ||
while True: | ||
|
||
method_parameter = Addends(addend1=1, addend2=2) | ||
method_success, method_result = await client_instance_addition.call_method(SAMPLE_METHOD_ID, method_parameter.serialize()) | ||
if method_success == MethodResult.SUCCESS: | ||
print(f"Received result for method: {' '.join(f'0x{b:02x}' for b in method_result)}") | ||
try: | ||
sum = Sum().deserialize(method_result) | ||
print(f"Sum: {sum.value.value}") | ||
except e: | ||
print(f"Error during deserialization: {e}") | ||
elif method_success == MethodResult.ERROR: | ||
print("Method call failed..") | ||
elif method_success == MethodResult.TIMEOUT: | ||
print("Method call timed out..") | ||
elif method_success == MethodResult.SERVICE_NOT_FOUND: | ||
print("Service not yet available..") | ||
|
||
await asyncio.sleep(2) | ||
except asyncio.CancelledError: | ||
print("Shutdown..") | ||
finally: | ||
print("Service Discovery close..") | ||
service_discovery.close() | ||
|
||
print("End main task..") | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
asyncio.run(main()) | ||
except KeyboardInterrupt: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from ._internal.someip_sd_header import TransportLayerProtocol # noqa: F401 | ||
from .server_service_instance import ServerServiceInstance, construct_server_service_instance # noqa: F401 | ||
from .service import Service, ServiceBuilder, EventGroup # noqa: F401 | ||
from .server_service_instance import ServerServiceInstance, construct_server_service_instance # noqa: F401 | ||
from .client_service_instance import ClientServiceInstance, construct_client_service_instance, MethodResult # noqa: F401 | ||
|
||
from ._internal.someip_message import SomeIpMessage # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.