Beispiel #1
0
END_TEST

START_TEST (null_sequence)
{
    reset_errno();
    assert_null(sequence_get(NULL, 0));
    assert_errno(EINVAL);
}
Beispiel #2
0
END_TEST

START_TEST (key_anchor)
{
    document_model *model = anchor_setup(KEY_ANCHOR_YAML);
    node *root = model_document_root(model, 0);

    reset_errno();
    node *one = mapping_get(root, (uint8_t *)"one", 3ul);
    assert_noerr();
    assert_not_null(one);
    assert_node_kind(one, SEQUENCE);
    assert_node_size(one, 2);

    reset_errno();
    node *alias1 = sequence_get(one, 1);
    assert_noerr();
    assert_not_null(alias1);
    assert_node_kind(alias1, ALIAS);

    node *one_1 = alias_target(alias1);
    assert_noerr();
    assert_not_null(one_1);
    assert_node_kind(one_1, SCALAR);
    assert_scalar_kind(one_1, SCALAR_STRING);
    assert_scalar_value(one_1, "one");
    reset_errno();

    node *alias2 = mapping_get(root, (uint8_t *)"two", 3ul);
    assert_noerr();
    assert_not_null(alias2);

    node *two = alias_target(alias2);
    assert_node_kind(two, SCALAR);
    assert_scalar_kind(two, SCALAR_STRING);
    assert_scalar_value(two, "one");
}
Beispiel #3
0
static qeo_retcode_t data_member_accessor(qeocore_data_t *data,
                                          qeocore_member_id_t id,
                                          void *value,
                                          int get)
{
    qeo_retcode_t rc = QEO_EINVAL;
    DDS_ReturnCode_t ddsrc;
    DDS_DynamicTypeMember mtype = DDS_DynamicTypeMember__alloc();
    DDS_DynamicType dyntype = dtype_from_data(data, &data->d.dynamic);
    DDS_DynamicData dyndata = (DDS_DynamicData)sample_from_data(data);

    if (NULL != mtype) {
        ddsrc = DDS_DynamicType_get_member(dyntype, mtype, id);
        qeo_log_dds_rc("DDS_DynamicType_get_member", ddsrc);
        if (DDS_RETCODE_OK == ddsrc) {
            DDS_ReturnCode_t ddsrc = DDS_RETCODE_BAD_PARAMETER;
            DDS_MemberDescriptor mdesc = { 0 };
            DDS_TypeDescriptor tdesc = { 0 };

            ddsrc = DDS_DynamicTypeMember_get_descriptor(mtype, &mdesc);
            qeo_log_dds_rc("DDS_DynamicTypeMember_get_descriptor", ddsrc);
            ddsrc = DDS_DynamicType_get_descriptor(mdesc.type, &tdesc);
            qeo_log_dds_rc("DDS_DynamicType_get_descriptor", ddsrc);
            switch (tdesc.kind) {
                case DDS_BOOLEAN_TYPE: {
                    if (get) {
                        ddsrc = DDS_DynamicData_get_boolean_value(dyndata, (qeo_boolean_t *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_boolean_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_boolean_value(dyndata, id, *((qeo_boolean_t *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_boolean_value", ddsrc);
                    }
                    break;
                }
                case DDS_BYTE_TYPE: /* QEOCORE_TYPECODE_INT8 */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_byte_value(dyndata, (unsigned char *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_byte_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_byte_value(dyndata, id, *((unsigned char *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_byte_value", ddsrc);
                    }
                    break;
                case DDS_INT_16_TYPE: /* QEOCORE_TYPECODE_INT16 */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_int16_value(dyndata, (int16_t *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_int16_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_int16_value(dyndata, id, *((int16_t *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_int16_value", ddsrc);
                    }
                    break;
                case DDS_INT_32_TYPE: /* QEOCORE_TYPECODE_INT32 */
                case DDS_ENUMERATION_TYPE: /* QEOCORE_TYPECODE_ENUM */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_int32_value(dyndata, (int32_t *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_int32_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_int32_value(dyndata, id, *((int32_t *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_int32_value", ddsrc);
                    }
                    break;
                case DDS_INT_64_TYPE: /* QEOCORE_TYPECODE_INT64 */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_int64_value(dyndata, (int64_t *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_int64_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_int64_value(dyndata, id, *((int64_t *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_int64_value", ddsrc);
                    }
                    break;
                case DDS_FLOAT_32_TYPE: /* QEOCORE_TYPECODE_FLOAT32 */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_float32_value(dyndata, (float *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_float32_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_float32_value(dyndata, id, *((float *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_float32_value", ddsrc);
                    }
                    break;
                case DDS_STRING_TYPE: /* QEOCORE_TYPECODE_STRING */
                    if (get) {
                        char **string = (char **)value;
                        int len = DDS_DynamicData_get_string_length(dyndata, id);

                        if (len > -1) {
                            *string = malloc(len + 1);
                            if (NULL != *string) {
                                ddsrc = DDS_DynamicData_get_string_value(dyndata, *string, id);
                                qeo_log_dds_rc("DDS_DynamicData_get_string_value", ddsrc);
                                if (DDS_RETCODE_OK != ddsrc) {
                                    free(*string);
                                    *string = NULL;
                                }
                            }
                        }
                    }
                    else {
                        char **string = (char **)value;

                        ddsrc = DDS_DynamicData_set_string_value(dyndata, id, *string);
                        qeo_log_dds_rc("DDS_DynamicData_set_string_value", ddsrc);
                    }
                    break;
                case DDS_SEQUENCE_TYPE: { /* QEOCORE_TYPECODE_SEQUENCE */
                    if (get) {
                        ddsrc = sequence_get(value, dyndata, id, mdesc.type);
                    }
                    else {
                        ddsrc = sequence_set(value, dyndata, id);
                    }
                    break;
                }
                case DDS_STRUCTURE_TYPE: { /* QEOCORE_TYPECODE_STRUCT */
                    qeocore_data_t **inner_data = (qeocore_data_t **)value;

                    if (get) {
                        ddsrc = struct_get(inner_data, dyndata, id, &mdesc);
                    }
                    else {
                        ddsrc = struct_set(inner_data, dyndata, id);
                    }
                    break;
                }
                default:
                    qeo_log_e("unsupported type %d", tdesc.kind);
                    abort(); // unsupported for now
                    break;
            }
            DDS_MemberDescriptor__clear(&mdesc);
            DDS_TypeDescriptor__clear(&tdesc);

            //TODO: Make the following code more generic and use the overall error translation function
            if ((DDS_RETCODE_OK == ddsrc) || (DDS_RETCODE_NO_DATA == ddsrc)){
                rc = QEO_OK;
            } else if (DDS_RETCODE_OUT_OF_RESOURCES == ddsrc) {
                rc = QEO_ENOMEM;
            } else {
                rc = QEO_EFAIL;
            }
        }
        DDS_DynamicTypeMember__free(mtype);
    }
    return rc;
}
Beispiel #4
0
END_TEST

static void assert_model_state(loader_context *loader, document_model *model)
{
    assert_int_eq(LOADER_SUCCESS, loader_status(loader));
    assert_not_null(model);
    assert_uint_eq(1, model_document_count(model));

    reset_errno();
    node *root = model_document_root(model, 0);
    assert_noerr();
    assert_not_null(root);
    
    assert_node_kind(root, MAPPING);
    assert_node_size(root, 5);

    reset_errno();
    node *one = mapping_get(root, (uint8_t *)"one", 3ul);
    assert_noerr();
    assert_not_null(one);
    assert_node_kind(one, SEQUENCE);
    assert_node_size(one, 2);

    reset_errno();
    node *one_0 = sequence_get(one, 0);
    assert_noerr();
    assert_node_kind(one_0, SCALAR);
    assert_scalar_value(one_0, "foo1");
    assert_scalar_kind(one_0, SCALAR_STRING);
    reset_errno();
    node *one_1 = sequence_get(one, 1);
    assert_noerr();
    assert_node_kind(one_1, SCALAR);
    assert_scalar_value(one_1, "bar1");
    assert_scalar_kind(one_1, SCALAR_STRING);

    reset_errno();
    node *two = mapping_get(root, (uint8_t *)"two", 3ul);
    assert_noerr();
    assert_not_null(two);
    assert_node_kind(two, SCALAR);
    assert_scalar_value(two, "foo2");
    assert_scalar_kind(two, SCALAR_STRING);

    reset_errno();
    node *three = mapping_get(root, (uint8_t *)"three", 5ul);
    assert_noerr();
    assert_not_null(three);
    assert_node_kind(three, SCALAR);
    assert_scalar_value(three, "null");
    assert_scalar_kind(three, SCALAR_NULL);

    reset_errno();
    node *four = mapping_get(root, (uint8_t *)"four", 4ul);
    assert_noerr();
    assert_not_null(four);
    assert_node_kind(four, SEQUENCE);

    reset_errno();
    node *four_0 = sequence_get(four, 0);
    assert_noerr();
    assert_node_kind(four_0, SCALAR);
    assert_scalar_value(four_0, "true");
    assert_scalar_kind(four_0, SCALAR_BOOLEAN);
    assert_true(scalar_boolean_is_true(four_0));
    assert_false(scalar_boolean_is_false(four_0));
    reset_errno();
    node *four_1 = sequence_get(four, 1);
    assert_noerr();
    assert_node_kind(four_0, SCALAR);
    assert_scalar_value(four_1, "false");
    assert_scalar_kind(four_1, SCALAR_BOOLEAN);
    assert_true(scalar_boolean_is_false(four_1));
    assert_false(scalar_boolean_is_true(four_1));

    reset_errno();
    node *five = mapping_get(root, (uint8_t *)"five", 4ul);
    assert_noerr();
    assert_not_null(five);
    assert_node_kind(five, SEQUENCE);
    node *five_0 = sequence_get(five, 0);
    assert_noerr();
    assert_node_kind(five_0, SCALAR);
    assert_scalar_value(five_0, "1.5");
    assert_scalar_kind(five_0, SCALAR_REAL);
    reset_errno();
    node *five_1 = sequence_get(five, 1);
    assert_noerr();
    assert_node_kind(five_1, SCALAR);
    assert_scalar_value(five_1, "42");
    assert_scalar_kind(five_1, SCALAR_INTEGER);
    reset_errno();
    node *five_2 = sequence_get(five, 2);
    assert_noerr();
    assert_node_kind(five_2, SCALAR);
    assert_scalar_value(five_2, "1978-07-26 10:15");
    assert_scalar_kind(five_2, SCALAR_TIMESTAMP);
    reset_errno();
}
Beispiel #5
0
END_TEST

START_TEST (sequence_type)
{
    reset_errno();
    Node *r = model_document_root(model, 0);
    assert_noerr();
    assert_not_null(r);
    assert_node_kind(r, MAPPING);

    reset_errno();
    Node *s = mapping_get(mapping(r), (uint8_t *)"one", 3ul);
    assert_noerr();
    assert_not_null(s);
    assert_node_kind(s, SEQUENCE);
    assert_node_size(s, 2);
    
    reset_errno();
    Node *zero = sequence_get(sequence(s), 0);
    assert_noerr();
    assert_not_null(zero);
    assert_node_kind(zero, SCALAR);
    
    reset_errno();
    Node *one = sequence_get(sequence(s), 1);
    assert_noerr();
    assert_not_null(one);
    assert_node_kind(one, SCALAR);

    reset_errno();
    Scalar *x = make_scalar_node((uint8_t *)"x", 1, SCALAR_STRING);
    assert_noerr();
    assert_not_null(x);
    reset_errno();
    Scalar *y = make_scalar_node((uint8_t *)"y", 1, SCALAR_STRING);
    assert_noerr();
    assert_not_null(y);
    reset_errno();
    Scalar *z = make_scalar_node((uint8_t *)"z", 1, SCALAR_STRING);
    assert_noerr();
    assert_not_null(z);
    reset_errno();
    Sequence *xyz = make_sequence_node();
    assert_noerr();
    assert_not_null(xyz);

    reset_errno();
    sequence_add(xyz, node(x));
    assert_noerr();
    reset_errno();
    sequence_add(xyz, node(y));
    assert_noerr();
    reset_errno();
    sequence_add(xyz, node(z));
    assert_noerr();
    assert_uint_eq(3, node_size(node(xyz)));
    assert_ptr_eq(node(x), sequence_get(xyz, 0));
    assert_ptr_eq(node(y), sequence_get(xyz, 1));
    assert_ptr_eq(node(z), sequence_get(xyz, 2));
    node_free(node(xyz));
}
Beispiel #6
0
	if ((XRESET_GPIO_pin > 7) || (DREQ_GPIO_pin > 7))
		return MP3_VS1053_INVALID_PARAMETER;

	mp3_VS1053_prvt_ctx.hSpiMaster = spi_master_handle;
	mp3_VS1053_prvt_ctx.XRESET_GPIO_port = XRESET_GPIO_port;
	mp3_VS1053_prvt_ctx.XRESET_GPIO_pin = XRESET_GPIO_pin;
	mp3_VS1053_prvt_ctx.DREQ_GPIO_port = DREQ_GPIO_port;
	mp3_VS1053_prvt_ctx.DREQ_GPIO_pin = DREQ_GPIO_pin;
	mp3_VS1053_prvt_ctx.SDI_CS_identifier = SDI_CS_identifier;
	mp3_VS1053_prvt_ctx.SCI_CS_identifier = SCI_CS_identifier;

	return MP3_VS1053_OK;
}

int	mp3_VS1053_detach()
{
	mp3_VS1053_prvt_ctx.hSpiMaster = NULL;

	return MP3_VS1053_OK;
}

int mp3_VS1053_hard_reset(void)
{
	unsigned char mask;
	mask = 0x01 << mp3_VS1053_prvt_ctx.XRESET_GPIO_pin;

	switch (mp3_VS1053_prvt_ctx.XRESET_GPIO_port)
	{
		case PORT_A:
			vII_gpio_data_tx_pa_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pa_1 |= mask; // set the pin HIGH
			break;
		case PORT_B:
			vII_gpio_data_tx_pb_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pb_1 |= mask; // set the pin HIGH
			break;
		case PORT_C:
			vII_gpio_data_tx_pc_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pc_1 |= mask; // set the pin HIGH
			break;
		case PORT_D:
			vII_gpio_data_tx_pd_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pd_1 |= mask; // set the pin HIGH
			break;
		case PORT_E:
			vII_gpio_data_tx_pe_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pe_1 |= mask; // set the pin HIGH
			break;
		default:
			return MP3_VS1053_INVALID_PARAMETER;
	}
	return MP3_VS1053_OK;
}
	
int mp3_VS1053_soft_reset(void)
{
	mp3_VS1053_write_reg(SCI_MODE, MASK_SM_RESET); // Set Reset bit in mode register
	vos_delay_msecs(2); // At least 2 millisecond delay
	mp3_VS1053_wait_for_dreq(); // wait for startup
	// Then set mode register and clock register again
	mp3_VS1053_write_reg(SCI_MODE, MASK_SM_SDINEW_VS1002);
	mp3_VS1053_write_reg(SCI_CLOCKF, 0x8800);
	vos_delay_msecs(1); // 1 millisecond delay
	mp3_VS1053_wait_for_dreq(); // wait for the commands to complete

	return MP3_VS1053_OK;
}	

int mp3_VS1053_setup(void)
{
	unsigned short regVal;
	common_ioctl_cb_t spim_iocb;

	// Initialize SPI pins
	// Reset VS1053 codec hardware
	mp3_VS1053_hard_reset();
	// Configure VS1053 defaults
	mp3_VS1053_write_reg(SCI_MODE, MASK_SM_SDINEW_VS1002);	
	mp3_VS1053_write_reg(SCI_CLOCKF, 0xe000);
	return 0;
}

// Waits for the DREQ line to go high...
int mp3_VS1053_wait_for_dreq(void)
{
	unsigned char port_value = 0, mask;
	int timeout = 0;
	
	mask = 0x01 << mp3_VS1053_prvt_ctx.DREQ_GPIO_pin;
	
	switch (mp3_VS1053_prvt_ctx.DREQ_GPIO_port)
	{
		case PORT_A:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do
			{
				port_value = vII_gpio_data_rx_pa_1;
			}
			while ((port_value & mask) == 0);
			break;
		case PORT_B:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do {
				port_value = vII_gpio_data_rx_pb_1;
				//vos_delay_msecs(1);
			} while ((port_value & mask) == 0);
			break;
		case PORT_C:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do
			{
				port_value = vII_gpio_data_rx_pc_1;
			}
			while ((port_value & mask) == 0);
			break;
		case PORT_D:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do
			{
				port_value = vII_gpio_data_rx_pd_1;
			}
			while ((port_value & mask) == 0);
			break;
		case PORT_E:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do
			{
				port_value = vII_gpio_data_rx_pe_1;
			}
			while ((port_value & mask) == 0);
			break;
		default:
			return MP3_VS1053_INVALID_PARAMETER;
	}		
}

int mp3_VS1053_select_control(void)	
{
	if (mp3_VS1053_prvt_ctx.SCI_CS_identifier == SPI_CHIP_SELECT_0)
		spim_iocb.ioctl_code = VOS_IOCTL_SPI_MASTER_SS_0;
	else if (mp3_VS1053_prvt_ctx.SCI_CS_identifier == SPI_CHIP_SELECT_1)
		spim_iocb.ioctl_code = VOS_IOCTL_SPI_MASTER_SS_1;
	spim_iocb.set.param = SPI_MASTER_SS_ENABLE;
	vos_dev_ioctl(mp3_VS1053_prvt_ctx.hSpiMaster, &spim_iocb);
	
	return MP3_VS1053_OK;