[tuxdroid-svn] r1105 - software_suite_v2/middleware/tuxdriver/trunk/src
Status: Beta
Brought to you by:
ks156
From: eFfeM <c2m...@c2...> - 2008-05-05 20:04:44
|
Author: eFfeM Date: 2008-05-05 22:04:46 +0200 (Mon, 05 May 2008) New Revision: 1105 Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_cmd_parser.c software_suite_v2/middleware/tuxdriver/trunk/src/tux_types.h Log: finished rewriting the parser; still need to add execute function; (then test; then remove old code). The current code is still fully operational (but has one warning) 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-05 19:56:40 UTC (rev 1104) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_cmd_parser.c 2008-05-05 20:04:46 UTC (rev 1105) @@ -201,6 +201,45 @@ /** * */ +static bool +str_to_state_t(const char *conststr, state_t *state) +{ + if (!strcmp(conststr, "UNDEFINED")) + { + *state = UNDEFINED; + return true; + } + if (!strcmp(conststr, "OPEN")) + { + *state = OPENED; + return true; + } + if (!strcmp(conststr, "UP")) + { + return 1; + *state = OPENED; + } + if (!strcmp(conststr, "CLOSE")) + { + *state = CLOSED; + return true; + } + if (!strcmp(conststr, "DOWN")) + { + *state = CLOSED; + return true; + } + if (!strcmp(conststr, "STOP")) + { + *state = STOP; + return true; + } + return false; +} + +/** + * + */ static unsigned char conststr_to_ledval(const char *conststr) { @@ -226,6 +265,35 @@ /** * */ +static bool +str_to_leds_t(const char *conststr, leds_t *leds) +{ + if (!strcmp(conststr, "LED_NONE")) + { + *leds = LED_NONE; + return true; + } + if (!strcmp(conststr, "LED_LEFT")) + { + *leds = LED_LEFT; + return true; + } + if (!strcmp(conststr, "LED_RIGHT")) + { + *leds = LED_RIGHT; + return true; + } + if (!strcmp(conststr, "LED_BOTH")) + { + *leds = LED_BOTH; + return true; + } + return false; +} + +/** + * + */ static unsigned char conststr_to_effectval(const char *conststr) { @@ -268,6 +336,55 @@ * */ static bool +str_to_effect_type(const char *conststr, effect_type_t *effect_type) +{ + if (!strcmp(conststr, "UNAFFECTED")) + { + *effect_type = UNAFFECTED; + return true; + } + if (!strcmp(conststr, "LAST")) + { + *effect_type = LAST; + return true; + } + if (!strcmp(conststr, "NONE")) + { + *effect_type = NONE; + return true; + } + if (!strcmp(conststr, "DEFAULT")) + { + *effect_type = DEFAULT; + return true; + } + if (!strcmp(conststr, "FADE_DURATION")) + { + *effect_type = FADE_DURATION; + return true; + } + if (!strcmp(conststr, "FADE_RATE")) + { + *effect_type = FADE_RATE; + return true; + } + if (!strcmp(conststr, "GRADIENT_NBR")) + { + *effect_type = GRADIENT_NBR; + return true; + } + if (!strcmp(conststr, "GRADIENT_DELTA")) + { + *effect_type = GRADIENT_DELTA; + return true; + } + return false; +} + +/** + * + */ +static bool tux_cmd_parser_parse_raw_cmd(tokens_t tokens, int nr_tokens) { raw_frame data = {0, 0, 0, 0}; @@ -779,12 +896,11 @@ executed directly todo: -define data structure for parameters -write data to parameters -some functions do not have a check for correctness -(reading effect_type and final_state); add execute function +enter cmd in queue +retrieve cmd and execute it remove old code (cmd param in struct, old parsing code etc) +test! */ @@ -808,10 +924,8 @@ } else if (strcmp(tokens[2], "MUTE") == 0) { - bool value; - cmd->sub_command = MUTE; - if (str_to_bool(tokens[3], &value)) + if (str_to_bool(tokens[3], &cmd->audio_parameters.muteflag)) { // write to struct ret = E_TUXDRV_NOERROR; @@ -840,29 +954,19 @@ } else if (strcmp(tokens[2], "ON") == 0) { - unsigned char counter; - cmd->sub_command = ON; - if (str_to_uint8(tokens[3], &counter)) + if (str_to_uint8(tokens[3], &cmd->eyes_parameters.nr_movements) && + str_to_state_t(tokens[4], &cmd->eyes_parameters.state)) { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - // write to struct ret = E_TUXDRV_NOERROR; } } else if (strcmp(tokens[2], "ON_DURING") == 0) { - float timeout = 0; - cmd->sub_command = ON_DURING; - if (str_to_float(tokens[3], &timeout)) + if (str_to_float(tokens[3], &cmd->eyes_parameters.duration) && + str_to_state_t(tokens[4], &cmd->eyes_parameters.state)) { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - // write to struct ret = E_TUXDRV_NOERROR; } } @@ -895,12 +999,8 @@ else if (strcmp(tokens[2], "SEND") == 0) { cmd->sub_command = SEND; - unsigned char address; - unsigned char command; - - // write to struct - if (str_to_uint8(tokens[3], &address) && - str_to_uint8(tokens[4], &command)) + if (str_to_uint8(tokens[3], &cmd->ir_parameters.address) && + str_to_uint8(tokens[4], &cmd->ir_parameters.command)) { ret = E_TUXDRV_NOERROR; } @@ -916,68 +1016,52 @@ parse_tux_led_command(tokens_t tokens, delay_cmd_t *cmd) { TuxDrvError ret = E_TUXDRV_INVALIDCOMMAND; - leds_t leds; - leds = conststr_to_ledval(tokens[3]); // check if ok - - if (strcmp(tokens[2], "BLINK") == 0) + if (str_to_leds_t(tokens[3], &cmd->led_parameters.leds)) { - unsigned char pulse_count; - float pulse_period; - - cmd->sub_command = BLINK; - if (str_to_uint8(tokens[4], &pulse_count) && - str_to_float(tokens[5], &pulse_period)) + if (strcmp(tokens[2], "BLINK") == 0) { - ret = E_TUXDRV_NOERROR; + cmd->sub_command = BLINK; + if (str_to_uint8(tokens[4], &cmd->led_parameters.nr_blinks) && + str_to_float(tokens[5], &cmd->led_parameters.duration)) + { + ret = E_TUXDRV_NOERROR; + } } - } - else if (strcmp(tokens[2], "OFF") == 0) - { - cmd->sub_command = OFF; - ret = E_TUXDRV_NOERROR; - } - else if (strcmp(tokens[2], "ON") == 0) - { - cmd->sub_command = ON; - ret = E_TUXDRV_NOERROR; - } - else if (strcmp(tokens[2], "PULSE") == 0) - { - float min_intensity; - float max_intensity; - unsigned char pulse_count; - float pulse_period; - unsigned char effect_type; - float effect_speed; - unsigned char effect_step; - - cmd->sub_command = PULSE; - effect_type = conststr_to_effectval(tokens[8]); - if (str_to_float(tokens[4], &min_intensity) && - str_to_float(tokens[5], &max_intensity) && - str_to_uint8(tokens[6], &pulse_count) && - str_to_float(tokens[7], &pulse_period) && - str_to_float(tokens[9], &effect_speed) && - str_to_uint8(tokens[10], &effect_step)) + else if (strcmp(tokens[2], "OFF") == 0) { + cmd->sub_command = OFF; ret = E_TUXDRV_NOERROR; } - } - else if (strcmp(tokens[2], "SET") == 0) - { - float intensity; - unsigned char effect_type; - float effect_speed; - unsigned char effect_step; - - cmd->sub_command = SET; - effect_type = conststr_to_effectval(tokens[5]); - if (str_to_float(tokens[4], &intensity) && - str_to_float(tokens[6], &effect_speed) && - str_to_uint8(tokens[7], &effect_step)) + else if (strcmp(tokens[2], "ON") == 0) { + cmd->sub_command = ON; ret = E_TUXDRV_NOERROR; } + else if (strcmp(tokens[2], "PULSE") == 0) + { + cmd->sub_command = PULSE; + if (str_to_float(tokens[4], &cmd->led_parameters.min_intensity) && + str_to_float(tokens[5], &cmd->led_parameters.max_intensity) && + str_to_uint8(tokens[6], &cmd->led_parameters.pulse_count) && + str_to_float(tokens[7], &cmd->led_parameters.pulse_period) && + str_to_effect_type(tokens[8], &cmd->led_parameters.effect_type) && + str_to_float(tokens[9], &cmd->led_parameters.effect_speed) && + str_to_uint8(tokens[10], &cmd->led_parameters.effect_step)) + { + ret = E_TUXDRV_NOERROR; + } + } + else if (strcmp(tokens[2], "SET") == 0) + { + cmd->sub_command = SET; + if (str_to_float(tokens[4], &cmd->led_parameters.intensity) && + str_to_effect_type(tokens[5], &cmd->led_parameters.effect_type) && + str_to_float(tokens[6], &cmd->led_parameters.effect_speed) && + str_to_uint8(tokens[7], &cmd->led_parameters.effect_step)) + { + ret = E_TUXDRV_NOERROR; + } + } } return ret; } @@ -1002,29 +1086,19 @@ } else if (strcmp(tokens[2], "ON") == 0) { - unsigned char counter; - cmd->sub_command = ON; - if (str_to_uint8(tokens[3], &counter)) + if (str_to_uint8(tokens[3], &cmd->mouth_parameters.nr_movements) && + str_to_state_t(tokens[4], &cmd->mouth_parameters.state)) { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - // write to struct ret = E_TUXDRV_NOERROR; } } else if (strcmp(tokens[2], "ON_DURING") == 0) { - float timeout = 0; - cmd->sub_command = ON_DURING; - if (str_to_float(tokens[3], &timeout)) + if (str_to_float(tokens[3], &cmd->mouth_parameters.duration) && + str_to_state_t(tokens[4], &cmd->mouth_parameters.state)) { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - // write to struct ret = E_TUXDRV_NOERROR; } } @@ -1046,12 +1120,9 @@ if (strcmp(tokens[2], "PLAY") == 0) { - unsigned char track_num = 1; - float volume = 0; - cmd->sub_command = PLAY; - if (str_to_uint8(tokens[3], &track_num) && - str_to_float(tokens[4], &volume)) + if (str_to_uint8(tokens[3], &cmd->sound_flash_parameters.track) && + str_to_float(tokens[4], &cmd->sound_flash_parameters.volume)) { ret = E_TUXDRV_NOERROR; } @@ -1069,40 +1140,32 @@ if (strcmp(tokens[2], "LEFT_ON") == 0) { - unsigned char speed; - cmd->sub_command = LEFT_ON; - if (str_to_uint8(tokens[3], &speed)) + if (str_to_uint8(tokens[3], &cmd->spinning_parameters.nr_qturns)) { ret = E_TUXDRV_NOERROR; } } else if (strcmp(tokens[2], "LEFT_ON_DURING") == 0) { - float timeout; - cmd->sub_command = LEFT_ON_DURING; - if (str_to_float(tokens[3], &timeout)) + if (str_to_float(tokens[3], &cmd->spinning_parameters.duration)) { ret = E_TUXDRV_NOERROR; } } else if (strcmp(tokens[2], "RIGHT_ON") == 0) { - unsigned char speed; - cmd->sub_command = RIGHT_ON; - if (str_to_uint8(tokens[3], &speed)) + if (str_to_uint8(tokens[3], &cmd->spinning_parameters.nr_qturns)) { ret = E_TUXDRV_NOERROR; } } else if (strcmp(tokens[2], "RIGHT_ON_DURING") == 0) { - float timeout; - cmd->sub_command = RIGHT_ON_DURING; - if (str_to_float(tokens[3], &timeout)) + if (str_to_float(tokens[3], &cmd->spinning_parameters.duration)) { ret = E_TUXDRV_NOERROR; } @@ -1114,10 +1177,8 @@ } else if (strcmp(tokens[2], "SPEED") == 0) { - unsigned char speed; - cmd->sub_command = SPEED; - if (str_to_uint8(tokens[3], &speed)) + if (str_to_uint8(tokens[3], &cmd->spinning_parameters.speed)) { ret = E_TUXDRV_NOERROR; } @@ -1145,29 +1206,19 @@ } else if (strcmp(tokens[2], "ON") == 0) { - unsigned char counter; - cmd->sub_command = ON; - if (str_to_uint8(tokens[3], &counter)) + if (str_to_uint8(tokens[3], &cmd->wings_parameters.nr_movements) && + str_to_state_t(tokens[4], &cmd->wings_parameters.state)) { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - // write to struct ret = E_TUXDRV_NOERROR; } } else if (strcmp(tokens[2], "ON_DURING") == 0) { - float timeout = 0; - cmd->sub_command = ON_DURING; - if (str_to_float(tokens[3], &timeout)) + if (str_to_float(tokens[3], &cmd->wings_parameters.duration) && + str_to_state_t(tokens[4], &cmd->wings_parameters.state)) { - unsigned char final_state; - - final_state = tux_movement_conststr_to_val(tokens[4]); - // write to struct ret = E_TUXDRV_NOERROR; } cmd->sub_command = ON_DURING; @@ -1180,10 +1231,8 @@ } else if (strcmp(tokens[2], "SPEED") == 0) { - unsigned char speed; - cmd->sub_command = SPEED; - if (str_to_uint8(tokens[3], &speed)) + if (str_to_uint8(tokens[3], &cmd->wings_parameters.speed)) { ret = E_TUXDRV_NOERROR; } @@ -1249,11 +1298,21 @@ parse_raw_command(tokens_t tokens, delay_cmd_t *cmd) { TuxDrvError ret = E_TUXDRV_INVALIDCOMMAND; + int r = 0; + int i; - /* - tokens [1] to tokens[6] should be hex - */ - ret = E_TUXDRV_NOERROR; + for (i = 0; i < TUX_SEND_LENGTH; i++) + { + if (hex_to_uint8(tokens[i], &cmd->raw_parameters.raw[i])) + { + r++; + } + } + + if (r == TUX_SEND_LENGTH) + { + ret = E_TUXDRV_NOERROR; + } 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-05 19:56:40 UTC (rev 1104) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_types.h 2008-05-05 20:04:46 UTC (rev 1105) @@ -68,9 +68,10 @@ } tux_sub_command_t; typedef enum { + UNDEFINED, CLOSED, - NDEF, - OPENED + OPENED, + STOP } state_t; typedef struct { @@ -97,7 +98,7 @@ float max_intensity; unsigned char pulse_count; float pulse_period; - // effect type + effect_type_t effect_type; float effect_speed; unsigned char effect_step; } led_parameters_t; @@ -105,6 +106,7 @@ typedef struct { unsigned char nr_movements; state_t state; + float duration; } mouth_parameters_t; typedef struct { @@ -121,6 +123,8 @@ typedef struct { unsigned char nr_movements; state_t state; + float duration; + unsigned char speed; } wings_parameters_t; typedef struct { @@ -146,7 +150,7 @@ spinning_parameters_t spinning_parameters; wings_parameters_t wings_parameters; raw_parameters_t raw_parameters; - } parameters; + }; char cmd[CMDSIZE]; } delay_cmd_t; |