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
Diff: trame.cpp
- Revision:
- 15:79a78f997f18
- Child:
- 17:cce0eada6d82
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trame.cpp Tue Feb 28 13:40:13 2017 +0000 @@ -0,0 +1,96 @@ +#include "mbed.h" +#include "trame.h" +#include "debug.h" + +TrameData::TrameData(char id, int nbNiveau, char etatP, char niveau, char batterie){ + idEmetteur = id; + if(nbNiveau >= 63){ + nombreNiveau = 0x1F; + }else{ + nombreNiveau = (char) nbNiveau; + } + mettreAJourEtatPompe(etatP); + mettreAJourNiveauCuve(niveau); + mettreAJourNiveauBatterie(batterie); + +} +char getiemebit(char c, int i) +{ + return ((c>>(7-i)) & 1); +} + +char* TrameData::creerTrame(){ + trame[0] = idEmetteur; + trame[1] = (etatPompe<<7)|(nombreNiveau<<2)|(niveauCuve>>3); + trame[2] = (niveauCuve<<5)|(niveauBatterie); + + //Etat Pompe + for(int i=0; i < 8; i++){ + if(getiemebit(etatPompe, i)){ + debug("1"); + } + else{ + debug("0"); + } + } + debug("\r\n"); + //nombreNiveau + for(int i=0; i < 8; i++){ + if(getiemebit(nombreNiveau, i)){ + debug("1"); + } + else{ + debug("0"); + } + } + debug("\r\n"); + //niveauCuve + for(int i=0; i < 8; i++){ + if(getiemebit(niveauCuve, i)){ + debug("1"); + } + else{ + debug("0"); + } + } + + debug("\r\n"); + //niveauBatterie + for(int i=0; i < 8; i++){ + if(getiemebit(niveauBatterie, i)){ + debug("1"); + } + else{ + debug("0"); + } + } + + //debug("%c ; %c ; %c\r\n",trame[0],trame[1],trame[2]); + char courant; + debug("%d\r\n", sizeof(char)); + for(int j=0; j<3;j++){ + courant = trame[j]; + for(int i=0; i < 8; i++){ + if(getiemebit(courant, i)){ + debug("1"); + } + else{ + debug("0"); + } + } + debug(" "); + } + debug("\r\n"); + + + return trame; +} +void TrameData::mettreAJourEtatPompe(char etatP){ + etatPompe = etatP; +} +void TrameData::mettreAJourNiveauCuve(char niveau){ + niveauCuve = niveau; +} +void TrameData::mettreAJourNiveauBatterie(char niveau){ + niveauBatterie = niveau; +}