summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dummy_functions.c1
-rw-r--r--dummy_functions.h2
-rw-r--r--globals.c9
-rw-r--r--globals.h8
-rw-r--r--parser.c357
5 files changed, 280 insertions, 97 deletions
diff --git a/dummy_functions.c b/dummy_functions.c
index ffd4917..98d0afb 100644
--- a/dummy_functions.c
+++ b/dummy_functions.c
@@ -8,3 +8,4 @@ void GPIB_Set_Device_Dependent_Error() {}
void GPIB_Set_Execution_Error() {}
void Main_update_shift_registers() { }
void Error_check(void* p) { }
+void writeUserBlock(int addr, int numbytes) {}
diff --git a/dummy_functions.h b/dummy_functions.h
index aced9b3..f72ba6a 100644
--- a/dummy_functions.h
+++ b/dummy_functions.h
@@ -9,5 +9,5 @@ void GPIB_Set_Device_Dependent_Error();
void GPIB_Set_Execution_Error();
void Main_update_shift_registers();
void Error_check(void*);
-
+void writeUserBlock(int addr, int numbytes);
#endif
diff --git a/globals.c b/globals.c
index 15f210b..8324fed 100644
--- a/globals.c
+++ b/globals.c
@@ -2,10 +2,11 @@
GlobalStruct globals = {
.ChannelState = {0.0},
- .Flash = { .aux_error_message="FIXME",
- .channels = (int)1,
- .enable_avrq_extra_ampls = (char)0,
- .ChanKey_frequency = (char)0 },
+ .Flash = { .flash_start = (char) 99,
+ .aux_error_message="FIXME",
+ .channels = (short) 1,
+ .enable_avrq_extra_ampls = (char) 12,
+ .ChanKey_frequency = (char) 0 },
.error_queue = {0},
.number_of_errors = 0
};
diff --git a/globals.h b/globals.h
index 245fc12..a647a46 100644
--- a/globals.h
+++ b/globals.h
@@ -17,15 +17,17 @@ typedef struct {
// this will be enlarged later
} ChannelStruct;
+#pragma pack(push) /* push current alignment to stack */
+#pragma pack(1)
typedef struct {
char flash_start;
- char* aux_error_message;
- int channels;
+ short channels;
+ char aux_error_message[32];
char enable_avrq_extra_ampls;
char ChanKey_frequency;
char flash_end;
} FlashStruct;
-
+#pragma pack(pop)
typedef struct {
ChannelStruct ChannelState[max_channels];
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; i<strlen(store_string); ++i) {
+ /* convert ~ to spaces */
+ if (store_string[i]=='~') {
+ store_string[i]=' ';
+ }
+ *(char *)(&globals.Flash.flash_start + eprom_loc+i)=store_string[i];
+ }
+ *(char *)(&globals.Flash.flash_start + eprom_loc + i)=(char) 0; /* end of string */
+ writeUserBlock(eprom_loc,strlen(store_string)+1);
+ return OK;
+ } else {
+ return OutOfRange;
+ }
+ break;
+
+ case query_param:
+ return query_string (response, (char *)(&globals.Flash.flash_start + eprom_loc));
+ break;
+
+ default:
+ return SyntaxError;
+ break;
+ }
+}
+
+
+static int Go_int_eprom_48(gchar** response, int channel, char *loc_string,char *store_string,int command_type)
+{
+ /* diag:eprom:int - 48 */
+ int eprom_loc;
+ int i;
+ int 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=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 ((*value<min_val) || (*value>max_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 ((*value<min_val) || (*value>max_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)