teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Mon Aug 14 13:59:27 2017 +0000
Revision:
10:263c093f8977
Parent:
9:cf406384efd9
Child:
15:0f78bf9c13ec
Ultima vers?o instalada na UCSal dia 10/08/2017

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 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 1:0e0967c88590 114 eventosRTC::rotina15Minutos=true;
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 0:1c0a769988ee 123 }
brunofgc 0:1c0a769988ee 124
brunofgc 10:263c093f8977 125
brunofgc 9:cf406384efd9 126
brunofgc 9:cf406384efd9 127 if(strstr(bufIn,"excluiArquivo:config.bin")!=NULL){
brunofgc 9:cf406384efd9 128 sdCard::excluiArquivo(&sdCard::config);
brunofgc 9:cf406384efd9 129 return;
brunofgc 0:1c0a769988ee 130 }
brunofgc 0:1c0a769988ee 131
brunofgc 10:263c093f8977 132 if(strstr(bufIn,"excluiArquivo:currentBank.txt")!=NULL){
brunofgc 10:263c093f8977 133 sdCard::excluiArquivo(&sdCard::currentBankFile);
brunofgc 0:1c0a769988ee 134 return;
brunofgc 10:263c093f8977 135 }
brunofgc 10:263c093f8977 136
brunofgc 10:263c093f8977 137
brunofgc 0:1c0a769988ee 138
brunofgc 0:1c0a769988ee 139 if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 140 sdCard::excluiArquivo(&sdCard::devices);
brunofgc 0:1c0a769988ee 141 return;
brunofgc 0:1c0a769988ee 142 }
brunofgc 0:1c0a769988ee 143
brunofgc 7:ae9c47f62946 144 if(strstr(bufIn,"conectaWifi()")!=NULL){
brunofgc 7:ae9c47f62946 145 inicializaModemBool = true;
brunofgc 7:ae9c47f62946 146 return;
brunofgc 7:ae9c47f62946 147 }
brunofgc 7:ae9c47f62946 148
brunofgc 7:ae9c47f62946 149
brunofgc 7:ae9c47f62946 150
brunofgc 0:1c0a769988ee 151 if(strstr(bufIn,"exibeArquivo:devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 152 sdCard::exibeArquivo(&sdCard::devices);
brunofgc 0:1c0a769988ee 153 return;
brunofgc 4:13ff9c81dc10 154 }
brunofgc 4:13ff9c81dc10 155
brunofgc 4:13ff9c81dc10 156 ptr=strstr(bufIn,"*ServerCommand*");
brunofgc 4:13ff9c81dc10 157 if(ptr) {
brunofgc 4:13ff9c81dc10 158 //naoCompreendido=false;
brunofgc 4:13ff9c81dc10 159 scanPtr = strtok (ptr,"\\");
brunofgc 4:13ff9c81dc10 160 scanPtr = strtok (NULL,">");
brunofgc 4:13ff9c81dc10 161 strcpy(commands::buffer,scanPtr);
brunofgc 4:13ff9c81dc10 162 pc.printf("Comandos <%s>.\n",commands::buffer);
brunofgc 4:13ff9c81dc10 163 executaComandoServer = true;
brunofgc 4:13ff9c81dc10 164 //Se devo executar comando tenho que sair imediatamente.
brunofgc 4:13ff9c81dc10 165 return;
brunofgc 4:13ff9c81dc10 166 }
brunofgc 4:13ff9c81dc10 167
brunofgc 0:1c0a769988ee 168 if(strstr(bufIn,"writeReadingsToSD()")){
brunofgc 0:1c0a769988ee 169 eventosRTC::rotina15Minutos = true;
brunofgc 0:1c0a769988ee 170 return;
brunofgc 0:1c0a769988ee 171 }
brunofgc 0:1c0a769988ee 172
brunofgc 0:1c0a769988ee 173 //bufLength
brunofgc 0:1c0a769988ee 174 /*
brunofgc 0:1c0a769988ee 175 stack overflow de thread...
brunofgc 0:1c0a769988ee 176 if(strstr(bufIn,"execAct(")){
brunofgc 0:1c0a769988ee 177 strtok(bufIn,"(");
brunofgc 0:1c0a769988ee 178 bufLength = atoi(strtok(NULL,")"));
brunofgc 0:1c0a769988ee 179 dispositivos[0]->execAct(bufLength);
brunofgc 0:1c0a769988ee 180 return;
brunofgc 0:1c0a769988ee 181 }
brunofgc 0:1c0a769988ee 182 */
brunofgc 0:1c0a769988ee 183 //Se chegou aqui é pq não foi uma mensagem reconhecida.
brunofgc 0:1c0a769988ee 184 pc.printf("Lido do CircularBuffer PC <%s>.\r\n",bufIn);
brunofgc 0:1c0a769988ee 185 }