Versão limpa em 04/09/2014. Telnet funcionando.

Dependencies:   EthernetInterface mbed-rtos mbed NTPClient

Files at this revision

API Documentation at this revision

Comitter:
rebonatto
Date:
Fri May 01 14:46:08 2015 +0000
Parent:
30:9bf44d2785d5
Child:
32:8b108d8089e8
Commit message:
Ajustes para processar FFT com float e retirar o vm das amostras.

Changed in this revision

Codes/Capture.cpp Show annotated file Show diff for this revision Revisions of this file
Codes/EventDetector.cpp Show annotated file Show diff for this revision Revisions of this file
Codes/SignalProcessor.cpp Show annotated file Show diff for this revision Revisions of this file
Headers/Capture.h Show annotated file Show diff for this revision Revisions of this file
Headers/EventDetector.h Show annotated file Show diff for this revision Revisions of this file
Headers/SignalProcessor.h Show annotated file Show diff for this revision Revisions of this file
--- a/Codes/Capture.cpp	Tue Apr 28 14:38:37 2015 +0000
+++ b/Codes/Capture.cpp	Fri May 01 14:46:08 2015 +0000
@@ -83,6 +83,14 @@
     }
 }
 
+void Capture::CopyBufferFloat(int channel, float *dest)
+{
+    for(int i=0;i<NUMBER_OF_SAMPLES;i++)
+    {
+        dest[i] = (float) GetValue(i,channel);
+    }
+}
+
 //DMA ISR signals the capture thread about the end of capture event
 extern "C" void DMA_IRQHandler(void)
 {
--- a/Codes/EventDetector.cpp	Tue Apr 28 14:38:37 2015 +0000
+++ b/Codes/EventDetector.cpp	Fri May 01 14:46:08 2015 +0000
@@ -11,8 +11,7 @@
  #define MARCA 10
  #define GERAFUGA 0
  #define UMCICLO 16.666666667
- #define ZEROMV 1
-
+ 
 CaptureMailbox EventDetector::m_EventMailbox;
 EventDetector EventDetector::m_Detector[NUMBER_OF_CHANNELS] = {0,1,2,3,4,5};
 
@@ -48,7 +47,8 @@
 //void EventDetector::ProcessEvent(float rmsvalue, int t)
 void EventDetector::ProcessEvent(float rmsvalue, float mv2, int under, int over)
 {
-    int tempofuga = 0;    
+    int i, tempofuga = 0;    
+    float buf[NUMBER_OF_SAMPLES*2];    
     
     //Thread::wait(500);//TimeDelay(t));
     //printf("%d time delay\n", TimeDelay(t));
@@ -63,7 +63,7 @@
         Capture::Stop();              
         //printf("Passou Stop\n");
         //CommTCP::RequestAcom();
-        OnTrigger(rmsvalue, mv2, under, over, 0);       //TODO: must change the parameter of this function call
+        OnTrigger(NULL,rmsvalue, mv2, under, over, 0);       //TODO: must change the parameter of this function call
         //printf("Passou OnTriger\n");        
         Capture::Start();
         //printf("Passou Start\n");
@@ -78,7 +78,7 @@
         m_OutletTriggered = false;
         Capture::Stop();
         //printf("Passou Stop\n");
-        OnTrigger(rmsvalue, mv2, under, over, 0);//TODO: must change the parameter of this function call
+        OnTrigger(NULL, rmsvalue, mv2, under, over, 0);//TODO: must change the parameter of this function call
         //printf("Passou onTrigger\n");
         Capture::Start();
         //printf("Passou Start\n");
@@ -99,44 +99,46 @@
         */    
         if(rmsvalue > Settings::get_Limit(m_Channel))                
         {
-            if ( ZEROMV ) // verifica se é para retirar o VM
-            {
-                short int buf[NUMBER_OF_SAMPLES];
-                int i;
-                float newvm = 0;
-                Capture::CopyBufferSigned(m_Channel,buf);
+            /* Retira o VM das amostras */
+            //pega os dados da captura atual
+            mv2 = 0;
+            Capture::CopyBufferFloat(m_Channel,buf);
+            
+            /* Retira o valorMedio de todas as amostras */
+            for(i=0; i < NUMBER_OF_SAMPLES; i++){
+                buf[i] -= mv2;
+                mv2 += buf[i];
+            }
+            if ( m_EventCounter == Settings::get_EventLimit() ){                    
+                mv2 = mv2 / NUMBER_OF_SAMPLES;
+                printf("Novo valor medio %f RMS original %f\n", mv2, rmsvalue);
+            }
                 
-                /* Retira o valorMedio de todas as amostras */
-                for(i=0; i < NUMBER_OF_SAMPLES; i++){
-                    buf[i] -= (int) mv2;
-                    newvm += buf[i];
-                }
-                if ( m_EventCounter == Settings::get_EventLimit() ){                    
-                    newvm = newvm / NUMBER_OF_SAMPLES;
-                    printf("Novo valor medio %.0f\n", newvm);
-                }
-                    
-                rmsvalue = SignalProcessor::CalculateRMSSigned(buf, m_Channel);
-            }
+            rmsvalue = SignalProcessor::CalculateRMSSigned(buf, m_Channel);
+            if ( m_EventCounter == Settings::get_EventLimit() )
+                printf("novo RMS %f\n", rmsvalue);                
+
             
             if(!m_OutletTriggered)
             {
-                if(m_EventCounter < Settings::get_EventLimit())
-                {
-                    m_EventCounter++;
-                }
-                else
-                {
-                    //printf("Deu evento de liga ou Fuga\n");
-                    if (m_Channel % 2 ==  1) // Canais impares sao de diferencial
-                        m_tempo.start();
-                    m_OutletTriggered = true;  
-                    Capture::Stop();              
-                    OnTrigger(rmsvalue, mv2, under, over, 0); //TODO: must change the parameter of this function call
-                    //CommTCP::RequestAcom();
-                    //zzz
-                    Capture::Start();
-                    m_EventCounter = 0;
+                if (rmsvalue > Settings::get_Limit(m_Channel)) {
+                    if(m_EventCounter < Settings::get_EventLimit() )
+                    {
+                        m_EventCounter++;
+                    }
+                    else
+                    {
+                        //printf("Deu evento de liga ou Fuga\n");
+                        if (m_Channel % 2 ==  1) // Canais impares sao de diferencial
+                            m_tempo.start();
+                        m_OutletTriggered = true;  
+                        Capture::Stop();              
+                        OnTrigger(buf, rmsvalue, mv2, under, over, 0); //TODO: must change the parameter of this function call
+                        //CommTCP::RequestAcom();
+                        //zzz
+                        Capture::Start();
+                        m_EventCounter = 0;
+                    }
                 }
             }
             else
@@ -163,7 +165,7 @@
                         tempofuga = 0;
                     m_OutletTriggered = false;
                     Capture::Stop();
-                    OnTrigger(rmsvalue, mv2, under, over, tempofuga);//TODO: must change the parameter of this function call
+                    OnTrigger(buf, rmsvalue, mv2, under, over, tempofuga);//TODO: must change the parameter of this function call
                     //printf("===> contliga %d contdesliga %d\n", contliga, contdesl);
                     //zzz
                     Capture::Start();                    
@@ -199,9 +201,9 @@
 }
 
 //void EventDetector::OnTrigger(float rmsvalue)
-void EventDetector::OnTrigger(float rmsvalue, float mv2, int under, int over, int duration)
+void EventDetector::OnTrigger(float *buf, float rmsvalue, float mv2, int under, int over, int duration)
 {
-    SendMessage(0,rmsvalue, mv2, under, over, duration);
+    SendMessage(0, buf, rmsvalue, mv2, under, over, duration);
     //printf("Ontrigger::Enviou mensagem\n");
     /*
     if(m_OutletTriggered)
@@ -222,11 +224,11 @@
 void EventDetector::ExternalTrigger()
 {
     // Ajustar valores de mv2, under, over e duration na chamada!!!
-    SendMessage(1, 0, 0, 0, 0, 0);
+    SendMessage(1, NULL, 0, 0, 0, 0, 0);
 }
 
 //void EventDetector::SendMessage(int ext,float rmsvalue)
-void EventDetector::SendMessage(int ext, float rmsvalue, float mv2, int under, int over, int duration)
+void EventDetector::SendMessage(int ext, float *buf, float rmsvalue, float mv2, int under, int over, int duration)
 {       
     int flagrfid = 0;
     //printf("Chegou SendMessage\n");
@@ -235,9 +237,10 @@
     //printf("Capturou evento\n");
     //then initialize the object properly
     
+    /* O buffer foi coletado no ProcessEvent para retirada do VM
     unsigned short int buf[NUMBER_OF_SAMPLES];
     Capture::CopyBuffer(m_Channel,buf);
-    
+    */
     if(ext)
     {
         rmsvalue = 0;//SignalProcessor::CalculateRMS(buf,m_Channel);
--- a/Codes/SignalProcessor.cpp	Tue Apr 28 14:38:37 2015 +0000
+++ b/Codes/SignalProcessor.cpp	Fri May 01 14:46:08 2015 +0000
@@ -97,18 +97,9 @@
     result = sqrt(result);
     return result;
 }
-
  
-void SignalProcessor::CalculateFFT(unsigned short int *buffer,float *sen,float *cos,float *vm,int sign, int ch)
-{
-    /*
-    printf("Tamanho float %lu\n", sizeof(float));        
-    printf("Tamanho double %lu\n", sizeof(double));        
-    printf("Tamanho unsigned short int %lu\n", sizeof(unsigned short int));   
-    printf("Tamanho unsigned long %lu\n", sizeof(unsigned long));   
-    printf("Tamanho unsigned long long %lu\n", sizeof(unsigned long long));       
-    */   
-    
+void SignalProcessor::CalculateFFT(float *buffer,float *sen,float *cos,float *vm,int sign, int ch)
+{    
     /*
     for(int i=0; i < Settings::get_Samples(); i++)
         printf("%d*",buffer[i]);
@@ -159,11 +150,11 @@
     //printf("[3] %d %d %d %d\n", buffer[0], buffer[100], buffer[200], buffer[255]);
 }
 
-float* SignalProcessor::ComplexFFT(unsigned short int* data, int sign, int ch)
+float* SignalProcessor::ComplexFFT(float* data, int sign, int ch)
 {
 
     //variables for the fft 
-    unsigned long n,mmax,m,j,istep,i;
+    unsigned long n,mmax,m,j,istep,i, met;
     //double wtemp,wr,wpr,wpi,wi,theta,tempr,tempi;
     float wtemp,wr,wpr,wpi,wi,theta,tempr,tempi;
     float *vector;
@@ -177,18 +168,20 @@
     //vector=(float*)malloc(2*SAMPLE_RATE*sizeof(float)); era assim, define estava em Capture.h
     
     //printf("Antes malloc\n");
+    /*
     vector=(float*)malloc(2*NUMBER_OF_SAMPLES*sizeof(float));
     memset(vector,0,2*NUMBER_OF_SAMPLES*sizeof(float));
-    //printf("DEpois malloc\n");
-    
+    */
+    //printf("DEpois malloc\n");    
     
     //DisplayRAMBanks();
     
     //put the real array in a complex array
     //the complex part is filled with 0's
     //the remaining vector with no data is filled with 0's
-    //for(n=0; n<SAMPLE_RATE;n++)era assim, define estava em Capture.h
+    //for(n=0; n<SAMPLE_RATE;n++)era assim, define estava em Capture.h       
             
+    /*
     for(n=0; n<NUMBER_OF_SAMPLES;n++)
     {
         if(n<NUMBER_OF_SAMPLES){
@@ -199,8 +192,18 @@
         else
             vector[2*n]=0;
         vector[2*n+1]=0;
-    }
-
+    }    
+    */
+    /* trazendo o vetor em float, com metade ocupada, mudança dos valores reais e complexos */    
+    met=(NUMBER_OF_SAMPLES/2)-1;    
+    for(n=NUMBER_OF_SAMPLES-1; n > 0; n--){
+        if (n % 2 == 0){
+            vet[n] = vet[met];
+            met--;
+        }
+        else
+            vet[n] = 0;
+    }    
     //printf("\n");    
     
     //printf("[1] %d %d %d %d\n", data[0], data[100], data[200], data[255]);
--- a/Headers/Capture.h	Tue Apr 28 14:38:37 2015 +0000
+++ b/Headers/Capture.h	Fri May 01 14:46:08 2015 +0000
@@ -40,6 +40,7 @@
     static unsigned short int GetValue(int nsamples, int nchannel);
     static void CopyBuffer(int channel, unsigned short int *dest);
     static void CopyBufferSigned(int channel, short int *dest);
+    static void CopyBufferFloat(sint channel, float *dest)
 
     static void ISRHandler();
 
--- a/Headers/EventDetector.h	Tue Apr 28 14:38:37 2015 +0000
+++ b/Headers/EventDetector.h	Fri May 01 14:46:08 2015 +0000
@@ -71,10 +71,10 @@
     Timer m_tempo;
 
     //void OnTrigger(float rmsvalue);
-    void OnTrigger(float rmsvalue, float mv2, int under, int over, int duration);
+    void OnTrigger(float *buf, float rmsvalue, float mv2, int under, int over, int duration);
     
     //void SendMessage(int ext,float rmsvalue);
-    void SendMessage(int ext,float rmsvalue, float mv2, int under, int over, int duration);
+    void SendMessage(int ext, float *buf, float rmsvalue, float mv2, int under, int over, int duration);
     
     int TimeDelay(int t);
         
--- a/Headers/SignalProcessor.h	Tue Apr 28 14:38:37 2015 +0000
+++ b/Headers/SignalProcessor.h	Fri May 01 14:46:08 2015 +0000
@@ -16,7 +16,7 @@
 class SignalProcessor
 {
 
-    static float* ComplexFFT(unsigned short int* data, int sign, int ch);
+    static float* ComplexFFT(float* data, int sign, int ch);
     static float ComplexFFTTeste(unsigned short int* data, float *vector, int sign, int ch);
     
 public:
@@ -25,7 +25,7 @@
     static void CalculateRMSBulk(float *result, float *vm2, int *under, int *over);
     static float CalculateRMS(unsigned short int *buffer,int nChannel);
     static float CalculateRMSSigned( short int *buffer,int nChannel);
-    static void CalculateFFT(unsigned short int *buffer,float *sen,float *cos,float *vm,int sign, int ch);
+    static void CalculateFFT(float *buffer,float *sen,float *cos,float *vm,int sign, int ch);
     //static float DFT(float *data, float *seno, float *coss);
     
 };