summaryrefslogtreecommitdiff
path: root/2004
diff options
context:
space:
mode:
authorschodet2004-04-17 08:22:22 +0000
committerschodet2004-04-17 08:22:22 +0000
commit494d04e99b004567ea8949d4a094248ac714ece1 (patch)
treef4e6e8717f25d5947cf66b24cb86c3b2dfed0542 /2004
parent38309a2e4afecdd1546120019437a7093513944d (diff)
Déplacement des fonctions de décodage hexa.
Diffstat (limited to '2004')
-rw-r--r--2004/i/nono/src/motor/asserv.cc28
-rw-r--r--2004/i/nono/src/motor/asserv.h4
-rw-r--r--2004/i/nono/src/utils/hexa.cc18
-rw-r--r--2004/i/nono/src/utils/hexa.h6
4 files changed, 29 insertions, 27 deletions
diff --git a/2004/i/nono/src/motor/asserv.cc b/2004/i/nono/src/motor/asserv.cc
index e0ebd37..adb3fb1 100644
--- a/2004/i/nono/src/motor/asserv.cc
+++ b/2004/i/nono/src/motor/asserv.cc
@@ -308,9 +308,9 @@ Asserv::handleStatMotor (void)
return;
}
char side = inBuf_[2];
- int vacc = getSignedChar (inBuf_ + 2 + 1);
- int e = getSignedShort (inBuf_ + 2 + 1 + 2 + 1);
- int pwm = getSignedShort (inBuf_ + 2 + 1 + 2 + 1 + 4 + 1);
+ int vacc = hexSignedChar2int (inBuf_ + 2 + 1);
+ int e = hexSignedShort2int (inBuf_ + 2 + 1 + 2 + 1);
+ int pwm = hexSignedShort2int (inBuf_ + 2 + 1 + 2 + 1 + 4 + 1);
log_ (Log::verydebug) << "stat motor " << side << ' ' << vacc << ' ' << e
<< ' ' << pwm << std::endl;
}
@@ -325,8 +325,8 @@ Asserv::handleCounter (void)
log_ (Log::warning) << "counter error" << std::endl;
return;
}
- int l = getSignedShort (inBuf_ + 2);
- int r = getSignedShort (inBuf_ + 2 + 4 + 1);
+ int l = hexSignedShort2int (inBuf_ + 2);
+ int r = hexSignedShort2int (inBuf_ + 2 + 4 + 1);
if (firstCounter_)
{
// Première valeur ignorée.
@@ -355,21 +355,3 @@ Asserv::handleCounter (void)
countLeft_ = l;
countRight_ = r;
}
-
-/// Décode un mot signé (1 octets).
-int
-Asserv::getSignedChar (const char *s) const
-{
- return (signed char) (hex2digit (s[0]) << 4
- | hex2digit (s[1]) << 0);
-}
-
-/// Décode un mot signé (2 octets).
-int
-Asserv::getSignedShort (const char *s) const
-{
- return (short) (hex2digit (s[0]) << 12
- | hex2digit (s[1]) << 8
- | hex2digit (s[2]) << 4
- | hex2digit (s[3]));
-}
diff --git a/2004/i/nono/src/motor/asserv.h b/2004/i/nono/src/motor/asserv.h
index e95a3c7..5685bff 100644
--- a/2004/i/nono/src/motor/asserv.h
+++ b/2004/i/nono/src/motor/asserv.h
@@ -106,10 +106,6 @@ class Asserv
void handleStatMotor (void);
/// Traite un message du compteur.
void handleCounter (void);
- /// Décode un mot signé (1 octets).
- int getSignedChar (const char *s) const;
- /// Décode un mot signé (2 octets).
- int getSignedShort (const char *s) const;
};
#endif // asserv_h
diff --git a/2004/i/nono/src/utils/hexa.cc b/2004/i/nono/src/utils/hexa.cc
index 247b44c..ab43f64 100644
--- a/2004/i/nono/src/utils/hexa.cc
+++ b/2004/i/nono/src/utils/hexa.cc
@@ -62,3 +62,21 @@ digit2hex (int d)
return digit2hexTbl_[d];
}
+/// Décode un mot signé (1 octets).
+int
+hexSignedChar2int (const char *s) const
+{
+ return (signed char) (hex2digit (s[0]) << 4
+ | hex2digit (s[1]) << 0);
+}
+
+/// Décode un mot signé (2 octets).
+int
+hexSignedShort2int (const char *s) const
+{
+ return (short) (hex2digit (s[0]) << 12
+ | hex2digit (s[1]) << 8
+ | hex2digit (s[2]) << 4
+ | hex2digit (s[3]));
+}
+
diff --git a/2004/i/nono/src/utils/hexa.h b/2004/i/nono/src/utils/hexa.h
index 2bcf81d..cdae943 100644
--- a/2004/i/nono/src/utils/hexa.h
+++ b/2004/i/nono/src/utils/hexa.h
@@ -31,4 +31,10 @@ int hex2digit (char c);
/// Converti un chiffre (0-15) en hexa (0-9a-f).
char digit2hex (int d);
+/// Décode un mot signé (1 octets).
+int hexSignedChar2int (const char *s) const;
+
+/// Décode un mot signé (2 octets).
+int hexSignedShort2int (const char *s) const;
+
#endif // hexa_h