Polytech school project. RICM4 students, see http://air.imag.fr/index.php/Projets-2016-2017-Station_de_pompage_connect%C3%A9e for more information

Dependencies:   SX1272Lib mbed WakeUp

Fork of SX1272PingPong by Semtech

Committer:
chevamax
Date:
Tue Feb 28 13:40:13 2017 +0000
Revision:
15:79a78f997f18
Child:
17:cce0eada6d82
Application de test.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chevamax 15:79a78f997f18 1 #include "mbed.h"
chevamax 15:79a78f997f18 2 #include "trame.h"
chevamax 15:79a78f997f18 3 #include "debug.h"
chevamax 15:79a78f997f18 4
chevamax 15:79a78f997f18 5 TrameData::TrameData(char id, int nbNiveau, char etatP, char niveau, char batterie){
chevamax 15:79a78f997f18 6 idEmetteur = id;
chevamax 15:79a78f997f18 7 if(nbNiveau >= 63){
chevamax 15:79a78f997f18 8 nombreNiveau = 0x1F;
chevamax 15:79a78f997f18 9 }else{
chevamax 15:79a78f997f18 10 nombreNiveau = (char) nbNiveau;
chevamax 15:79a78f997f18 11 }
chevamax 15:79a78f997f18 12 mettreAJourEtatPompe(etatP);
chevamax 15:79a78f997f18 13 mettreAJourNiveauCuve(niveau);
chevamax 15:79a78f997f18 14 mettreAJourNiveauBatterie(batterie);
chevamax 15:79a78f997f18 15
chevamax 15:79a78f997f18 16 }
chevamax 15:79a78f997f18 17 char getiemebit(char c, int i)
chevamax 15:79a78f997f18 18 {
chevamax 15:79a78f997f18 19 return ((c>>(7-i)) & 1);
chevamax 15:79a78f997f18 20 }
chevamax 15:79a78f997f18 21
chevamax 15:79a78f997f18 22 char* TrameData::creerTrame(){
chevamax 15:79a78f997f18 23 trame[0] = idEmetteur;
chevamax 15:79a78f997f18 24 trame[1] = (etatPompe<<7)|(nombreNiveau<<2)|(niveauCuve>>3);
chevamax 15:79a78f997f18 25 trame[2] = (niveauCuve<<5)|(niveauBatterie);
chevamax 15:79a78f997f18 26
chevamax 15:79a78f997f18 27 //Etat Pompe
chevamax 15:79a78f997f18 28 for(int i=0; i < 8; i++){
chevamax 15:79a78f997f18 29 if(getiemebit(etatPompe, i)){
chevamax 15:79a78f997f18 30 debug("1");
chevamax 15:79a78f997f18 31 }
chevamax 15:79a78f997f18 32 else{
chevamax 15:79a78f997f18 33 debug("0");
chevamax 15:79a78f997f18 34 }
chevamax 15:79a78f997f18 35 }
chevamax 15:79a78f997f18 36 debug("\r\n");
chevamax 15:79a78f997f18 37 //nombreNiveau
chevamax 15:79a78f997f18 38 for(int i=0; i < 8; i++){
chevamax 15:79a78f997f18 39 if(getiemebit(nombreNiveau, i)){
chevamax 15:79a78f997f18 40 debug("1");
chevamax 15:79a78f997f18 41 }
chevamax 15:79a78f997f18 42 else{
chevamax 15:79a78f997f18 43 debug("0");
chevamax 15:79a78f997f18 44 }
chevamax 15:79a78f997f18 45 }
chevamax 15:79a78f997f18 46 debug("\r\n");
chevamax 15:79a78f997f18 47 //niveauCuve
chevamax 15:79a78f997f18 48 for(int i=0; i < 8; i++){
chevamax 15:79a78f997f18 49 if(getiemebit(niveauCuve, i)){
chevamax 15:79a78f997f18 50 debug("1");
chevamax 15:79a78f997f18 51 }
chevamax 15:79a78f997f18 52 else{
chevamax 15:79a78f997f18 53 debug("0");
chevamax 15:79a78f997f18 54 }
chevamax 15:79a78f997f18 55 }
chevamax 15:79a78f997f18 56
chevamax 15:79a78f997f18 57 debug("\r\n");
chevamax 15:79a78f997f18 58 //niveauBatterie
chevamax 15:79a78f997f18 59 for(int i=0; i < 8; i++){
chevamax 15:79a78f997f18 60 if(getiemebit(niveauBatterie, i)){
chevamax 15:79a78f997f18 61 debug("1");
chevamax 15:79a78f997f18 62 }
chevamax 15:79a78f997f18 63 else{
chevamax 15:79a78f997f18 64 debug("0");
chevamax 15:79a78f997f18 65 }
chevamax 15:79a78f997f18 66 }
chevamax 15:79a78f997f18 67
chevamax 15:79a78f997f18 68 //debug("%c ; %c ; %c\r\n",trame[0],trame[1],trame[2]);
chevamax 15:79a78f997f18 69 char courant;
chevamax 15:79a78f997f18 70 debug("%d\r\n", sizeof(char));
chevamax 15:79a78f997f18 71 for(int j=0; j<3;j++){
chevamax 15:79a78f997f18 72 courant = trame[j];
chevamax 15:79a78f997f18 73 for(int i=0; i < 8; i++){
chevamax 15:79a78f997f18 74 if(getiemebit(courant, i)){
chevamax 15:79a78f997f18 75 debug("1");
chevamax 15:79a78f997f18 76 }
chevamax 15:79a78f997f18 77 else{
chevamax 15:79a78f997f18 78 debug("0");
chevamax 15:79a78f997f18 79 }
chevamax 15:79a78f997f18 80 }
chevamax 15:79a78f997f18 81 debug(" ");
chevamax 15:79a78f997f18 82 }
chevamax 15:79a78f997f18 83 debug("\r\n");
chevamax 15:79a78f997f18 84
chevamax 15:79a78f997f18 85
chevamax 15:79a78f997f18 86 return trame;
chevamax 15:79a78f997f18 87 }
chevamax 15:79a78f997f18 88 void TrameData::mettreAJourEtatPompe(char etatP){
chevamax 15:79a78f997f18 89 etatPompe = etatP;
chevamax 15:79a78f997f18 90 }
chevamax 15:79a78f997f18 91 void TrameData::mettreAJourNiveauCuve(char niveau){
chevamax 15:79a78f997f18 92 niveauCuve = niveau;
chevamax 15:79a78f997f18 93 }
chevamax 15:79a78f997f18 94 void TrameData::mettreAJourNiveauBatterie(char niveau){
chevamax 15:79a78f997f18 95 niveauBatterie = niveau;
chevamax 15:79a78f997f18 96 }