From d86fbe35ca2563b5f5fc2665014483cbc17837f5 Mon Sep 17 00:00:00 2001 From: Alden Hart Date: Mon, 12 Dec 2016 07:49:34 -0500 Subject: [PATCH] Continue to refactor accessors to remove them as a block to removing singletons; added error messages for inout values under/over range; added accessors for text verbosity --- g2core/config.cpp | 2 +- g2core/config_app.cpp | 37 +++++++++++++++++++++++++++++-------- g2core/g2core.cppproj | 8 ++++---- g2core/json_parser.cpp | 12 +++++------- g2core/json_parser.h | 4 ++-- g2core/text_parser.cpp | 13 +++++++++++++ g2core/text_parser.h | 3 +++ 7 files changed, 57 insertions(+), 22 deletions(-) mode change 100755 => 100644 g2core/json_parser.h mode change 100755 => 100644 g2core/text_parser.h diff --git a/g2core/config.cpp b/g2core/config.cpp index e6e73585..786ea4c2 100644 --- a/g2core/config.cpp +++ b/g2core/config.cpp @@ -682,7 +682,7 @@ nvObj_t *nv_add_string(const char *token, const char *string) // add a string ob nvObj_t *nv_add_conditional_message(const char *string) // conditionally add a message object to the body { - if ((js.json_mode == JSON_MODE) && (js.echo_json_messages != true)) { return (NULL);} + if ((js.json_mode == JSON_MODE) && (js.echo_json_messages != true)) { return (NULL); } return(nv_add_string((const char *)"msg", string)); } diff --git a/g2core/config_app.cpp b/g2core/config_app.cpp index 771490c7..6d8f3a90 100644 --- a/g2core/config_app.cpp +++ b/g2core/config_app.cpp @@ -637,10 +637,10 @@ const cfgItem_t cfgArray[] = { // Communications and reporting parameters #ifdef __TEXT_MODE - { "sys","tv", _fipn, 0, tx_print_tv, get_ui8, set_01, (float *)&txt.text_verbosity, TEXT_VERBOSITY }, + { "sys","tv", _fipn, 0, tx_print_tv, txt_get_tv, txt_set_tv, (float *)&cs.null, TEXT_VERBOSITY }, #endif - { "sys","ej", _fipn, 0, js_print_ej, get_ui8, json_set_ej,(float *)&cs.comm_mode, COMM_MODE }, - { "sys","jv", _fipn, 0, js_print_jv, get_ui8, json_set_jv,(float *)&js.json_verbosity, JSON_VERBOSITY }, + { "sys","ej", _fipn, 0, js_print_ej, get_ui8, js_set_ej,(float *)&cs.comm_mode, COMM_MODE }, + { "sys","jv", _fipn, 0, js_print_jv, get_ui8, js_set_jv,(float *)&js.json_verbosity, JSON_VERBOSITY }, { "sys","qv", _fipn, 0, qr_print_qv, get_ui8, set_0123, (float *)&qr.queue_report_verbosity, QUEUE_REPORT_VERBOSITY }, { "sys","sv", _fipn, 0, sr_print_sv, get_ui8, set_012, (float *)&sr.status_report_verbosity,STATUS_REPORT_VERBOSITY }, { "sys","si", _fipn, 0, sr_print_si, get_int32,sr_set_si, (float *)&sr.status_report_interval, STATUS_REPORT_INTERVAL_MS }, @@ -1055,10 +1055,21 @@ stat_t set_float(nvObj_t *nv, float &value) { } stat_t set_float_range(nvObj_t *nv, float &value, float low, float high) { + + char msg[64]; + process_incoming_float(nv); // conditional unit conversion - if ((nv->value < low) || (nv->value > high)) { + if (nv->value < low) { + sprintf(msg, "Input is less than minimum value %0.4f", low); + nv_add_conditional_message(msg); nv->valuetype = TYPE_NULL; - return (STAT_INPUT_VALUE_RANGE_ERROR); + return (STAT_INPUT_LESS_THAN_MIN_VALUE); + } + if (nv->value > high) { + sprintf(msg, "Input is more than maximum value %0.4f", high); + nv_add_conditional_message(msg); + nv->valuetype = TYPE_NULL; + return (STAT_INPUT_EXCEEDS_MAX_VALUE); } value = nv->value; return (STAT_OK); @@ -1077,11 +1088,21 @@ stat_t get_int(nvObj_t *nv, const uint8_t value) { stat_t set_int(nvObj_t *nv, uint8_t &value, uint8_t low, uint8_t high) { - if ((nv->value < low) || (nv->value > high)) { + char msg[64]; + + if (nv->value < low) { + sprintf(msg, "Input is less than minimum value %d", (int)low); + nv_add_conditional_message(msg); nv->valuetype = TYPE_NULL; - return (STAT_INPUT_VALUE_RANGE_ERROR); + return (STAT_INPUT_LESS_THAN_MIN_VALUE); } - value = nv->value; + if (nv->value > high) { + sprintf(msg, "Input is more than maximum value %d", (int)high); + nv_add_conditional_message(msg); + nv->valuetype = TYPE_NULL; + return (STAT_INPUT_EXCEEDS_MAX_VALUE); + } + value = nv->value; // note: valuetype = TYPE_INT already set return (STAT_OK); } diff --git a/g2core/g2core.cppproj b/g2core/g2core.cppproj index 504c10bd..bf644c0b 100644 --- a/g2core/g2core.cppproj +++ b/g2core/g2core.cppproj @@ -68,12 +68,12 @@ - 2000000 + 7992324 SWD com.atmel.avrdbg.tool.atmelice - J41800036434 + J41800030015 Atmel-ICE True @@ -100,9 +100,9 @@ True true - J41800036434 + J41800030015 0x284E0A60 - 2000000 + 7992324 diff --git a/g2core/json_parser.cpp b/g2core/json_parser.cpp index 3dbb2c87..51f14269 100644 --- a/g2core/json_parser.cpp +++ b/g2core/json_parser.cpp @@ -609,14 +609,11 @@ void json_print_response(uint8_t status) ***********************************************************************************/ /* - * json_set_jv() + * js_set_jv() */ -stat_t json_set_jv(nvObj_t *nv) +stat_t js_set_jv(nvObj_t *nv) { -// if ((uint8_t)nv->value >= JV_MAX_VALUE) { return (STAT_INPUT_EXCEEDS_MAX_VALUE);} -// js.json_verbosity = (jsonVerbosity)nv->value; - ritorno (set_int(nv, (uint8_t &)js.json_verbosity, 0, JV_MAX_VALUE)); js.echo_json_footer = false; @@ -640,11 +637,12 @@ stat_t json_set_jv(nvObj_t *nv) } /* - * json_set_ej() - set JSON communications mode + * js_set_ej() - set JSON communications mode */ -stat_t json_set_ej(nvObj_t *nv) +stat_t js_set_ej(nvObj_t *nv) { +// ritorno (set_int(nv, cs.comm_mode, TEXT_MODE, AUTO_MODE)); if ((nv->value < TEXT_MODE) || (nv->value > AUTO_MODE)) { nv->valuetype = TYPE_NULL; return (STAT_INPUT_VALUE_RANGE_ERROR); diff --git a/g2core/json_parser.h b/g2core/json_parser.h old mode 100755 new mode 100644 index e379ede3..e80ca5bf --- a/g2core/json_parser.h +++ b/g2core/json_parser.h @@ -88,8 +88,8 @@ void json_print_object(nvObj_t *nv); void json_print_response(uint8_t status); void json_print_list(stat_t status, uint8_t flags); -stat_t json_set_jv(nvObj_t *nv); -stat_t json_set_ej(nvObj_t *nv); +stat_t js_set_jv(nvObj_t *nv); +stat_t js_set_ej(nvObj_t *nv); #ifdef __TEXT_MODE diff --git a/g2core/text_parser.cpp b/g2core/text_parser.cpp index c731553d..7e085664 100644 --- a/g2core/text_parser.cpp +++ b/g2core/text_parser.cpp @@ -282,4 +282,17 @@ void text_print(nvObj_t *nv, const char *format) { static const char fmt_tv[] = "[tv] text verbosity%15d [0=silent,1=verbose]\n"; void tx_print_tv(nvObj_t *nv) { text_print(nv, fmt_tv);} // TYPE_INT +/*********************************************************************************** + * CONFIGURATION AND INTERFACE FUNCTIONS + * Functions to get and set variables from the cfgArray table + ***********************************************************************************/ + +/* + * txt_get_tv() - get text verbosity setting + * txt_set_tv() - set text verbosity + */ + +stat_t txt_get_tv(nvObj_t *nv) { return (get_int(nv, txt.text_verbosity)); } +stat_t txt_set_tv(nvObj_t *nv) { return (set_int(nv, txt.text_verbosity, TV_SILENT, TV_VERBOSE)); } + #endif // __TEXT_MODE diff --git a/g2core/text_parser.h b/g2core/text_parser.h old mode 100755 new mode 100644 index 6c300c94..2b37ea11 --- a/g2core/text_parser.h +++ b/g2core/text_parser.h @@ -95,4 +95,7 @@ stat_t text_parser_stub(char* str); void text_response_stub(const stat_t status, char* buf); void text_print_list_stub(stat_t status, uint8_t flags); +stat_t txt_get_tv(nvObj_t *nv); +stat_t txt_set_tv(nvObj_t *nv); + #endif // End of include guard: TEXT_PARSER_H_ONCE