summaryrefslogtreecommitdiff
path: root/2003
diff options
context:
space:
mode:
Diffstat (limited to '2003')
-rw-r--r--2003/i/buzz/src/busp/Makefile.defs9
-rw-r--r--2003/i/buzz/src/busp/busp.cc38
-rw-r--r--2003/i/buzz/src/busp/busp.h14
-rw-r--r--2003/i/buzz/src/busp/busp_capteurs.h8
-rw-r--r--2003/i/buzz/src/busp/busp_gps.cc4
-rw-r--r--2003/i/buzz/src/camera/Makefile.defs4
-rw-r--r--2003/i/buzz/src/camera/camera.cc35
-rw-r--r--2003/i/buzz/src/camera/camera.h5
-rw-r--r--2003/i/buzz/src/camera/dumpimage.cc10
-rw-r--r--2003/i/buzz/src/camera/test_camera.cc4
-rw-r--r--2003/i/buzz/src/erreur/erreur.cc5
-rw-r--r--2003/i/buzz/src/erreur/erreur.h6
12 files changed, 97 insertions, 45 deletions
diff --git a/2003/i/buzz/src/busp/Makefile.defs b/2003/i/buzz/src/busp/Makefile.defs
index 4ec0fb0..7882cfd 100644
--- a/2003/i/buzz/src/busp/Makefile.defs
+++ b/2003/i/buzz/src/busp/Makefile.defs
@@ -1,6 +1,9 @@
+LIBS += busp.a
TARGETS += test_busp
-test_busp_SOURCES = busp.cc busp_ir.cc busp_servo.cc busp_capteurs.cc \
- busp_actionneurs.cc busp_gps.cc test_busp.cc erreur.a \
- config.a
+busp_a_SOURCES = busp.cc busp_ir.cc busp_servo.cc busp_capteurs.cc \
+ busp_actionneurs.cc busp_gps.cc
+test_busp_SOURCES = test_busp.cc busp.a erreur.a config.a
test_busp: $(test_busp_SOURCES:%.cc=%.o)
+
+busp.a: ${busp_a_SOURCES:%.cc=busp.a(%.o)}
diff --git a/2003/i/buzz/src/busp/busp.cc b/2003/i/buzz/src/busp/busp.cc
index d830a30..5038a65 100644
--- a/2003/i/buzz/src/busp/busp.cc
+++ b/2003/i/buzz/src/busp/busp.cc
@@ -34,7 +34,7 @@ Busp::Busp ()
sa.sa_flags = SA_RESTART;
sigaction (SIGUSR1, &sa, 0); // Il n'y aura pas d'erreur, cf doc.
// Active les interruptions.
- sti ();
+// sti ();
// Remplis le tableau d'inversion des données.
// Les fils sont soudés à l'envers.
for (int i = 0; i < 256; ++i)
@@ -55,13 +55,13 @@ Busp::Busp ()
Busp::~Busp ()
{
// Désactive les interruptions.
- cli ();
+// cli ();
// Ignore les signaux, on sait jammais.
- struct sigaction sa;
- sa.sa_handler = SIG_IGN;
- sigemptyset (&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
- sigaction (SIGUSR1, &sa, 0);
+// struct sigaction sa;
+// sa.sa_handler = SIG_IGN;
+// sigemptyset (&sa.sa_mask);
+// sa.sa_flags = SA_RESTART;
+// sigaction (SIGUSR1, &sa, 0);
// Ferme le périphérique.
close (m_fd);
// Efface le pointeur d'instance.
@@ -72,31 +72,33 @@ Busp::~Busp ()
void
Busp::sti (void)
{
- ioctl (m_fd, PBUS_INTENABLE);
+// ioctl (m_fd, PBUS_INTENABLE);
}
// Désactive les interruptions.
void
Busp::cli (void)
{
- ioctl (m_fd, PBUS_INTDISABLE);
+// ioctl (m_fd, PBUS_INTDISABLE);
}
// Traite le signal envoyé par le kernel lors d'une interruption.
void
Busp::irq (int sig)
{
- Busp &busp = Busp::getInstance ();
+// Busp &busp = Busp::getInstance ();
// Désactivation des interuptions automatique.
// Récupère le numéro d'intéruption.
- struct pbus_io io;
- ioctl (busp.m_fd, PBUS_INTREAD, &io);
- cout << "irq " << (int) io.ints << endl;
+// struct pbus_io io;
+// ioctl (busp.m_fd, PBUS_INTREAD, &io);
+#ifdef BUSP_DEBUG
+// cout << "irq " << (int) io.ints << endl;
+#endif // BUSP_DEBUG
// Sous-traite l'interruption.
- if (io.ints & BuspIr::m_irqMask)
- busp.m_ir.irq ();
+// if (io.ints & BuspIr::m_irqMask)
+// busp.m_ir.irq ();
// Active à nouveau.
- busp.sti ();
+// busp.sti ();
}
// Ecrire sur le bus.
@@ -107,7 +109,9 @@ Busp::write (int addr, int data)
io.addr = addr;
io.data = m_inverse[data];
ioctl (m_fd, PBUS_WRITE, &io);
+#ifdef BUSP_DEBUG
cout << "write " << addr << " " << data << endl;
+#endif // BUSP_DEBUG
}
// Lire sur le bus.
@@ -117,6 +121,8 @@ Busp::read (int addr)
struct pbus_io io;
io.addr = addr;
ioctl (m_fd, PBUS_READ, &io);
+#ifdef BUSP_DEBUG
cout << "read " << addr << " = " << (int) m_inverse[io.data] << endl;
+#endif // BUSP_DEBUG
return m_inverse[io.data];
}
diff --git a/2003/i/buzz/src/busp/busp.h b/2003/i/buzz/src/busp/busp.h
index 99bcd72..051cbcc 100644
--- a/2003/i/buzz/src/busp/busp.h
+++ b/2003/i/buzz/src/busp/busp.h
@@ -9,15 +9,17 @@
#include "busp_actionneurs.h"
#include "busp_gps.h"
+#define BUSP_DEBUG
+
// Gère le busp coté hard.
class Busp
{
int m_fd;
- BuspIr m_ir;
+// BuspIr m_ir;
BuspServo m_servo;
BuspCapteurs m_capteurs;
- BuspActionneurs m_actionneurs;
- BuspGPS m_gps;
+// BuspActionneurs m_actionneurs;
+// BuspGPS m_gps;
static Busp *m_instance;
unsigned char m_inverse[256];
public:
@@ -41,11 +43,11 @@ class Busp
// Retourne une référence sur l'instance unique.
static Busp &getInstance (void) { return *m_instance; }
// Retourne une référence sur un module.
- BuspIr &getIr (void) { return m_ir; }
+// BuspIr &getIr (void) { return m_ir; }
BuspServo &getServo (void) { return m_servo; }
BuspCapteurs &getCapteurs (void) { return m_capteurs; }
- BuspActionneurs &getActionneurs (void) { return m_actionneurs; }
- BuspGPS &getGPS (void) { return m_gps; }
+// BuspActionneurs &getActionneurs (void) { return m_actionneurs; }
+// BuspGPS &getGPS (void) { return m_gps; }
};
diff --git a/2003/i/buzz/src/busp/busp_capteurs.h b/2003/i/buzz/src/busp/busp_capteurs.h
index 87f1aae..0189f64 100644
--- a/2003/i/buzz/src/busp/busp_capteurs.h
+++ b/2003/i/buzz/src/busp/busp_capteurs.h
@@ -7,10 +7,10 @@
class BuspCapteurs
{
public:
- static const unsigned char m_irqMask = 0x04;
+ static const unsigned char m_irqMask = 0x11;
private:
- static const int m_address = 2;
- unsigned char m_capteurs;
+ static const int m_address = 10;
+ int m_capteurs;
public:
// Constructeur.
BuspCapteurs ();
@@ -20,6 +20,8 @@ class BuspCapteurs
void irq (void);
// Sort les informations.
void dump (void);
+ // Récupère les infos capteurs.
+ int get (void) { return m_capteurs; }
};
#endif // busp_capteurs_h
diff --git a/2003/i/buzz/src/busp/busp_gps.cc b/2003/i/buzz/src/busp/busp_gps.cc
index b2f4ea3..97cb11e 100644
--- a/2003/i/buzz/src/busp/busp_gps.cc
+++ b/2003/i/buzz/src/busp/busp_gps.cc
@@ -23,25 +23,21 @@ BuspGPS::BuspGPS ()
{
rc.getId ();
rc >> m_fl1;
- cout << "fl1 " << m_fl1 << endl;
}
else if (rc.isId ("fl2"))
{
rc.getId ();
rc >> m_fl2;
- cout << "fl2 " << m_fl2 << endl;
}
else if (rc.isId ("fr"))
{
rc.getId ();
rc >> m_fr;
- cout << "fr " << m_fr << endl;
}
else if (rc.isId ("d"))
{
rc.getId ();
rc >> m_d;
- cout << "d " << m_d << endl;
}
else rc.noId ();
}
diff --git a/2003/i/buzz/src/camera/Makefile.defs b/2003/i/buzz/src/camera/Makefile.defs
index e9457f6..6c85f1b 100644
--- a/2003/i/buzz/src/camera/Makefile.defs
+++ b/2003/i/buzz/src/camera/Makefile.defs
@@ -1,7 +1,7 @@
TARGETS += test_camera dumpimage
LIBS += camera.a
-test_camera_SOURCES = camera.cc test_camera.cc erreur.a config.a
-dumpimage_SOURCES = camera.cc dumpimage.cc erreur.a config.a
+test_camera_SOURCES = camera.cc test_camera.cc erreur.a config.a date.a
+dumpimage_SOURCES = camera.cc dumpimage.cc erreur.a config.a date.a
camera_a_SOURCES = camera.cc
dumpimage: $(dumpimage_SOURCES:%.cc=%.o)
diff --git a/2003/i/buzz/src/camera/camera.cc b/2003/i/buzz/src/camera/camera.cc
index 5bc6920..fb1fe2d 100644
--- a/2003/i/buzz/src/camera/camera.cc
+++ b/2003/i/buzz/src/camera/camera.cc
@@ -6,6 +6,7 @@
#include "erreur/erreur.h"
#include "kernel/pbus.h"
#include "config/config.h"
+#include "date/date.h"
#include <fcntl.h>
#include <unistd.h>
@@ -15,6 +16,8 @@
#define CAM_FILE "/dev/robotcam"
+#define CAMERA_DEBUG
+
// Constructeur.
Camera::Camera ()
{
@@ -36,25 +39,33 @@ Camera::Camera ()
{
rc.getId ();
m_w = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera width " << m_w << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("height"))
{
rc.getId ();
m_h = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera height " << m_h << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("depth"))
{
rc.getId ();
m_d = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera depth " << m_d << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("cut"))
{
rc.getId ();
m_cut = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera cut " << m_cut << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("setup"))
{
@@ -62,14 +73,17 @@ Camera::Camera ()
addr = rc.getNum ();
data = rc.getNum ();
param.addr = addr; param.data = data;
+#ifdef CAMERA_DEBUG
cout << "camera sccbwrite 0x" << hex << addr << " 0x" << data <<
endl;
+#endif // CAMERA_DEBUG
ioctl (m_fd, CAM_SCCBWRITE, &param);
}
else
rc.noId ();
}
// Affiche les paramètres.
+#ifdef CAMERA_DEBUG
cout << hex << "camera sccbdump";
for (addr = 0; addr < 0x50; ++addr)
{
@@ -81,6 +95,8 @@ Camera::Camera ()
}
cout << endl << dec;
+#endif // CAMERA_DEBUG
+ m_lastRead = 0;
// Paramètre la taille de frame.
int hcount = m_w * m_d;
ioctl (m_fd, CAM_SETHCOUNT, &hcount);
@@ -97,28 +113,42 @@ Camera::~Camera ()
// Lit une image.
int
-Camera::read (unsigned char *image) const
+Camera::read (unsigned char *image)
{
int r;
+ int t = Date::getInstance ().start ();
+ // Attention, pas trops vite.
+ if (m_lastRead + 100 > t)
+ return 0;
+ m_lastRead = t;
// Lit les données sur la camera.
if (m_cut)
r = ::read (m_fd, image, m_cut);
if (!m_cut || r)
r = ::read (m_fd, image, m_frameSize - m_cut);
+#ifdef CAMERA_DEBUG
cout << "camera read " << r << endl;
+#endif // CAMERA_DEBUG
return r;
}
// Lit une image en RGB.
int
-Camera::readRGB (unsigned char *rgb) const
+Camera::readRGB (unsigned char *rgb)
{
int ret;
+ int t = Date::getInstance ().start ();
+ // Attention, pas trops vite.
+ if (m_lastRead + 100 > t)
+ return 0;
+ m_lastRead = t;
// Alloue de la mémoire.
unsigned char *image = new unsigned char[m_frameSize];
// Lit les données sur la camera.
ret = ::read (m_fd, image, m_frameSize);
+#ifdef CAMERA_DEBUG
cout << "camera read " << ret << endl;
+#endif // CAMERA_DEBUG
if (!ret) return 0;
// Positions de débuts.
unsigned char *r, *g, *b;
@@ -135,6 +165,7 @@ Camera::readRGB (unsigned char *rgb) const
*rgb++ = *b;
b += 4;
}
+ delete image;
return ret - m_cut;
}
diff --git a/2003/i/buzz/src/camera/camera.h b/2003/i/buzz/src/camera/camera.h
index 2ab1479..b6c003e 100644
--- a/2003/i/buzz/src/camera/camera.h
+++ b/2003/i/buzz/src/camera/camera.h
@@ -10,15 +10,16 @@ class Camera
int m_w, m_h, m_d;
int m_cut;
int m_frameSize;
+ int m_lastRead;
public:
// Constructeur.
Camera ();
// Destructeur.
~Camera ();
// Lit une image.
- int read (unsigned char *image) const;
+ int read (unsigned char *image);
// Lit une image en RGB.
- int readRGB (unsigned char *rgb) const;
+ int readRGB (unsigned char *rgb);
// Lit la taille.
void getSize (int &w, int &h) const { w = m_w; h = m_h; }
void getSize (int &w, int &h, int &d) const { w = m_w; h = m_h; d = m_d; }
diff --git a/2003/i/buzz/src/camera/dumpimage.cc b/2003/i/buzz/src/camera/dumpimage.cc
index e617c6a..90909af 100644
--- a/2003/i/buzz/src/camera/dumpimage.cc
+++ b/2003/i/buzz/src/camera/dumpimage.cc
@@ -3,6 +3,7 @@
// Copyright (C) 2003 Nicolas Schodet
//
#include "camera.h"
+#include "date/date.h"
#include <iomanip>
#include <unistd.h>
@@ -11,16 +12,17 @@ int
main (int argc, char **argv)
{
Camera cam;
- int w, h;
- cam.getSize (w, h);
- unsigned char *image = new unsigned char[w * h * 3];
+ Date date;
+ int w, h, d;
+ cam.getSize (w, h, d);
+ unsigned char *image = new unsigned char[w * h * d];
cout << hex;
int j = 0;
int pixel;
while (1)
{
cout << dec << "\n- " << j++ << hex << " ---------";
- while (cam.read (image) == 0) sleep (1);
+ while (cam.read (image) == 0);
for (int i = 0; i < 256; ++i)
{
if (!(i % 16))
diff --git a/2003/i/buzz/src/camera/test_camera.cc b/2003/i/buzz/src/camera/test_camera.cc
index 11dac93..701b050 100644
--- a/2003/i/buzz/src/camera/test_camera.cc
+++ b/2003/i/buzz/src/camera/test_camera.cc
@@ -4,6 +4,7 @@
//
#include "camera.h"
#include "erreur/erreur.h"
+#include "date/date.h"
#include <fstream>
#include <unistd.h>
@@ -15,6 +16,7 @@ main (int argc, char **argv)
try
{
Camera cam;
+ Date date;
int w, h, d;
cam.getSize (w, h, d);
unsigned char *image = new unsigned char[w * h * d];
@@ -42,7 +44,7 @@ main (int argc, char **argv)
}
for (int j = 0; j < w * h; ++j)
{
- int t = (int) image[j * 4 + 2] >> 2 - (int) image[j * 4 + 1] >> 2;
+ int t = ((int) image[j * 4 + 2] >> 1) - ((int) image[j * 4 + 1] >> 1);
t = t > 0 ? t : -t;
image2[j] = t;
}
diff --git a/2003/i/buzz/src/erreur/erreur.cc b/2003/i/buzz/src/erreur/erreur.cc
index b9be6ea..1015cdb 100644
--- a/2003/i/buzz/src/erreur/erreur.cc
+++ b/2003/i/buzz/src/erreur/erreur.cc
@@ -23,6 +23,9 @@ const char *
ErreurConfig::what () const
{
static char descr[1024];
- sprintf (descr, "%s: %s", m_file, m_descr);
+ 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/2003/i/buzz/src/erreur/erreur.h b/2003/i/buzz/src/erreur/erreur.h
index 572211b..be7d445 100644
--- a/2003/i/buzz/src/erreur/erreur.h
+++ b/2003/i/buzz/src/erreur/erreur.h
@@ -24,10 +24,14 @@ class ErreurFatale : public Erreur
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_descr = descr; }
+ { m_file = file; m_id = 0; m_descr = descr; }
virtual const char *what () const;
};