Пример #1
0
smcp_status_t
smcp_outbound_set_var_content_int(int v) {
	smcp_outbound_add_option_uint(
		COAP_OPTION_CONTENT_TYPE,
		SMCP_CONTENT_TYPE_APPLICATION_FORM_URLENCODED
	);
#if SMCP_AVOID_PRINTF
	{
		char nstr[12];
		smcp_outbound_append_content("v=", SMCP_CSTR_LEN);
		return smcp_outbound_append_content(int32_to_dec_cstr(nstr,v), SMCP_CSTR_LEN);
	}
#else
	return smcp_outbound_set_content_formatted_const("v=%d",v);
#endif
}
Пример #2
0
static smcp_status_t
smcp_group_variable_handler(
	smcp_variable_handler_t node,
	uint8_t action,
	uint8_t i,
	char* value
) {
	smcp_status_t ret = SMCP_STATUS_OK;
	smcp_group_t group = (smcp_group_t)node;

	if (i >= I_COUNT) {
		ret = SMCP_STATUS_NOT_FOUND;
		goto bail;
	}

	if (action == SMCP_VAR_GET_KEY) {
		strcpy(value, names[i]);

	} else if (action == SMCP_VAR_GET_LF_TITLE) {
		strcpy(value, lf_title[i]);

	} else if (action == SMCP_VAR_GET_OBSERVABLE) {
		switch (i) {
		case I_STABLE:
		case I_ENABLED:
			ret = SMCP_STATUS_OK;
			break;
		case I_FQDN:
		case I_ADDR:
			ret = SMCP_STATUS_NOT_IMPLEMENTED;
			break;
		}

	} else if (action == SMCP_VAR_GET_VALUE) {
		switch (i) {
		case I_STABLE:
			int32_to_dec_cstr(value, group->stable);
			break;
		case I_ENABLED:
			int32_to_dec_cstr(value, group->enabled);
			break;
		case I_FQDN:
			strcpy(value, group->fqdn);
			break;
		case I_ADDR:
			SMCP_ADDR_NTOP(value, SMCP_VARIABLE_MAX_VALUE_LENGTH, &group->addr);
			break;
		}

	} else if (action == SMCP_VAR_SET_VALUE) {
		switch (i) {
		case I_STABLE:
			ret = smcp_group_set_stable(group, str2bool(value));
			break;
		case I_ENABLED:
			ret = smcp_group_set_enabled(group, str2bool(value));
			break;
		case I_FQDN:
		case I_ADDR:
			ret = SMCP_STATUS_NOT_IMPLEMENTED;
			break;
		}

	} else {
		ret = SMCP_STATUS_NOT_IMPLEMENTED;
	}

bail:
	return ret;
}