Skip to content

Commit 5807c0c

Browse files
committed
added listener example
1 parent 0634056 commit 5807c0c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ RUN apt-get update && apt-get install -y \
1919
python-dev \
2020
unzip \
2121
net-tools \
22+
nano \
2223
# clean the apt cache
2324
&& rm -rf /var/lib/apt/lists/*
2425

@@ -41,3 +42,4 @@ RUN echo 'net.core.rmem_default=10485760' >> /etc/sysctl.conf
4142
# copy, then build examples
4243
COPY assets/examples /root/examples
4344
RUN cd /root/examples/publisher; lcm-gen -p example_t.lcm
45+
RUN cd /root/examples/listener; lcm-gen -p example_t.lcm
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package exlcm;
2+
struct example_t
3+
{
4+
int64_t timestamp;
5+
string name;
6+
boolean enabled;
7+
}

assets/examples/listener/main.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import lcm
2+
from exlcm import example_t
3+
4+
5+
def handler(channel, data):
6+
msg = example_t.decode(data)
7+
print 'Received msg: (%d, %s, %r)' % (msg.timestamp, msg.name, msg.enabled)
8+
9+
10+
lc = lcm.LCM()
11+
lc.subscribe("EXAMPLE", handler)
12+
13+
try:
14+
while True:
15+
lc.handle()
16+
except KeyboardInterrupt:
17+
pass

0 commit comments

Comments
 (0)