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
3539bool 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
0 commit comments