From 49034868bdc301ddfc83eb64053e3e00fb750049 Mon Sep 17 00:00:00 2001 From: haller Date: Sat, 20 May 2006 17:53:05 +0000 Subject: * Ajout de testProto.tty dans config (ouais c'est bof) * test_proto compile --- i/marvin/runtime/rc/config | 4 +++- i/marvin/src/proto/Makefile.defs | 2 +- i/marvin/src/proto/test_proto.cc | 47 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 5 deletions(-) (limited to 'i/marvin') diff --git a/i/marvin/runtime/rc/config b/i/marvin/runtime/rc/config index de0bf14..573101e 100644 --- a/i/marvin/runtime/rc/config +++ b/i/marvin/runtime/rc/config @@ -40,7 +40,7 @@ motor.pStatMotor = 0 # - file:/path/filename : to a file ; # - ram : in a circular buffer for getting it at the end of the program by # network. -# log.logger.default = "stdout" +log.logger.default = "ram" # log.logger.asserv = "null" ### Exemples @@ -48,3 +48,5 @@ foo = "toto" bar = ("a" "b" "c") foobar = (4 5 6 7 8) +# TestProto +testProto.tty = "/home/nicolas/robotSVN/n/asserv/src/asserv/uart0.pts" 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("proto.tty")); + proto_.open(config_.get("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; + } +} -- cgit v1.2.3