summaryrefslogtreecommitdiff
path: root/i/marvin/src
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src')
-rw-r--r--i/marvin/src/es/es.cc1
-rw-r--r--i/marvin/src/interpreter/interpreter.cc9
-rw-r--r--i/marvin/src/interpreter/interpreter.hh2
-rw-r--r--i/marvin/src/interpreter/interpreter_parser.cc3
-rw-r--r--i/marvin/src/proto/test_proto.cc98
5 files changed, 60 insertions, 53 deletions
diff --git a/i/marvin/src/es/es.cc b/i/marvin/src/es/es.cc
index 4b561cf..0e93d0f 100644
--- a/i/marvin/src/es/es.cc
+++ b/i/marvin/src/es/es.cc
@@ -39,6 +39,7 @@ void Es::init(void)
{
// On reset l'AVR
proto_.send('z');
+ // XXX Voir pour envoyer les config
}
bool
diff --git a/i/marvin/src/interpreter/interpreter.cc b/i/marvin/src/interpreter/interpreter.cc
index a160002..bbf4767 100644
--- a/i/marvin/src/interpreter/interpreter.cc
+++ b/i/marvin/src/interpreter/interpreter.cc
@@ -54,6 +54,15 @@ Interpreter::add (const std::string &s, Func *f)
add (s, f, "");
}
+/// Test if a function is defined.
+bool
+Interpreter::exists (const std::string &s) const
+{
+ Funcs::const_iterator i;
+ i = funcs_.find (s);
+ return i != funcs_.end ();
+}
+
/// Call a function by name.
void
Interpreter::call (const std::string &s, const Args &a,
diff --git a/i/marvin/src/interpreter/interpreter.hh b/i/marvin/src/interpreter/interpreter.hh
index 1f6e688..3341ea1 100644
--- a/i/marvin/src/interpreter/interpreter.hh
+++ b/i/marvin/src/interpreter/interpreter.hh
@@ -69,6 +69,8 @@ class Interpreter
void add (const std::string &s, Func *f, const std::string &desc);
/// Add a function without description, Interpreter owns f.
void add (const std::string &s, Func *f);
+ /// Test if a function is defined.
+ bool exists (const std::string &s) const;
/// Call a function by name.
void call (const std::string &s, const Args &a,
bool dryrun = false) const;
diff --git a/i/marvin/src/interpreter/interpreter_parser.cc b/i/marvin/src/interpreter/interpreter_parser.cc
index 2a3f54b..f10e8ec 100644
--- a/i/marvin/src/interpreter/interpreter_parser.cc
+++ b/i/marvin/src/interpreter/interpreter_parser.cc
@@ -37,6 +37,7 @@ void
InterpreterParser::call (const std::string &id, AnyList &args)
{
interpreter_.call (id, args, dryrun_);
- interpreter_.call ("_postcall", AnyList (), dryrun_);
+ if (interpreter_.exists ("_postcall"))
+ interpreter_.call ("_postcall", AnyList (), dryrun_);
}
diff --git a/i/marvin/src/proto/test_proto.cc b/i/marvin/src/proto/test_proto.cc
index a9f1fa8..01cac96 100644
--- a/i/marvin/src/proto/test_proto.cc
+++ b/i/marvin/src/proto/test_proto.cc
@@ -25,66 +25,60 @@
#include "proto.hh"
#include "timer/timer.hh"
#include "tester/tester.hh"
+#include "parser/parser.hh"
#include <iostream>
#include <stdexcept>
class TestProto : public Tester, Proto::Receiver
{
- private:
- Proto proto_;
- public:
- // Constructor
- TestProto (int argc, char ** argv)
- : Tester (argc, argv), proto_(*this){}
- void preRun (void)
- {
- Interpreter &interpreter = getInterpreter ();
- // Récupère le tty de config
- proto_.open(config_.get<std::string>("testProto.tty"));
- // Add functions.
- 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)
- {
- proto_.close();
- }
- void receive (char command, const Proto::Frame &frame)
- {
- std::cout << "received " << frame << std::endl;
- }
- void send (std::string str)
+ private:
+ Proto proto_;
+ public:
+ // Constructor
+ TestProto (int argc, char ** argv)
+ : Tester (argc, argv), proto_(*this){}
+ void preRun (void)
+ {
+ Interpreter &interpreter = getInterpreter ();
+ // Récupère le tty de config
+ proto_.open(config_.get<std::string>("testProto.tty"));
+ // Add functions.
+ 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)
+ {
+ proto_.close();
+ }
+ void receive (char command, const Proto::Frame &frame)
+ {
+ std::cout << "received " << frame << std::endl;
+ }
+ void send (const Parser::AnyList & al, bool dryrun)
+ {
+ Parser::AnyList::const_iterator it = al.begin();
+ // arguments envoyé à la fonctions Proto::send
+ int arg[6];
+ // command avr
+ char command = any_cast<char> (*it);
+ // format des arguments
+ std::string format = any_cast<std::string> (*++it);
+ // Récupération des arguments
+ for (unsigned i = 0; i < 6; ++i)
{
- // command avr
- char command = str[0];
- // format des arguments
- char *format;
- // arguments envoyé à la fonctions Proto::send
- 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, " ");
- // 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?"":format, arg[0], arg[1], arg[2], arg[3], arg[4],
- arg[5]);
- delete [] string;
+ if(i < al.size() - 2)
+ arg[i] = any_cast<int> (*++it);
+ else
+ arg[i] = 0;
}
+ if (!dryrun)
+ proto_.send(command, format.c_str(), arg[0], arg[1], arg[2],
+ arg[3], arg[4], arg[5]);
+ }
};
int