summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschodet2004-05-13 23:10:37 +0000
committerschodet2004-05-13 23:10:37 +0000
commit6006fee7b9eddd71dee20b6b39b233f7e4088db9 (patch)
tree40b170282e451d9da73eac179baf8ab4fc5054e5
parent18570afbe14ef0bcc12ddb6c39fc6047190e052e (diff)
Virure de Erreur
-rw-r--r--2004/i/nono/src/config/config.cc33
-rw-r--r--2004/i/nono/src/config/config.h15
-rw-r--r--2004/i/nono/src/erreur/Makefile.defs4
-rw-r--r--2004/i/nono/src/erreur/erreur.cc31
-rw-r--r--2004/i/nono/src/erreur/erreur.h39
-rw-r--r--2004/i/nono/src/io/Makefile.defs4
-rw-r--r--2004/i/nono/src/io/io_cmd.cc27
-rw-r--r--2004/i/nono/src/io/io_cmd.h3
-rw-r--r--2004/i/nono/src/io/test_io.cc6
-rw-r--r--2004/i/nono/src/logger/Makefile.defs2
-rw-r--r--2004/i/nono/src/logger/test_logger.cc1
-rw-r--r--2004/i/nono/src/motor/Makefile.defs8
-rw-r--r--2004/i/nono/src/motor/test_asserv.cc24
-rw-r--r--2004/i/nono/src/motor/test_tracker.cc13
-rw-r--r--2004/i/nono/src/ovision/Makefile.defs2
-rw-r--r--2004/i/nono/src/ovision/test_ovision.cc1
-rw-r--r--2004/i/nono/src/ovision/test_ovision_tracker.cc1
-rw-r--r--2004/i/nono/src/serial/serial_stdio.cc1
18 files changed, 73 insertions, 142 deletions
diff --git a/2004/i/nono/src/config/config.cc b/2004/i/nono/src/config/config.cc
index 9a88494..ea726c6 100644
--- a/2004/i/nono/src/config/config.cc
+++ b/2004/i/nono/src/config/config.cc
@@ -24,9 +24,20 @@
// }}}
#include "config.h"
#include "config_lex.h"
-#include "erreur/erreur.h"
#include <cstring>
+#include <cstdio>
+
+const char *
+ConfigError::what () const throw ()
+{
+ static char descr[1024];
+ if (!m_id)
+ sprintf (descr, "%s: %s", m_file, m_descr);
+ else
+ sprintf (descr, "%s: %s: %s", m_file, m_id, m_descr);
+ return descr;
+}
// Constructeur, prend l'identificateur de configuration en paramètre (nom de
// fichier).
@@ -54,7 +65,7 @@ Config::getNum (void)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != NUM)
- throw ErreurConfig (m_filename.c_str (), "Nombre attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Nombre attendu.\n");
m_type = -1;
return config_yylval.num;
}
@@ -64,7 +75,7 @@ Config::getId (void)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != ID)
- throw ErreurConfig (m_filename.c_str (), "Identificateur attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Identificateur attendu.\n");
m_type = -1;
return config_yylval.id;
}
@@ -74,7 +85,7 @@ Config::getId (std::string &s)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != ID)
- throw ErreurConfig (m_filename.c_str (), "Identificateur attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Identificateur attendu.\n");
m_type = -1;
s = config_yylval.id;
}
@@ -84,7 +95,7 @@ Config::getBool (void)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != BOOL)
- throw ErreurConfig (m_filename.c_str (), "Booléen attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Booléen attendu.\n");
m_type = -1;
return config_yylval.boolean;
}
@@ -104,7 +115,7 @@ Config::getFloat (void)
return (double) config_yylval.num;
}
else
- throw ErreurConfig (m_filename.c_str (), "Flotant attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Flotant attendu.\n");
}
void
@@ -112,7 +123,7 @@ Config::getString (std::string &s)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != STRING)
- throw ErreurConfig (m_filename.c_str (),
+ throw ConfigError (m_filename.c_str (),
"Chaîne de caractères attendue.\n");
m_type = -1;
s = config_yylval.str;
@@ -123,7 +134,7 @@ Config::getEof (void)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type)
- throw ErreurConfig (m_filename.c_str (),
+ throw ConfigError (m_filename.c_str (),
"Fin de fichier attendue.\n");
}
@@ -141,7 +152,7 @@ Config::isId (const char *s)
{
if (m_type == -1) m_type = config_yylex ();
if (m_type != ID)
- throw ErreurConfig (m_filename.c_str (), "Identificateur attendu.\n");
+ throw ConfigError (m_filename.c_str (), "Identificateur attendu.\n");
return strcmp (config_yylval.id, s) == 0;
}
@@ -149,14 +160,14 @@ Config::isId (const char *s)
void
Config::noId (void)
{
- throw ErreurConfig (m_filename.c_str (), config_yylval.id,
+ throw ConfigError (m_filename.c_str (), config_yylval.id,
"Identificateur inconnu.\n");
}
void
Config::throwError (const char *msg)
{
- throw ErreurConfig (m_filename.c_str (), msg);
+ throw ConfigError (m_filename.c_str (), msg);
}
// Appellé par le lexer pour changer de fichier.
diff --git a/2004/i/nono/src/config/config.h b/2004/i/nono/src/config/config.h
index f6f22df..4187223 100644
--- a/2004/i/nono/src/config/config.h
+++ b/2004/i/nono/src/config/config.h
@@ -26,6 +26,21 @@
// }}}
#include <string>
+#include <stdexcept>
+
+class ConfigError : public std::runtime_error
+{
+ const char *m_file;
+ const char *m_id;
+ const char *m_descr;
+ public:
+ ConfigError (const char *file, const char *id,
+ const char *descr)
+ { m_file = file; m_id = id; m_descr = descr; }
+ ConfigError (const char *file, const char *descr)
+ { m_file = file; m_id = 0; m_descr = descr; }
+ virtual const char *what () const throw ();
+};
class Config
{
diff --git a/2004/i/nono/src/erreur/Makefile.defs b/2004/i/nono/src/erreur/Makefile.defs
deleted file mode 100644
index 9ff08a8..0000000
--- a/2004/i/nono/src/erreur/Makefile.defs
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBS += erreur.a
-erreur_a_SOURCES = erreur.cc
-
-erreur.a: ${erreur_a_SOURCES:%.cc=erreur.a(%.o)}
diff --git a/2004/i/nono/src/erreur/erreur.cc b/2004/i/nono/src/erreur/erreur.cc
deleted file mode 100644
index 241b243..0000000
--- a/2004/i/nono/src/erreur/erreur.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-// erreur.cc
-// buzz - Programme du robot Efrei Robotique I1-I2 2003
-// Copyright (C) 2003 Nicolas Schodet
-//
-#include "erreur.h"
-
-#include <stdio.h>
-
-// Retourne une description de l'erreur.
-const char *
-Erreur::what () const throw ()
-{
- return "Erreur non spécifiée.\n";
-}
-
-const char *
-ErreurFatale::what () const throw ()
-{
- return m_descr;
-}
-
-const char *
-ErreurConfig::what () const throw ()
-{
- static char descr[1024];
- if (!m_id)
- sprintf (descr, "%s: %s", m_file, m_descr);
- else
- sprintf (descr, "%s: %s: %s", m_file, m_id, m_descr);
- return descr;
-}
diff --git a/2004/i/nono/src/erreur/erreur.h b/2004/i/nono/src/erreur/erreur.h
deleted file mode 100644
index fcbb0eb..0000000
--- a/2004/i/nono/src/erreur/erreur.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef erreur_h
-#define erreur_h
-// erreur.h
-// buzz - Programme du robot Efrei Robotique I1-I2 2003
-// Copyright (C) 2003 Nicolas Schodet
-
-#include <exception>
-
-class Erreur : public std::exception
-{
- public:
- // Retourne une description de l'erreur.
- virtual const char *what () const throw ();
-};
-
-class ErreurFatale : public Erreur
-{
- const char *m_descr;
- public:
- ErreurFatale (const char *descr) { m_descr = descr; }
- virtual const char *what () const throw ();
-};
-
-class ErreurConfig : public Erreur
-{
- const char *m_file;
- const char *m_id;
- const char *m_descr;
- public:
- ErreurConfig (const char *file, const char *id,
- const char *descr)
- { m_file = file; m_id = id; m_descr = descr; }
- ErreurConfig (const char *file, const char *descr)
- { m_file = file; m_id = 0; m_descr = descr; }
- virtual const char *what () const throw ();
-};
-
-
-#endif // erreur_h
diff --git a/2004/i/nono/src/io/Makefile.defs b/2004/i/nono/src/io/Makefile.defs
index b6bb88d..efc1ad0 100644
--- a/2004/i/nono/src/io/Makefile.defs
+++ b/2004/i/nono/src/io/Makefile.defs
@@ -1,7 +1,7 @@
TARGETS += test_io test_gpio_concat
LIBS += io.a
-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_io_SOURCES = test_io.cc io_cmd.cc servo_cmd.cc io.a date.a serial.a \
+ motor.a logger.a utils.a config.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
diff --git a/2004/i/nono/src/io/io_cmd.cc b/2004/i/nono/src/io/io_cmd.cc
index 1177f8b..d64928f 100644
--- a/2004/i/nono/src/io/io_cmd.cc
+++ b/2004/i/nono/src/io/io_cmd.cc
@@ -24,7 +24,6 @@
// }}}
#include "io_cmd.h"
#include "gpio.h"
-#include "servo.h"
#include <iostream>
#include <cstdlib>
@@ -32,12 +31,10 @@
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"
- " m <n> <diff> déplace le servo n de diff.\n"
- " M <n> <pos> déplace le servo n en pos.\n";
+ " d <n> <bits> <nb> dir des entrées/sorties.\n";
bool
-ioCmd (int argc, char **argv, int &i, Gpio &io, Servo &servo)
+ioCmd (int argc, char **argv, int &i, Gpio &io)
{
int n, bits, nb;
switch (argv[i][0])
@@ -77,26 +74,6 @@ ioCmd (int argc, char **argv, int &i, Gpio &io, Servo &servo)
std::dec << ' ' << nb << std::endl;
io.dir (n, bits, nb);
break;
- case 'm':
- i++;
- int diff;
- if (i >= argc) break;
- n = atoi (argv[i++]);
- if (i >= argc) break;
- diff = atoi (argv[i++]);
- std::cout << "test: servo move " << n << ' ' << diff << std::endl;
- servo.move (n, diff);
- break;
- case 'M':
- i++;
- int pos;
- if (i >= argc) break;
- n = atoi (argv[i++]);
- if (i >= argc) break;
- pos = atoi (argv[i++]);
- std::cout << "test: servo moveTo " << n << ' ' << pos << std::endl;
- servo.moveTo (n, pos);
- break;
default:
return false;
}
diff --git a/2004/i/nono/src/io/io_cmd.h b/2004/i/nono/src/io/io_cmd.h
index b199a9f..a7d6e8a 100644
--- a/2004/i/nono/src/io/io_cmd.h
+++ b/2004/i/nono/src/io/io_cmd.h
@@ -26,11 +26,10 @@
// }}}
class Gpio;
-class Servo;
extern const char ioHelp[];
bool
-ioCmd (int argc, char **argv, int &i, Gpio &io, Servo &servo);
+ioCmd (int argc, char **argv, int &i, Gpio &io);
#endif // io_cmd_h
diff --git a/2004/i/nono/src/io/test_io.cc b/2004/i/nono/src/io/test_io.cc
index 3834893..999549e 100644
--- a/2004/i/nono/src/io/test_io.cc
+++ b/2004/i/nono/src/io/test_io.cc
@@ -29,6 +29,7 @@
#include "date/date.h"
#include "motor/asserv.h"
#include "io_cmd.h"
+#include "servo_cmd.h"
#include <exception>
#include <iostream>
@@ -38,7 +39,7 @@ syntax (void)
{
std::cout <<
"test_io - teste les entrées/sorties.\n"
- << ioHelp <<
+ << ioHelp << servoHelp <<
" <timeout> attend\n"
" ? cet ecran d'aide" << std::endl;
}
@@ -57,7 +58,8 @@ main (int argc, char **argv)
int i = 1;
while (i < argc)
{
- if (!ioCmd (argc, argv, i, gc, gspp))
+ if (!ioCmd (argc, argv, i, gc)
+ && !servoCmd (argc, argv, i, gspp))
{
switch (argv[i][0])
{
diff --git a/2004/i/nono/src/logger/Makefile.defs b/2004/i/nono/src/logger/Makefile.defs
index 4ae4ab8..e892201 100644
--- a/2004/i/nono/src/logger/Makefile.defs
+++ b/2004/i/nono/src/logger/Makefile.defs
@@ -1,6 +1,6 @@
TARGETS += test_logger
LIBS += logger.a
-test_logger_SOURCES = test_logger.cc logger.a config.a erreur.a
+test_logger_SOURCES = test_logger.cc logger.a config.a
logger_a_SOURCES = logger.cc log.cc
test_logger: $(test_logger_SOURCES:%.cc=%.o)
diff --git a/2004/i/nono/src/logger/test_logger.cc b/2004/i/nono/src/logger/test_logger.cc
index 09c4923..b39ed75 100644
--- a/2004/i/nono/src/logger/test_logger.cc
+++ b/2004/i/nono/src/logger/test_logger.cc
@@ -25,7 +25,6 @@
#include "log.h"
#include <exception>
-#include "erreur/erreur.h"
int
main (void)
diff --git a/2004/i/nono/src/motor/Makefile.defs b/2004/i/nono/src/motor/Makefile.defs
index 6002fd8..40ff385 100644
--- a/2004/i/nono/src/motor/Makefile.defs
+++ b/2004/i/nono/src/motor/Makefile.defs
@@ -1,10 +1,10 @@
TARGETS += test_motor test_asserv test_tracker test_goto_hermite
LIBS += motor.a
test_motor_SOURCES = test_motor.cc motor_cmd.cc motor.a serial.a \
- config.a date.a utils.a logger.a erreur.a
-test_asserv_SOURCES = test_asserv.cc motor.a serial.a erreur.a config.a \
+ config.a date.a utils.a logger.a
+test_asserv_SOURCES = test_asserv.cc motor.a serial.a config.a \
date.a utils.a logger.a
-test_tracker_SOURCES = test_tracker.cc motor.a serial.a erreur.a config.a \
+test_tracker_SOURCES = test_tracker.cc motor.a serial.a config.a \
date.a utils.a logger.a
motor_a_SOURCES = asserv.cc tracker.cc motor.cc \
movement_basic.cc movement_goto.cc movement_rotation.cc \
@@ -12,7 +12,7 @@ motor_a_SOURCES = asserv.cc tracker.cc motor.cc \
goto_simple.cc goto_circle.cc goto_hermite.cc \
goto_tracker.cc
test_goto_hermite_SOURCES = goto_hermite.cc test_goto_hermite.cc tracker.cc \
- config.a logger.a erreur.a
+ config.a logger.a
test_motor: $(test_motor_SOURCES:%.cc=%.o)
diff --git a/2004/i/nono/src/motor/test_asserv.cc b/2004/i/nono/src/motor/test_asserv.cc
index cd8b55e..c83e72d 100644
--- a/2004/i/nono/src/motor/test_asserv.cc
+++ b/2004/i/nono/src/motor/test_asserv.cc
@@ -23,12 +23,12 @@
//
// }}}
#include "asserv.h"
-#include "erreur/erreur.h"
#include "date/date.h"
#include <iostream>
#include <unistd.h>
-#include <stdlib.h>
+#include <cstdlib>
+#include <stdexcept>
using namespace std;
@@ -77,22 +77,22 @@ main (int argc, char **argv)
{
case 's':
at.reset ();
- cout << "stop" << endl;
+ std::cout << "stop" << std::endl;
i++;
m.stop ();
break;
case 'z':
- cout << "rezet" << endl;
+ std::cout << "rezet" << std::endl;
i++;
m.reset ();
break;
case 'g':
- cout << "go" << endl;
+ std::cout << "go" << std::endl;
i++;
m.setAsserv ();
break;
case 'G':
- cout << "ungo" << endl;
+ std::cout << "ungo" << std::endl;
i++;
m.setAsserv (false);
break;
@@ -103,7 +103,7 @@ main (int argc, char **argv)
vg = atoi (argv[i++]);
if (i >= argc) break;
vd = atoi (argv[i++]);
- cout << "speed " << vg << ' ' << vd << endl;
+ std::cout << "speed " << vg << ' ' << vd << std::endl;
m.speed (vg, vd);
break;
case '?':
@@ -117,8 +117,10 @@ main (int argc, char **argv)
syntax ();
return 1;
}
- cout << "sleep " << s << endl;
- for (int j = 0; j < s * 1000 / 50; ++j)
+ std::cout << "sleep " << s << std::endl;
+ int start;
+ start = Date::getInstance ().start ();
+ while (Date::getInstance ().start () < start + s)
{
m.ok ();
Date::wait (1);
@@ -130,9 +132,9 @@ main (int argc, char **argv)
at.aff ();
return 0;
}
- catch (Erreur &e)
+ catch (const std::exception &e)
{
- cerr << e.what () << endl;
+ std::cerr << e.what () << std::endl;
return 1;
}
}
diff --git a/2004/i/nono/src/motor/test_tracker.cc b/2004/i/nono/src/motor/test_tracker.cc
index 18d709f..246e625 100644
--- a/2004/i/nono/src/motor/test_tracker.cc
+++ b/2004/i/nono/src/motor/test_tracker.cc
@@ -23,10 +23,10 @@
//
// }}}
#include "tracker.h"
-#include "erreur/erreur.h"
-#include <stdlib.h>
+#include <cstdlib>
#include <iostream>
+#include <stdexcept>
int
main (int argc, char **argv)
@@ -44,9 +44,10 @@ main (int argc, char **argv)
double x = atof (argv[i]);
double y = atof (argv[i + 1]);
double el, ea;
- t.computeError (x, y, el, ea);
+ double a;
+ t.computeError (x, y, el, ea, a);
std::cout << "error " << x << ' ' << y << ' ' << el << ' ' <<
- ea << std::endl;
+ ea << ' ' << a << std::endl;
}
break;
case 'a':
@@ -74,9 +75,9 @@ main (int argc, char **argv)
}
return 0;
}
- catch (Erreur &e)
+ catch (const std::exception &e)
{
- cerr << e.what () << endl;
+ std::cerr << e.what () << std::endl;
return 1;
}
}
diff --git a/2004/i/nono/src/ovision/Makefile.defs b/2004/i/nono/src/ovision/Makefile.defs
index d4a5307..e9548dd 100644
--- a/2004/i/nono/src/ovision/Makefile.defs
+++ b/2004/i/nono/src/ovision/Makefile.defs
@@ -5,7 +5,7 @@ testimg_SOURCES = testimg.cc ovision.a video4linux.a
test_ovision_SOURCES = test_ovision.cc ovision.a image.a video4linux.a
test_ovision_tracker_SOURCES = test_ovision_tracker.cc ovision.a image.a \
video4linux.a motor.a date.a \
- serial.a utils.a logger.a config.a erreur.a
+ serial.a utils.a logger.a config.a
testmap_SOURCES = testmap.cc ovision.a image.a video4linux.a
testdist_SOURCES = testdist.cc ovision.a
optim_SOURCES = optim.cc ovision.a image.a
diff --git a/2004/i/nono/src/ovision/test_ovision.cc b/2004/i/nono/src/ovision/test_ovision.cc
index 3b0219b..1a10385 100644
--- a/2004/i/nono/src/ovision/test_ovision.cc
+++ b/2004/i/nono/src/ovision/test_ovision.cc
@@ -1,3 +1,4 @@
+#include <cstdio>
#include "video4linux/video4linux.h"
#include "map.h"
diff --git a/2004/i/nono/src/ovision/test_ovision_tracker.cc b/2004/i/nono/src/ovision/test_ovision_tracker.cc
index 393dca8..dfd00c7 100644
--- a/2004/i/nono/src/ovision/test_ovision_tracker.cc
+++ b/2004/i/nono/src/ovision/test_ovision_tracker.cc
@@ -88,7 +88,6 @@ main ()
if (group.zoneListBall)
{
int x,y;
- double angle;
x = group.zoneListBall->centerx - img.width/2;
y = img.height - group.zoneListBall->centery;
std::cout << x << " " << y << std::endl;
diff --git a/2004/i/nono/src/serial/serial_stdio.cc b/2004/i/nono/src/serial/serial_stdio.cc
index a8cc17b..bff3ae3 100644
--- a/2004/i/nono/src/serial/serial_stdio.cc
+++ b/2004/i/nono/src/serial/serial_stdio.cc
@@ -23,7 +23,6 @@
//
// }}}
#include "serial_stdio.h"
-#include "erreur/erreur.h"
#include "utils/errno_exception.h"
#include <fcntl.h>