⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 robot open source code
💻 C
字号:
/**
 *
 * 文 件 名:Main.c
 *
 * 描    述:
 *
 * 创 建 者:
 *
 * 创建日期:
 *
 * 备    注:
 *
 *
 * * 维护历史 *
 *
 *   <日期>                <修改者>
 *   <修改内容...>
 *
 **/

#include <stdio.h>
#include <stdlib.h>
#include "Main.h"


extern  OBJECT*		g_pCar;
extern  OBJECT*		g_pShip;
extern  OBJECT*		g_pAmphicar;

/*=====================+ OICC label +====================*/

/*<oicc>*/
/*<ibn> OIOIC </ibn>*/
/*<crt>*/
/*</crt>*/
/*</oicc>*/

/*=====================+ Interface +=====================*/

/**
 *
 * 名称:Main_Open
 */
static IRESULT  Main_Open(OBJECT* This, const VR* pCaller)
{
	OBS_OBJECT_OPEN_;

	/* 在下面完成接口自己的任务。*/


	/* ... */


	return IR_P;
}

/**
 *
 * 名称:Main_Input
 */
static IRESULT  Main_Input(OBJECT* This, BYTE* IStrm, BYTKTY Qty, const VR* pCaller)
{

	/* ... */


	/* 在上面完成接口自己的任务。*/

	SBO_OBJECT_INPUT;
}

/**
 *
 * 名称:Main_Output
 */
static IRESULT  Main_Output(OBJECT* This, BYTE* OStrm, BYTKTY Cty, BYTKTY* pQty, const VR* pCaller)
{

	/* ... */


	/* 在上面完成接口自己的任务。*/

	SBO_OBJECT_OUTPUT;
}

/**
 *
 * 名称:Main_IOput
 */
static IRESULT  Main_IOput(OBJECT* This, BYTE* IStrm, BYTKTY Qty, BYTE* OStrm, BYTKTY Cty, BYTKTY* pQty, const VR* pCaller)
{

	/* ... */


	/* 在上面完成接口自己的任务。*/

	SBO_OBJECT_IOPUT;
}

/**
 *
 * 名称:Main_Interact0
 */
static IRESULT  Main_Interact0(OBJECT* This, ACTION Act, const VR* pCaller)
{

	/* ... */


	/* 在上面完成接口自己的任务。*/

	SBO_OBJECT_INTERACT0;
}

/**
 *
 * 名称:Main_Interact1
 */
static IRESULT  Main_Interact1(OBJECT* This, ACTION Act, BYTE* OStrm, BYTKTY Cty, BYTKTY* pQty, const VR* pCaller)
{

	/* ... */


	/* 在上面完成接口自己的任务。*/

	SBO_OBJECT_INTERACT1;
}

/**
 *
 * 名称:Main_Interact2
 */
static IRESULT  Main_Interact2(OBJECT* This, ACTION  Act, BYTE* IStrm, BYTKTY Qty, const VR* pCaller)
{

	/* ... */


	/* 在上面完成接口自己的任务。*/

	SBO_OBJECT_INTERACT2;
}

/**
 *
 * 名称:Main_Interact3
 */
static IRESULT  Main_Interact3(OBJECT* This, ACTION Act, BYTE* IStrm, BYTKTY Qty, BYTE* OStrm, BYTKTY Cty, BYTKTY* pQty, const VR* pCaller)
{

	/* ... */


	/* 在上面完成接口自己的任务。*/

	SBO_OBJECT_INTERACT3;
}

/**
 *
 * 名称:Main_Close
 */
static IRESULT  Main_Close(OBJECT* This, const VR* pCaller)
{
	OBS_OBJECT_CLOSE_;

	/* 在下面完成接口自己的任务。*/


	/* ... */


	return IR_P;
}

/*========================+ TOG +========================*/

/**
 *
 * 名称:TOG_Main
 */
VOID  TOG_Main(OBJECT* pObj)
{
	pObj->Open = Main_Open;
	pObj->Input = Main_Input;
	pObj->Output = Main_Output;
	pObj->IOput = Main_IOput;
	pObj->Interact0 = Main_Interact0;
	pObj->Interact1 = Main_Interact1;
	pObj->Interact2 = Main_Interact2;
	pObj->Interact3 = Main_Interact3;
	pObj->Close = Main_Close;
}


/*=======================+ Main +========================*/

/**
 *
 * 名称:Main
 * 描述:主体函数。
 */
