summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaller2005-12-19 23:21:42 +0000
committerhaller2005-12-19 23:21:42 +0000
commit08665d1190b5512046797e34041575aeaccc1ec7 (patch)
tree2f388ad8bee1119fd113ce3c0041628066eeeee3
parent001f91e6ddce33aec769348adc55f0c0b0c09534 (diff)
* Creation du fichier comc.c
* Codage de Aiguillage en progression... * Creation d'un test_aiguillage pipo (pour l'instant) * Ajout de fonctionnalité à GSMessage * Ajout de Aiguillage pour la compilation dans le Makefile.am
-rw-r--r--i/simulotron/src/Makefile.am4
-rw-r--r--i/simulotron/src/aiguillage/aiguillage.cc74
-rw-r--r--i/simulotron/src/aiguillage/aiguillage.hh14
-rw-r--r--i/simulotron/src/aiguillage/test_aiguillage.cc4
-rw-r--r--i/simulotron/src/comc/comc.cc39
-rw-r--r--i/simulotron/src/gs/gs_message.cc14
-rw-r--r--i/simulotron/src/gs/gs_message.hh4
7 files changed, 146 insertions, 7 deletions
diff --git a/i/simulotron/src/Makefile.am b/i/simulotron/src/Makefile.am
index ce848fe..ddf2d78 100644
--- a/i/simulotron/src/Makefile.am
+++ b/i/simulotron/src/Makefile.am
@@ -3,12 +3,14 @@ check_PROGRAMS =
include socket/Makefile.incl.am
include utils/Makefile.incl.am
include gs/Makefile.incl.am
+include aiguillage/Makefile.incl.am
bin_PROGRAMS = simulotron
simulotron_SOURCES = main.cc \
$(socket_S) \
$(gs_message_S) \
- $(gs_transmitter_S)
+ $(gs_transmitter_S) \
+ $(aiguillage_S)
AM_CXXFLAGS = -g -Wall -W -fmessage-length=0
simulotron_LDADD =
diff --git a/i/simulotron/src/aiguillage/aiguillage.cc b/i/simulotron/src/aiguillage/aiguillage.cc
new file mode 100644
index 0000000..95bbad1
--- /dev/null
+++ b/i/simulotron/src/aiguillage/aiguillage.cc
@@ -0,0 +1,74 @@
+/* aiguillage.cc - Classe rajoutant les info de la source et de la dest d'un packet */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2005 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2006.
+ * 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 "aiguillage/aiguillage.hh"
+#include "gs/gs_message.hh"
+
+#include <stdexcept>
+
+/// Constructeur
+Aiguillage::Aiguillage(const std::string & address, int port, const std::string & name)
+ :gst_(address, port)
+{
+ setName(name);
+}
+
+/// Envoie un paquet en rajoutant les infos de sources et de provenance
+void
+Aiguillage::send(const GSMessage & gsm, const std::string & source,
+ const std::string & dest)
+{
+ ///\todo Voir pour optimiser ca
+ GSMessage g = gsm;
+ g.insertFrontGS(dest.data(), MAX_SIZE_NAME);
+ // Si source est vide, mettre name_
+ if(source.empty())
+ g.insertFrontGS(name_.data(), MAX_SIZE_NAME);
+ else
+ g.insertFrontGS(source.data(), MAX_SIZE_NAME);
+ gst_.putGS(g);
+}
+
+/// Reçoie un paquet du réseau et supprime les infos src et dest du GSM
+int
+Aiguillage::receive(GSMessage & gsm, std::string & source, std::string & dest)
+{
+ if(gst_.getGS(gsm) != 0)
+ return -1;
+ gsm.getString(source, 8);
+ gsm.getString(dest, 8);
+ gsm.delBeforeIt();
+ return 0;
+}
+
+void
+Aiguillage::setName(const std::string & name)
+{
+ if(name.size() > MAX_SIZE_NAME)
+ throw std::runtime_error("Le nom est trop long!!");
+ name_ = name;
+ name_.append(MAX_SIZE_NAME - name.size(), '\0');
+}
+
diff --git a/i/simulotron/src/aiguillage/aiguillage.hh b/i/simulotron/src/aiguillage/aiguillage.hh
index a549eae..3ec2bae 100644
--- a/i/simulotron/src/aiguillage/aiguillage.hh
+++ b/i/simulotron/src/aiguillage/aiguillage.hh
@@ -25,22 +25,24 @@
*
* }}} */
+#include "gs/gs_transmitter.hh"
+
class Aiguillage
{
private:
- static const int MAX_SIZE_NAME = 8;
+ static const unsigned int MAX_SIZE_NAME = 8;
private:
- GSTransmitter gqt_;
+ GSTransmitter gst_;
std::string name_;
public:
/// Constructeur
- Aiguillage(void);
+ Aiguillage(const std::string & address, int port, const std::string & name);
/// Envoie un paquet en rajoutant les infos de sources et de provenance
- void send(GSMessage & gsm, const std::string & source, const std::string & dest);
+ void send(const GSMessage & gsm, const std::string & source, const std::string & dest);
/// Reçoie un paquet du réseau et supprime les infos src et dest du GSM
- int receive(GSMessage & gsm, std::string & source, const std::string & dest);
+ int receive(GSMessage & gsm, std::string & source, std::string & dest);
private:
/// Set le nom de transmition
- void setName(std::string & name);
+ void setName(const std::string & name);
};
#endif //AIGUILLAGE_HH
diff --git a/i/simulotron/src/aiguillage/test_aiguillage.cc b/i/simulotron/src/aiguillage/test_aiguillage.cc
new file mode 100644
index 0000000..82be6e4
--- /dev/null
+++ b/i/simulotron/src/aiguillage/test_aiguillage.cc
@@ -0,0 +1,4 @@
+int main (void)
+{
+ return 0;
+}
diff --git a/i/simulotron/src/comc/comc.cc b/i/simulotron/src/comc/comc.cc
new file mode 100644
index 0000000..4781c33
--- /dev/null
+++ b/i/simulotron/src/comc/comc.cc
@@ -0,0 +1,39 @@
+/* comc.cc - Classe la plus haute dans la transmission par socket */
+/* Simulotron - Programme de simulation de robot {{{
+ *
+ * Copyright (C) 2005 Nicolas Haller
+ *
+ * Robot APB Team/Efrei 2006.
+ * 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.
+ *
+ * }}} */
+
+/// Constructeur
+template <class C>
+ComC<C>::ComC(const std::string & address, int port, const std::string & name)
+ :C(),gst_(address, port)
+{
+}
+/// Envoie un truc dans le réseau
+template <class T>
+void send(const T & message, const std::string & destname);
+/// Recoie quelque chose et appelle une fonction callback
+template <class C>
+void receive(void);
+
+#endif //COMC_HH
diff --git a/i/simulotron/src/gs/gs_message.cc b/i/simulotron/src/gs/gs_message.cc
index 34a4368..c0e099a 100644
--- a/i/simulotron/src/gs/gs_message.cc
+++ b/i/simulotron/src/gs/gs_message.cc
@@ -56,6 +56,13 @@ GSMessage::readGS(void * data, size_t size)
}
void
+GSMessage::getString(std::string & str, size_t size)
+{
+ str.assign(igs_, igs_ + size);
+ igs_ += size;
+}
+
+void
GSMessage::appendGS (const void * data, size_t size)
{
gs_.append(static_cast<const char *> (data), size);
@@ -81,3 +88,10 @@ GSMessage::clear(void)
gs_.clear();
setIteratorBegin();
}
+
+void
+GSMessage::delBeforeIt(void)
+{
+ gs_.erase(gs_.begin(), igs_ - 1);
+ setIteratorBegin();
+}
diff --git a/i/simulotron/src/gs/gs_message.hh b/i/simulotron/src/gs/gs_message.hh
index 2f01949..45ed43d 100644
--- a/i/simulotron/src/gs/gs_message.hh
+++ b/i/simulotron/src/gs/gs_message.hh
@@ -44,6 +44,8 @@ class GSMessage
const std::string & getGS (void) const;
/// Récupération de données de la gs
void readGS (void * data, size_t size);
+ /// Récupère des données sous forme d'une string
+ void getString (std::string & str, size_t size);
/// Ecriture à la fin de la gs
void appendGS (const void * data, size_t size);
/// Ecriture au début de la gs
@@ -52,6 +54,8 @@ class GSMessage
void setIteratorBegin(void);
/// Efface la GS
void clear(void);
+ /// Efface tout ce qu'il y a avant l'iterateur
+ void delBeforeIt(void);
};
#endif //gs_message_hh