summaryrefslogtreecommitdiff
path: root/2005/i
diff options
context:
space:
mode:
authorhaller2005-04-06 15:14:06 +0000
committerhaller2005-04-06 15:14:06 +0000
commite055e4400ca30eb6cde9207a1a707504cafbe274 (patch)
tree381f280afc00fde793447c0e4dc91ffda87c4058 /2005/i
parent0c9b63e2dcaf9aac4aef287f84ecb36391b362f8 (diff)
Quelque modifs pour les codings standards(nom de fonction en colonne zéro)
améliorations de quelques parties du code corrections de quelques erreurs Y'a encore du boulot
Diffstat (limited to '2005/i')
-rw-r--r--2005/i/robert/src/proto/proto.cc280
-rw-r--r--2005/i/robert/src/proto/proto.hh8
2 files changed, 164 insertions, 124 deletions
diff --git a/2005/i/robert/src/proto/proto.cc b/2005/i/robert/src/proto/proto.cc
index 23ccb93..c8f4e1e 100644
--- a/2005/i/robert/src/proto/proto.cc
+++ b/2005/i/robert/src/proto/proto.cc
@@ -34,20 +34,23 @@ Proto::Proto(Receiver &receiver)
}
/// Ouvre le port srie.
-void Proto::open(const std::string &ttyname)
+void
+Proto::open(const std::string &ttyname)
{
serial_.open(ttyname);
}
/// Ferme le port srie
-void Proto::close(void)
+void
+Proto::close(void)
{
serial_.close();
}
/// Teste si tout les packets ont t envoys et aquits, sinon, essaye de
/// le faire.
-bool Proto::sync(void)
+bool
+Proto::sync(void)
{
bool reGet = true;
//Rcupration de la frame
@@ -80,7 +83,8 @@ bool Proto::sync(void)
}
/// Envoie un packet
-void Proto::send (const Frame & Frame)
+void
+Proto::send (const Frame & Frame)
{
frameQueue_.push(Frame);
sync();
@@ -90,13 +94,30 @@ void Proto::send (const Frame & Frame)
/// Envois un packet. COMMAND est la commande envoyer, FORMAT, donne le
/// format et le nombre de paramtres ('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,
+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);
+ //int nbArg = strlen(format);
frame.command = command;
+
+ if (format[0] != '\0')
+ {
+ newArgFrame(frame, format[0],a0);
+ if (format[1] != '\0')
+ {
+ newArgFrame(frame, format[1],a1);
+ if (format[2] != '\0')
+ {
+ newArgFrame(frame, format[2],a2);
+ if (format[3] != '\0')
+ newArgFrame(frame, format[3],a3);
+ }
+ }
+ }
+ /*
// Conversion et saisie des aguments
if(nbArg == 1)
newArgFrame(frame, format[0], a0);
@@ -118,30 +139,46 @@ void Proto::send (uint8_t command, const char *format, int a0, int a1,
newArgFrame(frame, format[2], a2);
newArgFrame(frame, format[3], a3);
}
+ */
send(frame);
}
-bool Proto::decode (const Proto::Frame &frame)
+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);
+ /*
//On teste si des arguments sont prsents(ca serait pas bon)
if(!frame.args.empty())
return false;
else
return true;
+ */
}
-bool Proto::decode (const Frame &frame, const char *format, int &a0)
+bool
+Proto::decode (const Frame &frame, const char *format, int &a0)
{
+ int dummy;
+ return decode(frame, format, a0, dummy, dummy, dummy);
+ /*
// On teste le format de la frame
if(!verifyFrame(frame, format, 1))
return false;
//On dcode et on envoie
a0 = decodeArg(frame, format, 0);
return true;
+ */
}
-bool Proto::decode (const Frame &frame, const char *format, int &a0, int &a1)
+bool
+Proto::decode (const Frame &frame, const char *format, int &a0, int &a1)
{
+ int dummy;
+ return decode(frame, format, a0, a1, dummy, dummy);
+ /*
// On vrifie le format de la frame
if(!verifyFrame(frame, format, 2))
return false;
@@ -149,11 +186,17 @@ bool Proto::decode (const Frame &frame, const char *format, int &a0, int &a1)
a0 = decodeArg(frame, format, 0);
a1 = decodeArg(frame, format, 1);
return true;
+ */
}
-bool Proto::decode (const Frame &frame, const char *format, int &a0,
+bool
+Proto::decode (const Frame &frame, const char *format, int &a0,
int &a1, int &a2)
{
+
+ int dummy;
+ return decode(frame, format, a0, a1, a2, dummy);
+ /*
// On vrifie le format de la frame
if(!verifyFrame(frame, format, 3))
return false;
@@ -162,24 +205,25 @@ bool Proto::decode (const Frame &frame, const char *format, int &a0,
a1 = decodeArg(frame, format, 1);
a2 = decodeArg(frame, format, 2);
return true;
+ */
}
-bool Proto::decode (const Frame &frame, const char *format, int &a0,
+bool
+Proto::decode (const Frame &frame, const char *format, int &a0,
int &a1, int &a2, int &a3)
-{
- // On vrifie le format de la frame
- if(!verifyFrame(frame, format, 3))
- return false;
+{
+ //Teste si il y a bien le bon nombre d'argument
+ if (int(frame.args.size()) != argsFrameSize(format))//un cast pour virer un warning
+ return false;
// On dcode et on envoie
- a0 = decodeArg(frame, format, 0);
- a1 = decodeArg(frame, format, 1);
- a2 = decodeArg(frame, format, 2);
- a3 = decodeArg(frame, format, 3);
+ decodeArg(frame, format, a0, a1, a2, a3);
+
return true;
}
/// Rcupre les infos de l'AVR pour construire une frame
-bool Proto::getFrame(void)
+bool
+Proto::getFrame(void)
{
int receivedChar;
//tant que le tampon n'est pas vide, on teste
@@ -203,22 +247,22 @@ bool Proto::getFrame(void)
}
//Pour les autres charactres
//Si on attend la commande
- else if(revState_ == 1)
- {
- currentFrame_.command = ((uint8_t)hex2digit( receivedChar ))
- << 4;
- revState_ = 2;
- }
- else if(revState_ == 2)
- {
- currentFrame_.command |= (uint8_t)hex2digit( receivedChar );
- revState_ = 3;
- }
- else if(revState_ == 3)
+ switch(revState_)
{
- currentFrame_.args.push_back(((uint8_t)
- hex2digit( receivedChar )) << 4);
- revState_ = 3;
+ case 1:
+ currentFrame_.command = (uint8_t(hex2digit( receivedChar )))
+ << 4;
+ revState_ = 2;
+ break;
+ case 2:
+ currentFrame_.command |= uint8_t(hex2digit( receivedChar ));
+ revState_ = 3;
+ break;
+ case 3:
+ currentFrame_.args.push_back(uint8_t(
+ hex2digit( receivedChar )) << 4);
+ revState_ = 3;
+ break;
}
//Si revState == 0 alors on jette
}
@@ -226,7 +270,8 @@ bool Proto::getFrame(void)
return false;
}
-void Proto::sendFrame(const Frame & frame)
+ void
+Proto::sendFrame(const Frame & frame)
{
//envoyer le bang
serial_.putchar('!');
@@ -236,7 +281,7 @@ void 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 < int(frame.args.size()); i++) //le cast est pour virer un warning
{
serial_.putchar(digit2hex(frame.args[i] >> 4));
serial_.putchar(digit2hex(frame.args[i] & 0x0f));
@@ -249,114 +294,111 @@ void Proto::sendFrame(const Frame & frame)
tLastSend_ = Timer::getProgramTime();
}
-void Proto::newArgFrame(Proto::Frame & frame, char format, int arg)
+ 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(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(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);
+ 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 size = 0;
- if(nbArg == 0)
- nbArg = strlen(format);
- for(int i = 0; i < nbArg; i++)
- size += argSize(format[i]);
+ for(; *format != '\0'; format++)
+ switch(*format)
+ {
+ case 'b':
+ case 'B':
+ size += 1;
+ case 'w':
+ case 'W':
+ size += 1;
+ case 'd':
+ case 'D':
+ size += 1;
+ default:
+ size += 1;
+ }
return size;
}
-int Proto::argSize(char format)
-{
- switch(format)
- {
- case 'b':
- case 'B':
- return 1;
- case 'w':
- case 'W':
- return 2;
- case 'd':
- case 'D':
- return 4;
- default:
- return 0;
- }
-}
-
-bool Proto::verifyFrame(const Frame &frame, const char *format, int nbArg)
+void
+Proto::decodeArg(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)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 temp[4];
+ int pos = 0;
- switch(format[numArg])
- {
- case 'b':
- argDecoded = (int)frame.args[beginArg];
- break;
- case 'B':
- {
- int8_t temp = (int8_t)frame.args[beginArg];
- argDecoded = (int) temp;
- break;
- }
- case 'w':
- 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
- |(int)frame.args[beginArg + 1];
- break;
- }
- case 'd':
- argDecoded = (int)frame.args[beginArg] << 24
- |(int)frame.args[beginArg + 1] << 16
- |(int)frame.args[beginArg + 2] << 8
- |(int)frame.args[beginArg + 3];
- break;
+ for(int i = 0; *format != '\0'; format++,i++)
+ {
+ switch(*format)
+ {
+ case 'b':
+ temp[i] = int(frame.args[pos]);
+ pos++;
+ break;
+ case 'B':
+ {
+ int8_t t = int8_t(frame.args[pos]);
+ temp[i] = int(t);
+ pos++;
+ break;
+ }
+ case 'w':
+ temp[i] = int(frame.args[pos]) << 8
+ |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]);
+ 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]);
+ pos += 4;
+ break;
- case 'D':
- int8_t temp1 = (int8_t)frame.args[beginArg];
- argDecoded = (int)temp1 << 24
- |(int)frame.args[beginArg + 1] << 16
- |(int)frame.args[beginArg + 2] << 8
- |(int)frame.args[beginArg + 3];
- 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]);
+ break;
+ }
}
- return argDecoded;
+ a0 = temp[0];
+ a1 = temp[1];
+ a2 = temp[2];
+ a3 = temp[3];
}
-bool Proto::Frame::operator==(const Frame& frame)
+ 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 d27619b..701c725 100644
--- a/2005/i/robert/src/proto/proto.hh
+++ b/2005/i/robert/src/proto/proto.hh
@@ -104,13 +104,11 @@ class Proto : public NonCopyable
/// Remplie une frame avec un argument
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,int nbArg = 0);
+ static int argsFrameSize(const char *format);
/// Renvoie la taille necessaire du vecteur args pour 1 argument
- static int argSize(char format);
- /// Vrifie le format de la frame
- static bool verifyFrame(const Frame &frame, const char *format, int nbArg);
+// static int argSize(char format);
/// Dcode un argument
- static int decodeArg(const Frame & frame, const char *format, int numArg);
+ static void decodeArg(const Frame & frame, const char *format, int &a0, int &a1, int &a2, int &a3);
};
#endif // proto_hh