From 245e32ae1d21dd84f91763ceb9f30a3b3a2d2335 Mon Sep 17 00:00:00 2001 From: Alden Hart Date: Fri, 30 Dec 2016 10:39:49 -0500 Subject: [PATCH] Added proper JSON handling for read-only parameters; fixed string overflow in hw_get_id(). Now passes regressions in g2-0.99/002-config/02-settings/settings-version.json --- g2core/board/Archim/hardware.h | 2 +- g2core/board/ArduinoDue/hardware.h | 2 +- g2core/board/G2v9/hardware.h | 2 +- g2core/board/gquadratic/hardware.h | 2 +- g2core/board/gquintic/hardware.h | 2 +- g2core/board/printrboardg2/hardware.h | 2 +- g2core/board/sbv300/hardware.h | 2 +- g2core/config.cpp | 12 +++++++++--- g2core/config.h | 3 ++- g2core/config_app.cpp | 16 ++++++++-------- g2core/main.cpp | 2 +- 11 files changed, 27 insertions(+), 20 deletions(-) mode change 100755 => 100644 g2core/config.h mode change 100755 => 100644 g2core/main.cpp diff --git a/g2core/board/Archim/hardware.h b/g2core/board/Archim/hardware.h index 83241d87..e69d67ec 100644 --- a/g2core/board/Archim/hardware.h +++ b/g2core/board/Archim/hardware.h @@ -85,7 +85,7 @@ using Motate::OutputPin; #define MILLISECONDS_PER_TICK 1 // MS for system tick (systick * N) #define SYS_ID_DIGITS 12 // actual digits in system ID (up to 16) -#define SYS_ID_LEN 16 // total length including dashes and NUL +#define SYS_ID_LEN 24 // total length including dashes and NUL /************************************************************************************ **** ARM SAM3X8E SPECIFIC HARDWARE ************************************************* diff --git a/g2core/board/ArduinoDue/hardware.h b/g2core/board/ArduinoDue/hardware.h index 4eaa74bc..7a81cf07 100644 --- a/g2core/board/ArduinoDue/hardware.h +++ b/g2core/board/ArduinoDue/hardware.h @@ -87,7 +87,7 @@ using Motate::OutputPin; #define MILLISECONDS_PER_TICK 1 // MS for system tick (systick * N) #define SYS_ID_DIGITS 12 // actual digits in system ID (up to 16) -#define SYS_ID_LEN 16 // total length including dashes and NUL +#define SYS_ID_LEN 24 // total length including dashes and NUL /************************************************************************************ **** ARM SAM3X8E SPECIFIC HARDWARE ************************************************* diff --git a/g2core/board/G2v9/hardware.h b/g2core/board/G2v9/hardware.h index 607f19b7..ab0e9872 100644 --- a/g2core/board/G2v9/hardware.h +++ b/g2core/board/G2v9/hardware.h @@ -87,7 +87,7 @@ using Motate::OutputPin; #define MILLISECONDS_PER_TICK 1 // MS for system tick (systick * N) #define SYS_ID_DIGITS 12 // actual digits in system ID (up to 16) -#define SYS_ID_LEN 16 // total length including dashes and NUL +#define SYS_ID_LEN 24 // total length including dashes and NUL /************************************************************************************ **** ARM SAM3X8E SPECIFIC HARDWARE ************************************************* diff --git a/g2core/board/gquadratic/hardware.h b/g2core/board/gquadratic/hardware.h index ee0125aa..82abb8bc 100644 --- a/g2core/board/gquadratic/hardware.h +++ b/g2core/board/gquadratic/hardware.h @@ -87,7 +87,7 @@ using Motate::OutputPin; #define MILLISECONDS_PER_TICK 1 // MS for system tick (systick * N) #define SYS_ID_DIGITS 12 // actual digits in system ID (up to 16) -#define SYS_ID_LEN 16 // total length including dashes and NUL +#define SYS_ID_LEN 24 // total length including dashes and NUL /************************************************************************************ **** ARM SAM3X8E SPECIFIC HARDWARE ************************************************* diff --git a/g2core/board/gquintic/hardware.h b/g2core/board/gquintic/hardware.h index 14ff68b2..557b3c8c 100644 --- a/g2core/board/gquintic/hardware.h +++ b/g2core/board/gquintic/hardware.h @@ -86,7 +86,7 @@ using Motate::OutputPin; #define MILLISECONDS_PER_TICK 1 // MS for system tick (systick * N) #define SYS_ID_DIGITS 12 // actual digits in system ID (up to 16) -#define SYS_ID_LEN 16 // total length including dashes and NUL +#define SYS_ID_LEN 24 // total length including dashes and NUL /************************************************************************************ **** ARM SAM3X8E SPECIFIC HARDWARE ************************************************* diff --git a/g2core/board/printrboardg2/hardware.h b/g2core/board/printrboardg2/hardware.h index 3cafbcd1..3943f10d 100644 --- a/g2core/board/printrboardg2/hardware.h +++ b/g2core/board/printrboardg2/hardware.h @@ -85,7 +85,7 @@ using Motate::OutputPin; #define MILLISECONDS_PER_TICK 1 // MS for system tick (systick * N) #define SYS_ID_DIGITS 12 // actual digits in system ID (up to 16) -#define SYS_ID_LEN 16 // total length including dashes and NUL +#define SYS_ID_LEN 24 // total length including dashes and NUL /************************************************************************************ **** ARM SAM3X8E SPECIFIC HARDWARE ************************************************* diff --git a/g2core/board/sbv300/hardware.h b/g2core/board/sbv300/hardware.h index 148e89e2..4f424261 100644 --- a/g2core/board/sbv300/hardware.h +++ b/g2core/board/sbv300/hardware.h @@ -84,7 +84,7 @@ using Motate::OutputPin; #define MILLISECONDS_PER_TICK 1 // MS for system tick (systick * N) #define SYS_ID_DIGITS 12 // actual digits in system ID (up to 16) -#define SYS_ID_LEN 16 // total length including dashes and NUL +#define SYS_ID_LEN 24 // total length including dashes and NUL /************************************************************************************ **** ARM SAM3X8E SPECIFIC HARDWARE ************************************************* diff --git a/g2core/config.cpp b/g2core/config.cpp index 36166f2b..181264b9 100644 --- a/g2core/config.cpp +++ b/g2core/config.cpp @@ -239,7 +239,8 @@ stat_t get_flt(nvObj_t *nv) } /* Generic sets() - * set_nul() - set nothing + * set_nul() - set nothing, return OK + * set_ro() - set nothing, return read-only error * set_ui8() - set value as 8 bit uint8_t value * set_int8() - set value as an 8 bit int8_t value * set_01() - set a 0 or 1 uint8_t value with validation @@ -249,8 +250,13 @@ stat_t get_flt(nvObj_t *nv) * set_data() - set value as 32 bit integer blind cast * set_flt() - set value as float */ -//stat_t set_nul(nvObj_t *nv) { return (STAT_PARAMETER_IS_READ_ONLY); } -stat_t set_nul(nvObj_t *nv) { return (STAT_OK); } // hack until JSON is refactored + +stat_t set_nul(nvObj_t *nv) { return (STAT_OK); } + +stat_t set_ro(nvObj_t *nv) { + nv->valuetype = TYPE_NULL; + return (STAT_PARAMETER_IS_READ_ONLY); +} stat_t set_ui8(nvObj_t *nv) { diff --git a/g2core/config.h b/g2core/config.h old mode 100755 new mode 100644 index 49fc5c24..a55d654c --- a/g2core/config.h +++ b/g2core/config.h @@ -317,7 +317,8 @@ bool nv_index_lt_groups(index_t index); // (see config_app.c) bool nv_group_is_prefixed(char *group); // generic internal functions and accessors -stat_t set_nul(nvObj_t *nv); // set nothing +stat_t set_nul(nvObj_t *nv); // set nothing, return OK +stat_t set_ro(nvObj_t *nv); // set nothing, return read-only error stat_t set_ui8(nvObj_t *nv); // set uint8_t value stat_t set_int8(nvObj_t *nv); // set signed 8 bit integer stat_t set_01(nvObj_t *nv); // set a 0 or 1 value with validation diff --git a/g2core/config_app.cpp b/g2core/config_app.cpp index e9b9ba49..807588b9 100644 --- a/g2core/config_app.cpp +++ b/g2core/config_app.cpp @@ -102,14 +102,14 @@ static stat_t get_tick(nvObj_t *nv); // get system tick count * the %f in the corresponding format string to set text mode display precision */ const cfgItem_t cfgArray[] = { - // group token flags p, print_func, get_func, set_func, target for get/set, default value - { "sys", "fb", _fipn,2, hw_print_fb, get_flt, set_nul, (float *)&cs.fw_build, G2CORE_FIRMWARE_BUILD }, // MUST BE FIRST! - { "sys", "fbs",_fn, 2, hw_print_fbs,hw_get_fbs,set_nul, (float *)&cs.null, 0 }, - { "sys", "fbc",_fn, 2, hw_print_fbc,hw_get_fbc,set_nul, (float *)&cs.null, 0 }, - { "sys", "fv", _fipn,2, hw_print_fv, get_flt, set_nul, (float *)&cs.fw_version, G2CORE_FIRMWARE_VERSION }, - { "sys", "hp", _fipn,0, hw_print_hp, get_flt, set_flt, (float *)&cs.hw_platform, G2CORE_HARDWARE_PLATFORM }, - { "sys", "hv", _fipn,0, hw_print_hv, get_flt, hw_set_hv,(float *)&cs.hw_version, G2CORE_HARDWARE_VERSION }, - { "sys", "id", _fn, 0, hw_print_id, hw_get_id, set_nul, (float *)&cs.null, 0 }, // device ID (ASCII signature) + // group token flags p, print_func, get_func, set_func, target for get/set, default value + { "sys", "fb", _fipn,2, hw_print_fb, get_flt, set_ro, (float *)&cs.fw_build, G2CORE_FIRMWARE_BUILD }, // MUST BE FIRST! + { "sys", "fbs",_fn, 2, hw_print_fbs,hw_get_fbs,set_ro, (float *)&cs.null, 0 }, + { "sys", "fbc",_fn, 2, hw_print_fbc,hw_get_fbc,set_ro, (float *)&cs.null, 0 }, + { "sys", "fv", _fipn,2, hw_print_fv, get_flt, set_ro, (float *)&cs.fw_version, G2CORE_FIRMWARE_VERSION }, + { "sys", "hp", _fipn,0, hw_print_hp, get_flt, set_ro, (float *)&cs.hw_platform, G2CORE_HARDWARE_PLATFORM }, + { "sys", "hv", _fipn,0, hw_print_hv, get_flt, set_ro, (float *)&cs.hw_version, G2CORE_HARDWARE_VERSION }, + { "sys", "id", _fn, 0, hw_print_id, hw_get_id, set_ro, (float *)&cs.null, 0 }, // device ID (ASCII signature) // dynamic model attributes for reporting purposes (up front for speed) { "", "stat",_f0, 0, cm_print_stat, cm_get_stat, set_nul,(float *)&cs.null, 0 }, // combined machine state diff --git a/g2core/main.cpp b/g2core/main.cpp old mode 100755 new mode 100644 index ca7dc444..625d38e5 --- a/g2core/main.cpp +++ b/g2core/main.cpp @@ -154,7 +154,7 @@ void loop() { } /* - * Traps for debugging. These must be in mail.cpp for proper linker ordering + * Traps for debugging. These must be in main.cpp for proper linker ordering */ void MemManage_Handler ( void ) { __asm__("BKPT"); }