Skip to content

Commit 6deed44

Browse files
committed
working on xml parser
1 parent 1931a46 commit 6deed44

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

eg8/dev1/dds_update/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
FROM python:3
22

3+
RUN mkdir /dds
4+
COPY ./cyclonedds.xml /dds
35
WORKDIR /usr/src/app
46

57
COPY requirements.txt ./
68
RUN pip install --no-cache-dir -r requirements.txt
79

8-
COPY . .
10+
COPY ./dds_xml_updater.py .
911

1012
CMD [ "python", "./dds_xml_updater.py" ]

eg8/dev1/dds_update/cyclonedds.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<CycloneDDS xmlns="https://cdds.io/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://cdds.io/config https://raw.githubusercontent.com/eclipse-cyclonedds/cyclonedds/master/etc/cyclonedds.xsd">
3+
<Domain id="any">
4+
<General>
5+
<NetworkInterfaceAddress>auto</NetworkInterfaceAddress>
6+
<AllowMulticast>false</AllowMulticast>
7+
<MaxMessageSize>65500B</MaxMessageSize>
8+
<FragmentSize>4000B</FragmentSize>
9+
<Transport>udp6</Transport>
10+
</General>
11+
<Discovery>
12+
<Peers>
13+
<Peer address="turtle-controller-1"/>
14+
<!-- <Peer address="[IPv6 addr]"/> -->
15+
</Peers>
16+
<ParticipantIndex>auto</ParticipantIndex>
17+
</Discovery>
18+
<Internal>
19+
<Watermarks>
20+
<WhcHigh>500kB</WhcHigh>
21+
</Watermarks>
22+
</Internal>
23+
<Tracing>
24+
<Verbosity>severe</Verbosity>
25+
<OutputFile>stdout</OutputFile>
26+
</Tracing>
27+
</Domain>
28+
</CycloneDDS>
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
import os
12
import time
3+
import xml.etree.ElementTree as ET
4+
25
print("Hello World!")
36

7+
tree = ET.parse(os.path.join('/dds', 'cyclonedds.xml'))
8+
root = tree.getroot()
49

10+
for peer in root.findall('.//{https://cdds.io/config}Peer'):
11+
print(peer.tag, peer.attrib)
12+
print(peer.attrib['address'])
13+
514
while True:
615
time.sleep(2)
16+
17+
# remove all Peers from xml
18+
for peer in root.findall('.//{https://cdds.io/config}Peer'):
19+
root.remove(peer)
20+
721
hosts = open('/etc/hosts','r')
822
for line in hosts:
9-
print(line.split()[1:])
23+
if(line.split()[2:6] == ['#', 'managed', 'by', 'Husarnet']):
24+
print(line.split()[0]) # Husarnet IPv6 address
25+
print(line.split()[1]) # Husarnet Hostname
26+
ET.SubElement('.//{https://cdds.io/config}Peers', 'Peer', address=line.split()[0])

eg8/dev1/docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
dds_updater:
55
build: dds_update/.
66
volumes:
7-
- shared_cyclonedds_xml:/cyclonedds.xml
7+
- shared_cyclonedds_xml:/dds
88
network_mode: service:husarnet
99
stdin_open: true # docker run -i
1010
tty: true # docker run -t
@@ -14,13 +14,13 @@ services:
1414
context: ../../
1515
dockerfile: eg8/dev1/Dockerfile
1616
volumes:
17-
- shared_cyclonedds_xml:/cyclonedds.xml
17+
- shared_cyclonedds_xml:/dds
1818
command:
1919
- bash
2020
- -c
2121
- |
2222
source /ros2_ws/install/setup.bash
23-
export CYCLONEDDS_URI=file:///cyclonedds.xml
23+
export CYCLONEDDS_URI=file:///dds/cyclonedds.xml
2424
ros2 run my_demo_pkg color_controller
2525
network_mode: service:husarnet
2626

@@ -29,13 +29,13 @@ services:
2929
context: ../../
3030
dockerfile: eg8/dev1/Dockerfile
3131
volumes:
32-
- shared_cyclonedds_xml:/cyclonedds.xml
32+
- shared_cyclonedds_xml:/dds
3333
command:
3434
- bash
3535
- -c
3636
- |
3737
source /ros2_ws/install/setup.bash
38-
export CYCLONEDDS_URI=file:///cyclonedds.xml
38+
export CYCLONEDDS_URI=file:///dds/cyclonedds.xml
3939
ros2 run my_demo_pkg move_controller
4040
network_mode: service:husarnet
4141

0 commit comments

Comments
 (0)