summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-11-14 11:15:58 -0500
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-11-14 11:15:58 -0500
commitb49a4e3d3f5e4005c4b1070979b7510011862233 (patch)
tree574be7edd3afa7db3c654457d14ed9dbd8f411e4
parent5e8c4720b8406764b5911d74898c63649d5d5802 (diff)
use GStrings instead of fixed length strings in self-cal
-rw-r--r--device-functions.c14
-rw-r--r--globals.h2
-rw-r--r--parser.c3
3 files changed, 13 insertions, 6 deletions
diff --git a/device-functions.c b/device-functions.c
index f2b3cd3..aca5cd3 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -4037,7 +4037,7 @@ int go_cal(CalStruct *caldata)
void cal_string(char *parameter, CalStruct *caldata)
{
gchar *string = g_strdup_printf ("CH%d %s cal: %d errors. Adj: %6.2f%% max, %6.2f%% avg.\r\n", caldata->channel+1,parameter, caldata->error, caldata->max_change, caldata->avg_change);
- strcat (caldata->response, string);
+ g_string_append (caldata->response, string);
g_free (string);
}
@@ -4045,7 +4045,12 @@ void cal_string(char *parameter, CalStruct *caldata)
int self_cal()
{
CalStruct caldata;
- return do_full_self_cal(&caldata);
+
+ int status = do_full_self_cal(&caldata);
+
+ g_string_free (caldata.response, TRUE);
+
+ return status;
}
@@ -4055,6 +4060,8 @@ int do_full_self_cal(CalStruct *caldata)
long start_timer, diff_timer;
int eprom_loc;
+ caldata->response = g_string_new ("");
+
Menu_Clear_Buttons();
LCD_clear(); /*0123456789012345678901234567890123456789*/
LCD_write(0,0,"Self-calibration in progress.");
@@ -4073,7 +4080,6 @@ int do_full_self_cal(CalStruct *caldata)
}
start_timer = sec_timer();
- caldata->response[0] = 0;
caldata->total_errors = 0;
caldata->total_max_change = 0.0;
@@ -4127,7 +4133,7 @@ int do_full_self_cal(CalStruct *caldata)
globals.Flash.self_cal_typical_time_sec = (int) (diff_timer % 60);
string = g_strdup_printf ("Completed in %d minutes and %d seconds\r\n", globals.Flash.self_cal_typical_time_min, globals.Flash.self_cal_typical_time_sec);
- strcat (caldata->response, string);
+ g_string_append (caldata->response, string);
g_free (string);
eprom_loc = (char *) &(globals.Flash.self_cal_typical_time_min) - (char *) &(globals.Flash.flash_start);
diff --git a/globals.h b/globals.h
index 96cab87..a4b0745 100644
--- a/globals.h
+++ b/globals.h
@@ -304,7 +304,7 @@ typedef struct {
float avg_change;
int total_errors;
float total_max_change;
- char response[max_output_length];
+ GString *response;
} CalStruct;
diff --git a/parser.c b/parser.c
index 2f8a52c..791561d 100644
--- a/parser.c
+++ b/parser.c
@@ -3985,7 +3985,8 @@ static int Go_cal_100(gchar** response, int channel, char *parameter,char *units
case query_simple:
status = do_full_self_cal(&caldata);
if (!no_report) {
- query_string(response, caldata.response);
+ query_string(response, caldata.response->str);
+ g_string_free (caldata.response, TRUE);
}
return status;
break;