Commit from zer0 on branch b_zer0 (2007-11-24 20:27 CET) =================================
All is in progmem Next step is to make it working back on x86 aversive modules/ihm/parse/parse.c 1.1.2.8 aversive modules/ihm/parse/parse.h 1.1.2.8 aversive modules/ihm/parse/parse_num.c 1.1.2.7 aversive modules/ihm/parse/parse_num.h 1.1.2.5 aversive modules/ihm/parse/parse_string.c 1.1.2.6 aversive modules/ihm/parse/parse_string.h 1.1.2.7 ================================== aversive/modules/ihm/parse/parse.c (1.1.2.7 -> 1.1.2.8) ================================== @@ -16,7 +16,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: parse.c,v 1.1.2.7 2007-11-22 21:40:17 zer0 Exp $ + * Revision : $Id: parse.c,v 1.1.2.8 2007-11-24 19:27:22 zer0 Exp $ * * */ @@ -83,14 +83,16 @@ void * result_buf) { uint8_t token_num=0; - struct token_hdr * token; + parse_pgm_token_hdr_t * token_p; uint8_t i=0; int8_t n = 0; + struct token_hdr token_hdr; - token = (struct token_hdr *)pgm_read_word(&inst->tokens[token_num]); + token_p = (parse_pgm_token_hdr_t *)pgm_read_word(&inst->tokens[token_num]); + memcpy_P(&token_hdr, token_p, sizeof(token_hdr)); /* check if we match all tokens of inst */ - while (token && (!nb_match_token || i<nb_match_token)) { + while (token_p && (!nb_match_token || i<nb_match_token)) { debug_printf("TK\n"); /* skip spaces */ while (isblank(*buf)) { @@ -101,7 +103,7 @@ if ( isendofline(*buf) || iscomment(*buf) ) break; - n = token->ops->parse(token, buf, (result_buf ? result_buf+token->offset : NULL)); + n = token_hdr.ops->parse(token_p, buf, (result_buf ? result_buf+token_hdr.offset : NULL)); if ( n < 0 ) break; debug_printf("TK parsed (len=%d)\n", n); @@ -109,7 +111,8 @@ buf += n; token_num ++; - token = (struct token_hdr *)pgm_read_word(&inst->tokens[token_num]); + token_p = (parse_pgm_token_hdr_t *)pgm_read_word(&inst->tokens[token_num]); + memcpy_P(&token_hdr, token_p, sizeof(token_hdr)); } /* does not match */ @@ -125,7 +128,7 @@ } /* we don't match all the tokens */ - if (token) { + if (token_p) { return i; } @@ -257,7 +260,8 @@ const char * incomplete_token = buf; uint8_t inst_num = 0; struct inst * inst; - struct token_hdr * token; + parse_pgm_token_hdr_t * token_p; + struct token_hdr token_hdr; char tmpbuf[64], completion_buf[64]; uint8_t incomplete_token_len; int8_t completion_len = -1; @@ -294,20 +298,21 @@ goto next; debug_printf("instruction match \n"); - token = (struct token_hdr *) pgm_read_word(&inst->tokens[nb_token]); + token_p = (parse_pgm_token_hdr_t *) pgm_read_word(&inst->tokens[nb_token]); + memcpy_P(&token_hdr, token_p, sizeof(token_hdr)); /* non completable */ - if (!token || - !token->ops->complete_get_nb || - !token->ops->complete_get_elt || - (n = token->ops->complete_get_nb(token)) == 0) { + if (!token_p || + !token_hdr.ops->complete_get_nb || + !token_hdr.ops->complete_get_elt || + (n = token_hdr.ops->complete_get_nb(token_p)) == 0) { nb_non_completable++; goto next; } debug_printf("%d choices for this token\n", n); for (i=0 ; i<n ; i++) { - if (token->ops->complete_get_elt(token, i, tmpbuf, sizeof(tmpbuf)-1) < 0) + if (token_hdr.ops->complete_get_elt(token_p, i, tmpbuf, sizeof(tmpbuf)-1) < 0) continue; strcat_P(tmpbuf, PSTR(" ")); /* we have at least room for one char */ debug_printf(" choice <%s>\n", tmpbuf); @@ -366,20 +371,21 @@ if (nb_token && match_inst(inst, buf, nb_token, NULL)) goto next2; - token = (struct token_hdr *)pgm_read_word(&inst->tokens[nb_token]); + token_p = (parse_pgm_token_hdr_t *)pgm_read_word(&inst->tokens[nb_token]); + memcpy_P(&token_hdr, token_p, sizeof(token_hdr)); /* one choice for this token */ - if (!token || - !token->ops->complete_get_nb || - !token->ops->complete_get_elt || - (n = token->ops->complete_get_nb(token)) == 0) { + if (!token_p || + !token_hdr.ops->complete_get_nb || + !token_hdr.ops->complete_get_elt || + (n = token_hdr.ops->complete_get_nb(token_p)) == 0) { if (local_state < *state) { local_state++; goto next2; } (*state)++; - if (token && token->ops->get_help) { - token->ops->get_help(token, tmpbuf, sizeof(tmpbuf)); + if (token_p && token_hdr.ops->get_help) { + token_hdr.ops->get_help(token_p, tmpbuf, sizeof(tmpbuf)); help_str = (prog_char *) pgm_read_word(&inst->help_str); if (help_str) snprintf_P(dst, size, PSTR("[%s]: %S"), tmpbuf, help_str); @@ -394,7 +400,7 @@ /* several choices */ for (i=0 ; i<n ; i++) { - if (token->ops->complete_get_elt(token, i, tmpbuf, sizeof(tmpbuf)-1) < 0) + if (token_hdr.ops->complete_get_elt(token_p, i, tmpbuf, sizeof(tmpbuf)-1) < 0) continue; strcat_P(tmpbuf, PSTR(" ")); /* we have at least room for one char */ debug_printf(" choice <%s>\n", tmpbuf); @@ -406,8 +412,8 @@ } (*state)++; l=snprintf(dst, size, "%s", tmpbuf); - if (l>=0 && token->ops->get_help) { - token->ops->get_help(token, tmpbuf, sizeof(tmpbuf)); + if (l>=0 && token_hdr.ops->get_help) { + token_hdr.ops->get_help(token_p, tmpbuf, sizeof(tmpbuf)); help_str = (prog_char *) pgm_read_word(&inst->help_str); if (help_str) snprintf_P(dst+l, size-l, PSTR("[%s]: %S"), tmpbuf, help_str); ================================== aversive/modules/ihm/parse/parse.h (1.1.2.7 -> 1.1.2.8) ================================== @@ -16,7 +16,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: parse.h,v 1.1.2.7 2007-11-22 21:40:17 zer0 Exp $ + * Revision : $Id: parse.h,v 1.1.2.8 2007-11-24 19:27:22 zer0 Exp $ * * */ @@ -37,6 +37,17 @@ #define PARSE_BAD_ARGS -3 /** + * Stores a pointer to the ops struct, and the offset: the place to + * write the parsed result in the destination structure. + */ +struct token_hdr { + struct token_ops *ops; + uint8_t offset; +}; +typedef struct token_hdr parse_token_hdr_t; +typedef PROGMEM parse_token_hdr_t parse_pgm_token_hdr_t; + +/** * A token is defined by this structure. * * parse() takes the token as first argument, then the source buffer @@ -57,25 +68,16 @@ */ struct token_ops { /** parse(token ptr, buf, res pts) */ - int8_t (*parse)(void *, const char *, void *); + int8_t (*parse)(parse_pgm_token_hdr_t *, const char *, void *); /** return the num of possible choices for this token */ - int8_t (*complete_get_nb)(void *); + int8_t (*complete_get_nb)(parse_pgm_token_hdr_t *); /** return the elt x for this token (token, idx, dstbuf, size) */ - int8_t (*complete_get_elt)(void *, int8_t, char *, uint8_t); + int8_t (*complete_get_elt)(parse_pgm_token_hdr_t *, int8_t, char *, uint8_t); /** get help for this token (token, dstbuf, size) */ - int8_t (*get_help)(void *, char *, uint8_t); + int8_t (*get_help)(parse_pgm_token_hdr_t *, char *, uint8_t); }; /** - * Stores a pointer to the ops struct, and the offset: the place to - * write the parsed result in the destination structure. - */ -struct token_hdr { - struct token_ops *ops; - uint8_t offset; -}; - -/** * Store a instruction, which is a pointer to a callback function and * its parameter that is called when the instruction is parsed, a help * string, and a list of token composing this instruction. @@ -85,7 +87,7 @@ void (*f)(void *, void *); void * data; char * help_str; - void * tokens[]; + prog_void * tokens[]; }; typedef struct inst parse_inst_t; typedef PROGMEM parse_inst_t parse_pgm_inst_t; ====================================== aversive/modules/ihm/parse/parse_num.c (1.1.2.6 -> 1.1.2.7) ====================================== @@ -81,14 +81,15 @@ /* parse an int or a float */ int8_t -parse_num(void * data, const char * srcbuf, void * res) +parse_num(parse_pgm_token_hdr_t * tk, const char * srcbuf, void * res) { - struct token_num * token = data; + struct token_num_data nd; enum num_parse_state_t st = START; const char * buf = srcbuf; char c = *buf; uint32_t res1=0, res2=0, res3=1; - enum numtype type = token->type; + + memcpy_P(&nd, &((struct token_num *)tk)->num_data, sizeof(nd)); while ( st != ERROR && c && ! isendoftoken(c) ) { debug_printf("%c %x -> ", c, c); @@ -296,37 +297,37 @@ case HEX_OK: case OCTAL_OK: case BIN_OK: - if ( type == INT8 && res1 <= S08_MAX ) { + if ( nd.type == INT8 && res1 <= S08_MAX ) { if (res) *(int8_t *)res = (int8_t) res1; return (buf-srcbuf); } - else if ( type == INT16 && res1 <= S16_MAX ) { + else if ( nd.type == INT16 && res1 <= S16_MAX ) { if (res) *(int16_t *)res = (int16_t) res1; return (buf-srcbuf); } - else if ( type == INT32 && res1 <= S32_MAX ) { + else if ( nd.type == INT32 && res1 <= S32_MAX ) { if (res) *(int32_t *)res = (int32_t) res1; return (buf-srcbuf); } - else if ( type == UINT8 && res1 <= U08_MAX ) { + else if ( nd.type == UINT8 && res1 <= U08_MAX ) { if (res) *(uint8_t *)res = (uint8_t) res1; return (buf-srcbuf); } - else if (type == UINT16 && res1 <= U16_MAX ) { + else if (nd.type == UINT16 && res1 <= U16_MAX ) { if (res) *(uint16_t *)res = (uint16_t) res1; return (buf-srcbuf); } - else if ( type == UINT32 ) { + else if ( nd.type == UINT32 ) { if (res) *(uint32_t *)res = (uint32_t) res1; return (buf-srcbuf); } - else if ( type == FLOAT ) { + else if ( nd.type == FLOAT ) { if (res) *(float *)res = (float)res1; return (buf-srcbuf); @@ -337,22 +338,22 @@ break; case DEC_NEG_OK: - if ( type == INT8 && res1 <= S08_MAX + 1 ) { + if ( nd.type == INT8 && res1 <= S08_MAX + 1 ) { if (res) *(int8_t *)res = - (int8_t) res1; return (buf-srcbuf); } - else if ( type == INT16 && res1 <= (uint16_t)S16_MAX + 1 ) { + else if ( nd.type == INT16 && res1 <= (uint16_t)S16_MAX + 1 ) { if (res) *(int16_t *)res = - (int16_t) res1; return (buf-srcbuf); } - else if ( type == INT32 && res1 <= (uint32_t)S32_MAX + 1 ) { + else if ( nd.type == INT32 && res1 <= (uint32_t)S32_MAX + 1 ) { if (res) *(int32_t *)res = - (int32_t) res1; return (buf-srcbuf); } - else if ( type == FLOAT ) { + else if ( nd.type == FLOAT ) { if (res) *(float *)res = - (float)res1; return (buf-srcbuf); @@ -364,7 +365,7 @@ case FLOAT_POS: case FLOAT_POS_OK: - if ( type == FLOAT ) { + if ( nd.type == FLOAT ) { if (res) *(float *)res = (float)res1 + ((float)res2 / (float)res3); return (buf-srcbuf); @@ -377,7 +378,7 @@ case FLOAT_NEG: case FLOAT_NEG_OK: - if ( type == FLOAT ) { + if ( nd.type == FLOAT ) { if (res) *(float *)res = - ((float)res1 + ((float)res2 / (float)res3)); return (buf-srcbuf); @@ -398,16 +399,17 @@ /* parse an int or a float */ int8_t -get_help_num(void * data, char * dstbuf, uint8_t size) +get_help_num(parse_pgm_token_hdr_t * tk, char * dstbuf, uint8_t size) { - struct token_num * token = data; - uint8_t type = (int)token->type; + struct token_num_data nd; + + memcpy_P(&nd, &((struct token_num *)tk)->num_data, sizeof(nd)); /* should not happen.... don't so this test */ -/* if (type >= (sizeof(num_help)/sizeof(const char *))) */ +/* if (nd.type >= (sizeof(num_help)/sizeof(const char *))) */ /* return -1; */ - strncpy_P(dstbuf, num_help[type], size); + strncpy_P(dstbuf, num_help[nd.type], size); dstbuf[size-1] = '\0'; return 0; } ====================================== aversive/modules/ihm/parse/parse_num.h (1.1.2.4 -> 1.1.2.5) ====================================== @@ -13,15 +13,23 @@ FLOAT, }; +struct token_num_data { + enum numtype type; +}; + struct token_num { struct token_hdr hdr; - enum numtype type; + struct token_num_data num_data; }; +typedef struct token_num parse_token_num_t; +typedef PROGMEM parse_token_num_t parse_pgm_token_num_t; extern struct token_ops token_num_ops; -int8_t parse_num(void * token_ptr, const char * srcbuf, void * res); -int8_t get_help_num(void * data, char * dstbuf, uint8_t size); +int8_t parse_num(parse_pgm_token_hdr_t * tk, + const char * srcbuf, void * res); +int8_t get_help_num(parse_pgm_token_hdr_t * tk, + char * dstbuf, uint8_t size); #define TOKEN_NUM_INITIALIZER(structure, field, numtype) \ { \ @@ -29,7 +37,9 @@ .ops = &token_num_ops, \ .offset = offsetof(structure, field), \ }, \ - .type = numtype, \ -}; + .num_data = { \ + .type = numtype, \ + }, \ +} #endif /* _PARSE_NUM_H_ */ ========================================= aversive/modules/ihm/parse/parse_string.c (1.1.2.5 -> 1.1.2.6) ========================================= @@ -42,18 +42,20 @@ } int8_t -parse_string(void * data, const char * buf, void * res) +parse_string(parse_pgm_token_hdr_t * tk, const char * buf, void * res) { - struct token_string * token = data; + struct token_string_data sd; uint8_t token_len; const prog_char * str; if (! *buf) return -1; + memcpy_P(&sd, &((struct token_string *)tk)->string_data, sizeof(sd)); + /* fixed string */ - if (token->str) { - str = token->str; + if (sd.str) { + str = sd.str; do { token_len = get_token_len(str); @@ -98,28 +100,32 @@ return token_len; } -int8_t complete_get_nb_string(void * data) +int8_t complete_get_nb_string(parse_pgm_token_hdr_t * tk) { - struct token_string * token = data; - const prog_char * str = token->str; + struct token_string_data sd; int8_t ret=1; - if (!str) + memcpy_P(&sd, &((struct token_string *)tk)->string_data, sizeof(sd)); + + if (!sd.str) return 0; - while( (str = get_next_token(str)) != NULL ) { + while( (sd.str = get_next_token(sd.str)) != NULL ) { ret++; } return ret; } -int8_t complete_get_elt_string(void * data, int8_t idx, +int8_t complete_get_elt_string(parse_pgm_token_hdr_t * tk, int8_t idx, char * dstbuf, uint8_t size) { - struct token_string * token = data; - const prog_char * s = token->str; + struct token_string_data sd; + const prog_char * s; uint8_t len; + memcpy_P(&sd, &((struct token_string *)tk)->string_data, sizeof(sd)); + s = sd.str; + while (idx-- && s) s = get_next_token(s); @@ -137,11 +143,14 @@ } -int8_t get_help_string(void * data, char * dstbuf, uint8_t size) +int8_t get_help_string(parse_pgm_token_hdr_t * tk, char * dstbuf, uint8_t size) { - struct token_string * token = data; - const prog_char * s = token->str; + struct token_string_data sd; + const prog_char * s; + memcpy_P(&sd, &((struct token_string *)tk)->string_data, sizeof(sd)); + s = sd.str; + if (s) { if (get_next_token(s)) { strncpy_P(dstbuf, MULTISTRING_HELP, size); ========================================= aversive/modules/ihm/parse/parse_string.h (1.1.2.6 -> 1.1.2.7) ========================================= @@ -8,18 +8,24 @@ typedef char fixed_string_t[STR_TOKEN_SIZE]; +struct token_string_data { + const prog_char * str; +}; + struct token_string { struct token_hdr hdr; - prog_char * str; + struct token_string_data string_data; }; +typedef struct token_string parse_token_string_t; +typedef PROGMEM parse_token_string_t parse_pgm_token_string_t; extern struct token_ops token_string_ops; -int8_t parse_string(void * token_ptr, const char * srcbuf, void * res); -int8_t complete_get_nb_string(void * token_ptr); -int8_t complete_get_elt_string(void * token_ptr, int8_t idx, +int8_t parse_string(parse_pgm_token_hdr_t * tk, const char * srcbuf, void * res); +int8_t complete_get_nb_string(parse_pgm_token_hdr_t * tk); +int8_t complete_get_elt_string(parse_pgm_token_hdr_t * tk, int8_t idx, char * dstbuf, uint8_t size); -int8_t get_help_string(void * data, char * dstbuf, uint8_t size); +int8_t get_help_string(parse_pgm_token_hdr_t * tk, char * dstbuf, uint8_t size); #define TOKEN_STRING_INITIALIZER(structure, field, string) \ { \ @@ -27,7 +33,9 @@ .ops = &token_string_ops, \ .offset = offsetof(structure, field), \ }, \ - .str = string, \ + .string_data = { \ + .str = string, \ + }, \ } #endif /* _PARSE_STRING_H_ */ Commit from zer0 on branch b_zer0 (2007-11-24 22:53 CET) ================================= add cast aversive modules/base/math/vect2/test/.config 1.6.4.7 aversive modules/base/scheduler/test/.config 1.5.4.10 ============================================= aversive/modules/base/math/vect2/test/.config (1.6.4.6 -> 1.6.4.7) ============================================= @@ -75,6 +75,7 @@ # Enable math library in generation options to see all modules # # CONFIG_MODULE_CIRBUF is not set +# CONFIG_MODULE_CIRBUF_LARGE is not set # CONFIG_MODULE_FIXED_POINT is not set CONFIG_MODULE_VECT2=y # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ============================================ aversive/modules/base/scheduler/test/.config (1.5.4.9 -> 1.5.4.10) ============================================ @@ -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 is not set # CONFIG_MODULE_VECT2 is not set CONFIG_MODULE_SCHEDULER=y @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules Commit from zer0 on branch b_zer0 (2007-11-24 23:12 CET) ================================= fix confs aversive modules/base/scheduler/test/.config 1.5.4.11 aversive modules/comm/uart/test/.config 1.13.4.7 aversive modules/crypto/test/.config 1.2.4.7 aversive modules/debug/diagnostic/test/.config 1.11.4.7 aversive modules/debug/error/test/.config 1.8.4.7 aversive modules/devices/control_system/control_system_manager/test/.config 1.7.4.7 aversive modules/devices/control_system/filters/pid/test/.config 1.7.4.7 aversive modules/devices/control_system/filters/quadramp/test/.config 1.7.4.7 aversive modules/devices/control_system/filters/quadramp_derivate/quadramp_derivate.c 1.2.2.4 aversive modules/devices/ihm/lcd/test/.config 1.7.4.7 aversive modules/devices/robot/robot_system/test/.config 1.6.4.7 aversive modules/devices/servo/multiservo/test/.config 1.6.4.7 aversive modules/encoding/base64/test/.config 1.2.4.6 aversive modules/encoding/hamming/test/.config 1.2.4.7 aversive modules/hardware/adc/test/.config 1.4.4.6 aversive modules/hardware/pwm/test/.config 1.4.4.6 aversive modules/hardware/timer/test/.config 1.1.2.6 aversive modules/ihm/menu/test/.config 1.6.4.7 aversive projects/example1/.config 1.5.4.5 aversive projects/example2/.config 1.2.2.4 ============================================ aversive/modules/base/scheduler/test/.config (1.5.4.10 -> 1.5.4.11) ============================================ @@ -1,5 +1,5 @@ # -# Automatically generated make config: don't edit +# Automatically generated by make menuconfig: don't edit # # @@ -70,10 +70,6 @@ # # Base modules # - -# -# 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 is not set @@ -87,10 +83,6 @@ # # Communication modules # - -# -# uart needs circular buffer, mf2 client may need scheduler -# CONFIG_MODULE_UART=y # CONFIG_MODULE_UART_CREATE_CONFIG is not set # CONFIG_MODULE_I2C is not set @@ -159,10 +151,6 @@ # Control system modules # # CONFIG_MODULE_CONTROL_SYSTEM_MANAGER is not set - -# -# Filters -# # CONFIG_MODULE_PID is not set # CONFIG_MODULE_RAMP is not set # CONFIG_MODULE_QUADRAMP is not set @@ -172,10 +160,6 @@ # # 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 @@ -185,20 +169,12 @@ # # 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_CREATE_CONFIG is not set CONFIG_MODULE_ERROR=y ======================================= aversive/modules/comm/uart/test/.config (1.13.4.6 -> 1.13.4.7) ======================================= @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ==================================== aversive/modules/crypto/test/.config (1.2.4.6 -> 1.2.4.7) ==================================== @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ============================================== aversive/modules/debug/diagnostic/test/.config (1.11.4.6 -> 1.11.4.7) ============================================== @@ -74,6 +74,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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -116,6 +117,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ========================================= aversive/modules/debug/error/test/.config (1.8.4.6 -> 1.8.4.7) ========================================= @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules =========================================================================== aversive/modules/devices/control_system/control_system_manager/test/.config (1.7.4.6 -> 1.7.4.7) =========================================================================== @@ -1,5 +1,5 @@ # -# Automatically generated make config: don't edit +# Automatically generated by make menuconfig: don't edit # # @@ -53,11 +53,11 @@ # # Generation options # -CONFIG_OPTM_0=y +# CONFIG_OPTM_0 is not set # CONFIG_OPTM_1 is not set # CONFIG_OPTM_2 is not set # CONFIG_OPTM_3 is not set -# CONFIG_OPTM_S is not set +CONFIG_OPTM_S=y CONFIG_MATH_LIB=y # CONFIG_FDEVOPEN_COMPAT is not set # CONFIG_MINIMAL_PRINTF is not set @@ -70,11 +70,8 @@ # # Base modules # - -# -# 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 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -86,10 +83,6 @@ # # 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,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules @@ -153,10 +151,6 @@ # Control system modules # CONFIG_MODULE_CONTROL_SYSTEM_MANAGER=y - -# -# Filters -# CONFIG_MODULE_PID=y # CONFIG_MODULE_RAMP is not set CONFIG_MODULE_QUADRAMP=y @@ -166,10 +160,6 @@ # # 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 @@ -179,20 +169,12 @@ # # 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_CREATE_CONFIG is not set # CONFIG_MODULE_ERROR is not set ================================================================ aversive/modules/devices/control_system/filters/pid/test/.config (1.7.4.6 -> 1.7.4.7) ================================================================ @@ -75,6 +75,7 @@ # Enable math library in generation options to see all modules # # CONFIG_MODULE_CIRBUF is not set +# CONFIG_MODULE_CIRBUF_LARGE is not set # CONFIG_MODULE_FIXED_POINT is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ===================================================================== aversive/modules/devices/control_system/filters/quadramp/test/.config (1.7.4.6 -> 1.7.4.7) ===================================================================== @@ -75,6 +75,7 @@ # Enable math library in generation options to see all modules # # CONFIG_MODULE_CIRBUF is not set +# CONFIG_MODULE_CIRBUF_LARGE is not set CONFIG_MODULE_FIXED_POINT=y # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ===================================================================================== aversive/modules/devices/control_system/filters/quadramp_derivate/quadramp_derivate.c (1.2.2.3 -> 1.2.2.4) ===================================================================================== @@ -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: quadramp_derivate.c,v 1.2.2.3 2007-05-23 17:18:13 zer0 Exp $ + * Revision : $Id: quadramp_derivate.c,v 1.2.2.4 2007-11-24 22:12:07 zer0 Exp $ * */ @@ -25,7 +25,7 @@ #include <quadramp_derivate.h> -inline void quadramp_derivate_init(struct quadramp_derivate_filter * q) +void quadramp_derivate_init(struct quadramp_derivate_filter * q) { uint8_t flags; IRQ_LOCK(flags); @@ -49,7 +49,7 @@ } -inline void quadramp_derivate_set_gain_anticipation(struct quadramp_derivate_filter * q, uint16_t gain_anticipation) +void quadramp_derivate_set_gain_anticipation(struct quadramp_derivate_filter * q, uint16_t gain_anticipation) { uint8_t flags; IRQ_LOCK(flags); @@ -57,7 +57,7 @@ IRQ_UNLOCK(flags); } -inline void quadramp_derivate_set_goal_window(struct quadramp_derivate_filter * q, uint32_t goal_window) +void quadramp_derivate_set_goal_window(struct quadramp_derivate_filter * q, uint32_t goal_window) { uint8_t flags; IRQ_LOCK(flags); @@ -65,7 +65,7 @@ IRQ_UNLOCK(flags); } -inline void quadramp_derivate_set_2nd_order_vars(struct quadramp_derivate_filter * q, uint32_t var_2nd_ord_pos, uint32_t var_2nd_ord_neg) +void quadramp_derivate_set_2nd_order_vars(struct quadramp_derivate_filter * q, uint32_t var_2nd_ord_pos, uint32_t var_2nd_ord_neg) { uint8_t flags; IRQ_LOCK(flags); @@ -74,7 +74,7 @@ IRQ_UNLOCK(flags); } -inline void quadramp_derivate_set_1st_order_vars(struct quadramp_derivate_filter * q, uint32_t var_1st_ord_pos, uint32_t var_1st_ord_neg) +void quadramp_derivate_set_1st_order_vars(struct quadramp_derivate_filter * q, uint32_t var_1st_ord_pos, uint32_t var_1st_ord_neg) { uint8_t flags; IRQ_LOCK(flags); @@ -84,7 +84,7 @@ } -inline void quadramp_derivate_set_divisor(struct quadramp_derivate_filter * q, uint8_t divisor) +void quadramp_derivate_set_divisor(struct quadramp_derivate_filter * q, uint8_t divisor) { uint8_t flags; IRQ_LOCK(flags); ============================================= aversive/modules/devices/ihm/lcd/test/.config (1.7.4.6 -> 1.7.4.7) ============================================= @@ -75,6 +75,7 @@ # Enable math library in generation options to see all modules # # CONFIG_MODULE_CIRBUF is not set +# CONFIG_MODULE_CIRBUF_LARGE is not set # CONFIG_MODULE_FIXED_POINT is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ======================================================== aversive/modules/devices/robot/robot_system/test/.config (1.6.4.6 -> 1.6.4.7) ======================================================== @@ -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 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ====================================================== aversive/modules/devices/servo/multiservo/test/.config (1.6.4.6 -> 1.6.4.7) ====================================================== @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ============================================= aversive/modules/encoding/base64/test/.config (1.2.4.5 -> 1.2.4.6) ============================================= @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ============================================== aversive/modules/encoding/hamming/test/.config (1.2.4.6 -> 1.2.4.7) ============================================== @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ========================================== aversive/modules/hardware/adc/test/.config (1.4.4.5 -> 1.4.4.6) ========================================== @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ========================================== aversive/modules/hardware/pwm/test/.config (1.4.4.5 -> 1.4.4.6) ========================================== @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ============================================ aversive/modules/hardware/timer/test/.config (1.1.2.5 -> 1.1.2.6) ============================================ @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ====================================== aversive/modules/ihm/menu/test/.config (1.6.4.6 -> 1.6.4.7) ====================================== @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules ================================== aversive/projects/example1/.config (1.5.4.4 -> 1.5.4.5) ================================== @@ -114,6 +114,7 @@ # CONFIG_MODULE_RDLINE_CREATE_CONFIG is not set # CONFIG_MODULE_RDLINE_KILL_BUF is not set # CONFIG_MODULE_RDLINE_HISTORY is not set +# CONFIG_MODULE_PARSE is not set # # External devices modules @@ -142,9 +143,9 @@ # # Robot specific modules # -CONFIG_MODULE_ROBOT_SYSTEM=y -CONFIG_MODULE_POSITION_MANAGER=y -CONFIG_MODULE_TRAJECTORY_MANAGER=y +# CONFIG_MODULE_ROBOT_SYSTEM is not set +# CONFIG_MODULE_POSITION_MANAGER is not set +# CONFIG_MODULE_TRAJECTORY_MANAGER is not set # # Control system modules @@ -174,7 +175,7 @@ # # Debug modules # -CONFIG_MODULE_DIAGNOSTIC=y +# CONFIG_MODULE_DIAGNOSTIC is not set # CONFIG_MODULE_DIAGNOSTIC_CREATE_CONFIG is not set CONFIG_MODULE_ERROR=y CONFIG_MODULE_ERROR_CREATE_CONFIG=y ================================== aversive/projects/example2/.config (1.2.2.3 -> 1.2.2.4) ================================== @@ -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 is not set # CONFIG_MODULE_VECT2 is not set # CONFIG_MODULE_SCHEDULER is not set @@ -117,6 +118,11 @@ # 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 +# CONFIG_MODULE_PARSE is not set # # External devices modules Commit from zer0 on branch b_zer0 (2007-11-24 23:57 CET) ================================= simple test example : a calculator aversive modules/ihm/parse/test/.config 1.1.2.5 aversive modules/ihm/parse/test/commands.c 1.1.2.3 aversive modules/ihm/parse/test/main.c 1.1.2.6 aversive modules/ihm/parse/test/uart_config.h 1.1.2.2 ======================================= aversive/modules/ihm/parse/test/.config (1.1.2.4 -> 1.1.2.5) ======================================= @@ -53,16 +53,16 @@ # # Generation options # -CONFIG_OPTM_0=y +# CONFIG_OPTM_0 is not set # CONFIG_OPTM_1 is not set # CONFIG_OPTM_2 is not set # CONFIG_OPTM_3 is not set -# CONFIG_OPTM_S is not set +CONFIG_OPTM_S=y CONFIG_MATH_LIB=y # CONFIG_FDEVOPEN_COMPAT is not set # CONFIG_MINIMAL_PRINTF is not set -CONFIG_STANDARD_PRINTF=y -# CONFIG_ADVANCED_PRINTF is not set +# CONFIG_STANDARD_PRINTF is not set +CONFIG_ADVANCED_PRINTF=y CONFIG_FORMAT_IHEX=y # CONFIG_FORMAT_SREC is not set # CONFIG_FORMAT_BINARY is not set ========================================== aversive/modules/ihm/parse/test/commands.c (1.1.2.2 -> 1.1.2.3) ========================================== @@ -1,127 +1,152 @@ +#include <math.h> #include <stdio.h> #include <string.h> +#include <aversive/pgmspace.h> +#include <aversive/wait.h> + #include <parse.h> #include <parse_num.h> #include <parse_string.h> -/****** CMD 1 */ -/* this structure is filled when cmd1 is parsed successfully */ -struct cmd1_result { - fixed_string_t arg0; - fixed_string_t arg1; - uint32_t arg2; - fixed_string_t arg3; +/**********************************************************/ +/* operations on float */ + +/* this structure is filled when cmd_float is parsed successfully */ +struct cmd_float_result { + float a; + fixed_string_t op; + float b; }; -/* function called when cmd1 is parsed successfully */ -void cmd1_parsed(void * parsed_result, void * data) +/* function called when cmd_float is parsed successfully */ +static void cmd_float_parsed(void * parsed_result, void * data) { - struct cmd1_result * res = parsed_result; - printf("MATCH %s %s %d %s\n", res->arg0, res->arg1, (int)res->arg2, res->arg3); -} + struct cmd_float_result * cmd = (struct cmd_float_result *) parsed_result; + float res=0.; -struct token_string cmd1_arg0 = TOKEN_STRING_INITIALIZER(struct cmd1_result, arg0, "cmd1"); -struct token_string cmd1_arg1 = TOKEN_STRING_INITIALIZER(struct cmd1_result, arg1, "pouet#coin#mouarf#mouais"); -struct token_num cmd1_arg2 = TOKEN_NUM_INITIALIZER(struct cmd1_result, arg2, UINT32); -/* str == NULL means any string */ -struct token_string cmd1_arg3 = TOKEN_STRING_INITIALIZER(struct cmd1_result, arg3, NULL); + switch(cmd->op[0]) { + case '+': res = cmd->a + cmd->b; break; + case '-': res = cmd->a - cmd->b; break; + case '*': res = cmd->a * cmd->b; break; + case '/': res = cmd->a / cmd->b; break; + default: break; + } + printf_P(PSTR("%f\n"), res); +} -struct inst cmd1 = { - .f = cmd1_parsed, /* function to call */ +parse_pgm_token_num_t cmd_float_a = TOKEN_NUM_INITIALIZER(struct cmd_float_result, a, FLOAT); +prog_char str_float_op[] = "+#-#*#/"; +parse_pgm_token_string_t cmd_float_op = TOKEN_STRING_INITIALIZER(struct cmd_float_result, op, str_float_op); +parse_pgm_token_num_t cmd_float_b = TOKEN_NUM_INITIALIZER(struct cmd_float_result, b, FLOAT); + +prog_char help_float[] = "Operation on float (ex: '2 + 5.4')"; +parse_pgm_inst_t cmd_float = { + .f = cmd_float_parsed, /* function to call */ .data = NULL, /* 2nd arg of func */ - .help_str = "This is help for cmd1", /* help string for instruction */ + .help_str = help_float, .tokens = { /* token list, NULL terminated */ - &cmd1_arg0, &cmd1_arg1, &cmd1_arg2, &cmd1_arg3, NULL, + (prog_void *)&cmd_float_a, + (prog_void *)&cmd_float_op, + (prog_void *)&cmd_float_b, + NULL, }, }; -/****** CMD 2 */ +/**********************************************************/ +/* operations on trigo */ -struct cmd2_result { - fixed_string_t arg0; +/* this structure is filled when cmd_trigo is parsed successfully */ +struct cmd_trigo_result { + fixed_string_t op; + float a; }; -void cmd2_parsed(void * parsed_result, void * data) +/* function called when cmd_trigo is parsed successfully */ +static void cmd_trigo_parsed(void * parsed_result, void * data) { - struct cmd2_result * res = parsed_result; + struct cmd_trigo_result * cmd = (struct cmd_trigo_result *) parsed_result; + float res=0.; - printf("MATCH %s\n", res->arg0); -} + if (!strcmp_P(cmd->op, PSTR("sin"))) { + res = sin(cmd->a); + } + + else if (!strcmp_P(cmd->op, PSTR("cos"))) { + res = cos(cmd->a); + } + + else if (!strcmp_P(cmd->op, PSTR("tan"))) { + res = tan(cmd->a); + } -struct token_string cmd2_arg0 = TOKEN_STRING_INITIALIZER(struct cmd2_result, arg0, "toto"); + printf_P(PSTR("%f\n"), res); +} -struct inst cmd2 = { - .f = cmd2_parsed, - .data = NULL, - .help_str = "Help for toto instruction", - .tokens = { - &cmd2_arg0, NULL, +prog_char str_trigo_op[] = "sin#tan#cos"; +parse_pgm_token_string_t cmd_trigo_op = TOKEN_STRING_INITIALIZER(struct cmd_trigo_result, op, str_trigo_op); +parse_pgm_token_num_t cmd_trigo_a = TOKEN_NUM_INITIALIZER(struct cmd_trigo_result, a, FLOAT); + +prog_char help_trigo[] = "Trigonometric operations (ex: 'sin 2.03')"; +parse_pgm_inst_t cmd_trigo = { + .f = cmd_trigo_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_trigo, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_trigo_op, + (prog_void *)&cmd_trigo_a, + NULL, }, }; -/****** CMD 3 */ +/**********************************************************/ +/* Help */ -struct cmd3_result { +/* this structure is filled when cmd_help is parsed successfully */ +struct cmd_help_result { fixed_string_t arg0; - float arg1; }; -void cmd3_parsed(void * parsed_result, void * data) +/* function called when cmd_help is parsed successfully */ +static void cmd_help_parsed(void * parsed_result, void * data) { - struct cmd3_result * res = parsed_result; - - printf("MATCH %s %f\n", res->arg0, (double)res->arg1); + printf_P(PSTR("== Simple calculator program ==\n" + "You can do simple operations on floats, like '1 + 3'\n" + "or '4.4 * 2.' (space is important).\n" + "Some trigonometric operations are available, like\n" + "'sin 4.5'.\n")); } -struct token_string cmd3_arg0 = TOKEN_STRING_INITIALIZER(struct cmd3_result, arg0, "toto#titi"); -struct token_num cmd3_arg1 = TOKEN_NUM_INITIALIZER(struct cmd3_result, arg1, FLOAT); +prog_char str_help_arg0[] = "help"; +parse_pgm_token_string_t cmd_help_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_help_result, arg0, str_help_arg0); -struct inst cmd3 = { - .f = cmd3_parsed, - .data = NULL, - .tokens = { - &cmd3_arg0, &cmd3_arg1, NULL, +prog_char help_help[] = "Display help"; +parse_pgm_inst_t cmd_help = { + .f = cmd_help_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_help, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_help_arg0, + NULL, }, }; -/****** CMD 4 */ - -struct cmd4_result { - fixed_string_t arg0; - fixed_string_t arg1; -}; - -void cmd4_parsed(void * parsed_result, void * data) -{ - struct cmd4_result * res = parsed_result; - - printf("MATCH %s %s\n", res->arg0, res->arg1); -} - -struct token_string cmd4_arg0 = TOKEN_STRING_INITIALIZER(struct cmd4_result, arg0, "titi"); -struct token_string cmd4_arg1 = TOKEN_STRING_INITIALIZER(struct cmd4_result, arg0, "tutu"); - -struct inst cmd4 = { - .f = cmd4_parsed, - .data = NULL, - .help_str = "Help for titi instruction", - .tokens = { - &cmd4_arg0, &cmd4_arg1, NULL, - }, -}; +/**********************************************************/ +/**********************************************************/ /****** CONTEXT (list of instruction) */ -struct ctx main_ctx = { - .name = "main", - .insts = { - &cmd1, &cmd2, &cmd3, &cmd4, NULL, - }, +/* in progmem */ +parse_pgm_ctx_t main_ctx[] = { + (parse_pgm_inst_t *)&cmd_float, + (parse_pgm_inst_t *)&cmd_trigo, + (parse_pgm_inst_t *)&cmd_help, + NULL, }; + ====================================== aversive/modules/ihm/parse/test/main.c (1.1.2.5 -> 1.1.2.6) ====================================== @@ -1,6 +1,5 @@ -/* +/* * 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 @@ -16,216 +15,82 @@ * 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.5 2007-10-14 10:17:02 zer0 Exp $ - * + * Revision : $Id: main.c,v 1.1.2.6 2007-11-24 22:57:54 zer0 Exp $ * */ -/* test program for rdline, works on AVR and HOST... but there are a - * lot of defines... ;) */ #include <stdio.h> #include <string.h> +#include <math.h> - -#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/pgmspace.h> +#include <aversive/error.h> #include <aversive/wait.h> -#include <uart.h> + #include <rdline.h> #include <parse.h> -#include <parse_string.h> -#include <parse_num.h> - -extern struct ctx main_ctx; -/* globals */ struct rdline rdl; char prompt[RDLINE_PROMPT_SIZE]; -int cpt=0; +extern parse_pgm_ctx_t main_ctx[]; +extern void cmd_event_parsed(void * parsed_result, void * data); +#include <stdlib.h> +#include <stdarg.h> +#include <inttypes.h> +#include <ctype.h> #ifdef HOST_VERSION +#include <unistd.h> +#include <termios.h> + +/* for rdline */ void write_char(char c) { write(1, &c, 1); } + #else +#include <uart.h> + void write_char(char c) { uart0_send(c); } +#endif -static void -rx(char c) +void +valid_buffer(const char * buf, uint8_t size) { 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"); - } + ret = parse(main_ctx, buf); + if (ret == PARSE_AMBIGUOUS) + printf_P(PSTR("Ambiguous command\n")); + else if (ret == PARSE_NOMATCH) + printf_P(PSTR("Command not found\n")); + else if (ret == PARSE_BAD_ARGS) + printf_P(PSTR("Bad arguments\n")); } -#endif - -void display_buffer(const char * buf, uint8_t size) +int8_t +complete_buffer(const char * buf, char * dstbuf, uint8_t dstsize, + int16_t * state) { - if (parse(&main_ctx, buf) < 0) - printf("Command not found\n"); + return complete(main_ctx, buf, state, dstbuf, dstsize); } -int8_t complete_buffer(const char * buf, uint8_t size, - char * dstbuf, uint8_t dstsize, - int16_t * state) -{ - return complete(&main_ctx, buf, state, dstbuf, dstsize); -} -struct cmd_result { - fixed_string_t arg0; -} result; -struct token_string tok = TOKEN_STRING_INITIALIZER(struct cmd_result, arg0, "test1#test2#dd"); - -struct cmd_result_num { - uint32_t arg0; -} result_num; -struct token_num tok_num = TOKEN_NUM_INITIALIZER(struct cmd_result_num, arg0, UINT32); +/*** main */ -int main(void) +int main(void) { #ifdef HOST_VERSION struct termios oldterm, term; - int n, i; - int8_t ret; -#endif - char buf[127]; - int err; - int16_t state=0; - - -#ifndef HOST_VERSION - uart_init(); - fdevopen(uart0_dev_send, uart0_dev_recv); - - wait_ms(5000); - uart0_register_rx_event(rx); - - sei(); - printf("Start\n"); + int n; #endif - - err = parse_string(&tok, "test1", &result); - if (err >= 0) - printf("Match : <%s> (consumed %d)\n", result.arg0, err); - - err = parse_string(&tok, "test2", &result); - if (err >= 0) - printf("Match : <%s> (consumed %d)\n", result.arg0, err); - - err = parse_string(&tok, "test3", &result); - if (err >= 0) - printf("Match : <%s> (consumed %d)\n", result.arg0, err); - - err = parse_string(&tok, "test", &result); - if (err >= 0) - printf("Match : <%s> (consumed %d)\n", result.arg0, err); - - printf("\n"); - err = parse_num(&tok_num, "123", &result_num); - if (err >= 0) - printf("Match : <%d> (consumed %d)\n", (int)result_num.arg0, err); - - err = parse_num(&tok_num, "0x55", &result_num); - if (err >= 0) - printf("Match : <%d> (consumed %d)\n", (int)result_num.arg0, err); - - err = parse_num(&tok_num, "121321003115165 ", &result_num); - if (err >= 0) - printf("Match : <%d> (consumed %d)\n", (int)result_num.arg0, err); - - if (parse(&main_ctx, "toto 3.3\n")) - printf("does not match... :'(\n"); - - printf("\n"); - printf("complete nb = %d\n", complete_get_nb_string(&tok)); - - complete_get_elt_string(&tok, 0, buf, sizeof(buf)); - printf("complete 0 : <%s>\n", buf); - complete_get_elt_string(&tok, 1, buf, sizeof(buf)); - printf("complete 1 : <%s>\n", buf); - complete_get_elt_string(&tok, 2, buf, sizeof(buf)); - printf("complete 2 : <%s>\n", buf); - if (complete_get_elt_string(&tok, 3, buf, sizeof(buf)) != -1) - printf("complete 3 ????? : <%s>\n", buf); - - printf("\n\n"); - state=0; - while ( (err = complete(&main_ctx, "cmd1 mo", &state, buf, sizeof(buf))) == 1) { - printf("err = %d, buf = <%s>\n", err, buf); - } - if (err <= 0) - printf("err = %d\n", err); - else - printf("err = %d, buf = <%s>\n", err, buf); - - printf("\n\n"); - state=0; - while ( (err = complete(&main_ctx, "cmd1 p", &state, buf, sizeof(buf))) == 1) { - printf("err = %d, buf = <%s>\n", err, buf); - } - if (err <= 0) - printf("err = %d\n", err); - else - printf("err = %d, buf = <%s>\n", err, buf); - - printf("\n\n"); - state=0; - while ( (err = complete(&main_ctx, "cmd1 ", &state, buf, sizeof(buf))) == 1) { - printf("err = %d, buf = <%s>\n", err, buf); - } - if (err <= 0) - printf("err = %d\n", err); - else - printf("err = %d, buf = <%s>\n", err, buf); - - printf("\n\n"); - state=0; - while ( (err = complete(&main_ctx, "toto", &state, buf, sizeof(buf))) == 1) { - printf("err = %d, buf = <%s>\n", err, buf); - } - if (err <= 0) - printf("err = %d\n", err); - else - printf("err = %d, buf = <%s>\n", err, buf); - - printf("\n\n"); - state=0; - while ( (err = complete(&main_ctx, "csdcds", &state, buf, sizeof(buf))) == 1) { - printf("err = %d, buf = <%s>\n", err, buf); - } - if (err <= 0) - printf("err = %d\n", err); - else - printf("err = %d, buf = <%s>\n", err, buf); - + int8_t ret; + char c; #ifdef HOST_VERSION tcgetattr(0, &oldterm); @@ -233,41 +98,46 @@ term.c_lflag &= ~(ICANON | ECHO | ISIG); tcsetattr(0, TCSANOW, &term); setbuf(stdin, NULL); +#else + fdevopen(uart0_dev_send, uart0_dev_recv); + uart_init(); + sei(); #endif - /* common init */ - rdline_init(&rdl, write_char, display_buffer, complete_buffer); - snprintf(prompt, sizeof(prompt), "toto[%d] > ", cpt++); - rdline_newline(&rdl, prompt); + printf_P(PSTR("Start\n")); + wait_ms(500); + rdline_init(&rdl, write_char, valid_buffer, complete_buffer); + snprintf(prompt, sizeof(prompt), "main > "); - /* loop to send chars on host */ -#ifdef HOST_VERSION - while ((n=read(0, buf, sizeof(buf)-1)) > 0) { - buf[n] = 0; + rdline_newline(&rdl, prompt); - 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; - } + c = -1; + while (1) { +#ifdef HOST_VERSION + n=read(0, &c, 1); + if (n<=0) + break; +#else + c=uart0_recv(); +#endif + + ret = rdline_char_in(&rdl, c); + if (ret == -2) + break; + + if (ret != 2 && ret != 0) { + rdline_add_history(&rdl, rdline_get_buffer(&rdl)); + rdline_newline(&rdl, prompt); } } +#ifdef HOST_VERSION tcsetattr(0, TCSANOW, &oldterm); - printf("\nEND n=%d\n", n); - - /* irq driven on avr, see rx() */ -#else - while(1); #endif + printf("\n"); return 0; } + + ============================================= aversive/modules/ihm/parse/test/uart_config.h (1.1.2.1 -> 1.1.2.2) ============================================= @@ -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: uart_config.h,v 1.1.2.1 2007-09-17 20:53:28 zer0 Exp $ + * Revision : $Id: uart_config.h,v 1.1.2.2 2007-11-24 22:57:54 zer0 Exp $ * */ @@ -39,7 +39,7 @@ /* enable uart0 interrupts if == 1, disable if == 0 */ #define UART0_INTERRUPT_ENABLED 1 -#define UART0_BAUDRATE 57600 +#define UART0_BAUDRATE 38400 /* * if you enable this, the maximum baudrate you can reach is _______________________________________________ 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