main_imu, MPU6050 , racolta_dati sono per il funzionamento dell' accelerometro. my_img_sd è una libreria per gestire i dati su un sd sulla quale vengono forniti solamente le funzioni di lettura e scrittura a blocchi i file trasmetti sono la definizione e implementazione delle funzioni del protoccolo per la gestione dell' invio dei dati con il relativo formato
Dependencies: mbed
Diff: trasmetti.cpp
- Revision:
- 0:a9753886e1e0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trasmetti.cpp Sun Nov 05 14:20:26 2017 +0000 @@ -0,0 +1,185 @@ +#define tra_cpp +#include "trasmetti.h" +#include <cstring> +//#include <iostream> + +namespace mydati{ + + + +bool trasmetti::ins_in_testa(pacco* d,char priorita){ + coda* app; + app =new coda; + if(!app)return false; + app->dato=d; + app->priorita=priorita; + n++; + app->suc=testa; + testa=app; + delete [] d->txt; + return true; + +} +bool trasmetti::ins_in_coda(pacco* d,char priorita){ + + coda* app; + app =new coda; + if(!app)return false; + // pc.printf("funzione ins coda 1 \r\n"); + + app->dato=d; + + /* + app->dato=new pacco; + app->dato->n=d->n; + app->dato->txt=new char[d->n]; + strcpy(app->dato->txt,d->txt); + delete [] d->txt; + */ + + if(!n){testa=fine=app; n++;return true;} +//pc.printf("funzione ins coda 3 \r\n"); + fine->suc=app; + fine=app; + fine->suc=0; + n++; + return true; +}; +bool trasmetti::ins_priorita(pacco* d,char priorita){ + + coda* app; + app =new coda; + if(!app)return false; + app->dato=d; + + app->priorita=priorita; + + if(!n){app->suc=0;testa=fine=app; n++;return true;} + if(testa->priorita<priorita){n++;app->suc=testa; testa=app;return true;} + + coda* cerca = testa; + if(n!=1){ bool tr =true; + while(cerca->suc->suc!=0&&tr) + if(cerca->suc->priorita>=priorita) + { + cerca=cerca->suc; + } + else tr=false; + + app->suc=cerca->suc; + cerca->suc=app; + n++; + return true; + } + fine->suc=app; + fine=app; + fine->suc=0; + n++; + return true; +}; + +bool trasmetti::invio(){ // iovio i dati! + + if(!n)return false; + pacco* app; + extract(&app); + +if(!pc_trasmisione(app->n,app->txt))return false; + delete [] app->txt; + delete app; + + return true; +} +void trasmetti::extract(pacco** d){ + if(n!=0){ + + coda* app=testa; + *d=testa->dato; + testa=testa->suc; + n--; + + delete app; + } + +} +bool dati_imu::invia(char p){ + //da agiungere una stringa per il protocolla dei tipo dei dati... + //es #nomeclasse@dati + pacco* app; + app= new pacco; + app->n=nb_classe; + app->txt=new char[nb_classe+1]; + sprintf(app->txt,"A%03.0f%03.0f%03.0f%04.0f%04.0f%04.0f#%d",1000*ax+off_set_a,1000*ay+off_set_a,1000*az+off_set_a,10*gx+off_set_g,10*gy+off_set_g,10*gz+off_set_g,number()); + + + //app->txt=buffer; + /* + app->txt=new char[strlen(buffer)+1]; + //printf("ximu %d X \n",strlen(buffer)); + strcpy(app->txt,buffer); + */ + //*funzione se si vuole usare la trasmisione binaria + //memcpy((void*)app->txt,(void*)this,nb_classe); + + + + return telemetria.ins_in_coda(app,p); +} + + + + +bool estensimetro::invia(char p){ + pacco* app; + app= new pacco; + app->n=nb_classe; + app->txt=new char[nb_classe+1]; + sprintf(app->txt,"B%04.0f%04.0f%04.0f%04.0f#%d",ad,as,pd,ps,number()); + + + + return telemetria.ins_in_coda(app,p); +} + +bool ruota_fonica::invia(char p){ + pacco* app; + app= new pacco; + app->n=nb_classe; + app->txt=new char[nb_classe+1]; + + sprintf(app->txt,"C%04.0f%04.0f%04.0f%04.0f#%d",ad,as,pd,ps,number()); + //sprintf(app->txt,"C%04.0f%04.0f#%d",ad,as,pd,ps,number()); + + + return telemetria.ins_in_coda(app,p); +} + +bool motore::invia(char p){ + pacco* app; + app= new pacco; + app->n=nb_classe; + //char buffer[50]; + app->txt=new char[nb_classe+1]; + + + if(P_olio>10){pc.printf("errore olio troppo alto");P_olio=9.9;} + + if(velocita>10000){pc.printf("errore velocita troppo alta!");velocita=9999;} + //D 2000 7700 80800 9400 22 5#2 + sprintf(app->txt,"D%03d%03d%05.0f%04.0f%02.0f%d#%d",T_acqua,T_olio,RMP,velocita,10*P_olio,marcia,number()); + // pc.printf("funzione motore.invia \r\n"); + return telemetria.ins_in_coda(app,p); +} +bool allert::invia(const char* s){ + + + pacco* app; + app= new pacco; + app->n=strlen(s+1); + //app->txt=new char[app->n+1]; + app->txt=(char*)s; + + return telemetria.ins_in_testa(app); + } +} +