Update channel.py

Added option to connect using IP address of the robot.

For Example:

python3 ./example/front_camera/camera_opencv.py enp2s0

python3 ./example/front_camera/camera_opencv.py 192.168.123.51

Both of the above will work, where "192.168.123.51" is the static IP address of the robot.
This commit is contained in:
Irfan 2024-05-22 21:56:25 +04:00 committed by GitHub
parent 9ca77a1dc5
commit 82d2fd63ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -13,7 +13,7 @@ from cyclonedds.util import duration
from cyclonedds.internal import dds_c_t, InvalidSample
# for channel config
from .channel_config import ChannelConfigAutoDetermine, ChannelConfigHasInterface
from .channel_config import ChannelConfigAutoDetermine, ChannelConfigHasInterface, ChannelConfigHasIP
# for singleton
from ..utils.singleton import Singleton
@ -201,7 +201,12 @@ class ChannelFactory(Singleton):
if networkInterface is None:
config = ChannelConfigAutoDetermine
else:
config = ChannelConfigHasInterface.replace('$__IF_NAME__$', networkInterface)
if "." in networkInterface: # connect using IP
config = ChannelConfigHasIP.replace('$__IF_IP__$', networkInterface)
print(f"connecting using IP: {networkInterface}")
else: # connect using Iface
config = ChannelConfigHasInterface.replace('$__IF_NAME__$', networkInterface)
print(f"connecting using Iface: {networkInterface}")
try:
self.__domain = Domain(id, config)