Skip to content

Commit 9f9570d

Browse files
committed
More PABB2 iteration.
1 parent ba3efb9 commit 9f9570d

15 files changed

Lines changed: 158 additions & 126 deletions

Common/PABotBase2/PABotBase2CC_MessageDumper.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,17 @@ MessageLogger::MessageLogger(){
373373
return str;
374374
}
375375
);
376+
add_message<Message_u32>(
377+
"PABB2_MESSAGE_OPCODE_SET_LOGGING_FLAG",
378+
PABB2_MESSAGE_OPCODE_SET_LOGGING_FLAG,
379+
true,
380+
[](const Message_u32* message){
381+
std::string str;
382+
str += "id = " + std::to_string(message->id);
383+
str += ", flag = " + tostr_hex(message->data);
384+
return str;
385+
}
386+
);
376387
add_message<MessageHeader>(
377388
"PABB2_MESSAGE_OPCODE_CQ_CAPACITY",
378389
PABB2_MESSAGE_OPCODE_CQ_CAPACITY,

Common/PABotBase2/ReliableConnectionLayer/PABotBase2FW_ReliableStreamConnection.cpp

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "PABotBase2_ConnectionDebug.h"
1010
#include "PABotBase2FW_ReliableStreamConnection.h"
1111

12+
#ifdef PABB2_SUPPORTS_PRINTF_LOGGING
13+
#include <stdio.h>
14+
#endif
15+
1216
//#include <iostream>
1317
//using std::cout;
1418
//using std::endl;
@@ -35,6 +39,9 @@ ReliableStreamConnectionFW::ReliableStreamConnectionFW(UnreliableStreamConnectio
3539
bool ReliableStreamConnectionFW::enqueue_uncommitted_reliable_sends(const void* data, size_t bytes) noexcept{
3640
if (!m_stream_ready){
3741
m_reliable_sender.send_oob_packet_empty(0, PABB2_CONNECTION_OPCODE_INFO_STREAM_NOT_READY);
42+
#ifdef PABB2_SUPPORTS_PRINTF_LOGGING
43+
printf("Stream not ready...\n");
44+
#endif
3845
return false;
3946
}
4047
if (m_reliable_sender.enqueue_uncommitted_send_stream(data, bytes)){
@@ -44,6 +51,9 @@ bool ReliableStreamConnectionFW::enqueue_uncommitted_reliable_sends(const void*
4451
if (!m_send_is_currently_full){
4552
m_send_is_currently_full = true;
4653
m_reliable_sender.send_oob_packet_empty(0, PABB2_CONNECTION_OPCODE_INFO_STREAM_SEND_FULL);
54+
#ifdef PABB2_SUPPORTS_PRINTF_LOGGING
55+
printf("Send stream is full...\n");
56+
#endif
4757
}
4858
return false;
4959
}
@@ -103,28 +113,28 @@ bool ReliableStreamConnectionFW::run_recv_events(const WallDuration& timeout){
103113
? POLL_RATE
104114
: timeout;
105115

106-
const PacketHeader* packet = m_parser.pull_bytes(m_unreliable_connection, adjusted_timeout);
107-
if (packet == nullptr){
116+
const PacketHeader* header = m_parser.pull_bytes(m_unreliable_connection, adjusted_timeout);
117+
if (header == nullptr){
108118
return false;
109119
}
110120

111121
m_packets_received++;
112122

113123
// Check the packet status.
114-
switch (packet->magic_number){
124+
switch (header->magic_number){
115125
case PABB2_PacketParser_RESULT_VALID:
116126
break;
117127
case PABB2_PacketParser_RESULT_INVALID:
118128
// printf("PABB2_PacketParser_RESULT_INVALID\n");
119129
m_reliable_sender.send_oob_packet_empty(
120-
packet->seqnum,
130+
header->seqnum,
121131
PABB2_CONNECTION_OPCODE_INVALID_LENGTH
122132
);
123133
return true;
124134
case PABB2_PacketParser_RESULT_CHECKSUM_FAIL:
125135
// printf("PABB2_PacketParser_RESULT_CHECKSUM_FAIL\n");
126136
m_reliable_sender.send_oob_packet_empty(
127-
packet->seqnum,
137+
header->seqnum,
128138
PABB2_CONNECTION_OPCODE_INVALID_CHECKSUM_FAIL
129139
);
130140
// cout << "CRC error:";
@@ -138,74 +148,76 @@ bool ReliableStreamConnectionFW::run_recv_events(const WallDuration& timeout){
138148
// printf("Device Received: %d\n", packet->opcode);
139149

140150
// Now handle the different opcodes.
141-
uint8_t opcode = packet->opcode & PABB2_CONNECTION_OPCODE_MASK;
151+
uint8_t opcode = header->opcode & PABB2_CONNECTION_OPCODE_MASK;
142152
switch (opcode){
143153
case PABB2_CONNECTION_OPCODE_ASK_RESET:
144-
m_reliable_sender.send_oob_packet_empty(
145-
packet->seqnum,
146-
PABB2_CONNECTION_OPCODE_RET_RESET
147-
);
154+
m_stream_ready = false;
155+
m_send_is_currently_full = false;
148156
m_reliable_sender.reset();
149157
m_parser.reset();
150158
m_stream_coalescer.reset();
151159
m_stream_coalescer.push_packet(0);
160+
m_reliable_sender.send_oob_packet_empty(
161+
header->seqnum,
162+
PABB2_CONNECTION_OPCODE_RET_RESET
163+
);
152164
#ifdef PABB2_ENABLE
153165
issue_reset_to_all();
154166
#endif
155-
m_stream_ready = false;
156167
return true;
157168
case PABB2_CONNECTION_OPCODE_ASK_VERSION:
158-
m_stream_coalescer.push_packet(packet->seqnum);
169+
m_stream_coalescer.push_packet(header->seqnum);
159170
m_reliable_sender.send_oob_packet_u32(
160-
packet->seqnum,
171+
header->seqnum,
161172
PABB2_CONNECTION_OPCODE_RET_VERSION,
162173
PABB2_CONNECTION_PROTOCOL_VERSION
163174
);
164175
return true;
165176
case PABB2_CONNECTION_OPCODE_ASK_PACKET_SIZE:
166-
m_stream_coalescer.push_packet(packet->seqnum);
177+
m_stream_coalescer.push_packet(header->seqnum);
167178
m_reliable_sender.send_oob_packet_u16(
168-
packet->seqnum,
179+
header->seqnum,
169180
PABB2_CONNECTION_OPCODE_RET_PACKET_SIZE,
170181
PABB2_MAX_INCOMING_PACKET_SIZE
171182
);
172183
return true;
173184
case PABB2_CONNECTION_OPCODE_ASK_BUFFER_SLOTS:
174-
m_stream_coalescer.push_packet(packet->seqnum);
185+
m_stream_coalescer.push_packet(header->seqnum);
175186
m_reliable_sender.send_oob_packet_u8(
176-
packet->seqnum,
187+
header->seqnum,
177188
PABB2_CONNECTION_OPCODE_RET_BUFFER_SLOTS,
178189
PABB2_StreamCoalescer_SLOTS
179190
);
180191
return true;
181192
case PABB2_CONNECTION_OPCODE_ASK_BUFFER_BYTES:
182-
m_stream_coalescer.push_packet(packet->seqnum);
193+
m_stream_coalescer.push_packet(header->seqnum);
183194
m_reliable_sender.send_oob_packet_u16(
184-
packet->seqnum,
195+
header->seqnum,
185196
PABB2_CONNECTION_OPCODE_RET_BUFFER_BYTES,
186197
PABB2_StreamCoalescer_BUFFER_SIZE
187198
);
188199
return true;
200+
189201
case PABB2_CONNECTION_OPCODE_ASK_STREAM_DATA:
190202
m_stream_ready = true;
191-
if (!m_stream_coalescer.push_stream((const PacketHeaderData*)packet)){
203+
if (!m_stream_coalescer.push_stream((const PacketHeaderData*)header)){
192204
send_oob_info_label_u32("Push Stream Failed", m_stream_coalescer.free_bytes());
193205
return true;
194206
}
195207
m_reliable_sender.send_oob_packet_u16(
196-
packet->seqnum,
208+
header->seqnum,
197209
PABB2_CONNECTION_OPCODE_RET_STREAM_DATA,
198210
m_stream_coalescer.free_bytes()
199211
);
200212
return true;
201213
case PABB2_CONNECTION_OPCODE_RET_STREAM_DATA:
202-
m_reliable_sender.remove(packet->seqnum);
214+
m_reliable_sender.remove(header->seqnum);
203215
return true;
204216
default:
205217
m_reliable_sender.send_oob_packet_u8(
206-
packet->seqnum,
218+
header->seqnum,
207219
PABB2_CONNECTION_OPCODE_UNKNOWN_OPCODE,
208-
packet->opcode
220+
header->opcode
209221
);
210222
}
211223

Common/PABotBase2/ReliableConnectionLayer/PABotBase2FW_ReliableStreamConnection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ReliableStreamConnectionFW final
4444
return m_reliable_sender.slots_used() != 0;
4545
}
4646

47+
4748
public:
4849
virtual bool enqueue_uncommitted_reliable_sends(const void* data, size_t bytes) noexcept override;
4950
virtual void abort_uncommitted_reliable_sends() noexcept override;

Common/PABotBase2/ReliableConnectionLayer/PABotBase2_ConnectionDebug.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ void StreamCoalescer::print(bool ascii) const{
132132
std::cout << "---- StreamCoalescer ---- (Start)" << std::endl;
133133
std::cout << "Slot Head: " << (int)m_slot_head << std::endl;
134134
std::cout << "Slot Tail: " << (int)m_slot_tail << std::endl;
135+
std::cout << "Stream Free: " << m_stream_free << std::endl;
135136
std::cout << "Stream Head: " << m_stream_head << std::endl;
136137
std::cout << "Stream Tail: " << m_stream_tail << std::endl;
137138
for (uint8_t seqnum = m_slot_head; seqnum != m_slot_tail; seqnum++){
@@ -142,13 +143,13 @@ void StreamCoalescer::print(bool ascii) const{
142143
std::cout << std::endl;
143144
continue;
144145
}
145-
if (size == 255){
146+
if (size == 0xff){
146147
std::cout << " non-stream" << std::endl;
147148
continue;
148149
}
149150

150-
uint16_t offset_s = m_offsets[index];
151-
uint16_t offset_e = offset_s + size;
151+
uint16_t offset_e = m_end_offsets[index];
152+
uint16_t offset_s = offset_e - size;
152153
std::cout << "[" << offset_s << ":" << offset_e << "] => ";
153154

154155
offset_s &= BUFFER_MASK;

Common/PABotBase2/ReliableConnectionLayer/PABotBase2_PacketSender.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ bool PacketSender::remove(uint8_t seqnum){
139139
// cout << "PacketSender::remove(" << this << "): " << (int)seqnum << endl;
140140
// }
141141

142-
// Seqnum is out of range.
142+
// Too far in the future.
143143
if ((uint8_t)(seqnum - m_slot_head) >= SLOTS){
144144
return false;
145145
}
146+
147+
// Too far in the past.
146148
if ((uint8_t)(m_slot_tail - seqnum) > SLOTS){
147149
return false;
148150
}

0 commit comments

Comments
 (0)