Big commit. Added nv->value_int, and changed nv_value to nv->value_flt. Many many things changed. Passes smoke test. Now on to some real regressions.

This commit is contained in:
Alden Hart
2017-03-19 20:27:53 -04:00
parent 36f8b9a9cc
commit 5f306e1657
15 changed files with 841 additions and 811 deletions

View File

@@ -513,8 +513,8 @@ void cm_update_model_position()
/****************************************************************************************
* cm_deferred_write_callback() - write any changed G10 values back to persistence
*
* Only runs if there is G10 data to write, there is no movement, and the serial queues are quiescent
* This could be made tighter by issuing an XOFF or ~CTS beforehand and releasing it afterwards.
* Only runs if there is G10 data to write, there is no movement, and the serial queues
* are quiescent.
*/
stat_t cm_deferred_write_callback()
@@ -526,8 +526,8 @@ stat_t cm_deferred_write_callback()
for (uint8_t j=0; j<AXES; j++) {
sprintf((char *)nv.token, "g%2d%c", 53+i, ("xyzabc")[j]);
nv.index = nv_get_index((const char *)"", nv.token);
nv.value = cm->coord_offset[i][j];
nv_persist(&nv); // Note: only writes values that have changed
nv.value_flt = cm->coord_offset[i][j];
nv_persist(&nv); // Note: nv_persist() only writes values that have changed
}
}
}
@@ -543,11 +543,10 @@ stat_t cm_deferred_write_callback()
stat_t cm_set_tram(nvObj_t *nv)
{
if ((nv->valuetype == TYPE_BOOL) ||
(nv->valuetype == TYPE_INT) ||
(nv->valuetype == TYPE_FLOAT))
{
bool do_set = !!((uint32_t)nv->value);
// Ah yes. If you call {tram:true} or any non-zero it will tram. Anything falsey will clear the tram.
if ((nv->valuetype == TYPE_BOOLEAN) || (nv->valuetype == TYPE_INTEGER) || (nv->valuetype == TYPE_FLOAT)) {
bool do_set = !!(nv->value_int);
// if passed false/0, we will clear the rotation matrix
if (!do_set) {
@@ -641,7 +640,7 @@ stat_t cm_set_tram(nvObj_t *nv)
stat_t cm_get_tram(nvObj_t *nv)
{
nv->value = true;
nv->value_int = true;
if (fp_NOT_ZERO(cm->rotation_z_offset) ||
fp_NOT_ZERO(cm->rotation_matrix[0][1]) ||
@@ -654,9 +653,9 @@ stat_t cm_get_tram(nvObj_t *nv)
fp_NE(1.0, cm->rotation_matrix[1][1]) ||
fp_NE(1.0, cm->rotation_matrix[2][2]))
{
nv->value = false;
nv->value_int = false;
}
nv->valuetype = TYPE_BOOL;
nv->valuetype = TYPE_BOOLEAN;
return (STAT_OK);
}
@@ -1736,20 +1735,12 @@ char cm_get_axis_char(const int8_t axis)
/***********************************************************************************
* Run Commands
*
* cm_run_qf() - flush planner queue
* cm_run_home() - run homing sequence
*/
/*
stat_t cm_run_qf(nvObj_t *nv)
{
cm_request_queue_flush();
return (STAT_OK);
}
*/
stat_t cm_run_home(nvObj_t *nv)
{
if (fp_TRUE(nv->value)) {
if (nv->value_int) { // if true
float axes[] = { 1,1,1,1,1,1 };
bool flags[] = { 1,1,1,1,1,1 };
cm_homing_cycle_start(axes, flags);
@@ -1958,10 +1949,10 @@ static const char *const msg_frmo[] = { msg_g93, msg_g94, msg_g95 };
#endif // __TEXT_MODE
// Add the string for the enum to the nv, but leave it as a TYPE_INT
stat_t _get_msg_helper(nvObj_t *nv, const char *const msg_array[], uint8_t value)
stat_t _get_msg_helper(nvObj_t *nv, const char *const msg_array[], int32_t value)
{
nv->value = (float)value;
nv->valuetype = TYPE_INT;
nv->value_int = value;
nv->valuetype = TYPE_INTEGER;
return(nv_copy_string(nv, (const char *)GET_TEXT_ITEM(msg_array, value)));
}
@@ -1988,11 +1979,11 @@ stat_t cm_get_line(nvObj_t *nv) { return(get_int32(nv, cm_get_linenum(ACTIVE_MO
stat_t cm_get_vel(nvObj_t *nv)
{
if (cm_get_motion_state() == MOTION_STOP) {
nv->value = 0;
nv->value_flt = 0;
} else {
nv->value = mp_get_runtime_velocity();
nv->value_flt = mp_get_runtime_velocity();
if (cm_get_units_mode(RUNTIME) == INCHES) {
nv->value *= INCHES_PER_MM;
nv->value_flt *= INCHES_PER_MM;
}
}
nv->precision = GET_TABLE_WORD(precision);
@@ -2070,25 +2061,25 @@ stat_t cm_set_tt(nvObj_t *nv)
stat_t cm_get_am(nvObj_t *nv)
{
int8_t axis = _axis(nv);
nv->value = (float)cm->a[axis].axis_mode;
return(_get_msg_helper(nv, msg_am, nv->value));
nv->value_int = cm->a[axis].axis_mode;
return(_get_msg_helper(nv, msg_am, nv->value_int));
}
stat_t cm_set_am(nvObj_t *nv) // axis mode
{
if (cm_get_axis_type(nv) == AXIS_TYPE_LINEAR) {
if (nv->value > AXIS_MODE_LINEAR_MAX) {
if (nv->value_int > AXIS_MODE_LINEAR_MAX) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
} else {
if (nv->value > AXIS_MODE_ROTARY_MAX) {
if (nv->value_int > AXIS_MODE_ROTARY_MAX) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
}
nv->valuetype = TYPE_INT;
cm->a[_axis(nv)].axis_mode = (cmAxisMode)nv->value;
nv->valuetype = TYPE_INTEGER;
cm->a[_axis(nv)].axis_mode = (cmAxisMode)nv->value_int;
return(STAT_OK);
}
@@ -2155,7 +2146,7 @@ stat_t cm_set_vm(nvObj_t *nv)
{
uint8_t axis = _axis(nv);
ritorno(set_float_range(nv, cm->a[axis].velocity_max, 0, MAX_LONG));
cm->a[axis].recip_velocity_max = 1/nv->value;
cm->a[axis].recip_velocity_max = 1/nv->value_flt;
return(STAT_OK);
}
@@ -2164,7 +2155,7 @@ stat_t cm_set_fr(nvObj_t *nv)
{
uint8_t axis = _axis(nv);
ritorno(set_float_range(nv, cm->a[axis].feedrate_max, 0, MAX_LONG));
cm->a[axis].recip_feedrate_max = 1/nv->value;
cm->a[axis].recip_feedrate_max = 1/nv->value_flt;
return(STAT_OK);
}
@@ -2173,17 +2164,16 @@ stat_t cm_set_jm(nvObj_t *nv)
{
uint8_t axis = _axis(nv);
ritorno(set_float_range(nv, cm->a[axis].jerk_max, JERK_INPUT_MIN, JERK_INPUT_MAX));
cm_set_axis_max_jerk(axis, nv->value);
cm_set_axis_max_jerk(axis, nv->value_flt);
return(STAT_OK);
}
stat_t cm_get_jh(nvObj_t *nv) { return (get_float(nv, cm->a[_axis(nv)].jerk_high)); }
stat_t cm_set_jh(nvObj_t *nv)
// { return (set_float_range(nv, cm->a[_axis(nv)].jerk_high, JERK_INPUT_MIN, JERK_INPUT_MAX)); }
{
uint8_t axis = _axis(nv);
ritorno(set_float_range(nv, cm->a[axis].jerk_high, JERK_INPUT_MIN, JERK_INPUT_MAX));
cm_set_axis_high_jerk(axis, nv->value);
cm_set_axis_high_jerk(axis, nv->value_flt);
return(STAT_OK);
}
@@ -2458,7 +2448,7 @@ static const char fmt_hom[] = "%c axis homing state:%2.0f\n";
static void _print_axis_ui8(nvObj_t *nv, const char *format)
{
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, (uint8_t)nv->value);
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->value_int);
xio_writeline(cs.out_buf);
}
@@ -2470,7 +2460,7 @@ static void _print_axis_flt(nvObj_t *nv, const char *format)
} else {
units = (char *)GET_TEXT_ITEM(msg_units, DEGREE_INDEX);
}
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->value, units);
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->value_flt, units);
xio_writeline(cs.out_buf);
}
@@ -2482,7 +2472,7 @@ static void _print_axis_coord_flt(nvObj_t *nv, const char *format)
} else {
units = (char *)GET_TEXT_ITEM(msg_units, DEGREE_INDEX);
}
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->token, nv->value, units);
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->token, nv->value_flt, units);
xio_writeline(cs.out_buf);
}
@@ -2491,7 +2481,7 @@ static void _print_pos(nvObj_t *nv, const char *format, uint8_t units)
char axes[] = {"XYZABC"};
uint8_t axis = _axis(nv);
if (axis >= AXIS_A) { units = DEGREES;}
sprintf(cs.out_buf, format, axes[axis], nv->value, GET_TEXT_ITEM(msg_units, units));
sprintf(cs.out_buf, format, axes[axis], nv->value_flt, GET_TEXT_ITEM(msg_units, units));
xio_writeline(cs.out_buf);
}
@@ -2499,14 +2489,14 @@ static void _print_hom(nvObj_t *nv, const char *format)
{
char axes[] = {"XYZABC"};
uint8_t axis = _axis(nv);
sprintf(cs.out_buf, format, axes[axis], nv->value);
sprintf(cs.out_buf, format, axes[axis], nv->value_int);
xio_writeline(cs.out_buf);
}
void cm_print_am(nvObj_t *nv) // print axis mode with enumeration string
{
sprintf(cs.out_buf, fmt_Xam, nv->group, nv->token, nv->group, (uint8_t)nv->value,
GET_TEXT_ITEM(msg_am, (uint8_t)nv->value));
sprintf(cs.out_buf, fmt_Xam, nv->group, nv->token, nv->group, nv->value_int,
GET_TEXT_ITEM(msg_am, nv->value_int));
xio_writeline(cs.out_buf);
}

View File

@@ -128,15 +128,15 @@ static void _set_defa(nvObj_t *nv, bool print)
cm_set_units_mode(MILLIMETERS); // must do inits in MM mode
for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
if (cfgArray[nv->index].flags & F_INITIALIZE) {
if (cfgArray[nv->index].flags & F_ZERO) {
nv->value = 0;
} else {
if (cfgArray[nv->index].flags & F_INT32) {
// if (cfgArray[nv->index].flags & F_ZERO) {
// nv->value = 0;
// } else {
if ((cfgArray[nv->index].flags & F_TYPE_MASK) == TYPE_INTEGER) {
nv->value_int = cfgArray[nv->index].def_value;
} else {
nv->value = cfgArray[nv->index].def_value;
}
nv->value_flt = cfgArray[nv->index].def_value;
}
// }
strncpy(nv->token, cfgArray[nv->index].token, TOKEN_LEN);
cfgArray[nv->index].set(nv); // run the set method, nv_set(nv);
if (cfgArray[nv->index].flags & F_PERSIST) {
@@ -152,8 +152,10 @@ static void _set_defa(nvObj_t *nv, bool print)
stat_t set_defaults(nvObj_t *nv)
{
// failsafe. nv->value must be true or no action occurs
if (fp_FALSE(nv->value)) return(help_defa(nv));
// failsafe. nv->value_int must be true or no action occurs
if (!nv->value_int) {
return(help_defa(nv));
}
_set_defa(nv, true);
// The nvlist was used for the initialize message so the values are all garbage
@@ -161,8 +163,8 @@ stat_t set_defaults(nvObj_t *nv)
nv_reset_nv_list();
strncpy(nv->token, "defa", TOKEN_LEN);
// nv->index = nv_get_index("", nv->token); // correct, but not required
nv->valuetype = TYPE_INT;
nv->value = 1;
nv->valuetype = TYPE_INTEGER; // ++++ probably should be TYPE_BOOLEAN
nv->value_int = true;
return (STAT_OK);
}
@@ -212,29 +214,31 @@ stat_t get_nul(nvObj_t *nv)
stat_t get_ui8(nvObj_t *nv)
{
nv->value = (float)*((uint8_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_INT;
// nv->value = (float)*((uint8_t *)GET_TABLE_WORD(target));
nv->value_int = *((uint8_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
stat_t get_int8(nvObj_t *nv)
{
nv->value = (float)*((int8_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_INT;
// nv->value = (float)*((int8_t *)GET_TABLE_WORD(target));
nv->value_int = *((int8_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
stat_t get_int32(nvObj_t *nv)
{
//+++++ nv->value = *((uint32_t *)GET_TABLE_WORD(target));
// nv->value = *((uint32_t *)GET_TABLE_WORD(target));
nv->value_int = *((uint32_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_INT;
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
stat_t get_data(nvObj_t *nv)
{
uint32_t *v = (uint32_t*)&nv->value;
uint32_t *v = (uint32_t*)&nv->value_flt;
*v = *((uint32_t *)GET_TABLE_WORD(target));
nv->valuetype = TYPE_DATA;
return (STAT_OK);
@@ -242,7 +246,7 @@ stat_t get_data(nvObj_t *nv)
stat_t get_flt(nvObj_t *nv)
{
nv->value = *((float *)GET_TABLE_WORD(target));
nv->value_flt= *((float *)GET_TABLE_WORD(target));
nv->precision = (int8_t)GET_TABLE_WORD(precision);
nv->valuetype = TYPE_FLOAT;
return (STAT_OK);
@@ -283,25 +287,25 @@ stat_t set_ro(nvObj_t *nv) {
stat_t set_ui8(nvObj_t *nv)
{
*((uint8_t *)GET_TABLE_WORD(target)) = nv->value;
nv->valuetype = TYPE_INT;
*((uint8_t *)GET_TABLE_WORD(target)) = nv->value_int;
nv->valuetype = TYPE_INTEGER;
return(STAT_OK);
}
stat_t set_int8(nvObj_t *nv)
{
*((int8_t *)GET_TABLE_WORD(target)) = (int8_t)nv->value;
nv->valuetype = TYPE_INT;
*((int8_t *)GET_TABLE_WORD(target)) = (int8_t)nv->value_int;
nv->valuetype = TYPE_INTEGER;
return(STAT_OK);
}
stat_t set_01(nvObj_t *nv)
{
if (nv->value < 0) {
if (nv->value_int < 0) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_LESS_THAN_MIN_VALUE);
}
if (nv->value > 1) {
if (nv->value_int > 1) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
@@ -310,11 +314,11 @@ stat_t set_01(nvObj_t *nv)
stat_t set_012(nvObj_t *nv)
{
if (nv->value < 0) {
if (nv->value_int < 0) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_LESS_THAN_MIN_VALUE);
}
if (nv->value > 2) {
if (nv->value_int > 2) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
@@ -323,11 +327,11 @@ stat_t set_012(nvObj_t *nv)
stat_t set_0123(nvObj_t *nv)
{
if (nv->value < 0) {
if (nv->value_int < 0) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_LESS_THAN_MIN_VALUE);
}
if (nv->value > 3) {
if (nv->value_int > 3) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
@@ -338,13 +342,13 @@ stat_t set_int32(nvObj_t *nv)
{
// *((uint32_t *)GET_TABLE_WORD(target)) = (uint32_t)nv->value; +++++
*((uint32_t *)GET_TABLE_WORD(target)) = nv->value_int;
nv->valuetype = TYPE_INT;
nv->valuetype = TYPE_INTEGER;
return(STAT_OK);
}
stat_t set_data(nvObj_t *nv)
{
uint32_t *v = (uint32_t*)&nv->value;
uint32_t *v = (uint32_t*)&nv->value_flt;
*((uint32_t *)GET_TABLE_WORD(target)) = *v;
nv->valuetype = TYPE_DATA;
return(STAT_OK);
@@ -352,7 +356,7 @@ stat_t set_data(nvObj_t *nv)
stat_t set_flt(nvObj_t *nv)
{
*((float *)GET_TABLE_WORD(target)) = nv->value;
*((float *)GET_TABLE_WORD(target)) = nv->value_flt;
nv->precision = GET_TABLE_WORD(precision);
nv->valuetype = TYPE_FLOAT;
return(STAT_OK);
@@ -499,6 +503,25 @@ uint8_t nv_get_type(nvObj_t *nv)
return (NV_TYPE_CONFIG);
}
/*
* nv_coerce_types() - change types based on type field in configApp table
*/
void nv_coerce_types(nvObj_t *nv)
{
valueType type = (valueType)(cfgArray[nv->index].flags & F_TYPE_MASK);
if (type == TYPE_INTEGER) {
nv->valuetype = TYPE_INTEGER; // will pay attention to the int value, not the float
} else if (type == TYPE_BOOLEAN) { // it may have been marked as a boolean, but if it's not...
nv->valuetype = TYPE_BOOLEAN;
if (nv->valuetype == TYPE_INTEGER) {
nv->value_int = nv->value_int ? true : false;
} else
if (nv->valuetype == TYPE_FLOAT) {
nv->value_int = (fp_ZERO(nv->value_flt)) ? true : false;
}
}
}
/******************************************************************************
* nvObj low-level object and list operations
* nv_get_nvObj() - setup a nv object by providing the index
@@ -550,7 +573,8 @@ nvObj_t *nv_reset_nv(nvObj_t *nv) // clear a single nvObj structur
{
nv->valuetype = TYPE_EMPTY; // selective clear is much faster than calling memset
nv->index = 0;
nv->value = 0;
nv->value_int = 0;
nv->value_flt = 0;
nv->precision = 0;
nv->token[0] = NUL;
nv->group[0] = NUL;
@@ -639,7 +663,7 @@ nvObj_t *nv_add_object(const char *token) // add an object to the body usi
return (NULL);
}
nvObj_t *nv_add_integer(const char *token, const uint32_t value)// add an integer object to the body
nvObj_t *nv_add_integer(const char *token, const int32_t value) // add an integer object to the body
{
nvObj_t *nv = nv_body;
for (uint8_t i=0; i<NV_BODY_LEN; i++) {
@@ -650,8 +674,8 @@ nvObj_t *nv_add_integer(const char *token, const uint32_t value)// add an intege
continue;
}
strncpy(nv->token, token, TOKEN_LEN);
nv->value = (float) value;
nv->valuetype = TYPE_INT;
nv->value_int = value;
nv->valuetype = TYPE_INTEGER;
return (nv);
}
return (NULL);
@@ -669,7 +693,7 @@ nvObj_t *nv_add_data(const char *token, const uint32_t value)// add an integer o
}
strcpy(nv->token, token);
float *v = (float*)&value;
nv->value = *v;
nv->value_flt = *v;
nv->valuetype = TYPE_DATA;
return (nv);
}
@@ -687,7 +711,7 @@ nvObj_t *nv_add_float(const char *token, const float value) // add a float ob
continue;
}
strncpy(nv->token, token, TOKEN_LEN);
nv->value = value;
nv->value_flt = value;
nv->valuetype = TYPE_FLOAT;
return (nv);
}
@@ -761,7 +785,7 @@ void nv_dump_nv(nvObj_t *nv)
nv->depth,
nv->valuetype,
nv->precision,
(double)nv->value,
(double)nv->value_flt, // would need to add in value_int to be complete
nv->group,
nv->token,
(char *)nv->stringp);

View File

@@ -204,28 +204,84 @@ typedef enum {
} flowControl;
typedef enum { // value typing for config and JSON
// exception types
TYPE_SKIP = -2, // do not serialize this object (used for filtering)
TYPE_EMPTY = -1, // value struct is empty (which is not the same as "NULL")
// fundamental JSON types // must be 0-3. Do not change. Used by F_'s and JSON decoding
TYPE_NULL = 0, // value is 'null' (meaning the JSON null value)
TYPE_PARENT, // object is a parent to a sub-object
TYPE_FLOAT, // value is a floating point number
TYPE_INT, // value is a signed or unsigned integer < 32 bits
TYPE_INT32, // value is a 32 bit signed integer
TYPE_STRING, // value is in string field
TYPE_BOOL, // value is "true" (1) or "false"(0)
TYPE_DATA, // value is blind cast to uint32_t
TYPE_ARRAY // value is array element count, values are CSV ASCII in string field
TYPE_BOOLEAN = 1, // value is "true" (1) or "false"(0)
TYPE_INTEGER = 2, // value is an 8 or 32 bit signed integer
TYPE_STRING = 3, // value is in string field
// derived data types // must be 4-7. Do not change.
TYPE_FLOAT = 4, // value is a floating point number
TYPE_UINT32 = 5, // unsigned 32 bit integer (unused)
TYPE_ARRAY = 6, // value is array element count, values are CSV ASCII in string field
TYPE_DATA = 7, // value is blind cast to uint32_t (willbe removed)
// transient types and types used during JSON processing
TYPE_PARENT // object is a parent to a sub-object
// TYPE_NEW_LEVEL, // 'value' is actually child key at new nesting level
// TYPE_NULL_STRING, // empty string - treated as null
// TYPE_TYPE_ERROR // none of the above
} valueType;
/**** operations flags and shorthand ****/
#define F_INITIALIZE 0x01 // initialize this item (run set during initialization)
#define F_PERSIST 0x02 // persist this item when set is run
#define F_NOSTRIP 0x04 // do not strip the group prefix from the token
#define F_CONVERT 0x08 // set if unit conversion is required
#define F_ICONVERT 0x10 // set if unit conversion is required AND value is an inverse quantity
#define F_ZERO 0x20 // initialize to zero (requires F_INITIALIZE set as well)
#define F_INT32 0x40 // treat as int32
#define F_TYPE_MASK 0x00000007 // 3 LSB's used for data type
#define F_INITIALIZE 0x08 // initialize this item (run set during initialization)
#define F_PERSIST 0x10 // persist this item when set is run
#define F_NOSTRIP 0x20 // do not strip the group prefix from the token
#define F_CONVERT 0x40 // set if unit conversion is required
#define F_ICONVERT 0x80 // set if unit conversion is required AND value is an inverse quantity
// Shorthand
// _n(ull) (used by commands or other case where there is no target data)
// _b(oolean)
// _s(tring)
// _i(nteger)
// _f(loat)
// _t(ext container)
// _d(ata)
#define _n0 (TYPE_NULL)
#define _nn (TYPE_NULL | F_NOSTRIP)
#define _s0 (TYPE_STRING)
#define _sn (TYPE_STRING | F_NOSTRIP)
#define _d0 (TYPE_DATA)
#define _dip (TYPE_DATA | F_INITIALIZE | F_PERSIST)
#define _b0 (TYPE_BOOLEAN) // boolean data types (only listing the ones we use)
#define _bip (TYPE_BOOLEAN | F_INITIALIZE | F_PERSIST)
#define _bin (TYPE_BOOLEAN | F_INITIALIZE | F_NOSTRIP)
#define _bipn (TYPE_BOOLEAN | F_INITIALIZE | F_PERSIST | F_NOSTRIP)
#define _i0 (TYPE_INTEGER) // integer data types (only listing the ones we use)
#define _ii (TYPE_INTEGER | F_INITIALIZE)
#define _ip (TYPE_INTEGER | F_PERSIST)
#define _in (TYPE_INTEGER | F_NOSTRIP)
#define _iip (TYPE_INTEGER | F_INITIALIZE | F_PERSIST)
#define _iipn (TYPE_INTEGER | F_INITIALIZE | F_PERSIST | F_NOSTRIP)
#define _f0 (TYPE_FLOAT) // floating point data types (only listing the ones we use)
#define _fi (TYPE_FLOAT | F_INITIALIZE)
#define _fp (TYPE_FLOAT | F_PERSIST)
#define _fn (TYPE_FLOAT | F_NOSTRIP)
#define _fip (TYPE_FLOAT | F_INITIALIZE | F_PERSIST)
#define _fic (TYPE_FLOAT | F_INITIALIZE | F_CONVERT)
#define _fin (TYPE_FLOAT | F_INITIALIZE | F_NOSTRIP)
#define _fipc (TYPE_FLOAT | F_INITIALIZE | F_PERSIST | F_CONVERT)
#define _fipn (TYPE_FLOAT | F_INITIALIZE | F_PERSIST | F_NOSTRIP)
#define _fipi (TYPE_FLOAT | F_INITIALIZE | F_PERSIST | F_ICONVERT)
#define _fipnc (TYPE_FLOAT | F_INITIALIZE | F_PERSIST | F_NOSTRIP | F_CONVERT)
#define _t0 (TYPE_TXTCON)
/*
#define _f0 0x00
#define _fi (F_INITIALIZE)
#define _fp (F_PERSIST)
@@ -233,26 +289,27 @@ typedef enum { // value typing for config and JSON
#define _fc (F_CONVERT)
#define _fic (F_INITIALIZE | F_CONVERT)
#define _fip (F_INITIALIZE | F_PERSIST)
#define _fiz (F_INITIALIZE | F_ZERO)
#define _fizc (F_INITIALIZE | F_ZERO | F_CONVERT)
//#define _fiz (F_INITIALIZE | F_ZERO)
//#define _fizc (F_INITIALIZE | F_ZERO | F_CONVERT)
#define _fipc (F_INITIALIZE | F_PERSIST | F_CONVERT)
#define _fipn (F_INITIALIZE | F_PERSIST | F_NOSTRIP)
#define _fipi (F_INITIALIZE | F_PERSIST | F_ICONVERT)
#define _fipnc (F_INITIALIZE | F_PERSIST | F_NOSTRIP | F_CONVERT)
#define _i0 (F_INT32)
#define _ii (F_INT32) | (F_INITIALIZE)
#define _ip (F_INT32) | (F_PERSIST)
#define _in (F_INT32) | (F_NOSTRIP)
#define _ic (F_INT32) | (F_CONVERT)
#define _iic (F_INT32) | (F_INITIALIZE | F_CONVERT)
#define _iip (F_INT32) | (F_INITIALIZE | F_PERSIST)
#define _iiz (F_INT32) | (F_INITIALIZE | F_ZERO)
#define _iizc (F_INT32) | (F_INITIALIZE | F_ZERO | F_CONVERT)
#define _iipc (F_INT32) | (F_INITIALIZE | F_PERSIST | F_CONVERT)
#define _iipn (F_INT32) | (F_INITIALIZE | F_PERSIST | F_NOSTRIP)
#define _iipi (F_INT32) | (F_INITIALIZE | F_PERSIST | F_ICONVERT)
#define _iipnc (F_INT32) | (F_INITIALIZE | F_PERSIST | F_NOSTRIP | F_CONVERT)
#define _i0 (F_TYPE_INTEGER)
#define _ii (F_TYPE_INTEGER) | (F_INITIALIZE)
#define _ip (F_TYPE_INTEGER) | (F_PERSIST)
#define _in (F_TYPE_INTEGER) | (F_NOSTRIP)
#define _ic (F_TYPE_INTEGER) | (F_CONVERT)
#define _iic (F_TYPE_INTEGER) | (F_INITIALIZE | F_CONVERT)
#define _iip (F_TYPE_INTEGER) | (F_INITIALIZE | F_PERSIST)
#define _iiz (F_TYPE_INTEGER) | (F_INITIALIZE | F_ZERO)
#define _iizc (F_TYPE_INTEGER) | (F_INITIALIZE | F_ZERO | F_CONVERT)
#define _iipc (F_TYPE_INTEGER) | (F_INITIALIZE | F_PERSIST | F_CONVERT)
#define _iipn (F_TYPE_INTEGER) | (F_INITIALIZE | F_PERSIST | F_NOSTRIP)
#define _iipi (F_TYPE_INTEGER) | (F_INITIALIZE | F_PERSIST | F_ICONVERT)
#define _iipnc (F_TYPE_INTEGER) | (F_INITIALIZE | F_PERSIST | F_NOSTRIP | F_CONVERT)
*/
/**** Structures ****/
@@ -270,17 +327,15 @@ typedef struct nvString { // shared string object
typedef struct nvObject { // depending on use, not all elements may be populated
struct nvObject *pv; // pointer to previous object or NULL if first object
struct nvObject *nx; // pointer to next object or NULL if last object
index_t index; // index of tokenized name, or -1 if no token (optional)
int8_t depth; // depth of object in the tree. 0 is root (-1 is invalid)
valueType valuetype; // see valueType enum
int8_t precision; // decimal precision for reporting (JSON)
union {
float value; // float values
int32_t value_int; // int32 values
};
char group[GROUP_LEN+1]; // group prefix or NUL if not in a group
char token[TOKEN_LEN+1]; // full mnemonic token for lookup
char (*stringp)[]; // pointer to array of characters from shared character array
index_t index; // index of tokenized name, or -1 if no token (optional)
valueType valuetype; // type of value that follows: see valueType enum
int8_t precision; // decimal precision for reporting floating point numbers (JSON only)
float value_flt; // floating point values
int32_t value_int; // signed integer values and booleans
char (*stringp)[]; // string value: pointer to array of characters from shared character array
} nvObj_t; // OK, so it's not REALLY an object
typedef uint8_t (*fptrCmd)(nvObj_t *nv);// required for cfg table access
@@ -330,6 +385,7 @@ stat_t nv_persist(nvObj_t *nv); // main entry point for persistence
// helpers
uint8_t nv_get_type(nvObj_t *nv);
void nv_coerce_types(nvObj_t *nv);
index_t nv_get_index(const char *group, const char *token);
index_t nv_index_max(void); // (see config_app.c)
bool nv_index_is_single(index_t index); // (see config_app.c)

File diff suppressed because it is too large Load Diff

View File

@@ -154,9 +154,9 @@ static void _exec_coolant_control(float* value, bool* flag) {
***********************************************************************************/
stat_t co_get_com(nvObj_t *nv) { return(get_int(nv, coolant.mist.state)); }
stat_t co_set_com(nvObj_t *nv) { return(coolant_control_immediate((coControl)nv->value, COOLANT_MIST)); }
stat_t co_set_com(nvObj_t *nv) { return(coolant_control_immediate((coControl)nv->value_int, COOLANT_MIST)); }
stat_t co_get_cof(nvObj_t *nv) { return(get_int(nv, coolant.flood.state)); }
stat_t co_set_cof(nvObj_t *nv) { return(coolant_control_immediate((coControl)nv->value, COOLANT_FLOOD)); }
stat_t co_set_cof(nvObj_t *nv) { return(coolant_control_immediate((coControl)nv->value_int, COOLANT_FLOOD)); }
stat_t co_get_coph(nvObj_t *nv) { return(get_int(nv, coolant.mist.pause_enable)); }
stat_t co_set_coph(nvObj_t *nv) {

View File

@@ -379,13 +379,13 @@ static void _send_probe_report() {
stat_t cm_get_prbr(nvObj_t *nv)
{
nv->value = (float)cm->probe_report_enable;
nv->valuetype = TYPE_INT;
nv->value_int = cm->probe_report_enable;
nv->valuetype = TYPE_INTEGER; // ++++ should probably be type boolean
return (STAT_OK);
}
stat_t cm_set_prbr(nvObj_t *nv)
{
cm->probe_report_enable = fp_NOT_ZERO(nv->value);
cm->probe_report_enable = nv->value_int;
return (STAT_OK);
}

View File

@@ -481,7 +481,7 @@ bool gpio_read_input(const uint8_t input_num_ext)
static stat_t _input_set_helper(nvObj_t *nv, const int8_t lower_bound, const int8_t upper_bound)
{
if ((nv->value < lower_bound) || (nv->value >= upper_bound)) {
if ((nv->value_int < lower_bound) || (nv->value_int >= upper_bound)) {
return (STAT_INPUT_VALUE_RANGE_ERROR);
}
set_ui8(nv); // will this work if -1 is a valid value?
@@ -493,7 +493,7 @@ static stat_t _input_set_helper(nvObj_t *nv, const int8_t lower_bound, const int
static stat_t _output_set_helper(nvObj_t *nv, const int8_t lower_bound, const int8_t upper_bound)
{
if ((nv->value < lower_bound) || (nv->value >= upper_bound)) {
if ((nv->value_int < lower_bound) || (nv->value_int >= upper_bound)) {
return (STAT_INPUT_VALUE_RANGE_ERROR);
}
set_ui8(nv); // will this work in -1 is a valid value?
@@ -529,12 +529,12 @@ stat_t io_get_input(nvObj_t *nv)
// skip over "in"
num_start+=2;
}
nv->value = d_in[strtol(num_start, NULL, 10)-1].state;
nv->value_int = d_in[strtol(num_start, NULL, 10)-1].state;
if (nv->value > 1.1) {
if (nv->value_int > 1.1) {
nv->valuetype = TYPE_NULL;
} else {
nv->valuetype = TYPE_BOOL;
nv->valuetype = TYPE_BOOLEAN;
}
return (STAT_OK);
}
@@ -557,19 +557,19 @@ stat_t io_set_domode(nvObj_t *nv) // output function
// Force pins that aren't available to be "disabled"
switch (output_num) {
case 1: if (output_1_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 2: if (output_2_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 3: if (output_3_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 4: if (output_4_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 5: if (output_5_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 6: if (output_6_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 7: if (output_7_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 8: if (output_8_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 9: if (output_9_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 10: if (output_10_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 11: if (output_11_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 12: if (output_12_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 13: if (output_13_pin.isNull()) { nv->value = IO_MODE_DISABLED; } break;
case 1: if (output_1_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 2: if (output_2_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 3: if (output_3_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 4: if (output_4_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 5: if (output_5_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 6: if (output_6_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 7: if (output_7_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 8: if (output_8_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 9: if (output_9_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 10: if (output_10_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 11: if (output_11_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 12: if (output_12_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
case 13: if (output_13_pin.isNull()) { nv->value_int = IO_MODE_DISABLED; } break;
default:
break;
@@ -599,7 +599,7 @@ stat_t io_get_output(nvObj_t *nv)
ioMode outMode = d_out[output_num-1].mode;
if (outMode == IO_MODE_DISABLED) {
// nv->value = 0;
// nv->value_int = 0;
nv->valuetype = TYPE_NULL; // reports back as NULL
} else {
nv->valuetype = TYPE_FLOAT;
@@ -607,19 +607,19 @@ stat_t io_get_output(nvObj_t *nv)
bool invert = (outMode == 0);
// Note: !! forces a value to boolean 0 or 1
switch (output_num) {
case 1: { nv->value = (float)output_1_pin; } break;
case 2: { nv->value = (float)output_2_pin; } break;
case 3: { nv->value = (float)output_3_pin; } break;
case 4: { nv->value = (float)output_4_pin; } break;
case 5: { nv->value = (float)output_5_pin; } break;
case 6: { nv->value = (float)output_6_pin; } break;
case 7: { nv->value = (float)output_7_pin; } break;
case 8: { nv->value = (float)output_8_pin; } break;
case 9: { nv->value = (float)output_9_pin; } break;
case 10: { nv->value = (float)output_10_pin; } break;
case 11: { nv->value = (float)output_11_pin; } break;
case 12: { nv->value = (float)output_12_pin; } break;
case 13: { nv->value = (float)output_13_pin; } break;
case 1: { nv->value_flt = (float)output_1_pin; } break;
case 2: { nv->value_flt = (float)output_2_pin; } break;
case 3: { nv->value_flt = (float)output_3_pin; } break;
case 4: { nv->value_flt = (float)output_4_pin; } break;
case 5: { nv->value_flt = (float)output_5_pin; } break;
case 6: { nv->value_flt = (float)output_6_pin; } break;
case 7: { nv->value_flt = (float)output_7_pin; } break;
case 8: { nv->value_flt = (float)output_8_pin; } break;
case 9: { nv->value_flt = (float)output_9_pin; } break;
case 10: { nv->value_flt = (float)output_10_pin; } break;
case 11: { nv->value_flt = (float)output_11_pin; } break;
case 12: { nv->value_flt = (float)output_12_pin; } break;
case 13: { nv->value_flt = (float)output_13_pin; } break;
default:
{
@@ -628,7 +628,7 @@ stat_t io_get_output(nvObj_t *nv)
}
}
if (invert) {
nv->value = 1.0 - nv->value;
nv->value_flt = 1.0 - nv->value_flt;
}
}
return (STAT_OK);
@@ -637,6 +637,7 @@ stat_t io_get_output(nvObj_t *nv)
/*
* io_set_output() - return output state given an nv object
*/
stat_t io_set_output(nvObj_t *nv)
{
char *num_start = nv->token;
@@ -650,10 +651,10 @@ stat_t io_set_output(nvObj_t *nv)
ioMode outMode = d_out[output_num-1].mode;
if (outMode == IO_MODE_DISABLED) {
nv->value = 0; // Inactive?
nv->value_flt = 0; // Inactive?
} else {
bool invert = (outMode == 0);
float value = nv->value;
float value = nv->value_flt;
if (invert) {
value = 1.0 - value;
}
@@ -675,7 +676,7 @@ stat_t io_set_output(nvObj_t *nv)
case 12: { output_12_pin = value; } break;
case 13: { output_13_pin = value; } break;
// END generated
default: { nv->value = 0; } // inactive
default: { nv->value_flt = 0; } // inactive
}
}
return (STAT_OK);
@@ -698,20 +699,20 @@ stat_t io_set_output(nvObj_t *nv)
static void _print_di(nvObj_t *nv, const char *format)
{
sprintf(cs.out_buf, format, nv->group, (int)nv->value);
sprintf(cs.out_buf, format, nv->group, nv->value_int);
xio_writeline(cs.out_buf);
}
void io_print_mo(nvObj_t *nv) {_print_di(nv, fmt_gpio_mo);}
void io_print_ac(nvObj_t *nv) {_print_di(nv, fmt_gpio_ac);}
void io_print_fn(nvObj_t *nv) {_print_di(nv, fmt_gpio_fn);}
void io_print_in(nvObj_t *nv) {
sprintf(cs.out_buf, fmt_gpio_in, nv->token, (int)nv->value);
sprintf(cs.out_buf, fmt_gpio_in, nv->token, (int)nv->value_int);
xio_writeline(cs.out_buf);
}
void io_print_domode(nvObj_t *nv) {_print_di(nv, fmt_gpio_domode);}
void io_print_out(nvObj_t *nv) {
sprintf(cs.out_buf, fmt_gpio_out, nv->token, (int)nv->value);
sprintf(cs.out_buf, fmt_gpio_out, nv->token, nv->value_int);
xio_writeline(cs.out_buf);
}
#endif

View File

@@ -45,7 +45,7 @@ jsSingleton_t js;
static stat_t _json_parser_kernal(nvObj_t *nv, char *str);
static stat_t _json_parser_execute(nvObj_t *nv);
static stat_t _normalize_json_string(char *str, uint16_t size);
static stat_t _get_nv_pair(nvObj_t *nv, char **pstr, int8_t *depth, uint32_t *value_int);
static stat_t _get_nv_pair(nvObj_t *nv, char **pstr, int8_t *depth);
/****************************************************************************
* json_parser() - exposed part of JSON parser
@@ -134,22 +134,10 @@ static stat_t _json_parser_execute(nvObj_t *nv) {
return (STAT_OK); // only successful commands exit through this point
}
// Return valueType defined for this variable.
// Currently just (f)loat and (int)
static valueType _value_type_defined(index_t i)
{
if (cfgArray[i].flags & F_INT32) {
return (TYPE_INT32);
}
return (TYPE_FLOAT);
}
static stat_t _json_parser_kernal(nvObj_t *nv, char *str)
{
stat_t status;
int8_t depth;
uint32_t value_int = 0;
char group[GROUP_LEN+1] = {""}; // group identifier - starts as NUL
int8_t i = NV_BODY_LEN;
@@ -166,7 +154,7 @@ static stat_t _json_parser_kernal(nvObj_t *nv, char *str)
}
// Use relaxed parser. Will read either strict or relaxed mode. To use strict-only parser refer
// to build earlier than 407.03. Substitute _get_nv_pair_strict() for _get_nv_pair()
if ((status = _get_nv_pair(nv, &str, &depth, &value_int)) > STAT_EAGAIN) { // erred out
if ((status = _get_nv_pair(nv, &str, &depth)) > STAT_EAGAIN) { // erred out
nv->valuetype = TYPE_NULL;
return (status);
}
@@ -182,10 +170,7 @@ static stat_t _json_parser_kernal(nvObj_t *nv, char *str)
if ((nv_index_is_group(nv->index)) && (nv_group_is_prefixed(nv->token))) {
strncpy(group, nv->token, GROUP_LEN); // record the group ID
}
if (_value_type_defined(nv->index) == TYPE_INT32) { // change out the float for an int32
nv->value_int = value_int;
nv->valuetype = TYPE_INT32;
}
nv_coerce_types(nv); // set final types following _get_nv_pair
if ((nv = nv->nx) == NULL) {
return (STAT_JSON_TOO_MANY_PAIRS); // Not supposed to encounter a NULL
}
@@ -251,7 +236,7 @@ static stat_t _normalize_json_string(char *str, uint16_t size)
* See build 406.xx or earlier for strict JSON parser - deleted in 407.03
*/
static stat_t _get_nv_pair(nvObj_t *nv, char **pstr, int8_t *depth, uint32_t *value_int)
static stat_t _get_nv_pair(nvObj_t *nv, char **pstr, int8_t *depth)
{
uint8_t i;
char *tmp;
@@ -301,12 +286,12 @@ static stat_t _get_nv_pair(nvObj_t *nv, char **pstr, int8_t *depth, uint32_t *va
// nulls (gets)
if ((**pstr == 'n') || ((**pstr == '\"') && (*(*pstr+1) == '\"'))) { // process null value
nv->valuetype = TYPE_NULL;
nv->value = TYPE_NULL;
nv->value_int = TYPE_NULL;
// numbers
} else if (isdigit(**pstr) || (**pstr == '-')) { // value is a number
*value_int = atol(*pstr); // get number as an integer first (non destructive)
nv->value = (float)strtod(*pstr, &tmp); // tmp is the end pointer
nv->value_int = atol(*pstr); // get the number as an integer
nv->value_flt = (float)strtod(*pstr, &tmp); // get the number as a float - tmp is the end pointer
if ((tmp == *pstr) || // if start pointer equals end the conversion failed
(strchr(terminators, *tmp) == NULL)) { // terminators are the only legal chars at the end of a number
@@ -334,7 +319,7 @@ static stat_t _get_nv_pair(nvObj_t *nv, char **pstr, int8_t *depth, uint32_t *va
// if string begins with 0x it might be data, needs to be at least 3 chars long
if( strlen(*pstr)>=3 && (*pstr)[0]=='0' && (*pstr)[1]=='x')
{
uint32_t *v = (uint32_t*)&nv->value;
uint32_t *v = (uint32_t*)&nv->value_flt;
*v = strtoul((const char *)*pstr, 0L, 0);
nv->valuetype = TYPE_DATA;
} else {
@@ -344,11 +329,11 @@ static stat_t _get_nv_pair(nvObj_t *nv, char **pstr, int8_t *depth, uint32_t *va
// boolean true/false
} else if (**pstr == 't') {
nv->valuetype = TYPE_BOOL;
nv->value = true;
nv->valuetype = TYPE_BOOLEAN;
nv->value_int = true;
} else if (**pstr == 'f') {
nv->valuetype = TYPE_BOOL;
nv->value = false;
nv->valuetype = TYPE_BOOLEAN;
nv->value_int = false;
// arrays
} else if (**pstr == '[') {
@@ -437,14 +422,14 @@ uint16_t json_serialize(nvObj_t *nv, char *out_buf, uint16_t size)
break;
}
case (TYPE_FLOAT): { convert_outgoing_float(nv);
str += floattoa(str, nv->value, nv->precision);
str += floattoa(str, nv->value_flt, nv->precision);
break;
}
case (TYPE_INT): { // str += inttoa(str, (int)nv->value); // doesn't handle negative numbers
str += sprintf(str, "%d", (int)nv->value);
break;
}
case (TYPE_INT32): { str += sprintf(str, "%d", (int)nv->value_int);
// case (TYPE_INT): { // str += inttoa(str, (int)nv->value); // doesn't handle negative numbers
// str += sprintf(str, "%d", (int)nv->value);
// break;
// }
case (TYPE_INTEGER):{ str += sprintf(str, "%d", (int)nv->value_int);
break;
}
case (TYPE_STRING): { *str++ = '"';
@@ -453,7 +438,7 @@ uint16_t json_serialize(nvObj_t *nv, char *out_buf, uint16_t size)
*str++ = '"';
break;
}
case (TYPE_BOOL): { if (fp_FALSE(nv->value)) {
case (TYPE_BOOLEAN):{ if (nv->value_int) {
strcpy(str, "false");
str += 5;
} else {
@@ -462,7 +447,7 @@ uint16_t json_serialize(nvObj_t *nv, char *out_buf, uint16_t size)
}
break;
}
case (TYPE_DATA): { uint32_t *v = (uint32_t*)&nv->value;
case (TYPE_DATA): { uint32_t *v = (uint32_t*)&nv->value_flt;
str += sprintf(str, "\"0x%lx\"", *v);
break;
}
@@ -472,6 +457,7 @@ uint16_t json_serialize(nvObj_t *nv, char *out_buf, uint16_t size)
strcpy(str++, "]");
break;
}
default: {}
}
}
if (str >= str_max) { return (-1);} // signal buffer overrun
@@ -582,7 +568,7 @@ void json_print_response(uint8_t status, const bool only_to_muted /*= false*/)
}
} else if (nv_type == NV_TYPE_LINENUM) { // kill line number echo if not enabled
if ((js.echo_json_linenum == false) || (fp_ZERO(nv->value))) { // do not report line# 0
if ((js.echo_json_linenum == false) || (fp_ZERO(nv->value_int))) { // do not report line# 0
nv->valuetype = TYPE_EMPTY;
}
}
@@ -647,8 +633,8 @@ stat_t js_get_ej(nvObj_t *nv) { return(get_int(nv, cs.comm_mode)); }
stat_t js_set_ej(nvObj_t *nv)
{
ritorno (set_int(nv, (uint8_t &)cs.comm_mode, TEXT_MODE, AUTO_MODE));
if (commMode(nv->value) < AUTO_MODE) { // set json_mode to 0 or 1, but don't change it if comm_mode == 2
js.json_mode = commMode(nv->value);
if (commMode(nv->value_int) < AUTO_MODE) { // set json_mode to 0 or 1, but don't change it if comm_mode == 2
js.json_mode = commMode(nv->value_int);
}
return (STAT_OK);
}
@@ -674,11 +660,11 @@ stat_t js_set_jv(nvObj_t *nv)
js.echo_json_messages = true;
js.echo_json_configs = true;
} else {
if (nv->value >= JV_FOOTER) js.echo_json_footer = true;
if (nv->value >= JV_MESSAGES) js.echo_json_messages = true;
if (nv->value >= JV_CONFIGS) js.echo_json_configs = true;
if (nv->value >= JV_LINENUM) js.echo_json_linenum = true;
if (nv->value >= JV_VERBOSE) js.echo_json_gcode_block = true;
if (nv->value_int >= JV_FOOTER) js.echo_json_footer = true;
if (nv->value_int >= JV_MESSAGES) js.echo_json_messages = true;
if (nv->value_int >= JV_CONFIGS) js.echo_json_configs = true;
if (nv->value_int >= JV_LINENUM) js.echo_json_linenum = true;
if (nv->value_int >= JV_VERBOSE) js.echo_json_gcode_block = true;
}
return(STAT_OK);
}

View File

@@ -58,7 +58,7 @@ void persistence_init()
stat_t read_persistent_value(nvObj_t *nv)
{
nv->value = 0;
nv->value_flt = 0;
return (STAT_OK);
}

View File

@@ -384,11 +384,13 @@ static stat_t _exec_json_wait(mpBuf_t *bf)
nvObj_t *nv = nv_exec;
while ((nv != NULL) && (nv->valuetype != TYPE_EMPTY)) {
// For now we ignore non-BOOL
if (nv->valuetype == TYPE_BOOL) {
bool old_value = !fp_ZERO(nv->value); // force it to bool
if (nv->valuetype == TYPE_BOOLEAN) {
// bool old_value = !fp_ZERO(nv->value); // force it to bool
bool old_value = (bool)nv->value_int; // force it to bool
nv_get_nvObj(nv);
bool new_value = !fp_ZERO(nv->value);
// bool new_value = !fp_ZERO(nv->value);
bool new_value = (bool)nv->value_int;
if (old_value != new_value) {
st_prep_dwell((uint32_t)(0.1 * 1000000.0));// 1ms converted to uSec
return STAT_OK;

View File

@@ -163,10 +163,10 @@ static uint8_t _populate_filtered_status_report(void);
uint8_t _is_stat(nvObj_t *nv)
{
char tok[TOKEN_LEN+1];
char token[TOKEN_LEN+1];
GET_TOKEN_STRING(nv->value, tok);
if (strcmp(tok, "stat") == 0) { return (true);}
GET_TOKEN_STRING(nv->value_int, token); // pass in index, get back token
if (strcmp(token, "stat") == 0) { return (true);}
return (false);
}
@@ -188,8 +188,9 @@ void sr_init_status_report()
for (uint8_t i=0; i < NV_STATUS_REPORT_LEN ; i++) {
if (sr_defaults[i][0] == NUL) break; // quit on first blank array entry
sr.status_report_value[i] = -1234567; // pre-load values with an unlikely number
nv->value = nv_get_index((const char *)"", sr_defaults[i]);// load the index for the SR element
if (fp_EQ(nv->value, NO_MATCH)) {
nv->value_int = nv_get_index((const char *)"", sr_defaults[i]);// load the index for the SR element
// if (fp_EQ(nv->value, NO_MATCH)) {
if (nv->value_int == NO_MATCH) {
rpt_exception(STAT_BAD_STATUS_REPORT_SETTING, "sr_init_status_report() encountered bad SR setting"); // trap mis-configured profile settings
return;
}
@@ -220,9 +221,9 @@ stat_t sr_set_status_report(nvObj_t *nv)
if (((nv = nv->nx) == NULL) || (nv->valuetype == TYPE_EMPTY)) {
break;
}
if ((nv->valuetype == TYPE_BOOL) && (fp_TRUE(nv->value))) {
if ((nv->valuetype == TYPE_BOOLEAN) && nv->value_int) {
status_report_list[i] = nv->index;
nv->value = nv->index; // persist the index as the value
nv->value_int = nv->index; // persist the index as the value
nv->index = sr_start + i; // index of the SR persistence location
nv_persist(nv);
elements++;
@@ -386,14 +387,14 @@ static uint8_t _populate_filtered_status_report()
nv_get_nvObj(nv);
// report values that have changed by more than 0.0001, but always stops and ends
if ((fabs(nv->value - sr.status_report_value[i]) > precision[cfgArray[nv->index].precision]) ||
((nv->index == sr.stat_index) && fp_EQ(nv->value, COMBINED_PROGRAM_STOP)) ||
((nv->index == sr.stat_index) && fp_EQ(nv->value, COMBINED_PROGRAM_END))) {
if ((fabs(nv->value_int - sr.status_report_value[i]) > precision[cfgArray[nv->index].precision]) ||
((nv->index == sr.stat_index) && fp_EQ(nv->value_int, COMBINED_PROGRAM_STOP)) ||
((nv->index == sr.stat_index) && fp_EQ(nv->value_int, COMBINED_PROGRAM_END))) {
strcpy(tmp, nv->group); // flatten out groups - WARNING - you cannot use strncpy here...
strcat(tmp, nv->token);
strcpy(nv->token, tmp); //...or here.
sr.status_report_value[i] = nv->value;
sr.status_report_value[i] = nv->value_int;
if ((nv = nv->nx) == NULL) return (false); // should never be NULL unless SR length exceeds available buffer array
has_data = true;
@@ -572,23 +573,23 @@ stat_t qr_queue_report_callback() // called by controller dispatcher
*/
stat_t qr_get(nvObj_t *nv)
{
nv->value = (float)mp_get_planner_buffers(mp); // ensure that manually requested QR count is always up to date
nv->valuetype = TYPE_INT;
nv->value_int = mp_get_planner_buffers(mp); // ensure that manually requested QR count is always up to date
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
stat_t qi_get(nvObj_t *nv)
{
nv->value = (float)qr.buffers_added;
nv->valuetype = TYPE_INT;
nv->value_int = qr.buffers_added;
nv->valuetype = TYPE_INTEGER;
qr.buffers_added = 0; // reset it
return (STAT_OK);
}
stat_t qo_get(nvObj_t *nv)
{
nv->value = (float)qr.buffers_removed;
nv->valuetype = TYPE_INT;
nv->value_int = qr.buffers_removed;
nv->valuetype = TYPE_INTEGER;
qr.buffers_removed = 0; // reset it
return (STAT_OK);
}
@@ -640,8 +641,8 @@ stat_t job_set_job_report(nvObj_t *nv)
for (uint8_t i=0; i<4; i++) {
if (((nv = nv->nx) == NULL) || (nv->valuetype == TYPE_EMPTY)) { break;}
if (nv->valuetype == TYPE_INT) {
cfg.job_id[i] = nv->value;
if (nv->valuetype == TYPE_INTEGER) {
cfg.job_id[i] = nv->value_int;
nv->index = job_start + i; // index of the SR persistence location
nv_persist(nv);
} else {

View File

@@ -414,9 +414,9 @@ stat_t sp_set_spo(nvObj_t *nv) { return(set_float_range(nv, spindle.override_fac
// These are provided as a way to view and control spindles without using M commands
stat_t sp_get_spc(nvObj_t *nv) { return(get_int(nv, spindle.state)); }
stat_t sp_set_spc(nvObj_t *nv) { return(spindle_control_immediate((spControl)nv->value)); }
stat_t sp_set_spc(nvObj_t *nv) { return(spindle_control_immediate((spControl)nv->value_int)); }
stat_t sp_get_sps(nvObj_t *nv) { return(get_float(nv, spindle.speed)); }
stat_t sp_set_sps(nvObj_t *nv) { return(spindle_speed_immediate(nv->value)); }
stat_t sp_set_sps(nvObj_t *nv) { return(spindle_speed_immediate(nv->value_flt)); }
/***********************************************************************************
* TEXT MODE SUPPORT

View File

@@ -841,19 +841,19 @@ stat_t st_set_tr(nvObj_t *nv)
stat_t st_get_mi(nvObj_t *nv) { return(get_int(nv, st_cfg.mot[_motor(nv->index)].microsteps)); }
stat_t st_set_mi(nvObj_t *nv)
{
if (nv->value <= 0) {
if (nv->value_int <= 0) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_LESS_THAN_MIN_VALUE);
}
uint8_t mi = (uint8_t)nv->value;
uint8_t mi = (uint8_t)nv->value_int;
if ((mi != 1) && (mi != 2) && (mi != 4) && (mi != 8) && (mi != 16) && (mi != 32)) {
nv_add_conditional_message((const char *)"*** WARNING *** Setting non-standard microstep value");
}
// set it anyway, even if it's unsupported
ritorno(set_int(nv, st_cfg.mot[_motor(nv->index)].microsteps, 1, 255));
_set_motor_steps_per_unit(nv);
_set_hw_microsteps(_motor(nv->index), (uint8_t)nv->value);
_set_hw_microsteps(_motor(nv->index), nv->value_int);
return (STAT_OK);
}
@@ -867,19 +867,19 @@ stat_t st_set_su(nvObj_t *nv)
{
// Don't set a zero or negative value - just calculate based on sa, tr, and mi
// This way, if STEPS_PER_UNIT is set to 0 it is unused and we get the computed value
if(nv->value <= 0) {
nv->value = _set_motor_steps_per_unit(nv);
if(nv->value_flt <= 0) {
nv->value_flt = _set_motor_steps_per_unit(nv);
return(STAT_OK);
}
// Do unit conversion here because it's a reciprocal value (rather than process_incoming_float())
if (cm_get_units_mode(MODEL) == INCHES) {
if (cm_get_axis_type(nv) == AXIS_TYPE_LINEAR) {
nv->value *= INCHES_PER_MM;
nv->value_flt *= INCHES_PER_MM;
}
}
uint8_t m = _motor(nv->index);
st_cfg.mot[m].steps_per_unit = nv->value;
st_cfg.mot[m].steps_per_unit = nv->value_flt;
st_cfg.mot[m].units_per_step = 1.0/st_cfg.mot[m].steps_per_unit;
// Scale TR so all the other values make sense
@@ -896,8 +896,8 @@ stat_t st_set_po(nvObj_t *nv) { return(set_int(nv, st_cfg.mot[_motor(nv->index)]
// power management mode
stat_t st_get_pm(nvObj_t *nv)
{
nv->value = (float)Motors[_motor(nv->index)]->getPowerMode();
nv->valuetype = TYPE_INT;
nv->value_int = (float)Motors[_motor(nv->index)]->getPowerMode();
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
@@ -906,7 +906,7 @@ stat_t st_set_pm(nvObj_t *nv)
// Test the value without setting it, then setPowerMode() now
// to both set and take effect immediately.
ritorno(set_int(nv, (uint8_t &)cs.null, 0, MOTOR_POWER_MODE_MAX_VALUE ));
Motors[_motor(nv->index)]->setPowerMode((stPowerMode)nv->value);
Motors[_motor(nv->index)]->setPowerMode((stPowerMode)nv->value_int);
return (STAT_OK);
}
@@ -923,7 +923,7 @@ stat_t st_set_pl(nvObj_t *nv)
{
uint8_t m = _motor(nv->index);
ritorno(set_float_range(nv, st_cfg.mot[m].power_level, 0.0, 1.0));
st_cfg.mot[m].power_level_scaled = (nv->value * POWER_LEVEL_SCALE_FACTOR);
st_cfg.mot[m].power_level_scaled = (nv->value_flt * POWER_LEVEL_SCALE_FACTOR);
st_run.mot[m].power_level_dynamic = (st_cfg.mot[m].power_level_scaled);
Motors[m]->setPowerLevel(st_cfg.mot[m].power_level_scaled);
return(STAT_OK);
@@ -942,7 +942,7 @@ stat_t st_get_pwr(nvObj_t *nv)
uint8_t motor = (cfgArray[nv->index].token[3] & 0x0F) - 1;
if (motor > MOTORS) { return STAT_INPUT_VALUE_RANGE_ERROR; };
nv->value = Motors[motor]->getCurrentPowerLevel(motor);
nv->value_flt = Motors[motor]->getCurrentPowerLevel(motor);
nv->valuetype = TYPE_FLOAT;
nv->precision = cfgArray[nv->index].precision;
return (STAT_OK);
@@ -972,7 +972,7 @@ stat_t st_set_mt(nvObj_t *nv) { return(set_float_range(nv, st_cfg.motor_power_ti
stat_t st_set_me(nvObj_t *nv)
{
for (uint8_t motor = MOTOR_1; motor < MOTORS; motor++) {
Motors[motor]->enable(nv->value); // nv->value is the timeout or 0 for default
Motors[motor]->enable(nv->value_int); // nv->value is the timeout or 0 for default
}
return (STAT_OK);
}
@@ -981,29 +981,29 @@ stat_t st_set_me(nvObj_t *nv)
// nv-value is motor to disable, or 0 for all motors
stat_t st_set_md(nvObj_t *nv)
{
if (nv->value < 0) {
if (nv->value_int < 0) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_LESS_THAN_MIN_VALUE);
}
if (nv->value > MOTORS) {
if (nv->value_int > MOTORS) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
}
// de-energize all motors
if ((uint8_t)nv->value == 0) { // 0 means all motors
if ((uint8_t)nv->value_int == 0) { // 0 means all motors
for (uint8_t motor = MOTOR_1; motor < MOTORS; motor++) {
Motors[motor]->disable();
}
} else { // otherwise it's just one motor
Motors[(uint8_t)nv->value -1]->disable();
Motors[(uint8_t)nv->value_int -1]->disable();
}
return (STAT_OK);
}
stat_t st_get_dw(nvObj_t *nv)
{
nv->value = st_run.dwell_ticks_downcount;
nv->valuetype = TYPE_INT;
nv->value_int = st_run.dwell_ticks_downcount;
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}
@@ -1039,25 +1039,25 @@ void st_print_mt(nvObj_t *nv) { text_print(nv, fmt_mt);} // TYPE_FLOAT
static void _print_motor_int(nvObj_t *nv, const char *format)
{
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, (int)nv->value);
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, (int)nv->value_int);
xio_writeline(cs.out_buf);
}
static void _print_motor_flt(nvObj_t *nv, const char *format)
{
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->value);
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->value_flt);
xio_writeline(cs.out_buf);
}
static void _print_motor_flt_units(nvObj_t *nv, const char *format, uint8_t units)
{
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->value, GET_TEXT_ITEM(msg_units, units));
sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->value_flt, GET_TEXT_ITEM(msg_units, units));
xio_writeline(cs.out_buf);
}
static void _print_motor_pwr(nvObj_t *nv, const char *format)
{
sprintf(cs.out_buf, format, nv->group, nv->token, nv->token[0], nv->value);
sprintf(cs.out_buf, format, nv->group, nv->token, nv->token[0], nv->value_flt);
xio_writeline(cs.out_buf);
}

File diff suppressed because it is too large Load Diff

View File

@@ -121,9 +121,10 @@ static stat_t _text_parser_kernal(char *str, nvObj_t *nv)
*rd = NUL; // terminate at end of name
strncpy(nv->token, str, TOKEN_LEN);
str = ++rd;
nv->value = strtof(str, &rd); // rd used as end pointer
nv->value_int = atol(str); // collect the number as an integer
nv->value_flt = strtof(str, &rd); // collect the number as a float - rd used as end pointer
if (rd != str) {
nv->valuetype = TYPE_FLOAT;
nv->valuetype = TYPE_FLOAT; // provisionally set it as a float
}
}
@@ -132,6 +133,7 @@ static stat_t _text_parser_kernal(char *str, nvObj_t *nv)
return (STAT_UNRECOGNIZED_NAME);
}
strcpy(nv->group, cfgArray[nv->index].group); // capture the group string if there is one
nv_coerce_types(nv); // adjust types based on type fields in configApp table
// see if you need to strip the token - but only if in text mode
if ((cs.comm_request_mode == TEXT_MODE) && (nv_group_is_prefixed(nv->group))) {
@@ -219,7 +221,7 @@ void tx_print_flt(nvObj_t *nv) { text_print_flt(nv, fmt_flt);}
void tx_print(nvObj_t *nv) {
switch ((int8_t)nv->valuetype) {
case TYPE_FLOAT: { text_print_flt(nv, fmt_flt); break;}
case TYPE_INT: { text_print_int(nv, fmt_int); break;}
case TYPE_INTEGER: { text_print_int(nv, fmt_int); break;}
case TYPE_STRING: { text_print_str(nv, fmt_str); break;}
// TYPE_NULL is not needed in this list as it does nothing
}
@@ -244,25 +246,26 @@ void text_print_str(nvObj_t *nv, const char *format)
void text_print_int(nvObj_t *nv, const char *format)
{
sprintf(cs.out_buf, format, (uint32_t)nv->value);
sprintf(cs.out_buf, format, nv->value_int);
xio_writeline(cs.out_buf);
}
void text_print_flt(nvObj_t *nv, const char *format)
{
sprintf(cs.out_buf, format, nv->value);
sprintf(cs.out_buf, format, nv->value_flt);
xio_writeline(cs.out_buf);
}
void text_print_flt_units(nvObj_t *nv, const char *format, const char *units)
{
sprintf(cs.out_buf, format, nv->value, units);
sprintf(cs.out_buf, format, nv->value_flt, units);
xio_writeline(cs.out_buf);
}
void text_print_bool(nvObj_t *nv, const char *format)
{
sprintf(cs.out_buf, format, !!((uint32_t)nv->value)?"True":"False");
// sprintf(cs.out_buf, format, !!((uint32_t)nv->value)?"True":"False");
sprintf(cs.out_buf, format, (nv->value_int ? "True" : "False"));
xio_writeline(cs.out_buf);
}
@@ -270,9 +273,9 @@ void text_print(nvObj_t *nv, const char *format) {
switch ((int8_t)nv->valuetype) {
case TYPE_NULL: { text_print_nul(nv, format); break;}
case TYPE_FLOAT: { text_print_flt(nv, format); break;}
case TYPE_INT: { text_print_int(nv, format); break;}
case TYPE_INTEGER: { text_print_int(nv, format); break;}
case TYPE_STRING: { text_print_str(nv, format); break;}
case TYPE_BOOL: { text_print_bool(nv, format); break;}
case TYPE_BOOLEAN: { text_print_bool(nv, format); break;}
}
}