==mvb document== *wiki: http://en.wikipedia.org/wiki/Train_Communication_Network http://en.wikipedia.org/wiki/Train_Communication_Network#External_links *pdf: http://lamspeople.epfl.ch/kirrmann/Pubs/TCN/IEC61375-4-WTB.ppt === Duagon MVB D013 === MVB发送信息必须有一个主设置,用来管理设置地址。我们调试使用的是D013LF。 MVB接收信息使用的MVB析型号是D013L。 MVB驱动代码:https://git.g77k.com/qichunren/d013_linux-driver_serial/tree/master 在使用MVB构建通信网络之前,需要根据具体的使用场景和需求,配置设备地址,sink/source端口,生成一个与之对应的ba_d2000.bin文件,这个用于主设备。这个文件由Duagon人员通过专门的配置工具生成。 [[File:Mvb_device_network.png]] 如图所示,在主设备VCU端口调用put_dataset发送数据时指定的端口对对方设备配置的sink端口,在主设备中调用get_dataset接收数据时指定的端口是对方设备配置的source端口。 配置主设置的相关代码:
#ifdef TCN_DEMO_BA_D2000
	if (0 == result)
	{
		memset((void*)&cm_d2000_parameter, 0, sizeof(cm_d2000_parameter));

		cm_d2000_parameter.nr_entries = 1;
		cm_d2000_parameter.entries_list[0].entry  = \
			CM_D2000_ENTRY_MVB_ADMINISTRATOR;
		cm_d2000_parameter.entries_list[0].bus_id = 0;

#ifdef TCN_CM_PRINT
		TCN_OSL_PRINTF("- cm_config_device()\n");
#endif /* #ifdef TCN_CM_PRINT */
		cm_result =                     \
			cm_config_device            \
			(                           \
				CM_CONFIG_TYPE_D2000,   \
				"ba_d2000.bin",         \
				&cm_d2000_parameter     \
			);
		// cm_result = CM_OK;
		if (cm_result != CM_OK)
		{
			TCN_OSL_PRINTF("CONFIG ERROR: cm_result=%u\n", cm_result);
			TCN_DEMO_ON_ERROR(cm_result);
			result = (UNSIGNED16)cm_result;
		} /* if (cm_result != CM_OK) */
	} /* if (0 == result) */

	/* ----------------------------------------------------------------------
	 *  as_service_handler(SV_MVB_SERVICE_WRITE_CONTROL)
	 * ----------------------------------------------------------------------
	 */
	if (0 == result)
	{
		TCN_OSL_PRINTF \
			("- as_service_handler(SV_MVB_SERVICE_WRITE_CONTROL)\n");
		/* enable BA */
		mvb_control.command |= SV_MVB_CTRL_CMD_BIT_AON;
		as_result =                             \
			as_service_handler                  \
			(                                   \
				0,                              \
				SV_MVB_SERVICE_WRITE_CONTROL,   \
				(void*)&mvb_control             \
			);
		if (as_result != AS_OK)
		{
			TCN_OSL_PRINTF("ERROR: as_result=%u\n", as_result);
			TCN_DEMO_ON_ERROR(as_result);
			result = (UNSIGNED16)as_result;
		} /* if (as_result != AS_OK) */
	} /* if (0 == result) */
#endif /* #ifdef TCN_DEMO_BA_D2000 */
配置设备地址的相关代码:
    /* ----------------------------------------------------------------------
     *  as_service_handler(SV_MVB_SERVICE_WRITE_CONTROL)
     * ----------------------------------------------------------------------
     */
    if (0 == result)
    {
        TCN_OSL_PRINTF \
            ("- as_service_handler(SV_MVB_SERVICE_WRITE_CONTROL)\n");
        /* set device address = 0x001, enable MVB line A & B */
        mvb_control.device_address  = 0x001;
        mvb_control.reserved1       = 0x00;
        mvb_control.t_ignore        = 0x00;
        mvb_control.reserved2       = 0x00;
        mvb_control.command         = SV_MVB_CTRL_CMD_BIT_SLA;
        mvb_control.command        |= SV_MVB_CTRL_CMD_BIT_SLB;
        mvb_control.reserved3       = 0x0000;
        as_result =                             \
            as_service_handler                  \
            (                                   \
                0,                              \
                SV_MVB_SERVICE_WRITE_CONTROL,   \
                (void*)&mvb_control             \
            );
        if (as_result != AS_OK)
        {
            TCN_OSL_PRINTF("ERROR: as_result=%u\n", as_result);
            TCN_DEMO_ON_ERROR(as_result);
            result = (UNSIGNED16)as_result;
        } /* if (as_result != AS_OK) */
    } /* if (0 == result) */
