tableaux
This commit is contained in:
290
autom.cpp
290
autom.cpp
@@ -50,7 +50,8 @@ unsigned long millis()
|
||||
|
||||
int marche = 0;
|
||||
int arret = 1;
|
||||
int light = 0;
|
||||
int reset = 0;
|
||||
|
||||
int b0, b1, b2, b3, b4, b5, b6, b7;
|
||||
int i0, i1, i2, i3, i4, i5, i6, i7;
|
||||
int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
|
||||
@@ -61,6 +62,16 @@ int p0;
|
||||
int a0, a1, a2, a3, a4, a5, a6, a7;
|
||||
int c0, c1, c2, c3, c4, c5, c6, c7;
|
||||
|
||||
int bouton[8];
|
||||
int interrupteur[8];
|
||||
int capteur[8];
|
||||
int sortie[12];
|
||||
|
||||
int moteur[4];
|
||||
int niveau[4];
|
||||
int consigne[4];
|
||||
int actionneur[8];
|
||||
|
||||
void process();
|
||||
|
||||
/* ********************************************************
|
||||
@@ -84,66 +95,100 @@ void mqtt_send(mqtt::async_client *client);
|
||||
class callback : public virtual mqtt::callback
|
||||
{
|
||||
public:
|
||||
void message_arrived(mqtt::const_message_ptr msg) override {
|
||||
std::string payload = msg->to_string();
|
||||
void message_arrived(mqtt::const_message_ptr msg) override
|
||||
{
|
||||
std::string payload = msg->to_string();
|
||||
|
||||
try {
|
||||
json j = json::parse(payload);
|
||||
try
|
||||
{
|
||||
json j = json::parse(payload);
|
||||
|
||||
marche = 0; arret = 1;
|
||||
b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = 0;
|
||||
marche = 0;
|
||||
arret = 1;
|
||||
b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = 0;
|
||||
|
||||
// Ne rien faire si l'objet JSON est vide
|
||||
if (j.empty()) return;
|
||||
// Ne rien faire si l'objet JSON est vide
|
||||
if (j.empty())
|
||||
return;
|
||||
|
||||
if (j.contains("marche")) marche = j["marche"].get<int>() != 0;
|
||||
if (j.contains("arret")) arret = j["arret"].get<int>() != 0;
|
||||
if (j.contains("marche"))
|
||||
marche = j["marche"].get<int>() != 0;
|
||||
|
||||
if (j.contains("arret"))
|
||||
arret = j["arret"].get<int>() != 0;
|
||||
|
||||
if (j.contains("reset"))
|
||||
reset = j["reset"].get<int>() != 0;
|
||||
|
||||
if (j.contains("b0") && j["b0"].is_number())
|
||||
b0 = j["b0"].get<int>();
|
||||
{
|
||||
bouton[0] = b0 = j["b0"].get<int>();
|
||||
}
|
||||
if (j.contains("b1") && j["b1"].is_number())
|
||||
b1 = j["b1"].get<int>();
|
||||
{
|
||||
bouton[1] = b1 = j["b1"].get<int>();
|
||||
}
|
||||
if (j.contains("b2") && j["b2"].is_number())
|
||||
b2 = j["b2"].get<int>();
|
||||
{
|
||||
bouton[2] = b2 = j["b2"].get<int>();
|
||||
}
|
||||
if (j.contains("b3") && j["b3"].is_number())
|
||||
b3 = j["b3"].get<int>();
|
||||
{
|
||||
bouton[3] = b3 = j["b3"].get<int>();
|
||||
}
|
||||
if (j.contains("b4") && j["b4"].is_number())
|
||||
b4 = j["b4"].get<int>();
|
||||
{
|
||||
bouton[4] = b4 = j["b4"].get<int>();
|
||||
}
|
||||
if (j.contains("b5") && j["b5"].is_number())
|
||||
b5 = j["b5"].get<int>();
|
||||
{
|
||||
bouton[5] = b5 = j["b5"].get<int>();
|
||||
}
|
||||
if (j.contains("b6") && j["b6"].is_number())
|
||||
b6 = j["b6"].get<int>();
|
||||
{
|
||||
bouton[6] = b6 = j["b6"].get<int>();
|
||||
}
|
||||
if (j.contains("b7") && j["b7"].is_number())
|
||||
b7 = j["b7"].get<int>();
|
||||
{
|
||||
bouton[7] = b7 = j["b7"].get<int>();
|
||||
}
|
||||
|
||||
if (j.contains("i0")) i0 = j["i0"].get<int>();
|
||||
if (j.contains("i1")) i1 = j["i1"].get<int>();
|
||||
if (j.contains("i2")) i2 = j["i2"].get<int>();
|
||||
if (j.contains("i3")) i3 = j["i3"].get<int>();
|
||||
if (j.contains("i4")) i4 = j["i4"].get<int>();
|
||||
if (j.contains("i5")) i5 = j["i5"].get<int>();
|
||||
if (j.contains("i6")) i6 = j["i6"].get<int>();
|
||||
if (j.contains("i7")) i7 = j["i7"].get<int>();
|
||||
if (j.contains("i0"))
|
||||
interrupteur[0] = i0 = j["i0"].get<int>();
|
||||
if (j.contains("i1"))
|
||||
interrupteur[1] = i1 = j["i1"].get<int>();
|
||||
if (j.contains("i2"))
|
||||
interrupteur[2] = i2 = j["i2"].get<int>();
|
||||
if (j.contains("i3"))
|
||||
interrupteur[3] = i3 = j["i3"].get<int>();
|
||||
if (j.contains("i4"))
|
||||
interrupteur[4] = i4 = j["i4"].get<int>();
|
||||
if (j.contains("i5"))
|
||||
interrupteur[5] = i5 = j["i5"].get<int>();
|
||||
if (j.contains("i6"))
|
||||
interrupteur[6] = i6 = j["i6"].get<int>();
|
||||
if (j.contains("i7"))
|
||||
interrupteur[7] = i7 = j["i7"].get<int>();
|
||||
|
||||
if (j.contains("c0") && j["c0"].is_number())
|
||||
c0 = j["c0"].get<int>();
|
||||
capteur[0] = c0 = j["c0"].get<int>();
|
||||
if (j.contains("c1") && j["c1"].is_number())
|
||||
c1 = j["c1"].get<int>();
|
||||
capteur[1] = c1 = j["c1"].get<int>();
|
||||
if (j.contains("c2") && j["c2"].is_number())
|
||||
c2 = j["c2"].get<int>();
|
||||
capteur[2] = c2 = j["c2"].get<int>();
|
||||
if (j.contains("c3") && j["c3"].is_number())
|
||||
c3 = j["c3"].get<int>();
|
||||
capteur[3] = c3 = j["c3"].get<int>();
|
||||
if (j.contains("c4") && j["c4"].is_number())
|
||||
c4 = j["c4"].get<int>();
|
||||
capteur[4] = c4 = j["c4"].get<int>();
|
||||
if (j.contains("c5") && j["c5"].is_number())
|
||||
c5 = j["c5"].get<int>();
|
||||
capteur[5] = c5 = j["c5"].get<int>();
|
||||
if (j.contains("c6") && j["c6"].is_number())
|
||||
c6 = j["c6"].get<int>();
|
||||
capteur[6] = c6 = j["c6"].get<int>();
|
||||
if (j.contains("c7") && j["c7"].is_number())
|
||||
c7 = j["c7"].get<int>();
|
||||
capteur[7] = c7 = j["c7"].get<int>();
|
||||
|
||||
if (j.contains("v0") && j["v0"].is_number())
|
||||
v0 = j["v0"].get<int>();
|
||||
v0 = j["v0"].get<int>();
|
||||
|
||||
if (j.contains("p0") && j["p0"].is_number())
|
||||
p0 = j["p0"].get<int>();
|
||||
@@ -151,29 +196,33 @@ public:
|
||||
process();
|
||||
mqtt_send(&client);
|
||||
}
|
||||
catch (const json::parse_error& e) {
|
||||
std::cerr << "Erreur JSON : " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
catch (const json::parse_error &e)
|
||||
{
|
||||
std::cerr << "Erreur JSON : " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
callback cb;
|
||||
|
||||
void mqtt_open(mqtt::async_client* client) {
|
||||
|
||||
client->set_callback(cb);
|
||||
mqtt::connect_options connOpts;
|
||||
connOpts.set_clean_session(true);
|
||||
connOpts.set_user_name("admin");
|
||||
connOpts.set_password("geii2025");
|
||||
try {
|
||||
client->connect(connOpts)->wait();
|
||||
client->start_consuming();
|
||||
client->subscribe(TOPIC, QOS)->wait();
|
||||
} catch (const mqtt::exception &exc) {
|
||||
std::cerr << "Erreur MQTT: " << exc.what() << "\n";
|
||||
}
|
||||
void mqtt_open(mqtt::async_client *client)
|
||||
{
|
||||
|
||||
client->set_callback(cb);
|
||||
mqtt::connect_options connOpts;
|
||||
connOpts.set_clean_session(true);
|
||||
connOpts.set_user_name("admin");
|
||||
connOpts.set_password("geii2025");
|
||||
try
|
||||
{
|
||||
client->connect(connOpts)->wait();
|
||||
client->start_consuming();
|
||||
client->subscribe(TOPIC, QOS)->wait();
|
||||
}
|
||||
catch (const mqtt::exception &exc)
|
||||
{
|
||||
std::cerr << "Erreur MQTT: " << exc.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void mqtt_send(mqtt::async_client *client)
|
||||
@@ -211,18 +260,21 @@ void mqtt_send(mqtt::async_client *client)
|
||||
client->publish(msg);
|
||||
}
|
||||
|
||||
void mqtt_close() {
|
||||
try {
|
||||
client.unsubscribe(TOPIC)->wait();
|
||||
client.stop_consuming();
|
||||
client.disconnect()->wait();
|
||||
} catch(const mqtt::exception &exc){
|
||||
std::cerr << "Erreur déconnexion MQTT: " << exc.what() << std::endl;
|
||||
}
|
||||
void mqtt_close()
|
||||
{
|
||||
try
|
||||
{
|
||||
client.unsubscribe(TOPIC)->wait();
|
||||
client.stop_consuming();
|
||||
client.disconnect()->wait();
|
||||
}
|
||||
catch (const mqtt::exception &exc)
|
||||
{
|
||||
std::cerr << "Erreur déconnexion MQTT: " << exc.what() << std::endl;
|
||||
}
|
||||
}
|
||||
// ************************************************************
|
||||
|
||||
|
||||
/* ********************************************************
|
||||
* TEMPORISATION RETARD A LA MONTEE *
|
||||
* La sortie passe à 1 au bout de la tempo *
|
||||
@@ -230,20 +282,20 @@ void mqtt_close() {
|
||||
|
||||
class TemporisationRetardMontee
|
||||
{
|
||||
// methodes
|
||||
public :
|
||||
// Contructeur qui prend la duree souhaitee de la temporisation
|
||||
// methodes
|
||||
public:
|
||||
// Contructeur qui prend la duree souhaitee de la temporisation
|
||||
TemporisationRetardMontee(unsigned long duree)
|
||||
{
|
||||
this->duree = duree;
|
||||
sortie = false;
|
||||
captureTemps = false;
|
||||
}
|
||||
// Activation de la temporisation. Doit etre fait tout le temps de la duree de la tempo
|
||||
// Activation de la temporisation. Doit etre fait tout le temps de la duree de la tempo
|
||||
void activation()
|
||||
{
|
||||
// Capture du temps de reference
|
||||
if(!captureTemps)
|
||||
if (!captureTemps)
|
||||
{
|
||||
debut = millis();
|
||||
captureTemps = true;
|
||||
@@ -269,44 +321,44 @@ class TemporisationRetardMontee
|
||||
captureTemps = false;
|
||||
}
|
||||
// Interrogation du bit de fin de tempo
|
||||
bool getSortie()
|
||||
bool getSortie()
|
||||
{
|
||||
return(sortie);
|
||||
return (sortie);
|
||||
}
|
||||
// Recuperation du temps ecoule depuis le debut si necessaire
|
||||
unsigned long getTempsEcoule()
|
||||
{
|
||||
return(tempsEcoule);
|
||||
return (tempsEcoule);
|
||||
}
|
||||
|
||||
// Attributs
|
||||
private:
|
||||
unsigned long duree;
|
||||
unsigned long debut;
|
||||
unsigned long tempsEcoule;
|
||||
bool captureTemps;
|
||||
bool sortie;
|
||||
// Attributs
|
||||
private:
|
||||
unsigned long duree;
|
||||
unsigned long debut;
|
||||
unsigned long tempsEcoule;
|
||||
bool captureTemps;
|
||||
bool sortie;
|
||||
};
|
||||
|
||||
/********************************************************
|
||||
* TEMPORISATION RETARD A LA DESCENTE *
|
||||
* La sortie passe à 0 au bout de la tempo *
|
||||
*********************************************************/
|
||||
* TEMPORISATION RETARD A LA DESCENTE *
|
||||
* La sortie passe à 0 au bout de la tempo *
|
||||
*********************************************************/
|
||||
class TemporisationRetardDescente
|
||||
{
|
||||
public :
|
||||
// Contructeur qui prend la duree souhaitee de la temporisation
|
||||
public:
|
||||
// Contructeur qui prend la duree souhaitee de la temporisation
|
||||
TemporisationRetardDescente(unsigned long duree)
|
||||
{
|
||||
this->duree = duree;
|
||||
sortie = false;
|
||||
captureTemps = false;
|
||||
}
|
||||
// Activation de la temporisation. Doit etre fait tout le temps de la duree de la tempo
|
||||
// Activation de la temporisation. Doit etre fait tout le temps de la duree de la tempo
|
||||
void activation()
|
||||
{
|
||||
// Capture du temps de reference
|
||||
if(!captureTemps)
|
||||
if (!captureTemps)
|
||||
{
|
||||
debut = millis();
|
||||
captureTemps = true;
|
||||
@@ -329,22 +381,22 @@ class TemporisationRetardDescente
|
||||
captureTemps = false;
|
||||
}
|
||||
// Interrogration du bit de fin de tempo
|
||||
bool getSortie()
|
||||
bool getSortie()
|
||||
{
|
||||
return(sortie);
|
||||
return (sortie);
|
||||
}
|
||||
// Recuperation du temps ecoule depuis le debut si necessaire
|
||||
unsigned long getTempsEcoule()
|
||||
unsigned long getTempsEcoule()
|
||||
{
|
||||
return(tempsEcoule);
|
||||
return (tempsEcoule);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned long duree;
|
||||
unsigned long debut;
|
||||
unsigned long tempsEcoule;
|
||||
bool captureTemps;
|
||||
bool sortie;
|
||||
private:
|
||||
unsigned long duree;
|
||||
unsigned long debut;
|
||||
unsigned long tempsEcoule;
|
||||
bool captureTemps;
|
||||
bool sortie;
|
||||
};
|
||||
|
||||
/********************************************************
|
||||
@@ -352,22 +404,22 @@ class TemporisationRetardDescente
|
||||
*********************************************************/
|
||||
class Clignoteur
|
||||
{
|
||||
// methodes
|
||||
public :
|
||||
// methodes
|
||||
public:
|
||||
// Construteur qui prend en parametre le temps haut ou bas souhaitee
|
||||
Clignoteur(int baseDeTemps)
|
||||
{
|
||||
this->baseDeTemps = baseDeTemps;
|
||||
}
|
||||
// Fonction qui renvoie true si le clignoteur est ├á l'├®tat haut et false s'il est ├á l'├®tat bas
|
||||
bool statut()
|
||||
bool statut()
|
||||
{
|
||||
return ((millis() / baseDeTemps) % 2 == 1);
|
||||
}
|
||||
|
||||
// Attributs
|
||||
private:
|
||||
int baseDeTemps;
|
||||
// Attributs
|
||||
private:
|
||||
int baseDeTemps;
|
||||
};
|
||||
|
||||
/********************************************************
|
||||
@@ -376,8 +428,8 @@ class Clignoteur
|
||||
*********************************************************/
|
||||
class Compteur
|
||||
{
|
||||
// methodes
|
||||
public :
|
||||
// methodes
|
||||
public:
|
||||
// Constructeur qui prend en parametre la valeur de preselection
|
||||
Compteur(int valeurPreselection)
|
||||
{
|
||||
@@ -402,18 +454,18 @@ class Compteur
|
||||
// recuperation de la valeur courante
|
||||
int getValeurCourante()
|
||||
{
|
||||
return(valeur);
|
||||
return (valeur);
|
||||
}
|
||||
// est-ce que la preselection est atteinte (sortie Q compteur Siemens ou Schnieder)
|
||||
bool getSortie()
|
||||
{
|
||||
return(valeur == valeurPreselection);
|
||||
return (valeur == valeurPreselection);
|
||||
}
|
||||
|
||||
// Attributs
|
||||
private:
|
||||
int valeur;
|
||||
int valeurPreselection;
|
||||
// Attributs
|
||||
private:
|
||||
int valeur;
|
||||
int valeurPreselection;
|
||||
};
|
||||
|
||||
/********************************************************
|
||||
@@ -421,9 +473,9 @@ class Compteur
|
||||
*********************************************************/
|
||||
class MiseAEchelle
|
||||
{
|
||||
public :
|
||||
public:
|
||||
// Constructeur qui ne prend en parametre la plage d'entree et la plage de sortie
|
||||
MiseAEchelle(float minEntree,float maxEntree,float minSortie,float maxSortie)
|
||||
MiseAEchelle(float minEntree, float maxEntree, float minSortie, float maxSortie)
|
||||
{
|
||||
this->minEntree = minEntree;
|
||||
this->maxEntree = maxEntree;
|
||||
@@ -433,19 +485,19 @@ class MiseAEchelle
|
||||
// fonction de conversion qui prend la valeur a convertir et renvoie la valeur convertie
|
||||
float convertir(float valeurAConvertir)
|
||||
{
|
||||
if(valeurAConvertir >= minEntree && valeurAConvertir <= maxEntree)
|
||||
if (valeurAConvertir >= minEntree && valeurAConvertir <= maxEntree)
|
||||
{
|
||||
float norm = (1 / (maxEntree - minEntree)) * (valeurAConvertir - minEntree);
|
||||
float scale = (maxSortie - minSortie) * norm + minSortie;
|
||||
return(scale);
|
||||
return (scale);
|
||||
}
|
||||
return(-1000);
|
||||
return (-1000);
|
||||
}
|
||||
|
||||
// Attributs
|
||||
private:
|
||||
float minEntree;
|
||||
float minSortie;
|
||||
float maxEntree;
|
||||
// Attributs
|
||||
private:
|
||||
float minEntree;
|
||||
float minSortie;
|
||||
float maxEntree;
|
||||
float maxSortie;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user