teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
Diff: serialPC.cpp
- Revision:
- 0:1c0a769988ee
- Child:
- 1:0e0967c88590
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serialPC.cpp Fri Mar 24 15:54:41 2017 +0000 @@ -0,0 +1,123 @@ +#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; + uint16_t bufLength = bufPC.getLength(); + bufIn = bufPC.get(); + + + static bool recebendoDeviceCfg = false; + + if(strstr(bufIn,"cmd/StartSendDeviceCfg;>")){ + recebendoDeviceCfg = 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); + modem.printf("%s",bufIn); + modemCom::status.exibeBufModem=true; + return; + } + + if(strstr(bufIn,"exibeArquivo:armazenamento.txt")!=NULL){ + sdCard::exibeArquivo(&sdCard::armazenamento); + return; + } + + if(strstr(bufIn,"exibeArquivo:tempFile.bin")!=NULL){ + sdCard::exibeArquivo(&sdCard::tempFile); + return; + } + + if(strstr(bufIn,"exibeArquivo:envio.txt")!=NULL){ + sdCard::exibeArquivo(&sdCard::envio); + return; + } + + if(strstr(bufIn,"enviaDadosAoServer")){ + eventosRTC::rotina1hora=true; + return; + } + + if(strstr(bufIn,"enviaArquivoDevices")){ + arquivoEnvioPointer = &sdCard::devices; + return; + } + + if(strstr(bufIn,"excluiArquivo:armazenamento.txt")!=NULL){ + sdCard::excluiArquivo(&sdCard::armazenamento); + return; + } + + if(strstr(bufIn,"excluiArquivo:envio.txt")!=NULL){ + sdCard::excluiArquivo(&sdCard::envio); + return; + } + + if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){ + sdCard::excluiArquivo(&sdCard::devices); + return; + } + + if(strstr(bufIn,"exibeArquivo:devices.cfg")!=NULL){ + sdCard::exibeArquivo(&sdCard::devices); + 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); +}