Skip to content

Commit 06c42bc

Browse files
committed
merged with rtcan transport
1 parent 83320b0 commit 06c42bc

12 files changed

+224
-123
lines changed

DebugTransport.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class DebugTransport : public Transport {
5353
private:
5454
RemotePublisher *create_publisher(Topic &topic) const;
5555
RemoteSubscriber *create_subscriber(
56+
Topic &topic,
5657
Transport &transport,
5758
TimestampedMsgPtrQueue::Entry queue_buf[],
5859
size_t queue_length
@@ -120,10 +121,12 @@ RemotePublisher *DebugTransport::create_publisher(Topic &topic) const {
120121

121122
inline
122123
RemoteSubscriber *DebugTransport::create_subscriber(
124+
Topic &topic,
123125
Transport &transport,
124126
TimestampedMsgPtrQueue::Entry queue_buf[],
125127
size_t queue_length) const {
126128

129+
(void)topic;
127130
return new DebugSubscriber(static_cast<DebugTransport &>(transport),
128131
queue_buf, queue_length);
129132
}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ ifeq ($(TEST),rtcan_sub_test)
110110
chnew.cpp main_rtcan_sub_test.cpp
111111
endif
112112

113+
ifeq ($(TEST),pubsub_test)
114+
CPPSRC += main_pubsub_test.cpp chnew.cpp
115+
endif
116+
113117
ifeq ($(TEST),)
114118
CPPSRC += DebugTransport.cpp DebugPublisher.cpp DebugSubscriber.cpp \
115119
main.cpp chnew.cpp

RTCANSubscriber.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ RTCANSubscriber::RTCANSubscriber(RTCANTransport &transport,
4747
size_t queue_length)
4848
:
4949
RemoteSubscriber(transport),
50-
queue_free(queue_length),
51-
rtcan_id(111 << 8)
50+
queue_free(queue_length)
5251
{}
5352

5453

RTCANTransport.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bool RTCANTransport::send_advertisement(const Topic &topic) {
7777
adv_tx_msg.type = 'P';
7878
adv_tx_msg.queue_length = 0;
7979
::strncpy(adv_tx_msg.topic, topic.get_name(), NamingTraits<Topic>::MAX_LENGTH);
80-
adv_tx_msg.rtcan_id = 111 << 8; // FIXME the transport-dependent id comes from the rsub, should we move to send_advertisement(rsub *) ?
80+
adv_tx_msg.rtcan_id = topic_id(topic.get_name()); // FIXME the transport-dependent id comes from the rsub, should we move to send_advertisement(rsub *) ?
8181

8282
return send_adv_msg(adv_tx_msg);
8383
}
@@ -172,7 +172,7 @@ void RTCANTransport::initialize(const RTCANConfig &rtcan_config) {
172172

173173
RemotePublisher *RTCANTransport::create_publisher(Topic &topic) const {
174174
RTCANPublisher * rpubp = new RTCANPublisher();
175-
rpubp->rtcan_header.id = 111 << 8; //FIXME
175+
rpubp->rtcan_header.id = topic_id(topic.get_name());
176176
rpubp->rtcan_header.callback = reinterpret_cast<rtcan_msgcallback_t>(recv_cb);
177177
rpubp->rtcan_header.params = rpubp;
178178
rpubp->rtcan_header.size = 4; // FIXME
@@ -184,11 +184,27 @@ RemotePublisher *RTCANTransport::create_publisher(Topic &topic) const {
184184

185185

186186
RemoteSubscriber *RTCANTransport::create_subscriber(
187+
Topic &topic,
187188
Transport &transport,
188189
TimestampedMsgPtrQueue::Entry queue_buf[],
189190
size_t queue_length) const {
191+
RTCANSubscriber * rsubp = new RTCANSubscriber(static_cast<RTCANTransport &>(transport), queue_buf, queue_length);
190192

191-
return new RTCANSubscriber(static_cast<RTCANTransport &>(transport), queue_buf, queue_length);
193+
rsubp->rtcan_id = topic_id(topic.get_name());
194+
195+
return rsubp;
196+
}
197+
198+
// FIXME: to implement
199+
rtcan_id_t RTCANTransport::topic_id(const char * namep) const {
200+
if (strcmp(namep, "led2") == 0)
201+
return 112 << 8;
202+
if (strcmp(namep, "led3") == 0)
203+
return 113 << 8;
204+
if (strcmp(namep, "ledall") == 0)
205+
return 114 << 8;
206+
207+
return 255 << 8;
192208
}
193209

194210
/*

RTCANTransport.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ class RTCANTransport : public Transport {
5454
bool send_reboot();
5555
bool send(Message * msgp, RTCANSubscriber * rsubp);
5656

57+
rtcan_id_t topic_id(const char * namep) const; // FIXME
58+
5759
void initialize(const RTCANConfig &rtcan_config);
5860

5961
private:
6062
bool send_adv_msg(const adv_msg_t &adv_msg);
6163
void recv_adv_msg(const adv_msg_t &adv_msg);
6264
RemotePublisher *create_publisher(Topic &topic) const;
6365
RemoteSubscriber *create_subscriber(
66+
Topic &topic,
6467
Transport &transport,
6568
TimestampedMsgPtrQueue::Entry queue_buf[], // TODO: remove
6669
size_t queue_length

0 commit comments

Comments
 (0)