protegemed, aquisição via A/D simples utilizando interrupção do timer
Dependencies: EthernetInterface NTPClient mbed-rtos mbed
Fork of ptgm_semDMA by
main.cpp@1:8129536051df, 2016-01-13 (annotated)
- Committer:
- viniciushl
- Date:
- Wed Jan 13 18:53:25 2016 +0000
- Revision:
- 1:8129536051df
- Parent:
- 0:fac116e94d44
Alterada captura para aquisi??o simples do A/D utilizando interrup??o do timer;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rebonatto | 0:fac116e94d44 | 1 | /* |
rebonatto | 0:fac116e94d44 | 2 | Projeto teste de Enviar dados coletados sem calcular a FFT. |
rebonatto | 0:fac116e94d44 | 3 | Aquisição das amostras realizada sem DMA |
rebonatto | 0:fac116e94d44 | 4 | |
rebonatto | 0:fac116e94d44 | 5 | */ |
rebonatto | 0:fac116e94d44 | 6 | |
viniciushl | 1:8129536051df | 7 | #define MSGWINDOW "Version 5" |
rebonatto | 0:fac116e94d44 | 8 | |
rebonatto | 0:fac116e94d44 | 9 | #include <stdio.h> |
rebonatto | 0:fac116e94d44 | 10 | |
rebonatto | 0:fac116e94d44 | 11 | #include "mbed.h" |
rebonatto | 0:fac116e94d44 | 12 | #include "rtos.h" |
rebonatto | 0:fac116e94d44 | 13 | #include "cmsis_os.h" |
rebonatto | 0:fac116e94d44 | 14 | #include "EthernetInterface.h" |
rebonatto | 0:fac116e94d44 | 15 | #include "Settings.h" |
rebonatto | 0:fac116e94d44 | 16 | #include "Capture.h" |
rebonatto | 0:fac116e94d44 | 17 | #include "Http_post.h" |
rebonatto | 0:fac116e94d44 | 18 | #include "SignalProcessor.h" |
rebonatto | 0:fac116e94d44 | 19 | #include "EventDetector.h" |
rebonatto | 0:fac116e94d44 | 20 | #include "limites.h" |
rebonatto | 0:fac116e94d44 | 21 | |
rebonatto | 0:fac116e94d44 | 22 | #include "TelnetServer.h" |
rebonatto | 0:fac116e94d44 | 23 | |
rebonatto | 0:fac116e94d44 | 24 | #include "tftpsrv.h" |
rebonatto | 0:fac116e94d44 | 25 | #include "ntpc.h" |
rebonatto | 0:fac116e94d44 | 26 | |
rebonatto | 0:fac116e94d44 | 27 | #include "PmedLog.h" |
rebonatto | 0:fac116e94d44 | 28 | |
rebonatto | 0:fac116e94d44 | 29 | #include "NTPClient.h" |
rebonatto | 0:fac116e94d44 | 30 | |
rebonatto | 0:fac116e94d44 | 31 | #include "whatchdog.h" |
rebonatto | 0:fac116e94d44 | 32 | |
rebonatto | 0:fac116e94d44 | 33 | EthernetInterface eth; |
rebonatto | 0:fac116e94d44 | 34 | Watchdog wdt; |
rebonatto | 0:fac116e94d44 | 35 | |
rebonatto | 0:fac116e94d44 | 36 | Semaphore tranca(1); |
rebonatto | 0:fac116e94d44 | 37 | |
rebonatto | 0:fac116e94d44 | 38 | void InitializeEthernetLink() |
rebonatto | 0:fac116e94d44 | 39 | { |
rebonatto | 0:fac116e94d44 | 40 | if(Settings::get_Dhcp()) |
rebonatto | 0:fac116e94d44 | 41 | //EthernetIf::Initialize(); //Use DHCP |
rebonatto | 0:fac116e94d44 | 42 | eth.init(); //Use DHCP |
rebonatto | 0:fac116e94d44 | 43 | else |
rebonatto | 0:fac116e94d44 | 44 | //EthernetIf::Initialize(Settings::get_IpAddress(),Settings::get_Netmask(),Settings::get_Gateway()); |
rebonatto | 0:fac116e94d44 | 45 | eth.init(Settings::get_IpAddress(),Settings::get_Netmask(),Settings::get_Gateway()); |
rebonatto | 0:fac116e94d44 | 46 | |
rebonatto | 0:fac116e94d44 | 47 | //EthernetIf::Connect(); |
rebonatto | 0:fac116e94d44 | 48 | eth.connect(); |
rebonatto | 0:fac116e94d44 | 49 | //printf("IP Address is %s\n", EthernetIf::get_IpAddress()); |
rebonatto | 0:fac116e94d44 | 50 | printf("IP Address is NEW %s\n", eth.getIPAddress()); |
rebonatto | 0:fac116e94d44 | 51 | } |
rebonatto | 0:fac116e94d44 | 52 | |
rebonatto | 0:fac116e94d44 | 53 | int main() { |
viniciushl | 1:8129536051df | 54 | |
viniciushl | 1:8129536051df | 55 | |
rebonatto | 0:fac116e94d44 | 56 | float inicio, fim, maior, menor, dif; |
rebonatto | 0:fac116e94d44 | 57 | float inicioc, fimc, maiorc, menorc, difc; |
rebonatto | 0:fac116e94d44 | 58 | Timer t,tc; |
viniciushl | 1:8129536051df | 59 | /* |
rebonatto | 0:fac116e94d44 | 60 | if ((LPC_WDT->WDMOD >> 2) & 1){ |
rebonatto | 0:fac116e94d44 | 61 | //myled4 = 1; |
rebonatto | 0:fac116e94d44 | 62 | PmedLog::WriteEntry(PMEDLOG_INITIALIZINGWDT); |
rebonatto | 0:fac116e94d44 | 63 | } |
rebonatto | 0:fac116e94d44 | 64 | else{ |
rebonatto | 0:fac116e94d44 | 65 | //myled3 = 1; |
rebonatto | 0:fac116e94d44 | 66 | PmedLog::WriteEntry(PMEDLOG_INITIALIZING); |
viniciushl | 1:8129536051df | 67 | }*/ |
rebonatto | 0:fac116e94d44 | 68 | |
rebonatto | 0:fac116e94d44 | 69 | printf("\r\n %s \r\n", MSGWINDOW); |
viniciushl | 1:8129536051df | 70 | |
rebonatto | 0:fac116e94d44 | 71 | FILE *f; |
rebonatto | 0:fac116e94d44 | 72 | |
viniciushl | 1:8129536051df | 73 | Settings::ReadFile(); |
viniciushl | 1:8129536051df | 74 | printf("\r\n\nCANAL\tOFFSET\t\tGAIN"); |
viniciushl | 1:8129536051df | 75 | |
rebonatto | 0:fac116e94d44 | 76 | InitializeEthernetLink(); |
rebonatto | 0:fac116e94d44 | 77 | printf("Inicializou link Ethernet\n"); |
rebonatto | 0:fac116e94d44 | 78 | |
rebonatto | 0:fac116e94d44 | 79 | //Start HTTP POST service |
rebonatto | 0:fac116e94d44 | 80 | Thread http_post(HttpPost::HttpPost_Thread); |
viniciushl | 1:8129536051df | 81 | |
viniciushl | 1:8129536051df | 82 | |
rebonatto | 0:fac116e94d44 | 83 | //Start Telnet Service |
rebonatto | 0:fac116e94d44 | 84 | //Thread telnetserver(TelnetServer::TelnetServer_Thread); |
rebonatto | 0:fac116e94d44 | 85 | |
rebonatto | 0:fac116e94d44 | 86 | //Start TFTP Service |
rebonatto | 0:fac116e94d44 | 87 | //Thread tftpsrv(tftpsrv::tftpsrv_Thread); |
rebonatto | 0:fac116e94d44 | 88 | |
rebonatto | 0:fac116e94d44 | 89 | //Start NTP Client for refresh time |
rebonatto | 0:fac116e94d44 | 90 | //Thread ntpc(ntpc::ntpc_Thread); |
rebonatto | 0:fac116e94d44 | 91 | time_t tempo = time(NULL); |
rebonatto | 0:fac116e94d44 | 92 | if ((tempo+60) < 1420077600) set_time(1420077600); |
rebonatto | 0:fac116e94d44 | 93 | |
rebonatto | 0:fac116e94d44 | 94 | // ntpClient.setTime("192.168.103.101"); |
rebonatto | 0:fac116e94d44 | 95 | |
rebonatto | 0:fac116e94d44 | 96 | DisplayRAMBanks(); |
rebonatto | 0:fac116e94d44 | 97 | |
rebonatto | 0:fac116e94d44 | 98 | printf(PMEDLOG_INITIALIZINGWDT); |
rebonatto | 0:fac116e94d44 | 99 | printf("\n\n"); |
rebonatto | 0:fac116e94d44 | 100 | |
viniciushl | 1:8129536051df | 101 | //PmedLog::WriteEntry(PMEDLOG_STARTED); |
rebonatto | 0:fac116e94d44 | 102 | |
viniciushl | 1:8129536051df | 103 | /* start test WatchDog */ |
viniciushl | 1:8129536051df | 104 | |
viniciushl | 1:8129536051df | 105 | int n = 0; |
rebonatto | 0:fac116e94d44 | 106 | //int tatual, tnovo; |
rebonatto | 0:fac116e94d44 | 107 | float rms[NUMBER_OF_CHANNELS], mv2[NUMBER_OF_CHANNELS]; |
rebonatto | 0:fac116e94d44 | 108 | int under[NUMBER_OF_CHANNELS], over[NUMBER_OF_CHANNELS]; |
rebonatto | 0:fac116e94d44 | 109 | |
viniciushl | 1:8129536051df | 110 | //wdt.kick(10.0); |
rebonatto | 0:fac116e94d44 | 111 | |
viniciushl | 1:8129536051df | 112 | Capture::InitializeAD(); |
viniciushl | 1:8129536051df | 113 | int cont1 = 0; |
viniciushl | 1:8129536051df | 114 | |
rebonatto | 0:fac116e94d44 | 115 | while(1) |
rebonatto | 0:fac116e94d44 | 116 | { |
viniciushl | 1:8129536051df | 117 | /*tranca.wait(); |
rebonatto | 0:fac116e94d44 | 118 | t.start(); |
rebonatto | 0:fac116e94d44 | 119 | inicio = t.read(); |
viniciushl | 1:8129536051df | 120 | */ |
rebonatto | 0:fac116e94d44 | 121 | //get sample values from 6 channels |
rebonatto | 0:fac116e94d44 | 122 | Capture::AcquireValues(); |
rebonatto | 0:fac116e94d44 | 123 | |
rebonatto | 0:fac116e94d44 | 124 | fim = t.read(); |
rebonatto | 0:fac116e94d44 | 125 | dif = fim-inicio; |
rebonatto | 0:fac116e94d44 | 126 | |
rebonatto | 0:fac116e94d44 | 127 | if (n == 0) |
rebonatto | 0:fac116e94d44 | 128 | maior = menor = dif; |
rebonatto | 0:fac116e94d44 | 129 | |
rebonatto | 0:fac116e94d44 | 130 | if (dif > maior) |
rebonatto | 0:fac116e94d44 | 131 | maior = dif; |
rebonatto | 0:fac116e94d44 | 132 | if (dif < menor) |
rebonatto | 0:fac116e94d44 | 133 | menor = dif; |
rebonatto | 0:fac116e94d44 | 134 | t.reset(); |
rebonatto | 0:fac116e94d44 | 135 | t.stop(); |
viniciushl | 1:8129536051df | 136 | //tranca.release(); |
rebonatto | 0:fac116e94d44 | 137 | |
viniciushl | 1:8129536051df | 138 | //tranca.wait(); |
rebonatto | 0:fac116e94d44 | 139 | tc.start(); |
rebonatto | 0:fac116e94d44 | 140 | inicioc = tc.read(); |
rebonatto | 0:fac116e94d44 | 141 | // Calcula o RMS dos 6 canais |
rebonatto | 0:fac116e94d44 | 142 | SignalProcessor::CalculateRMSBulk(rms, mv2, under, over); |
viniciushl | 1:8129536051df | 143 | /* |
viniciushl | 1:8129536051df | 144 | printf("\r\n\nCANAL\tOFFSET\t\tGAIN"); |
viniciushl | 1:8129536051df | 145 | for (int i=0;i<6;i++) |
viniciushl | 1:8129536051df | 146 | { |
viniciushl | 1:8129536051df | 147 | printf("\r\n%d\t%d\t\t%4.2f", i, Settings::get_Offset(i), Settings::get_Gain(i)); |
viniciushl | 1:8129536051df | 148 | } |
viniciushl | 1:8129536051df | 149 | |
viniciushl | 1:8129536051df | 150 | |
viniciushl | 1:8129536051df | 151 | printf("\r\n\n\tRMS\t\tMV2\t\tUNDER\t\tOVER"); |
viniciushl | 1:8129536051df | 152 | for (int i=0;i<6;i++) |
viniciushl | 1:8129536051df | 153 | { |
viniciushl | 1:8129536051df | 154 | printf("\r\n%d\t%4.2f\t\t%4.2f\t\t%d\t\t%d", i, rms[i], mv2[i], under[i], over[i]); |
viniciushl | 1:8129536051df | 155 | } |
viniciushl | 1:8129536051df | 156 | printf("\n"); |
viniciushl | 1:8129536051df | 157 | */ |
viniciushl | 1:8129536051df | 158 | |
rebonatto | 0:fac116e94d44 | 159 | fimc = tc.read(); |
rebonatto | 0:fac116e94d44 | 160 | difc = fimc-inicioc; |
rebonatto | 0:fac116e94d44 | 161 | |
rebonatto | 0:fac116e94d44 | 162 | if (n == 0) |
rebonatto | 0:fac116e94d44 | 163 | maiorc = menorc = difc; |
rebonatto | 0:fac116e94d44 | 164 | |
rebonatto | 0:fac116e94d44 | 165 | if (difc > maiorc) |
rebonatto | 0:fac116e94d44 | 166 | maiorc = difc; |
rebonatto | 0:fac116e94d44 | 167 | if (difc < menorc) |
rebonatto | 0:fac116e94d44 | 168 | menorc = difc; |
rebonatto | 0:fac116e94d44 | 169 | |
viniciushl | 1:8129536051df | 170 | for(int i=0;i<6;i++){ |
rebonatto | 0:fac116e94d44 | 171 | EventDetector::get_Detector(i).ProcessEvent(rms[i], mv2[i], under[i], over[i]); |
rebonatto | 0:fac116e94d44 | 172 | } |
rebonatto | 0:fac116e94d44 | 173 | |
rebonatto | 0:fac116e94d44 | 174 | n++; |
rebonatto | 0:fac116e94d44 | 175 | if(n % 60 == 0) |
rebonatto | 0:fac116e94d44 | 176 | { |
rebonatto | 0:fac116e94d44 | 177 | printf("%.2f %.0f %.2f %.0f\t%.2f %.0f %.2f %.0f\t%.2f %.0f %.2f %.0f\n",rms[0], mv2[0],rms[1],mv2[1],rms[2],mv2[2],rms[3],mv2[3],rms[4],mv2[4],rms[5],mv2[5]); |
viniciushl | 1:8129536051df | 178 | //led1 = !led1; |
rebonatto | 0:fac116e94d44 | 179 | // n=0; |
rebonatto | 0:fac116e94d44 | 180 | |
rebonatto | 0:fac116e94d44 | 181 | PmedLog::Mark(); |
rebonatto | 0:fac116e94d44 | 182 | } |
rebonatto | 0:fac116e94d44 | 183 | |
rebonatto | 0:fac116e94d44 | 184 | if (n % 600 == 0){ |
rebonatto | 0:fac116e94d44 | 185 | printf("Captura: Maior %f Menor %f\tCalculo Maior %f Menor %f\n", maior, menor, maiorc, menorc); |
rebonatto | 0:fac116e94d44 | 186 | } |
rebonatto | 0:fac116e94d44 | 187 | |
rebonatto | 0:fac116e94d44 | 188 | // End of main loop so "kick" to reset watchdog timer and avoid a reset |
viniciushl | 1:8129536051df | 189 | //wdt.kick(); |
rebonatto | 0:fac116e94d44 | 190 | tc.reset(); |
rebonatto | 0:fac116e94d44 | 191 | tc.stop(); |
viniciushl | 1:8129536051df | 192 | //tranca.release(); |
rebonatto | 0:fac116e94d44 | 193 | } |
rebonatto | 0:fac116e94d44 | 194 | |
rebonatto | 0:fac116e94d44 | 195 | while(1){//never reaches here |
rebonatto | 0:fac116e94d44 | 196 | PmedLog::WriteEntry(PMEDLOG_WRONGCODE); |
rebonatto | 0:fac116e94d44 | 197 | printf("Reset\n"); |
rebonatto | 0:fac116e94d44 | 198 | f = fopen(FILENAMERESET, "a"); |
rebonatto | 0:fac116e94d44 | 199 | if (f == NULL) |
rebonatto | 0:fac116e94d44 | 200 | f = fopen(FILENAMERESET, "w"); |
rebonatto | 0:fac116e94d44 | 201 | fprintf(f, "Laco Errado\n"); |
rebonatto | 0:fac116e94d44 | 202 | fclose(f); |
rebonatto | 0:fac116e94d44 | 203 | Thread::yield(); |
rebonatto | 0:fac116e94d44 | 204 | } |
rebonatto | 0:fac116e94d44 | 205 | } |
rebonatto | 0:fac116e94d44 | 206 |