From c210f9167be5bb4b8ac63faf1817e086c8d94ed7 Mon Sep 17 00:00:00 2001 From: "Michael J. Chudobiak" Date: Wed, 15 Aug 2012 20:42:24 -0400 Subject: initial support for read/write commands on packed flash struct --- parser.c | 357 +++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 268 insertions(+), 89 deletions(-) (limited to 'parser.c') diff --git a/parser.c b/parser.c index e59cb23..60025d0 100644 --- a/parser.c +++ b/parser.c @@ -39,6 +39,10 @@ static int Is_Max_Command(char *text); static int Go_freq_32_33(gchar** response, int channel, char *parameter,char *units,int command_type); static int Go_syst_err_11(gchar** response, int channel, char *parameter,char *units,int command_type); static int Go_syst_errcnt66(gchar** response, int channel, char *parameter,char *units,int command_type); +static int Go_Str_eprom_47(gchar** response, int channel, char *loc_string,char *store_string,int command_type); +static int Go_int_eprom_48(gchar** response, int channel, char *loc_string,char *store_string,int command_type); +static int Go_Float_eprom51(gchar** response, int channel, char *loc_string,char *store_string,int command_type); +static int Go_char_eprom_70(gchar** response, int channel, char *loc_string,char *store_string,int command_type); static int Go_eprom_siz_86(gchar** response, int channel, int command_type); @@ -514,35 +518,35 @@ static gchar* filter_input (gchar *raw_in) gchar *step1 = g_strdup (raw_in); // replace multiple whitespace with single space - GRegex *strip_space = g_regex_new ("\\s+", 0, 0, NULL); + GRegex *strip_space = g_regex_new ("\\s+", 0, 0, NULL); gchar *step2 = g_regex_replace_literal (strip_space, step1, -1, 0, " ", 0, NULL); g_regex_unref (strip_space); g_free (step1); - // remove spaces before and after semicolons in compound messages - GRegex *semi_space = g_regex_new ("\\s*;\\s*", 0, 0, NULL); - gchar *step3 = g_regex_replace_literal (semi_space, step2, -1, 0, ";", 0, NULL); - g_regex_unref (semi_space); - g_free (step2); + // remove spaces before and after semicolons in compound messages + GRegex *semi_space = g_regex_new ("\\s*;\\s*", 0, 0, NULL); + gchar *step3 = g_regex_replace_literal (semi_space, step2, -1, 0, ";", 0, NULL); + g_regex_unref (semi_space); + g_free (step2); // remove semicolon at end GRegex *end_semi = g_regex_new (";$", 0, 0, NULL); - gchar *step4 = g_regex_replace_literal (end_semi, step3, -1, 0, "", 0, NULL); + gchar *step4 = g_regex_replace_literal (end_semi, step3, -1, 0, "", 0, NULL); g_regex_unref (end_semi); - g_free (step3); + g_free (step3); - // remove leading spaces, colons, semicolons - GRegex *leading = g_regex_new ("^[\\s:;]*", 0, 0, NULL); - gchar *step5 = g_regex_replace_literal (leading, step4, -1, 0, "", 0, NULL); - g_regex_unref (leading); - g_free (step4); + // remove leading spaces, colons, semicolons + GRegex *leading = g_regex_new ("^[\\s:;]*", 0, 0, NULL); + gchar *step5 = g_regex_replace_literal (leading, step4, -1, 0, "", 0, NULL); + g_regex_unref (leading); + g_free (step4); // last step may leave hanging whitespace at end g_strstrip (step5); // add single space to terminate gchar *filt = g_strdup_printf ("%s ", step5); - g_free (step5); + g_free (step5); return filt; } @@ -730,9 +734,23 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer case 33: error_num=Go_freq_32_33(&response,channel,parameter,units,command_type); break; + case 47: + error_num=Go_Str_eprom_47(&response,channel,parameter,units,command_type); + break; + case 48: + error_num=Go_int_eprom_48(&response,channel,parameter,units,command_type); + break; + case 51: + error_num=Go_Float_eprom51(&response,channel,parameter,units,command_type); + break; + case 66: error_num=Go_syst_errcnt66(&response,channel,parameter,units,command_type); break; + case 70: + error_num=Go_char_eprom_70(&response,channel,parameter,units,command_type); + break; + case 86: error_num=Go_eprom_siz_86(&response,channel,command_type); break; @@ -860,17 +878,178 @@ static int Go_freq_32_33(gchar** response, int channel, char *parameter,char *un } +static int Go_Str_eprom_47(gchar** response, int channel, char *loc_string,char *store_string,int command_type) +{ + /* diag:eprom:string - 47 */ + int eprom_loc; + + eprom_loc = atoi(loc_string); + /* convert location string to a number */ + + if ((eprom_loc < 0) || (eprom_loc>sizeof(globals.Flash))) { + return OutOfRange; + } + + switch (command_type) { + case command_param_units: + if ( (strlen(store_string) < LCD_cols) && (eprom_loc >= 0)) { + int i; + for (i=0; isizeof(globals.Flash))) { + return OutOfRange; + } + + switch (command_type) { + case command_param_units: + the_number=atoi(store_string); + *(short *)(&globals.Flash.flash_start + eprom_loc)=(short) the_number; + writeUserBlock(eprom_loc,sizeof(the_number)); + return OK; + break; + + case query_param: + return query_int (response, (int) *(short *)(&globals.Flash.flash_start + eprom_loc)); + break; + + default: + return SyntaxError; + break; + } +} + + +static int Go_Float_eprom51(gchar** response, int channel, char *loc_string,char *store_string,int command_type) +{ + /* diag:eprom:float - 51 */ + int eprom_loc; + int i; + float the_number; + + eprom_loc = atoi(loc_string); + + /* convert location string to a number */ + + if ((eprom_loc < 0) || (eprom_loc>sizeof(globals.Flash))) { + return OutOfRange; + } + + switch (command_type) { + case command_param_units: + the_number=atof(store_string); + *(float *)(&globals.Flash.flash_start + eprom_loc)=the_number; + writeUserBlock(eprom_loc,sizeof(the_number)); + + return OK; + break; + + case query_param: + return query_float(response, *(float *)(&globals.Flash.flash_start + eprom_loc)); + break; + + default: + return SyntaxError; + break; + } +} + + +static int Go_char_eprom_70(gchar** response, int channel, char *loc_string,char *store_string,int command_type) +{ + /* diag:eprom:char - 70 */ + int eprom_loc; + int i; + char the_number; + + eprom_loc = atoi(loc_string); + /* convert location string to a number */ + + if ((eprom_loc < 0) || (eprom_loc>sizeof(globals.Flash))) { + return OutOfRange; + } + + switch (command_type) { + case command_param_units: + the_number=(char) atoi(store_string); + *(char *)(&globals.Flash.flash_start + eprom_loc)=the_number; + writeUserBlock(eprom_loc,sizeof(the_number)); + + return OK; + break; + + case query_param: + return query_int (response, (int) *(char *)(&globals.Flash.flash_start + eprom_loc)); + break; + + default: + return SyntaxError; + break; + } +} + + static int Go_eprom_siz_86(gchar** response, int channel, int command_type) { - switch (command_type) { - case query_simple: - return query_int (response, sizeof(globals.Flash)); - break; - - default: - return SyntaxError; - break; - } + char x_char; + short x_short; + int x_int; + float x_float; + double x_double; + + // FIXME + g_printf ("char %d, short %d, int %d, float %d, double %d\n\r",sizeof(x_char),sizeof(x_short),sizeof(x_int),sizeof(x_float),sizeof(x_double)); + + g_printf ("flash_start: %ld\n\r", (gpointer) &globals.Flash.flash_start - (gpointer) &globals.Flash.flash_start); + g_printf ("channels: %ld\n\r", (gpointer) &globals.Flash.channels - (gpointer) &globals.Flash.flash_start); + g_printf ("aux_error_message: %ld, %s\n\r", (gpointer) &globals.Flash.aux_error_message - (gpointer) &globals.Flash.flash_start, globals.Flash.aux_error_message); + g_printf ("enable_avrq_extra_ampls: %ld\n\r", (gpointer) &globals.Flash.enable_avrq_extra_ampls - (gpointer) &globals.Flash.flash_start); + g_printf ("ChanKey_frequency: %ld\n\r", (gpointer) &globals.Flash.ChanKey_frequency - (gpointer) &globals.Flash.flash_start); + g_printf ("flash_end: %ld\n\r", (gpointer) &globals.Flash.flash_end - (gpointer) &globals.Flash.flash_start); + + + switch (command_type) { + case query_simple: + return query_int (response, sizeof(globals.Flash)); + break; + + default: + return SyntaxError; + break; + } } @@ -975,18 +1154,18 @@ static int query_int (gchar** response, int n) static int query_min_max_int (gchar** response, char *parameter, int min_val, int max_val) { - int report_val; - - if (Is_Min_Command(parameter)) { - report_val=min_val; - } else if (Is_Max_Command(parameter)) { - report_val=max_val; - } else { - return SyntaxError; - } - - *response = g_strdup_printf ("%d", report_val); - return OK; + int report_val; + + if (Is_Min_Command(parameter)) { + report_val=min_val; + } else if (Is_Max_Command(parameter)) { + report_val=max_val; + } else { + return SyntaxError; + } + + *response = g_strdup_printf ("%d", report_val); + return OK; } static int query_min_max_float (gchar** response, char *parameter, float min_val, float max_val) @@ -1053,76 +1232,76 @@ static int process_float_param (char *parameter, float *value, float min_val, fl #define NO_ON_OFF 1 static int process_int_param (char *parameter, int *value, int item_count, int *valid_nums, int allow_on_off) { - int status, i, min_val, max_val, is_valid; - - status = OK; - is_valid = 0; - - min_val = valid_nums[0]; - max_val = valid_nums[item_count - 1]; - - if (String_is_it_numeric(parameter)) { - *value = atoi(parameter); - for (i = 0; (i < item_count) && (is_valid == 0); i++) { - if (*value == valid_nums[i]) { - is_valid = 1; - } - } - if (is_valid == 0) { - status = IllegalParameter; - } - } else if (!strcmp(parameter,"off") && (allow_on_off == USE_ON_OFF)) { - *value = 0; - } else if (!strcmp(parameter,"on") && (allow_on_off == USE_ON_OFF)) { - *value = 1; - } else if (Is_Min_Command(parameter) && (allow_on_off == NO_ON_OFF)) { - *value = min_val; - } else if (Is_Max_Command(parameter) && (allow_on_off == NO_ON_OFF)) { - *value = max_val; - } else { - status=SyntaxError; - } - - return status; + int status, i, min_val, max_val, is_valid; + + status = OK; + is_valid = 0; + + min_val = valid_nums[0]; + max_val = valid_nums[item_count - 1]; + + if (String_is_it_numeric(parameter)) { + *value = atoi(parameter); + for (i = 0; (i < item_count) && (is_valid == 0); i++) { + if (*value == valid_nums[i]) { + is_valid = 1; + } + } + if (is_valid == 0) { + status = IllegalParameter; + } + } else if (!strcmp(parameter,"off") && (allow_on_off == USE_ON_OFF)) { + *value = 0; + } else if (!strcmp(parameter,"on") && (allow_on_off == USE_ON_OFF)) { + *value = 1; + } else if (Is_Min_Command(parameter) && (allow_on_off == NO_ON_OFF)) { + *value = min_val; + } else if (Is_Max_Command(parameter) && (allow_on_off == NO_ON_OFF)) { + *value = max_val; + } else { + status=SyntaxError; + } + + return status; } static int process_int_range (char *parameter, int *value, int min_val, int max_val) { - int status; - status = OK; - - if (String_is_it_numeric(parameter)) { - *value = atoi(parameter); - if ((*valuemax_val)) { - status = OutOfRange; - } - } else if (Is_Min_Command(parameter)) { - *value = min_val; - } else if (Is_Max_Command(parameter)) { - *value = max_val; - } else { - status=SyntaxError; - } - - return status; + int status; + status = OK; + + if (String_is_it_numeric(parameter)) { + *value = atoi(parameter); + if ((*valuemax_val)) { + status = OutOfRange; + } + } else if (Is_Min_Command(parameter)) { + *value = min_val; + } else if (Is_Max_Command(parameter)) { + *value = max_val; + } else { + status=SyntaxError; + } + + return status; } static int process_on_off (char *parameter, int *value) { - int valid_choices[2] = {0, 1}; - return process_int_param (parameter, value, 2, valid_choices, USE_ON_OFF); + int valid_choices[2] = {0, 1}; + return process_int_param (parameter, value, 2, valid_choices, USE_ON_OFF); } static int process_two_ints (char *parameter, int *value, int min, int max) { - int valid_choices[2] = {min, max}; - return process_int_param (parameter, value, 2, valid_choices, NO_ON_OFF); + int valid_choices[2] = {min, max}; + return process_int_param (parameter, value, 2, valid_choices, NO_ON_OFF); } static int process_four_ints (char *parameter, int *value, int v1, int v2, int v3, int v4) { - int valid_choices[4] = {v1, v2, v3, v4}; - return process_int_param (parameter, value, 4, valid_choices, NO_ON_OFF); + int valid_choices[4] = {v1, v2, v3, v4}; + return process_int_param (parameter, value, 4, valid_choices, NO_ON_OFF); } static int check_channel_ok (int channel, int enabled_channels, char chankey) -- cgit