Example #1
0
/**
 * \brief This function initialize values of command Tag_Set
 */
struct Generic_Cmd *v_tag_set_create(const uint32 node_id,
		const uint16 taggroup_id,
		const uint16 tag_id,
		const uint8 data_type,
		const uint8 count,
		const void *value)
{
	int i, cmd_id;
	struct Generic_Cmd *tag_set;

	assert(count<=4);

	/* Tricky part :-) */
	cmd_id = CMD_TAG_SET_UINT8 + 4*(data_type-1) + (count-1);

	tag_set = (struct Generic_Cmd *)malloc(UINT8_SIZE +
			cmd_struct[cmd_id].size);

	if(tag_set == NULL) {
		return NULL;
	}

	tag_set->id = cmd_id;
	UINT32(tag_set->data[0]) = node_id;
	UINT16(tag_set->data[UINT32_SIZE]) = taggroup_id;
	UINT16(tag_set->data[UINT32_SIZE + UINT16_SIZE]) = tag_id;

	switch(data_type) {
	case VRS_VALUE_TYPE_UINT8:
		for(i=0; i<count; i++) {
			UINT8(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT8_SIZE]) = ((uint8*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT16:
		for(i=0; i<count; i++) {
			UINT16(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT16_SIZE]) = ((uint16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT32:
		for(i=0; i<count; i++) {
			UINT32(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE  + i*INT32_SIZE]) = ((uint32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT64:
		for(i=0; i<count; i++) {
			UINT64(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT64_SIZE]) = ((uint64*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL16:
		for(i=0; i<count; i++) {
			REAL16(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL16_SIZE]) = ((real16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL32:
		for(i=0; i<count; i++) {
			REAL32(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL32_SIZE]) = ((real32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL64:
		for(i=0; i<count; i++) {
			REAL64(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL64_SIZE]) = ((real64*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_STRING8:
		assert((char*)value != NULL);
		{
			char *name = (char*)value;
			size_t string8_len = strlen(name);

			/* The length of the name can't be longer then 255 bytes. Crop it, when it
			 * is necessary */
			if(string8_len > VRS_STRING8_MAX_SIZE) {
				v_print_log(VRS_PRINT_WARNING, "Cropping string8 %s(length:%d) to length: %d\n",
						name, string8_len, VRS_STRING8_MAX_SIZE);
				string8_len = VRS_STRING8_MAX_SIZE;
			}
			PTR(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]) = strndup(name, string8_len);
		}
		break;
	}

	return tag_set;
}
Example #2
0
/**
 * \brief This function initialize values of command Tag_Set
 */
struct Generic_Cmd *v_layer_set_value_create(const uint32 node_id,
		const uint16 layer_id,
		const uint32 item_id,
		const uint8 data_type,
		const uint8 count,
		const void *value)
{
	int i, cmd_id;
	struct Generic_Cmd *layer_set;

	assert(count<=4);

	/* Tricky part :-) */
	cmd_id = CMD_LAYER_SET_UINT8 + 4*(data_type-1) + (count-1);

	layer_set = (struct Generic_Cmd *)malloc(UINT8_SIZE +
			cmd_struct[cmd_id].size);

	layer_set->id = cmd_id;
	UINT32(layer_set->data[0]) = node_id;
	UINT16(layer_set->data[UINT32_SIZE]) = layer_id;
	UINT32(layer_set->data[UINT32_SIZE + UINT16_SIZE]) = item_id;

	switch(data_type) {
	case VRS_VALUE_TYPE_UINT8:
		for(i=0; i<count; i++) {
			UINT8(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*INT8_SIZE]) = ((uint8*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT16:
		for(i=0; i<count; i++) {
			UINT16(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*INT16_SIZE]) = ((uint16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT32:
		for(i=0; i<count; i++) {
			UINT32(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE  + i*INT32_SIZE]) = ((uint32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT64:
		for(i=0; i<count; i++) {
			UINT64(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*INT64_SIZE]) = ((uint64*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL16:
		for(i=0; i<count; i++) {
			REAL16(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*REAL16_SIZE]) = ((real16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL32:
		for(i=0; i<count; i++) {
			REAL32(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*REAL32_SIZE]) = ((real32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL64:
		for(i=0; i<count; i++) {
			REAL64(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*REAL64_SIZE]) = ((real64*)value)[i];
		}
		break;
	}

	return layer_set;
}