teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Wed Aug 09 20:38:10 2017 +0000
Revision:
9:cf406384efd9
Parent:
7:ae9c47f62946
Child:
10:263c093f8977
Ultima versao com enviaDados na thread comunicacoes;

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 0:1c0a769988ee 72 if(strstr(bufIn,"exibeArquivo:armazenamento.txt")!=NULL){
brunofgc 0:1c0a769988ee 73 sdCard::exibeArquivo(&sdCard::armazenamento);
brunofgc 0:1c0a769988ee 74 return;
brunofgc 2:55b7b466e742 75 }
brunofgc 2:55b7b466e742 76
brunofgc 9:cf406384efd9 77 if(strstr(bufIn,"exibeArquivo:config.bin")!=NULL){
brunofgc 9:cf406384efd9 78 sdCard::exibeArquivo(&sdCard::config);
brunofgc 9:cf406384efd9 79 return;
brunofgc 9:cf406384efd9 80 }
brunofgc 9:cf406384efd9 81
brunofgc 2:55b7b466e742 82 if(strstr(bufIn,"resetDigitais()")!=NULL){
brunofgc 2:55b7b466e742 83 SD_OE_R = 0;
brunofgc 2:55b7b466e742 84 osDelay(50);
brunofgc 2:55b7b466e742 85 SD_OE_R = 1;
brunofgc 2:55b7b466e742 86 return;
brunofgc 0:1c0a769988ee 87 }
brunofgc 2:55b7b466e742 88
brunofgc 2:55b7b466e742 89
brunofgc 1:0e0967c88590 90 if(strstr(bufIn,"testaTudoDevices()")!=NULL){
brunofgc 1:0e0967c88590 91 testaTudoDevices();
brunofgc 1:0e0967c88590 92 return;
brunofgc 1:0e0967c88590 93 }
brunofgc 1:0e0967c88590 94
brunofgc 0:1c0a769988ee 95
brunofgc 0:1c0a769988ee 96 if(strstr(bufIn,"exibeArquivo:tempFile.bin")!=NULL){
brunofgc 0:1c0a769988ee 97 sdCard::exibeArquivo(&sdCard::tempFile);
brunofgc 0:1c0a769988ee 98 return;
brunofgc 0:1c0a769988ee 99 }
brunofgc 0:1c0a769988ee 100
brunofgc 0:1c0a769988ee 101 if(strstr(bufIn,"exibeArquivo:envio.txt")!=NULL){
brunofgc 0:1c0a769988ee 102 sdCard::exibeArquivo(&sdCard::envio);
brunofgc 0:1c0a769988ee 103 return;
brunofgc 0:1c0a769988ee 104 }
brunofgc 0:1c0a769988ee 105
brunofgc 0:1c0a769988ee 106 if(strstr(bufIn,"enviaDadosAoServer")){
brunofgc 1:0e0967c88590 107 eventosRTC::rotina15Minutos=true;
brunofgc 0:1c0a769988ee 108 return;
brunofgc 0:1c0a769988ee 109 }
brunofgc 0:1c0a769988ee 110
brunofgc 7:ae9c47f62946 111
brunofgc 2:55b7b466e742 112
brunofgc 0:1c0a769988ee 113 if(strstr(bufIn,"enviaArquivoDevices")){
brunofgc 0:1c0a769988ee 114 arquivoEnvioPointer = &sdCard::devices;
brunofgc 0:1c0a769988ee 115 return;
brunofgc 0:1c0a769988ee 116 }
brunofgc 0:1c0a769988ee 117
brunofgc 0:1c0a769988ee 118 if(strstr(bufIn,"excluiArquivo:armazenamento.txt")!=NULL){
brunofgc 0:1c0a769988ee 119 sdCard::excluiArquivo(&sdCard::armazenamento);
brunofgc 0:1c0a769988ee 120 return;
brunofgc 9:cf406384efd9 121 }
brunofgc 9:cf406384efd9 122
brunofgc 9:cf406384efd9 123 if(strstr(bufIn,"excluiArquivo:config.bin")!=NULL){
brunofgc 9:cf406384efd9 124 sdCard::excluiArquivo(&sdCard::config);
brunofgc 9:cf406384efd9 125 return;
brunofgc 0:1c0a769988ee 126 }
brunofgc 0:1c0a769988ee 127
brunofgc 0:1c0a769988ee 128 if(strstr(bufIn,"excluiArquivo:envio.txt")!=NULL){
brunofgc 0:1c0a769988ee 129 sdCard::excluiArquivo(&sdCard::envio);
brunofgc 0:1c0a769988ee 130 return;
brunofgc 0:1c0a769988ee 131 }
brunofgc 0:1c0a769988ee 132
brunofgc 0:1c0a769988ee 133 if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 134 sdCard::excluiArquivo(&sdCard::devices);
brunofgc 0:1c0a769988ee 135 return;
brunofgc 0:1c0a769988ee 136 }
brunofgc 0:1c0a769988ee 137
brunofgc 7:ae9c47f62946 138 if(strstr(bufIn,"conectaWifi()")!=NULL){
brunofgc 7:ae9c47f62946 139 inicializaModemBool = true;
brunofgc 7:ae9c47f62946 140 return;
brunofgc 7:ae9c47f62946 141 }
brunofgc 7:ae9c47f62946 142
brunofgc 7:ae9c47f62946 143
brunofgc 7:ae9c47f62946 144
brunofgc 0:1c0a769988ee 145 if(strstr(bufIn,"exibeArquivo:devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 146 sdCard::exibeArquivo(&sdCard::devices);
brunofgc 0:1c0a769988ee 147 return;
brunofgc 4:13ff9c81dc10 148 }
brunofgc 4:13ff9c81dc10 149
brunofgc 4:13ff9c81dc10 150 ptr=strstr(bufIn,"*ServerCommand*");
brunofgc 4:13ff9c81dc10 151 if(ptr) {
brunofgc 4:13ff9c81dc10 152 //naoCompreendido=false;
brunofgc 4:13ff9c81dc10 153 scanPtr = strtok (ptr,"\\");
brunofgc 4:13ff9c81dc10 154 scanPtr = strtok (NULL,">");
brunofgc 4:13ff9c81dc10 155 strcpy(commands::buffer,scanPtr);
brunofgc 4:13ff9c81dc10 156 pc.printf("Comandos <%s>.\n",commands::buffer);
brunofgc 4:13ff9c81dc10 157 executaComandoServer = true;
brunofgc 4:13ff9c81dc10 158 //Se devo executar comando tenho que sair imediatamente.
brunofgc 4:13ff9c81dc10 159 return;
brunofgc 4:13ff9c81dc10 160 }
brunofgc 4:13ff9c81dc10 161
brunofgc 0:1c0a769988ee 162 if(strstr(bufIn,"writeReadingsToSD()")){
brunofgc 0:1c0a769988ee 163 eventosRTC::rotina15Minutos = true;
brunofgc 0:1c0a769988ee 164 return;
brunofgc 0:1c0a769988ee 165 }
brunofgc 0:1c0a769988ee 166
brunofgc 0:1c0a769988ee 167 //bufLength
brunofgc 0:1c0a769988ee 168 /*
brunofgc 0:1c0a769988ee 169 stack overflow de thread...
brunofgc 0:1c0a769988ee 170 if(strstr(bufIn,"execAct(")){
brunofgc 0:1c0a769988ee 171 strtok(bufIn,"(");
brunofgc 0:1c0a769988ee 172 bufLength = atoi(strtok(NULL,")"));
brunofgc 0:1c0a769988ee 173 dispositivos[0]->execAct(bufLength);
brunofgc 0:1c0a769988ee 174 return;
brunofgc 0:1c0a769988ee 175 }
brunofgc 0:1c0a769988ee 176 */
brunofgc 0:1c0a769988ee 177 //Se chegou aqui é pq não foi uma mensagem reconhecida.
brunofgc 0:1c0a769988ee 178 pc.printf("Lido do CircularBuffer PC <%s>.\r\n",bufIn);
brunofgc 0:1c0a769988ee 179 }