Beispiel #1
0
static stat_t _json_parser_kernal(char *str)
{
	stat_t status;
	int8_t depth;
	nvObj_t *nv = nv_reset_nv_list();				// get a fresh nvObj list
	char group[GROUP_LEN+1] = {""};				// group identifier - starts as NUL
	int8_t i = NV_BODY_LEN;

	ritorno(_normalize_json_string(str, JSON_OUTPUT_STRING_MAX));	// return if error

	// parse the JSON command into the nv body
	do {
		if (--i == 0) { return (STAT_JSON_TOO_MANY_PAIRS); } // length error
//		if ((status = _get_nv_pair_strict(nv, &str, &depth)) > STAT_EAGAIN) { // erred out
		if ((status = _get_nv_pair(nv, &str, &depth)) > STAT_EAGAIN) { // erred out
			return (status);
		}
		// propagate the group from previous NV pair (if relevant)
		if (group[0] != NUL) {
			strncpy(nv->group, group, GROUP_LEN);	// copy the parent's group to this child
		}
		// validate the token and get the index
		if ((nv->index = nv_get_index(nv->group, nv->token)) == NO_MATCH) {
			nv->valuetype = TYPE_NULL;
			return (STAT_UNRECOGNIZED_NAME);
		}
		if ((nv_index_is_group(nv->index)) && (nv_group_is_prefixed(nv->token))) {
			strncpy(group, nv->token, GROUP_LEN);	// record the group ID
		}
		if ((nv = nv->nx) == NULL) return (STAT_JSON_TOO_MANY_PAIRS);// Not supposed to encounter a NULL
	} while (status != STAT_OK);					// breaks when parsing is complete

	// execute the command
	nv = nv_body;
	if (nv->valuetype == TYPE_NULL){				// means GET the value
		ritorno(nv_get(nv));						// ritorno returns w/status on any errors
	} else {
        cm_parse_clear(*nv->stringp);               // parse Gcode and clear alarms if M30 or M2 is found
        ritorno(cm_is_alarmed());                   // return error status if in alarm, shutdown or panic
		ritorno(nv_set(nv));						// set value or call a function (e.g. gcode)
		nv_persist(nv);
	}
	return (STAT_OK);								// only successful commands exit through this point
}
Beispiel #2
0
stat_t _json_parser_kernal(char *str)
{
	uint8_t status;
	int8_t depth;
	cmdObj_t *cmd = cmd_reset_list();			// get a fresh cmdObj list
	char group[CMD_GROUP_LEN+1] = {""};			// group identifier - starts as NUL
	int8_t i = CMD_BODY_LEN;

	ritorno(_normalize_json_string(str, JSON_OUTPUT_STRING_MAX));	// return if error

	// parse the JSON command into the cmd body
	do {
		if (--i == 0) { return (STAT_JSON_TOO_MANY_PAIRS); }			// length error
		if ((status = _get_nv_pair_strict(cmd, &str, &depth)) > STAT_EAGAIN) { // erred out
			return (status);
		}
		// propagate the group from previous NV pair (if relevant)
		if (group[0] != NUL) {
			strncpy(cmd->group, group, CMD_GROUP_LEN);// copy the parent's group to this child
		}
		// validate the token and get the index
		if ((cmd->index = cmd_get_index(cmd->group, cmd->token)) == NO_MATCH) { 
			return (STAT_UNRECOGNIZED_COMMAND);
		}
		if ((cmd_index_is_group(cmd->index)) && (cmd_group_is_prefixed(cmd->token))) {
			strncpy(group, cmd->token, CMD_GROUP_LEN);// record the group ID
		}
		if ((cmd = cmd->nx) == NULL) return (STAT_JSON_TOO_MANY_PAIRS);// Not supposed to encounter a NULL
	} while (status != STAT_OK);					// breaks when parsing is complete

	// execute the command
	cmd = cmd_body;
	if (cmd->objtype == TYPE_NULL){				// means GET the value
		ritorno(cmd_get(cmd));					// ritorno returns w/status on any errors
	} else {
		ritorno(cmd_set(cmd));					// set value or call a function (e.g. gcode)
		cmd_persist(cmd);
	}
	return (STAT_OK);								// only successful commands exit through this point
}