summaryrefslogtreecommitdiffhomepage
path: root/digital/io-serial/src
diff options
context:
space:
mode:
Diffstat (limited to 'digital/io-serial/src')
-rw-r--r--digital/io-serial/src/codebar/Makefile2
-rw-r--r--digital/io-serial/src/codebar/avrconfig.h18
-rw-r--r--digital/io-serial/src/codebar/codebar.c173
-rw-r--r--digital/io-serial/src/codebar/codebar.h39
4 files changed, 83 insertions, 149 deletions
diff --git a/digital/io-serial/src/codebar/Makefile b/digital/io-serial/src/codebar/Makefile
index a62147a3..f607da5f 100644
--- a/digital/io-serial/src/codebar/Makefile
+++ b/digital/io-serial/src/codebar/Makefile
@@ -1,7 +1,7 @@
BASE = ../../../avr
AVR_PROGS = codebar_reader
codebar_reader_SOURCES = codebar.c timer.avr.c
-MODULES = proto twi uart utils
+MODULES = twi uart utils
AI_MODULES = utils
CONFIGFILE = avrconfig.h
AVR_MCU = atmega164p
diff --git a/digital/io-serial/src/codebar/avrconfig.h b/digital/io-serial/src/codebar/avrconfig.h
index 6acd0e81..b7624a5c 100644
--- a/digital/io-serial/src/codebar/avrconfig.h
+++ b/digital/io-serial/src/codebar/avrconfig.h
@@ -35,7 +35,7 @@
#define AC_UART0_PORT 0
/** Baudrate: 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800,
* 115200, 230400, 250000, 500000, 1000000. */
-#define AC_UART0_BAUDRATE 115200
+#define AC_UART0_BAUDRATE 9600
/** Send mode:
* - POLLING: no interrupts.
* - RING: interrupts, ring buffer. */
@@ -45,7 +45,7 @@
/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
#define AC_UART0_CHAR_SIZE 8
/** Parity : ODD, EVEN, NONE. */
-#define AC_UART0_PARITY EVEN
+#define AC_UART0_PARITY NONE
/** Stop bits : 1, 2. */
#define AC_UART0_STOP_BITS 1
/** Send buffer size, should be power of 2 for RING mode. */
@@ -62,11 +62,11 @@
#define AC_UART0_HOST_DRIVER PTS
/** Same thing for secondary port. */
#define AC_UART1_PORT 1
-#define AC_UART1_BAUDRATE 115200
+#define AC_UART1_BAUDRATE 9600
#define AC_UART1_SEND_MODE RING
#define AC_UART1_RECV_MODE RING
#define AC_UART1_CHAR_SIZE 8
-#define AC_UART1_PARITY EVEN
+#define AC_UART1_PARITY NONE
#define AC_UART1_STOP_BITS 1
#define AC_UART1_SEND_BUFFER_SIZE 32
#define AC_UART1_RECV_BUFFER_SIZE 32
@@ -97,14 +97,4 @@
/** Slave transmission buffer size. */
#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 16
-/* proto - Protocol module. */
-/** Maximum argument size. */
-#define AC_PROTO_ARGS_MAX_SIZE 12
-/** Callback function name. */
-#define AC_PROTO_CALLBACK proto_callback
-/** Putchar function name. */
-#define AC_PROTO_PUTC uart0_putc
-/** Support for quote parameter. */
-#define AC_PROTO_QUOTE 1
-
#endif /* avrconfig_h */
diff --git a/digital/io-serial/src/codebar/codebar.c b/digital/io-serial/src/codebar/codebar.c
index 056508c3..8d845784 100644
--- a/digital/io-serial/src/codebar/codebar.c
+++ b/digital/io-serial/src/codebar/codebar.c
@@ -23,12 +23,11 @@
*
* }}} */
-#include <stdio.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
-#include "codebar.h"
#include "modules/twi/twi.h"
#include "modules/proto/proto.h"
#include "modules/uart/uart.h"
@@ -39,13 +38,8 @@
/* from robospierre/element.h file */
#define ELEMENT_UNKOWN 0
-#define ELEMENT_PAWN 1
-#define ELEMENT_QUEEN 2
-#define ELEMENT_KING 4
-
-#define KING "KING"
-#define QUEEN "QUEEN"
-#define PAWN "PAWN"
+#define ELEMENT_QUEEN 4
+#define ELEMENT_KING 8
#define STRING_MAX 10
@@ -57,64 +51,56 @@ struct status_t
uint8_t piece2;
};
-void proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
-{
- /* nothing here*/
-}
+char buffer_u0[STRING_MAX], buffer_u1[STRING_MAX];
-uint8_t string_to_element(char* data)
+uint8_t
+string_to_element (char *data, uint8_t data_len)
{
- if (strlen(data) == 5)
- return ELEMENT_QUEEN;
- if (strcmp(data, KING) == 0)
- return ELEMENT_KING;
- if (strcmp(data, PAWN) == 0)
- return ELEMENT_PAWN;
+ uint8_t i;
+ for (i = 0; i < data_len - 5; i++)
+ {
+ if (memcmp (data + i, "QUEEN", 5) == 0)
+ {
+ data[i] = 0;
+ return ELEMENT_QUEEN;
+ }
+ }
+ for (i = 0; i < data_len - 4; i++)
+ {
+ if (memcmp (data + i, "KING", 4) == 0)
+ {
+ data[i] = 0;
+ return ELEMENT_KING;
+ }
+ }
return ELEMENT_UNKOWN;
}
-char* read_string(int uart_port)
-{
- static int cnt_char_u0 = 0;
- static char buffer_u0[STRING_MAX] = {'\0'};
- static int cnt_char_u1 = 0;
- static char buffer_u1[STRING_MAX] = {'\0'};
-
- char c;
-
- if (uart_port == 0 && uart0_poll ())
- {
- while ( uart0_poll() && (c = uart0_getc()) != '\r')
- {
- buffer_u0[cnt_char_u0] = c;
- cnt_char_u0++;
- }
- buffer_u0[cnt_char_u0+1] = '\0';
- cnt_char_u0 = 0;
- return buffer_u0;
- }
- else if (uart_port == 1 && uart1_poll())
- {
- while ( uart1_poll() && (c = uart1_getc()) != '\r')
- {
- buffer_u1[cnt_char_u1] = c;
- cnt_char_u1++;
- }
- buffer_u1[cnt_char_u1+1] = '\0';
- cnt_char_u1 = 0;
- return buffer_u1;
- }
- else
- {
- return NULL;
- }
+void
+read_strings (void)
+{
+ uint8_t i;
+ while (uart0_poll ())
+ {
+ /* Insert char at end of string. */
+ for (i = 1; i < STRING_MAX; i++)
+ buffer_u0[i - 1] = buffer_u0[i];
+ buffer_u0[STRING_MAX - 1] = uart0_getc ();
+ }
+ while (uart1_poll ())
+ {
+ /* Insert char at end of string. */
+ for (i = 1; i < STRING_MAX; i++)
+ buffer_u1[i - 1] = buffer_u1[i];
+ buffer_u1[STRING_MAX - 1] = uart1_getc ();
+ }
}
int
main (int argc, char **argv)
{
- char* buffer;
struct status_t status;
+ uint8_t element_type;
status.age1 = 0;
status.piece1 = ELEMENT_UNKOWN;
@@ -126,46 +112,43 @@ main (int argc, char **argv)
sei ();
uart0_init ();
uart1_init ();
- /* We have successfully boot. */
- proto_send0 ('z');
/* Initialize TWI. */
- twi_init (0x04);
- /* I am a slave. */
- proto_send0 ('S');
-
- while (1)
- {
- /* Wait until next cycle. */
- timer_wait ();
- if (status.age1 < (uint16_t) -1)
- status.age1 ++;
- if (status.age2 < (uint16_t) -1)
- status.age2 ++;
-
- if ((buffer = read_string(0)) != NULL)
- {
- status.piece1 = string_to_element(buffer);
- }
-
- if ((buffer = read_string(1)) != NULL)
- {
- status.piece2 = string_to_element(buffer);
- }
+ twi_init (0x20);
- uint8_t status_with_crc[8];
- uint8_t *status_twi = &status_with_crc[1];
- status_twi[0] = v16_to_v8 (status.age1, 0);
- status_twi[1] = v16_to_v8 (status.age1, 1);
- status_twi[2] = status.piece1;
- status_twi[3] = v16_to_v8 (status.age2, 0);
- status_twi[4] = v16_to_v8 (status.age2, 1);
- status_twi[5] = status.piece2;
- status_twi[6] = 42;
- status_twi[7] = 32;
- /* Compute CRC. */
- status_with_crc[0] = crc_compute (&status_with_crc[1], sizeof (status_with_crc) - 1);
- twi_slave_update (status_with_crc, sizeof (status_with_crc));
-
- }
+ while (1)
+ {
+ /* Wait until next cycle. */
+ timer_wait ();
+ if (status.age1 < (uint16_t) -1)
+ status.age1 ++;
+ if (status.age2 < (uint16_t) -1)
+ status.age2 ++;
+
+ read_strings ();
+ element_type = string_to_element (buffer_u0, STRING_MAX);
+ if (element_type)
+ {
+ status.piece1 = element_type;
+ status.age1 = 0;
+ }
+ element_type = string_to_element (buffer_u1, STRING_MAX);
+ if (element_type)
+ {
+ status.piece2 = element_type;
+ status.age2 = 0;
+ }
+
+ uint8_t status_with_crc[7];
+ uint8_t *status_twi = &status_with_crc[1];
+ status_twi[0] = v16_to_v8 (status.age1, 1);
+ status_twi[1] = v16_to_v8 (status.age1, 0);
+ status_twi[2] = status.piece1;
+ status_twi[3] = v16_to_v8 (status.age2, 1);
+ status_twi[4] = v16_to_v8 (status.age2, 0);
+ status_twi[5] = status.piece2;
+ /* Compute CRC. */
+ status_with_crc[0] = crc_compute (&status_with_crc[1], sizeof (status_with_crc) - 1);
+ twi_slave_update (status_with_crc, sizeof (status_with_crc));
+ }
return 0;
}
diff --git a/digital/io-serial/src/codebar/codebar.h b/digital/io-serial/src/codebar/codebar.h
deleted file mode 100644
index 5b84f898..00000000
--- a/digital/io-serial/src/codebar/codebar.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef codebar_h
-#define codebar_h
-/* codebar.h */
-/* {{{
- *
- * Copyright (C) 2011
- *
- * Robot APB Team/Efrei 2011
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * }}} */
-
-/* Read a string from UART0 and return NULL or the string read. */
-char* read_string(int uart_port);
-
-/* Take a string and check it againt the list of valid element
- * as defined in io-hub/src/robospierre/element.h and return the
- * u8 value of this element.
- */
-uint8_t string_to_element(char* data);
-
-void proto_callback (uint8_t cmd, uint8_t size, uint8_t *args);
-
-#endif /* codebar_h */