Unina Corse EL / Mbed 2 deprecated f4_sd_imu_4

Dependencies:   SDFileSystem_conMOD mbed-rtos mbed

Fork of f4_sd_imu_4 by ratto killer

Files at this revision

API Documentation at this revision

Comitter:
rattokiller
Date:
Sun Jan 21 20:40:24 2018 +0000
Parent:
10:3ec4696ad874
Commit message:
programma con scrittura sd con concorenza

Changed in this revision

accellerometro.h Show annotated file Show diff for this revision Revisions of this file
lettoreSD.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
messaggi.h Show annotated file Show diff for this revision Revisions of this file
sd_binario.h Show annotated file Show diff for this revision Revisions of this file
setting.h Show annotated file Show diff for this revision Revisions of this file
--- a/accellerometro.h	Wed Dec 13 21:08:45 2017 +0000
+++ b/accellerometro.h	Sun Jan 21 20:40:24 2018 +0000
@@ -72,6 +72,8 @@
         gy = (float)gyroCount[1]*gRes; // - gyroBias[1];  
         gz = (float)gyroCount[2]*gRes; // - gyroBias[2];   
 
+    
+        invia_m(1000*ax+4000,1000*ay+4000,1000*az+4000,0,0,0);
         tempCount = mpu6050.readTempData();  // Read the x/y/z adc values
         temperature = (tempCount) / 340. + 36.53; // Temperature in degrees Centigrade
     }  
--- a/lettoreSD.h	Wed Dec 13 21:08:45 2017 +0000
+++ b/lettoreSD.h	Sun Jan 21 20:40:24 2018 +0000
@@ -7,7 +7,7 @@
  
 SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
 FILE *fp;
-char buffer[86100];
+char buffer[100]; //prima era 86100
 int nCounter = 0;
 
 void initFile(){
@@ -48,4 +48,5 @@
     }
 }
 
+
 #endif
\ No newline at end of file
--- a/main.cpp	Wed Dec 13 21:08:45 2017 +0000
+++ b/main.cpp	Sun Jan 21 20:40:24 2018 +0000
@@ -1,52 +1,50 @@
 #include "mbed.h"
 #include "setting.h"
-#include "lettoreSD.h"
-#include "accellerometro.h"
-            
+#define f_campionamento 100 // se va male 50
+#define debug
+
 DigitalIn mybutton(USER_BUTTON);            
