teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Fri Mar 24 15:54:41 2017 +0000
Revision:
0:1c0a769988ee
Child:
1:0e0967c88590
Saidas digitais com pwm ok, entradas analogicas ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brunofgc 0:1c0a769988ee 1 #include "serialPC.h"
brunofgc 0:1c0a769988ee 2
brunofgc 0:1c0a769988ee 3 osTimerId serialPC::timer_pacote;
brunofgc 0:1c0a769988ee 4 bool serialPC::startTimer_pacote;
brunofgc 0:1c0a769988ee 5
brunofgc 0:1c0a769988ee 6 /*Timers*/
brunofgc 0:1c0a769988ee 7 //osTimerDef( "nomeDoTimer", "Função chamada pelo timer when match")
brunofgc 0:1c0a769988ee 8 osTimerDef(timerProcessaPacotePC,serialPC::processaPacotePC);
brunofgc 0:1c0a769988ee 9 /*Timers*/
brunofgc 0:1c0a769988ee 10
brunofgc 0:1c0a769988ee 11 void serialPC::serialPC_init(){
brunofgc 0:1c0a769988ee 12 //Instnciando o timer de processamento de pacotes entrantes na serial PC
brunofgc 0:1c0a769988ee 13 pc.baud(230400); //Inicialização de recurso Serial uart pc com baudrate 230400
brunofgc 0:1c0a769988ee 14 pc.printf("Serial PC inicializado.\n"); //Exibe mensagem de inicialização da serial pc
brunofgc 0:1c0a769988ee 15
brunofgc 0:1c0a769988ee 16 //Criando timer_pacote
brunofgc 0:1c0a769988ee 17 serialPC::timer_pacote = osTimerCreate(osTimer(timerProcessaPacotePC),osTimerOnce,NULL);
brunofgc 0:1c0a769988ee 18
brunofgc 0:1c0a769988ee 19 //Associando função a ISR da serial PC
brunofgc 0:1c0a769988ee 20 pc.attach(&serialPC::isr_serialPC); //Setando uma função para ISR Serial 0 (Serial pc)
brunofgc 0:1c0a769988ee 21 }
brunofgc 0:1c0a769988ee 22 void serialPC::isr_serialPC(){
brunofgc 0:1c0a769988ee 23 uint32_t RBR = LPC_UART0->RBR; //Reset RBR interrupt flag e captura o caractere entrante
brunofgc 0:1c0a769988ee 24
brunofgc 0:1c0a769988ee 25 bufPC.putc(RBR);
brunofgc 0:1c0a769988ee 26 serialPC::startTimer_pacote=true;
brunofgc 0:1c0a769988ee 27 osSignalSet(idThreadTimers, 0x1);
brunofgc 0:1c0a769988ee 28 }
brunofgc 0:1c0a769988ee 29
brunofgc 0:1c0a769988ee 30 void serialPC::processaPacotePC(void const *args){
brunofgc 0:1c0a769988ee 31 char * bufIn;
brunofgc 0:1c0a769988ee 32 uint16_t bufLength = bufPC.getLength();
brunofgc 0:1c0a769988ee 33 bufIn = bufPC.get();
brunofgc 0:1c0a769988ee 34
brunofgc 0:1c0a769988ee 35
brunofgc 0:1c0a769988ee 36 static bool recebendoDeviceCfg = false;
brunofgc 0:1c0a769988ee 37
brunofgc 0:1c0a769988ee 38 if(strstr(bufIn,"cmd/StartSendDeviceCfg;>")){
brunofgc 0:1c0a769988ee 39 recebendoDeviceCfg = true;
brunofgc 0:1c0a769988ee 40 return;
brunofgc 0:1c0a769988ee 41 }
brunofgc 0:1c0a769988ee 42
brunofgc 0:1c0a769988ee 43 if(strstr(bufIn,"cmd/StopSendDeviceCfg;>")){
brunofgc 0:1c0a769988ee 44 recebendoDeviceCfg = false;
brunofgc 0:1c0a769988ee 45 return;
brunofgc 0:1c0a769988ee 46 }
brunofgc 0:1c0a769988ee 47
brunofgc 0:1c0a769988ee 48 if(recebendoDeviceCfg){
brunofgc 0:1c0a769988ee 49 sdCard::insereDadosArquivo(&sdCard::devices,bufIn,bufLength);
brunofgc 0:1c0a769988ee 50 pc.printf("Caracteres inseridos %lu\n",bufLength);
brunofgc 0:1c0a769988ee 51 return;
brunofgc 0:1c0a769988ee 52 }
brunofgc 0:1c0a769988ee 53
brunofgc 0:1c0a769988ee 54 if(strstr(bufIn,"modem:")!=NULL){
brunofgc 0:1c0a769988ee 55 bufIn = &bufIn[6];
brunofgc 0:1c0a769988ee 56 pc.printf("Mensagem ao modem <%s>.\r\n",bufIn);
brunofgc 0:1c0a769988ee 57 modem.printf("%s",bufIn);
brunofgc 0:1c0a769988ee 58 modemCom::status.exibeBufModem=true;
brunofgc 0:1c0a769988ee 59 return;
brunofgc 0:1c0a769988ee 60 }
brunofgc 0:1c0a769988ee 61
brunofgc 0:1c0a769988ee 62 if(strstr(bufIn,"exibeArquivo:armazenamento.txt")!=NULL){
brunofgc 0:1c0a769988ee 63 sdCard::exibeArquivo(&sdCard::armazenamento);
brunofgc 0:1c0a769988ee 64 return;
brunofgc 0:1c0a769988ee 65 }
brunofgc 0:1c0a769988ee 66
brunofgc 0:1c0a769988ee 67 if(strstr(bufIn,"exibeArquivo:tempFile.bin")!=NULL){
brunofgc 0:1c0a769988ee 68 sdCard::exibeArquivo(&sdCard::tempFile);
brunofgc 0:1c0a769988ee 69 return;
brunofgc 0:1c0a769988ee 70 }
brunofgc 0:1c0a769988ee 71
brunofgc 0:1c0a769988ee 72 if(strstr(bufIn,"exibeArquivo:envio.txt")!=NULL){
brunofgc 0:1c0a769988ee 73 sdCard::exibeArquivo(&sdCard::envio);
brunofgc 0:1c0a769988ee 74 return;
brunofgc 0:1c0a769988ee 75 }
brunofgc 0:1c0a769988ee 76
brunofgc 0:1c0a769988ee 77 if(strstr(bufIn,"enviaDadosAoServer")){
brunofgc 0:1c0a769988ee 78 eventosRTC::rotina1hora=true;
brunofgc 0:1c0a769988ee 79 return;
brunofgc 0:1c0a769988ee 80 }
brunofgc 0:1c0a769988ee 81
brunofgc 0:1c0a769988ee 82 if(strstr(bufIn,"enviaArquivoDevices")){
brunofgc 0:1c0a769988ee 83 arquivoEnvioPointer = &sdCard::devices;
brunofgc 0:1c0a769988ee 84 return;
brunofgc 0:1c0a769988ee 85 }
brunofgc 0:1c0a769988ee 86
brunofgc 0:1c0a769988ee 87 if(strstr(bufIn,"excluiArquivo:armazenamento.txt")!=NULL){
brunofgc 0:1c0a769988ee 88 sdCard::excluiArquivo(&sdCard::armazenamento);
brunofgc 0:1c0a769988ee 89 return;
brunofgc 0:1c0a769988ee 90 }
brunofgc 0:1c0a769988ee 91
brunofgc 0:1c0a769988ee 92 if(strstr(bufIn,"excluiArquivo:envio.txt")!=NULL){
brunofgc 0:1c0a769988ee 93 sdCard::excluiArquivo(&sdCard::envio);
brunofgc 0:1c0a769988ee 94 return;
brunofgc 0:1c0a769988ee 95 }
brunofgc 0:1c0a769988ee 96
brunofgc 0:1c0a769988ee 97 if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 98 sdCard::excluiArquivo(&sdCard::devices);
brunofgc 0:1c0a769988ee 99 return;
brunofgc 0:1c0a769988ee 100 }
brunofgc 0:1c0a769988ee 101
brunofgc 0:1c0a769988ee 102 if(strstr(bufIn,"exibeArquivo:devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 103 sdCard::exibeArquivo(&sdCard::devices);
brunofgc 0:1c0a769988ee 104 return;
brunofgc 0:1c0a769988ee 105 }
brunofgc 0:1c0a769988ee 106 if(strstr(bufIn,"writeReadingsToSD()")){
brunofgc 0:1c0a769988ee 107 eventosRTC::rotina15Minutos = true;
brunofgc 0:1c0a769988ee 108 return;
brunofgc 0:1c0a769988ee 109 }
brunofgc 0:1c0a769988ee 110
brunofgc 0:1c0a769988ee 111 //bufLength
brunofgc 0:1c0a769988ee 112 /*
brunofgc 0:1c0a769988ee 113 stack overflow de thread...
brunofgc 0:1c0a769988ee 114 if(strstr(bufIn,"execAct(")){
brunofgc 0:1c0a769988ee 115 strtok(bufIn,"(");
brunofgc 0:1c0a769988ee 116 bufLength = atoi(strtok(NULL,")"));
brunofgc 0:1c0a769988ee 117 dispositivos[0]->execAct(bufLength);
brunofgc 0:1c0a769988ee 118 return;
brunofgc 0:1c0a769988ee 119 }
brunofgc 0:1c0a769988ee 120 */
brunofgc 0:1c0a769988ee 121 //Se chegou aqui é pq não foi uma mensagem reconhecida.
brunofgc 0:1c0a769988ee 122 pc.printf("Lido do CircularBuffer PC <%s>.\r\n",bufIn);
brunofgc 0:1c0a769988ee 123 }