Maxime Chevalier / Mbed 2 deprecated SX1272Pump

Dependencies:   SX1272Lib mbed WakeUp

Fork of SX1272PingPong by Semtech

Files at this revision

API Documentation at this revision

Comitter:
chevamax
Date:
Tue Feb 28 13:40:13 2017 +0000
Parent:
14:261007103beb
Child:
16:85fb5e37def7
Commit message:
Application de test.

Changed in this revision

niveau.cpp Show annotated file Show diff for this revision Revisions of this file
niveau.h Show annotated file Show diff for this revision Revisions of this file
ordre.cpp Show annotated file Show diff for this revision Revisions of this file
ordre.h Show annotated file Show diff for this revision Revisions of this file
pompe.cpp Show annotated file Show diff for this revision Revisions of this file
pompe.h Show annotated file Show diff for this revision Revisions of this file
trame.cpp Show annotated file Show diff for this revision Revisions of this file
trame.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/niveau.cpp	Tue Feb 28 13:40:13 2017 +0000
@@ -0,0 +1,10 @@
+#include "mbed.h"
+#include "niveau.h"
+#include "debug.h"
+
+
+Niveau::Niveau(){
+}
+char Niveau::getNiveauCuve(){
+    return 'a';//(char) ((p1<<2) | (p2<<1) | (p3));
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/niveau.h	Tue Feb 28 13:40:13 2017 +0000
@@ -0,0 +1,18 @@
+#ifndef __NIVEAU_H
+#define __NIVEAU_H
+
+#include "mbed.h"
+#include "PinNames.h"
+
+//TODO Version de base avec 3 PIN seulement
+class Niveau {
+  private:
+    //DigitalIn p1(PC_15);//(PC_15); //Poid fort
+    //DigitalIn p2(PH_0);
+    //DigitalIn p3(PH_1); //Poid faible
+  public:
+    Niveau();
+    char getNiveauCuve();
+};
+
+#endif // __NIVEAU_H
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ordre.cpp	Tue Feb 28 13:40:13 2017 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+#include "ordre.h"
+#include "debug.h"
+
+Ordre::Ordre(char id, char idR, char niveau){
+    //TODO   
+}
+
+char getiemebit1(char c, int i)
+{
+     return ((c>>(7-i)) & 1);
+}
+
+Ordre::Ordre(char* trameRecu){
+    idEmetteur = trameRecu[1];
+    idRecepteur = trameRecu[0];
+    niveauCuve = trameRecu[2]>>3;
+    debug("idEmetteur = ");
+    for(int i=0; i < 8; i++){
+        if(getiemebit1(trameRecu[1], i)){
+            debug("1");
+        }
+        else{
+            debug("0");
+        }
+    }
+    debug("\r\n idRecepteur = ");
+    for(int i=0; i < 8; i++){
+        if(getiemebit1(trameRecu[0], i)){
+            debug("1");
+        }
+        else{
+            debug("0");
+        }
+    }
+    debug("\r\n niveauCuve = ");
+    for(int i=0; i < 8; i++){
+        if(getiemebit1(trameRecu[2], i)){
+            debug("1");
+        }
+        else{
+            debug("0");
+        }
+    }
+}
+char* Ordre::creerTrame(){
+    //TODO
+    return NULL;
+}
+void Ordre::mettreAJourNiveauCuve(){
+    //TODO
+}
+void Ordre::executerOrdre(Pompe p, Niveau n){
+    //TODO
+    debug("Execution de l'ordre 10s \r\n");
+    wait(10);
+    debug("Fin execution ordre\r\n");
+}
+
+char Ordre::getIdEmetteur(){
+    return idEmetteur;
+}
+char Ordre::getIdRecepteur(){
+    return idRecepteur;
+}
+char Ordre::getNiveauCuve(){
+    return niveauCuve;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ordre.h	Tue Feb 28 13:40:13 2017 +0000
@@ -0,0 +1,29 @@
+#ifndef __ORDRE_H
+#define __ORDRE_H
+
+#include "mbed.h"
+#include "pompe.h"
+#include "niveau.h"
+
+#define TAILLE_TRAME_ORDRE 3 //octets
+
+class Ordre {
+  private:
+    char idEmetteur; // 1 octet
+    char idRecepteur; //1 octet
+    char niveauCuve;  //5 bits
+    char trame[TAILLE_TRAME_ORDRE];
+  
+  public:
+    Ordre(char id, char idR, char niveau);
+    Ordre(char* trameRecu);
+    char* creerTrame();
+    void mettreAJourNiveauCuve();
+    //Voir si on peut faire un thread TODO
+    void executerOrdre(Pompe p, Niveau n);
+    char getIdEmetteur();
+    char getIdRecepteur();
+    char getNiveauCuve();
+};
+
+#endif // __ORDRE_H
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pompe.cpp	Tue Feb 28 13:40:13 2017 +0000
@@ -0,0 +1,22 @@
+#include "mbed.h"
+#include "pompe.h"
+#include "debug.h"
+#include "PinNames.h"
+
+Pompe::Pompe(){
+    //p(PC_14);
+}
+
+Pompe::Pompe(PinName pin){
+    //p(pin);   
+}
+void Pompe::activerPompe(){
+    //p = 1;    
+}
+void Pompe::arreterPompe(){
+    //p = 0;
+}
+
+char Pompe::etat(){
+    return NULL;//(char) p;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pompe.h	Tue Feb 28 13:40:13 2017 +0000
@@ -0,0 +1,18 @@
+#ifndef __POMPE_H
+#define __POMPE_H
+
+#include "mbed.h"
+
+class Pompe {
+  public:
+    Pompe();
+    Pompe(PinName pin);
+    void activerPompe();
+    void arreterPompe();
+    char etat();
+    
+  private:
+    //DigitalOut p;
+};
+
+#endif // __POMPE_H
\ No newline at end of file
--- /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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trame.h	Tue Feb 28 13:40:13 2017 +0000
@@ -0,0 +1,24 @@
+#ifndef __TRAME_H
+#define __TRAME_H
+
+#include "mbed.h"
+#define TAILLE_TRAME_DATA 3 //octets
+
+class TrameData {
+  private:
+    char idEmetteur; // 1 octet
+    char etatPompe; //1 bit  
+    char nombreNiveau; //5 bits
+    char niveauCuve;  //5 bits
+    char niveauBatterie; //4bits
+    char trame[TAILLE_TRAME_DATA];
+  
+  public:
+    TrameData(char id, int nbNiveau, char etatP, char niveau, char batterie);
+    char* creerTrame();
+    void mettreAJourEtatPompe(char etatP);
+    void mettreAJourNiveauCuve(char niveau);
+    void mettreAJourNiveauBatterie(char niveau);
+};
+
+#endif // __TRAME_H
\ No newline at end of file