[tuxdroid-svn] r1132 - in software_suite_v2/middleware/tuxdriver/trunk: src test
Status: Beta
Brought to you by:
ks156
From: eFfeM <c2m...@c2...> - 2008-05-07 19:54:47
|
Author: eFfeM Date: 2008-05-07 21:54:14 +0200 (Wed, 07 May 2008) New Revision: 1132 Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_cmd_parser.c software_suite_v2/middleware/tuxdriver/trunk/src/tux_types.h software_suite_v2/middleware/tuxdriver/trunk/test/descriptor.txt software_suite_v2/middleware/tuxdriver/trunk/test/main.c software_suite_v2/middleware/tuxdriver/trunk/test/test_macro.txt Log: This completes the changes to the parser. The code compiles and passes the basic tests from use_tux_driver more indepth testing needs to be done testing all kind of combinations... Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_cmd_parser.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_cmd_parser.c 2008-05-07 14:39:47 UTC (rev 1131) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_cmd_parser.c 2008-05-07 19:54:14 UTC (rev 1132) @@ -44,11 +44,6 @@ #define NRCMDS 256 -#define check_result(funct_res) if (funct_res) \ - return E_TUXDRV_NOERROR; \ - else \ - return E_TUXDRV_INVALIDPARAMETER; - typedef struct { delay_cmd_t cmd_list[NRCMDS]; int cmd_count; @@ -62,20 +57,9 @@ #endif static bool cmd_parser_enable = true; - /** * */ -static inline bool match_token(tokens_t tokens, int i, int t_num, - const char *str, int t_count) -{ - return (i >= t_count) && (!strcmp(tokens[t_num], str)); -} - - -/** - * - */ LIBLOCAL void tux_cmd_parser_init(void) { @@ -148,64 +132,16 @@ /** * */ -static unsigned char -tux_movement_conststr_to_val(const char *conststr) +static bool +str_to_state_t(const char *conststr, state_t *state) { - if (!strcmp(conststr, "VERYLOW")) + if (!strcmp(conststr, "NDEF")) { - return 1; + *state = UNDEFINED; + return true; } - if (!strcmp(conststr, "LOW")) - { - return 2; - } - if (!strcmp(conststr, "MEDIUM")) - { - return 3; - } - if (!strcmp(conststr, "MIDHIGH")) - { - return 4; - } - if (!strcmp(conststr, "HIGH")) - { - return 5; - } if (!strcmp(conststr, "UNDEFINED")) { - return 0; - } - if (!strcmp(conststr, "OPEN")) - { - return 1; - } - if (!strcmp(conststr, "UP")) - { - return 1; - } - if (!strcmp(conststr, "CLOSE")) - { - return 2; - } - if (!strcmp(conststr, "DOWN")) - { - return 2; - } - if (!strcmp(conststr, "STOP")) - { - return 3; - } - return 0; -} - -/** - * - */ -static bool -str_to_state_t(const char *conststr, state_t *state) -{ - if (!strcmp(conststr, "UNDEFINED")) - { *state = UNDEFINED; return true; } @@ -240,31 +176,6 @@ /** * */ -static unsigned char -conststr_to_ledval(const char *conststr) -{ - if (!strcmp(conststr, "LED_NONE")) - { - return 0; - } - if (!strcmp(conststr, "LED_LEFT")) - { - return 1; - } - if (!strcmp(conststr, "LED_RIGHT")) - { - return 2; - } - if (!strcmp(conststr, "LED_BOTH")) - { - return 3; - } - return 0; -} - -/** - * - */ static bool str_to_leds_t(const char *conststr, leds_t *leds) { @@ -294,47 +205,6 @@ /** * */ -static unsigned char -conststr_to_effectval(const char *conststr) -{ - if (!strcmp(conststr, "UNAFFECTED")) - { - return 0; - } - if (!strcmp(conststr, "LAST")) - { - return 1; - } - if (!strcmp(conststr, "NONE")) - { - return 2; - } - if (!strcmp(conststr, "DEFAULT")) - { - return 3; - } - if (!strcmp(conststr, "FADE_DURATION")) - { - return 4; - } - if (!strcmp(conststr, "FADE_RATE")) - { - return 5; - } - if (!strcmp(conststr, "GRADIENT_NBR")) - { - return 6; - } - if (!strcmp(conststr, "GRADIENT_DELTA")) - { - return 7; - } - return 0; -} - -/** - * - */ static bool str_to_effect_type(const char *conststr, effect_type_t *effect_type) { @@ -382,532 +252,9 @@ } /** - * - */ -static bool -tux_cmd_parser_parse_raw_cmd(tokens_t tokens, int nr_tokens) -{ - raw_frame data = {0, 0, 0, 0}; - int r = 0; - int i; - - for (i = 0; i < TUX_SEND_LENGTH; i++) - { - if (hex_to_uint8(tokens[i], &data[i])) - { - r++; - } - } - - if (r < TUX_SEND_LENGTH) - { - return false; - } - - return tux_usb_send_raw(data); -} - -/* - The functions below implement the command parser. - else clauses are not needed since the check_result macro contains a return - an alternative implementation could use a table lookup and a switch - statement. This might clean up the code a little bit (to be investigated) -*/ - -/** * */ static TuxDrvError -tux_cmd_parser_handle_eyes_command(tokens_t tokens, int nr_tokens) -{ - /* EYES ON */ - if (match_token(tokens, nr_tokens, 2, "ON", 5)) - { - unsigned char counter; - - if (str_to_uint8(tokens[3], &counter)) - { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - check_result(tux_eyes_cmd_on(counter, final_state)); - } - } - /* EYES ON_DURING */ - if (match_token(tokens, nr_tokens, 2, "ON_DURING", 5)) - { - float timeout = 0; - - if (str_to_float(tokens[3], &timeout)) - { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - check_result(tux_eyes_cmd_on_during(timeout, final_state)); - } - } - /* EYES OPEN */ - if (match_token(tokens, nr_tokens, 2, "OPEN", 3)) - { - check_result(tux_eyes_cmd_open()); - } - /* EYES CLOSE */ - if (match_token(tokens, nr_tokens, 2, "CLOSE", 3)) - { - check_result(tux_eyes_cmd_close()); - } - /* EYES OFF */ - if (match_token(tokens, nr_tokens, 2, "OFF", 3)) - { - check_result(tux_eyes_cmd_off()); - } - return E_TUXDRV_INVALIDCOMMAND; -} - -/** - * - */ -static TuxDrvError -tux_cmd_parser_handle_mouth_command(tokens_t tokens, int nr_tokens) -{ - /* MOUTH ON */ - if (match_token(tokens, nr_tokens, 2, "ON", 5)) - { - unsigned char counter; - - if (str_to_uint8(tokens[3], &counter)) - { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - check_result(tux_mouth_cmd_on(counter, final_state)); - } - } - /* MOUTH ON_DURING */ - if (match_token(tokens, nr_tokens, 2, "ON_DURING", 5)) - { - float timeout = 0; - - if (str_to_float(tokens[3], &timeout)) - { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - check_result(tux_mouth_cmd_on_during(timeout, final_state)); - } - } - /* MOUTH OPEN */ - if (match_token(tokens, nr_tokens, 2, "OPEN", 3)) - { - check_result(tux_mouth_cmd_open()); - } - /* MOUTH CLOSE */ - if (match_token(tokens, nr_tokens, 2, "CLOSE", 3)) - { - check_result(tux_mouth_cmd_close()); - } - /* MOUTH OFF */ - if (match_token(tokens, nr_tokens, 2, "OFF", 3)) - { - check_result(tux_mouth_cmd_off()); - } - return E_TUXDRV_INVALIDCOMMAND; -} - -/** - * - */ -static TuxDrvError -tux_cmd_parser_handle_wings_command(tokens_t tokens, int nr_tokens) -{ - /* WINGS ON */ - if (match_token(tokens, nr_tokens, 2, "ON", 5)) - { - unsigned char counter; - - if (str_to_uint8(tokens[3], &counter)) - { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - check_result(tux_wings_cmd_on(counter, final_state)); - } - } - /* WINGS ON_DURING */ - if (match_token(tokens, nr_tokens, 2, "ON_DURING", 5)) - { - float timeout = 0; - - if (str_to_float(tokens[3], &timeout)) - { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - check_result(tux_wings_cmd_on_during(timeout, final_state)); - } - } - /* WINGS OPEN */ - if (match_token(tokens, nr_tokens, 2, "UP", 3)) - { - check_result(tux_wings_cmd_up()); - } - /* WINGS CLOSE */ - if (match_token(tokens, nr_tokens, 2, "DOWN", 3)) - { - check_result(tux_wings_cmd_down()); - } - /* WINGS OFF */ - if (match_token(tokens, nr_tokens, 2, "OFF", 3)) - { - check_result(tux_wings_cmd_off()); - } - /* WINGS SPEED */ - if (match_token(tokens, nr_tokens, 2, "SPEED", 4)) - { - unsigned char speed; - - if (str_to_uint8(tokens[3], &speed)) - { - check_result(tux_wings_cmd_speed(speed)); - } - } - return E_TUXDRV_INVALIDCOMMAND; -} - -/** - * - */ -static TuxDrvError -tux_cmd_parser_handle_spinning_command(tokens_t tokens, int nr_tokens) -{ - /* SPINNING SPEED */ - if (match_token(tokens, nr_tokens, 2, "SPEED", 4)) - { - unsigned char speed; - - if (str_to_uint8(tokens[3], &speed)) - { - check_result(tux_spinning_cmd_speed(speed)); - } - } - /* SPINNING LEFT ON */ - if (match_token(tokens, nr_tokens, 2, "LEFT_ON", 4)) - { - unsigned char speed; - - if (str_to_uint8(tokens[3], &speed)) - { - check_result(tux_spinning_cmd_left_on(speed)); - } - } - /* SPINNING RIGHT ON */ - if (match_token(tokens, nr_tokens, 2, "RIGHT_ON", 4)) - { - unsigned char speed; - - if (str_to_uint8(tokens[3], &speed)) - { - check_result(tux_spinning_cmd_right_on(speed)); - } - } - /* SPINNING LEFT ON DURING */ - if (match_token(tokens, nr_tokens, 2, "LEFT_ON_DURING", 4)) - { - float timeout; - - if (str_to_float(tokens[3], &timeout)) - { - check_result(tux_spinning_cmd_left_on_during(timeout)); - } - } - /* SPINNING RIGHT ON DURING */ - if (match_token(tokens, nr_tokens, 2, "RIGHT_ON_DURING", 4)) - { - float timeout; - - if (str_to_float(tokens[3], &timeout)) - { - check_result(tux_spinning_cmd_right_on_during(timeout)); - } - } - /* SPINNING OFF */ - if (match_token(tokens, nr_tokens, 2, "OFF", 3)) - { - check_result(tux_spinning_cmd_off()); - } - return E_TUXDRV_INVALIDCOMMAND; -} - -/** - * - */ -static TuxDrvError -tux_cmd_parser_handle_ir_command(tokens_t tokens, int nr_tokens) -{ - /* IR ON */ - if (match_token(tokens, nr_tokens, 2, "ON", 3)) - { - check_result(tux_user_inputs_cmd_ir_on()); - } - /* IR OFF */ - if (match_token(tokens, nr_tokens, 2, "OFF", 3)) - { - check_result(tux_user_inputs_cmd_ir_off()); - } - /* IR SEND */ - if (match_token(tokens, nr_tokens, 2, "SEND", 5)) - { - unsigned char address; - unsigned char command; - bool ret; - - ret = str_to_uint8(tokens[3], &address); - ret &= str_to_uint8(tokens[4], &command); - - if (ret) - { - check_result(tux_user_inputs_cmd_ir_send(address, command)); - } - } - return E_TUXDRV_INVALIDCOMMAND; -} - -/** - * - */ -static TuxDrvError -tux_cmd_parser_handle_leds_command(tokens_t tokens, int nr_tokens) -{ - bool ret = true; - - /* LED SET */ - if (match_token(tokens, nr_tokens, 2, "SET", 8)) - { - leds_t leds; - float intensity; - unsigned char effect_type; - float effect_speed; - unsigned char effect_step; - - leds = conststr_to_ledval(tokens[3]); - ret = str_to_float(tokens[4], &intensity); - effect_type = conststr_to_effectval(tokens[5]); - ret &= str_to_float(tokens[6], &effect_speed); - ret &= str_to_uint8(tokens[7], &effect_step); - - if (ret) - { - check_result(tux_leds_cmd_set(leds, intensity, - effect_type, effect_speed, effect_step)); - } - } - /* LED ON */ - if (match_token(tokens, nr_tokens, 2, "ON", 5)) - { - leds_t leds; - float intensity; - - leds = conststr_to_ledval(tokens[3]); - ret = str_to_float(tokens[4], &intensity); - if (ret) - { - check_result(tux_leds_cmd_set(leds, intensity, NONE, 0, 0)); - } - } - /* LED OFF */ - if (match_token(tokens, nr_tokens, 2, "OFF", 4)) - { - leds_t leds; - - leds = conststr_to_ledval(tokens[3]); - check_result(tux_leds_cmd_set(leds, 0.0, NONE, 0, 0)); - } - /* LED PULSE */ - if (match_token(tokens, nr_tokens, 2, "PULSE", 11)) - { - leds_t leds; - float min_intensity; - float max_intensity; - unsigned char pulse_count; - float pulse_period; - unsigned char effect_type; - float effect_speed; - unsigned char effect_step; - - leds = conststr_to_ledval(tokens[3]); - ret = str_to_float(tokens[4], &min_intensity); - ret &= str_to_float(tokens[5], &max_intensity); - ret &= str_to_uint8(tokens[6], &pulse_count); - ret &= str_to_float(tokens[7], &pulse_period); - effect_type = conststr_to_effectval(tokens[8]); - ret &= str_to_float(tokens[9], &effect_speed); - ret &= str_to_uint8(tokens[10], &effect_step); - - if (ret) - { - check_result(tux_leds_cmd_pulse(leds, min_intensity, max_intensity, - pulse_count, pulse_period, - effect_type, effect_speed, effect_step)); - } - } - /* LED BLINK */ - if (match_token(tokens, nr_tokens, 2, "BLINK", 6)) - { - leds_t leds; - unsigned char pulse_count; - float pulse_period; - - leds = conststr_to_ledval(tokens[3]); - ret &= str_to_uint8(tokens[4], &pulse_count); - ret &= str_to_float(tokens[5], &pulse_period); - check_result(tux_leds_cmd_pulse(leds, 0.0, 1.0, - pulse_count, pulse_period, NONE, 0, 0)); - } - return E_TUXDRV_INVALIDCOMMAND; -} - -/** - * - */ -static TuxDrvError -tux_cmd_parser_handle_play_command(tokens_t tokens, int nr_tokens) -{ - /* SOUND FLASH PLAY */ - if (match_token(tokens, nr_tokens, 2, "PLAY", 5)) - { - unsigned char track_num = 1; - float volume = 0; - bool ret; - - ret = str_to_uint8(tokens[3], &track_num); - ret &= str_to_float(tokens[4], &volume); - if (ret) - { - check_result(tux_sound_flash_cmd_play(track_num, volume)); - } - } - return E_TUXDRV_INVALIDCOMMAND; -} - - -/** - * - */ -static TuxDrvError -tux_cmd_parser_handle_audio_command(tokens_t tokens, int nr_tokens) -{ - /* CHANNEL GENERAL */ - if (match_token(tokens, nr_tokens, 2, "CHANNEL_GENERAL", 3)) - { - check_result(tux_audio_cmd_channel_general()); - } - /* CHANNEL TTS */ - if (match_token(tokens, nr_tokens, 2, "CHANNEL_TTS", 3)) - { - check_result(tux_audio_cmd_channel_tts()); - } - /* MUTE */ - if (match_token(tokens, nr_tokens, 2, "MUTE", 4)) - { - bool value; - - if (!str_to_bool(tokens[3], &value)) - { - return E_TUXDRV_INVALIDCOMMAND; - } - check_result(tux_audio_cmd_mute(value)); - } - return E_TUXDRV_INVALIDCOMMAND; -} - -/** - * Parse a command. - */ -LIBLOCAL TuxDrvError -tux_cmd_parser_parse_command(const char *cmd_str) -{ - tokens_t tokens; - int nr_tokens; - - /* If the parser is not enabled then fail */ - if (!cmd_parser_enable) - { - return E_TUXDRV_PARSERISDISABLED; - } - - log_debug("Parse command : [%s]", cmd_str); - nr_tokens = tux_cmd_parser_get_tokens(cmd_str, &tokens, 32, ":,"); - - /* If no tokens in the command then fail */ - if (nr_tokens <= 0) - { - return E_TUXDRV_INVALIDCOMMAND; - } - - /* Command to tux */ - if (match_token(tokens, nr_tokens, 0, "TUX_CMD", 1)) - { - if (match_token(tokens, nr_tokens, 1, "EYES", 2)) - { - return tux_cmd_parser_handle_eyes_command(tokens, nr_tokens); - } - if (match_token(tokens, nr_tokens, 1, "MOUTH", 2)) - { - return tux_cmd_parser_handle_mouth_command(tokens, nr_tokens); - } - if (match_token(tokens, nr_tokens, 1, "WINGS", 2)) - { - return tux_cmd_parser_handle_wings_command(tokens, nr_tokens); - } - if (match_token(tokens, nr_tokens, 1, "SPINNING", 2)) - { - return tux_cmd_parser_handle_spinning_command(tokens, nr_tokens); - } - if (match_token(tokens, nr_tokens, 1, "IR", 2)) - { - return tux_cmd_parser_handle_ir_command(tokens, nr_tokens); - } - if (match_token(tokens, nr_tokens, 1, "LED", 2)) - { - return tux_cmd_parser_handle_leds_command(tokens, nr_tokens); - } - if (match_token(tokens, nr_tokens, 1, "SOUND_FLASH", 2)) - { - return tux_cmd_parser_handle_play_command(tokens, nr_tokens); - } - if (match_token(tokens, nr_tokens, 1, "AUDIO", 2)) - { - return tux_cmd_parser_handle_audio_command(tokens, nr_tokens); - } - } - /* Command raw to fux dongle or tux */ - if (match_token(tokens, nr_tokens, 0, "RAW_CMD", 6)) - { - check_result(tux_cmd_parser_parse_raw_cmd(tokens, nr_tokens)); - } - return E_TUXDRV_INVALIDCOMMAND; -} - -/* -WORK IN PROGRESS -idea is to parse a command when it is inserted and put it in the queue only if -it is a valid command -when executing the command does not need to be parsed any more but can be -executed directly - -todo: -add execute function -enter cmd in queue -retrieve cmd and execute it -remove old code (cmd param in struct, old parsing code etc) -test! -*/ - - -/** - * - */ -static TuxDrvError parse_tux_audio_command(tokens_t tokens, delay_cmd_t *cmd) { TuxDrvError ret = E_TUXDRV_INVALIDCOMMAND; @@ -1104,7 +451,7 @@ } else if (strcmp(tokens[2], "OPEN") == 0) { - cmd->sub_command = SET; + cmd->sub_command = OPEN; ret = E_TUXDRV_NOERROR; } return ret; @@ -1332,7 +679,7 @@ return E_TUXDRV_PARSERISDISABLED; } - log_debug("Parse command : [%s]", cmd_str); + log_debug("parse_command : [%s]", cmd_str); memset(&tokens, 0, sizeof(tokens_t)); nr_tokens = tux_cmd_parser_get_tokens(cmd_str, &tokens, 32, ":,"); @@ -1350,6 +697,303 @@ } /** + * + */ +static void +execute_audio_command (delay_cmd_t *cmd) +{ + switch (cmd->sub_command) { + case CHANNEL_GENERAL: + tux_audio_cmd_channel_general(); + break; + case CHANNEL_TTS: + tux_audio_cmd_channel_tts(); + break; + case MUTE: + tux_audio_cmd_mute(cmd->audio_parameters.muteflag); + break; + default: /* should not occur */ + log_error("execute invalid audio command"); + } +} + +/** + * + */ +static void +execute_eyes_command (delay_cmd_t *cmd) +{ + switch (cmd->sub_command) { + case ON: + tux_eyes_cmd_on( + cmd->eyes_parameters.nr_movements, + cmd->eyes_parameters.state); + break; + case ON_DURING: + tux_eyes_cmd_on_during( + cmd->eyes_parameters.duration, + cmd->eyes_parameters.state); + break; + case OPEN: + tux_eyes_cmd_open(); + break; + case CLOSE: + tux_eyes_cmd_close(); + break; + case OFF: + tux_eyes_cmd_off(); + break; + default: /* should not occur */ + log_error("execute invalid eyes command"); + } +} + +/** + * + */ +static void +execute_ir_command (delay_cmd_t *cmd) +{ + switch (cmd->sub_command) { + case ON: + tux_user_inputs_cmd_ir_on(); + break; + case OFF: + tux_user_inputs_cmd_ir_off(); + case SEND: + tux_user_inputs_cmd_ir_send( + cmd->ir_parameters.address, + cmd->ir_parameters.command); + break; + default: /* should not occur */ + log_error("execute invalid ir command"); + } +} + +/** + * + */ +static void +execute_led_command (delay_cmd_t *cmd) +{ + switch (cmd->sub_command) { + case ON: + tux_leds_cmd_set( + cmd->led_parameters.leds, + cmd->led_parameters.intensity, + NONE, + 0, + 0); + break; + case OFF: + tux_leds_cmd_set( + cmd->led_parameters.leds, + 0.0, + NONE, + 0, + 0); + break; + case PULSE: + tux_leds_cmd_pulse( + cmd->led_parameters.leds, + cmd->led_parameters.min_intensity, + cmd->led_parameters.max_intensity, + cmd->led_parameters.pulse_count, + cmd->led_parameters.pulse_period, + cmd->led_parameters.effect_type, + cmd->led_parameters.effect_speed, + cmd->led_parameters.effect_step); + break; + case BLINK: + tux_leds_cmd_pulse( + cmd->led_parameters.leds, + 0.0, + 1.0, + cmd->led_parameters.pulse_count, + cmd->led_parameters.pulse_period, + NONE, + 0, + 0); + break; + case SET: + tux_leds_cmd_set( + cmd->led_parameters.leds, + cmd->led_parameters.intensity, + cmd->led_parameters.effect_type, + cmd->led_parameters.effect_speed, + cmd->led_parameters.effect_step); + break; + default: /* should not occur */ + log_error("execute invalid led command"); + } +} + +/** + * + */ +static void +execute_mouth_command (delay_cmd_t *cmd) +{ + switch (cmd->sub_command) { + case ON: + tux_mouth_cmd_on( + cmd->mouth_parameters.nr_movements, + cmd->mouth_parameters.state); + break; + case ON_DURING: + tux_mouth_cmd_on_during( + cmd->mouth_parameters.duration, + cmd->mouth_parameters.state); + break; + case OPEN: + tux_mouth_cmd_open(); + break; + case CLOSE: + tux_mouth_cmd_close(); + break; + case OFF: + tux_mouth_cmd_off(); + break; + default: /* should not occur */ + log_error("execute invalid mouth command"); + } +} + +/** + * + */ +static void +execute_sound_flash_command (delay_cmd_t *cmd) +{ + switch (cmd->sub_command) { + case PLAY: + tux_sound_flash_cmd_play( + cmd->sound_flash_parameters.track, + cmd->sound_flash_parameters.volume); + break; + default: /* should not occur */ + log_error("execute invalid sound flash command"); + } +} + +/** + * + */ +static void +execute_spinning_command (delay_cmd_t *cmd) +{ + switch (cmd->sub_command) { + case LEFT_ON: + tux_spinning_cmd_left_on(cmd->spinning_parameters.nr_qturns); + break; + case RIGHT_ON: + tux_spinning_cmd_right_on(cmd->spinning_parameters.nr_qturns); + break; + case LEFT_ON_DURING: + tux_spinning_cmd_left_on_during(cmd->spinning_parameters.duration); + break; + case RIGHT_ON_DURING: + tux_spinning_cmd_right_on_during(cmd->spinning_parameters.duration); + break; + case OFF: + tux_spinning_cmd_off(); + break; + case SPEED: + tux_spinning_cmd_speed(cmd->spinning_parameters.speed); + break; + default: /* should not occur */ + log_error("execute invalid spinning command"); + } +} + +/** + * + */ +static void +execute_wings_command (delay_cmd_t *cmd) +{ + switch (cmd->sub_command) { + case ON: + tux_wings_cmd_on( + cmd->wings_parameters.nr_movements, + cmd->wings_parameters.state); + break; + case ON_DURING: + tux_wings_cmd_on_during( + cmd->wings_parameters.duration, + cmd->wings_parameters.state); + break; + case OFF: + tux_wings_cmd_off(); + break; + case UP: + tux_wings_cmd_up(); + break; + case DOWN: + tux_wings_cmd_down(); + break; + case SPEED: + tux_wings_cmd_speed(cmd->wings_parameters.speed); + break; + default: /* should not occur */ + log_error("execute invalid wings command"); + } +} + +/** + * + */ +static void +execute_raw_command (delay_cmd_t *cmd) +{ + tux_usb_send_raw(cmd->raw_parameters.raw); +} + +/** + * + */ +static void +execute_command (delay_cmd_t *cmd) +{ + if(cmd->command_group == TUX_CMD) + { + switch(cmd->command) { + case AUDIO: + execute_audio_command(cmd); + break; + case EYES: + execute_eyes_command(cmd); + break; + case IR: + execute_ir_command(cmd); + break; + case LED: + execute_led_command(cmd); + break; + case MOUTH: + execute_mouth_command(cmd); + break; + case SOUND_FLASH: + execute_sound_flash_command(cmd); + break; + case SPINNING: + execute_spinning_command(cmd); + break; + case WINGS: + execute_wings_command(cmd); + break; + } + } + else + { + if(cmd->command_group == RAW_CMD) + { + execute_raw_command(cmd); + } + } + cmd->command_group = NO_CMD; +} +/** * */ static TuxDrvError @@ -1361,12 +1005,18 @@ for (i = 0; i < NRCMDS; i++) { - if (!strcmp(stack->cmd_list[i].cmd, "")) + if (stack->cmd_list[i].command_group == NO_CMD) { - //parse_command(cmd_str, &(stack->cmd_list[i])); - strcpy(stack->cmd_list[i].cmd, cmd_str); - stack->cmd_list[i].timeout = delay + curtime; - ret = E_TUXDRV_NOERROR; + ret = parse_command(cmd_str, &(stack->cmd_list[i])); + if (ret == E_TUXDRV_NOERROR) + { + stack->cmd_list[i].timeout = delay + curtime; + } + else + { + /* might be overwritten */ + stack->cmd_list[i].command_group = NO_CMD; + } break; } } @@ -1419,9 +1069,9 @@ /* process all pending system commands */ for (i = 0; i < NRCMDS; i++) { - if (strcmp(sys_cmd_stack.cmd_list[i].cmd, "")) + if (sys_cmd_stack.cmd_list[i].command_group != NO_CMD) { - tux_cmd_parser_parse_command(sys_cmd_stack.cmd_list[i].cmd); + execute_command(&sys_cmd_stack.cmd_list[i]); /* no need to execute the following command as we are going to clear the complete stack after this for loop memset(&sys_cmd_stack.cmd_list[i], 0, sizeof(delay_cmd_t)); @@ -1454,26 +1104,26 @@ for (i = 0; i < NRCMDS; i++) { - if (strcmp(user_cmd_stack.cmd_list[i].cmd, "")) + if (user_cmd_stack.cmd_list[i].command_group != NO_CMD) { if (curtime >= user_cmd_stack.cmd_list[i].timeout) { - tux_cmd_parser_parse_command(user_cmd_stack.cmd_list[i].cmd); + execute_command(&user_cmd_stack.cmd_list[i]); /* next two commands are faster than a memset writing a null byte to the first char of cmd is sufficient to make it an empty string */ user_cmd_stack.cmd_list[i].timeout = 0; - user_cmd_stack.cmd_list[i].cmd[0] = 0; + user_cmd_stack.cmd_list[i].command_group = NO_CMD; } } - if (strcmp(sys_cmd_stack.cmd_list[i].cmd, "")) + if (sys_cmd_stack.cmd_list[i].command_group != NO_CMD) { if (curtime >= sys_cmd_stack.cmd_list[i].timeout) { - tux_cmd_parser_parse_command(sys_cmd_stack.cmd_list[i].cmd); + execute_command(&sys_cmd_stack.cmd_list[i]); sys_cmd_stack.cmd_list[i].timeout = 0; - sys_cmd_stack.cmd_list[i].cmd[0] = 0; + sys_cmd_stack.cmd_list[i].command_group = NO_CMD; } } } @@ -1588,3 +1238,25 @@ return ret; } + +/** + * Parse a command. + */ +LIBLOCAL TuxDrvError +tux_cmd_parser_parse_command(const char *cmd_str) +{ + TuxDrvError ret; + delay_cmd_t cmd; + + /* If the parser is not enabled then fail */ + if (!cmd_parser_enable) + { + return E_TUXDRV_PARSERISDISABLED; + } + ret = parse_command(cmd_str, &cmd); + if (ret == E_TUXDRV_NOERROR) + { + execute_command(&cmd); + } + return ret; +} Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_types.h =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_types.h 2008-05-07 14:39:47 UTC (rev 1131) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_types.h 2008-05-07 19:54:14 UTC (rev 1132) @@ -29,6 +29,7 @@ #define CMDSIZE 1024 typedef enum { + NO_CMD = 0, TUX_CMD, RAW_CMD } tux_command_group_t; @@ -151,7 +152,6 @@ wings_parameters_t wings_parameters; raw_parameters_t raw_parameters; }; - char cmd[CMDSIZE]; } delay_cmd_t; #endif /* _TUX_TYPES_H_ */ Modified: software_suite_v2/middleware/tuxdriver/trunk/test/descriptor.txt =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/test/descriptor.txt 2008-05-07 14:39:47 UTC (rev 1131) +++ software_suite_v2/middleware/tuxdriver/trunk/test/descriptor.txt 2008-05-07 19:54:14 UTC (rev 1132) @@ -2,7 +2,7 @@ -------------------- - Firmwares - - Global release package : [tuxdroid firmware release 0.4.0] + - Global release package : [Unofficial package] - CPU 1 CPU id : 0 CPU name : Tuxcore @@ -60,14 +60,14 @@ CPU name : FuxUSB Version major : 0 Version minor : 4 - Version update : 0 + Version update : 1 Revision : 0 Released : True Local modification : False Mixed revisions : False Author id : 0 Variation : 0 - Symbolic version : [FuxUSB_0.4.0] + Symbolic version : [FuxUSB_0.4.1] - Sound flash Number of sounds : 10 Last used block : 9 Modified: software_suite_v2/middleware/tuxdriver/trunk/test/main.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/test/main.c 2008-05-07 14:39:47 UTC (rev 1131) +++ software_suite_v2/middleware/tuxdriver/trunk/test/main.c 2008-05-07 19:54:14 UTC (rev 1132) @@ -213,7 +213,7 @@ argc -= optind; argv += optind; - TuxDrv_SetLogLevel(LOG_LEVEL_ERROR); + TuxDrv_SetLogLevel(LOG_LEVEL_DEBUG); TuxDrv_SetLogTarget(LOG_TARGET_SHELL); TuxDrv_SetStatusCallback(on_status_event); TuxDrv_SetEndCycleCallback(on_end_cycle); Modified: software_suite_v2/middleware/tuxdriver/trunk/test/test_macro.txt =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/test/test_macro.txt 2008-05-07 14:39:47 UTC (rev 1131) +++ software_suite_v2/middleware/tuxdriver/trunk/test/test_macro.txt 2008-05-07 19:54:14 UTC (rev 1132) @@ -3,5 +3,5 @@ 2.0:TUX_CMD:LED:SET:LED_BOTH,1.0,GRADIENT_DELTA,3.0,30 1.0:TUX_CMD:SOUND_FLASH:PLAY:1:100 1.0:TUX_CMD:WINGS:ON_DURING:2.0,DOWN -#3.0:TUX_CMD:SPINNING:LEFT_ON:5 -#5.0:TUX_CMD:SPINNING:RIGHT_ON:5 +3.0:TUX_CMD:SPINNING:LEFT_ON:1 +7.0:TUX_CMD:SPINNING:RIGHT_ON:5 |