
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
trame.cpp
00001 #include "mbed.h" 00002 #include "trame.h" 00003 #include "debug.h" 00004 00005 TrameData::TrameData(char idE, char idS, int nbNiveau, char etatP, char niveau, char batterie){ 00006 idEmetteur = idE; 00007 idStation = idS; 00008 if(nbNiveau >= 63){ 00009 nombreNiveau = 0x1F; 00010 }else{ 00011 nombreNiveau = (char) nbNiveau; 00012 } 00013 mettreAJourEtatPompe(etatP); 00014 mettreAJourNiveauCuve(niveau); 00015 mettreAJourNiveauBatterie(batterie); 00016 trame[4]=0; 00017 00018 } 00019 char getiemebit(char c, int i) 00020 { 00021 return ((c>>(7-i)) & 1); 00022 } 00023 00024 char* TrameData::creerTrame(){ 00025 trame[0] = idStation; 00026 trame[1] = idEmetteur; 00027 trame[2] = (etatPompe<<7)|(nombreNiveau<<2)|(niveauCuve>>3); 00028 trame[3] = (niveauCuve<<5)|(niveauBatterie); 00029 00030 //Etat Pompe 00031 for(int i=0; i < 8; i++){ 00032 if(getiemebit(etatPompe, i)){ 00033 debug("1"); 00034 } 00035 else{ 00036 debug("0"); 00037 } 00038 } 00039 debug("\r\n"); 00040 //nombreNiveau 00041 for(int i=0; i < 8; i++){ 00042 if(getiemebit(nombreNiveau, i)){ 00043 debug("1"); 00044 } 00045 else{ 00046 debug("0"); 00047 } 00048 } 00049 debug("\r\n"); 00050 //niveauCuve 00051 for(int i=0; i < 8; i++){ 00052 if(getiemebit(niveauCuve, i)){ 00053 debug("1"); 00054 } 00055 else{ 00056 debug("0"); 00057 } 00058 } 00059 00060 debug("\r\n"); 00061 //niveauBatterie 00062 for(int i=0; i < 8; i++){ 00063 if(getiemebit(niveauBatterie, i)){ 00064 debug("1"); 00065 } 00066 else{ 00067 debug("0"); 00068 } 00069 } 00070 00071 //debug("%c ; %c ; %c\r\n",trame[0],trame[1],trame[2]); 00072 char courant; 00073 debug("%d\r\n", sizeof(char)); 00074 for(int j=0; j<4;j++){ 00075 courant = trame[j]; 00076 for(int i=0; i < 8; i++){ 00077 if(getiemebit(courant, i)){ 00078 debug("1"); 00079 } 00080 else{ 00081 debug("0"); 00082 } 00083 } 00084 debug(" "); 00085 } 00086 debug("\r\n"); 00087 00088 00089 return trame; 00090 } 00091 void TrameData::mettreAJourEtatPompe(char etatP){ 00092 etatPompe = etatP; 00093 } 00094 void TrameData::mettreAJourNiveauCuve(char niveau){ 00095 niveauCuve = niveau; 00096 } 00097 void TrameData::mettreAJourNiveauBatterie(char niveau){ 00098 niveauBatterie = niveau; 00099 }
Generated on Thu Jul 14 2022 10:55:31 by