-            
+Ticker accelerometro;
+Thread thread; 
+Timer tempo;
+float temp;
+int n=0;
+void simula_dati(){
+
+    ax=n++ /100.0;
+    ay=4.56;
+    az=-4.358;
+    //prelivevo dei dati fatto in tempo
+    float t=tempo.read();
+    if((t-temp)>1.0/(2*f_campionamento))pc.printf("problema");
+    temp=t;
+ invia_m(1000*ax+4000,1000*ay+4000,1000*az+4000,0,0,0);   
+}
+
 int main() {
     init();  
     initFile();
-    initAccellerometro();
+
+    //initAccellerometro();
     aperturaFile(); 
     
-    Timer timer;
+    tempo.reset();
+    tempo.start();
+    temp=0;
+    accelerometro.attach(&raccoltaDati,1.0/f_campionamento);
+      
+    thread.start(callback(scrivi_m));
+    
     
     while(1){ 
-        
-        timer.start();
-        raccoltaDati();
-        //stampaFile("A1xxxxoooooggggggeeeeeeerrrryyyyynhgrgr#2\r\n");
-        //fprintf(fp, "A1xxxxoooooggggggeeeeeeerrrryyyyynhgrgr#2\r\n");
-        timer.stop();
-        if(timer.read_ms()>10){
-                int overTime = (timer.read_ms() / 10) + 1;
-                pc.printf("tempo: %d e overtime %d\n\r ", timer.read_ms(), overTime);
-                for (int i=0; i<overTime; i++){
-                    fprintf(fp,"#\n\r");
-                } 
-        }
-        else{
-            wait_ms(10-timer.read_ms());
-            //printf("tempo: %f\n\r", timer.read());
-        }
-        timer.reset();
-        if (mybutton == 0) {
-            //chiusuraFile();
-            //aperturaFile(); 
-            fprintf(fp, "###########FLAG MARCATORE PRESSIONE PULSANTE############\r\n");
-            wait(1); 
+    Thread::wait(0.01);
+        if (mybutton) {
+          
+               invia_m(65535,65535,65535,65535,65535,65535);
+    
+          Thread::wait(2);
         }
         
-        /*if(i%100==99){
-            timer.stop();
-            float tempo = 1 - timer.read();
-            wait(tempo);
-            printf("tempo: %f\n\r", tempo + timer.read());
-            timer.reset();
-            timer.start();  
-        }
-        i++;*/
+
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sun Jan 21 20:40:24 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5713cbbdb706
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/messaggi.h	Sun Jan 21 20:40:24 2018 +0000
@@ -0,0 +1,67 @@
+char num_n0(int a){
+  return a%256;
+}
+char num_n1(int a){
+    return (char)( a / 256);
+}
+
+typedef struct {
+    char ax[2];
+    char ay[2];
+    char az[2];
+    char gx[2];
+    char gy[2];
+    char gz[2];             
+} message_t;
+
+void copia(message_t & a, message_t b){
+   for(int i=0;i<2;i++){
+    a.ax[i]=b.ax[i];
+    a.ay[i]=b.ay[i];
+    a.az[i]=b.az[i];
+    a.gx[i]=b.gx[i];
+    a.gy[i]=b.gy[i];
+    a.gz[i]=b.gz[i];
+  
+    } 
+    
+}
+void scrivi_imu(message_t* );
+MemoryPool<message_t, 16> mpool;
+Queue<message_t, 16> queue;
+
+/* Send Thread */
+void invia_m (int ax,int ay,int az,int gx,int gy,int gz) {
+    
+    {
+        
+        message_t *message = mpool.alloc();
+        message->ax[0] = num_n0(ax); message->ax[1] = num_n1(ax);
+        message->ay[0] = num_n0(ay); message->ay[1] = num_n1(ay);
+        message->az[0] = num_n0(az); message->az[1] = num_n1(az);
+        message->gx[0] = num_n0(gx); message->gx[1] = num_n1(gx);
+        message->gy[0] = num_n0(gy); message->gy[1] = num_n1(gy);
+        message->gz[0] = num_n0(gz); message->gz[1] = num_n1(gz);
+        queue.put(message);
+        Thread::wait(1000);
+    }
+}
+
+void scrivi_m(void) {
+    
+    
+    while (true) {
+        Thread::wait(0.001);
+        osEvent evt = queue.get();
+        while (evt.status == osEventMessage) {
+            message_t *message = (message_t*)evt.value.p;
+           
+           
+           scrivi_imu(message);
+
+           
+            mpool.free(message);
+            osEvent evt = queue.get();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sd_binario.h	Sun Jan 21 20:40:24 2018 +0000
@@ -0,0 +1,32 @@
+
+
+struct r_f{
+char r_d;
+char r_s;   
+    
+};
+
+void scrivi_rf(r_f ruote,bool flag=false){
+
+    if(flag){
+     ruote.r_d=255;
+    ruote.r_s=255;
+    }
+ fwrite(&ruote, sizeof(r_f), 1, fp);    
+    
+    
+}
+
+#define N 10
+void scrivi_imu(message_t*  imu){
+static int n=0;
+
+static message_t msg[N];
+copia(msg[n],*imu);
+if(n==N){
+ fwrite(&imu, sizeof(message_t ), N, fp);    
+    n=0;
+}
+    
+}
+
--- a/setting.h	Wed Dec 13 21:08:45 2017 +0000
+++ b/setting.h	Sun Jan 21 20:40:24 2018 +0000
@@ -2,16 +2,20 @@
 #define __SETTING__
 
 #include "mbed.h"
-
+#include "rtos.h"
 #include "lettoreSD.h"
 
+#include "messaggi.h"
+#include "sd_binario.h"
 Serial pc(USBTX, USBRX);
 
 void init(){
     pc.baud(921600);    
 }
 
-
+#include "lettoreSD.h"
+#include "accellerometro.h"
+