From b673946d76e436c067d24e535b1e0a167b9dfc47 Mon Sep 17 00:00:00 2001 From: galmes Date: Sun, 25 Jan 2004 21:31:01 +0000 Subject: Implémentation des classes "Communication_module" et "communication_asservissement_control" --- .../src/communication_asservissement_control.cc | 59 ++++++++++++++++++++ .../src/communication_asservissement_control.h | 12 +++- i/siroco/src/communication_asservissement_data.h | 14 +++-- i/siroco/src/communication_hub.cc | 58 ++++++++++++++++++++ i/siroco/src/communication_module.cc | 64 ++++++++++++++++++++++ i/siroco/src/communication_module.h | 25 ++++++++- i/siroco/src/message.h | 9 ++- i/siroco/src/message_asservissement_control.h | 2 +- i/siroco/src/pg_test/Makefile | 14 ++++- .../communication_asservissement_control_test.cc | 42 ++++++++++++++ i/siroco/src/pg_test/communication_module_test.cc | 42 ++++++++++++++ 11 files changed, 325 insertions(+), 16 deletions(-) create mode 100644 i/siroco/src/communication_asservissement_control.cc create mode 100644 i/siroco/src/communication_hub.cc create mode 100644 i/siroco/src/communication_module.cc create mode 100644 i/siroco/src/pg_test/communication_asservissement_control_test.cc create mode 100644 i/siroco/src/pg_test/communication_module_test.cc (limited to 'i') diff --git a/i/siroco/src/communication_asservissement_control.cc b/i/siroco/src/communication_asservissement_control.cc new file mode 100644 index 0000000..9645cf4 --- /dev/null +++ b/i/siroco/src/communication_asservissement_control.cc @@ -0,0 +1,59 @@ +// communication_asservissement_control.cc +// {{{ +// +// Copyright (C) 2004 Pierre-André Galmes +// +// Robot APB Team/Efrei 2004. +// Web: http://assos.efrei.fr/robot/ +// Email: robot AT efrei DOT fr +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} +#include "communication_asservissement_control.h" + +namespace Siroco +{ + +// Paramètre le connecteur. +void +CommunicationAsservissementControl::setConnector (Connector &c) +{ +} + +// Recoie un message. +void +CommunicationAsservissementControl::recv (const Message &m) +{ +} + +// Envoie des messages de changement de Coef. +void +CommunicationAsservissementControl::coefP (int val) const +{ + +} + +void +CommunicationAsservissementControl::coefI (int val) const +{ +} + +void +CommunicationAsservissementControl::coefD (int val) const +{ +} + +}; //namespace Siroco diff --git a/i/siroco/src/communication_asservissement_control.h b/i/siroco/src/communication_asservissement_control.h index 4c04879..e408cb8 100644 --- a/i/siroco/src/communication_asservissement_control.h +++ b/i/siroco/src/communication_asservissement_control.h @@ -24,16 +24,24 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // }}} +#include "communication_module.h" -class CommunicationAsservissementControl +namespace Siroco { + +class CommunicationAsservissementControl : public CommunicationModule +{ + + public: class Connector { public: // Envoie les informations de PID à l'objet. virtual void recvPID (int p, int i, int d) = 0; }; + private: Connector &connector_; + public: // Paramètre le connecteur. void setConnector (Connector &c); @@ -45,4 +53,6 @@ class CommunicationAsservissementControl void coefD (int val) const; }; +}; //Siroco + #endif // communication_asservissement_control_h diff --git a/i/siroco/src/communication_asservissement_data.h b/i/siroco/src/communication_asservissement_data.h index 8c8eb31..6cd0fa0 100644 --- a/i/siroco/src/communication_asservissement_data.h +++ b/i/siroco/src/communication_asservissement_data.h @@ -25,8 +25,11 @@ // // }}} -class CommunicationAsservissementData +class CommunicationAsservissementData : public CommunicationModule { + private: + Connector &connector_; + public: // Classe de connection entre CommunicationAsservissementData et un autre // objet. class Connector @@ -39,16 +42,17 @@ class CommunicationAsservissementData int consignMax, int pwmMax, int measureMax) = 0; }; - Connector &connector_; - public: - // Destructeur. + + // Constructeur / Destructeur. + CommunicationModule (void); ~CommunicationModule (void); // Paramètre le connecteur. void setConnector (Connector &c); // Recoie un message. void recv (const Message &m); + // Active (true) ou désactive (false) le module. - void activate (bool flag = true); + //void activate (bool flag = true); }; #endif // communication_asservissement_data_h diff --git a/i/siroco/src/communication_hub.cc b/i/siroco/src/communication_hub.cc new file mode 100644 index 0000000..5247d7f --- /dev/null +++ b/i/siroco/src/communication_hub.cc @@ -0,0 +1,58 @@ +// communication_hub.cc +// {{{ +// +// Copyright (C) 2004 Pierre-André Galmes +// +// Robot APB Team/Efrei 2004. +// Web: http://assos.efrei.fr/robot/ +// Email: robot AT efrei DOT fr +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} +#include "communication_hub.h" + +namespace Siroco +{ + +// Enregistre un module. +void +CommunicationHub::add (CommunicationModule &m) +{ + moduleList_.push_back (m); +} + +// Unregister a module. +void +CommunicationHub::remove (CommunicationModule &m) +{ + moduleList_.pop_back (m); +} + +// Envoie un message à tout le monde sauf à soit même. +void +CommunicationHub::send (CommunicationModule &sender, Message &m) +{ + CommunicationModule::iterator i; + + for (i = moduleList_.begin(); i != moduleList.end(); i++) + { + // On envoie le message à tous les modules sauf à l'envoyeur ! + if (&sender != i) + i.recv (m); + } +} + +}; diff --git a/i/siroco/src/communication_module.cc b/i/siroco/src/communication_module.cc new file mode 100644 index 0000000..e8c7e6f --- /dev/null +++ b/i/siroco/src/communication_module.cc @@ -0,0 +1,64 @@ +// communication_module.cc +// {{{ +// +// Copyright (C) 2004 Pierre-André Galmes +// +// Robot APB Team/Efrei 2004. +// Web: http://assos.efrei.fr/robot/ +// Email: robot AT efrei DOT fr +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} +#include "communication_module.h" + +namespace Siroco +{ + +// Constructeur. +CommunicationModule::CommunicationModule (bool state) +{ + // module est désactivé par défaut. + state_ = state; +} + +// Destructeur (virtuel). +CommunicationModule::~CommunicationModule (void) +{ + // vide +} + +// Recoie un message (virtuel). +void +CommunicationModule::recv (const Message &m) +{ + // vide +} + +// Active (true) ou désactive (false) le module. +void +CommunicationModule::activate (bool flag) +{ + state_ = flag; +} + +// +bool +CommunicationModule::is_active (void) +{ + return state_; +} + +}; diff --git a/i/siroco/src/communication_module.h b/i/siroco/src/communication_module.h index 865b882..d95bab6 100644 --- a/i/siroco/src/communication_module.h +++ b/i/siroco/src/communication_module.h @@ -26,15 +26,34 @@ // }}} #include "message.h" +namespace Siroco +{ + class CommunicationModule { + private: + // Activé ou Désactivé. + bool state_; public: - // Destructeur. - virtual ~CommunicationModule (void); + // Constructeur / Destructeur. + CommunicationModule (bool state = false); + ~CommunicationModule (void); + + // ce qu'on avait dit qui me semble pas top;.. + //virtual ~CommunicationModule (void); + // Recoie un message. + // virtual void recv (void); + //Message m); + // Initial virtual void recv (const Message &m); + + // Active (true) ou désactive (false) le module. - virtual void activate (bool flag = true); + // virtual void activate (bool flag = true); + void activate (bool flag = true); + bool is_active (void); }; +}; //namespace Siroco #endif // communication_module_h diff --git a/i/siroco/src/message.h b/i/siroco/src/message.h index 302ef4d..3b955a5 100644 --- a/i/siroco/src/message.h +++ b/i/siroco/src/message.h @@ -42,7 +42,10 @@ class Message }; private: Type type_; - public: + // Méthodes interdites. + Message (const Message &); + Message &operator= (const Message &); + public: // Constructeur. Message (Type type); // Destructeur et Big 3. @@ -52,10 +55,6 @@ class Message // Récupère le message. template const T &get (void) const; - private: - // Méthodes interdites. - Message (const Message &); - Message &operator= (const Message &); }; // Récupère le message. diff --git a/i/siroco/src/message_asservissement_control.h b/i/siroco/src/message_asservissement_control.h index f460656..b6e0039 100644 --- a/i/siroco/src/message_asservissement_control.h +++ b/i/siroco/src/message_asservissement_control.h @@ -41,6 +41,6 @@ class MessageAsservissementControl : public Message void get (char &type, int &val) const; }; -}; +}; //Siroco #endif // message_asservissement_control_h diff --git a/i/siroco/src/pg_test/Makefile b/i/siroco/src/pg_test/Makefile index 6d01b3c..88603c0 100755 --- a/i/siroco/src/pg_test/Makefile +++ b/i/siroco/src/pg_test/Makefile @@ -3,7 +3,8 @@ TARGET_A = message_test OBJECTS_A = message_test.o ../message.o TARGET_B = message_asservissement_info_test -OBJECTS_B = message_asservissement_info_test.o ../message_asservissement_info.o ../message.o +OBJECTS_B = message_asservissement_info_test.o \ + ../message_asservissement_info.o ../message.o TARGET_MAGI = message_asservissement_get_info_test OBJECTS_MAGI = message_asservissement_get_info_test.o \ @@ -17,6 +18,10 @@ TARGET_MAC = message_asservissement_control_test OBJECTS_MAC = message_asservissement_control_test.o \ ../message_asservissement_control.o ../message.o +TARGET_CM = communication_module_test +OBJECTS_CM = communication_module_test.o ../communication_module.o \ + ../message.o + # LIB = -lccgnu2 -ldl -pthread CFLAGS = -O2 -Wall -g @@ -48,6 +53,13 @@ mac: $(TARGET_MAC) $(TARGET_MAC): $(OBJECTS_MAC) $(CC) $(CFLAGS) -o $@ $^ + +cm: $(TARGET_CM) + +$(TARGET_CM): $(OBJECTS_CM) + $(CC) $(CFLAGS) -o $@ $^ + + #$(LIB) # $(TARGET_B): $(OBJECTS_B) diff --git a/i/siroco/src/pg_test/communication_asservissement_control_test.cc b/i/siroco/src/pg_test/communication_asservissement_control_test.cc new file mode 100644 index 0000000..03c5059 --- /dev/null +++ b/i/siroco/src/pg_test/communication_asservissement_control_test.cc @@ -0,0 +1,42 @@ +// communication_module_test.cc +// {{{ +// +// Copyright (C) 2004 Pierre-André Galmes +// +// Robot APB Team/Efrei 2004. +// Web: http://assos.efrei.fr/robot/ +// Email: robot AT efrei DOT fr +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} +#include +#include "../communication_asservissement_control.h" + + +using namespace std; +using namespace Siroco; + +int +main (void) +{ + Communication c; + + cout << "active : " << c.is_active () << endl; + + c.activate (); + cout << "active : " << c.is_active () << endl; + +} diff --git a/i/siroco/src/pg_test/communication_module_test.cc b/i/siroco/src/pg_test/communication_module_test.cc new file mode 100644 index 0000000..cde9279 --- /dev/null +++ b/i/siroco/src/pg_test/communication_module_test.cc @@ -0,0 +1,42 @@ +// communication_module_test.cc +// {{{ +// +// Copyright (C) 2004 Pierre-André Galmes +// +// Robot APB Team/Efrei 2004. +// Web: http://assos.efrei.fr/robot/ +// Email: robot AT efrei DOT fr +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} +#include +#include "../communication_module.h" + + +using namespace std; +using namespace Siroco; + +int +main (void) +{ + CommunicationModule c; + + cout << "active : " << c.is_active () << endl; + + c.activate (); + cout << "active : " << c.is_active () << endl; + +} -- cgit v1.2.3