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:
Sat Apr 01 12:29:59 2017 +0000
Revision:
17:cce0eada6d82
Parent:
15:79a78f997f18
Version finale

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