Skip to content

Commit

Permalink
First implementation for eCAL Core with nanobind.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashariff-11 authored and KerstinKeller committed Jul 2, 2024
1 parent 120f12f commit 622c97d
Show file tree
Hide file tree
Showing 52 changed files with 3,058 additions and 38 deletions.
4 changes: 1 addition & 3 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,7 @@ set(ECAL_CORE_FEATURES
foreach(CORE_FEATURE ${ECAL_CORE_FEATURES})
if(${CORE_FEATURE})
target_compile_definitions(${PROJECT_NAME}
PRIVATE ${CORE_FEATURE})
target_compile_definitions(${PROJECT_NAME}_c
PRIVATE ${CORE_FEATURE})
PUBLIC ${CORE_FEATURE})
endif()
endforeach()

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/pubsub/ecal_publisher.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lang/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH "ON")
add_subdirectory(core)
add_dependencies(${PROJECT_NAME} _ecal_core_py)

add_subdirectory(nanobind_core)
add_subdirectory(nanobind_core/src)
add_dependencies(${PROJECT_NAME} nanobind_core)

if(HAS_HDF5)
Expand Down
28 changes: 0 additions & 28 deletions lang/python/nanobind_core/CMakeLists.txt

This file was deleted.

5 changes: 0 additions & 5 deletions lang/python/nanobind_core/main.cpp

This file was deleted.

69 changes: 69 additions & 0 deletions lang/python/nanobind_core/samples/minimal_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ========================= eCAL LICENSE =================================

from pickle import TRUE
import sys
import time

import nanobind_core as ecal_core

# define the client response callback to catch server responses
def client_resp_callback(service_info, response):
if (service_info["call_state"] == "call_state_executed"):
print("'DemoService' method '{}' responded : '{}'".format(service_info["method_name"], response))
print()
else:
print("server {} response failed, error : '{}'".format(service_info["host_name"], service_info["error_msg"]))
print()

def main():
# print eCAL version and date
print("eCAL {} ({})\n".format(ecal_core.get_version_string(), ecal_core.get_version_date()))

# initialize eCAL API
ecal_core.initialize()

# create a client for the "DemoService" service
client = ecal_core.ServiceClient("DemoService")

# and add it to the client
client.add_response_callback(client_resp_callback)

# idle and call service methods
i = 0
while(ecal_core.ok()):
i = i + 1
# call foo
request = bytes("hello foo {}".format(i), "ascii")
print("'DemoService' method 'foo' requested with : {}".format(request))
client.call("foo", "request", 1234)
time.sleep(0.5)
# call ping
request = bytes("ping number {}".format(i), "ascii")
print("'DemoService' method 'ping' requested with : {}".format(request))
client.call("ping", "request", 1234)
time.sleep(0.5)

# destroy client
client.destroy()

# finalize eCAL API
ecal_core.finalize()

if __name__ == "__main__":
main()
24 changes: 24 additions & 0 deletions lang/python/nanobind_core/samples/minimal_rec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys

import nanobind_core as ecal_core

def main():
# print eCAL version and date
print("eCAL {} ({})\n".format(ecal_core.get_version_string(), ecal_core.get_version_date()))

# initialize eCAL API
ecal_core.initialize()

# create subscriber
sub = ecal_core.Subscriber("Hello")

# receive messages
while ecal_core.ok():
msg = sub.receive(1234)
print("Received: {} ".format(msg))

# finalize eCAL API
ecal_core.finalize()

if __name__ == "__main__":
main()
48 changes: 48 additions & 0 deletions lang/python/nanobind_core/samples/minimal_rec_cb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ========================= eCAL LICENSE =================================

import sys
import time

import nanobind_core as ecal_core

# eCAL receive callback
def callback(topic_name, msg, time):
print("Received: {} ms {}".format(time, msg))

def main():
# print eCAL version and date
print("eCAL {} ({})\n".format(ecal_core.get_version_string(), ecal_core.get_version_date()))

# initialize eCAL API
ecal_core.initialize()

# create subscriber and connect callback
sub = ecal_core.Subscriber("Hello")
sub.add_receive_callback(callback)

# idle main thread
while ecal_core.ok():
time.sleep(0.1)

# finalize eCAL API
ecal_core.finalize()

if __name__ == "__main__":
main()

66 changes: 66 additions & 0 deletions lang/python/nanobind_core/samples/minimal_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ========================= eCAL LICENSE =================================

import sys
import time

import nanobind_core as ecal_core

# define the server method "foo" function
def foo_req_callback(method_name, req_type, resp_type, request):
print("'DemoService' method '{}' called with {}".format(method_name, request))
#return True #, bytes("thank you for calling foo :-)", "ascii")
return 0, "pong"

# define the server method "ping" function
def ping_req_callback(method_name, req_type, resp_type, request):
print("'DemoService' method '{}' called with {}".format(method_name, request))
return 0, bytes("pong", "ascii")

def main():
# print eCAL version and date
print("eCAL {} ({})\n".format(ecal_core.get_version_string(), ecal_core.get_version_date()))

# initialize eCAL API
ecal_core.initialize()

# initialize eCAL API
# ecal_core.initialize(sys.argv, "py_minimal_service_server")

# set process state
# ecal_core.set_process_state(1, 1, "I feel good")

# create a server for the "DemoService" service
server = ecal_core.ServiceServer("DemoService")

# define the server methods and connect them to the callbacks
server.add_method_callback("foo", "string", "string", foo_req_callback)
server.add_method_callback("ping", "ping_type", "pong_type", ping_req_callback)

# idle
while(ecal_core.ok()):
time.sleep(1.0)

# destroy server
server.destroy()

# finalize eCAL API
server.finalize()

if __name__ == "__main__":
main()
30 changes: 30 additions & 0 deletions lang/python/nanobind_core/samples/minimal_snd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
import time

import nanobind_core as ecal_core

def main():
# print eCAL version and date
print("eCAL {} ({})\n".format(ecal_core.get_version_string(), ecal_core.get_version_date()))

# initialize eCAL API
ecal_core.initialize()

# create publisher
pub = ecal_core.Publisher("Hello")
msg = "HELLO WORLD FROM PYTHON"

# send messages
i = 0
while ecal_core.ok():
i = i + 1
current_message = "{} {:6d}".format(msg, i)
print("Sending: {}".format(current_message))
pub.send(current_message,1234)
time.sleep(0.5)

# finalize eCAL API
ecal_core.finalize()

if __name__ == "__main__":
main()
Loading

0 comments on commit 622c97d

Please sign in to comment.