Commit from zer0 on branch b_zer0 (2007-09-17 22:53 CEST)
=================================

Add parse module

  aversive  config/Configure.help                  1.13.4.9
  aversive  config/config.in                       1.42.4.11
  aversive  config/generate_aversive_config        1.23.4.8
+ aversive  modules/ihm/parse/Makefile             1.1.2.1
+ aversive  modules/ihm/parse/parse.c              1.1.2.1
+ aversive  modules/ihm/parse/parse.h              1.1.2.1
+ aversive  modules/ihm/parse/parse_num.c          1.1.2.1
+ aversive  modules/ihm/parse/parse_num.h          1.1.2.1
+ aversive  modules/ihm/parse/parse_string.c       1.1.2.1
+ aversive  modules/ihm/parse/parse_string.h       1.1.2.1
+ aversive  modules/ihm/parse/test/Makefile        1.1.2.1
+ aversive  modules/ihm/parse/test/error_config.h  1.1.2.1
+ aversive  modules/ihm/parse/test/main.c          1.1.2.1
+ aversive  modules/ihm/parse/test/uart_config.h   1.1.2.1
  aversive  projects/example1/.config              1.5.4.4


==============================
aversive/config/Configure.help  (1.13.4.8 -> 1.13.4.9)
==============================

@@ -169,6 +169,10 @@
 CONFIG_MODULE_RDLINE_HISTORY
   Enable history buffer, to save last commands (up and down arrows)
 
+CONFIG_MODULE_PARSE
+  The parse module is able to parse a buffer containing strings, 
+  numbers, (...) into a C structure.
+
 
 CONFIG_MODULE_LCD
   This module provide an interface to control an external standard


=========================
aversive/config/config.in  (1.42.4.10 -> 1.42.4.11)
=========================

@@ -225,7 +225,7 @@
 #### menu
 bool 'Menu' CONFIG_MODULE_MENU
 
-#### menu
+#### rdline
 dep_bool 'Rdline' CONFIG_MODULE_RDLINE \
        $CONFIG_MODULE_CIRBUF
 
@@ -238,6 +238,10 @@
 dep_bool '  |-- Enable history' CONFIG_MODULE_RDLINE_HISTORY \
        $CONFIG_MODULE_RDLINE
 
+#### parse
+
+bool 'Parse' CONFIG_MODULE_PARSE
+
 endmenu
 
 #############################################################################


========================================
aversive/config/generate_aversive_config  (1.23.4.7 -> 1.23.4.8)
========================================

@@ -16,6 +16,7 @@
               CONFIG_MODULE_PWM,hardware/pwm
               CONFIG_MODULE_ADC,hardware/adc
               CONFIG_MODULE_MENU,ihm/menu
+              CONFIG_MODULE_PARSE,ihm/parse
               CONFIG_MODULE_RDLINE,ihm/rdline
               CONFIG_MODULE_LCD,devices/ihm/lcd
               CONFIG_MODULE_MULTISERVO,devices/servo/multiservo


===================================
aversive/modules/ihm/parse/Makefile  (1.1.2.1)
===================================

@@ -0,0 +1,6 @@
+TARGET = parse
+
+# List C source files here. (C dependencies are automatically generated.)
+SRC = parse.c parse_num.c parse_string.c
+
+include $(AVERSIVE_DIR)/mk/aversive_module.mk


==================================
aversive/modules/ihm/parse/parse.c  (1.1.2.1)
==================================

