variant_t*  command_class_read_data(device_record_t* record, const char* path)
{
    variant_t* ret_val = NULL;
    zdata_acquire_lock(ZDataRoot(zway));
    ZDataHolder dh = zway_find_device_instance_cc_data(zway, record->nodeId, record->instanceId, record->commandId, path);

    ZWDataType type;
    zdata_get_type(dh, &type);

    switch(type)
    {
    case Integer:
        {
            int int_val;
            zdata_get_integer(dh, &int_val);
            ret_val = variant_create_int32(DT_INT32, int_val);
        }
        break;
    case String:
        {
            const char* string_val;
            zdata_get_string(dh, &string_val);
            ret_val = variant_create_string(strdup(string_val));
        }
        break;
    case Boolean:
        {
            ZWBOOL bool_val;
            zdata_get_boolean(dh, &bool_val);
            ret_val = variant_create_bool((bool)bool_val);
        }
        break;
    default:
        break;

    }
    zdata_release_lock(ZDataRoot(zway));
    return ret_val;
}
Exemplo n.º 2
0
void dataChangeCallback(const ZWay aZWay, ZWDataChangeType aType, ZDataHolder aData) {
    ZWBOOL value;
    zdata_get_boolean(aData, &value);
    printf("binary switch %d\n", value);
}
Exemplo n.º 3
0
void dump_data(const ZWay zway, ZDataHolder data) {
	char *path = zdata_get_path(data);
	ZWDataType type;
	zdata_get_type(data, &type);

	ZWBOOL bool_val;
	int int_val;
	float float_val;
	ZWCSTR str_val;
	const ZWBYTE *binary;
	const int *int_arr;
	const float *float_arr;
	const ZWCSTR *str_arr;
	size_t len, i;

	switch (type) {
	case Empty:
		zway_log(zway, Debug, ZSTR("DATA %s = Empty"), path);
		break;
	case Boolean:
		zdata_get_boolean(data, &bool_val);
		if (bool_val)
			zway_log(zway, Debug, ZSTR("DATA %s = True"), path);
		else
			zway_log(zway, Debug, ZSTR("DATA %s = False"), path);
		break;
	case Integer:
		zdata_get_integer(data, &int_val);
		zway_log(zway, Debug, ZSTR("DATA %s = %d (0x%08x)"), path, int_val,
				int_val);
		break;
	case Float:
		zdata_get_float(data, &float_val);
		zway_log(zway, Debug, ZSTR("DATA %s = %f"), path, float_val);
		break;
	case String:
		zdata_get_string(data, &str_val);
		zway_log(zway, Debug, ZSTR("DATA %s = \"%s\""), path, str_val);
		break;
	case Binary:
		zdata_get_binary(data, &binary, &len);
		zway_log(zway, Debug, ZSTR("DATA %s = byte[%d]"), path, len);
		zway_dump(zway, Debug, ZSTR("  "), len, binary);
		break;
	case ArrayOfInteger:
		zdata_get_integer_array(data, &int_arr, &len);
		zway_log(zway, Debug, ZSTR("DATA %s = int[%d]"), path, len);
		for (i = 0; i < len; i++)
			zway_log(zway, Debug, ZSTR("  [%02d] %d"), i, int_arr[i]);
		break;
	case ArrayOfFloat:
		zdata_get_float_array(data, &float_arr, &len);
		zway_log(zway, Debug, ZSTR("DATA %s = float[%d]"), path, len);
		for (i = 0; i < len; i++)
			zway_log(zway, Debug, ZSTR("  [%02d] %f"), i, float_arr[i]);
		break;
	case ArrayOfString:
		zdata_get_string_array(data, &str_arr, &len);
		zway_log(zway, Debug, ZSTR("DATA %s = string[%d]"), path, len);
		for (i = 0; i < len; i++)
			zway_log(zway, Debug, ZSTR("  [%02d] \"%s\""), i, str_arr[i]);
		break;
	}
	free(path);

	ZDataIterator child = zdata_first_child(data);
	while (child != NULL) {
		path = zdata_get_path(child->data);
		zway_log(zway, Debug, ZSTR("CHILD %s"), path);
		free(path);
		child = zdata_next_child(child);
	}
	//printf("intval : %d \n", int_val);
}