summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/proto/proto.cc
diff options
context:
space:
mode:
authorhaller2005-04-04 16:49:03 +0000
committerhaller2005-04-04 16:49:03 +0000
commit1441236626460fba0d4e032c04a0fadb8861b619 (patch)
tree1ec5247ca9a91ae439d2f66d97c3ffff59270004 /2005/i/robert/src/proto/proto.cc
parent4bf8554325d4db51f9c18fbcc8f96233a9f733df (diff)
Correction de quelques entorses aux robot coding standards
Diffstat (limited to '2005/i/robert/src/proto/proto.cc')
-rw-r--r--2005/i/robert/src/proto/proto.cc90
1 files changed, 47 insertions, 43 deletions
diff --git a/2005/i/robert/src/proto/proto.cc b/2005/i/robert/src/proto/proto.cc
index 15a2272..23ccb93 100644
--- a/2005/i/robert/src/proto/proto.cc
+++ b/2005/i/robert/src/proto/proto.cc
@@ -29,9 +29,7 @@
/// Constructeur.
Proto::Proto(Receiver &receiver)
- :receiver_(receiver)
- ,tLastSend_(0)
- ,revState_(0)
+ :receiver_(receiver), tLastSend_(0), revState_(0)
{
}
@@ -41,13 +39,14 @@ void Proto::open(const std::string &ttyname)
serial_.open(ttyname);
}
-//Ferme le port série
+/// Ferme le port série
void Proto::close(void)
{
serial_.close();
}
-
+/// Teste si tout les packets ont été envoyés et aquités, sinon, essaye de
+/// le faire.
bool Proto::sync(void)
{
bool reGet = true;
@@ -77,9 +76,9 @@ bool Proto::sync(void)
if(Timer::getProgramTime() - tLastSend_ > 500)
sendFrame(frameQueue_.front());
}
-
return frameQueue_.empty();
}
+
/// Envoie un packet
void Proto::send (const Frame & Frame)
{
@@ -87,15 +86,18 @@ void Proto::send (const Frame & Frame)
sync();
}
-void Proto::send (uint8_t command, const char *format, int a0, int a1, int a2, int a3)
+
+/// 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 Proto::send (uint8_t command, const char *format, int a0, int a1,
+ int a2, int a3)
{
// Constitution de la frame
Proto::Frame frame;
int nbArg = strlen(format);
-
frame.command = command;
// Conversion et saisie des aguments
-
if(nbArg == 1)
newArgFrame(frame, format[0], a0);
if (nbArg == 2)
@@ -116,7 +118,6 @@ void Proto::send (uint8_t command, const char *format, int a0, int a1, int a2, i
newArgFrame(frame, format[2], a2);
newArgFrame(frame, format[3], a3);
}
-
send(frame);
}
@@ -132,8 +133,8 @@ bool Proto::decode (const Proto::Frame &frame)
bool Proto::decode (const Frame &frame, const char *format, int &a0)
{
// On teste le format de la frame
- if(!verifyFrame(frame, format, 1)) return false;
-
+ if(!verifyFrame(frame, format, 1))
+ return false;
//On décode et on envoie
a0 = decodeArg(frame, format, 0);
return true;
@@ -142,19 +143,20 @@ bool Proto::decode (const Frame &frame, const char *format, int &a0)
bool Proto::decode (const Frame &frame, const char *format, int &a0, int &a1)
{
// On vérifie le format de la frame
- if(!verifyFrame(frame, format, 2)) return false;
-
+ if(!verifyFrame(frame, format, 2))
+ return false;
// On décode et on envoie
a0 = decodeArg(frame, format, 0);
a1 = decodeArg(frame, format, 1);
return true;
}
-bool Proto::decode (const Frame &frame, const char *format, int &a0, int &a1, int &a2)
+bool Proto::decode (const Frame &frame, const char *format, int &a0,
+ int &a1, int &a2)
{
// On vérifie le format de la frame
- if(!verifyFrame(frame, format, 3)) return false;
-
+ if(!verifyFrame(frame, format, 3))
+ return false;
// On décode et on envoie
a0 = decodeArg(frame, format, 0);
a1 = decodeArg(frame, format, 1);
@@ -162,25 +164,24 @@ bool Proto::decode (const Frame &frame, const char *format, int &a0, int &a1, in
return true;
}
-bool Proto::decode (const Frame &frame, const char *format, int &a0, int &a1, int &a2, int &a3)
+bool Proto::decode (const Frame &frame, const char *format, int &a0,
+ int &a1, int &a2, int &a3)
{
// On vérifie le format de la frame
- if(!verifyFrame(frame, format, 3)) return false;
-
+ if(!verifyFrame(frame, format, 3))
+ return false;
// On décode et on envoie
a0 = decodeArg(frame, format, 0);
a1 = decodeArg(frame, format, 1);
a2 = decodeArg(frame, format, 2);
a3 = decodeArg(frame, format, 3);
return true;
-
}
/// Récupère les infos de l'AVR pour construire une frame
bool Proto::getFrame(void)
{
int receivedChar;
-
//tant que le tampon n'est pas vide, on teste
while((receivedChar = serial_.getchar()) != -1)
{
@@ -204,7 +205,8 @@ bool Proto::getFrame(void)
//Si on attend la commande
else if(revState_ == 1)
{
- currentFrame_.command = ((uint8_t)hex2digit( receivedChar )) << 4;
+ currentFrame_.command = ((uint8_t)hex2digit( receivedChar ))
+ << 4;
revState_ = 2;
}
else if(revState_ == 2)
@@ -214,7 +216,8 @@ bool Proto::getFrame(void)
}
else if(revState_ == 3)
{
- currentFrame_.args.push_back(((uint8_t)hex2digit( receivedChar )) << 4);
+ currentFrame_.args.push_back(((uint8_t)
+ hex2digit( receivedChar )) << 4);
revState_ = 3;
}
//Si revState == 0 alors on jette
@@ -256,31 +259,30 @@ void Proto::newArgFrame(Proto::Frame & frame, char format, int arg)
break;
case 'w':
case 'W':
- frame.args.push_back((uint8_t)(arg>>8));
+ frame.args.push_back((uint8_t)(arg >> 8));
frame.args.push_back((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 >> 24));
+ frame.args.push_back((uint8_t)(arg >> 16));
+ frame.args.push_back((uint8_t)(arg >> 8));
frame.args.push_back((uint8_t)arg);
break;
}
}
-int Proto::ArgsFrameSize(const char *format, int nbArg)
+int Proto::argsFrameSize(const char *format, int nbArg)
{
int size = 0;
if(nbArg == 0)
nbArg = strlen(format);
-
for(int i = 0; i < nbArg; i++)
- size += ArgSize(format[i]);
+ size += argSize(format[i]);
return size;
}
-int Proto::ArgSize(char format)
+int Proto::argSize(char format)
{
switch(format)
{
@@ -301,41 +303,43 @@ int Proto::ArgSize(char format)
bool Proto::verifyFrame(const Frame &frame, const char *format, int nbArg)
{
//Teste si il y a bien le bon nombre d'argument
- if ((int)strlen(format) != nbArg) return false; //Un cast pour shooter un warning
- if ((int)frame.args.size() != ArgsFrameSize(format)) return false; //un cast pour virer un warning
+ if ((int)strlen(format) != nbArg)//Un cast pour shooter un warning
+ return false;
+ if ((int)frame.args.size() != argsFrameSize(format))//un cast pour virer un warning
+ return false;
//Voir pour des test plus approffondi si possible et necessaire
return true;
}
int Proto::decodeArg(const Frame & frame, const char *format, int numArg)
{
- int ArgDecoded = 0;
- int beginArg = ArgsFrameSize(format, numArg);
+ int argDecoded = 0;
+ int beginArg = argsFrameSize(format, numArg);
switch(format[numArg])
{
case 'b':
- ArgDecoded = (int)frame.args[beginArg];
+ argDecoded = (int)frame.args[beginArg];
break;
case 'B':
{
int8_t temp = (int8_t)frame.args[beginArg];
- ArgDecoded = (int) temp;
+ argDecoded = (int) temp;
break;
}
case 'w':
- ArgDecoded = (int)frame.args[beginArg] << 8
+ argDecoded = (int)frame.args[beginArg] << 8
|(int)frame.args[beginArg + 1];
break;
case 'W':
{
int8_t temp1 = (int8_t)frame.args[beginArg];
- ArgDecoded = (int)temp1 << 8
+ argDecoded = (int)temp1 << 8
|(int)frame.args[beginArg + 1];
break;
}
case 'd':
- ArgDecoded = (int)frame.args[beginArg] << 24
+ argDecoded = (int)frame.args[beginArg] << 24
|(int)frame.args[beginArg + 1] << 16
|(int)frame.args[beginArg + 2] << 8
|(int)frame.args[beginArg + 3];
@@ -343,13 +347,13 @@ int Proto::decodeArg(const Frame & frame, const char *format, int numArg)
case 'D':
int8_t temp1 = (int8_t)frame.args[beginArg];
- ArgDecoded = (int)temp1 << 24
+ argDecoded = (int)temp1 << 24
|(int)frame.args[beginArg + 1] << 16
|(int)frame.args[beginArg + 2] << 8
|(int)frame.args[beginArg + 3];
break;
}
- return ArgDecoded;
+ return argDecoded;
}
bool Proto::Frame::operator==(const Frame& frame)