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
ordre.cpp@17:cce0eada6d82, 2017-04-01 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
chevamax | 15:79a78f997f18 | 1 | #include "mbed.h" |
chevamax | 15:79a78f997f18 | 2 | #include "ordre.h" |
chevamax | 15:79a78f997f18 | 3 | #include "debug.h" |
chevamax | 15:79a78f997f18 | 4 | |
chevamax | 17:cce0eada6d82 | 5 | #define TEMPS_ATTENTE_REMPLISSAGE 10 |
chevamax | 15:79a78f997f18 | 6 | |
chevamax | 15:79a78f997f18 | 7 | char getiemebit1(char c, int i) |
chevamax | 15:79a78f997f18 | 8 | { |
chevamax | 15:79a78f997f18 | 9 | return ((c>>(7-i)) & 1); |
chevamax | 15:79a78f997f18 | 10 | } |
chevamax | 15:79a78f997f18 | 11 | |
chevamax | 15:79a78f997f18 | 12 | Ordre::Ordre(char* trameRecu){ |
chevamax | 15:79a78f997f18 | 13 | idEmetteur = trameRecu[1]; |
chevamax | 15:79a78f997f18 | 14 | idRecepteur = trameRecu[0]; |
chevamax | 15:79a78f997f18 | 15 | niveauCuve = trameRecu[2]>>3; |
chevamax | 17:cce0eada6d82 | 16 | ordreAFaire = (trameRecu[2]&0x4)>>2; |
chevamax | 17:cce0eada6d82 | 17 | /*debug("idEmetteur = "); |
chevamax | 15:79a78f997f18 | 18 | for(int i=0; i < 8; i++){ |
chevamax | 15:79a78f997f18 | 19 | if(getiemebit1(trameRecu[1], i)){ |
chevamax | 15:79a78f997f18 | 20 | debug("1"); |
chevamax | 15:79a78f997f18 | 21 | } |
chevamax | 15:79a78f997f18 | 22 | else{ |
chevamax | 15:79a78f997f18 | 23 | debug("0"); |
chevamax | 15:79a78f997f18 | 24 | } |
chevamax | 15:79a78f997f18 | 25 | } |
chevamax | 15:79a78f997f18 | 26 | debug("\r\n idRecepteur = "); |
chevamax | 15:79a78f997f18 | 27 | for(int i=0; i < 8; i++){ |
chevamax | 15:79a78f997f18 | 28 | if(getiemebit1(trameRecu[0], i)){ |
chevamax | 15:79a78f997f18 | 29 | debug("1"); |
chevamax | 15:79a78f997f18 | 30 | } |
chevamax | 15:79a78f997f18 | 31 | else{ |
chevamax | 15:79a78f997f18 | 32 | debug("0"); |
chevamax | 15:79a78f997f18 | 33 | } |
chevamax | 15:79a78f997f18 | 34 | } |
chevamax | 15:79a78f997f18 | 35 | debug("\r\n niveauCuve = "); |
chevamax | 15:79a78f997f18 | 36 | for(int i=0; i < 8; i++){ |
chevamax | 17:cce0eada6d82 | 37 | if(getiemebit1(niveauCuve, i)){ |
chevamax | 17:cce0eada6d82 | 38 | debug("1"); |
chevamax | 17:cce0eada6d82 | 39 | } |
chevamax | 17:cce0eada6d82 | 40 | else{ |
chevamax | 17:cce0eada6d82 | 41 | debug("0"); |
chevamax | 17:cce0eada6d82 | 42 | } |
chevamax | 17:cce0eada6d82 | 43 | } |
chevamax | 17:cce0eada6d82 | 44 | debug("\r\n ordreAfaire = "); |
chevamax | 17:cce0eada6d82 | 45 | for(int i=0; i < 8; i++){ |
chevamax | 17:cce0eada6d82 | 46 | if(getiemebit1(ordreAFaire, i)){ |
chevamax | 15:79a78f997f18 | 47 | debug("1"); |
chevamax | 15:79a78f997f18 | 48 | } |
chevamax | 15:79a78f997f18 | 49 | else{ |
chevamax | 15:79a78f997f18 | 50 | debug("0"); |
chevamax | 15:79a78f997f18 | 51 | } |
chevamax | 15:79a78f997f18 | 52 | } |
chevamax | 17:cce0eada6d82 | 53 | debug("\r\n");*/ |
chevamax | 15:79a78f997f18 | 54 | } |
chevamax | 17:cce0eada6d82 | 55 | |
chevamax | 17:cce0eada6d82 | 56 | void Ordre::executerOrdre(Pompe p, Niveau n, char niveauCible){ |
chevamax | 15:79a78f997f18 | 57 | //TODO |
chevamax | 15:79a78f997f18 | 58 | debug("Execution de l'ordre 10s \r\n"); |
chevamax | 17:cce0eada6d82 | 59 | //wait(10); |
chevamax | 17:cce0eada6d82 | 60 | if(n.getNiveauCuve() < niveauCible){ |
chevamax | 17:cce0eada6d82 | 61 | p.activerPompe(); |
chevamax | 17:cce0eada6d82 | 62 | } |
chevamax | 17:cce0eada6d82 | 63 | while(n.getNiveauCuve() < niveauCible){ |
chevamax | 17:cce0eada6d82 | 64 | wait(TEMPS_ATTENTE_REMPLISSAGE); |
chevamax | 17:cce0eada6d82 | 65 | } |
chevamax | 17:cce0eada6d82 | 66 | |
chevamax | 17:cce0eada6d82 | 67 | p.arreterPompe(); |
chevamax | 15:79a78f997f18 | 68 | debug("Fin execution ordre\r\n"); |
chevamax | 15:79a78f997f18 | 69 | } |
chevamax | 15:79a78f997f18 | 70 | |
chevamax | 15:79a78f997f18 | 71 | char Ordre::getIdEmetteur(){ |
chevamax | 15:79a78f997f18 | 72 | return idEmetteur; |
chevamax | 15:79a78f997f18 | 73 | } |
chevamax | 15:79a78f997f18 | 74 | char Ordre::getIdRecepteur(){ |
chevamax | 15:79a78f997f18 | 75 | return idRecepteur; |
chevamax | 15:79a78f997f18 | 76 | } |
chevamax | 15:79a78f997f18 | 77 | char Ordre::getNiveauCuve(){ |
chevamax | 15:79a78f997f18 | 78 | return niveauCuve; |
chevamax | 17:cce0eada6d82 | 79 | } |
chevamax | 17:cce0eada6d82 | 80 | char Ordre::getOrdreAFaire(){ |
chevamax | 17:cce0eada6d82 | 81 | return ordreAFaire; |
chevamax | 15:79a78f997f18 | 82 | } |