From 134d70d22824e3d7b7c696622792a2c97cc4a57f Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 11 May 2012 00:46:02 +0200 Subject: digital/ai/src/twi_master, digital/beacon/src/stub: update twi protocol --- digital/ai/src/twi_master/beacon.c | 27 +++++++++++++++++++++++++-- digital/ai/src/twi_master/beacon.h | 8 ++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'digital/ai') diff --git a/digital/ai/src/twi_master/beacon.c b/digital/ai/src/twi_master/beacon.c index b9703d7b..c17a1896 100644 --- a/digital/ai/src/twi_master/beacon.c +++ b/digital/ai/src/twi_master/beacon.c @@ -36,6 +36,10 @@ struct beacon_t vect_t position[AC_BEACON_POSITION_NB]; /** Obstacles trust. */ uint8_t trust[AC_BEACON_POSITION_NB]; + /** To send: beacon system powered. */ + uint8_t on; + /** To send: number of robots. */ + uint8_t robot_nb; }; struct beacon_t beacon; @@ -45,6 +49,8 @@ beacon_init (void) uint8_t i; for (i = 0; i < AC_BEACON_POSITION_NB; i++) beacon.trust[i] = 0; + beacon.on = 0; + beacon.robot_nb = 0; } void @@ -64,10 +70,27 @@ beacon_status_cb (uint8_t *status) void beacon_on (uint8_t on_off) +{ + beacon.on = on_off; +} + +void +beacon_robot_nb (uint8_t robot_nb) +{ + beacon.robot_nb = robot_nb; +} + +void +beacon_send_position (vect_t *position) { uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_BEACON); - buffer[0] = on_off; - twi_master_send_buffer (1); + buffer[0] = beacon.on; + buffer[1] = beacon.robot_nb; + buffer[2] = v16_to_v8 (position->x, 1); + buffer[3] = v16_to_v8 (position->x, 0); + buffer[4] = v16_to_v8 (position->y, 1); + buffer[5] = v16_to_v8 (position->y, 0); + twi_master_send_transient_buffer (6); } uint8_t diff --git a/digital/ai/src/twi_master/beacon.h b/digital/ai/src/twi_master/beacon.h index d0faa701..767dc21c 100644 --- a/digital/ai/src/twi_master/beacon.h +++ b/digital/ai/src/twi_master/beacon.h @@ -47,6 +47,14 @@ beacon_status_cb (uint8_t *status); void beacon_on (uint8_t on_off); +/** Communicate the number of opponent robots. */ +void +beacon_robot_nb (uint8_t robot_nb); + +/** Send my position, along with other informations. */ +void +beacon_send_position (vect_t *position); + /** Get a detected position, return trust (0 for invalid, 100 for full * trust). */ uint8_t -- cgit v1.2.3