summaryrefslogtreecommitdiff
path: root/2004
diff options
context:
space:
mode:
Diffstat (limited to '2004')
-rw-r--r--2004/i/nono/src/io/Makefile.defs10
-rw-r--r--2004/i/nono/src/io/gpio.cc52
-rw-r--r--2004/i/nono/src/io/gpio.h8
-rw-r--r--2004/i/nono/src/io/gpio_asserv.cc76
-rw-r--r--2004/i/nono/src/io/gpio_asserv.h53
-rw-r--r--2004/i/nono/src/io/gpio_concat.cc117
-rw-r--r--2004/i/nono/src/io/gpio_concat.h49
-rw-r--r--2004/i/nono/src/io/gpio_servo_pp.cc111
-rw-r--r--2004/i/nono/src/io/gpio_servo_pp.h22
-rw-r--r--2004/i/nono/src/io/io_cmd.cc82
-rw-r--r--2004/i/nono/src/io/io_cmd.h35
-rw-r--r--2004/i/nono/src/io/test_gpio_concat.cc105
-rw-r--r--2004/i/nono/src/io/test_io.cc73
13 files changed, 605 insertions, 188 deletions
diff --git a/2004/i/nono/src/io/Makefile.defs b/2004/i/nono/src/io/Makefile.defs
index 6927dc0..b6bb88d 100644
--- a/2004/i/nono/src/io/Makefile.defs
+++ b/2004/i/nono/src/io/Makefile.defs
@@ -1,9 +1,13 @@
-TARGETS += test_io
+TARGETS += test_io test_gpio_concat
LIBS += io.a
-test_io_SOURCES = test_io.cc io.a date.a serial.a
-io_a_SOURCES = gpio.cc gpio_servo_pp.cc
+test_io_SOURCES = test_io.cc io_cmd.cc io.a date.a serial.a motor.a logger.a \
+ utils.a config.a erreur.a
+test_gpio_concat_SOURCES = test_gpio_concat.cc io_cmd.cc io.a date.a serial.a
+io_a_SOURCES = gpio.cc gpio_servo_pp.cc gpio_concat.cc gpio_asserv.cc
test_io: $(test_io_SOURCES:%.cc=%.o)
+test_gpio_concat: $(test_gpio_concat_SOURCES:%.cc=%.o)
+
io.a: ${io_a_SOURCES:%.cc=io.a(%.o)}
diff --git a/2004/i/nono/src/io/gpio.cc b/2004/i/nono/src/io/gpio.cc
index 172394d..4b23450 100644
--- a/2004/i/nono/src/io/gpio.cc
+++ b/2004/i/nono/src/io/gpio.cc
@@ -33,72 +33,52 @@ Gpio::~Gpio (void)
void
Gpio::set (int n, unsigned int bits, int nb)
{
- for (int i = 0; i < nb; ++i)
- {
- set (n + i, bits & 1);
- bits >>= 1;
- }
}
/// Change une sortie.
void
Gpio::set (int n, unsigned int bit)
{
+ set (n, bit, 1);
}
/// Lit plusieurs entrées.
unsigned int
Gpio::get (int n, int nb)
{
- unsigned int bits = 0;
- for (int i = nb - 1; i >= 0; --i)
- {
- bits <<= 1;
- bits |= get (n + i) & 1;
- }
- return bits;
+ return 0;
}
/// Lit une entrée.
unsigned int
Gpio::get (int n)
{
- return 0;
+ return get (n, 1);
}
-/// Pré-lit plusieurs entrées.
-bool
-Gpio::preget (int n, int nb)
+/// Change la direction de plusieurs I/O.
+void
+Gpio::dir (int n, unsigned int bits, int nb)
{
- bool ok = true;
- for (int i = nb - 1; i >= 0; --i)
- {
- ok &= preget (n + i);
- }
- return ok;
}
-/// Pré-lit une entrée.
-bool
-Gpio::preget (int n)
+/// Change la direction d'un I/O (1 pour I, 0 pour O).
+void
+Gpio::dir (int n, unsigned int bit)
{
- return true;
+ dir (n, bit, 1);
}
-/// Change la direction de plusieurs I/O.
+/// Met à jour.
void
-Gpio::dir (int n, unsigned int bits, int nb)
+Gpio::update (void)
{
- for (int i = 0; i < nb; ++i)
- {
- dir (n + i, bits & 1);
- bits >>= 1;
- }
}
-/// Change la direction d'un I/O (1 pour I, 0 pour O).
-void
-Gpio::dir (int n, unsigned int bit)
+/// Récupère le nombre d'entrées/sorties.
+int
+Gpio::getNbIo (void)
{
+ return 0;
}
diff --git a/2004/i/nono/src/io/gpio.h b/2004/i/nono/src/io/gpio.h
index ecc63f0..65a5a64 100644
--- a/2004/i/nono/src/io/gpio.h
+++ b/2004/i/nono/src/io/gpio.h
@@ -45,14 +45,14 @@ class Gpio
virtual unsigned int get (int n, int nb);
/// Lit une entrée.
virtual unsigned int get (int n);
- /// Pré-lit plusieurs entrées.
- virtual bool preget (int n, int nb);
- /// Pré-lit une entrée.
- virtual bool preget (int n);
/// Change la direction de plusieurs I/O.
virtual void dir (int n, unsigned int bits, int nb);
/// Change la direction d'un I/O (1 pour I, 0 pour O).
virtual void dir (int n, unsigned int bit);
+ /// Met à jour.
+ virtual void update (void);
+ /// Récupère le nombre d'entrées/sorties.
+ virtual int getNbIo (void);
};
#endif // gpio_h
diff --git a/2004/i/nono/src/io/gpio_asserv.cc b/2004/i/nono/src/io/gpio_asserv.cc
new file mode 100644
index 0000000..de2256d
--- /dev/null
+++ b/2004/i/nono/src/io/gpio_asserv.cc
@@ -0,0 +1,76 @@
+// gpio_asserv.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "gpio_asserv.h"
+#include "motor/asserv.h"
+
+#include <stdexcept>
+
+/// Constructeur.
+GpioAsserv::GpioAsserv (Asserv &asserv)
+ : outputs_ (0), asserv_ (asserv)
+{
+ asserv_.setGpiDelay (3);
+}
+
+/// Destructeur.
+GpioAsserv::~GpioAsserv (void)
+{
+ asserv_.setGpiDelay (0);
+}
+
+/// Change plusieurs sorties.
+void
+GpioAsserv::set (int n, unsigned int bits, int nb)
+{
+ if (n < 0 || n + nb > nbOutputs_)
+ throw std::out_of_range ("GpioServoPp::set: Out of range.");
+ unsigned int mask = (1 << nb) - 1;
+ mask <<= n;
+ bits <<= n;
+ outputs_ = (outputs_ & ~mask) | (bits & mask);
+ unsigned int toSend = (outputs_ & 0x07) << 1 | (outputs_ & 0x18) << 2;
+ asserv_.sendGpo (toSend);
+}
+
+/// Lit plusieurs entrées.
+unsigned int
+GpioAsserv::get (int n, int nb)
+{
+ if (n < nbOutputs_ || n + nb > nbOutputs_ + nbInputs_)
+ throw std::out_of_range ("GpioServoPp::get: Out of range.");
+ unsigned int mask = 1 << (nb) - 1;
+ unsigned int recv = asserv_.getGpi ();
+ recv = recv >> 2;
+ unsigned int bits = (recv >> (n - nbOutputs_)) & mask;
+ return bits;
+}
+
+/// Récupère le nombre d'entrées/sorties.
+int
+GpioAsserv::getNbIo (void)
+{
+ return nbOutputs_ + nbInputs_;
+}
+
diff --git a/2004/i/nono/src/io/gpio_asserv.h b/2004/i/nono/src/io/gpio_asserv.h
new file mode 100644
index 0000000..557b77e
--- /dev/null
+++ b/2004/i/nono/src/io/gpio_asserv.h
@@ -0,0 +1,53 @@
+#ifndef gpio_asserv_h
+#define gpio_asserv_h
+// gpio_asserv.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "gpio.h"
+
+class Asserv;
+
+/// Classe pour la gestion de la carte servo à Pierre Prot.
+class GpioAsserv : public Gpio
+{
+ /// Nombre d'entrées/sorties.
+ static const int nbInputs_ = 6, nbOutputs_ = 5;
+ /// Sorties courantes.
+ unsigned int outputs_;
+ /// Référence vers l'asserv.
+ Asserv &asserv_;
+ public:
+ /// Constructeur.
+ explicit GpioAsserv (Asserv &asserv);
+ /// Destructeur.
+ ~GpioAsserv (void);
+ /// Change plusieurs sorties.
+ void set (int n, unsigned int bits, int nb);
+ /// Lit plusieurs entrées.
+ unsigned int get (int n, int nb);
+ /// Récupère le nombre d'entrées/sorties.
+ int getNbIo (void);
+};
+
+#endif // gpio_asserv_h
diff --git a/2004/i/nono/src/io/gpio_concat.cc b/2004/i/nono/src/io/gpio_concat.cc
new file mode 100644
index 0000000..646a524
--- /dev/null
+++ b/2004/i/nono/src/io/gpio_concat.cc
@@ -0,0 +1,117 @@
+// gpio_concat.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "gpio_concat.h"
+
+/// Constructeur.
+GpioConcat::GpioConcat (Gpio &io0, Gpio &io1, int nSep)
+ : io0_ (io0), io1_ (io1), nSep_ (nSep)
+{
+}
+
+/// Change plusieurs sorties.
+void
+GpioConcat::set (int n, unsigned int bits, int nb)
+{
+ if (n < nSep_)
+ {
+ int n0, bits0, nb0;
+ n0 = n;
+ nb0 = n + nb > nSep_ ? nSep_ - n : nb;
+ bits0 = bits & ((1 << nb0) - 1);
+ io0_.set (n0, bits0, nb0);
+ }
+ if (n + nb > nSep_)
+ {
+ int n1, bits1, nb1;
+ n1 = n < nSep_ ? 0 : n - nSep_;
+ nb1 = n < nSep_ ? nb - nSep_ + n : nb;
+ bits1 = n < nSep_ ? bits >> (nSep_ - n) : bits;
+ bits1 &= ((1 << nb1) - 1);
+ io1_.set (n1, bits1, nb1);
+ }
+}
+
+/// Lit plusieurs entrées.
+unsigned int
+GpioConcat::get (int n, int nb)
+{
+ int n0, bits0 = 0, nb0;
+ int n1, bits1 = 0, nb1;
+ if (n < nSep_)
+ {
+ n0 = n;
+ nb0 = n + nb > nSep_ ? nSep_ - n : nb;
+ bits0 = io0_.get (n0, nb0);
+ bits0 &= ((1 << nb0) - 1);
+ }
+ if (n + nb > nSep_)
+ {
+ n1 = n < nSep_ ? 0 : n - nSep_;
+ nb1 = n < nSep_ ? nb - nSep_ + n : nb;
+ bits1 = io1_.get (n1, nb1);
+ bits1 &= ((1 << nb1) - 1);
+ bits1 = n < nSep_ ? bits1 << (nSep_ - n) : bits1;
+ }
+ return bits0 | bits1;
+}
+
+/// Change la direction de plusieurs I/O.
+void
+GpioConcat::dir (int n, unsigned int bits, int nb)
+{
+ if (n < nSep_)
+ {
+ int n0, bits0, nb0;
+ n0 = n;
+ nb0 = n + nb > nSep_ ? nSep_ - n : nb;
+ bits0 = bits & ((1 << nb0) - 1);
+ io0_.dir (n0, bits0, nb0);
+ }
+ if (n + nb > nSep_)
+ {
+ int n1, bits1, nb1;
+ n1 = n < nSep_ ? 0 : n - nSep_;
+ nb1 = n < nSep_ ? nb - nSep_ + n : nb;
+ bits1 = n < nSep_ ? bits >> (nSep_ - n) : bits;
+ bits1 &= ((1 << nb1) - 1);
+ io1_.dir (n1, bits1, nb1);
+ }
+}
+
+/// Met à jour.
+void
+GpioConcat::update (void)
+{
+ io0_.update ();
+ io1_.update ();
+}
+
+/// Récupère le nombre d'entrées/sorties.
+int
+GpioConcat::getNbIo (void)
+{
+ return io0_.getNbIo () + io1_.getNbIo ();
+}
+
diff --git a/2004/i/nono/src/io/gpio_concat.h b/2004/i/nono/src/io/gpio_concat.h
new file mode 100644
index 0000000..73bab01
--- /dev/null
+++ b/2004/i/nono/src/io/gpio_concat.h
@@ -0,0 +1,49 @@
+#ifndef gpio_concat_h
+#define gpio_concat_h
+// gpio_concat.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "gpio.h"
+
+/// Classe de composition de Gpio.
+class GpioConcat : public Gpio
+{
+ Gpio &io0_, &io1_;
+ int nSep_;
+ public:
+ /// Constructeur.
+ GpioConcat (Gpio &io0, Gpio &io1, int nSep);
+ /// Change plusieurs sorties.
+ void set (int n, unsigned int bits, int nb);
+ /// Lit plusieurs entrées.
+ unsigned int get (int n, int nb);
+ /// Change la direction de plusieurs I/O.
+ void dir (int n, unsigned int bits, int nb);
+ /// Met à jour.
+ void update (void);
+ /// Récupère le nombre d'entrées/sorties.
+ int getNbIo (void);
+};
+
+#endif // gpio_concat_h
diff --git a/2004/i/nono/src/io/gpio_servo_pp.cc b/2004/i/nono/src/io/gpio_servo_pp.cc
index 36f9334..1e1036d 100644
--- a/2004/i/nono/src/io/gpio_servo_pp.cc
+++ b/2004/i/nono/src/io/gpio_servo_pp.cc
@@ -26,11 +26,12 @@
#include "config/config.h"
#include <iomanip>
+#include <stdexcept>
/// Constructeur.
GpioServoPp::GpioServoPp (void)
- : outputs_ (0), inputs_ (0), lastInputRequestSend_ (-10000),
- lastInputRecv_ (-10000), serial_ (true), ttyspeed_ (0),
+ : outputs_ (0), inputs_ (0),
+ serial_ (true), ttyspeed_ (0),
log_ ("io", "pp")
{
Config rc ("rc/gpio_servo_pp");
@@ -38,7 +39,7 @@ GpioServoPp::GpioServoPp (void)
{
if (!(
rc.get ("tty", ttyname_) ||
- rc.get ("ttyspeed", ttyspeed_) ||
+ rc.get ("ttyspeed", ttyspeed_)
))
rc.noId ();
}
@@ -61,18 +62,11 @@ GpioServoPp::set (int n, unsigned int bits, int nb)
unsigned int mask = (1 << nb) - 1;
bits <<= n;
outputs_ = (outputs_ & ~mask) | (bits & mask) | 0x80;
- serial.putchar (outputs_);
+ serial_.putchar (outputs_);
log_ (Log::debug) << "send " << std::hex << outputs_ << std::dec <<
std::endl;
}
-/// Change une sortie.
-void
-GpioServoPp::set (int n, unsigned int bit)
-{
- set (n, bit, 1);
-}
-
/// Lit plusieurs entrées.
unsigned int
GpioServoPp::get (int n, int nb)
@@ -84,81 +78,14 @@ GpioServoPp::get (int n, int nb)
return bits;
}
-/// Lit une entrée.
-unsigned int
-GpioServoPp::get (int n)
-{
- return get (n, 1);
-}
-
-/// Pré-lit plusieurs entrées.
-bool
-GpioServoPp::preget (int n, int nb)
-{
- int date = Date::getInstance ().start ();
- if (lastInputRecv_ + inputValidityTimeout_ > date)
- {
- // Donnée prête.
- return true;
- }
- else
- {
- // Donnée périmée.
- // Lit tout ce qui arrive du port serie.
- int c;
- while ((c = serial_.getchar ()) != -1)
- {
- log_ (Log::debug) << "recv " << std::hex << c << std::dec <<
- std::endl;
- inputs_ = c;
- lastInputRecv_ = date;
- }
- // Si le dernier envois est assez recent, on garde ce qu'on a recu.
- if (lastInputRequestSend_ + inputRequestTimeout_ > date)
- {
- return true;
- }
- else
- {
- lastInputRecv_ = -10000;
- lastInputRequestSend_ = date;
- serial_.putchar (0xff);
- log_ (Log::debug) << "recv " << std::hex << 0xff << std::dec <<
- std::endl;
- return false;
- }
- }
-}
-
-/// Pré-lit une entrée.
-bool
-GpioServoPp::preget (int n)
-{
- return preget (n, 1);
-}
-
-/// Change la direction de plusieurs I/O.
-void
-GpioServoPp::dir (int n, unsigned int bits, int nb)
-{
- throw std::invalid_argument ("GpioServoPp::dir: Operation not supported");
-}
-
-/// Change la direction d'un I/O (1 pour I, 0 pour O).
-void
-GpioServoPp::dir (int n, unsigned int bit)
-{
- dir (n, bit, 1);
-}
-
/// Bouge un servo de DIFF.
void
GpioServoPp::move (int n, int diff)
{
- n %= servoPos_;
+ n %= nbServo_;
servoPos_[n] += diff;
int v = n << 7 | servoPos_[n];
- serial.putchar (v);
+ serial_.putchar (v);
log_ (Log::debug) << "send " << std::hex << v << std::dec << std::endl;
}
@@ -166,10 +93,30 @@ GpioServoPp::move (int n, int diff)
void
GpioServoPp::moveTo (int n, int pos)
{
- n %= servoPos_;
+ n %= nbServo_;
servoPos_[n] = pos;
int v = n << 7 | servoPos_[n];
- serial.putchar (v);
+ serial_.putchar (v);
log_ (Log::debug) << "send " << std::hex << v << std::dec << std::endl;
}
+/// Met à jour.
+void
+GpioServoPp::update (void)
+{
+ int c;
+ while ((c = serial_.getchar ()) != -1)
+ {
+ log_ (Log::debug) << "recv " << std::hex << c << std::dec <<
+ std::endl;
+ inputs_ = c;
+ }
+}
+
+/// Récupère le nombre d'entrées/sorties.
+int
+GpioServoPp::getNbIo (void)
+{
+ return nbOutputs_ + nbInputs_;
+}
+
diff --git a/2004/i/nono/src/io/gpio_servo_pp.h b/2004/i/nono/src/io/gpio_servo_pp.h
index 5ece61f..f5ee63a 100644
--- a/2004/i/nono/src/io/gpio_servo_pp.h
+++ b/2004/i/nono/src/io/gpio_servo_pp.h
@@ -40,12 +40,6 @@ class GpioServoPp : public Gpio, public Servo
unsigned int outputs_;
/// Dernière valeurs d'entrées.
unsigned int inputs_;
- /// Timeouts.
- static const int inputRequestTimeout_ = 100, inputValidityTimeout_ = 100;
- /// Date du dernier envois.
- int lastInputRequestSend_;
- /// Date de la dernière reception.
- int lastInputRecv_;
/// Position des servos.
int servoPos_[nbServo_];
// Ligne série.
@@ -61,24 +55,16 @@ class GpioServoPp : public Gpio, public Servo
~GpioServoPp (void);
/// Change plusieurs sorties.
void set (int n, unsigned int bits, int nb);
- /// Change une sortie.
- void set (int n, unsigned int bit);
/// Lit plusieurs entrées.
unsigned int get (int n, int nb);
- /// Lit une entrée.
- unsigned int get (int n);
- /// Pré-lit plusieurs entrées.
- bool preget (int n, int nb);
- /// Pré-lit une entrée.
- bool preget (int n);
- /// Change la direction de plusieurs I/O.
- void dir (int n, unsigned int bits, int nb);
- /// Change la direction d'un I/O (1 pour I, 0 pour O).
- void dir (int n, unsigned int bit);
/// Bouge un servo de DIFF.
void move (int n, int diff);
/// Bouge un servo en position POS.
void moveTo (int n, int pos);
+ /// Met à jour.
+ void update (void);
+ /// Récupère le nombre d'entrées/sorties.
+ int getNbIo (void);
};
#endif // gpio_servo_pp_h
diff --git a/2004/i/nono/src/io/io_cmd.cc b/2004/i/nono/src/io/io_cmd.cc
new file mode 100644
index 0000000..d64928f
--- /dev/null
+++ b/2004/i/nono/src/io/io_cmd.cc
@@ -0,0 +1,82 @@
+// io_cmd.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "io_cmd.h"
+#include "gpio.h"
+
+#include <iostream>
+#include <cstdlib>
+
+const char ioHelp[] =
+ " o <n> <bits> <nb> set des sorties.\n"
+ " i <n> <nb> get des entrées.\n"
+ " d <n> <bits> <nb> dir des entrées/sorties.\n";
+
+bool
+ioCmd (int argc, char **argv, int &i, Gpio &io)
+{
+ int n, bits, nb;
+ switch (argv[i][0])
+ {
+ case 'o':
+ i++;
+ if (i >= argc) break;
+ n = atoi (argv[i++]);
+ if (i >= argc) break;
+ bits = atoi (argv[i++]);
+ if (i >= argc) break;
+ nb = atoi (argv[i++]);
+ std::cout << "test: set " << n << ' ' << std::hex << bits <<
+ std::dec << ' ' << nb << std::endl;
+ io.set (n, bits, nb);
+ break;
+ case 'i':
+ i++;
+ if (i >= argc) break;
+ n = atoi (argv[i++]);
+ if (i >= argc) break;
+ nb = atoi (argv[i++]);
+ std::cout << "test: get " << n << ' ' << nb << std::endl;
+ bits = io.get (n, nb);
+ std::cout << "test: get result " << std::hex << bits <<
+ std::dec << std::endl;
+ break;
+ case 'd':
+ i++;
+ if (i >= argc) break;
+ n = atoi (argv[i++]);
+ if (i >= argc) break;
+ bits = atoi (argv[i++]);
+ if (i >= argc) break;
+ nb = atoi (argv[i++]);
+ std::cout << "test: dir " << n << ' ' << std::hex << bits <<
+ std::dec << ' ' << nb << std::endl;
+ io.dir (n, bits, nb);
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
diff --git a/2004/i/nono/src/io/io_cmd.h b/2004/i/nono/src/io/io_cmd.h
new file mode 100644
index 0000000..a7d6e8a
--- /dev/null
+++ b/2004/i/nono/src/io/io_cmd.h
@@ -0,0 +1,35 @@
+#ifndef io_cmd_h
+#define io_cmd_h
+// io_cmd.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// }}}
+
+class Gpio;
+
+extern const char ioHelp[];
+
+bool
+ioCmd (int argc, char **argv, int &i, Gpio &io);
+
+#endif // io_cmd_h
diff --git a/2004/i/nono/src/io/test_gpio_concat.cc b/2004/i/nono/src/io/test_gpio_concat.cc
new file mode 100644
index 0000000..a6ec722
--- /dev/null
+++ b/2004/i/nono/src/io/test_gpio_concat.cc
@@ -0,0 +1,105 @@
+// test_gpio_concat.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "gpio_concat.h"
+#include "io_cmd.h"
+
+#include <string>
+#include <iostream>
+#include <iomanip>
+
+/// Gpio de test.
+class TestGpio : public Gpio
+{
+ std::string id_;
+ public:
+ /// Constructeur.
+ TestGpio (const std::string &id) : id_ (id) { }
+ /// Change plusieurs sorties.
+ void set (int n, unsigned int bits, int nb)
+ {
+ std::cout << id_ << ": set " << n << ' ' << std::hex << bits <<
+ std::dec << ' ' << nb << std::endl;
+ }
+ /// Lit plusieurs entrées.
+ unsigned int get (int n, int nb)
+ {
+ std::cout << id_ << ": get " << n << ' ' << nb << std::endl;
+ return 0x11 >> n;
+ }
+ /// Change la direction de plusieurs I/O.
+ void dir (int n, unsigned int bits, int nb)
+ {
+ std::cout << id_ << ": dir " << n << ' ' << std::hex << bits <<
+ std::dec << ' ' << nb << std::endl;
+ }
+ /// Met à jour.
+ void update (void)
+ {
+ std::cout << id_ << ": update" << std::endl;
+ }
+};
+
+void
+syntax (void)
+{
+ std::cout <<
+ "test_io - teste les entrées/sorties.\n"
+ << ioHelp <<
+ " ? cet ecran d'aide" << std::endl;
+}
+
+int
+main (int argc, char **argv)
+{
+ try
+ {
+ TestGpio io0 ("io0"), io1 ("io1");
+ GpioConcat cc (io0, io1, 3);
+ int i = 1;
+ while (i < argc)
+ {
+ if (!ioCmd (argc, argv, i, cc))
+ {
+ switch (argv[i][0])
+ {
+ case '?':
+ i++;
+ syntax ();
+ return 0;
+ default:
+ i++;
+ syntax ();
+ return 1;
+ }
+ }
+ }
+ return 0;
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << e.what () << std::endl;
+ return 1;
+ }
+}
diff --git a/2004/i/nono/src/io/test_io.cc b/2004/i/nono/src/io/test_io.cc
index 8b01554..5af38bf 100644
--- a/2004/i/nono/src/io/test_io.cc
+++ b/2004/i/nono/src/io/test_io.cc
@@ -23,10 +23,14 @@
//
// }}}
#include "gpio_servo_pp.h"
+#include "gpio_asserv.h"
+#include "gpio_concat.h"
#include "servo.h"
#include "date/date.h"
+#include "motor/asserv.h"
+#include "io_cmd.h"
-#include <stdexcept>
+#include <exception>
#include <iostream>
void
@@ -34,9 +38,8 @@ syntax (void)
{
std::cout <<
"test_io - teste les entrées/sorties.\n"
- " s <n> <bits> <nb> set des sorties.\n"
- " g <n> <nb> get des entrées.\n"
- " <timeout> attend un certain temps (qui augmente avec timeout)\n"
+ << ioHelp <<
+ " <timeout> attend\n"
" ? cet ecran d'aide" << std::endl;
}
@@ -45,57 +48,37 @@ main (int argc, char **argv)
{
try
{
+ AsservTracker at;
+ Asserv a (at);
+ a.reset ();
GpioServoPp gspp;
+ GpioAsserv ga (a);
+ GpioConcat gc (ga, gspp, ga.getNbIo ());
int i = 1;
while (i < argc)
{
- switch (argv[i][0])
+ if (!ioCmd (argc, argv, i, gc))
{
- case 's':
- i++;
- int n, bits, nb;
- if (i >= argc) break;
- n = atoi (argv[i++]);
- if (i >= argc) break;
- bits = atoi (argv[i++]);
- if (i >= argc) break;
- nb = atoi (argv[i++]);
- std::cout << "set " << n << ' ' << std::hex << bits <<
- std::dec << ' ' << nb << std::endl;
- gspp.set (n, bits, nb);
- break;
- case 'g':
- i++;
- int n, bits, nb;
- if (i >= argc) break;
- n = atoi (argv[i++]);
- if (i >= argc) break;
- nb = atoi (argv[i++]);
- for (int i = 0; i < 20; ++i)
+ switch (argv[i][0])
{
- std::cout << "preget " << n << ' ' << nb << std::endl;
- if (gspp.preget (n, nb))
+ case '?':
+ syntax ();
+ return 0;
+ default:
+ int s;
+ s = atoi (argv[i++]);
+ if (s == 0)
{
- bits = gspp.get (n, nb);
- std::cout << "get " << std::hex << bits << std::dec <<
- std::endl;
- break;
+ syntax ();
+ return 1;
}
- Date::wait (50);
- }
- break;
- default:
- int s;
- s = atoi (argv[i++]);
- if (s == 0)
- {
- syntax ();
- return 1;
+ cout << "test: sleep " << s << endl;
+ Date::wait (s * 1000);
+ break;
}
- cout << "test: sleep " << s << endl;
- Date::wait (s * 1000);
- break;
}
+ a.waitOk ();
+ gspp.update ();
}
return 0;
}