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
trasmetti.h@0:a9753886e1e0, 2017-11-05 (annotated)
- Committer:
- rattokiller
- Date:
- Sun Nov 05 14:20:26 2017 +0000
- Revision:
- 0:a9753886e1e0
librerie utili
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rattokiller | 0:a9753886e1e0 | 1 | //#ifndef mydati_h |
rattokiller | 0:a9753886e1e0 | 2 | //#odefine mydati_h |
rattokiller | 0:a9753886e1e0 | 3 | #include "mbed.h" |
rattokiller | 0:a9753886e1e0 | 4 | |
rattokiller | 0:a9753886e1e0 | 5 | |
rattokiller | 0:a9753886e1e0 | 6 | |
rattokiller | 0:a9753886e1e0 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
rattokiller | 0:a9753886e1e0 | 8 | |
rattokiller | 0:a9753886e1e0 | 9 | #ifndef mydati_h |
rattokiller | 0:a9753886e1e0 | 10 | #define mydati_h |
rattokiller | 0:a9753886e1e0 | 11 | extern Serial pc; |
rattokiller | 0:a9753886e1e0 | 12 | extern Serial device; |
rattokiller | 0:a9753886e1e0 | 13 | extern Serial device2; |
rattokiller | 0:a9753886e1e0 | 14 | |
rattokiller | 0:a9753886e1e0 | 15 | namespace mydati{ |
rattokiller | 0:a9753886e1e0 | 16 | |
rattokiller | 0:a9753886e1e0 | 17 | bool pc_trasmisione(int,char* s); |
rattokiller | 0:a9753886e1e0 | 18 | |
rattokiller | 0:a9753886e1e0 | 19 | struct pacco{ |
rattokiller | 0:a9753886e1e0 | 20 | char* txt; |
rattokiller | 0:a9753886e1e0 | 21 | char n; |
rattokiller | 0:a9753886e1e0 | 22 | }; |
rattokiller | 0:a9753886e1e0 | 23 | |
rattokiller | 0:a9753886e1e0 | 24 | class trasmetti{ /* classe superiore che ha il compito di interagire con l' altra scheda, |
rattokiller | 0:a9753886e1e0 | 25 | le altre sottoclassi si intrfacciano a lei */ |
rattokiller | 0:a9753886e1e0 | 26 | private: |
rattokiller | 0:a9753886e1e0 | 27 | int addr_slave; |
rattokiller | 0:a9753886e1e0 | 28 | I2C* master; |
rattokiller | 0:a9753886e1e0 | 29 | char conteggio; |
rattokiller | 0:a9753886e1e0 | 30 | |
rattokiller | 0:a9753886e1e0 | 31 | struct coda{ |
rattokiller | 0:a9753886e1e0 | 32 | char priorita; |
rattokiller | 0:a9753886e1e0 | 33 | pacco* dato; |
rattokiller | 0:a9753886e1e0 | 34 | coda* suc; |
rattokiller | 0:a9753886e1e0 | 35 | }; |
rattokiller | 0:a9753886e1e0 | 36 | coda* testa; |
rattokiller | 0:a9753886e1e0 | 37 | coda* fine; |
rattokiller | 0:a9753886e1e0 | 38 | char n; |
rattokiller | 0:a9753886e1e0 | 39 | void extract(pacco**); |
rattokiller | 0:a9753886e1e0 | 40 | public: |
rattokiller | 0:a9753886e1e0 | 41 | trasmetti():n(0){testa=fine=0;} |
rattokiller | 0:a9753886e1e0 | 42 | |
rattokiller | 0:a9753886e1e0 | 43 | void set_add(int a){addr_slave=a;} |
rattokiller | 0:a9753886e1e0 | 44 | void set_master(I2C* a){master=a;} |
rattokiller | 0:a9753886e1e0 | 45 | |
rattokiller | 0:a9753886e1e0 | 46 | bool ins_in_coda(pacco* ,char priorita= 0); |
rattokiller | 0:a9753886e1e0 | 47 | bool ins_priorita(pacco* ,char priorita= 0); |
rattokiller | 0:a9753886e1e0 | 48 | bool ins_in_testa(pacco* ,char priorita= 0); |
rattokiller | 0:a9753886e1e0 | 49 | |
rattokiller | 0:a9753886e1e0 | 50 | bool pc_trasmisione(int n,char* s); |
rattokiller | 0:a9753886e1e0 | 51 | |
rattokiller | 0:a9753886e1e0 | 52 | bool invio(); |
rattokiller | 0:a9753886e1e0 | 53 | } |
rattokiller | 0:a9753886e1e0 | 54 | //serve perche deve essere unina per tutti e quindi di variabile di qeusta classe ne deve essere creata solo una |
rattokiller | 0:a9753886e1e0 | 55 | #ifdef tra_cpp |
rattokiller | 0:a9753886e1e0 | 56 | telemetria; |
rattokiller | 0:a9753886e1e0 | 57 | #else |
rattokiller | 0:a9753886e1e0 | 58 | ; |
rattokiller | 0:a9753886e1e0 | 59 | extern trasmetti telemetria; |
rattokiller | 0:a9753886e1e0 | 60 | #endif |
rattokiller | 0:a9753886e1e0 | 61 | class sensore{ //classe generia appezotata, da riempire sucesivamente per oblicare alle altri figlie di implemetare la funzione |
rattokiller | 0:a9753886e1e0 | 62 | private: |
rattokiller | 0:a9753886e1e0 | 63 | static const int max_n=10; |
rattokiller | 0:a9753886e1e0 | 64 | int n; |
rattokiller | 0:a9753886e1e0 | 65 | |
rattokiller | 0:a9753886e1e0 | 66 | public: |
rattokiller | 0:a9753886e1e0 | 67 | sensore():n(-1){} |
rattokiller | 0:a9753886e1e0 | 68 | virtual bool invia(char p=0)=0; |
rattokiller | 0:a9753886e1e0 | 69 | int number(){n++;n=n%max_n;return n;} |
rattokiller | 0:a9753886e1e0 | 70 | virtual ~sensore(){} |
rattokiller | 0:a9753886e1e0 | 71 | }; |
rattokiller | 0:a9753886e1e0 | 72 | |
rattokiller | 0:a9753886e1e0 | 73 | |
rattokiller | 0:a9753886e1e0 | 74 | /*le sucesive classi hanno il compito di legere i dati dal sensore |
rattokiller | 0:a9753886e1e0 | 75 | e di inviari interfaciandosi con la classe di sopra, |
rattokiller | 0:a9753886e1e0 | 76 | le funzioni che prendoi i dati vengono cambiate, c'è un set_all che viene implementato in mbed, |
rattokiller | 0:a9753886e1e0 | 77 | l' altro serve a me per testare il tutto con il cp |
rattokiller | 0:a9753886e1e0 | 78 | */ |
rattokiller | 0:a9753886e1e0 | 79 | class dati_imu : public sensore{ |
rattokiller | 0:a9753886e1e0 | 80 | private: |
rattokiller | 0:a9753886e1e0 | 81 | static const char priorita_imu =5; |
rattokiller | 0:a9753886e1e0 | 82 | static const int nb_classe =25; |
rattokiller | 0:a9753886e1e0 | 83 | float ax,ay,az; |
rattokiller | 0:a9753886e1e0 | 84 | float gx,gy,gz; |
rattokiller | 0:a9753886e1e0 | 85 | float pich,roll,yaw; |
rattokiller | 0:a9753886e1e0 | 86 | float temp; |
rattokiller | 0:a9753886e1e0 | 87 | static const int off_set_a=2000; |
rattokiller | 0:a9753886e1e0 | 88 | static const int off_set_g=1000; |
rattokiller | 0:a9753886e1e0 | 89 | public: |
rattokiller | 0:a9753886e1e0 | 90 | //dati_imu():sensore(),ax(0),ay(0),az(0),gx(0),gy(0),gz(0),pich(0),roll(0),yaw(0),temp(0){} |
rattokiller | 0:a9753886e1e0 | 91 | |
rattokiller | 0:a9753886e1e0 | 92 | void set_all(float a,float b,float c,float d,float e,float f,float g,float h, float i, float t){ // da elimiare i parametri di ingresso, essa chiamera una funzione dedicata |
rattokiller | 0:a9753886e1e0 | 93 | ax=a;ay=b;az=c;gx=d;gy=e;gz=f;pich=g;roll=h;yaw=i;temp=t; |
rattokiller | 0:a9753886e1e0 | 94 | } |
rattokiller | 0:a9753886e1e0 | 95 | void set_all(); |
rattokiller | 0:a9753886e1e0 | 96 | |
rattokiller | 0:a9753886e1e0 | 97 | virtual bool invia(char p=priorita_imu); |
rattokiller | 0:a9753886e1e0 | 98 | }; |
rattokiller | 0:a9753886e1e0 | 99 | |
rattokiller | 0:a9753886e1e0 | 100 | class estensimetro : public sensore{ |
rattokiller | 0:a9753886e1e0 | 101 | private: |
rattokiller | 0:a9753886e1e0 | 102 | static const char priorita_estensimetro =4; |
rattokiller | 0:a9753886e1e0 | 103 | static const int nb_classe =17; |
rattokiller | 0:a9753886e1e0 | 104 | float ad,as,pd,ps; // a= anteriore p= posteriore |
rattokiller | 0:a9753886e1e0 | 105 | public: |
rattokiller | 0:a9753886e1e0 | 106 | void set_all(float vad,float vas,float vpd,float vps){ad=vad; as=vas; pd=vpd; ps=vps;} |
rattokiller | 0:a9753886e1e0 | 107 | void set_all(); |
rattokiller | 0:a9753886e1e0 | 108 | virtual bool invia(char p=priorita_estensimetro); |
rattokiller | 0:a9753886e1e0 | 109 | }; |
rattokiller | 0:a9753886e1e0 | 110 | |
rattokiller | 0:a9753886e1e0 | 111 | class ruota_fonica : public sensore{ |
rattokiller | 0:a9753886e1e0 | 112 | private: |
rattokiller | 0:a9753886e1e0 | 113 | static const char priorita_ruota_fonica =4; |
rattokiller | 0:a9753886e1e0 | 114 | static const int nb_classe =17; |
rattokiller | 0:a9753886e1e0 | 115 | float ad,as,pd,ps; // a= anteriore p= posteriore |
rattokiller | 0:a9753886e1e0 | 116 | public: |
rattokiller | 0:a9753886e1e0 | 117 | void set_all(float vad,float vas,float vpd,float vps){ad=vad; as=vas; pd=vpd; ps=vps;} |
rattokiller | 0:a9753886e1e0 | 118 | void set_all(){} |
rattokiller | 0:a9753886e1e0 | 119 | virtual bool invia(char p=priorita_ruota_fonica); |
rattokiller | 0:a9753886e1e0 | 120 | }; |
rattokiller | 0:a9753886e1e0 | 121 | |
rattokiller | 0:a9753886e1e0 | 122 | class motore : public sensore{ |
rattokiller | 0:a9753886e1e0 | 123 | private: |
rattokiller | 0:a9753886e1e0 | 124 | static const char priorita_motore =4; |
rattokiller | 0:a9753886e1e0 | 125 | static const int nb_classe =24; |
rattokiller | 0:a9753886e1e0 | 126 | float P_olio,RMP,velocita; |
rattokiller | 0:a9753886e1e0 | 127 | char marcia,T_acqua,T_olio; |
rattokiller | 0:a9753886e1e0 | 128 | public: |
rattokiller | 0:a9753886e1e0 | 129 | motore():P_olio(0),RMP(0),velocita(0),marcia(0),T_acqua(0),T_olio(0){} |
rattokiller | 0:a9753886e1e0 | 130 | void set_all(char Ta,char To,float Po,float vrmp,float vel, char m){T_acqua=Ta; T_olio=To;P_olio=Po;RMP=vrmp;velocita=vel;marcia=m;} |
rattokiller | 0:a9753886e1e0 | 131 | void set_1(float a,char b){RMP=a;T_acqua=b;} |
rattokiller | 0:a9753886e1e0 | 132 | void set_velocita_gear(float a,char b){velocita=a;marcia=b;} |
rattokiller | 0:a9753886e1e0 | 133 | void set_T_oil(char a){T_olio=a;} |
rattokiller | 0:a9753886e1e0 | 134 | void set_P_oil(float a){P_olio=a;} |
rattokiller | 0:a9753886e1e0 | 135 | |
rattokiller | 0:a9753886e1e0 | 136 | char get_marcia()const{return marcia;} |
rattokiller | 0:a9753886e1e0 | 137 | char get_Tacq()const{return T_acqua;} |
rattokiller | 0:a9753886e1e0 | 138 | char get_Tolio()const{return T_olio;} |
rattokiller | 0:a9753886e1e0 | 139 | float get_Polio()const{return P_olio;} |
rattokiller | 0:a9753886e1e0 | 140 | float get_rmp()const{return RMP;} |
rattokiller | 0:a9753886e1e0 | 141 | float get_vel()const{return velocita;} |
rattokiller | 0:a9753886e1e0 | 142 | |
rattokiller | 0:a9753886e1e0 | 143 | virtual bool invia(char p=priorita_motore); |
rattokiller | 0:a9753886e1e0 | 144 | }; |
rattokiller | 0:a9753886e1e0 | 145 | |
rattokiller | 0:a9753886e1e0 | 146 | class allert{ |
rattokiller | 0:a9753886e1e0 | 147 | public: |
rattokiller | 0:a9753886e1e0 | 148 | bool invia(const char*); |
rattokiller | 0:a9753886e1e0 | 149 | }; |
rattokiller | 0:a9753886e1e0 | 150 | #ifdef tra_cpp |
rattokiller | 0:a9753886e1e0 | 151 | |
rattokiller | 0:a9753886e1e0 | 152 | void led_rpm(int rpm, char a[]){ |
rattokiller | 0:a9753886e1e0 | 153 | |
rattokiller | 0:a9753886e1e0 | 154 | int r=rpm; |
rattokiller | 0:a9753886e1e0 | 155 | |
rattokiller | 0:a9753886e1e0 | 156 | if(r==0)a[0]=a[1]=0xff; |
rattokiller | 0:a9753886e1e0 | 157 | else if(r<3000){a[0]=0xfb;a[1]=0xef;} |
rattokiller | 0:a9753886e1e0 | 158 | else if(r<(3000+1333)){a[0]=0xf3;a[1]=0b11001111;} |
rattokiller | 0:a9753886e1e0 | 159 | else if(r<(3000+1333*2)){a[0]=0xe3;a[1]=0b11000111;} |
rattokiller | 0:a9753886e1e0 | 160 | else if(r<(3000+1333*3)){a[0]=0xc3;a[1]=0b11000011;} |
rattokiller | 0:a9753886e1e0 | 161 | else if(r<(3000+1333*4)){a[0]=0x83;a[1]=0b11000001;} |
rattokiller | 0:a9753886e1e0 | 162 | else if(r<(3000+1333*5)){a[0]=0x03;a[1]=0b11000000;} |
rattokiller | 0:a9753886e1e0 | 163 | else if(r<(11000)){a[0]=0x01;a[1]=0b10000000;} |
rattokiller | 0:a9753886e1e0 | 164 | else {a[0]=0x00;a[1]=0x00;} |
rattokiller | 0:a9753886e1e0 | 165 | } |
rattokiller | 0:a9753886e1e0 | 166 | |
rattokiller | 0:a9753886e1e0 | 167 | |
rattokiller | 0:a9753886e1e0 | 168 | bool trasmetti::pc_trasmisione(int n,char* s) |
rattokiller | 0:a9753886e1e0 | 169 | {// da implementae con funzione che invia i dati su |
rattokiller | 0:a9753886e1e0 | 170 | char ss[30]; |
rattokiller | 0:a9753886e1e0 | 171 | |
rattokiller | 0:a9753886e1e0 | 172 | for(int i=0;i<20;i++)ss[5+i]='X'; |
rattokiller | 0:a9753886e1e0 | 173 | strcpy(ss,s); |
rattokiller | 0:a9753886e1e0 | 174 | |
rattokiller | 0:a9753886e1e0 | 175 | |
rattokiller | 0:a9753886e1e0 | 176 | /*da portare in setting e trovare un modo epr farli risultare qui*/ |
rattokiller | 0:a9753886e1e0 | 177 | const int addr = 0x70; |
rattokiller | 0:a9753886e1e0 | 178 | const int addr1 = 0x72; |
rattokiller | 0:a9753886e1e0 | 179 | |
rattokiller | 0:a9753886e1e0 | 180 | |
rattokiller | 0:a9753886e1e0 | 181 | |
rattokiller | 0:a9753886e1e0 | 182 | char nn[2]; |
rattokiller | 0:a9753886e1e0 | 183 | |
rattokiller | 0:a9753886e1e0 | 184 | char a[2]; |
rattokiller | 0:a9753886e1e0 | 185 | |
rattokiller | 0:a9753886e1e0 | 186 | nn[0]=22; |
rattokiller | 0:a9753886e1e0 | 187 | int rpm; |
rattokiller | 0:a9753886e1e0 | 188 | |
rattokiller | 0:a9753886e1e0 | 189 | //master->frequency(100000);//da portare in setting e non farlo sempre |
rattokiller | 0:a9753886e1e0 | 190 | |
rattokiller | 0:a9753886e1e0 | 191 | //aggiungere condizione di return false se il write fallisce ! |
rattokiller | 0:a9753886e1e0 | 192 | wait_us(10); |
rattokiller | 0:a9753886e1e0 | 193 | |
rattokiller | 0:a9753886e1e0 | 194 | master->write(addr_slave,ss,nn[0]); |
rattokiller | 0:a9753886e1e0 | 195 | wait_us(1); |
rattokiller | 0:a9753886e1e0 | 196 | master->stop(); |
rattokiller | 0:a9753886e1e0 | 197 | |
rattokiller | 0:a9753886e1e0 | 198 | |
rattokiller | 0:a9753886e1e0 | 199 | #define led_genny |
rattokiller | 0:a9753886e1e0 | 200 | |
rattokiller | 0:a9753886e1e0 | 201 | #ifdef led_genny |
rattokiller | 0:a9753886e1e0 | 202 | if(s[0]=='D'){ |
rattokiller | 0:a9753886e1e0 | 203 | rpm=(s[7]-'0')*10000+(s[8]-'0')*1000+(s[9]-'0')*100+(s[10]-'0')*10+s[11]-'0'; |
rattokiller | 0:a9753886e1e0 | 204 | led_rpm(rpm,a); |
rattokiller | 0:a9753886e1e0 | 205 | master->write(addr, a, 1); // Send command string |
rattokiller | 0:a9753886e1e0 | 206 | master->stop(); |
rattokiller | 0:a9753886e1e0 | 207 | master->write(addr1, &a[1], 1); // Send command string |
rattokiller | 0:a9753886e1e0 | 208 | master->stop(); |
rattokiller | 0:a9753886e1e0 | 209 | } |
rattokiller | 0:a9753886e1e0 | 210 | |
rattokiller | 0:a9753886e1e0 | 211 | |
rattokiller | 0:a9753886e1e0 | 212 | #endif |
rattokiller | 0:a9753886e1e0 | 213 | |
rattokiller | 0:a9753886e1e0 | 214 | |
rattokiller | 0:a9753886e1e0 | 215 | // device.printf("%s@",s); |
rattokiller | 0:a9753886e1e0 | 216 | // device2.printf("%s@",s); |
rattokiller | 0:a9753886e1e0 | 217 | |
rattokiller | 0:a9753886e1e0 | 218 | // pc.printf("%s\r\n",ss); |
rattokiller | 0:a9753886e1e0 | 219 | |
rattokiller | 0:a9753886e1e0 | 220 | |
rattokiller | 0:a9753886e1e0 | 221 | return true; |
rattokiller | 0:a9753886e1e0 | 222 | } |
rattokiller | 0:a9753886e1e0 | 223 | #endif |
rattokiller | 0:a9753886e1e0 | 224 | } |
rattokiller | 0:a9753886e1e0 | 225 | #endif |