配置设备sink端口的相关代码:
    /* ----------------------------------------------------------------------
     *  ap_port_manage(PD_PRT_CMD_CONFIG)
     * ----------------------------------------------------------------------
     */
    if (0 == result)
    {
        TCN_OSL_PRINTF("- ap_port_manage(PD_PRT_CMD_CONFIG)\n");
        /* configure port 0x010 as sink with size of 2 bytes */
        pd_port_address            = 0x010;
        pd_prt_attr.port_size      = 8;
        pd_prt_attr.port_config    = PD_SINK_PORT;
        pd_prt_attr.p_bus_specific = NULL;
        ap_result =                 \
            ap_port_manage          \
            (                       \
                0,                  \
                pd_port_address,    \
                PD_PRT_CMD_CONFIG,  \
                &pd_prt_attr        \
            );
        if (ap_result != AP_OK)
        {
            TCN_OSL_PRINTF("ERROR: ap_result=%u\n", ap_result);
            TCN_DEMO_ON_ERROR(ap_result);
            result = (UNSIGNED16)ap_result;
        } /* if (ap_result != AP_OK) */
    } /* if (0 == result) */
配置设备source端口的相关代码:
if (0 == result)
    {
        /* configure port 0x018 as source with size of 2 bytes */
        pd_port_address            = 0x018;
        pd_prt_attr.port_size      = 8;
        pd_prt_attr.port_config    = PD_SOURCE_PORT;
        pd_prt_attr.p_bus_specific = NULL;
        ap_result =                 \
            ap_port_manage          \
            (                       \
                0,                  \
                pd_port_address,    \
                PD_PRT_CMD_CONFIG,  \
                &pd_prt_attr        \
            );
        if (ap_result != AP_OK)
        {
            TCN_OSL_PRINTF("ERROR: ap_result=%u\n", ap_result);
            TCN_DEMO_ON_ERROR(ap_result);
            result = (UNSIGNED16)ap_result;
        } /* if (ap_result != AP_OK) */
    } /* if (0 == result) */
发送数据的相关代码:
ds_name.traffic_store_id = 0;
        ds_name.port_address     = 0x018;
        pd_port_data[0]          = 0x12;
        pd_port_data[1]          = 0x34;
        pd_port_data[7]          = 0xA0;
        TCN_OSL_PRINTF("- ap_put_dataset(0x018)\n");
        TCN_OSL_PRINTF("  -> port_data = 0x%02X 0x%02X\n", pd_port_data[0], \
            pd_port_data[1]);
        ap_result = ap_put_dataset(&ds_name, &pd_port_data[0]);
        if (ap_result != AP_OK)
        {
            TCN_OSL_PRINTF("ERROR: ap_result=%u\n", ap_result);
            TCN_DEMO_ON_ERROR(ap_result);
            result = (UNSIGNED16)ap_result;
        } /* if (ap_result != AP_OK) */
接收数据的相关代码:
ds_name.traffic_store_id = 0;
        ds_name.port_address     = 0x010;
        TCN_OSL_PRINTF("- ap_get_dataset(0x010)\n");
        ap_result = ap_get_dataset(&ds_name, &pd_port_data[0], \
            &pd_port_freshness);
        printf("-> %02X %02X %02X %02X %02X %02X %02X %02X\n", pd_port_data[0],
            pd_port_data[1], pd_port_data[2], pd_port_data[3],
            pd_port_data[4], pd_port_data[5], pd_port_data[6],
            pd_port_data[7]);
        TCN_OSL_PRINTF("  -> result    = %d\n", ap_result);
        TCN_OSL_PRINTF("  -> port_data = 0x%02X 0x%02X\n", pd_port_data[0], \
            pd_port_data[1]);
        if (ap_result != AP_OK)
        {
            TCN_OSL_PRINTF("ERROR: ap_result=%u\n", ap_result);
            TCN_DEMO_ON_ERROR(ap_result);
            result = (UNSIGNED16)ap_result;
        } /* if (ap_result != AP_OK) */