summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dummy_functions.c2
-rw-r--r--dummy_functions.h2
-rw-r--r--parser.c32
-rw-r--r--parser.h2
-rw-r--r--response.c8
5 files changed, 20 insertions, 26 deletions
diff --git a/dummy_functions.c b/dummy_functions.c
index 71b4e83..16564e8 100644
--- a/dummy_functions.c
+++ b/dummy_functions.c
@@ -9,7 +9,7 @@ void GPIB_Set_Execution_Error() {}
void Main_update_shift_registers() { }
void IO_output_to_comm_bus(char* w, int n) { } //replace with real function
void Error_check(void* p) { }
-int query_int(char* resp, int n)
+int query_int(char** resp, int n)
{
return 0;
}
diff --git a/dummy_functions.h b/dummy_functions.h
index 9990ec7..d10e62b 100644
--- a/dummy_functions.h
+++ b/dummy_functions.h
@@ -10,6 +10,6 @@ void GPIB_Set_Execution_Error();
void Main_update_shift_registers();
void IO_output_to_comm_bus(char* w, int n);
void Error_check(void*);
-int query_int(char* resp, int n);
+int query_int(char** resp, int n);
#endif
diff --git a/parser.c b/parser.c
index f20867e..9d0fb98 100644
--- a/parser.c
+++ b/parser.c
@@ -26,7 +26,7 @@ static int Handle_Units(float *mult,char *units, char *base);
static int Is_Min_Command(char *text);
static int Is_Max_Command(char *text);
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_syst_errcnt66(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Parser_id_word(char *id_me, int *channel, int *with_id_code)
{
@@ -528,7 +528,7 @@ static int Parser_get_unit(char *parameter,char *units)
return units_present;
}
-void Parser_main (char *in, gchar** response, int allow_unrequested_responses)
+void Parser_main (char *in, int allow_unrequested_responses, void(*cbfunc)(gpointer, gchar *), gpointer user_data)
{
int in_pos; /* this identifies the single character of in being processed */
int command_depth; /* how many command words have been parsed */
@@ -550,7 +550,6 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses)
int compound_message; /* this indicates that at least one semicolon has been found, so */
/* the message is a compound one */
-// char response[max_output_length];
int is_query;
int command_type; /* combination of is_query, parameter_found, and units_found */
@@ -684,7 +683,8 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses)
/* add end of tokens marker (0) */
int error_num=OK;
- response[0]=0;
+ gchar *response = NULL;
+ gchar *error_response = NULL;
if (parameter_found) {
units_found = Parser_get_unit(parameter,units);
@@ -715,18 +715,18 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses)
switch (routine_num) {
case 0:
- *response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
+ response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
error_num=Unrecognized;
break;
case 11:
- error_num=Go_syst_err_11(response,channel,parameter,units,command_type);
+ error_num=Go_syst_err_11(&response,channel,parameter,units,command_type);
break;
case 32:
case 33:
- error_num=Go_freq_32_33(response,channel,parameter,units,command_type);
+ error_num=Go_freq_32_33(&response,channel,parameter,units,command_type);
break;
case 66:
- error_num=Go_syst_errcnt66(*response,channel,parameter,units,command_type);
+ error_num=Go_syst_errcnt66(&response,channel,parameter,units,command_type);
break;
case 9999:
@@ -735,24 +735,24 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses)
default:
/* valid but not implemented yet */
- *response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
+ response = g_strdup_printf("routine_num: %d, channel: %d, parameter: %s, units: %s, command type: %d\n\r",routine_num,channel,parameter,units,command_type);
break;
}
}
- // FIXME
if (error_num) {
- g_free (*response);
- *response = NULL;
- queue_error_from_parser(response, error_num);
+ queue_error_from_parser(&error_response, error_num);
if (allow_unrequested_responses) {
- ; // SEND ERROR RESPONSE TO CLIENT NOW!
+ (*cbfunc)(user_data, error_response);
}
} else {
- ; // SEND RESPONSE TO CLIENT NOW!
+ (*cbfunc)(user_data, response);
}
+ g_free (response);
+ g_free (error_response);
+
if (!is_query) {
Main_update_shift_registers(); /* update values in pulse generator circuit */
}
@@ -1024,7 +1024,7 @@ static int Go_syst_err_11(gchar** response, int channel, char *parameter,char *u
}
}
-static int Go_syst_errcnt66(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)
{
switch (command_type) {
case query_simple:
diff --git a/parser.h b/parser.h
index 7f5a710..df90407 100644
--- a/parser.h
+++ b/parser.h
@@ -29,6 +29,6 @@
#define USE_ON_OFF 0
#define NO_ON_OFF 1
-void Parser_main (char *in, gchar** response, int allow_unrequested_responses);
+void Parser_main (char *in, int allow_unrequested_responses, void(*cbfunc)(gpointer, gchar *), gpointer user_data);
#endif
diff --git a/response.c b/response.c
index d49baad..d6bfcc1 100644
--- a/response.c
+++ b/response.c
@@ -136,9 +136,6 @@ void responseCb(gpointer instance, GObject *arg1, gpointer user_data)
GPollableOutputStream* stream = (GPollableOutputStream*)data->outStream;
gchar* str = data->data;
-
- gchar* out = NULL;
-
g_strstrip(str);
// I2C/LCD test functions - start
@@ -148,10 +145,7 @@ void responseCb(gpointer instance, GObject *arg1, gpointer user_data)
// I2C/LCD test functions - stop
// FIXME - Parser_main may generate multiple responses
- Parser_main(str, &out, 1);
-
- data->cb(stream, out);
+ Parser_main(str, 1, data->cb, stream);
- g_free(out);
g_static_mutex_unlock (&mutex);
}