ERIS CORE

◆ update()

void FLASHMEM SvcSerialCommandInterface::update ( void  )
overrideprotectedvirtual

update loop

Reimplemented from AppBaseClass.

Definition at line 650 of file svcSerialCommandInterface.cpp.

650  {
651  char endMarker = '\n';
652  boolean newRxMsg = false;
653  char bufferChr;
654 
655  if (is_streaming_file){ //streaming file handler
657  }
658 
659  if(is_capturing_bulk_data){ //bulk data state handler
661  }else { //check for incoming data
662  //This is the incoming message handler - it collects the message one byte at a time until
663  //the end of message marker. If a full message is received the newRxMsg flag is set true.
664  //if a partial message is received the flag remains false.
665  //if the receiving buffer reaches an overflow condition, reset the buffer and clear in remaining serial input
666  if (Serial.available() > 0 && false == newRxMsg ){
667  do{
668  bufferChr = Serial.read();
669  p_received_chars[index_rx_buffer++] = bufferChr;
670 
671  if(index_rx_buffer >= (SERIAL_RX_BUFFER_SIZE-2)){
672  //input overflow - clear serial input and reset the index
673  index_rx_buffer = 0;
674  Serial.clear();
675  Serial.clearReadError();
676  return;
677  }
678 
679  if (bufferChr == endMarker){
680  p_received_chars[--index_rx_buffer] = '\0'; //remove the end marker and null terminate the string
681  index_rx_buffer = 0; //reset the input write index
682  newRxMsg = true;
683  }
684  } while (Serial.available() > 0 && false == newRxMsg);
685  }
686  if (newRxMsg){
687  //Once a new message is received, first the command is parsed out from the message
688  // this first split into cmd and param is for the purpose of identifying the requested command
689  // each individual message handler is then responsible for parsing out their own parameters if required.
690  char cmd[128], param[128],param2[128];
691  int total_read;
692  total_read = sscanf(p_received_chars, "%127s %127s" , cmd, param);
693  while(throttle()){delay(10);}; //let the transmitt buffer clear out
694  if (strncmp(cmd, "LS",sizeof(cmd)) == 0){
696  }else if (strncmp(cmd, "GET",sizeof(cmd)) == 0){
698  }else if (strncmp(cmd, "ACON",sizeof(cmd)) == 0){ //audio connections
699  uint16_t i;
700  char csBuffer[128];
701  i = 0;
702  Serial.println(F("M ACON START"));
703 
704  while(ad->getConnectionString(i,csBuffer)){
705  i += 1;
706  Serial.print("M ");
707  Serial.println(csBuffer);
708  }
709  Serial.println(F("M ACON END"));
710 
711  }else if (strncmp(cmd, "CONNECT",sizeof(cmd)) == 0){
712  int source_port;
713  int dest_port;
714 
715  total_read = sscanf(p_received_chars, "%127s %127s %d %127s %d" , cmd, param,&source_port,param2,&dest_port);
716  if (total_read < 3){
717  Serial.print(F("M CONNECT WRONG PARAM COUNT "));
718  Serial.println(p_received_chars);
719  } else{
720  ad->connect(param,source_port,param2,dest_port);
721  }
722  }else if (strncmp(cmd, "DISCONNECT",sizeof(cmd)) == 0){
723  int dest_port;
724  total_read = sscanf(p_received_chars, "%127s %127s %d" , cmd, param,&dest_port);
725  if (total_read < 2){
726  Serial.print(F("M DISCONNECT WRONG PARAM COUNT "));
727  Serial.println(p_received_chars);
728  } else{
729  if (ad->disconnect(param,dest_port)){
730  Serial.printf(F("M DISCONNECTED %s %d\n"),param,dest_port);
731  }else{
732  Serial.printf(F("M FAILED DISCONNECT OF %s %d\n"),param,dest_port);
733  }
734  }
735  }else if (strncmp(cmd, "AA",sizeof(cmd)) == 0){ //active app message
736  if (total_read > 1) am->getActiveApp()->messageHandler(this,param);
737  }else if (strncmp(cmd, "APC",sizeof(cmd)) == 0){
738  //forward the message to the SvcErisAudioParameterController
739  am->getAppByName("APC")->messageHandler(this,p_received_chars + 4);
740  }else if (strncmp(cmd, "STATS",sizeof(cmd)) == 0){
741  ad->printStats();
742  while(throttle()){delay(1);}
743  am->printStats();
744  }else if (strncmp(cmd, "CQT_CFG",sizeof(cmd)) == 0){
745  am->sendMessage(this,"AppCQT","CQT_INFO");
746  }else if (strncmp(cmd, "GET_DD",sizeof(cmd)) == 0){
747  am->data->printDictionary(this);
748  }else if (strncmp(cmd, "GET_WREN_SCRIPT",sizeof(cmd)) == 0){
749  while(throttle()){delay(100);}
751  println("#WREN_START!");
752  println(g_wrenScript);
753  println("#WREN_EOF!");
754  sendLZ4Message();
755  }
756  }else if (strncmp(cmd, "WREN_SCRIPT_START",sizeof(cmd)) == 0){
758  }else if (strncmp(cmd, "WREN_SCRIPT_COMPILE",sizeof(cmd)) == 0){
760  }else if (strncmp(cmd, "WREN_SCRIPT_EXECUTE",sizeof(cmd)) == 0){
762  }else if (strncmp(cmd, "WREN_SCRIPT_SAVE",sizeof(cmd)) == 0){
764  }else if (strncmp(cmd, "UPDATE_DD",sizeof(cmd)) == 0){
766  }else if (strncmp(cmd, "HELO",sizeof(cmd)) == 0){
768  println(gWelcomeMessage);
769  sendLZ4Message();
770  }
771  }else if (strncmp(cmd, "GET_RAM",sizeof(cmd)) == 0){
772  char* mp;
773  long num;
774  num = strtol(param,NULL,10);
775  mp = (char*)num;
776  Serial.printf("M GET_RAM {\"addr\":\"%08X\",\"data\":\"%02X\"}\n",num,(uint8_t)*mp);
777  }else if (strncmp(cmd, "GET_RAM2",sizeof(cmd)) == 0){
779  }else if (strncmp(cmd, "GET_RAM1",sizeof(cmd)) == 0){
781  }else if (strncmp(cmd, "AUDIO_NO_INTERRUPTS",sizeof(cmd)) == 0){
782  AudioNoInterrupts();
783  }else if (strncmp(cmd, "AUDIO_INTERRUPTS",sizeof(cmd)) == 0){
784  AudioInterrupts();
785  }
786  //END
787  newRxMsg = false;
788 
789  #ifdef SERIAL_AUTO_TRANSMIT_DATA_PERIODICALLY
791  if (et_since_periodic_stats_tx > SERIAL_AUTO_TRANSMIT_STATS_PERIOD){
794  ad->printStats();
795  }else if (et_since_periodic_data_dict_tx > SERIAL_AUTO_TRANSMIT_DATA_DICT_PERIOD){
798  }
799  }
800  #else
801  }
802  #endif
803  }
AppManager * am
Definition: AppBaseClass.h:38
AudioDirector * ad
Definition: AppBaseClass.h:37
virtual void messageHandler(AppBaseClass *sender, const char *message)
receiver method for inter-app string based communication
Definition: AppBaseClass.h:248
AppBaseClass * getAppByName(const char *appName)
Get the App pointer By Name. Returns NULL if not found.
Definition: AppManager.cpp:489
SvcDataDictionary * data
Definition: AppManager.h:63
bool sendMessage(AppBaseClass *sender, const char *to_app, const char *message)
provides an interface for apps to send messages to other apps
Definition: AppManager.cpp:469
static AppManager * getInstance()
Definition: AppManager.h:66
void printStats()
prints out some stats in JSON format to the serial port
Definition: AppManager.cpp:504
AppBaseClass * getActiveApp()
provides an interface for apps to request the active app object
Definition: AppManager.cpp:458
bool getConnectionString(uint16_t connectionIndex, char *connectionStringBuffer)
bool disconnect(AudioStream *destination, int destinationInput)
bool connect(AudioStream *source, int sourceOutput, AudioStream *destination, int destinationInput)
void printDictionary(SvcSerialCommandInterface *sci)
prints the dictionary to the SvcSerialCommandInterface
bool requestStartLZ4Message()
request to start a lz4 compressed message starts the message and returns true if available returns f...
bool throttle()
returns true if the available serial buffer falls below SERIAL_THROTTLE_BUFFER_REMAINING_THRESHOLD if...
void sendLZ4Message()
Calling this function signals the end of a compressed message. The txBuffer contents are lz4 compres...
const char * gWelcomeMessage

References AppBaseClass::ad, AppBaseClass::am, AudioDirector::connect(), AppManager::data, AudioDirector::disconnect(), et_since_periodic_data_dict_tx, et_since_periodic_stats_tx, AppManager::getActiveApp(), AppManager::getAppByName(), AudioDirector::getConnectionString(), AppManager::getInstance(), gWelcomeMessage, index_rx_buffer, is_capturing_bulk_data, is_periodic_messages_enabled, is_streaming_file, AppBaseClass::messageHandler(), messageHandler_GET(), messageHandler_GET_RAM1(), messageHandler_GET_RAM2(), messageHandler_LS(), messageHandler_UPDATE_DD(), messageHandler_WREN_SCRIPT_COMPILE(), messageHandler_WREN_SCRIPT_EXECUTE(), messageHandler_WREN_SCRIPT_SAVE(), messageHandler_WREN_SCRIPT_START(), p_received_chars, SvcDataDictionary::printDictionary(), AppManager::printStats(), AudioDirector::printStats(), requestStartLZ4Message(), sendLZ4Message(), AppManager::sendMessage(), streamReceiveHandler(), streamTransmitHandler(), and throttle().

+ Here is the call graph for this function: