Projet3i4

Files at this revision

API Documentation at this revision

Comitter:
fabienlepoutre
Date:
Tue Apr 24 14:51:28 2012 +0000
Parent:
0:f0c9c47e4edd
Child:
2:e253b64effa0
Commit message:

Changed in this revision

AnalogTest.cpp Show annotated file Show diff for this revision Revisions of this file
AnalogTest.h Show annotated file Show diff for this revision Revisions of this file
ComSPI.cpp Show annotated file Show diff for this revision Revisions of this file
LibTest.cpp Show annotated file Show diff for this revision Revisions of this file
LibTest.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/AnalogTest.cpp	Mon Apr 23 14:40:40 2012 +0000
+++ b/AnalogTest.cpp	Tue Apr 24 14:51:28 2012 +0000
@@ -8,85 +8,88 @@
 AnalogIn In20(p20);
 
 void v_TestCAN_CNA(){
-    char char1 = 0;
-    float val=1;
-    int aff = 0;
-    cout<<"\033[2J";
-    cout<<"\033[H";
+    int choix=0;
+    printf("\033[2J");
+    printf("\033[H");
     
-    while(char1 != 'q'){
+    while(choix != 3){
+        printf("Test rampe : 1 \r\n Test pas a pas : 2\r\n Quitter : 3\r\n");
+        scanf("%d", &choix);        
+        switch (choix){
+            case 1    : v_TestPortsRampe();
+                        break;
+            case 2    : v_TestPorts();
+                        break;
+            default     : printf("Commande errone\r\n");
+                        break;
+        }
+    }
+}
 
-        
-        cout<<"valeur testee = "<<val<<" \n\r";
-        
-        int result = i_TestPorts(val, aff);
-        aff =0;
-        if((result == 6)&&val<3.3){
-            cout<<"Il y a "<<result<<"ports defaillants et V < 3,3V => Probleme sur Port Analog Out \r\n";
+void v_TestPorts(){
+        printf("\033[2J");
+        printf("\033[H");
+        float val =0;
+        int cont;
+        while(val<=1){
+            printf("\033[2J");
+            printf("\033[H");
+            printf("\033[2J \n\r");
+            printf("\033[H \n\r");
+            
+            printf("valeur testee = %f\r\n", val*3.3);
+            Out18 = val;
+            printf("p15 =%f \r\n",In15.read()*3.3);
+            printf("p16 =%f \r\n",In16.read()*3.3);
+            printf("p17 =%f \r\n",In17.read()*3.3);
+            printf("p18 =%f \r\n",Out18.read()*3.3);
+            printf("p19 =%f \r\n",In19.read()*3.3);
+            printf("p20 =%f \r\n",In20.read()*3.3);
+
+            val = val + 0.2;
+            printf("Appuyez sur une touche pour continuer \r\n");
+            cont=getchar();
        }
-       
-        cout<<"Continuer? y / q voir valeur des ports : v \r\n";
-        cin>>char1;
-        if(char1 == 'v'){
-            aff = 1;
-        }
-        
-        val = val + 0.2;
-        if(val >= 3.3){
-            val = 0;
-        }
-        
-        cout<<"\033[2J \n\r";
-        cout<<"\033[H \n\r";
-        
-    }
 } 
 
 
-int i_TestPorts(float val, int aff){
-     int ret = 0;
-     val = val/3.3;
-     Out18 = val;
-
-     cout<<"Compte rendu du test : \r\n";
-     if((In15.read() < (val-0.01))||(In15 > val + 0.01)){
-        cout<<"Port p15 inexact \n\r";
-        ret ++;
-     }
-     if((In16.read() < (val-0.01))||(In16 > val + 0.01)){
-        cout<<"Port p16 inexact \n\r";
-        ret ++;
+void v_TestPortsRampe(){
+     printf("Entree dans rampe\r\n");
+     float val=0;
+     int IN[6];
+     int i;
+     for(i=0; i<6; i++){
+        IN[i]=0;
      }
      
-     if((In17.read() < (val-0.01))||(In17 > val + 0.01)){
-        cout<<"Port p17 inexact \n\r";
-        ret ++;
-     }     
-     
-     if((Out18.read() < (val-0.01))||(Out18.read() > val + 0.01)){
-        cout<<"Port p18 inexact \n\r";
-        ret ++;
-     }
-     
-     if((In19.read() < (val-0.01))||(In19 > val + 0.01)){
-        cout<<"Port p19 inexact \n\r";     
-        ret ++;
-     }
-     
-     if((In20.read() < (val-0.01))||(In20 > val + 0.01)){
-        cout<<"Port p20 inexact \n\r";
-        ret ++;
-     }
-     if(aff ==1){
-       cout<<"p15 ="<<In15.read()*3.3<<" \r\n";
-       cout<<"p16 ="<<In16.read()*3.3<<" \r\n";
-       cout<<"p17 ="<<In17.read()*3.3<<" \r\n";
-       cout<<"p18 ="<<Out18.read()*3.3<<" \r\n";
-       cout<<"p19 ="<<In19.read()*3.3<<" \r\n";
-       cout<<"p20 ="<<In20.read()*3.3<<" \r\n"; 
-
-        }                     
-     
-     return ret;
-     
-}
\ No newline at end of file
+    while(val <=1){
+         Out18 = val;
+         if((In15.read() < (val-0.01))||(In15 > val + 0.01)){
+            IN[0]++;
+         }
+         if((In16.read() < (val-0.01))||(In16 > val + 0.01)){
+            IN[1]++;
+         }
+         
+         if((In17.read() < (val-0.01))||(In17 > val + 0.01)){
+            IN[2]++;
+         }     
+         
+         if((Out18.read() < (val-0.01))||(Out18.read() > val + 0.01)){
+            IN[3]++;
+         }
+         
+         if((In19.read() < (val-0.01))||(In19 > val + 0.01)){
+           IN[4]++;
+         }
+         
+         if((In20.read() < (val-0.01))||(In20 > val + 0.01)){
+           IN[5]++;
+         }
+         val = val+0.05;
+   }
+   printf("Compte rendu du test sur 20 valeurs: \r\n");
+   for(i=0; i<6; i++)
+        printf("Port %d : %d erreurs de lecture \r\n", i+15, IN[i]);
+}
+  
\ No newline at end of file
--- a/AnalogTest.h	Mon Apr 23 14:40:40 2012 +0000
+++ b/AnalogTest.h	Tue Apr 24 14:51:28 2012 +0000
@@ -4,4 +4,5 @@
 
 
 void v_TestCAN_CNA();
-int i_TestPorts(float val, int aff);
\ No newline at end of file
+void v_TestPortsRampe();
+void v_TestPorts();
\ No newline at end of file
--- a/ComSPI.cpp	Mon Apr 23 14:40:40 2012 +0000
+++ b/ComSPI.cpp	Tue Apr 24 14:51:28 2012 +0000
@@ -2,35 +2,30 @@
 SPI SPI_Master(p11, p12, p13);          //mosi, miso, sck
 DigitalOut cs(p14);                     //Selection Slave
 SPISlave SPI_Slave(p5, p6, p7, p8);     //mosi, miso, sck, ssel
-
+volatile int attente;
 
 
 void v_InitSPI(){
-    printf("Entree dans Init \n\r");
     SPI_Master.format(8,0);
     SPI_Master.frequency(1000000);    
     SPI_Slave.format(8,0);
-    SPI_Slave.frequency(1000000);
-        
+    SPI_Slave.frequency(1000000); 
 }
 
 
 void v_TestComSPI(){
-    printf("Entree dans testcom \r\n");
+    attente=0;
     v_InitSPI();
     Thread tSlave(v_threadSPISlave);
     Thread tMaster(v_threadSPIMaster);
+    while(attente==0);
 }
 
 void v_threadSPIMaster(void const* argument){    
-    printf("Entree dans le thread Master \r \n");
     int answer, msgsend=1;
-    
-   
     cs=0;
     answer = SPI_Master.write(msgsend);   
     cs=1;  
-    cout<<endl<<cs<<endl;
     wait_ms(100);
     cs=0;
     answer = SPI_Master.write(0x00); 
@@ -41,19 +36,20 @@
         cs=0;
         answer=SPI_Master.write(TERMINATE);   //send a Terminate value
         cs=1;  
-        if(answer==0) printf("Communication OK \r\n)");    //Normaly Slave returns 0 : end of transmission
-        else printf("Probleme de communication \r\n)");
+        if(answer==0) printf("Communication SPI OK \r\n)");    //Normaly Slave returns 0 : end of transmission
+        else printf("Probleme de communication SPI1 \r\n)");
     }  
-    printf("Sortie du thread Master \r\n");
+    else{
+        printf("Probleme de communication SPI2 \r\n");
+        }
+        attente++;
 }
 
 void v_threadSPISlave(void const* argument){
-    printf("Entree dans le thread Slave \r\n");
      int rec, rec2;
      bool end=false;
      while(!end){
          if(SPI_Slave.receive()) {
-                
                 rec = SPI_Slave.read(); 
                 rec2=rec+5;                   // Read byte from master
                 printf("Slave -> Valeur recue :%d\r\n", rec);                  
@@ -68,12 +64,8 @@
                         SPI_Slave.reply(rec2);                   // Make this the next reply (add 5);
                         printf("Slave -> Valeur renvoyee : %d \r\n",rec2);
                         }
-                }
-                    
+                }      
           }
       }
-      printf("Sortie du thread Slave \r\n");
-
-
 }
 
--- a/LibTest.cpp	Mon Apr 23 14:40:40 2012 +0000
+++ b/LibTest.cpp	Tue Apr 24 14:51:28 2012 +0000
@@ -5,16 +5,15 @@
 
 int i_IntroTest(){
     int choix;
-    cout<<endl<<"Programme de test \r"<<endl;
+    printf("\r\n Programme de test \r");
 
-    cout<<"Selectionner le test a effectuer: \n\r";
-    cout<<"1. CAN / CNA \n\r";
-    
-    cout<<"Choix : ";
-    cin>>choix;
-    cout<<choix<<"\r\n";
-    
-    
+    printf("Selectionner le test a effectuer: \n\r");
+    printf("1. CAN / CNA \n\r");
+    printf("2. Connexion SPI \n\r");
+    printf("4. Test Complet\r\n");
+    printf("5. Quitter \r\n");
+    printf("Choix : ");
+    scanf("%d", &choix);
     return choix;
 }
 
--- a/LibTest.h	Mon Apr 23 14:40:40 2012 +0000
+++ b/LibTest.h	Tue Apr 24 14:51:28 2012 +0000
@@ -4,6 +4,7 @@
 #define ANALOG_IN_OUT 1
 #define SPI 2
 #define I2C 3
