teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
serialPC.cpp
- Committer:
- brunofgc
- Date:
- 2017-08-14
- Revision:
- 10:263c093f8977
- Parent:
- 9:cf406384efd9
- Child:
- 15:0f78bf9c13ec
File content as of revision 10:263c093f8977:
#include "serialPC.h" osTimerId serialPC::timer_pacote; bool serialPC::startTimer_pacote; /*Timers*/ //osTimerDef( "nomeDoTimer", "Função chamada pelo timer when match") osTimerDef(timerProcessaPacotePC,serialPC::processaPacotePC); /*Timers*/ void serialPC::serialPC_init(){ //Instnciando o timer de processamento de pacotes entrantes na serial PC pc.baud(230400); //Inicialização de recurso Serial uart pc com baudrate 230400 pc.printf("Serial PC inicializado.\n"); //Exibe mensagem de inicialização da serial pc //Criando timer_pacote serialPC::timer_pacote = osTimerCreate(osTimer(timerProcessaPacotePC),osTimerOnce,NULL); //Associando função a ISR da serial PC pc.attach(&serialPC::isr_serialPC); //Setando uma função para ISR Serial 0 (Serial pc) } void serialPC::isr_serialPC(){ uint32_t RBR = LPC_UART0->RBR; //Reset RBR interrupt flag e captura o caractere entrante bufPC.putc(RBR); serialPC::startTimer_pacote=true; osSignalSet(idThreadTimers, 0x1); } void serialPC::processaPacotePC(void const *args){ char * bufIn; char *ptr; char *scanPtr; uint16_t bufLength = bufPC.getLength(); bufIn = bufPC.get(); static bool recebendoDeviceCfg = false; if(strstr(bufIn,"cmd/StartSendDeviceCfg;>")){ recebendoDeviceCfg = true; return; } if(strstr(bufIn,"execAct(")){ strtok(bufIn,"("); act=atoi(strtok(NULL,")")); boolExecAct = true; return; } if(strstr(bufIn,"cmd/StopSendDeviceCfg;>")){ recebendoDeviceCfg = false; return; } if(recebendoDeviceCfg){ sdCard::insereDadosArquivo(&sdCard::devices,bufIn,bufLength); pc.printf("Caracteres inseridos %lu\n",bufLength); return; } if(strstr(bufIn,"modem:")!=NULL){ bufIn = &bufIn[6]; pc.printf("Mensagem ao modem <%s>.\r\n",bufIn); modemCom::sendToModem(bufIn,1,NULL,NULL,100,1,1); pc.printf("Mesagem do modem <%s>.\r\n",bufModem.getRowBuffer()); return; } if(strstr(bufIn,"exibeArquivo:config.bin")!=NULL){ sdCard::exibeArquivo(&sdCard::config); return; } if(strstr(bufIn,"resetDigitais()")!=NULL){ SD_OE_R = 0; osDelay(50); SD_OE_R = 1; return; } if(strstr(bufIn,"testaTudoDevices()")!=NULL){ testaTudoDevices(); return; } if(strstr(bufIn,"exibeArquivo:tempFile.bin")!=NULL){ sdCard::exibeArquivo(&sdCard::tempFile); return; } if(strstr(bufIn,"exibeArquivo:bank0.txt")!=NULL){ sdCard::exibeArquivo(&sdCard::bank0); return; } if(strstr(bufIn,"exibeArquivo:bank1.txt")!=NULL){ sdCard::exibeArquivo(&sdCard::bank1); return; } if(strstr(bufIn,"exibeArquivo:currentBank.txt")!=NULL){ sdCard::exibeArquivo(&sdCard::currentBankFile); return; } if(strstr(bufIn,"enviaDadosAoServer")){ eventosRTC::rotina15Minutos=true; return; } if(strstr(bufIn,"enviaArquivoDevices")){ arquivoEnvioPointer = &sdCard::devices; return; } if(strstr(bufIn,"excluiArquivo:config.bin")!=NULL){ sdCard::excluiArquivo(&sdCard::config); return; } if(strstr(bufIn,"excluiArquivo:currentBank.txt")!=NULL){ sdCard::excluiArquivo(&sdCard::currentBankFile); return; } if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){ sdCard::excluiArquivo(&sdCard::devices); return; } if(strstr(bufIn,"conectaWifi()")!=NULL){ inicializaModemBool = true; return; } if(strstr(bufIn,"exibeArquivo:devices.cfg")!=NULL){ sdCard::exibeArquivo(&sdCard::devices); return; } ptr=strstr(bufIn,"*ServerCommand*"); if(ptr) { //naoCompreendido=false; scanPtr = strtok (ptr,"\\"); scanPtr = strtok (NULL,">"); strcpy(commands::buffer,scanPtr); pc.printf("Comandos <%s>.\n",commands::buffer); executaComandoServer = true; //Se devo executar comando tenho que sair imediatamente. return; } if(strstr(bufIn,"writeReadingsToSD()")){ eventosRTC::rotina15Minutos = true; return; } //bufLength /* stack overflow de thread... if(strstr(bufIn,"execAct(")){ strtok(bufIn,"("); bufLength = atoi(strtok(NULL,")")); dispositivos[0]->execAct(bufLength); return; } */ //Se chegou aqui é pq não foi uma mensagem reconhecida. pc.printf("Lido do CircularBuffer PC <%s>.\r\n",bufIn); }