From 712fcb0da93d06f65e0a3e33ab6211f101593000 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 30 Mar 2011 22:25:25 +0200 Subject: digital/mimot: use message type registry, refs #157 --- digital/mimot/src/dirty/simu.host.c | 14 +++++++++++--- digital/mimot/tools/mimot/mex.py | 18 ++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/digital/mimot/src/dirty/simu.host.c b/digital/mimot/src/dirty/simu.host.c index c773f5a2..af07d744 100644 --- a/digital/mimot/src/dirty/simu.host.c +++ b/digital/mimot/src/dirty/simu.host.c @@ -74,6 +74,10 @@ uint32_t simu_counter_aux[AC_ASSERV_AUX_NB]; /** Use mex. */ int simu_mex; +/** Mex message types. */ +uint8_t simu_mex_aux; +uint8_t simu_mex_limits; + /** Counter to limit the interval between information is sent. */ int simu_send_cpt; @@ -114,15 +118,19 @@ simu_init (void) { int argc; char **argv; + const char *mex_instance; host_get_program_arguments (&argc, &argv); if (argc == 2 && strncmp (argv[0], "-m", 2) == 0) { simu_mex = atoi (argv[0] + 2); + argc--; argv++; if (!simu_mex) simu_mex = 1; simu_send_cpt = simu_mex; mex_node_connect (); - mex_node_register (0xcc, simu_handle_limits, 0); - argc--; argv++; + mex_instance = host_get_instance ("mimot0", 0); + simu_mex_aux = mex_node_reservef ("%s:aux", mex_instance); + simu_mex_limits = mex_node_reservef ("%s:limits", mex_instance); + mex_node_register (simu_mex_limits, simu_handle_limits, 0); } if (argc != 1) { @@ -204,7 +212,7 @@ simu_send (void) } if (first || simu_aux_model_changed) { - m = mex_msg_new (0xc8); + m = mex_msg_new (simu_mex_aux); for (i = 0; i < AC_ASSERV_AUX_NB; i++) { if (simu_robot->aux_motor[i]) diff --git a/digital/mimot/tools/mimot/mex.py b/digital/mimot/tools/mimot/mex.py index a190c1cc..5724189e 100644 --- a/digital/mimot/tools/mimot/mex.py +++ b/digital/mimot/tools/mimot/mex.py @@ -26,9 +26,6 @@ from utils.observable import Observable import simu.mex.msg -ID_AUX = 0xc8 -ID_LIMITS = 0xcc - class Mex: """Handle communications with simulated mimot.""" @@ -46,9 +43,9 @@ class Mex: class Pack: """Handle reception of several Aux for one message.""" - def __init__ (self, node, list): + def __init__ (self, node, instance, list): self.__list = list - node.register (ID_AUX, self.__handle) + node.register (instance + ':aux', self.__handle) def __handle (self, msg): angles = msg.pop ('%dl' % len (self.__list)) @@ -77,8 +74,9 @@ class Mex: class Pack: """Handle emission of several limits for one message.""" - def __init__ (self, node): + def __init__ (self, node, instance): self.node = node + self.mtype = node.reserve (instance + ':limits') self.limits = [ None, None, None, None ] def set (self, index, min, max): @@ -87,7 +85,7 @@ class Mex: self.__send () def __send (self): - m = simu.mex.msg.Msg (ID_LIMITS) + m = simu.mex.msg.Msg (self.mtype) for l in self.limits: if l is None: li = -1 @@ -96,10 +94,10 @@ class Mex: m.push ('l', li) self.node.send (m) - def __init__ (self, node): + def __init__ (self, node, instance = 'mimot0'): self.aux = (self.Aux (), self.Aux ()) - self.__aux_pack = self.Aux.Pack (node, self.aux) - self.__limits_pack = self.Limits.Pack (node) + self.__aux_pack = self.Aux.Pack (node, instance, self.aux) + self.__limits_pack = self.Limits.Pack (node, instance) for index, aux in enumerate (self.aux): aux.limits = self.Limits (self.__limits_pack, index) -- cgit v1.2.3