summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaller2005-04-07 20:27:53 +0000
committerhaller2005-04-07 20:27:53 +0000
commita957915d1fc7d5c465e43647bdce04ca8d9e992b (patch)
treee18dcaee0430e4ab4c3a7acb67e964f5c77b349d
parente280e5728defeb5c0d362da5a905fdf429c21f8d (diff)
Modifications des commentaires
Ajout de la possibilité d'envoie des packets non fiables ajout des static_cast
-rw-r--r--2005/i/robert/src/proto/proto.cc98
-rw-r--r--2005/i/robert/src/proto/proto.hh14
2 files changed, 67 insertions, 45 deletions
diff --git a/2005/i/robert/src/proto/proto.cc b/2005/i/robert/src/proto/proto.cc
index d65aa58..c0f95f7 100644
--- a/2005/i/robert/src/proto/proto.cc
+++ b/2005/i/robert/src/proto/proto.cc
@@ -84,9 +84,16 @@ Proto::sync(void)
/// Envoie un packet
void
-Proto::send (const Frame & Frame)
+Proto::send (const Frame & frame, bool fiable)
{
- frameQueue_.push(Frame);
+ if(fiable)
+ {
+ if(frameQueue_.empty())
+ tLastSend_ =0;
+ frameQueue_.push(frame);
+ }
+ else
+ sendFrame(frame);
sync();
}
@@ -96,11 +103,10 @@ Proto::send (const Frame & Frame)
/// 32 bits, majuscule pour signé).
void
Proto::send (uint8_t command, const char *format, int a0, int a1,
- int a2, int a3)
+ int a2, int a3, bool fiable)
{
// Constitution de la frame
Proto::Frame frame;
- //int nbArg = strlen(format);
frame.command = command;
if (format[0] != '\0')
@@ -117,13 +123,22 @@ Proto::send (uint8_t command, const char *format, int a0, int a1,
}
}
}
- send(frame);
+ send(frame,fiable);
}
+/// permet d'envoyer un packet pas fiable
+void
+Proto::send_pas_fiable (uint8_t command, const char *format, int a0, int a1,
+ int a2, int a3)
+{
+ send(command, format, a0, a1, a2, a3, false);
+}
+
+/// Teste si le packet correspond au format et décode les valeurs. Utilise
+/// le même format que send.
bool
Proto::decode (const Proto::Frame &frame)
{
- //bon, est-ce que c'est bien utile ça?
int dummy;
return decode(frame, "", dummy, dummy, dummy, dummy);
}
@@ -156,7 +171,7 @@ Proto::decode (const Frame &frame, const char *format, int &a0,
int &a1, int &a2, int &a3)
{
//Teste si il y a bien le bon nombre d'argument
- if (int(frame.args.size()) != argsFrameSize(format))//un cast pour virer un warning
+ if (static_cast<int>(frame.args.size()) != argsFrameSize(format))
return false;
// On décode et on envoie
decodeArg(frame, format, a0, a1, a2, a3);
@@ -193,16 +208,17 @@ Proto::getFrame(void)
switch(revState_)
{
case 1:
- currentFrame_.command = (uint8_t(hex2digit( receivedChar )))
+ currentFrame_.command = (static_cast<uint8_t>(hex2digit( receivedChar )))
<< 4;
revState_ = 2;
break;
case 2:
- currentFrame_.command |= uint8_t(hex2digit( receivedChar ));
+ currentFrame_.command |= static_cast<uint8_t>(hex2digit(
+ receivedChar ));
revState_ = 3;
break;
case 3:
- currentFrame_.args.push_back(uint8_t(
+ currentFrame_.args.push_back(static_cast<uint8_t>(
hex2digit( receivedChar )) << 4);
revState_ = 3;
break;
@@ -213,7 +229,8 @@ Proto::getFrame(void)
return false;
}
- void
+/// Envoie la frame dans l'AVR
+void
Proto::sendFrame(const Frame & frame)
{
//envoyer le bang
@@ -224,7 +241,7 @@ Proto::sendFrame(const Frame & frame)
serial_.putchar(digit2hex(frame.command & 0x0f));
//Envoyer les arguments
- for(int i = 0; i < int(frame.args.size()); i++) //le cast est pour virer un warning
+ for(int i = 0; i < static_cast<int>(frame.args.size()); i++)
{
serial_.putchar(digit2hex(frame.args[i] >> 4));
serial_.putchar(digit2hex(frame.args[i] & 0x0f));
@@ -237,31 +254,33 @@ Proto::sendFrame(const Frame & frame)
tLastSend_ = Timer::getProgramTime();
}
- void
+/// Remplie une frame avec un argument
+void
Proto::newArgFrame(Proto::Frame & frame, char format, int arg)
{
switch(format)
{
case 'b':
case 'B':
- frame.args.push_back(uint8_t(arg));
+ frame.args.push_back(static_cast<uint8_t>(arg));
break;
case 'w':
case 'W':
- frame.args.push_back(uint8_t(arg >> 8));
- frame.args.push_back(uint8_t(arg));
+ frame.args.push_back(static_cast<uint8_t>(arg >> 8));
+ frame.args.push_back(static_cast<uint8_t>(arg));
break;
case 'd':
case 'D':
- frame.args.push_back(uint8_t(arg >> 24));
- frame.args.push_back(uint8_t(arg >> 16));
- frame.args.push_back(uint8_t(arg >> 8));
- frame.args.push_back(uint8_t(arg));
+ frame.args.push_back(static_cast<uint8_t>(arg >> 24));
+ frame.args.push_back(static_cast<uint8_t>(arg >> 16));
+ frame.args.push_back(static_cast<uint8_t>(arg >> 8));
+ frame.args.push_back(static_cast<uint8_t>(arg));
break;
}
}
- int
+/// Renvoie la taille necessaire du vecteur args pour un format donné
+int
Proto::argsFrameSize(const char *format)
{
int size = 0;
@@ -283,6 +302,7 @@ Proto::argsFrameSize(const char *format)
return size;
}
+/// Décode un argument
void
Proto::decodeArg(const Frame & frame, const char *format, int &a0, int &a1, int &a2, int &a3)
{
@@ -294,43 +314,43 @@ Proto::decodeArg(const Frame & frame, const char *format, int &a0, int &a1, int
switch(*format)
{
case 'b':
- temp[i] = int(frame.args[pos]);
+ temp[i] = static_cast<int>(frame.args[pos]);
pos++;
break;
case 'B':
{
- int8_t t = int8_t(frame.args[pos]);
- temp[i] = int(t);
+ int8_t t = static_cast<int8_t>(frame.args[pos]);
+ temp[i] = static_cast<int>(t);
pos++;
break;
}
case 'w':
- temp[i] = int(frame.args[pos]) << 8
- |int(frame.args[pos + 1]);
+ temp[i] = static_cast<int>(frame.args[pos]) << 8
+ |static_cast<int>(frame.args[pos + 1]);
pos += 2;
break;
case 'W':
{
- int8_t t = int8_t(frame.args[pos]);
- temp[i] = int(t) << 8
- |int(frame.args[pos + 1]);
+ int8_t t = static_cast<int8_t>(frame.args[pos]);
+ temp[i] = static_cast<int>(t) << 8
+ |static_cast<int>(frame.args[pos + 1]);
pos += 2;
break;
}
case 'd':
- temp[i] = int(frame.args[pos]) << 24
- |int(frame.args[pos + 1]) << 16
- |int(frame.args[pos + 2]) << 8
- |int(frame.args[pos + 3]);
+ temp[i] = static_cast<int>(frame.args[pos]) << 24
+ |static_cast<int>(frame.args[pos + 1]) << 16
+ |static_cast<int>(frame.args[pos + 2]) << 8
+ |static_cast<int>(frame.args[pos + 3]);
pos += 4;
break;
case 'D':
- int8_t t = int8_t(frame.args[pos]);
- temp[i] = int(t) << 24
- |int(frame.args[pos + 1]) << 16
- |int(frame.args[pos + 2]) << 8
- |int(frame.args[pos + 3]);
+ int8_t t = static_cast<int8_t>(frame.args[pos]);
+ temp[i] = static_cast<int>(t) << 24
+ |static_cast<int>(frame.args[pos + 1]) << 16
+ |static_cast<int>(frame.args[pos + 2]) << 8
+ |static_cast<int>(frame.args[pos + 3]);
break;
}
}
@@ -340,7 +360,7 @@ Proto::decodeArg(const Frame & frame, const char *format, int &a0, int &a1, int
a3 = temp[3];
}
- bool
+bool
Proto::Frame::operator==(const Frame& frame)
{
return this->command == frame.command && this->args == frame.args;
diff --git a/2005/i/robert/src/proto/proto.hh b/2005/i/robert/src/proto/proto.hh
index 701c725..49c88e9 100644
--- a/2005/i/robert/src/proto/proto.hh
+++ b/2005/i/robert/src/proto/proto.hh
@@ -37,7 +37,7 @@ class Proto : public NonCopyable
/// Packet.
struct Frame
{
- uint8_t command;
+ char command;
std::vector<uint8_t> args;
bool operator==(const Frame& frame);
};
@@ -70,12 +70,15 @@ class Proto : public NonCopyable
/// le faire.
bool sync (void);
/// Envois un packet.
- void send (const Frame &frame);
+ void send (const Frame &frame, bool fiable = true);
/// Envois un packet. COMMAND est la commande à envoyer, FORMAT, donne le
/// format et le nombre de paramètres ('b' : 8 bits, 'w' : 16 bits, 'd' :
/// 32 bits, majuscule pour signé).
void send (uint8_t command, const char *format = 0, int a0 = 0, int a1 = 0,
- int a2 = 0, int a3 = 0);
+ int a2 = 0, int a3 = 0, bool fiable = true);
+ /// permet d'envoyer un packet robert
+ void Proto::send_pas_fiable (uint8_t command, const char *format, int a0,
+ int a1, int a2, int a3);
//@{
/// Teste si le packet correspond au format et décode les valeurs. Utilise
/// le même format que send.
@@ -105,10 +108,9 @@ class Proto : public NonCopyable
void newArgFrame(Proto::Frame & frame, char format, int arg);
/// Renvoie la taille necessaire du vecteur args pour un format donné
static int argsFrameSize(const char *format);
- /// Renvoie la taille necessaire du vecteur args pour 1 argument
-// static int argSize(char format);
/// Décode un argument
- static void decodeArg(const Frame & frame, const char *format, int &a0, int &a1, int &a2, int &a3);
+ static void decodeArg(const Frame & frame, const char *format, int &a0,
+ int &a1, int &a2, int &a3);
};
#endif // proto_hh