@@ -0,0 +1,170 @@
+#include <stdio.h>
+#include <inttypes.h>
+#include <ctype.h>
+
+#include "parse.h"
+
+/* XXX */
+#ifndef BUFSIZ
+#define BUFSIZ 128
+#endif
+
+static int
+isendofline(char c)
+{
+       if (c == '\n' || 
+           c == '\r' )
+               return 1;
+       return 0;
+}
+
+static int
+iscomment(char c)
+{
+       if (c == '#')
+               return 1;
+       return 0;
+}
+
+int
+isendoftoken(char c)
+{
+       if (!c || iscomment(c) || isblank(c) || isendofline(c))
+               return 1;
+       return 0;
+}
+
+
+
+int8_t
+parse_buf(struct ctx * ctx, char * buf)
+{
+       struct inst ** inst_list = (struct inst **) ctx->insts;
+       struct inst * inst = *inst_list;
+       struct token_hdr ** token_list;
+       struct token_hdr * token;
+       char *curbuf;
+       char result_buf[BUFSIZ]; /* XXX align, size */
+       void (*f)(void *, void *) = NULL;
+       void * data = NULL;
+       int8_t n;
+       int comment = 0;
+       int linelen = 0;
+       int parse_it = 0;
+#ifdef CMDLINE_DEBUG
+       char debug_buf[BUFSIZ];
+#endif
+
+       /* 
+        * - look if the buffer contains at least one line
+        * - look if line contains only spaces or comments 
+        * - count line length
+        */
+       curbuf = buf;
+       while (! isendofline(*curbuf)) {
+               if ( *curbuf == '\0' ) {
+                       dprintf("Incomplete buf (len=%d)\n", linelen);
+                       return 0;
+               }
+               if ( iscomment(*curbuf) ) {
+                       comment = 1;
+               }
+               if ( ! isblank(*curbuf) && ! comment) {
+                       parse_it = 1;
+               }
+               curbuf++;
+               linelen++;
+       }
+
+       /* skip all endofline chars */
+       while (isendofline(buf[linelen])) {
+               linelen++;
+       }
+
+       /* empty line */
+       if ( parse_it == 0 ) {
+               dprintf("Empty line (len=%d)\n", linelen);
+               return linelen;
+       }
+
+#ifdef CMDLINE_DEBUG
+       snprintf(debug_buf, (linelen>BUFSIZ-n ? BUFSIZ-n : linelen), "%s", buf);
+       dprintf("Parse line : len=%d, <%s>\n", linelen, debug_buf);
+#endif
+
+       /* parse it !! */
+       while (inst) {
+               dprintf("INST\n");
+               inst = *inst_list;
+               token_list = (struct token_hdr **) inst->tokens;
+               token = *token_list;
+               curbuf = buf;
+
+               /* check if we match all tokens of inst */
+               while (token) {
+                       dprintf("TK\n");
+                       /* skip spaces */
+                       while (isblank(*curbuf)) {
+                               curbuf++;
+                       }
+                       
+                       /* end of buf */
+                       if ( isendofline(*curbuf) || iscomment(*curbuf) )
+                               break;
+
+                       n = token->parse(token, curbuf, 
result_buf+token->offset);
+                       if ( n < 0 )
+                               break;
+                       dprintf("TK parsed (len=%d)\n", n);
+                       curbuf += n;
+
+                       token_list ++;
+                       token = *token_list;
+               }
+
+               /* fully parsed */
+               if (!token) {
+                       dprintf("INST fully parsed\n");
+                       /* skip spaces */
+                       while (isblank(*curbuf)) {
+                               curbuf++;
+                       }
+                       
+                       /* if end of buf -> there is no garbage after inst */
+                       if (isendofline(*curbuf) || iscomment(*curbuf)) {
+                               if (!f) {
+                                       f = inst->f;
+                                       data = inst->data;
+                               }
+                               else {
+                                       /* more than 1 inst matches */
+                                       /* return -1; */
+                                       /* XXX */
+                                       f=NULL;
+                                       dprintf("Ambiguous cmd\n");
+                                       break;
+                               }
+                       }
+                       else {
+                               dprintf("Garbage after inst %x\n", *curbuf & 
0xff);
+                       }
+               }
+                       
+               inst_list ++;
+               inst = *inst_list;
+       }
+       
+       /* call func */
+       if (f) {
+               f(result_buf, data);
+       }
+
+       /* no match */
+       else {
+               /* XXX */
+               /* return mes couilles */
+               dprintf("No match\n");
+       }
+       
+       return linelen;
+}


==================================
aversive/modules/ihm/parse/parse.h  (1.1.2.1)
==================================

@@ -0,0 +1,35 @@
+#ifndef _PARSE_H_
+#define _PARSE_H_
+
+#include <aversive/types.h>
+
+#ifndef offsetof
+#define offsetof(type, field)  ((size_t) &( ((type *)0)->field) )
+#endif
+
+struct token_hdr {
+       /* parse(token ptr, buf, res pts) */
+       int8_t (*parse)(void *, char *, void *);
+       int8_t (*complete)(void *, char *, char *, uint8_t);
+       char * help_str;
+       uint8_t offset;
+};
+
+struct inst {
+       /* f(parsed_struct, data) */
+       void (*f)(void *, void *);
+       void * data;
+       char * help_str;
+       void * tokens[];
+};
+
+struct ctx {
+       char * name;
+       void * insts[];
+};
+
+
+int8_t parse_buf(struct ctx * ctx, char * buf);
+int isendoftoken(char c);
+
+#endif /* _PARSE_H_ */


======================================
aversive/modules/ihm/parse/parse_num.c  (1.1.2.1)
======================================