SI32  Main(SI32 argc, SI8 **argv)
{
	IRESULT   ir;
	FRESULT   fr;
	SR32	  sr32_Val;
	BYTKTY    qty;
	VR        caller = {OID_MAIN, OID_FACTORY};

	/* 动态创建car对象。*/
	fr = CreateObject(MSN_CAR, 0, 0, 1, &g_pCar);
	if(NFR(fr))
	{
		printf("Can't create car object.\n");
		return -1;
	}

	/* 动态创建ship对象。*/
	fr = CreateObject(MSN_SHIP, 0, 0, 1, &g_pShip);
	if(NFR(fr))
	{
		printf("Can't create ship object.\n");
		DestroyObject(g_pCar); 
		return -1;
	}

	/* 动态创建amphicar对象。*/
	fr = CreateObject(MSN_AMPHICAR, 0, 0, 1, &g_pAmphicar);
	if(NFR(fr))
	{
		printf("Can't create amphicar object.\n");
		DestroyObject(g_pCar); 
		DestroyObject(g_pShip); 
		return -1;
	}

	/* 打开car对象。*/
    ir = VO_Open(g_pCar, &caller);
	if(NIR(ir))
	{
		printf("Can't open car object.\n");
		DestroyObject(g_pCar); 
		DestroyObject(g_pShip);
		DestroyObject(g_pAmphicar);
		return -1;
	}

	/* 打开ship对象。*/
    ir = VO_Open(g_pShip, &caller);
	if(NIR(ir))
	{
		printf("Can't open ship object.\n");
		VO_Close(g_pCar, &caller);
		DestroyObject(g_pCar);
		DestroyObject(g_pShip); 
		return -1;
	}
	
	/* 打开amphicar对象。*/
    ir = VO_Open(g_pAmphicar, &caller);
	if(NIR(ir))
	{
		printf("Can't open amphicar object.\n");
		VO_Close(g_pCar, &caller);
		DestroyObject(g_pCar);
		VO_Close(g_pShip, &caller);
		DestroyObject(g_pShip);
		DestroyObject(g_pAmphicar); 
		return -1;
	}

	do{
		/* 输出car的重量。*/
		ir = VO_Interact1(g_pCar, GET_WEIGHT, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("car's weight is %f ton.\n", sr32_Val);
		}else
		{
			printf("Can't get car's weight.\n");
			break;
		}

		/* 输出car的最大载重量。*/
		ir = VO_Interact1(g_pCar, GET_MAXLOAD, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("car's max-load is %f ton.\n", sr32_Val);
		}else
		{
			printf("Can't get car's max-load.\n");
			break;
		}

		/* 输出car的最大速度。*/
		ir = VO_Interact1(g_pCar, GET_MAXVELOCITY, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("car's max-velocity is %f km/h.\n", sr32_Val);
		}else
		{
			printf("Can't get car's max-velocity.\n");
			break;
		}

		putchar('\n');

		/* 输出ship的重量。*/
		ir = VO_Interact1(g_pShip, GET_WEIGHT, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("ship's weight is %f ton.\n", sr32_Val);
		}else
		{
			printf("Can't get ship's weight.\n");
			break;
		}

		/* 输出ship的最大载重量。*/
		ir = VO_Interact1(g_pShip, GET_MAXLOAD, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("ship's max-load is %f ton.\n", sr32_Val);
		}else
		{
			printf("Can't get ship's max-load.\n");
			break;
		}

		/* 输出ship的最大速度。*/
		ir = VO_Interact1(g_pShip, GET_MAXVELOCITY, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("ship's max-velocity is %f km/h.\n", sr32_Val);
		}else
		{
			printf("Can't get ship's max-velocity.\n");
			break;
		}

		putchar('\n');

		/* 输出amphicar的重量。*/
		ir = VO_Interact1(g_pAmphicar, GET_WEIGHT, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("amphicar's weight is %f ton.\n", sr32_Val);
		}else
		{
			printf("Can't get amphicar's weight.\n");
			break;
		}

		/* 输出amphicar的陆上最大载重量。*/
		ir = VO_Interact1(g_pAmphicar, GET_TMAXLOAD, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("amphicar's terrestrial max-load is %f ton.\n", sr32_Val);
		}else
		{
			printf("Can't get amphicar's terrestrial max-load.\n");
			break;
		}

		/* 输出amphicar的水上最大载重量。*/
		ir = VO_Interact1(g_pAmphicar, GET_AMAXLOAD, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("amphicar's aquatic max-load is %f ton.\n", sr32_Val);
		}else
		{
			printf("Can't get amphicar's aquatic max-load.\n");
			break;
		}

		/* 输出amphicar的陆上最大速度。*/
		ir = VO_Interact1(g_pAmphicar, GET_TMAXVELOCITY, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("amphicar's terrestrial max-velocity is %f km/h.\n", sr32_Val);
		}else
		{
			printf("Can't get amphicar's terrestrial max-velocity.\n");
			break;
		}

		/* 输出amphicar的水上最大速度。*/
		ir = VO_Interact1(g_pAmphicar, GET_AMAXVELOCITY, (BYTE*)&sr32_Val, sizeof(sr32_Val), &qty, &caller);
		if(PIR(ir))
		{
			printf("amphicar's aquatic max-velocity is %f km/h.\n", sr32_Val);
		}else
		{
			printf("Can't get amphicar's aquatic max-velocity.\n");
			break;
		}
	}while(0);

	ir = VO_Close(g_pCar, &caller);
	if(IR_P_RCZERO == ir)
	{
		DestroyObject(g_pCar); /* 销毁动态创建的car对象。*/
	}else
	{
		/* 因为仅一次打开car对象,如果引用计数不是0,就是错误的。*/
		printf("Reference count is not zero, after close car.\n");
		return -1; 
	}

	ir = VO_Close(g_pShip, &caller);
	if(IR_P_RCZERO == ir)
	{
		DestroyObject(g_pShip); /* 销毁动态创建的ship对象。*/
	}else
	{
		printf("Reference count is not zero, after close ship.\n");
		return -1; 
	}
	
	ir = VO_Close(g_pAmphicar, &caller);
	if(IR_P_RCZERO == ir)
	{
		DestroyObject(g_pAmphicar); /* 销毁动态创建的amphicar对象。*/
	}else
	{
		printf("Reference count is not zero, after close amphicar.\n");
		return -1; 
	}

	return 0;
}


/*=======================+ IRF(s) +======================*/
/*... */

/*====================+ Function(s) +====================*/
/* ... */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -