Beispiel #1
0
int waitAnswer(uint32_t TIMEOUT, const char *MSG_TRUE, const char *MSG_FALSE)
{
uint32_t now = 0;
char ret[BUFFER_SZ];
int i = 0;
	c_memset(ret,0,BUFFER_SZ);
	now = system_get_time() + TIMEOUT;
	while( now > system_get_time() )
	{
		system_soft_wdt_feed ();
		if( uart_getc(&ret[i & BUFFER_MSK]) )
		{
			if( ret[i] == 0 )
				i--;

			i++;
			if( i >= c_strlen(MSG_TRUE) || i >= c_strlen(MSG_FALSE) )
			{
				milisec(1);
				if( STRCMP((char*)MSG_TRUE, (char*)HTTP_OK) != 0 )
				{
					if( c_strstr(ret,MSG_TRUE) != NULL )
						return 1;
					else if( c_strstr(ret,MSG_FALSE) != NULL )
						return 2;
				}else
				{
					if( c_strstr(ret,HTTP_ANSWER[0]) != NULL )
						return 1;
					else if( c_strstr(ret,HTTP_ANSWER[1]) != NULL )
						return 3;
					else if( c_strstr(ret,HTTP_ANSWER[2]) != NULL )
						return 4;
					else if( c_strstr(ret,HTTP_ANSWER[3]) != NULL )
						return 5;
					else if( c_strstr(ret,HTTP_ANSWER[4]) != NULL )
						return 6;
					else if( c_strstr(ret,MSG_FALSE) != NULL )
						return 2;
				}
			}
		}
	}
	milisec(1);
	return 0;
}
Beispiel #2
0
int gprs_StartSocket(lua_State *L)
{
int timeout = luaL_checkinteger(L, 1)*1000000;
const char *URL = luaL_checkstring( L, 2 );
char Aux[BUFFER_SZ];
char cont;
	if( URL == NULL )
		return 0;
	c_memset(Aux,0,BUFFER_SZ);
	c_sprintf(Aux, CIPSTART, URL );
	sendCommand(GETSTATUS, MSG_OK, MSG_NOK, 2, timeout);
	sendCommand(GETSTATUS, MSG_OK, MSG_NOK, 2, timeout);
	//milisec(1000);
	for( cont = 0; cont < 5; cont++ )
	{
		if( sendCommonCommand(L, Aux) == 1 )
			return 1;
		else
			sendCommand(CIPCLOSE,MSG_OK,MSG_NOK,strlen(CIPCLOSE),2000000);
		milisec(500);
	}
	return 0;
}
Beispiel #3
0
	//------------------------------------------
	bool CEngine::Initialize(const wchar* settings/*="game.ini"*/, bool customWindow/*=false*/, sDisplayProperties *dp/*=NULL*/){
		assertd(s_bInit==false, "DOUBLE ENGINE INITIALIZATION!");

		s_bInit = true; //predict :-P

		// initialize random generator
		srand( (unsigned int)milisec() );

		cInternalWindow()->BeginSplash();

		// memory leaks detection
#if defined(_DEBUG) && defined(_MSC_VER) && _MSC_VER >= 800
		_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
		//_CrtSetBreakAlloc(23296);
#endif

		// ---------------------------------------------------
		// QUEUE TESTS
		CON(MSG_INFO, _W("------- Command Queue Test -------"));
		CCommandQueue q;
		DWORD tim;
		for (int t=0; t<10; t++)
		{
			tim = GetTickCount();
			// FILL IN QUEUE
			for (int i=0; i<20000; i++)
			{
					sE2RCanvasDesc *cd;
					q.Enqueue(NULL, CQI_ENGINE2RENDERER_CANVAS_CREATE, (void*&)cd, sizeof(sE2RCanvasDesc));
					cd->handle = 0;
			}
			CON(MSG_INFO, _W("Iteration #%d: Enqueue %d ms"), t, GetTickCount()-tim );

			// DEQUEUE
			unsigned int cqi; const void* optr; IQueueCommandReceiver *recv;
			tim = GetTickCount();
			while (q.Dequeue(cqi, optr, recv))
			{
				switch(cqi)
				{
				case CQI_ENGINE2RENDERER_CANVAS_CREATE:
					{
						sE2RCanvasDesc *cd = (sE2RCanvasDesc *)optr;
					}
					break;
				}
			}
			CON(MSG_INFO, _W("Iteration #%d: Dequeue %d ms"), t, GetTickCount()-tim );
		}
		CON(MSG_INFO, _W("----------------------------------"));
		// ---------------------------------------------------


		// --- WRITE INFO ABOUT LIBRARIES AND MODULES
		I_DebugPrint( ConsoleMsg );

		CON(MSG_INFO, _W("= %s %s build %d initialization ="), _W(P3DNAME), sizeof(void*)==8?_W("x64"):_W("x86"), GetBuildNum());
		if (sizeof(wchar)>1) 
			CON(MSG_INFO, _W("Unicode support \x263A"));
		else
			CON(MSG_INFO, _W("Multibyte character set"));

		// --- LOAD SETTINGS
		m_szSettings = new wchar[wstrlen(settings)+1];
		wstrcpy(m_szSettings, settings);

		cConfig()->Load(m_szSettings);
		//cConfig()->Save(m_szSettings);

		// --- INITIALIZE SCRIPT SYSTEM
		CON(MSG_INFO, _W("Script system initialization"));
		cScriptEngine()->Initialize();

		// --- LOAD KEY BINDINGS
		cInputManager()->Assign(_W("GUI_CURSOR"), WE_MOUSE_MOTION, 0);
		cInputManager()->Assign(_W("GUI_SELECT"), WE_MOUSE_DOWN, 0);

		cInputManager()->Save(_W("keys.ini")); // TODO: FIXME: What about load? :D

		// --- CREATE MAIN WINDOW
		Vec2i mainWindowSize(800,600);
		bool initFullscreen = false;
		if (customWindow)
		{
			// use primary screen resolution for frame buffer
			// TODO: multiplatform
#ifdef _WIN32
			mainWindowSize.x = GetSystemMetrics(SM_CXSCREEN);
			mainWindowSize.y = GetSystemMetrics(SM_CYSCREEN);
#endif
		}
		else
		{
			if (dp) 
			{
				// use user-defined resolution
				initFullscreen = dp->Fullscreen;
				mainWindowSize.x = dp->HorRes;
				mainWindowSize.y = dp->VertRes;
			}
			else
			{
				// use settings
				initFullscreen = svFullscreen.GetBool();
				mainWindowSize.x = svResolutionX.GetInt();
				mainWindowSize.y = svResolutionY.GetInt();
			}
		}
		cInternalWindow()->Create(mainWindowSize);

		//Init the internal input system
		cInternalInput()->Init( cInternalWindow()->GetHandle() );
		//Init the Filesystem
		cFilesystem()->Init();

		
		// --- LOAD SELECTED MODULES
		s_pRenderer = (IRenderer*)I_GetModule(_W("renderer"), svRenderer.GetString());
		if (!s_pRenderer) CON(MSG_ERR_FATAL, _W("Cannot load renderer module. It is a core module, cannot continue!"));
		s_pSound = (ISoundEngine*)I_GetModule(_W("sound"), svSound.GetString());
		if (!s_pSound) CON(MSG_ERR_FATAL, _W("Cannot load sound module. It is a core module, cannot continue!"));
		s_pPhys = (IPhysEngine*)I_GetModule(_W("physics"), svPhysics.GetString());
		if (!s_pPhys) CON(MSG_ERR_FATAL, _W("Cannot load phys module. It is a core module, cannot continue!"));
		s_pFS = (IFileSystem*)I_GetModule(_W("filesystem"), svFileSystem.GetString());
		if (!s_pFS) CON(MSG_ERR_FATAL, _W("Cannot load filesystem module. It is a core module, cannot continue!"));
		s_pGUI = (IGUI*)I_GetModule(_W("gui"), svGUI.GetString());
		if (!s_pGUI) CON(MSG_ERR_FATAL, _W("Cannot load GUI module. It is a core module, cannot continue!"));
		m_bModulesLoaded=true;

		// ==== INITIALIZE MODULES ====
		s_pRenderer->Initialize(this, &m_queueRenderer);

		bool ret = s_pRenderer->iGraphicsDevice()->Initialize(mainWindowSize.x, mainWindowSize.y, initFullscreen, cInternalWindow()->GetHandle());
		if (!ret)
		{
			CON(MSG_ERR_FATAL, _W("Failed to initialize graphics device!"));
		}

		// ===== SERIALIZATION DEBUG AND TEST =======
		Scene scene;
		//scene.Save(s_pFS, _W("scenes/test.robject"), iConsole());
		
		//CModel model;

		/*model = (Model*)cObjectManager()->CreateObject( _W("Model") );
		MeshData md;
          MeshSubset ms;
//           Material m;
//		  ms.Material = m;
		  ms.NumTriangles = 1;
		  ms.StartIndex = 0;
		  //ms.StartVertex = 0;
		 md.Subsets.AddEx(ms);
		 md.Indices.AddEx(0);
		 md.Indices.AddEx(1);
		 md.Indices.AddEx(2);
		 md.NumIndices = 3;
		  MeshVertexData mvd;
		  mvd.Usage = _W("P3DVU_POSITION");
		  mvd.DataSize = 3;
		  mvd.Float3.AddEx(Vec3Param(0.0f, 0.0f, 0.0f));
		  mvd.Float3.AddEx(Vec3Param(0.0f, 1.0f, 0.0f));
		  mvd.Float3.AddEx(Vec3Param(1.0f, 1.0f , 0.0f));
		 md.DataStreams.AddEx(mvd);
		 md.NumVerts = 3;
		model->LODs.AddEx(md);

		model->Save(s_pFS, _W("triangle.robject"), iConsole());
		model->PreCache();*/
		// ===========================================

		bool initOK=true;
		initOK &= s_pSound->Initialize(this);
		initOK &= s_pPhys->Initialize(this);
		initOK &= s_pFS->Initialize(this);
		initOK &= s_pGUI->Initialize(this);

		if (!initOK)
			CON(MSG_ERR_FATAL, _W("Failed to initialize some core module(s)! Cannot continue. For more details see console.htm."));

		cSceneManager()->Create();

		cConsole()->InitializeGUI(); // at this time, coz it uses GUI module and it must be initialized ;)

		// FIXME: register engine to script, temporary here
		/*using namespace luabind;
		lua_State* L = cScriptEngine()->GetLVM();
		module(L)
		[
			class_<CEngine>("Engine")
			.scope
			[
				def("GetBuildNum", &CEngine::GetBuildNum )
			]
		];*/

		// load bootstrap script
		cScriptEngine()->LoadScript(_W("scripts/bootstrap.rscript"));

		// DEBUG TESTING OF QUEUE TO RENDERER
		sE2RCanvasDesc* canvas;
		EnqueueMessage( MC_RENDERER, this, CQI_ENGINE2RENDERER_CANVAS_CREATE, (void*&)canvas, sizeof(sE2RCanvasDesc) );
		canvas->handle = cInternalWindow()->GetHandle();
		canvas->size = Vec2i(800,600);
		canvas->windowed = !initFullscreen;

		//Sleep(10000);
		cInternalWindow()->EndSplash();
		cInternalWindow()->SetVisible(true);

		
		//Filesystem test
		/*UINT oSize;
		void *lData=0;
		if(cFilesystem()->Load(_W("scripts.bootstrap"), &lData, oSize)==P3D_FILERESULT_OK)
			cFilesystem()->FreeLoadedData(lData);
		const char* testStr = "this is a test string";
		cFilesystem()->Save(_W("scripts.fstest"), testStr, sizeof(char)*strlen(testStr));*/

		return true;
	}
