teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
serialPC.cpp@4:13ff9c81dc10, 2017-06-02 (annotated)
- Committer:
- brunofgc
- Date:
- Fri Jun 02 13:31:56 2017 +0000
- Revision:
- 4:13ff9c81dc10
- Parent:
- 2:55b7b466e742
- Child:
- 7:ae9c47f62946
Vers?o Est?vel instalada no AP201 antes de incluir as scheduleExceptions.
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:13ff9c81dc10 | 31 | char * bufIn; |
brunofgc | 4:13ff9c81dc10 | 32 | char *ptr; |
brunofgc | 4:13ff9c81dc10 | 33 | char *scanPtr; |
brunofgc | 0:1c0a769988ee | 34 | uint16_t bufLength = bufPC.getLength(); |
brunofgc | 0:1c0a769988ee | 35 | bufIn = bufPC.get(); |
brunofgc | 0:1c0a769988ee | 36 | |
brunofgc | 0:1c0a769988ee | 37 | |
brunofgc | 0:1c0a769988ee | 38 | static bool recebendoDeviceCfg = false; |
brunofgc | 0:1c0a769988ee | 39 | |
brunofgc | 0:1c0a769988ee | 40 | if(strstr(bufIn,"cmd/StartSendDeviceCfg;>")){ |
brunofgc | 0:1c0a769988ee | 41 | recebendoDeviceCfg = true; |
brunofgc | 0:1c0a769988ee | 42 | return; |
brunofgc | 0:1c0a769988ee | 43 | } |
brunofgc | 0:1c0a769988ee | 44 | |
brunofgc | 0:1c0a769988ee | 45 | if(strstr(bufIn,"cmd/StopSendDeviceCfg;>")){ |
brunofgc | 0:1c0a769988ee | 46 | recebendoDeviceCfg = false; |
brunofgc | 0:1c0a769988ee | 47 | return; |
brunofgc | 0:1c0a769988ee | 48 | } |
brunofgc | 0:1c0a769988ee | 49 | |
brunofgc | 0:1c0a769988ee | 50 | if(recebendoDeviceCfg){ |
brunofgc | 0:1c0a769988ee | 51 | sdCard::insereDadosArquivo(&sdCard::devices,bufIn,bufLength); |
brunofgc | 0:1c0a769988ee | 52 | pc.printf("Caracteres inseridos %lu\n",bufLength); |
brunofgc | 0:1c0a769988ee | 53 | return; |
brunofgc | 0:1c0a769988ee | 54 | } |
brunofgc | 0:1c0a769988ee | 55 | |
brunofgc | 0:1c0a769988ee | 56 | if(strstr(bufIn,"modem:")!=NULL){ |
brunofgc | 0:1c0a769988ee | 57 | bufIn = &bufIn[6]; |
brunofgc | 0:1c0a769988ee | 58 | pc.printf("Mensagem ao modem <%s>.\r\n",bufIn); |
brunofgc | 0:1c0a769988ee | 59 | modem.printf("%s",bufIn); |
brunofgc | 0:1c0a769988ee | 60 | modemCom::status.exibeBufModem=true; |
brunofgc | 0:1c0a769988ee | 61 | return; |
brunofgc | 0:1c0a769988ee | 62 | } |
brunofgc | 0:1c0a769988ee | 63 | |
brunofgc | 0:1c0a769988ee | 64 | if(strstr(bufIn,"exibeArquivo:armazenamento.txt")!=NULL){ |
brunofgc | 0:1c0a769988ee | 65 | sdCard::exibeArquivo(&sdCard::armazenamento); |
brunofgc | 0:1c0a769988ee | 66 | return; |
brunofgc | 2:55b7b466e742 | 67 | } |
brunofgc | 2:55b7b466e742 | 68 | |
brunofgc | 2:55b7b466e742 | 69 | if(strstr(bufIn,"resetDigitais()")!=NULL){ |
brunofgc | 2:55b7b466e742 | 70 | SD_OE_R = 0; |
brunofgc | 2:55b7b466e742 | 71 | osDelay(50); |
brunofgc | 2:55b7b466e742 | 72 | SD_OE_R = 1; |
brunofgc | 2:55b7b466e742 | 73 | return; |
brunofgc | 0:1c0a769988ee | 74 | } |
brunofgc | 2:55b7b466e742 | 75 | |
brunofgc | 2:55b7b466e742 | 76 | |
brunofgc | 1:0e0967c88590 | 77 | if(strstr(bufIn,"testaTudoDevices()")!=NULL){ |
brunofgc | 1:0e0967c88590 | 78 | testaTudoDevices(); |
brunofgc | 1:0e0967c88590 | 79 | return; |
brunofgc | 1:0e0967c88590 | 80 | } |
brunofgc | 1:0e0967c88590 | 81 | |
brunofgc | 0:1c0a769988ee | 82 | |
brunofgc | 0:1c0a769988ee | 83 | if(strstr(bufIn,"exibeArquivo:tempFile.bin")!=NULL){ |
brunofgc | 0:1c0a769988ee | 84 | sdCard::exibeArquivo(&sdCard::tempFile); |
brunofgc | 0:1c0a769988ee | 85 | return; |
brunofgc | 0:1c0a769988ee | 86 | } |
brunofgc | 0:1c0a769988ee | 87 | |
brunofgc | 0:1c0a769988ee | 88 | if(strstr(bufIn,"exibeArquivo:envio.txt")!=NULL){ |
brunofgc | 0:1c0a769988ee | 89 | sdCard::exibeArquivo(&sdCard::envio); |
brunofgc | 0:1c0a769988ee | 90 | return; |
brunofgc | 0:1c0a769988ee | 91 | } |
brunofgc | 0:1c0a769988ee | 92 | |
brunofgc | 0:1c0a769988ee | 93 | if(strstr(bufIn,"enviaDadosAoServer")){ |
brunofgc | 1:0e0967c88590 | 94 | eventosRTC::rotina15Minutos=true; |
brunofgc | 0:1c0a769988ee | 95 | return; |
brunofgc | 0:1c0a769988ee | 96 | } |
brunofgc | 0:1c0a769988ee | 97 | |
brunofgc | 2:55b7b466e742 | 98 | if(strstr(bufIn,"enviaStatusAoServer")){ |
brunofgc | 2:55b7b466e742 | 99 | enviaStatusAoServer = true; |
brunofgc | 2:55b7b466e742 | 100 | return; |
brunofgc | 2:55b7b466e742 | 101 | } |
brunofgc | 2:55b7b466e742 | 102 | |
brunofgc | 0:1c0a769988ee | 103 | if(strstr(bufIn,"enviaArquivoDevices")){ |
brunofgc | 0:1c0a769988ee | 104 | arquivoEnvioPointer = &sdCard::devices; |
brunofgc | 0:1c0a769988ee | 105 | return; |
brunofgc | 0:1c0a769988ee | 106 | } |
brunofgc | 0:1c0a769988ee | 107 | |
brunofgc | 0:1c0a769988ee | 108 | if(strstr(bufIn,"excluiArquivo:armazenamento.txt")!=NULL){ |
brunofgc | 0:1c0a769988ee | 109 | sdCard::excluiArquivo(&sdCard::armazenamento); |
brunofgc | 0:1c0a769988ee | 110 | return; |
brunofgc | 0:1c0a769988ee | 111 | } |
brunofgc | 0:1c0a769988ee | 112 | |
brunofgc | 0:1c0a769988ee | 113 | if(strstr(bufIn,"excluiArquivo:envio.txt")!=NULL){ |
brunofgc | 0:1c0a769988ee | 114 | sdCard::excluiArquivo(&sdCard::envio); |
brunofgc | 0:1c0a769988ee | 115 | return; |
brunofgc | 0:1c0a769988ee | 116 | } |
brunofgc | 0:1c0a769988ee | 117 | |
brunofgc | 0:1c0a769988ee | 118 | if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){ |
brunofgc | 0:1c0a769988ee | 119 | sdCard::excluiArquivo(&sdCard::devices); |
brunofgc | 0:1c0a769988ee | 120 | return; |
brunofgc | 0:1c0a769988ee | 121 | } |
brunofgc | 0:1c0a769988ee | 122 | |
brunofgc | 0:1c0a769988ee | 123 | if(strstr(bufIn,"exibeArquivo:devices.cfg")!=NULL){ |
brunofgc | 0:1c0a769988ee | 124 | sdCard::exibeArquivo(&sdCard::devices); |
brunofgc | 0:1c0a769988ee | 125 | return; |
brunofgc | 4:13ff9c81dc10 | 126 | } |
brunofgc | 4:13ff9c81dc10 | 127 | |
brunofgc | 4:13ff9c81dc10 | 128 | ptr=strstr(bufIn,"*ServerCommand*"); |
brunofgc | 4:13ff9c81dc10 | 129 | if(ptr) { |
brunofgc | 4:13ff9c81dc10 | 130 | //naoCompreendido=false; |
brunofgc | 4:13ff9c81dc10 | 131 | scanPtr = strtok (ptr,"\\"); |
brunofgc | 4:13ff9c81dc10 | 132 | scanPtr = strtok (NULL,">"); |
brunofgc | 4:13ff9c81dc10 | 133 | strcpy(commands::buffer,scanPtr); |
brunofgc | 4:13ff9c81dc10 | 134 | pc.printf("Comandos <%s>.\n",commands::buffer); |
brunofgc | 4:13ff9c81dc10 | 135 | executaComandoServer = true; |
brunofgc | 4:13ff9c81dc10 | 136 | //Se devo executar comando tenho que sair imediatamente. |
brunofgc | 4:13ff9c81dc10 | 137 | return; |
brunofgc | 4:13ff9c81dc10 | 138 | } |
brunofgc | 4:13ff9c81dc10 | 139 | |
brunofgc | 0:1c0a769988ee | 140 | if(strstr(bufIn,"writeReadingsToSD()")){ |
brunofgc | 0:1c0a769988ee | 141 | eventosRTC::rotina15Minutos = true; |
brunofgc | 0:1c0a769988ee | 142 | return; |
brunofgc | 0:1c0a769988ee | 143 | } |
brunofgc | 0:1c0a769988ee | 144 | |
brunofgc | 0:1c0a769988ee | 145 | //bufLength |
brunofgc | 0:1c0a769988ee | 146 | /* |
brunofgc | 0:1c0a769988ee | 147 | stack overflow de thread... |
brunofgc | 0:1c0a769988ee | 148 | if(strstr(bufIn,"execAct(")){ |
brunofgc | 0:1c0a769988ee | 149 | strtok(bufIn,"("); |
brunofgc | 0:1c0a769988ee | 150 | bufLength = atoi(strtok(NULL,")")); |
brunofgc | 0:1c0a769988ee | 151 | dispositivos[0]->execAct(bufLength); |
brunofgc | 0:1c0a769988ee | 152 | return; |
brunofgc | 0:1c0a769988ee | 153 | } |
brunofgc | 0:1c0a769988ee | 154 | */ |
brunofgc | 0:1c0a769988ee | 155 | //Se chegou aqui é pq não foi uma mensagem reconhecida. |
brunofgc | 0:1c0a769988ee | 156 | pc.printf("Lido do CircularBuffer PC <%s>.\r\n",bufIn); |
brunofgc | 0:1c0a769988ee | 157 | } |