teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
serialPC.cpp@33:a60abda630f7, 2018-05-30 (annotated)
- Committer:
- brunofgc
- Date:
- Wed May 30 04:24:55 2018 +0000
- Revision:
- 33:a60abda630f7
- Parent:
- 31:a1ba855c6e8a
- Child:
- 34:348991c54ff3
Ultima vers?o feita com bootloader ruim. 29/05/2018
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 | 0:1c0a769988ee | 33 | uint16_t bufLength = bufPC.getLength(); |
brunofgc | 0:1c0a769988ee | 34 | bufIn = bufPC.get(); |
brunofgc | 0:1c0a769988ee | 35 | |
brunofgc | 0:1c0a769988ee | 36 | |
brunofgc | 7:ae9c47f62946 | 37 | if(strstr(bufIn,"execAct(")){ |
brunofgc | 7:ae9c47f62946 | 38 | strtok(bufIn,"("); |
brunofgc | 7:ae9c47f62946 | 39 | act=atoi(strtok(NULL,")")); |
brunofgc | 7:ae9c47f62946 | 40 | boolExecAct = true; |
brunofgc | 7:ae9c47f62946 | 41 | return; |
brunofgc | 7:ae9c47f62946 | 42 | } |
brunofgc | 30:8a06a85d8807 | 43 | |
brunofgc | 0:1c0a769988ee | 44 | if(strstr(bufIn,"modem:")!=NULL){ |
brunofgc | 0:1c0a769988ee | 45 | bufIn = &bufIn[6]; |
brunofgc | 0:1c0a769988ee | 46 | pc.printf("Mensagem ao modem <%s>.\r\n",bufIn); |
brunofgc | 31:a1ba855c6e8a | 47 | modemCom::sendToModem(bufIn,1,NULL,NULL,150,1,1); |
brunofgc | 7:ae9c47f62946 | 48 | pc.printf("Mesagem do modem <%s>.\r\n",bufModem.getRowBuffer()); |
brunofgc | 0:1c0a769988ee | 49 | return; |
brunofgc | 0:1c0a769988ee | 50 | } |
brunofgc | 30:8a06a85d8807 | 51 | |
brunofgc | 30:8a06a85d8807 | 52 | if(strstr(bufIn,"config")!=NULL){ |
brunofgc | 9:cf406384efd9 | 53 | sdCard::exibeArquivo(&sdCard::config); |
brunofgc | 9:cf406384efd9 | 54 | } |
brunofgc | 9:cf406384efd9 | 55 | |
brunofgc | 30:8a06a85d8807 | 56 | if(strstr(bufIn,"devices")!=NULL){ |
brunofgc | 30:8a06a85d8807 | 57 | sdCard::exibeArquivo(&sdCard::devices); |
brunofgc | 30:8a06a85d8807 | 58 | } |
brunofgc | 2:55b7b466e742 | 59 | |
brunofgc | 1:0e0967c88590 | 60 | if(strstr(bufIn,"testaTudoDevices()")!=NULL){ |
brunofgc | 1:0e0967c88590 | 61 | testaTudoDevices(); |
brunofgc | 0:1c0a769988ee | 62 | } |
brunofgc | 0:1c0a769988ee | 63 | |
brunofgc | 29:823a9da3696b | 64 | ptr=strstr(bufIn,"deleteArmazenamento"); |
brunofgc | 29:823a9da3696b | 65 | if(ptr){ |
brunofgc | 30:8a06a85d8807 | 66 | pc.printf("Deletando banks.\r\n"); |
brunofgc | 30:8a06a85d8807 | 67 | sdCard::deleteBanks(2); |
brunofgc | 30:8a06a85d8807 | 68 | } |
brunofgc | 30:8a06a85d8807 | 69 | |
brunofgc | 30:8a06a85d8807 | 70 | if(strstr(bufIn,"enviaDadosAoServer")){ |
brunofgc | 30:8a06a85d8807 | 71 | eventosRTC::rotinaEnvioDeDados=maxTentativasEnvioDados; |
brunofgc | 33:a60abda630f7 | 72 | modemCom::timeOutEnvioDados=maxTimeEnvioDados; |
brunofgc | 29:823a9da3696b | 73 | } |
brunofgc | 30:8a06a85d8807 | 74 | |
brunofgc | 33:a60abda630f7 | 75 | if(strstr(bufIn,"wdtReset")){ |
brunofgc | 33:a60abda630f7 | 76 | pc.printf("Comandando Reset por wdt.\r\n"); |
brunofgc | 33:a60abda630f7 | 77 | osDelay(50); |
brunofgc | 33:a60abda630f7 | 78 | diversos::wdt.kick(0.1); |
brunofgc | 33:a60abda630f7 | 79 | while(true); |
brunofgc | 33:a60abda630f7 | 80 | } |
brunofgc | 0:1c0a769988ee | 81 | |
brunofgc | 21:b9315cdd9275 | 82 | if(strstr(bufIn,"debug")){ |
brunofgc | 21:b9315cdd9275 | 83 | if(debug){debug = false;} |
brunofgc | 21:b9315cdd9275 | 84 | else{debug = true;} |
brunofgc | 21:b9315cdd9275 | 85 | } |
brunofgc | 0:1c0a769988ee | 86 | |
brunofgc | 30:8a06a85d8807 | 87 | if(strstr(bufIn,"xereta")){ |
brunofgc | 30:8a06a85d8807 | 88 | if(xeretaModem){debug = false;} |
brunofgc | 30:8a06a85d8807 | 89 | else{xeretaModem = true;} |
brunofgc | 30:8a06a85d8807 | 90 | } |
brunofgc | 10:263c093f8977 | 91 | |
brunofgc | 25:a6da63ed025b | 92 | if(strstr(bufIn,"excluiArquivoPeloNome:")!=NULL){ |
brunofgc | 25:a6da63ed025b | 93 | strtok(bufIn,":"); |
brunofgc | 25:a6da63ed025b | 94 | ptr = strtok(NULL,":"); |
brunofgc | 25:a6da63ed025b | 95 | remove(ptr); |
brunofgc | 25:a6da63ed025b | 96 | return; |
brunofgc | 25:a6da63ed025b | 97 | } |
brunofgc | 0:1c0a769988ee | 98 | |
brunofgc | 0:1c0a769988ee | 99 | if(strstr(bufIn,"excluiArquivo:devices.cfg")!=NULL){ |
brunofgc | 0:1c0a769988ee | 100 | sdCard::excluiArquivo(&sdCard::devices); |
brunofgc | 30:8a06a85d8807 | 101 | } |
brunofgc | 0:1c0a769988ee | 102 | } |