summaryrefslogtreecommitdiff
path: root/i/marvin/src/proto/proto.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/proto/proto.cc')
-rw-r--r--i/marvin/src/proto/proto.cc52
1 files changed, 37 insertions, 15 deletions
diff --git a/i/marvin/src/proto/proto.cc b/i/marvin/src/proto/proto.cc
index 07a6634..4380f07 100644
--- a/i/marvin/src/proto/proto.cc
+++ b/i/marvin/src/proto/proto.cc
@@ -59,7 +59,7 @@ Proto::sync(void)
// Récupération de la frame
while (getFrame())
{
-// log_ ("recv") << "frame" << currentFrame_;
+// log_ ("recv", Log::debug) << "frame" << currentFrame_;
// Si la frame est un aquittement
if(currentFrame_ == frameQueue_.front())
{
@@ -119,22 +119,34 @@ Proto::send (char command, const char *format, int a0, int a1,
{
newArgFrame(frame, format[2],a2);
if (format[3] != '\0')
- {
+ {
newArgFrame(frame, format[3],a3);
if(format[4] != '\0')
- {
+ {
newArgFrame(frame, format[4],a4);
if(format[5] != '\0')
newArgFrame(frame, format[5],a5);
- }
+ }
- }
+ }
}
+ }
}
-}
send(frame,reliable);
}
+/// Send a string of size number.
+void
+Proto::send (char command, const std::string &str, int size, bool reliable)
+{
+ Proto::Frame frame;
+
+ for (int compt = 0; compt < size; compt++)
+ newArgFrame (frame, 'b', str[compt]);
+
+ send (frame,reliable);
+}
+
/// permet d'envoyer un packet pas fiable
void
Proto::sendUnreliable (char command, const char *format, int a0, int a1,
@@ -149,21 +161,21 @@ bool
Proto::decode (const Proto::Frame &frame)
{
int dummy;
- return decode(frame, "", dummy, dummy, dummy, dummy);
+ return decode(frame, "", dummy, dummy, dummy, dummy, dummy);
}
bool
Proto::decode (const Frame &frame, const char *format, int &a0)
{
int dummy;
- return decode(frame, format, a0, dummy, dummy, dummy);
+ return decode(frame, format, a0, dummy, dummy, dummy, dummy);
}
bool
Proto::decode (const Frame &frame, const char *format, int &a0, int &a1)
{
int dummy;
- return decode(frame, format, a0, a1, dummy, dummy);
+ return decode(frame, format, a0, a1, dummy, dummy, dummy);
}
bool
@@ -171,18 +183,26 @@ Proto::decode (const Frame &frame, const char *format, int &a0,
int &a1, int &a2)
{
int dummy;
- return decode(frame, format, a0, a1, a2, dummy);
+ return decode(frame, format, a0, a1, a2, dummy, dummy);
}
bool
Proto::decode (const Frame &frame, const char *format, int &a0,
int &a1, int &a2, int &a3)
+{
+ int dummy;
+ return decode(frame, format, a0, a1, a2, a3, dummy);
+}
+
+bool
+Proto::decode (const Frame &frame, const char *format, int &a0,
+ int &a1, int &a2, int &a3, int &a4)
{
// Teste si il y a bien le bon nombre d'argument
if (static_cast<int>(frame.args.size()) != argsFrameSize(format))
return false;
// On décode et on envoie
- decodeArg(frame, format, a0, a1, a2, a3);
+ decodeArg(frame, format, a0, a1, a2, a3, a4);
return true;
}
@@ -267,7 +287,8 @@ Proto::getFrame(void)
{
// On renvoie en mettant le compteur à 0, la commande sera
// renvoyer de retour à sync
-// log_("Erreur de reception") << "commande inconnue" << "";
+// log_("Erreur de reception", Log::debug)
+// << "commande inconnue" << "";
tLastSend_ = 0;
revState_ = 0;
return false;
@@ -280,7 +301,7 @@ Proto::getFrame(void)
void
Proto::sendFrame(const Frame & frame)
{
-// log_ ("send") << "frame" << frame;
+// log_ ("send", Log::debug) << "frame" << frame;
// envoyer le bang
serial_.putchar('!');
@@ -355,9 +376,9 @@ Proto::argsFrameSize(const char *format)
/// Décode un argument
void
-Proto::decodeArg(const Frame & frame, const char *format, int &a0, int &a1, int &a2, int &a3)
+Proto::decodeArg(const Frame & frame, const char *format, int &a0, int &a1, int &a2, int &a3, int &a4)
{
- int temp[4];
+ int temp[5];
int pos = 0;
for(int i = 0; *format != '\0'; format++,i++)
@@ -412,6 +433,7 @@ Proto::decodeArg(const Frame & frame, const char *format, int &a0, int &a1, int
a1 = temp[1];
a2 = temp[2];
a3 = temp[3];
+ a4 = temp[4];
}
bool