Beispiel #4
0
static int gprs_start( lua_State* L )
{
uint32_t len;
int timeout = luaL_checkinteger(L, 1);
const char *APN[10];
char *APN_USED;
char Param[BUFFER_SZ];
uint8_t i = 0;
uint8_t j = 5;
uint8_t result = 1;
unsigned char cont = lua_gettop(L) - 1;

	APN[0] = lua_tolstring( L, 2, &len );
	APN[1] = lua_tolstring( L, 3, &len );
	APN[2] = lua_tolstring( L, 4, &len );
	APN[3] = lua_tolstring( L, 5, &len );
	APN[4] = lua_tolstring( L, 6, &len );
	APN[5] = lua_tolstring( L, 7, &len );
	APN[6] = lua_tolstring( L, 8, &len );
	APN[7] = lua_tolstring( L, 9, &len );
	APN[8] = lua_tolstring( L, 10, &len );
	APN[9] = lua_tolstring( L, 11, &len );
	c_memset(Param, 0 , BUFFER_SZ);
	if( APN[0] != NULL && APN[1] != NULL && APN[2] != NULL && APN[3] != NULL )
	{
		result = 1;
		gprs_clear(L);
		milisec(1500);
		tcpip_getIpStatus(L);
		len = gprs_Attach(L);
		if( len == 1 )
		{
			result = 2;
			for(i = 0; i < 5; i++)
			{
				gprs_clear(L);
				//tcpip_getIpStatus(L);
				if( APN[9] != NULL )
				{
					APN_USED = (char*)APN[9];
					c_sprintf(Param, CGDCONT, APN[9]);
					for(j = 0; j < 5; j++)
					{
						len = gprs_Activate(L,Param);
						if( len == 1 )
							goto end_act;

						milisec(1000);
					}
				}
				if( j>= 5 )
				{
					for(j = 0; j < cont; j++)
					{
						if( APN[j] != NULL )
						{
							APN_USED = (char*)APN[j];
							c_sprintf(Param, CGDCONT, APN[j]);
							len = gprs_Activate(L,Param);
							if( len == 1 )
								goto end_act;

							milisec(1000);
						}
					}
				}
			}
end_act:
			if( tcpip_getIpStatus(L) == 1 )
			{
				tcpip_getIp(L);
				tcpip_getIpStatus(L);
				result = 0;
				lua_pushinteger(L, result);
				lua_pushstring(L,APN_USED);
				return 2;
			}
		}
	}

	lua_pushinteger(L, result);
	return 1;
}