summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2011-03-30 22:57:27 +0200
committerNicolas Schodet2011-03-30 23:52:36 +0200
commitde33ce7ed22fffc12861416c6140ce152eaad180 (patch)
treecbffd2eda0ac0da0d9e7b741b814729706333021
parent712fcb0da93d06f65e0a3e33ab6211f101593000 (diff)
digital/io: use message type registry, refs #157
-rw-r--r--digital/io/src/simu.host.c48
-rw-r--r--digital/io/tools/io/mex.py56
2 files changed, 52 insertions, 52 deletions
diff --git a/digital/io/src/simu.host.c b/digital/io/src/simu.host.c
index bc4c404f..276c3b14 100644
--- a/digital/io/src/simu.host.c
+++ b/digital/io/src/simu.host.c
@@ -35,18 +35,6 @@
#include "modules/path/path.h"
#include "io.h"
-enum
-{
- MSG_SIMU_IO_JACK = 0xb0,
- MSG_SIMU_IO_COLOR = 0xb1,
- MSG_SIMU_IO_SERVO = 0xb2,
- MSG_SIMU_IO_ADC = 0xb3,
- MSG_SIMU_IO_PATH = 0xb4,
- MSG_SIMU_IO_PWM = 0xb5,
- MSG_SIMU_IO_CONTACT = 0xb6,
- MSG_SIMU_IO_POS_REPORT = 0xb7,
-};
-
/** Requested servo position. */
uint8_t servo_high_time_[SERVO_NUMBER];
@@ -76,6 +64,16 @@ uint8_t PORTC, PINC;
/** Unused AVR registers. */
uint8_t PORTD, PORTG, DDRC, DDRD, DDRG;
+/** Message types. */
+uint8_t simu_mex_jack;
+uint8_t simu_mex_color;
+uint8_t simu_mex_servo;
+uint8_t simu_mex_adc;
+uint8_t simu_mex_path;
+uint8_t simu_mex_pwm;
+uint8_t simu_mex_contact;
+uint8_t simu_mex_pos_report;
+
void
handle_contact (void *user, mex_msg_t *msg)
{
@@ -86,8 +84,18 @@ handle_contact (void *user, mex_msg_t *msg)
void
simu_init (void)
{
+ const char *mex_instance;
mex_node_connect ();
- mex_node_register (MSG_SIMU_IO_CONTACT, handle_contact, 0);
+ mex_instance = host_get_instance ("io0", 0);
+ simu_mex_jack = mex_node_reservef ("%s:jack", mex_instance);
+ simu_mex_color = mex_node_reservef ("%s:color", mex_instance);
+ simu_mex_servo = mex_node_reservef ("%s:servo", mex_instance);
+ simu_mex_adc = mex_node_reservef ("%s:adc", mex_instance);
+ simu_mex_path = mex_node_reservef ("%s:path", mex_instance);
+ simu_mex_pwm = mex_node_reservef ("%s:pwm", mex_instance);
+ simu_mex_contact = mex_node_reservef ("%s:contact", mex_instance);
+ simu_mex_pos_report = mex_node_reservef ("%s:pos-report", mex_instance);
+ mex_node_register (simu_mex_contact, handle_contact, 0);
PINC = 0x3f;
simu_servo_update_cpt = 1;
simu_switch_update_cpt = 1;
@@ -116,7 +124,7 @@ simu_step (void)
if (simu_servo_update && !--simu_servo_update_cpt)
{
simu_servo_update_cpt = simu_servo_update;
- m = mex_msg_new (MSG_SIMU_IO_SERVO);
+ m = mex_msg_new (simu_mex_servo);
for (i = 0; i < SERVO_NUMBER; i++)
mex_msg_push (m, "B", servo_high_time_current_[i]);
mex_node_send (m);
@@ -128,14 +136,14 @@ simu_step (void)
uint8_t r;
simu_switches = 0;
/* Get color switch. */
- m = mex_msg_new (MSG_SIMU_IO_COLOR);
+ m = mex_msg_new (simu_mex_color);
m = mex_node_request (m);
mex_msg_pop (m, "B", &r);
mex_msg_delete (m);
if (!r)
simu_switches |= 1;
/* Get jack. */
- m = mex_msg_new (MSG_SIMU_IO_JACK);
+ m = mex_msg_new (simu_mex_jack);
m = mex_node_request (m);
mex_msg_pop (m, "B", &r);
mex_msg_delete (m);
@@ -146,7 +154,7 @@ simu_step (void)
if (simu_adc_update && !--simu_adc_update_cpt)
{
simu_adc_update_cpt = simu_adc_update;
- m = mex_msg_new (MSG_SIMU_IO_ADC);
+ m = mex_msg_new (simu_mex_adc);
m = mex_node_request (m);
uint8_t i, n;
n = mex_msg_len (m) / 2;
@@ -159,7 +167,7 @@ simu_step (void)
if (simu_pwm_update && !--simu_pwm_update_cpt)
{
simu_pwm_update_cpt = simu_pwm_update;
- m = mex_msg_new (MSG_SIMU_IO_PWM);
+ m = mex_msg_new (simu_mex_pwm);
mex_msg_push (m, "h", (IO_PORT (PWM_DIR_IO) & IO_BV (PWM_DIR_IO))
? PWM_OCR : -PWM_OCR);
mex_node_send (m);
@@ -241,7 +249,7 @@ simu_send_path (vect_t *points, uint8_t len,
{
int i;
mex_msg_t *m;
- m = mex_msg_new (MSG_SIMU_IO_PATH);
+ m = mex_msg_new (simu_mex_path);
for (i = 0; i < len; i++)
mex_msg_push (m, "hh", points[i].x, points[i].y);
mex_node_send (m);
@@ -251,7 +259,7 @@ void
simu_send_pos_report (vect_t *pos, uint8_t pos_nb, uint8_t id)
{
mex_msg_t *m;
- m = mex_msg_new (MSG_SIMU_IO_POS_REPORT);
+ m = mex_msg_new (simu_mex_pos_report);
mex_msg_push (m, "b", id);
for (; pos_nb; pos++, pos_nb--)
mex_msg_push (m, "hh", pos->x, pos->y);
diff --git a/digital/io/tools/io/mex.py b/digital/io/tools/io/mex.py
index 16c8eef6..4d7e1649 100644
--- a/digital/io/tools/io/mex.py
+++ b/digital/io/tools/io/mex.py
@@ -26,15 +26,6 @@
from utils.observable import Observable
import simu.mex.msg
-ID_JACK = 0xb0
-ID_COLOR = 0xb1
-ID_SERVO = 0xb2
-ID_ADC = 0xb3
-ID_PATH = 0xb4
-ID_PWM = 0xb5
-ID_CONTACT = 0xb6
-ID_POS_REPORT = 0xb7
-
SERVO_NB = 6
SERVO_VALUE_MAX = 255
@@ -56,11 +47,11 @@ class Mex:
"""
- def __init__ (self, node, id):
+ def __init__ (self, node, mtype):
Observable.__init__ (self)
self.__node = node
self.state = None
- node.register (id, self.__handle)
+ node.register (mtype, self.__handle)
def __handle (self, msg):
assert self.state is not None
@@ -82,9 +73,9 @@ class Mex:
class Pack:
"""Handle reception of several Servo for one message."""
- def __init__ (self, node, list):
+ def __init__ (self, node, instance, list):
self.__list = list
- node.register (ID_SERVO, self.__handle)
+ node.register (instance + ':servo', self.__handle)
def __handle (self, msg):
values = msg.pop ('%dB' % len (self.__list))
@@ -106,10 +97,10 @@ class Mex:
class Pack:
"""Handle transmission of several ADC for one message."""
- def __init__ (self, node, list):
+ def __init__ (self, node, instance, list):
self.__node = node
self.__list = list
- node.register (ID_ADC, self.__handle)
+ node.register (instance + ':adc', self.__handle)
def __handle (self, msg):
m = msg
@@ -128,10 +119,10 @@ class Mex:
"""
- def __init__ (self, node):
+ def __init__ (self, node, instance):
Observable.__init__ (self)
self.path = [ ]
- node.register (ID_PATH, self.__handle)
+ node.register (instance + ':path', self.__handle)
def __handle (self, msg):
self.path = [ ]
@@ -153,9 +144,9 @@ class Mex:
class Pack:
"""Handle reception of several PWM for one message."""
- def __init__ (self, node, list):
+ def __init__ (self, node, instance, list):
self.__list = list
- node.register (ID_PWM, self.__handle)
+ node.register (instance + ':pwm', self.__handle)
def __handle (self, msg):
values = msg.pop ('%dh' % len (self.__list))
@@ -183,9 +174,10 @@ class Mex:
class Pack:
"""Handle emission of several contacts for one message."""
- def __init__ (self, node):
+ def __init__ (self, node, instance):
self.node = node
self.contacts = CONTACT_INIT
+ self.mtype = node.reserve (instance + ':contact')
def set (self, index, state):
if state is None or state:
@@ -195,7 +187,7 @@ class Mex:
self.__send ()
def __send (self):
- m = simu.mex.msg.Msg (ID_CONTACT)
+ m = simu.mex.msg.Msg (self.mtype)
m.push ('B', self.contacts)
self.node.send (m)
@@ -207,10 +199,10 @@ class Mex:
"""
- def __init__ (self, node):
+ def __init__ (self, node, instance):
Observable.__init__ (self)
self.pos = { }
- node.register (ID_POS_REPORT, self.__handle)
+ node.register (instance + ':pos-report', self.__handle)
def __handle (self, msg):
p = [ ]
@@ -220,18 +212,18 @@ class Mex:
self.pos[id] = p
self.notify ()
- def __init__ (self, node):
- self.jack = self.Switch (node, ID_JACK)
- self.color_switch = self.Switch (node, ID_COLOR)
+ def __init__ (self, node, instance = 'io0'):
+ self.jack = self.Switch (node, instance + ':jack')
+ self.color_switch = self.Switch (node, instance + ':color')
self.servo = tuple (self.Servo () for i in range (0, SERVO_NB))
- self.__servo_pack = self.Servo.Pack (node, self.servo)
+ self.__servo_pack = self.Servo.Pack (node, instance, self.servo)
self.adc = tuple (self.ADC () for i in range (0, ADC_NB))
- self.__adc_pack = self.ADC.Pack (node, self.adc)
- self.path = self.Path (node)
+ self.__adc_pack = self.ADC.Pack (node, instance, self.adc)
+ self.path = self.Path (node, instance)
self.pwm = tuple (self.PWM () for i in range (0, PWM_NB))
- self.__adc_pwm = self.PWM.Pack (node, self.pwm)
- self.__contact_pack = self.Contact.Pack (node)
+ self.__adc_pwm = self.PWM.Pack (node, instance, self.pwm)
+ self.__contact_pack = self.Contact.Pack (node, instance)
self.contact = tuple (self.Contact (self.__contact_pack, i)
for i in range (CONTACT_NB))
- self.pos_report = self.PosReport (node)
+ self.pos_report = self.PosReport (node, instance)