-
Notifications
You must be signed in to change notification settings - Fork 18
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
4 changed files
with
140 additions
and
27 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import sys | ||
import time | ||
import traceback | ||
import random | ||
|
||
import dds | ||
|
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,38 @@ | ||
from twisted.internet import main, reactor | ||
from twisted.python import failure | ||
|
||
import dds | ||
|
||
class DDSTransport(object): | ||
def __init__(self, topic, protocol): | ||
self.topic = topic | ||
self.protocol = protocol | ||
|
||
def connect(self): | ||
self._cb_ref = self.topic.add_data_available_callback(self._data_available_callback) | ||
self.protocol.transport = self | ||
self.protocol.connectionMade() | ||
|
||
def send(self, msg): | ||
self.topic.send(msg) | ||
|
||
def _data_available_callback(self): | ||
reactor.callFromThread(self._data_available_callback2) | ||
|
||
def _data_available_callback2(self): | ||
while True: | ||
try: | ||
msg = self.topic.recv() | ||
except dds.Error, e: | ||
if e.message == 'no data': | ||
break | ||
raise | ||
else: | ||
self.protocol.messageReceived(msg) | ||
|
||
def loseConnection(self): | ||
self.topic.remove_data_available_callback(self._cb_ref) | ||
self.protocol.connectionLost(failure.Failure(main.CONNECTION_DONE)) | ||
|
||
def connectDDS(topic, protocol): | ||
DDSTransport(topic, protocol).connect() |
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,18 @@ | ||
from twisted.internet import reactor | ||
|
||
import dds | ||
import twistedds | ||
|
||
class TestProtocol(object): | ||
def connectionMade(self): | ||
print 'connection made!' | ||
|
||
def messageReceived(self, msg): | ||
print 'message received:', msg | ||
|
||
def connectionLost(self, reason): | ||
print 'connection lost! reason:', reason | ||
|
||
twistedds.connectDDS(dds.DDS().get_topic('t2', dds.Library('./libddsmessages_c.so').HydrophoneMessage), TestProtocol()) | ||
|
||
reactor.run() |