+#define COMPLET 4
 
 int i_IntroTest();
 
--- a/main.cpp	Mon Apr 23 14:40:40 2012 +0000
+++ b/main.cpp	Tue Apr 24 14:51:28 2012 +0000
@@ -1,20 +1,24 @@
-#include "mbed.h"
-#include "LibTest.h"
-#include "ComSPI.h"
-#include "AnalogTest.h"
-DigitalOut myled(LED1);
-
-int main() {
-    int choix = i_IntroTest();
-    switch(choix){
-        case ANALOG_IN_OUT :    v_TestCAN_CNA();
-                                break;
-        case SPI:               v_TestComSPI();
-                                break;
-        case I2C:               
-        
-        default :               break;
-    
-    }
-
-}
+#include "mbed.h"
+#include "LibTest.h"
+#include "ComSPI.h"
+#include "AnalogTest.h"
+
+int main() {
+    int choix = 0;
+    while(choix!=5){
+        choix =i_IntroTest();
+        switch(choix){
+            case ANALOG_IN_OUT :    v_TestCAN_CNA();
+                                    break;
+            case SPI:               v_TestComSPI();
+                                    break;
+            case I2C:               
+            
+            case COMPLET:           v_TestPortsRampe();
+                                    v_TestComSPI();
+                                    
+            default :               break;
+        
+        }
+     }
+}