teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Mon Apr 16 12:30:29 2018 +0000
Revision:
25:a6da63ed025b
Parent:
22:cb832a9bc704
Child:
29:823a9da3696b
Vers?o 16/04/2018 com modbus otimizado para 100 leituras

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 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 22:cb832a9bc704 92 if(strstr(bufIn,"excluiArquivo:tempFile.bin")!=NULL){
brunofgc 22:cb832a9bc704 93 sdCard::exibeArquivo(&sdCard::tempFile);
brunofgc 22:cb832a9bc704 94 remove("/sd/RAD/tempFile.bin");
brunofgc 22:cb832a9bc704 95 return;
brunofgc 22:cb832a9bc704 96 }
brunofgc 22:cb832a9bc704 97 /*
brunofgc 0:1c0a769988ee 98
brunofgc 22:cb832a9bc704 99 if(strstr(bufIn,"format c:")!=NULL){
brunofgc 22:cb832a9bc704 100 pc.printf("Formatando ");
brunofgc 22:cb832a9bc704 101 if(format()){
brunofgc 22:cb832a9bc704 102 pc.printf("ok\r\n");
brunofgc 22:cb832a9bc704 103 }else{pc.printf("nok\r\n");}
brunofgc 22:cb832a9bc704 104 return;
brunofgc 22:cb832a9bc704 105 }
brunofgc 22:cb832a9bc704 106 */
brunofgc 22:cb832a9bc704 107
brunofgc 22:cb832a9bc704 108 if(strstr(bufIn,"exibeArquivo:tempFile.bin")!=NULL){
brunofgc 0:1c0a769988ee 109 sdCard::exibeArquivo(&sdCard::tempFile);
brunofgc 0:1c0a769988ee 110 return;
brunofgc 0:1c0a769988ee 111 }
brunofgc 0:1c0a769988ee 112
brunofgc 10:263c093f8977 113 if(strstr(bufIn,"exibeArquivo:bank0.txt")!=NULL){
brunofgc 10:263c093f8977 114 sdCard::exibeArquivo(&sdCard::bank0);
brunofgc 10:263c093f8977 115 return;
brunofgc 10:263c093f8977 116 }
brunofgc 10:263c093f8977 117
brunofgc 10:263c093f8977 118 if(strstr(bufIn,"exibeArquivo:bank1.txt")!=NULL){
brunofgc 10:263c093f8977 119 sdCard::exibeArquivo(&sdCard::bank1);
brunofgc 10:263c093f8977 120 return;
brunofgc 10:263c093f8977 121 }
brunofgc 10:263c093f8977 122
brunofgc 22:cb832a9bc704 123 if(strstr(bufIn,"testeEscrita")!=NULL){
brunofgc 22:cb832a9bc704 124 sdCard::abreArquivo(&sdCard::tempFile,"a");
brunofgc 22:cb832a9bc704 125 fprintf(sdCard::tempFile.fp,"Linha escrita\r\n");
brunofgc 22:cb832a9bc704 126 sdCard::fechaArquivo(&sdCard::tempFile);
brunofgc 22:cb832a9bc704 127 return;
brunofgc 22:cb832a9bc704 128 }
brunofgc 22:cb832a9bc704 129
brunofgc 10:263c093f8977 130 if(strstr(bufIn,"exibeArquivo:currentBank.txt")!=NULL){
brunofgc 10:263c093f8977 131 sdCard::exibeArquivo(&sdCard::currentBankFile);
brunofgc 0:1c0a769988ee 132 return;
brunofgc 0:1c0a769988ee 133 }
brunofgc 0:1c0a769988ee 134
brunofgc 0:1c0a769988ee 135 if(strstr(bufIn,"enviaDadosAoServer")){
brunofgc 18:1eefda1f7736 136 eventosRTC::rotinaEnvioDeDados=maxTentativasEnvioDados;
brunofgc 0:1c0a769988ee 137 return;
brunofgc 0:1c0a769988ee 138 }
brunofgc 0:1c0a769988ee 139
brunofgc 7:ae9c47f62946 140
brunofgc 2:55b7b466e742 141
brunofgc 0:1c0a769988ee 142 if(strstr(bufIn,"enviaArquivoDevices")){
brunofgc 0:1c0a769988ee 143 arquivoEnvioPointer = &sdCard::devices;
brunofgc 0:1c0a769988ee 144 return;
brunofgc 21:b9315cdd9275 145 }
brunofgc 0:1c0a769988ee 146
brunofgc 21:b9315cdd9275 147 if(strstr(bufIn,"debug")){
brunofgc 21:b9315cdd9275 148 if(debug){debug = false;}
brunofgc 21:b9315cdd9275 149 else{debug = true;}
brunofgc 21:b9315cdd9275 150 return;
brunofgc 21:b9315cdd9275 151 }
brunofgc 9:cf406384efd9 152
brunofgc 9:cf406384efd9 153 if(strstr(bufIn,"excluiArquivo:config.bin")!=NULL){
brunofgc 9:cf406384efd9 154 sdCard::excluiArquivo(&sdCard::config);
brunofgc 9:cf406384efd9 155 return;
brunofgc 21:b9315cdd9275 156 }
brunofgc 0:1c0a769988ee 157
brunofgc 21:b9315cdd9275 158 if(strstr(bufIn,"excluiArquivo:currentBank.txt")!=NULL){
brunofgc 10:263c093f8977 159 sdCard::excluiArquivo(&sdCard::currentBankFile);
brunofgc 0:1c0a769988ee 160 return;
brunofgc 10:263c093f8977 161 }
brunofgc 10:263c093f8977 162
brunofgc 25:a6da63ed025b 163 if(strstr(bufIn,"excluiArquivoPeloNome:")!=NULL){
brunofgc 25:a6da63ed025b 164 strtok(bufIn,":");
brunofgc 25:a6da63ed025b 165 ptr = strtok(NULL,":");
brunofgc 25:a6da63ed025b 166 remove(ptr);
brunofgc 25:a6da63ed025b 167 return;
brunofgc 25:a6da63ed025b 168 }
brunofgc 0:1c0a769988ee 169
brunofgc 0:1c0a769988ee 170 if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 171 sdCard::excluiArquivo(&sdCard::devices);
brunofgc 0:1c0a769988ee 172 return;
brunofgc 0:1c0a769988ee 173 }
brunofgc 0:1c0a769988ee 174
brunofgc 7:ae9c47f62946 175 if(strstr(bufIn,"conectaWifi()")!=NULL){
brunofgc 7:ae9c47f62946 176 inicializaModemBool = true;
brunofgc 7:ae9c47f62946 177 return;
brunofgc 7:ae9c47f62946 178 }
brunofgc 7:ae9c47f62946 179
brunofgc 7:ae9c47f62946 180
brunofgc 7:ae9c47f62946 181
brunofgc 0:1c0a769988ee 182 if(strstr(bufIn,"exibeArquivo:devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 183 sdCard::exibeArquivo(&sdCard::devices);
brunofgc 0:1c0a769988ee 184 return;
brunofgc 4:13ff9c81dc10 185 }
brunofgc 4:13ff9c81dc10 186
brunofgc 4:13ff9c81dc10 187 ptr=strstr(bufIn,"*ServerCommand*");
brunofgc 4:13ff9c81dc10 188 if(ptr) {
brunofgc 4:13ff9c81dc10 189 //naoCompreendido=false;
brunofgc 4:13ff9c81dc10 190 scanPtr = strtok (ptr,"\\");
brunofgc 4:13ff9c81dc10 191 scanPtr = strtok (NULL,">");
brunofgc 4:13ff9c81dc10 192 strcpy(commands::buffer,scanPtr);
brunofgc 4:13ff9c81dc10 193 pc.printf("Comandos <%s>.\n",commands::buffer);
brunofgc 4:13ff9c81dc10 194 executaComandoServer = true;
brunofgc 4:13ff9c81dc10 195 //Se devo executar comando tenho que sair imediatamente.
brunofgc 4:13ff9c81dc10 196 return;
brunofgc 4:13ff9c81dc10 197 }
brunofgc 4:13ff9c81dc10 198
brunofgc 0:1c0a769988ee 199 if(strstr(bufIn,"writeReadingsToSD()")){
brunofgc 18:1eefda1f7736 200 eventosRTC::rotinaEnvioDeDados = maxTentativasEnvioDados;
brunofgc 0:1c0a769988ee 201 return;
brunofgc 0:1c0a769988ee 202 }
brunofgc 0:1c0a769988ee 203
brunofgc 0:1c0a769988ee 204 //bufLength
brunofgc 0:1c0a769988ee 205 /*
brunofgc 0:1c0a769988ee 206 stack overflow de thread...
brunofgc 0:1c0a769988ee 207 if(strstr(bufIn,"execAct(")){
brunofgc 0:1c0a769988ee 208 strtok(bufIn,"(");
brunofgc 0:1c0a769988ee 209 bufLength = atoi(strtok(NULL,")"));
brunofgc 0:1c0a769988ee 210 dispositivos[0]->execAct(bufLength);
brunofgc 0:1c0a769988ee 211 return;
brunofgc 0:1c0a769988ee 212 }
brunofgc 0:1c0a769988ee 213 */
brunofgc 0:1c0a769988ee 214 //Se chegou aqui é pq não foi uma mensagem reconhecida.
brunofgc 0:1c0a769988ee 215 pc.printf("Lido do CircularBuffer PC <%s>.\r\n",bufIn);
brunofgc 0:1c0a769988ee 216 }