summaryrefslogtreecommitdiff
path: root/i/marvin/src/proto/test_proto.cc
diff options
context:
space:
mode:
authorhaller2006-05-20 17:53:05 +0000
committerhaller2006-05-20 17:53:05 +0000
commit49034868bdc301ddfc83eb64053e3e00fb750049 (patch)
tree573650ea302f9e64afba19be39fead298e2cb27b /i/marvin/src/proto/test_proto.cc
parentd4c3552bfa3a97ad9c962a71cef6413a94a157f3 (diff)
* Ajout de testProto.tty dans config (ouais c'est bof)
* test_proto compile
Diffstat (limited to 'i/marvin/src/proto/test_proto.cc')
-rw-r--r--i/marvin/src/proto/test_proto.cc47
1 files changed, 44 insertions, 3 deletions
diff --git a/i/marvin/src/proto/test_proto.cc b/i/marvin/src/proto/test_proto.cc
index 5af8d14..08b3b42 100644
--- a/i/marvin/src/proto/test_proto.cc
+++ b/i/marvin/src/proto/test_proto.cc
@@ -41,10 +41,10 @@ class TestProto : public Tester, Proto::Receiver
{
Interpreter &interpreter = getInterpreter ();
// Récupère le tty de config
- proto_.open(config_.get<std::string>("proto.tty"));
+ proto_.open(config_.get<std::string>("testProto.tty"));
// Add functions.
- interpreter.add ("s", Interpreter::memFunc ( proto_, &Proto::send ),
- "Fonction wait (string, commande, string format, int arg...)");
+ interpreter.add ("s", Interpreter::memFunc ( *this, &TestProto::send ),
+ "Fonction send (string commande, string format, int arg...)");
interpreter.add ("w", Interpreter::memFunc ( proto_, &Proto::wait ), "Fonction wait ()");
}
void postRun(void)
@@ -55,5 +55,46 @@ class TestProto : public Tester, Proto::Receiver
{
std::cout << "received " << frame << std::endl;
}
+ void send (std::string str)
+ {
+ char command = str[0];
+ char *format;
+ int arg[6];
+ int nbArg = 0;
+ char *temp;
+ char *string = new char[str.size() + 1];
+ strcpy(string, str.c_str());
+ // On fait un strtok qui sert à rien
+ strtok(string, " ");
+ // On récupère le format
+ format = strtok(0, " ");
+ if(!format)
+ throw std::runtime_error("La commande n'a pas de format");
+ // On récupère les arguments
+ for(; nbArg < 6; nbArg++)
+ {
+ if((temp = strtok(0, " ")))
+ break;
+ else
+ arg[nbArg] = atoi(temp);
+ }
+ for(;nbArg < 6; nbArg++)
+ arg[nbArg] = 0;
+ proto_.send(command, format, arg[0], arg[1], arg[2], arg[3], arg[4],
+ arg[5]);
+ }
};
+int
+main (int argc, char **argv)
+{
+ try
+ {
+ TestProto tp (argc, argv);
+ tp.run ();
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << e.what () << std::endl;
+ }
+}