@@ -0,0 +1,365 @@
+#include <stdio.h>
+#include <inttypes.h>
+#include <ctype.h>
+
+#include "parse.h"
+#include "parse_num.h"
+
+//#define debug_printf(args...) printf(args)
+#define debug_printf(args...) do {} while(0)
+
+/* XXX to remove ?? */
+#define U08_MIN 0x00
+#define U08_MAX 0xFF
+#define U16_MIN 0x0000
+#define U16_MAX 0xFFFF
+#define U32_MIN 0x00000000
+#define U32_MAX 0xFFFFFFFF
+#define S08_MIN 0x80
+#define S08_MAX 0x7F
+#define S16_MIN 0x8000
+#define S16_MAX 0x7FFF
+#define S32_MIN 0x80000000
+#define S32_MAX 0x7FFFFFFF
+
+
+
+
+
+enum num_parse_state_t {
+       START,
+       DEC_NEG,
+       BIN,
+       HEX,
+       FLOAT_POS,
+       FLOAT_NEG,
+       ERROR,
+
+       FIRST_OK, /* not used */
+       ZERO_OK,
+       HEX_OK,
+       OCTAL_OK,
+       BIN_OK,
+       DEC_NEG_OK,
+       DEC_POS_OK,
+       FLOAT_POS_OK,
+       FLOAT_NEG_OK,
+};
+
+
+static inline int8_t 
+add_to_res(uint8_t c, uint32_t * res, uint8_t base)
+{
+       /* overflow */
+       if ( (U32_MAX - c) / base < *res ) {
+               return -1;
+       }
+
+       *res = *res * base + c ;
+       return 0;
+}
+
+
+/* parse an int or a float */
+int8_t 
+parse_num(void * data, char * srcbuf, void * res)
+{
+       struct token_num * token = data;
+       enum num_parse_state_t st = START;
+       char * buf = srcbuf;
+       char c = *buf;
+       uint32_t res1=0, res2=0, res3=1;
+       enum numtype type = token->type;
+
+       while ( st != ERROR && c && ! isendoftoken(c) ) {
+               debug_printf("%c %x -> ", c, c);
+               switch (st) {
+               case START:
+                       if (c == '-') {
+                               st = DEC_NEG;
+                       }
+                       else if (c == '0') {
+                               st = ZERO_OK;
+                       }
+                       else if (c == '.') {
+                               st = FLOAT_POS;
+                               res1 = 0;
+                       }
+                       else if (c >= '1' && c <= '9') {
+                               if (add_to_res(c - '0', &res1, 10) < 0)
+                                       st = ERROR;
+                               else
+                                       st = DEC_POS_OK;
+                       }
+                       else  {
+                               st = ERROR;
+                       }
+                       break;
+
+               case ZERO_OK:
+                       if (c == 'x') {
+                               st = HEX;
+                       }
+                       else if (c == 'b') {
+                               st = BIN;
+                       }
+                       else if (c == '.') {
+                               st = FLOAT_POS;
+                               res1 = 0;
+                       }
+                       else if (c >= '0' && c <= '7') {
+                               if (add_to_res(c - '0', &res1, 10) < 0)
+                                       st = ERROR;
+                               else
+                                       st = OCTAL_OK;
+                       }                       
+                       else  {
+                               st = ERROR;
+                       }
+                       break;
+
+               case DEC_NEG:
+                       if (c >= '0' && c <= '9') {
+                               if (add_to_res(c - '0', &res1, 10) < 0)
+                                       st = ERROR;
+                               else
+                                       st = DEC_NEG_OK;
+                       }
+                       else if (c == '.') {
+                               res1 = 0;
+                               st = FLOAT_NEG;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               case DEC_NEG_OK:
+                       if (c >= '0' && c <= '9') {
+                               if (add_to_res(c - '0', &res1, 10) < 0)
+                                       st = ERROR;
+                       }
+                       else if (c == '.') {
+                               st = FLOAT_NEG;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               case DEC_POS_OK:
+                       if (c >= '0' && c <= '9') {
+                               if (add_to_res(c - '0', &res1, 10) < 0)
+                                       st = ERROR;
+                       }
+                       else if (c == '.') {
+                               st = FLOAT_POS;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               case HEX:
+                       st = HEX_OK;
+                       /* no break */
+               case HEX_OK:
+                       if (c >= '0' && c <= '9') {
+                               if (add_to_res(c - '0', &res1, 16) < 0)
+                                       st = ERROR;
+                       }
+                       else if (c >= 'a' && c <= 'f') {
+                               if (add_to_res(c - 'a' + 10, &res1, 16) < 0)
+                                       st = ERROR;
+                       }
+                       else if (c >= 'A' && c <= 'F') {
+                               if (add_to_res(c - 'A' + 10, &res1, 16) < 0)
+                                       st = ERROR;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+
+               case OCTAL_OK:
+                       if (c >= '0' && c <= '7') {
+                               if (add_to_res(c - '0', &res1, 8) < 0)
+                                       st = ERROR;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               case BIN:
+                       st = BIN_OK; 
+                       /* no break */
+               case BIN_OK:
+                       if (c >= '0' && c <= '1') {
+                               if (add_to_res(c - '0', &res1, 2) < 0)
+                                       st = ERROR;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               case FLOAT_POS:
+                       if (c >= '0' && c <= '9') {
+                               if (add_to_res(c - '0', &res2, 10) < 0)
+                                       st = ERROR;
+                               else 
+                                       st = FLOAT_POS_OK;
+                               res3 = 10;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               case FLOAT_NEG:
+                       if (c >= '0' && c <= '9') {
+                               if (add_to_res(c - '0', &res2, 10) < 0)
+                                       st = ERROR;
+                               else 
+                                       st = FLOAT_NEG_OK;
+                               res3 = 10;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               case FLOAT_POS_OK:
+                       if (c >= '0' && c <= '9') {
+                               if (add_to_res(c - '0', &res2, 10) < 0)
+                                       st = ERROR;
+                               if (add_to_res(0, &res3, 10) < 0)
+                                       st = ERROR;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               case FLOAT_NEG_OK:
+                       if (c >= '0' && c <= '9') {
+                               if (add_to_res(c - '0', &res2, 10) < 0)
+                                       st = ERROR;
+                               if (add_to_res(0, &res3, 10) < 0)
+                                       st = ERROR;
+                       }
+                       else {
+                               st = ERROR;
+                       }
+                       break;
+
+               default:
+                       debug_printf("not impl ");
+                       
+               }
+
+               /* XXX uint32_t et %d */
+               debug_printf("(%d)  (%d)  (%d)\n", res1, res2, res3);
+
+               buf ++;
+               c = *buf;
+
+               /* token too long */
+               if (buf-srcbuf > 127)
+                       return -1;
+       }
+       
+       switch (st) {
+       case ZERO_OK:
+       case DEC_POS_OK:
+       case HEX_OK:
+       case OCTAL_OK:
+       case BIN_OK:
+               if ( type == INT8 && res1 <= S08_MAX ) {
+                       *(int8_t *)res = (int8_t) res1;
+                       return (buf-srcbuf);
+               }
+               else if ( type == INT16 && res1 <= S16_MAX ) {
+                       *(int16_t *)res = (int16_t) res1;
+                       return (buf-srcbuf);
+               }
+               else if ( type == INT32 && res1 <= S32_MAX ) {
+                       *(int32_t *)res = (int32_t) res1;
+               }
+               else if ( type == UINT8 && res1 <= U08_MAX ) {
+                       *(uint8_t *)res = (uint8_t) res1;
+                       return (buf-srcbuf);
+               }
+               else if (type == UINT16  && res1 <= U16_MAX ) {
+                       *(uint16_t *)res = (uint16_t) res1;
+                       return (buf-srcbuf);
+               }
+               else if ( type == UINT32 ) {
+                       *(uint32_t *)res = (uint32_t) res1;
+                       return (buf-srcbuf);
+               }
+               else if ( type == FLOAT ) {
+                       *(float *)res = (float)res1;
+                       return (buf-srcbuf);
+               }
+               else {
+                       return -1;
+               }
+               break;
+
+       case DEC_NEG_OK:
+               if ( type == INT8 && res1 <= S08_MAX + 1 ) {
+                       *(int8_t *)res = (int8_t) res1;
+                       return (buf-srcbuf);
+               }
+               else if ( type == INT16 && res1 <= S16_MAX + 1 ) {
+                       *(int16_t *)res = (int16_t) res1;
+                       return (buf-srcbuf);
+               }
+               else if ( type == INT32 && res1 <= (uint32_t)S32_MAX + 1 ) {
+                       *(int32_t *)res = (int32_t) res1;
+                       return (buf-srcbuf);
+               }
+               else if ( type == FLOAT ) {
+                       *(float *)res = - (float)res1;
+                       return (buf-srcbuf);
+               }
+               else {
+                       return -1;
+               }
+               break;
+
+       case FLOAT_POS:
+       case FLOAT_POS_OK:
+               if ( type == FLOAT ) {
+                       *(float *)res = (float)res1 + ((float)res2 / 
(float)res3);
+                       return (buf-srcbuf);
+                       
+               }
+               else {
+                       return -1;
+               }
+               break;
+
+       case FLOAT_NEG:
+       case FLOAT_NEG_OK:
+               if ( type == FLOAT ) {
+                       *(float *)res = - ((float)res1 + ((float)res2 / 
(float)res3));
+                       return (buf-srcbuf);
+                       
+               }
+               else {
+                       return -1;
+               }
+               break;
+
+       default:
+               debug_printf("error\n");
+               return -1;
+       }
+       return -1;
+}
+
+


======================================
aversive/modules/ihm/parse/parse_num.h  (1.1.2.1)
======================================

@@ -0,0 +1,34 @@
+#ifndef _PARSE_NUM_H_
+#define _PARSE_NUM_H_
+
+#include "parse.h"
+
+enum numtype {
+       UINT8,
+       UINT16,
+       UINT32,
+       INT8,
+       INT16,
+       INT32,
+       FLOAT,
+};
+
+struct token_num {
+       struct token_hdr hdr;
+       enum numtype type;
+};
+
+int8_t parse_num(void * token_ptr, char * srcbuf, void * res);
+
+#define TOKEN_NUM_INITIALIZER(structure, field, numtype)   \
+{                                                         \
+       {                                                  \
+               .parse = parse_num,                        \
+               .complete = NULL,                          \
+               .help_str = NULL,                          \
+               .offset = offsetof(structure, field),      \
+       },                                                 \
+       .type = numtype,                                   \
+};
+
+#endif /* _PARSE_NUM_H_ */


=========================================
aversive/modules/ihm/parse/parse_string.c  (1.1.2.1)
=========================================

@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <inttypes.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "parse.h"
+#include "parse_string.h"
+
+int8_t 
+parse_string(void * data, char * buf, void * res)
+{
+       struct token_string * token = data;
+       uint8_t token_len;
+
+       if (! *buf)
+               return -1;
+
+       /* fixed string */
+       if (token->str) {
+               token_len = strlen(token->str);
+               
+               /* if token is too big... */
+               if (token_len >= STR_TOKEN_SIZE - 1) {
+                       return -1;
+               }
+               
+               if ( strncmp(buf, token->str, token_len) ) {
+                       return -1;
+               }
+
+               if ( !isendoftoken(*(buf+token_len)) )
+                       return -1;
+       }
+       /* unspecified string */
+       else {
+               token_len=0;
+               while(!isendoftoken(buf[token_len]) && 
+                     token_len < (STR_TOKEN_SIZE-1))
+                       token_len++;
+
+               /* return if token too long */
+               if (token_len >= STR_TOKEN_SIZE - 1) {
+                       return -1;
+               }
+       }
+       
+       /* we are sure that token_len is < STR_TOKEN_SIZE-1 */
+       strncpy(res, buf, token_len);
+       *((char *)res + token_len) = 0;
+
+       return token_len;
+}


=========================================
aversive/modules/ihm/parse/parse_string.h  (1.1.2.1)
=========================================

@@ -0,0 +1,28 @@
+#ifndef _PARSE_STRING_H_
+#define _PARSE_STRING_H_
+
+#include "parse.h"
+
+#define STR_TOKEN_SIZE 32
+
+typedef char fixed_string_t[STR_TOKEN_SIZE];
+
+struct token_string {
+       struct token_hdr hdr;
+       const char * str;
+};
+
+int8_t parse_string(void * token_ptr, char * srcbuf, void * res);
+
+#define TOKEN_STRING_INITIALIZER(structure, field, string)   \
+{                                                           \
+       {                                                    \
+               .parse = parse_string,                       \
+               .complete = NULL,                            \
+               .help_str = NULL,                            \
+               .offset = offsetof(structure, field),        \
+       },                                                   \
+       .str = string,                                       \
+}
+
+#endif /* _PARSE_STRING_H_ */


========================================
aversive/modules/ihm/parse/test/Makefile  (1.1.2.1)
========================================

@@ -0,0 +1,21 @@
+TARGET = main
+
+# repertoire des modules
+AVERSIVE_DIR = ../../../..
+
+# List C source files here. (C dependencies are automatically generated.)
+SRC = $(TARGET).c
+
+# List Assembler source files here.
+# Make them always end in a capital .S.  Files ending in a lowercase .s
+# will not be considered source files but generated files (assembler
+# output from the compiler), and will be deleted upon "make clean"!
+# Even though the DOS/Win* filesystem matches both .s and .S the same,
+# it will preserve the spelling of the filenames, and gcc itself does
+# care about how the name is spelled on its command-line.
+ASRC = 
+
+########################################
+
+-include .aversive_conf
+include $(AVERSIVE_DIR)/mk/aversive_project.mk


==============================================
aversive/modules/ihm/parse/test/error_config.h  (1.1.2.1)
==============================================

@@ -0,0 +1,31 @@
+/*  
+ *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
+ * 
+ *  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
+ *
+ *  Revision : $Id: error_config.h,v 1.1.2.1 2007-09-17 20:53:28 zer0 Exp $
+ *
+ */
+
+#ifndef _ERROR_CONFIG_
+#define _ERROR_CONFIG_
+
+/** enable the dump of the comment */
+#define ERROR_DUMP_TEXTLOG 
+
+/** enable the dump of filename and line number */
+#define ERROR_DUMP_FILE_LINE
+
+#endif


======================================
aversive/modules/ihm/parse/test/main.c  (1.1.2.1)
======================================

@@ -0,0 +1,254 @@
+/*  
+ *  Copyright Droids Corporation (2007)
+ *  Olivier MATZ <[EMAIL PROTECTED]>
+ * 
+ *  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
+ *
+ *  Revision : $Id: main.c,v 1.1.2.1 2007-09-17 20:53:28 zer0 Exp $
+ *
+ *
+ */
+
+/* test program for rdline, works on AVR and HOST... but there are a
+ * lot of defines... ;) */
+
+#include <stdio.h>
+#include <string.h>
+
+//#define DEBUG_SOCKET
+
+
+#ifdef HOST_VERSION
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <inttypes.h>
+#include <termios.h>
+#include <ctype.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#endif
+
+#include <aversive/wait.h>
+#include <uart.h>
+#include "rdline.h"
+
+/* globals */
+struct rdline rdl;
+char prompt[RDLINE_PROMPT_SIZE];
+int cpt=0;
+
+
+#ifdef DEBUG_SOCKET /* debug... keep it because it is nice */
+
+int s = -1;
+
+void sock_printf(const char * fmt, ...)
+{
+       va_list ap;
+       char buf[BUFSIZ];
+       int n;
+
+       va_start(ap, fmt);
+       n=vsnprintf(buf, BUFSIZ, fmt, ap);
+       if (s>0) write(s, buf, n);
+       va_end(ap);
+}
+
+void dump_it(struct cirbuf * cbuf)
+{
+       int i;
+       char e;
+
+       sock_printf("sta=%2.2d end=%2.2d len=%2.2d/%2.2d { ", 
+                cbuf->start, cbuf->end,
+                CIRBUF_GET_LEN(cbuf),
+                CIRBUF_GET_MAXLEN(cbuf));
+
+       sock_printf("[ ");
+       CIRBUF_FOREACH(cbuf, i, e) {
+               sock_printf("%2.2x, ", e&0xFF);
+       }
+       sock_printf("]\n");
+}
+
+#else
+
+void sock_printf(const char * fmt, ...) {}
+void dump_it(struct cirbuf * cbuf) {}
+
+#endif /* DEBUG_SOCKET */
+
+
+#ifdef HOST_VERSION
+void
+write_char(char c) {
+       write(1, &c, 1);
+}
+#else
+void
+write_char(char c) {
+       uart0_send(c);
+}
+
+static void
+rx(char c)
+{
+       int8_t ret;
+       ret = rdline_char_in(&rdl, c);
+       if (ret == 1) {
+               rdline_add_history(&rdl, rdline_get_buffer(&rdl));
+               snprintf(prompt, sizeof(prompt), "toto[%d] > ", cpt++);
+               rdline_newline(&rdl, prompt);
+       }
+       else if (ret == -2) {
+               rdline_stop(&rdl);
+               printf("END\n");
+       }
+}
+
+#endif
+
+
+void display_buffer(const char * buf, uint8_t size) 
+{
+       printf("**** GOT  (%d) >> %s", size, buf);
+}
+
+const char * dummy_complete[] = {
+       "toto",
+       "titi",
+       "pouet",
+       "coin",
+};
+
+#define TEST_COMPLETION 1
+//#define TEST_COMPLETION 2
+int8_t complete_buffer(const char * buf, uint8_t size, 
+                    char * dstbuf, uint8_t dstsize,
+                    int * state)
+{
+       sock_printf("complete -> %d\n", *state);
+#if TEST_COMPLETION == 1
+       if (*state < (sizeof(dummy_complete)/sizeof(const char *))) {
+               /* pourri mais bon c'est temporaire */
+               strcpy(dstbuf, dummy_complete[*state]);
+               (*state) ++;
+               return 1;
+       }
+       return 0;
+#else
+       dstbuf[0] = 'x';
+       dstbuf[1] = 'y';
+       dstbuf[2] = 'z';
+       dstbuf[3] = '\0';
+       return 2;
+#endif
+}
+
+
+
+int main(void)
+{
+#ifdef HOST_VERSION
+       struct termios oldterm, term;
+       char buf[BUFSIZ];
+       int n, i;
+       int8_t ret;
+#endif
+#ifdef DEBUG_SOCKET
+       struct sockaddr_in sin_ci;
+
+
+       s = socket(PF_INET, SOCK_STREAM, 0);
+       if (s < 0) {
+               printf("socket() failed\n");
+       }
+
+       memset(&sin_ci, 0, sizeof(sin_ci));
+       sin_ci.sin_family = AF_INET;
+       sin_ci.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+       sin_ci.sin_port = htons(31337);
+#ifndef __linux__
+       sin_ci.sin_len = sizeof(sin_ci);
+#endif
+
+       if (s > 0 && connect(s, (struct sockaddr *)&sin_ci, sizeof(sin_ci)) < 
0) {
+               printf("connect() failed\n");
+               s = -1;
+       }
+#endif /* DEBUG_SOCKET */
+
+#ifdef HOST_VERSION
+       tcgetattr(0, &oldterm);
+       memcpy(&term, &oldterm, sizeof(term));
+       term.c_lflag &= ~(ICANON | ECHO | ISIG);
+       tcsetattr(0, TCSANOW, &term);
+       setbuf(stdin, NULL);
+#else
+       uart_init();
+       fdevopen(uart0_dev_send, uart0_dev_recv);
+
+       wait_ms(5000);
+       printf("Start\n");
+       uart0_register_rx_event(rx);
+       
+       sei();
+#endif
+
+
+       /* common init */
+       rdline_init(&rdl, write_char, display_buffer, complete_buffer);
+       snprintf(prompt, sizeof(prompt), "toto[%d] > ", cpt++); 
+       rdline_newline(&rdl, prompt);
+
+
+       /* loop to send chars on host */
+#ifdef HOST_VERSION
+       while ((n=read(0, buf, BUFSIZ-1)) > 0) {
+               buf[n] = 0;
+
+               for (i=0 ; i<n ; i++) {
+                       sock_printf("%o ", buf[i]&0xff);
+               }
+               sock_printf(" RECV\n");
+               for (i=0 ; i<n ; i++) {
+                       ret = rdline_char_in(&rdl, buf[i]);
+                       if (ret == 1) {
+                               rdline_add_history(&rdl, 
rdline_get_buffer(&rdl));
+                               snprintf(prompt, sizeof(prompt), "toto[%d] > ", 
cpt++);
+                               rdline_newline(&rdl, prompt);
+                       }
+                       else if (ret == -2) {
+                               tcsetattr(0, TCSANOW, &oldterm);
+                               printf("\n");
+                               return 0;
+                       }
+               }
+       }
+
+       tcsetattr(0, TCSANOW, &oldterm);
+       printf("\n");
+
+       /* irq driven on avr, see rx() */
+#else
+       while(1);
+#endif
+
+       return 0;
+}


=============================================
aversive/modules/ihm/parse/test/uart_config.h  (1.1.2.1)
=============================================

@@ -0,0 +1,72 @@
+/*  
+ *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
+ * 
+ *  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
+ *
+ *  Revision : $Id: uart_config.h,v 1.1.2.1 2007-09-17 20:53:28 zer0 Exp $
+ *
+ */
+
+/* Droids-corp 2004 - Zer0
+ * config for uart module
+ */
+
+#ifndef UART_CONFIG_H
+#define UART_CONFIG_H
+
+/*
+ * UART0 definitions 
+ */
+
+/* compile uart0 fonctions, undefine it to pass compilation */
+#define UART0_COMPILE  
+
+/* enable uart0 if == 1, disable if == 0 */
+#define UART0_ENABLED  1
+
+/* enable uart0 interrupts if == 1, disable if == 0 */
+#define UART0_INTERRUPT_ENABLED  1
+
+#define UART0_BAUDRATE 57600
+
+/* 
+ * if you enable this, the maximum baudrate you can reach is 
+ * higher, but the precision is lower. 
+ */
+#define UART0_USE_DOUBLE_SPEED 0
+//#define UART0_USE_DOUBLE_SPEED 1
+
+#define UART0_RX_FIFO_SIZE 4
+#define UART0_TX_FIFO_SIZE 16
+//#define UART0_NBITS 5
+//#define UART0_NBITS 6
+//#define UART0_NBITS 7
+#define UART0_NBITS 8
+//#define UART0_NBITS 9
+
+#define UART0_PARITY UART_PARTITY_NONE
+//#define UART0_PARITY UART_PARTITY_ODD
+//#define UART0_PARITY UART_PARTITY_EVEN
+
+#define UART0_STOP_BIT UART_STOP_BITS_1
+//#define UART0_STOP_BIT UART_STOP_BITS_2
+
+
+
+
+/* .... same for uart 1, 2, 3 ... */
+
+#endif
+


==================================
aversive/projects/example1/.config  (1.5.4.3 -> 1.5.4.4)
==================================

@@ -1,5 +1,5 @@
 #
-# Automatically generated make config: don't edit
+# Automatically generated by make menuconfig: don't edit
 #
 
 #
@@ -70,26 +70,19 @@
 #
 # Base modules
 #
-
-#
-# Enable math library in generation options to see all modules
-#
 CONFIG_MODULE_CIRBUF=y
-# CONFIG_MODULE_FIXED_POINT is not set
-# CONFIG_MODULE_VECT2 is not set
-# CONFIG_MODULE_SCHEDULER is not set
-# CONFIG_MODULE_SCHEDULER_CREATE_CONFIG is not set
+# CONFIG_MODULE_CIRBUF_LARGE is not set
+CONFIG_MODULE_FIXED_POINT=y
+CONFIG_MODULE_VECT2=y
+CONFIG_MODULE_SCHEDULER=y
+CONFIG_MODULE_SCHEDULER_CREATE_CONFIG=y
 # CONFIG_MODULE_SCHEDULER_USE_TIMERS is not set
-# CONFIG_MODULE_TIME is not set
-# CONFIG_MODULE_TIME_CREATE_CONFIG is not set
+CONFIG_MODULE_TIME=y
+CONFIG_MODULE_TIME_CREATE_CONFIG=y
 
 #
 # Communication modules
 #
-
-#
-# uart needs circular buffer, mf2 client may need scheduler
-#
 CONFIG_MODULE_UART=y
 CONFIG_MODULE_UART_CREATE_CONFIG=y
 # CONFIG_MODULE_I2C is not set
@@ -117,6 +110,10 @@
 # IHM modules
 #
 # CONFIG_MODULE_MENU is not set
+# CONFIG_MODULE_RDLINE is not set
+# CONFIG_MODULE_RDLINE_CREATE_CONFIG is not set
+# CONFIG_MODULE_RDLINE_KILL_BUF is not set
+# CONFIG_MODULE_RDLINE_HISTORY is not set
 
 #
 # External devices modules
@@ -145,55 +142,39 @@
 #
 # Robot specific modules
 #
-# CONFIG_MODULE_ROBOT_SYSTEM is not set
-# CONFIG_MODULE_POSITION_MANAGER is not set
-# CONFIG_MODULE_TRAJECTORY_MANAGER is not set
+CONFIG_MODULE_ROBOT_SYSTEM=y
+CONFIG_MODULE_POSITION_MANAGER=y
+CONFIG_MODULE_TRAJECTORY_MANAGER=y
 
 #
 # Control system modules
 #
 CONFIG_MODULE_CONTROL_SYSTEM_MANAGER=y
-
-#
-# Filters
-#
 # CONFIG_MODULE_PID is not set
 # CONFIG_MODULE_RAMP is not set
 # CONFIG_MODULE_QUADRAMP is not set
-# CONFIG_MODULE_QUADRAMP_DERIVATE is not set
-# CONFIG_MODULE_BIQUAD is not set
+CONFIG_MODULE_QUADRAMP_DERIVATE=y
+CONFIG_MODULE_BIQUAD=y
 
 #
 # Crypto modules
 #
-
-#
-# Crypto modules depend on utils module
-#
-# CONFIG_MODULE_AES is not set
-# CONFIG_MODULE_AES_CTR is not set
-# CONFIG_MODULE_MD5 is not set
-# CONFIG_MODULE_MD5_HMAC is not set
-# CONFIG_MODULE_RC4 is not set
+CONFIG_MODULE_AES=y
+CONFIG_MODULE_AES_CTR=y
+CONFIG_MODULE_MD5=y
+CONFIG_MODULE_MD5_HMAC=y
+CONFIG_MODULE_RC4=y
 
 #
 # Encodings modules
 #
-
-#
-# Encoding modules depend on utils module
-#
 # CONFIG_MODULE_BASE64 is not set
 # CONFIG_MODULE_HAMMING is not set
 
 #
 # Debug modules
 #
-
-#
-# Debug modules depend on utils module
-#
-# CONFIG_MODULE_DIAGNOSTIC is not set
+CONFIG_MODULE_DIAGNOSTIC=y
 # CONFIG_MODULE_DIAGNOSTIC_CREATE_CONFIG is not set
 CONFIG_MODULE_ERROR=y
 CONFIG_MODULE_ERROR_CREATE_CONFIG=y


Commit from zer0 (2007-09-17 22:53 CEST)
================

Add parse module

  aversive_projects  microb2008/main/.config  1.5
  aversive_projects  microb2008/main/main.c   1.6


=========================================
aversive_projects/microb2008/main/.config  (1.4 -> 1.5)
=========================================

@@ -75,6 +75,7 @@
 # Enable math library in generation options to see all modules
 #
 CONFIG_MODULE_CIRBUF=y
+# CONFIG_MODULE_CIRBUF_LARGE is not set
 CONFIG_MODULE_FIXED_POINT=y
 CONFIG_MODULE_VECT2=y
 CONFIG_MODULE_SCHEDULER=y
@@ -117,6 +118,10 @@
 # IHM modules
 #
 CONFIG_MODULE_MENU=y
+# CONFIG_MODULE_RDLINE is not set
+# CONFIG_MODULE_RDLINE_CREATE_CONFIG is not set
+# CONFIG_MODULE_RDLINE_KILL_BUF is not set
+# CONFIG_MODULE_RDLINE_HISTORY is not set
 
 #
 # External devices modules


========================================
aversive_projects/microb2008/main/main.c  (1.5 -> 1.6)
========================================

@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- *  Revision : $Id: main.c,v 1.5 2007-08-21 21:51:34 zer0 Exp $
+ *  Revision : $Id: main.c,v 1.6 2007-09-17 20:53:28 zer0 Exp $
  *
  */
 
@@ -367,15 +367,15 @@
        /* TIME */
        time_init(TIME_PRIO);
 
-       scheduler_add_periodical_event_priority(sensor_update, NULL, 
-                                               50000L / SCHEDULER_UNIT, 
SENSORS_PRIO);
-
        /* CAM */
        cam_init();
 
        action_init();
        sensor_init();
 
+       scheduler_add_periodical_event_priority(sensor_update, NULL, 
+                                               50000L / SCHEDULER_UNIT, 
SENSORS_PRIO);
+
        sei();
 
        wait_ms(100);

_______________________________________________
Avr-list mailing list
Avr-list@droids-corp.org
CVSWEB : http://cvsweb.droids-corp.org/cgi-bin/viewcvs.cgi/aversive
WIKI : http://wiki.droids-corp.org/index.php/Aversive
DOXYGEN : http://zer0.droids-corp.org/doxygen_aversive/html/
BUGZILLA : http://bugzilla.droids-corp.org
COMMIT LOGS : http://zer0.droids-corp.org/aversive_commitlog

Répondre à