@@ -63,6 +63,14 @@ bool CommandInterface::hasNewCommands(){
6363 return parserReady;
6464}
6565
66+ /* *
67+ * Returns true if it can send replies.
68+ * False if the command thread should wait until previous replies are processed
69+ */
70+ bool CommandInterface::readyToSend (){
71+ return true ;
72+ }
73+
6674
6775/*
6876 *
@@ -88,6 +96,10 @@ bool StringCommandInterface::addBuf(char* Buf, uint32_t *Len){
8896 return res;
8997}
9098
99+ uint32_t StringCommandInterface::bufferCapacity (){
100+ return parser.bufferCapacity ();
101+ }
102+
91103void StringCommandInterface::formatReply (std::string& reply,const std::vector<CommandResult>& results,const bool formatWriteAsRead){
92104 // uint16_t lastId = 0xFFFF;
93105 for (const CommandResult& result : results){ // All commands processed this batch
@@ -214,16 +226,24 @@ CDC_CommandInterface::~CDC_CommandInterface() {
214226
215227
216228void CDC_CommandInterface::sendReplies (std::vector<CommandResult>& results,CommandInterface* originalInterface){
217- if ( (!enableBroadcastFromOtherInterfaces && originalInterface != this ) || ! tud_ready () ){
229+ if ( (!enableBroadcastFromOtherInterfaces && originalInterface != this ) ){
218230 return ;
219231 }
232+
220233 std::string replystr;
221234 replystr.reserve (100 );
222235 StringCommandInterface::formatReply (replystr,results, originalInterface != this && originalInterface != nullptr );
223236 if (!replystr.empty ())
224237 CDCcomm::cdcSend (&replystr, 0 );
225238}
226239
240+ /* *
241+ * Ready to send if there is no data in the backup buffer of the cdc port
242+ */
243+ bool CDC_CommandInterface::readyToSend (){
244+ return CDCcomm::remainingData (0 ) == 0 ;
245+ }
246+
227247
228248
229249/* ************************
@@ -233,7 +253,6 @@ void CDC_CommandInterface::sendReplies(std::vector<CommandResult>& results,Comma
233253 *
234254 */
235255
236-
237256extern UARTPort external_uart; // defined in cpp_target_config.cpp
238257UART_CommandInterface::UART_CommandInterface (uint32_t baud) : StringCommandInterface(128 ), UARTDevice(external_uart),Thread(" UARTCMD" , 256 , 36 ), baud(baud){ //
239258 uartconfig = uartport->getConfig ();
@@ -280,7 +299,7 @@ void UART_CommandInterface::Run(){
280299// }
281300
282301void UART_CommandInterface::sendReplies (std::vector<CommandResult>& results,CommandInterface* originalInterface){
283- if ( (!enableBroadcastFromOtherInterfaces && originalInterface != this ) || ! tud_ready () ){
302+ if ( (!enableBroadcastFromOtherInterfaces && originalInterface != this ) ){
284303 return ;
285304 }
286305
@@ -297,7 +316,7 @@ void UART_CommandInterface::sendReplies(std::vector<CommandResult>& results,Comm
297316void UART_CommandInterface::uartRcv (char & buf){
298317 uint32_t len = 1 ;
299318 BaseType_t savedInterruptStatus = cpp_freertos::CriticalSection::EnterFromISR ();
300- if (this ->parser .bufferCapacity () > len) // Check buffer because we can't allocate more memory inside the ISR safely at the moment
319+ if (this ->parser .bufferCapacity () > ( int32_t ) len) // Check buffer because we can't allocate more memory inside the ISR safely at the moment
301320 StringCommandInterface::addBuf (&buf, &len);
302321 cpp_freertos::CriticalSection::ExitFromISR (savedInterruptStatus);
303322}
0 commit comments