ERIS CORE

◆ messageHandler_LS()

void FLASHMEM SvcSerialCommandInterface::messageHandler_LS ( )
protected

Definition at line 571 of file svcSerialCommandInterface.cpp.

571  {
572  bool first;
573  int total_read;
574  char cmd[128], param[128],param2[128];
575  total_read = sscanf(p_received_chars, "%127s %127s %127s" , cmd, param,param2);
576  while(Serial.availableForWrite() < 6000){
577  delay(20);
578  }
579  if (total_read < 2){
580  //send the root directory
581  //delay(100);
582  empty();
583  println(F("DIR"));
584  print(F("LS . ["));
585 #ifdef USE_EXTMEM
586  //do nothing - one time malloc in the constructor
587 #else
588  workingBuffer = (char*)malloc(SERIAL_WORKING_BUFFER_SIZE);
589 #endif
591  empty();
592  Serial.print(p_working_buffer);
593  sd->chdir();
594  tx_buffer_overflow_flag = false;
595  sd->ls(this);
596  memset(p_working_buffer,0,SERIAL_WORKING_BUFFER_SIZE);
598  empty();
599  first = true;
600  token = strtok(p_working_buffer, &newline);
601  while( token != NULL ) {
602  if (first && !tx_buffer_overflow_flag) Serial.print(F("\""));
603  else Serial.print(F(",\""));
604  Serial.print(token);
605  Serial.print(F("\""));
606  token = strtok(NULL, &newline);
607  first = false;
608  }
609  Serial.println(F("]"));
610  Serial.println(F("DIR_EOF"));
611 #ifdef USE_EXTMEM
612  //do nothing - one time malloc in the constructor
613 #else
614  free(workingBuffer);
615 #endif
616  //delay(200);
617  } else{
618  //send the requested path
619  replacechar(param,':',' '); //replace space token used to tx the path
620  empty();
621  print(F("M "));
622  println(param);
623  println(F("DIR"));
624  send();
625  sd->chdir();
626  replacechar(param,' ',':'); //replace any spaces in the transmitted path to ':'
627  sprintf(p_multipart_header, "LS %s [", param);
628  Serial.print(p_multipart_header);
629  replacechar(param,':',' '); // put the spaces back in time for the ls command
630  sd->ls(this,param,false);
631  first = true;
632  token = strtok(p_tx_Buffer, &newline);
633  while( token != NULL && index_tx_buffer > 1) {
634  if (first && !tx_buffer_overflow_flag) Serial.print(F("\""));
635  else Serial.print(F(",\""));
636  replacechar(token,'\r',0);
637  Serial.print(token);
638  Serial.print(F("\""));
639  token = strtok(NULL, &newline);
640  first = false;
641  while(throttle()){
642  delay(50);
643  }
644  }
645  Serial.println(F("]"));
646  Serial.println(F("DIR_EOF"));
647  }
648 }
bool throttle()
returns true if the available serial buffer falls below SERIAL_THROTTLE_BUFFER_REMAINING_THRESHOLD if...
void send()
immediately transmit then clear the txBuffer
void empty()
zero out the transmit buffer and reset the write index
const char newline
int FLASHMEM replacechar(char *str, char orig, char rep)

References empty(), index_tx_buffer, newline, p_multipart_header, p_received_chars, p_tx_Buffer, p_working_buffer, replacechar(), AppBaseClass::sd, send(), throttle(), token, and tx_buffer_overflow_flag.

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: