summaryrefslogtreecommitdiff
path: root/i/marvin/src/proto
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/proto')
-rw-r--r--i/marvin/src/proto/Makefile.defs2
-rw-r--r--i/marvin/src/proto/test_proto.cc47
2 files changed, 45 insertions, 4 deletions
diff --git a/i/marvin/src/proto/Makefile.defs b/i/marvin/src/proto/Makefile.defs
index 1b13568..b351026 100644
--- a/i/marvin/src/proto/Makefile.defs
+++ b/i/marvin/src/proto/Makefile.defs
@@ -2,4 +2,4 @@ PROGRAMS += test_proto
proto_OBJECTS = proto.o $(serial_OBJECTS) $(log_OBJECTS) $(utils_OBJECTS) $(timer_OBJECTS)
-test_proto_OBJECTS = test_proto.o $(proto_OBJECTS)
+test_proto_OBJECTS = test_proto.o $(proto_OBJECTS) $(tester_OBJECTS)
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;
+ }
+}