teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
serialPC.cpp@21:b9315cdd9275, 2018-02-06 (annotated)
- Committer:
- brunofgc
- Date:
- Tue Feb 06 16:33:51 2018 +0000
- Revision:
- 21:b9315cdd9275
- Parent:
- 18:1eefda1f7736
- Child:
- 22:cb832a9bc704
Ultima vers?o antes de usar urldecode2 para parsear a string de config.bin
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 | 7:ae9c47f62946 | 45 | if(strstr(bufIn,"execAct(")){ |
brunofgc | 7:ae9c47f62946 | 46 | strtok(bufIn,"("); |
brunofgc | 7:ae9c47f62946 | 47 | act=atoi(strtok(NULL,")")); |
brunofgc | 7:ae9c47f62946 | 48 | boolExecAct = true; |
brunofgc | 7:ae9c47f62946 | 49 | return; |
brunofgc | 7:ae9c47f62946 | 50 | } |
brunofgc | 7:ae9c47f62946 | 51 | |
brunofgc | 0:1c0a769988ee | 52 | if(strstr(bufIn,"cmd/StopSendDeviceCfg;>")){ |
brunofgc | 0:1c0a769988ee | 53 | recebendoDeviceCfg = false; |
brunofgc | 0:1c0a769988ee | 54 | return; |
brunofgc | 0:1c0a769988ee | 55 | } |
brunofgc | 0:1c0a769988ee | 56 | |
brunofgc | 0:1c0a769988ee | 57 | if(recebendoDeviceCfg){ |
brunofgc | 0:1c0a769988ee | 58 | sdCard::insereDadosArquivo(&sdCard::devices,bufIn,bufLength); |
brunofgc | 0:1c0a769988ee | 59 | pc.printf("Caracteres inseridos %lu\n",bufLength); |
brunofgc | 0:1c0a769988ee | 60 | return; |
brunofgc | 0:1c0a769988ee | 61 | } |
brunofgc | 0:1c0a769988ee | 62 | |
brunofgc | 0:1c0a769988ee | 63 | if(strstr(bufIn,"modem:")!=NULL){ |
brunofgc | 0:1c0a769988ee | 64 | bufIn = &bufIn[6]; |
brunofgc | 0:1c0a769988ee | 65 | pc.printf("Mensagem ao modem <%s>.\r\n",bufIn); |
brunofgc | 7:ae9c47f62946 | 66 | modemCom::sendToModem(bufIn,1,NULL,NULL,100,1,1); |
brunofgc | 7:ae9c47f62946 | 67 | pc.printf("Mesagem do modem <%s>.\r\n",bufModem.getRowBuffer()); |
brunofgc | 0:1c0a769988ee | 68 | return; |
brunofgc | 0:1c0a769988ee | 69 | } |
brunofgc | 0:1c0a769988ee | 70 | |
brunofgc | 9:cf406384efd9 | 71 | |
brunofgc | 10:263c093f8977 | 72 | |
brunofgc | 2:55b7b466e742 | 73 | |
brunofgc | 9:cf406384efd9 | 74 | if(strstr(bufIn,"exibeArquivo:config.bin")!=NULL){ |
brunofgc | 9:cf406384efd9 | 75 | sdCard::exibeArquivo(&sdCard::config); |
brunofgc | 9:cf406384efd9 | 76 | return; |
brunofgc | 9:cf406384efd9 | 77 | } |
brunofgc | 9:cf406384efd9 | 78 | |
brunofgc | 2:55b7b466e742 | 79 | if(strstr(bufIn,"resetDigitais()")!=NULL){ |
brunofgc | 2:55b7b466e742 | 80 | SD_OE_R = 0; |
brunofgc | 2:55b7b466e742 | 81 | osDelay(50); |
brunofgc | 2:55b7b466e742 | 82 | SD_OE_R = 1; |
brunofgc | 2:55b7b466e742 | 83 | return; |
brunofgc | 0:1c0a769988ee | 84 | } |
brunofgc | 2:55b7b466e742 | 85 | |
brunofgc | 2:55b7b466e742 | 86 | |
brunofgc | 1:0e0967c88590 | 87 | if(strstr(bufIn,"testaTudoDevices()")!=NULL){ |
brunofgc | 1:0e0967c88590 | 88 | testaTudoDevices(); |
brunofgc | 1:0e0967c88590 | 89 | return; |
brunofgc | 1:0e0967c88590 | 90 | } |
brunofgc | 1:0e0967c88590 | 91 | |
brunofgc | 0:1c0a769988ee | 92 | |
brunofgc | 0:1c0a769988ee | 93 | if(strstr(bufIn,"exibeArquivo:tempFile.bin")!=NULL){ |
brunofgc | 0:1c0a769988ee | 94 | sdCard::exibeArquivo(&sdCard::tempFile); |
brunofgc | 0:1c0a769988ee | 95 | return; |
brunofgc | 0:1c0a769988ee | 96 | } |
brunofgc | 0:1c0a769988ee | 97 | |
brunofgc | 10:263c093f8977 | 98 | if(strstr(bufIn,"exibeArquivo:bank0.txt")!=NULL){ |
brunofgc | 10:263c093f8977 | 99 | sdCard::exibeArquivo(&sdCard::bank0); |
brunofgc | 10:263c093f8977 | 100 | return; |
brunofgc | 10:263c093f8977 | 101 | } |
brunofgc | 10:263c093f8977 | 102 | |
brunofgc | 10:263c093f8977 | 103 | if(strstr(bufIn,"exibeArquivo:bank1.txt")!=NULL){ |
brunofgc | 10:263c093f8977 | 104 | sdCard::exibeArquivo(&sdCard::bank1); |
brunofgc | 10:263c093f8977 | 105 | return; |
brunofgc | 10:263c093f8977 | 106 | } |
brunofgc | 10:263c093f8977 | 107 | |
brunofgc | 10:263c093f8977 | 108 | if(strstr(bufIn,"exibeArquivo:currentBank.txt")!=NULL){ |
brunofgc | 10:263c093f8977 | 109 | sdCard::exibeArquivo(&sdCard::currentBankFile); |
brunofgc | 0:1c0a769988ee | 110 | return; |
brunofgc | 0:1c0a769988ee | 111 | } |
brunofgc | 0:1c0a769988ee | 112 | |
brunofgc | 0:1c0a769988ee | 113 | if(strstr(bufIn,"enviaDadosAoServer")){ |
brunofgc | 18:1eefda1f7736 | 114 | eventosRTC::rotinaEnvioDeDados=maxTentativasEnvioDados; |
brunofgc | 0:1c0a769988ee | 115 | return; |
brunofgc | 0:1c0a769988ee | 116 | } |
brunofgc | 0:1c0a769988ee | 117 | |
brunofgc | 7:ae9c47f62946 | 118 | |
brunofgc | 2:55b7b466e742 | 119 | |
brunofgc | 0:1c0a769988ee | 120 | if(strstr(bufIn,"enviaArquivoDevices")){ |
brunofgc | 0:1c0a769988ee | 121 | arquivoEnvioPointer = &sdCard::devices; |
brunofgc | 0:1c0a769988ee | 122 | return; |
brunofgc | 21:b9315cdd9275 | 123 | } |
brunofgc | 0:1c0a769988ee | 124 | |
brunofgc | 21:b9315cdd9275 | 125 | if(strstr(bufIn,"debug")){ |
brunofgc | 21:b9315cdd9275 | 126 | if(debug){debug = false;} |
brunofgc | 21:b9315cdd9275 | 127 | else{debug = true;} |
brunofgc | 21:b9315cdd9275 | 128 | return; |
brunofgc | 21:b9315cdd9275 | 129 | } |
brunofgc | 9:cf406384efd9 | 130 | |
brunofgc | 9:cf406384efd9 | 131 | if(strstr(bufIn,"excluiArquivo:config.bin")!=NULL){ |
brunofgc | 9:cf406384efd9 | 132 | sdCard::excluiArquivo(&sdCard::config); |
brunofgc | 9:cf406384efd9 | 133 | return; |
brunofgc | 21:b9315cdd9275 | 134 | } |
brunofgc | 0:1c0a769988ee | 135 | |
brunofgc | 21:b9315cdd9275 | 136 | if(strstr(bufIn,"excluiArquivo:currentBank.txt")!=NULL){ |
brunofgc | 10:263c093f8977 | 137 | sdCard::excluiArquivo(&sdCard::currentBankFile); |
brunofgc | 0:1c0a769988ee | 138 | return; |
brunofgc | 10:263c093f8977 | 139 | } |
brunofgc | 10:263c093f8977 | 140 | |
brunofgc | 10:263c093f8977 | 141 | |
brunofgc | 0:1c0a769988ee | 142 | |
brunofgc | 0:1c0a769988ee | 143 | if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){ |
brunofgc | 0:1c0a769988ee | 144 | sdCard::excluiArquivo(&sdCard::devices); |
brunofgc | 0:1c0a769988ee | 145 | return; |
brunofgc | 0:1c0a769988ee | 146 | } |
brunofgc | 0:1c0a769988ee | 147 | |
brunofgc | 7:ae9c47f62946 | 148 | if(strstr(bufIn,"conectaWifi()")!=NULL){ |
brunofgc | 7:ae9c47f62946 | 149 | inicializaModemBool = true; |
brunofgc | 7:ae9c47f62946 | 150 | return; |
brunofgc | 7:ae9c47f62946 | 151 | } |
brunofgc | 7:ae9c47f62946 | 152 | |
brunofgc | 7:ae9c47f62946 | 153 | |
brunofgc | 7:ae9c47f62946 | 154 | |
brunofgc | 0:1c0a769988ee | 155 | if(strstr(bufIn,"exibeArquivo:devices.cfg")!=NULL){ |
brunofgc | 0:1c0a769988ee | 156 | sdCard::exibeArquivo(&sdCard::devices); |
brunofgc | 0:1c0a769988ee | 157 | return; |
brunofgc | 4:13ff9c81dc10 | 158 | } |
brunofgc | 4:13ff9c81dc10 | 159 | |
brunofgc | 4:13ff9c81dc10 | 160 | ptr=strstr(bufIn,"*ServerCommand*"); |
brunofgc | 4:13ff9c81dc10 | 161 | if(ptr) { |
brunofgc | 4:13ff9c81dc10 | 162 | //naoCompreendido=false; |
brunofgc | 4:13ff9c81dc10 | 163 | scanPtr = strtok (ptr,"\\"); |
brunofgc | 4:13ff9c81dc10 | 164 | scanPtr = strtok (NULL,">"); |
brunofgc | 4:13ff9c81dc10 | 165 | strcpy(commands::buffer,scanPtr); |
brunofgc | 4:13ff9c81dc10 | 166 | pc.printf("Comandos <%s>.\n",commands::buffer); |
brunofgc | 4:13ff9c81dc10 | 167 | executaComandoServer = true; |
brunofgc | 4:13ff9c81dc10 | 168 | //Se devo executar comando tenho que sair imediatamente. |
brunofgc | 4:13ff9c81dc10 | 169 | return; |
brunofgc | 4:13ff9c81dc10 | 170 | } |
brunofgc | 4:13ff9c81dc10 | 171 | |
brunofgc | 0:1c0a769988ee | 172 | if(strstr(bufIn,"writeReadingsToSD()")){ |
brunofgc | 18:1eefda1f7736 | 173 | eventosRTC::rotinaEnvioDeDados = maxTentativasEnvioDados; |
brunofgc | 0:1c0a769988ee | 174 | return; |
brunofgc | 0:1c0a769988ee | 175 | } |
brunofgc | 0:1c0a769988ee | 176 | |
brunofgc | 0:1c0a769988ee | 177 | //bufLength |
brunofgc | 0:1c0a769988ee | 178 | /* |
brunofgc | 0:1c0a769988ee | 179 | stack overflow de thread... |
brunofgc | 0:1c0a769988ee | 180 | if(strstr(bufIn,"execAct(")){ |
brunofgc | 0:1c0a769988ee | 181 | strtok(bufIn,"("); |
brunofgc | 0:1c0a769988ee | 182 | bufLength = atoi(strtok(NULL,")")); |
brunofgc | 0:1c0a769988ee | 183 | dispositivos[0]->execAct(bufLength); |
brunofgc | 0:1c0a769988ee | 184 | return; |
brunofgc | 0:1c0a769988ee | 185 | } |
brunofgc | 0:1c0a769988ee | 186 | */ |
brunofgc | 0:1c0a769988ee | 187 | //Se chegou aqui é pq não foi uma mensagem reconhecida. |
brunofgc | 0:1c0a769988ee | 188 | pc.printf("Lido do CircularBuffer PC <%s>.\r\n",bufIn); |
brunofgc | 0:1c0a769988ee | 189 | } |