示例#1
0
int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    InitNetwork();
    DisplayStart();
    RTC_WDT_Init();

    Display("Sync time...");
    CyDelay(2000);
    
    
    if(NTPsync() == TIME_SYNC_OK)
    {
        Display("Sync ok");
        CyDelay(4 * TIMEOUT_USER_READ_INFO);
        
        result = TIME_SYNC_OK;
    }
    else
    {
        Display("Sync time error");

        CyDelay(4 * TIMEOUT_USER_READ_INFO);
        
        result = TIME_SYNC_ERR;
    }

    for(;;)
    {
        DisplayRealTime();
        CyDelay(100);
    }
}
示例#2
0
bool CHSNetwork::Listen(unsigned short usPort)
{
    if (m_bClientMode)
    {
        // The client cannot also be a server.
        return false;
    }

    if (!InitNetwork())
    {
        return false;           // Unknown network problem.
    }

    // Open a new listening socket.
    CHSSocket *pSocket = new CHSSocket;
    pSocket->SetCallbacks(NETRECEIVECALLBACK, NETACCEPTCALLBACK,
                          NETCLOSECALLBACK);
    if (pSocket->Listen(usPort))
    {
        m_listSockets.push_back(pSocket);
        m_bServerMode = true;
        m_bInitialized = true;
        return true;
    }

    // Listen failure.
    return false;
}
示例#3
0
int main(void)
{    
    CyGlobalIntEnable; /* Enable global interrupts. */
    
    DisplayStart();
    Display("System init...");
    
    RTC_WDT_Init(); 
    InitNetwork();
    
    
    
    Display("Sync time...");

    uint8_t number = 0;
    while((result = NTPsync()) != TIME_SYNC_OK)
    {
        char buf[10];
        sprintf(buf, "Sync time -%d", number++);
        LCD_Position(0,0);
        LCD_PrintString(buf);
        CyDelay(500);
    }
    
    Display("Sync ok        ");
    CyDelay(4*TIMEOUT_USER_READ_INFO);
    
    for(;;)
    {
        DisplayRealTime();
        CyDelay(500);
    }
}
示例#4
0
int main()
{
	InitDB();

	CurrentLoad = GetBaseLoad();

	//let's init babonet so people can connect to us
	InitNetwork();

	
	//main program here
	bool isRunning = true;
	
	dkcInit(60);

	//linux time struct
	#ifndef WIN32
		timespec ts;

		ts.tv_sec = 0;
		ts.tv_nsec = 1000000;
	#endif

	GetLatestVersion();

	while(isRunning)
	{
		// On va updater notre timer
		int nbFrameElapsed = dkcUpdateTimer();

		// On va chercher notre delay
		float delay = dkcGetElapsedf();
		
		while (nbFrameElapsed)
		{ 
			//let's update our NetManager
			isRunning	=	Update(delay);

			nbFrameElapsed--;
		}
		//linux sleep
		#ifndef WIN32
			nanosleep(&ts,0);
			ts.tv_sec = 0;
			ts.tv_nsec = 1000000;
		//windows sleep
		#else
			Sleep(1);
		#endif
		
	}


	//cleanup
	CleanUp();
		
	return 0;
}
示例#5
0
unsigned int
    CHSNetwork::Connect(const char *pcAddress,
                        unsigned short usPort,
                        const char *pcPlayerName, const char *pcPassword)
{
    // The CHSNetwork cannot operate in both client and server mode.
    if (m_bServerMode)
    {
        return 0;
    }

    if (!InitNetwork())
    {
        return false;           // Unknown network problem.
    }

    // Allocate a CHSSocket.
    CHSSocket *pSocket = new CHSSocket;
    pSocket->SetCallbacks(NETRECEIVECALLBACK, NULL, NETCLOSECALLBACK);
    if (pSocket->Connect(pcAddress, usPort))
    {
        m_listSockets.push_back(pSocket);
        m_bClientMode = true;
        m_bInitialized = true;

        // Send a login packet.
        CHSPLogin cmdLogin;

        cmdLogin.m_pcPassword = (char *) pcPassword;
        cmdLogin.m_pcPlayerName = (char *) pcPlayerName;

        cmdLogin.SetPacketAddress((unsigned int) pSocket);

        SendPacket(cmdLogin);

        // Wait for the login response.
        if (WaitForPacket(PT_LOGIN_RESPONSE))
        {
            // The login response came back.  It should be the first on the list.
            CHSPacket *pPacket = GetPendingPacket();

            if (pPacket->GetPacketType() == PT_LOGIN_RESPONSE)
            {
                CHSPLoginResponse *cmdResponse =
                    static_cast < CHSPLoginResponse * >(pPacket);

                if (cmdResponse->m_bLoggedIn)
                {
                    return (unsigned int) pSocket;
                }
            }
        }
    }

    // Everything's in the toilet.
    return 0;
}
示例#6
0
BOOL CNetManager::Start( IDataHandler *pBufferHandler )
{
	if(pBufferHandler == NULL)
	{
		ASSERT_FAIELD;

		return FALSE;
	}

	m_pBufferHandler = pBufferHandler;

	if(!InitNetwork())
	{
		ASSERT_FAIELD;
		CLog::GetInstancePtr()->AddLog("初始化网络失败!!");
		return FALSE;
	}

	if(!CreateCompletePort())
	{
		ASSERT_FAIELD;
		CLog::GetInstancePtr()->AddLog("创建完成端口或Epoll失败!!");
		return FALSE;
	}

	if(!CreateEventThread(0))
	{
		ASSERT_FAIELD;
		CLog::GetInstancePtr()->AddLog("创建网络事件处理线程失败!!");
		return FALSE;
	}

	if(!CreateDispatchThread())
	{
		ASSERT_FAIELD;
		CLog::GetInstancePtr()->AddLog("创建事件分发线程失败!!");
		return FALSE;
	}

	if(!CreateSendDataThread())
	{
		ASSERT_FAIELD;
		CLog::GetInstancePtr()->AddLog("创建数据发送线程失败!!");
		return FALSE;
	}

	if(!StartListen())
	{
		ASSERT_FAIELD;
		CLog::GetInstancePtr()->AddLog("开启监听失败!!");
		return FALSE;
	}

	return TRUE;
}
示例#7
0
//---------------------------------------------------------------------------
void __fastcall TServerGuiForm::StartButtonClick(TObject *Sender)
{ // This does all the real work.
 // D 1. Check that there are protocols
 // D 2. Check that there is a reply and it can be loaded
 // D 3. Check that there is a server
 // D 4. Load the protocols
 // D 5. Load the server
 // D 6. Enable Stop
 // D 7. Disable Start
 // 8. Update Count
 if (!ProtocolsListBox->Items->Count)
    {
     Application->MessageBox( "Please select protocol and port combination to use", Caption.c_str(), MB_OK );
     return;
    }
 if (ReplyComboBox->ItemIndex==-1)
    {
     Application->MessageBox( "Please select reply type to use", Caption.c_str(), MB_OK );
     return;
    }
 if (ServerComboBox->ItemIndex==-1)
    {
     Application->MessageBox( "Please select server type to use", Caption.c_str(), MB_OK );
     return;
    }
// ServerComboBox->Enabled=False;
// ReplyComboBox->Enabled=False;
// AddButton->Enabled=False;
// RemoveButton->Enabled=False;
// ClearButton->Enabled=False;
 StartButton->Enabled=False;
 StopButton->Enabled=True;
 SettingsPanel->Enabled=False;
 sr=allocate_reply();
 if (!sr) return;
 InitNetwork();
 sp=allocate_protocol();
 if (!sp)
   {
    cleanup( NULL, sr, NULL );
    sr=NULL;
    return;
   }
 ss=allocate_servers( sr, sp );
 if (!ss)
   {
    cleanup( NULL, sr, sp );
    sr=NULL;
    sp=NULL;
    return;
   }
 ActivityTimer->Enabled=True;
 ss->serv->StartServer( ss->handle );
}
示例#8
0
static void
Init (const char sDataDir[])
{
static bool fInitialized = false;
if (fInitialized)
    return;

// following must be static for InitNetwork
static char s0[SLEN], s1[SLEN], s2[SLEN], s3[SLEN];
sprintf(s0, "%s/%s", sDataDir, NET_0);
sprintf(s1, "%s/%s", sDataDir, NET_1);
sprintf(s2, "%s/%s", sDataDir, NET_2);
sprintf(s3, "%s/%s", sDataDir, NET_3);
const char *pNetworkNames[]={s0, s1, s2, s3};

AllocateNetworks(4);
InitNetwork(0, 1, pNetworkNames);       // network 0: umec
InitNetwork(1, 1, pNetworkNames+1);     // network 1: face17c
InitNetwork(2, 1, pNetworkNames+2);     // network 1: face18c
InitNetwork(3, 1, pNetworkNames+3);     // network 2: eye

char sFace[SLEN];                       // load face mask
logprintf("\n");
sprintf(sFace, "%s/facemask20x20.pgm", sDataDir);
LoadMask(gFaceMask, sFace);

char sMask[SLEN];                       // load eye mask
sprintf(sMask, "%s/eyemask25x15.pgm", sDataDir);
LoadMask(gEyeMask, sMask);

// a consistency check -- prevents overflow in FindEyes()

if (gNetList[3]->nInputs - 1 != gEyeMask.width * gEyeMask.height)
    Err("network \"%s\" number of inputs %d does not match %s size %d",
        pNetworkNames[3], gNetList[3]->nInputs-1,
        sFace, gEyeMask.width * gEyeMask.height);

fInitialized = true;
}
示例#9
0
文件: ddcs.c 项目: frustreated/ddcs
int main(int argc, char **argv) {
	printf("%s%s%s\n%s\n%s\n", 
		"DDCS Version [", VERSION, "] Copyright (C) 2013 Jan Peter Koenig",
		"This is free software, and you are welcome to redistribute it under", "certain conditions."
	);

	InitNetwork();

	// Hold Application in Stand-By
	while (1) { usleep(1); }

	return 0;
}
示例#10
0
int main()
{
	// Setup
	int screenWidth  = 800;
	int screenHeight = 450;
	InitWindow(
		screenWidth, screenHeight, "raylib [network] example - udp server");
	SetTargetFPS(60);
	SetTraceLogLevel(LOG_DEBUG);

	// Networking
	InitNetwork();

	//  Create the server
	//
	//  Performs
	//      getaddrinfo
	//      socket
	//      setsockopt
	//      bind
	//      listen
	server_res = AllocSocketResult();
	if (!SocketCreate(&server_cfg, server_res)) {
		TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d",
				 server_res->status, server_res->socket->status);
	} else {
		if (!SocketBind(&server_cfg, server_res)) {
			TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d",
					 server_res->status, server_res->socket->status);
		}
	}

	//  Create & Add sockets to the socket set
	socket_set = AllocSocketSet(1);
	msglen     = strlen(pingmsg) + 1;
	memset(recvBuffer, '\0', sizeof(recvBuffer));
	AddSocket(socket_set, server_res->socket);

	// Main game loop
	while (!WindowShouldClose()) {
		BeginDrawing();
		ClearBackground(RAYWHITE);
		NetworkUpdate();
		EndDrawing();
	}

	// Cleanup
	CloseWindow();
	return 0;
}
//---------------------------------------------------------------------------
void __fastcall TTrafficServerForm::StartButtonClick(TObject *Sender)
{
    if (!ProtocolsListBox->Items->Count)
    {
        Application->MessageBox( "Please select protocol and port combination to use", Caption, TMessageButtons() << smbOK, smsWarning );
        return;
    }
    if (ReplyComboBox->ItemIndex==-1)
    {
        Application->MessageBox( "Please select reply type to use", Caption , TMessageButtons() << smbOK, smsWarning  );
        return;
    }
    if (ServerComboBox->ItemIndex==-1)
    {
        Application->MessageBox( "Please select server type to use", Caption, TMessageButtons() << smbOK, smsWarning );
        return;
    }
    StartButton->Enabled=False;
    StopButton->Enabled=True;
    SettingsPanel->Enabled=False;
    sr=allocate_reply();
    if (!sr)
    {
        StartButton->Enabled=True;
        StopButton->Enabled=False;
        return;
    }
    InitNetwork();
    sp=allocate_protocol();
    if (!sp)
    {
        StartButton->Enabled=True;
        StopButton->Enabled=False;
        cleanup( NULL, sr, NULL );
        sr=NULL;
        return;
    }
    ss=allocate_servers( sr, sp );
    if (!ss)
    {
        StartButton->Enabled=True;
        StopButton->Enabled=False;
        cleanup( NULL, sr, sp );
        sr=NULL;
        sp=NULL;
        return;
    }
    ActivityTimer->Enabled=True;
    ss->serv->StartServer( ss->handle );
}
示例#12
0
uint32_t SystemInit(void)
{
    uint32_t result;
    uint32_t unixTime;
        
    SetRebootFlag();
    LedInit();   
    //DisplayStart();   
    RTC_WDT_Init();
    InitNetwork();
    GateInit();
    InitBuff();
    BattADC_Init();

    /* Enable global interrupts */
    CyGlobalIntEnable;
   
    /*sync real time*/
    unixTime = DS1307_GetUnixTime();
//    unixTime = 1485184625 ;
    if(unixTime > 0)
    {      
        RTC_SetUnixTime(unixTime);
        result = DataBaseStart();
        if(result == DB_NO_ERROR)
        {
            Display("System init...");
            result = NO_ERROR;
        }
        else
        {
            Display("Please insert SD");
            result = ERROR;
            SendFinStatus(FIN_NO_READY);
            MyDelay(300);
        }
    }
    else
    {
        Display("Error sync time");
        result = ERROR;
        SendFinStatus(FIN_NO_READY);
        MyDelay(500);
    }
    
    return result;    
}
示例#13
0
文件: ExNet.c 项目: virqin/brew_code
static boolean ExNet_HandleEvent(ExNet* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  

	switch (eCode) 
	{
		// App is told it is starting up
	case EVT_APP_START:                        
		// Add your code here...
		InitNetwork(pMe);
		Connect(pMe,"localhost",10200);

		return(TRUE);


		// App is told it is exiting
	case EVT_APP_STOP:
		// Add your code here...

		return(TRUE);


		// App is being suspended 
	case EVT_APP_SUSPEND:
		// Add your code here...

		return(TRUE);


		// App is being resumed
	case EVT_APP_RESUME:

		return(TRUE);

	case EVT_APP_MESSAGE:
		// Add your code here...

		return(TRUE);
	case EVT_KEY:


		return(TRUE);
	default:
		break;
	}

	return FALSE;
}
//-----------------------------------------------------------------//
c_Network::c_Network(std::string _filename)
/* 
 * Load network from edge list in file
 */
{
	m_sFilename = _filename;

	//m_bstNodes = new i64BinarySearchTree(-1);
	m_bstNodes = NULL;

	m_iNetworkType = 0;
	m_sNetworkType = "";

	m_bInitialized = false;

	InitNetwork();

}
示例#15
0
int main( int argc, char **argv )
{
  struct client_payload *payload;
  struct client_protocol *protocol;
  struct client_client *client;
  config_info ci( argc, argv );

  if (!ci.isOk())
    {
      if (ci.isVersion())
	{
	  std::cout << ci.getErrorString() << std::endl;
	  return( 0 );
	}
      std::cerr << argv[0] << ":Error " << ci.getErrorString() << std::endl;
      std::cerr << std::endl << ci.help() << std::endl;
      return( 1 );
    }
  std::cout << argv[0] << " Starting" << std::endl;
  std::cout << "Initializing Payloads" << std::endl;
  payload=allocate_payload( &ci );
  if (!payload) return( 2 );
  std::cout << "Initializing Protocols" << std::endl;
  InitNetwork();
  protocol=allocate_protocol( &ci );
  if (!protocol)
    {
      cleanup( payload, NULL, NULL, &ci );
      return( 3 );
    }
  client=allocate_clients( &ci, protocol, ci.getNumClients(), payload, ci.getNumClients() );
  if (!client)
    {
      cleanup( payload, protocol, NULL, &ci );
      return( 4 );
    }
  std::cout << "Starting clients. Press ENTER to end." << std::endl;
  client->clnt->StartClient( client->handle );
  getchar();
  client->clnt->StopClient( client->handle );
  cleanup( payload, protocol, client, &ci );
  std::cout << "Client stopped." << std::endl;
  return( 0 );
}
示例#16
0
CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) :
	PROTO<CSkypeProto>(protoName, userName),
		m_PopupClasses(1), 
		m_InviteDialogs(1),
		m_GCCreateDialogs(1),
		m_OutMessages(3, PtrKeySortT)
{
	m_hProtoIcon = Icons[0].Handle;

	InitNetwork();

	requestQueue = new RequestQueue(m_hNetlibUser);

	CreateProtoService(PS_CREATEACCMGRUI, &CSkypeProto::OnAccountManagerInit);
	CreateProtoService(PS_GETAVATARINFO,  &CSkypeProto::SvcGetAvatarInfo);
	CreateProtoService(PS_GETAVATARCAPS,  &CSkypeProto::SvcGetAvatarCaps);
	CreateProtoService(PS_GETMYAVATAR,    &CSkypeProto::SvcGetMyAvatar);
	CreateProtoService(PS_SETMYAVATAR,    &CSkypeProto::SvcSetMyAvatar);

	CreateProtoService("/IncomingCallCLE", &CSkypeProto::OnIncomingCallCLE);
	CreateProtoService("/IncomingCallPP", &CSkypeProto::OnIncomingCallPP);

	m_tszAvatarFolder = std::tstring(VARST(_T("%miranda_avatarcache%"))) + _T("\\") + m_tszUserName;
	DWORD dwAttributes = GetFileAttributes(m_tszAvatarFolder.c_str());
	if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
		CreateDirectoryTreeT(m_tszAvatarFolder.c_str());

	//sounds
	SkinAddNewSoundEx("skype_inc_call", "SkypeWeb", LPGEN("Incoming call sound"));
	SkinAddNewSoundEx("skype_call_canceled", "SkypeWeb", LPGEN("Incoming call canceled sound"));

	m_hTrouterEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
	m_hPollingEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
	m_hTrouterHealthEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

	SkypeSetTimer();

	m_hPollingThread = ForkThreadEx(&CSkypeProto::PollingThread, NULL, NULL);
	m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, NULL, NULL);
}
示例#17
0
文件: Main.cpp 项目: txal/XProject
int main(int nArg, char *pArgv[])
{
	assert(nArg >= 2);
	signal(SIGINT, OnSigInt);
	signal(SIGTERM, OnSigTerm);
	int8_t nServiceID = (int8_t)atoi(pArgv[1]);
#ifdef _WIN32
	::SetUnhandledExceptionFilter(Platform::MyUnhandledFilter);
#endif
	atexit(ExitFunc);
	Logger::Instance()->Init();
	Logger::Instance()->SetSync(true);
	MysqlDriver::MysqlLibaryInit();

	LuaWrapper* poLuaWrapper = LuaWrapper::Instance();
	poLuaWrapper->Init(Platform::FileExist("./adb.txt"));
	char szWorkDir[256] = { 0 };
	char szScriptPath[512] = { 0 };
	Platform::GetWorkDir(szWorkDir, sizeof(szWorkDir)-1);
	sprintf(szScriptPath, ";%s/Script/?.lua;%s/../Script/?.lua;", szWorkDir, szWorkDir);
	poLuaWrapper->AddSearchPath(szScriptPath);

	g_poContext = XNEW(ServerContext);
	bool bRes = g_poContext->LoadServerConfig();
	assert(bRes);
	if (!bRes)
	{
		XLog(LEVEL_ERROR, "load server conf fail!\n");
		exit(-1);
	}

	NetAPI::StartupNetwork();
	if (!Platform::FileExist("./debug.txt"))
	{
		char szLogName[128] = "";
		sprintf(szLogName, "logserver%d", nServiceID);
		Logger::Instance()->SetLogFile(g_poContext->GetServerConfig().sLogPath, szLogName);
	}


	RouterMgr* poRouterMgr = XNEW(RouterMgr);
	g_poContext->SetRouterMgr(poRouterMgr);

	PacketHandler* poPacketHandler = XNEW(PacketHandler);
	g_poContext->SetPacketHandler(poPacketHandler);

	NSPacketProc::RegisterPacketProc();

	LogServer* poLogServer = XNEW(LogServer);
	poLogServer->Init(nServiceID);
	g_poContext->SetService(poLogServer);

	LuaSerialize* poSerialize = XNEW(LuaSerialize);
	g_poContext->SetLuaSerialize(poSerialize);

	bRes = InitNetwork(nServiceID);
	assert(bRes);
	if (!bRes)
	{
		XLog(LEVEL_ERROR, "init network fail!\n");
		exit(-1);
	}

	goHttpClient.Init();
	ServerConfig& oSrvConf = g_poContext->GetServerConfig();
	for (int i = 0; i < oSrvConf.oLogList.size(); i++)
	{
		LogNode& oNode = oSrvConf.oLogList[i];
		if (oNode.uServer == oSrvConf.uServerID && oNode.uID == poLogServer->GetServiceID())
		{
			if (oNode.sHttpAddr[0] != '\0')
			{
				goHttpServer.Init(oNode.sHttpAddr);
			}
			WorkerMgr::Instance()->Init(oNode.uWorkers);
			break;
		}
	}

	XLog(LEVEL_INFO, "LogServer start successful\n");
	bRes = g_poContext->GetService()->Start();
	assert(bRes);
	if (!bRes)
	{
		XLog(LEVEL_ERROR, "start server fail!\n");
		exit(-1);
	}

	//wchar_t wcBuffer[256] = { L"" };
	//wsprintfW(wcBuffer, L"log%d.leak", g_poContext->GetService()->GetServiceID());
	//VLDSetReportOptions(VLD_OPT_REPORT_TO_FILE | VLD_OPT_REPORT_TO_DEBUGGER, wcBuffer);

	SAFE_DELETE(g_poContext);
	TimerMgr::Instance()->Release();
	WorkerMgr::Instance()->Release();
	LuaWrapper::Instance()->Release();
	Logger::Instance()->Terminate();
	MysqlDriver::MysqlLibaryEnd();
	return 0;
}
示例#18
0
extern "C" int main(int argc, char **argv)
{
	timeval tv;
	gettimeofday(&tv, NULL);
	srand(tv.tv_usec);
#if defined(GEKKO)
	DIR *dir_tmp;
#endif

	// Init SDL
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) < 0) {
                fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError());
                return 1;
	}
        if (TTF_Init() < 0)
        {
                fprintf(stderr, "Unable to init TTF: %s\n", TTF_GetError() );
		return 1;
        }

	fflush(stdout);

	#ifdef GEKKO
	
	printf("\x1b[2;0H");

	//initialize libfat library
	if (fatInitDefault())
		printf("FAT subsytem initialized\n\n");
	else
		{
		printf("Couldn't initialize FAT subsytem\n\n");
		sleep(3);
		exit(0);
		}
		
	DIR *dp;
    
	dp = opendir ("sd:/");
	if (dp) sdismount = 1; else sdismount = 0;
	
	if (sdismount)
		printf("SD FAT subsytem initialized\n\n");
	else
		printf("Couldn't initialize SD fat subsytem\n\n");
 	
	if (sdismount) closedir (dp);
	
	usbismount = InitUSB();
	if (usbismount) 
		printf("USB FAT subsytem initialized\n\n");
	else
		printf("Impossible to initialize USB FAT subsytem\n\n");
	
	networkisinit = InitNetwork();	
		
	sleep(2);
	
	//create tmp directory if it does not exist
	dir_tmp = opendir("/frodo/tmp");	
	if (!dir_tmp) {mkdir("/frodo/tmp",0777);printf("Making tmp directory\n");sleep(2);} else closedir(dir_tmp);
	
	//Cancel the old files
	unlink ("/frodo/tmp/a");
	unlink ("/frodo/tmp/dummy");
	
	#endif

	Frodo *the_app = new Frodo();
	the_app->ArgvReceived(argc, argv);
	the_app->ReadyToRun();
	delete the_app;
	
	if (smbismount) CloseShare (true);

	#ifdef GEKKO
	DeInitUSB();
	fatUnmount(0);
	#endif

	return 0;
}
示例#19
0
CServerListener::CServerListener()
{
	InitNetwork();
	lastID = 0;
	game = NULL;;
}
示例#20
0
int main(int argc, char **argv)
{
  float *Hydrograph = NULL;
  float ***MM5Input = NULL;
  float **PrecipLapseMap = NULL;
  float **PrismMap = NULL;
  unsigned char ***ShadowMap = NULL;
  float **SkyViewMap = NULL;
  float ***WindModel = NULL;
  /* Glacier Model Variable */
  double  dt_year;
  double  year_min;
  double  year_max;
  int MaxStreamID, MaxRoadID;
  clock_t start, finish1;
  double runtime = 0.0;
  int t = 0;
  float roadarea;
  int i;
  int j;
  int x;						/* row counter */
  int y;						/* column counter */
  int shade_offset;				/* a fast way of handling arraay position given the number of mm5 input options */
  int NStats;					/* Number of meteorological stations */
  uchar ***MetWeights = NULL;	/* 3D array with weights for interpolating meteorological variables between the stations */

  int NGraphics;				/* number of graphics for X11 */
  int *which_graphics;			/* which graphics for X11 */

  AGGREGATED Total = {			/* Total or average value of a  variable over the entire basin */
    {0.0, NULL, NULL, NULL, NULL, 0.0},												/* EVAPPIX */
    {0.0, 0.0, 0.0, 0.0, 0.0, NULL, NULL, 0.0, 0, 0.0},								/* PRECIPPIX */
    {{0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, 0.0, {0.0, 0.0}, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
                                                                                    /* PIXRAD */
    {0.0, 0.0, 0, NULL, NULL, 0.0, 0, 0.0, 0.0, 0.0, 0.0, NULL, NULL},				/* ROADSTRUCT*/
    {0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},		/* SNOWPIX */
    {0, 0.0, NULL, NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},			                /* SOILPIX */
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0l, 0.0, 0.0
  };
  CHANNEL ChannelData = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL, NULL, NULL};
  DUMPSTRUCT Dump;
  EVAPPIX **EvapMap = NULL;
  INPUTFILES InFiles;
  LAYER Soil;
  LAYER Veg;
  LISTPTR Input = NULL;			/* Linked list with input strings */
  MAPSIZE Map;					/* Size and location of model area */
  MAPSIZE Radar;				/* Size and location of area covered by precipitation radar */
  MAPSIZE MM5Map;				/* Size and location of area covered by MM5 input files */
  GRID Grid;
  METLOCATION *Stat = NULL;
  OPTIONSTRUCT Options;			/* Structure with information which program options to follow */
  PIXMET LocalMet;				/* Meteorological conditions for current pixel */
  PRECIPPIX **PrecipMap = NULL;
  RADARPIX **RadarMap	= NULL;
  PIXRAD **RadiationMap = NULL;
  ROADSTRUCT **Network	= NULL;	/* 2D Array with channel information for each pixel */
  SNOWPIX **SnowMap		= NULL;
  GLPIX **GlacierMap = NULL; /* glacier model*/
  MET_MAP_PIX **MetMap	= NULL;
  SNOWTABLE *SnowAlbedo = NULL;
  SOILPIX **SoilMap		= NULL;
  SOILTABLE *SType	    = NULL;
  SOLARGEOMETRY SolarGeo;		/* Geometry of Sun-Earth system (needed for INLINE radiation calculations */
  TIMESTRUCT Time;
  TOPOPIX **TopoMap = NULL;
  UNITHYDR **UnitHydrograph = NULL;
  UNITHYDRINFO HydrographInfo;	/* Information about unit hydrograph */
  VEGPIX **VegMap = NULL;
  VEGTABLE *VType = NULL;
  WATERBALANCE Mass =			/* parameter for mass balance calculations */
    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

/*****************************************************************************
  Initialization Procedures 
*****************************************************************************/
  if (argc != 2) {
    fprintf(stderr, "\nUsage: %s inputfile\n\n", argv[0]);
    fprintf(stderr, "DHSVM uses two output streams: \n");
    fprintf(stderr, "Standard Out, for the majority of output \n");
    fprintf(stderr, "Standard Error, for the final mass balance \n");
    fprintf(stderr, "\nTo pipe output correctly to files: \n");
    fprintf(stderr, "(cmd > f1) >& f2 \n");
    fprintf(stderr, "where f1 is stdout_file and f2 is stderror_file\n");
    exit(EXIT_FAILURE);
  }

  sprintf(commandline, "%s %s", argv[0], argv[1]);
  printf("%s \n", commandline);
  fprintf(stderr, "%s \n", commandline);
  strcpy(InFiles.Const, argv[1]);

  printf("\nRunning DHSVM %s\n", version);
  printf("\nSTARTING INITIALIZATION PROCEDURES\n\n");

  /* Start recording time */
  start = clock();

  ReadInitFile(InFiles.Const, &Input);
  InitConstants(Input, &Options, &Map, &SolarGeo, &Time);

  InitFileIO(Options.FileFormat);
  InitTables(Time.NDaySteps, Input, &Options, &SType, &Soil, &VType, &Veg,
	     &SnowAlbedo);
  InitGlacierMap(&Map, &GlacierMap); /*glacier model*/
  InitTerrainMaps(Input, &Options, &Map, &Soil, &TopoMap, &SoilMap, &VegMap, &GlacierMap);
  
  CheckOut(&Options, Veg, Soil, VType, SType, &Map, TopoMap, VegMap, SoilMap);

  if (Options.HasNetwork)
    InitChannel(Input, &Map, Time.Dt, &ChannelData, SoilMap, &MaxStreamID, &MaxRoadID, &Options);
  else if (Options.Extent != POINT)
    InitUnitHydrograph(Input, &Map, TopoMap, &UnitHydrograph,
		       &Hydrograph, &HydrographInfo);
 
  InitNetwork(Map.NY, Map.NX, Map.DX, Map.DY, TopoMap, SoilMap, 
	      VegMap, VType, &Network, &ChannelData, Veg, &Options);

  InitMetSources(Input, &Options, &Map, TopoMap, Soil.MaxLayers, &Time,
		 &InFiles, &NStats, &Stat, &Radar, &MM5Map, &Grid);

  /* the following piece of code is for the UW PRISM project */
  /* for real-time verification of SWE at Snotel sites */
  /* Other users, set OPTION.SNOTEL to FALSE, or use TRUE with caution */

  if (Options.Snotel == TRUE && Options.Outside == FALSE) {
    printf
      ("Warning: All met stations locations are being set to the vegetation class GLACIER\n");
    printf
      ("Warning: This requires that you have such a vegetation class in your vegetation table\n");
    printf("To disable this feature set Snotel OPTION to FALSE\n");
    for (i = 0; i < NStats; i++) {
      printf("veg type for station %d is %d ", i,
	     VegMap[Stat[i].Loc.N][Stat[i].Loc.E].Veg);
      for (j = 0; j < Veg.NTypes; j++) {
	    if (VType[j].Index == GLACIER) {
	      VegMap[Stat[i].Loc.N][Stat[i].Loc.E].Veg = j;
		  break;
		}
      }
      if (j == Veg.NTypes) {	/* glacier class not found */
	    ReportError("MainDHSVM", 62);
	  }
      printf("setting to glacier type (assumed bare class): %d\n", j);
    }
  }

  InitMetMaps(Time.NDaySteps, &Map, &Radar, &Options, InFiles.WindMapPath,
	      InFiles.PrecipLapseFile, &PrecipLapseMap, &PrismMap,
	      &ShadowMap, &SkyViewMap, &EvapMap, &PrecipMap,
	      &RadarMap, &RadiationMap, SoilMap, &Soil, VegMap, &Veg, TopoMap,
	      &MM5Input, &WindModel);

  InitInterpolationWeights(&Map, &Options, TopoMap, &MetWeights, Stat, NStats);

  InitDump(Input, &Options, &Map, Soil.MaxLayers, Veg.MaxLayers, Time.Dt,
	   TopoMap, &Dump, &NGraphics, &which_graphics);

  if (Options.HasNetwork == TRUE) {
    InitChannelDump(&Options, &ChannelData, Dump.Path);
    ReadChannelState(Dump.InitStatePath, &(Time.Start), ChannelData.streams);
	if (Options.StreamTemp && Options.CanopyShading)
	  InitChannelRVeg(&Time, ChannelData.streams);
  }

  InitSnowMap(&Map, &SnowMap);
  InitAggregated(Veg.MaxLayers, Soil.MaxLayers, &Total);

  InitModelState(&(Time.Start), &Map, &Options, PrecipMap, SnowMap, SoilMap,
		 Soil, SType, VegMap, Veg, VType, Dump.InitStatePath,
		 SnowAlbedo, TopoMap, Network, &HydrographInfo, Hydrograph, &Total, GlacierMap);

#ifdef HAVE_GLACIER
/* Glacier Model is run independently to "spinup" glacier ice state over 1000 years */
  if (Options.Glacier == GLSPINUP){
   dt_year  = 1;
   year_min = 0;
   year_max = 1000;
   printf("Glacier model spin up run for %f years\n", year_max);
   main_spinup(&Map, TopoMap, SnowMap,GlacierMap, dt_year,year_min,year_max, 
   &(Time.Current), &Dump, &Options);
   return EXIT_SUCCESS;
  }
#endif

  InitNewMonth(&Time, &Options, &Map, TopoMap, PrismMap, ShadowMap,
	       &InFiles, Veg.NTypes, VType, NStats, Stat, Dump.InitStatePath);

  InitNewDay(Time.Current.JDay, &SolarGeo);

  if (NGraphics > 0) {
    printf("Initialzing X11 display and graphics \n");
    InitXGraphics(argc, argv, Map.NY, Map.NX, NGraphics, &MetMap);
  }

  shade_offset = FALSE;
  if (Options.Shading == TRUE)
    shade_offset = TRUE;

  /* Done with initialization, delete the list with input strings */
  DeleteList(Input);

  /* setup for mass balance calculations */
  Aggregate(&Map, &Options, TopoMap, &Soil, &Veg, VegMap, EvapMap, PrecipMap,
	      RadiationMap, SnowMap, SoilMap, &Total, VType, Network, &ChannelData, &roadarea);

  Mass.StartWaterStorage =
    Total.Soil.IExcess + Total.CanopyWater + Total.SoilWater + Total.Snow.Swq +
    Total.Soil.SatFlow + Total.Snow.Iwq + Total.Snow.IceRemoved;
  Mass.OldWaterStorage = Mass.StartWaterStorage;

  /* computes the number of grid cell contributing to one segment */
  if (Options.StreamTemp) 
	Init_segment_ncell(TopoMap, ChannelData.stream_map, Map.NY, Map.NX, ChannelData.streams);

/*****************************************************************************
  Perform Calculations 
*****************************************************************************/
  while (Before(&(Time.Current), &(Time.End)) ||
	 IsEqualTime(&(Time.Current), &(Time.End))) {

    /* debug */
    if (Time.Current.Month == 5 && Time.Current.Day == 20 && Time.Current.Hour >= 9 && Time.Current.Hour <= 15)
      printf("stop here for a little\n");
    /* debug ends */

    /* reset aggregated variables */
    ResetAggregate(&Soil, &Veg, &Total, &Options);

    if (IsNewMonth(&(Time.Current), Time.Dt)){
      InitNewMonth(&Time, &Options, &Map, TopoMap, PrismMap, ShadowMap,
		   &InFiles, Veg.NTypes, VType, NStats, Stat, Dump.InitStatePath);
#ifdef HAVE_GLACIER
          /* Run the glacier model at the end of every month */
	  if (Options.Glacier == GLSTATIC || Options.Glacier == GLDYNAMIC){
            dt_year  = 1.0;
            year_min = 1.0;
            year_max = 1.0;
             if(Time.Current.Month == 10 && Time.Current.Day == 1){
            /* Calculate Equilibrium Line Altitude at end of Water Year (assumed Oct1) */
	    /* will need to be changed depending on geography define water year */
	     calc_ela(&Map, TopoMap,SnowMap,GlacierMap,&(Time.Current), &Dump);
	}

            main_gl(&Map, TopoMap, SnowMap,GlacierMap, dt_year,year_min,year_max,
	    &(Time.Current), &Dump,&Options);
            /*Use the next program to output balance information for indivdual glaciers */
            gl_massbalance(&Map, TopoMap, SnowMap,GlacierMap, dt_year,year_min,
	    year_max, &(Time.Current), &Dump);
	}
#endif
    }
    if (IsNewDay(Time.DayStep)) {
      InitNewDay(Time.Current.JDay, &SolarGeo);
      PrintDate(&(Time.Current), stdout);
      printf("\n");
    }

    InitNewStep(&InFiles, &Map, &Time, Soil.MaxLayers, &Options, NStats, Stat,
		InFiles.RadarFile, &Radar, RadarMap, &SolarGeo, TopoMap, 
        SoilMap, MM5Input, WindModel, &MM5Map);

    /* initialize channel/road networks for time step */
    if (Options.HasNetwork) {
      channel_step_initialize_network(ChannelData.streams);
      channel_step_initialize_network(ChannelData.roads);
    }

    for (y = 0; y < Map.NY; y++) {
      for (x = 0; x < Map.NX; x++) {
	    if (INBASIN(TopoMap[y][x].Mask)) {
		  if (Options.Shading)
	        LocalMet =
	        MakeLocalMetData(y, x, &Map, Time.DayStep, &Options, NStats,
			       Stat, MetWeights[y][x], TopoMap[y][x].Dem,
			       &(RadiationMap[y][x]), &(PrecipMap[y][x]), &Radar,
			       RadarMap, PrismMap, &(SnowMap[y][x]),
			       SnowAlbedo, MM5Input, WindModel, PrecipLapseMap,
			       &MetMap, NGraphics, Time.Current.Month,
			       SkyViewMap[y][x], ShadowMap[Time.DayStep][y][x],
			       SolarGeo.SunMax, SolarGeo.SineSolarAltitude);
		  else
	        LocalMet =
	        MakeLocalMetData(y, x, &Map, Time.DayStep, &Options, NStats,
			       Stat, MetWeights[y][x], TopoMap[y][x].Dem,
			       &(RadiationMap[y][x]), &(PrecipMap[y][x]), &Radar,
			       RadarMap, PrismMap, &(SnowMap[y][x]),
			       SnowAlbedo, MM5Input, WindModel, PrecipLapseMap,
			       &MetMap, NGraphics, Time.Current.Month, 0.0,
			       0.0, SolarGeo.SunMax,
			       SolarGeo.SineSolarAltitude);

		  /* get surface tempeature of each soil layer */
		  for (i = 0; i < Soil.MaxLayers; i++) {
	        if (Options.HeatFlux == TRUE) {
	          if (Options.MM5 == TRUE)
		        SoilMap[y][x].Temp[i] =
				MM5Input[shade_offset + i + N_MM5_MAPS][y][x];

              /* read tempeature of each soil layer from met station input */
			  else
		        SoilMap[y][x].Temp[i] = Stat[0].Data.Tsoil[i];
			}
            /* if heat flux option is turned off, soil temperature of all 3 layers 
            is taken equal to air tempeature */
	        else
	          SoilMap[y][x].Temp[i] = LocalMet.Tair;
		  }
		  
		  MassEnergyBalance(&Options, y, x, SolarGeo.SineSolarAltitude, Map.DX, Map.DY, 
			    Time.Dt, Options.HeatFlux, Options.CanopyRadAtt, Options.Infiltration, 
				Veg.MaxLayers, &LocalMet, &(Network[y][x]), &(PrecipMap[y][x]), 
			    &(VType[VegMap[y][x].Veg-1]), &(VegMap[y][x]), &(SType[SoilMap[y][x].Soil-1]),
			    &(SoilMap[y][x]), &(SnowMap[y][x]), &(RadiationMap[y][x]), &(EvapMap[y][x]), 
                &(Total.Rad), &ChannelData, SkyViewMap);
		 
		  PrecipMap[y][x].SumPrecip += PrecipMap[y][x].Precip;
		}
	  }
    }

	/* Average all RBM inputs over each segment */
	if (Options.StreamTemp) {
	  channel_grid_avg(ChannelData.streams);
      if (Options.CanopyShading)
	    CalcCanopyShading(&Time, ChannelData.streams, &SolarGeo);
	}

 #ifndef SNOW_ONLY
    
    RouteSubSurface(Time.Dt, &Map, TopoMap, VType, VegMap, Network,
		    SType, SoilMap, &ChannelData, &Time, &Options, Dump.Path,
		    MaxStreamID, SnowMap);

    if (Options.HasNetwork)
      RouteChannel(&ChannelData, &Time, &Map, TopoMap, SoilMap, &Total, 
		   &Options, Network, SType, PrecipMap, LocalMet.Tair, LocalMet.Rh);

    if (Options.Extent == BASIN)
      RouteSurface(&Map, &Time, TopoMap, SoilMap, &Options,
        UnitHydrograph, &HydrographInfo, Hydrograph,
        &Dump, VegMap, VType, &ChannelData);

#endif

    if (NGraphics > 0)
      draw(&(Time.Current), IsEqualTime(&(Time.Current), &(Time.Start)),
	   Time.DayStep, &Map, NGraphics, which_graphics, VType,
	   SType, SnowMap, SoilMap, VegMap, TopoMap, PrecipMap,
	   PrismMap, SkyViewMap, ShadowMap, EvapMap, RadiationMap, 
	   MetMap, Network, &Options);
    
    Aggregate(&Map, &Options, TopoMap, &Soil, &Veg, VegMap, EvapMap, PrecipMap,
	      RadiationMap, SnowMap, SoilMap, &Total, VType, Network, &ChannelData, &roadarea);
    
    MassBalance(&(Time.Current), &(Time.Start), &(Dump.Balance), &Total, &Mass);

    ExecDump(&Map, &(Time.Current), &(Time.Start), &Options, &Dump, TopoMap,
	     EvapMap, RadiationMap, PrecipMap, SnowMap, MetMap, VegMap, &Veg, 
		 SoilMap, Network, &ChannelData, &Soil, &Total, &HydrographInfo,Hydrograph);
	
    IncreaseTime(&Time);
	t += 1;
  }

  ExecDump(&Map, &(Time.Current), &(Time.Start), &Options, &Dump, TopoMap,
	   EvapMap, RadiationMap, PrecipMap, SnowMap, MetMap, VegMap, &Veg, SoilMap,
	   Network, &ChannelData, &Soil, &Total, &HydrographInfo, Hydrograph);

  FinalMassBalance(&(Dump.FinalBalance), &Total, &Mass);

  printf("\nEND OF MODEL RUN\n\n");

  /* record the run time at the end of each time loop */
  finish1 = clock ();
  runtime = (finish1-start)/CLOCKS_PER_SEC;
  printf("***********************************************************************************");
  printf("\nRuntime Summary:\n");
  printf("%6.2f hours elapsed for the simulation period of %d hours (%.1f days) \n", 
	  runtime/3600, t*Time.Dt/3600, (float)t*Time.Dt/3600/24);

  return EXIT_SUCCESS;
}
示例#21
0
int main(int argc, char **argv)
{
  float *Hydrograph = NULL;
  float ***MM5Input = NULL;
  float **PrecipLapseMap = NULL;
  float **PrismMap = NULL;
  unsigned char ***ShadowMap = NULL;
  float **SkyViewMap = NULL;
  float ***WindModel = NULL;
  int MaxStreamID, MaxRoadID;
  float SedDiams[NSEDSIZES];     /* Sediment particle diameters (mm) */
  clock_t start, finish1;
  double runtime = 0.0;
  int t = 0;
  float roadarea;
  time_t tloc;
  int flag;
  int i;
  int j;
  int x;						/* row counter */
  int y;						/* column counter */
  int shade_offset;				/* a fast way of handling arraay position given the number of mm5 input options */
  int NStats;					/* Number of meteorological stations */
  uchar ***MetWeights = NULL;	/* 3D array with weights for interpolating meteorological variables between the stations */

  int NGraphics;				/* number of graphics for X11 */
  int *which_graphics;			/* which graphics for X11 */
  char buffer[32];

  AGGREGATED Total = {			/* Total or average value of a  variable over the entire basin */
    {0.0, NULL, NULL, NULL, NULL, 0.0},												/* EVAPPIX */
    {0.0, 0.0, 0.0, 0.0, 0.0, NULL, NULL, 0.0, 0, 0.0},								/* PRECIPPIX */
    {{0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, 0.0, 0.0, 0.0},							/* PIXRAD */
    {0.0, 0.0},																		/* RADCLASSPIX */
    {0.0, 0.0, 0, NULL, NULL, 0.0, 0, 0.0, 0.0, 0.0, 0.0, NULL, 
	NULL, NULL, NULL, NULL, NULL, 0.0},												/* ROADSTRUCT*/
    {0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},		/* SNOWPIX */
    {0, 0.0, NULL, NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
     0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},			/*SOILPIX */
    { 0.0, 0.0, 0.0, 0.0, 0.0},														/*SEDPIX */
    { 0.0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},							/*FINEPIX */
    0.0, 0.0, 0.0, 0.0, 0.0, 0l, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
  };
  CHANNEL ChannelData = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL};
  DUMPSTRUCT Dump;
  EVAPPIX **EvapMap = NULL;
  INPUTFILES InFiles;
  LAYER Soil;
  LAYER Veg;
  LISTPTR Input = NULL;			/* Linked list with input strings */
  MAPSIZE Map;					/* Size and location of model area */
  MAPSIZE Radar;				/* Size and location of area covered by precipitation radar */
  MAPSIZE MM5Map;				/* Size and location of area covered by MM5 input files */
  METLOCATION *Stat = NULL;
  OPTIONSTRUCT Options;			/* Structure with information which program options to follow */
  PIXMET LocalMet;				/* Meteorological conditions for current pixel */
  FINEPIX ***FineMap	= NULL;
  PRECIPPIX **PrecipMap = NULL;
  RADARPIX **RadarMap	= NULL;
  RADCLASSPIX **RadMap	= NULL;
  PIXRAD **RadiationMap = NULL;
  ROADSTRUCT **Network	= NULL;	/* 2D Array with channel information for each pixel */
  SNOWPIX **SnowMap		= NULL;
  MET_MAP_PIX **MetMap	= NULL;
  SNOWTABLE *SnowAlbedo = NULL;
  SOILPIX **SoilMap		= NULL;
  SEDPIX **SedMap		= NULL;
  SOILTABLE *SType	    = NULL;
  SEDTABLE *SedType		= NULL;
  SOLARGEOMETRY SolarGeo;		/* Geometry of Sun-Earth system (needed for INLINE radiation calculations */
  TIMESTRUCT Time;
  TOPOPIX **TopoMap = NULL;
  UNITHYDR **UnitHydrograph = NULL;
  UNITHYDRINFO HydrographInfo;	/* Information about unit hydrograph */
  VEGPIX **VegMap = NULL;
  VEGTABLE *VType = NULL;
  WATERBALANCE Mass =			/* parameter for mass balance calculations */
    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  
      0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

/*****************************************************************************
  Initialization Procedures 
*****************************************************************************/
  if (argc != 2) {
    fprintf(stderr, "\nUsage: %s inputfile\n\n", argv[0]);
    fprintf(stderr, "DHSVM uses two output streams: \n");
    fprintf(stderr, "Standard Out, for the majority of output \n");
    fprintf(stderr, "Standard Error, for the final mass balance \n");
    fprintf(stderr, "\nTo pipe output correctly to files: \n");
    fprintf(stderr, "(cmd > f1) >& f2 \n");
    fprintf(stderr, "where f1 is stdout_file and f2 is stderror_file\n");
    exit(EXIT_FAILURE);
  }

  sprintf(commandline, "%s %s", argv[0], argv[1]);
  printf("%s \n", commandline);
  fprintf(stderr, "%s \n", commandline);
  strcpy(InFiles.Const, argv[1]);

  printf("\nRunning DHSVM %s\n", version);
  printf("\nSTARTING INITIALIZATION PROCEDURES\n\n");

  /* Start recording time */
  start = clock();

  ReadInitFile(InFiles.Const, &Input);
  InitConstants(Input, &Options, &Map, &SolarGeo, &Time);

  InitFileIO(Options.FileFormat);
  InitTables(Time.NDaySteps, Input, &Options, &SType, &Soil, &VType, &Veg,
	     &SnowAlbedo);

  InitTerrainMaps(Input, &Options, &Map, &Soil, &TopoMap, &SoilMap, &VegMap);

  CheckOut(Options.CanopyRadAtt, Veg, Soil, VType, SType, &Map, TopoMap, 
	   VegMap, SoilMap);

  if (Options.HasNetwork)
    InitChannel(Input, &Map, Time.Dt, &ChannelData, SoilMap, &MaxStreamID, &MaxRoadID, &Options);
  else if (Options.Extent != POINT)
    InitUnitHydrograph(Input, &Map, TopoMap, &UnitHydrograph,
		       &Hydrograph, &HydrographInfo);
 
  InitNetwork(Map.NY, Map.NX, Map.DX, Map.DY, TopoMap, SoilMap, 
	      VegMap, VType, &Network, &ChannelData, Veg, &Options);

  InitMetSources(Input, &Options, &Map, Soil.MaxLayers, &Time,
		 &InFiles, &NStats, &Stat, &Radar, &MM5Map);

  /* the following piece of code is for the UW PRISM project */
  /* for real-time verification of SWE at Snotel sites */
  /* Other users, set OPTION.SNOTEL to FALSE, or use TRUE with caution */

  if (Options.Snotel == TRUE && Options.Outside == FALSE) {
    printf
      ("Warning: All met stations locations are being set to the vegetation class GLACIER\n");
    printf
      ("Warning: This requires that you have such a vegetation class in your vegetation table\n");
    printf("To disable this feature set Snotel OPTION to FALSE\n");
    for (i = 0; i < NStats; i++) {
      printf("veg type for station %d is %d ", i,
	     VegMap[Stat[i].Loc.N][Stat[i].Loc.E].Veg);
      for (j = 0; j < Veg.NTypes; j++) {
	    if (VType[j].Index == GLACIER) {
	      VegMap[Stat[i].Loc.N][Stat[i].Loc.E].Veg = j;
		  break;
		}
      }
      if (j == Veg.NTypes) {	/* glacier class not found */
	    ReportError("MainDHSVM", 62);
	  }
      printf("setting to glacier type (assumed bare class): %d\n", j);
    }
  }

  InitMetMaps(Time.NDaySteps, &Map, &Radar, &Options, InFiles.WindMapPath,
	      InFiles.PrecipLapseFile, &PrecipLapseMap, &PrismMap,
	      &ShadowMap, &SkyViewMap, &EvapMap, &PrecipMap,
	      &RadarMap, &RadMap, SoilMap, &Soil, VegMap, &Veg, TopoMap,
	      &MM5Input, &WindModel);

  InitInterpolationWeights(&Map, &Options, TopoMap, &MetWeights, Stat, NStats);

  InitDump(Input, &Options, &Map, Soil.MaxLayers, Veg.MaxLayers, Time.Dt,
	   TopoMap, &Dump, &NGraphics, &which_graphics);

  if (Options.HasNetwork == TRUE) {
    InitChannelDump(&Options, &ChannelData, Dump.Path);
    ReadChannelState(Dump.InitStatePath, &(Time.Start), ChannelData.streams);
  }

  InitSnowMap(&Map, &SnowMap);
  InitAggregated(Veg.MaxLayers, Soil.MaxLayers, &Total);

  InitModelState(&(Time.Start), &Map, &Options, PrecipMap, SnowMap, SoilMap,
		 Soil, SType, VegMap, Veg, VType, Dump.InitStatePath,
		 SnowAlbedo, TopoMap, Network, &HydrographInfo, Hydrograph);

  InitNewMonth(&Time, &Options, &Map, TopoMap, PrismMap, ShadowMap,
	       RadMap, &InFiles, Veg.NTypes, VType, NStats, Stat, 
	       Dump.InitStatePath);

  InitNewDay(Time.Current.JDay, &SolarGeo);

  if (NGraphics > 0) {
    printf("Initialzing X11 display and graphics \n");
    InitXGraphics(argc, argv, Map.NY, Map.NX, NGraphics, &MetMap);
  }

  shade_offset = FALSE;
  if (Options.Shading == TRUE)
    shade_offset = TRUE;

  /* Done with initialization, delete the list with input strings */
  DeleteList(Input);

  /*****************************************************************************
  Sediment Initialization Procedures 
  *****************************************************************************/
  if(Options.Sediment) {
     time (&tloc);
     srand (tloc);
  /* Randomize Random Generator */
 
  /* Commenting the line above and uncommenting the line below 
     allows for the comparison of scenarios. */
  /*  srand48 (0);  */
    printf("\nSTARTING SEDIMENT INITIALIZATION PROCEDURES\n\n");

    ReadInitFile(Options.SedFile, &Input);

    InitParameters(Input, &Options, &Map, &Network, &ChannelData, TopoMap,
		   &Time, SedDiams);

    InitSedimentTables(Time.NDaySteps, Input, &SedType, &SType, &VType, &Soil, &Veg);

    InitFineMaps(Input, &Options, &Map, &Soil, &TopoMap, &SoilMap, 
		  &FineMap);

    if (Options.HasNetwork){ 
      printf("Initializing channel sediment\n\n");
      InitChannelSedimentDump(&ChannelData, Dump.Path, Options.ChannelRouting); 
      InitChannelSediment(ChannelData.streams, &Total);
      InitChannelSediment(ChannelData.roads, &Total);
    }

    InitSedMap( &Map, &SedMap);

    /* Done with initialization, delete the list with input strings */
    DeleteList(Input);
  }

  /* setup for mass balance calculations */
  Aggregate(&Map, &Options, TopoMap, &Soil, &Veg, VegMap, EvapMap, PrecipMap,
	      RadMap, SnowMap, SoilMap, &Total, VType, Network, SedMap, FineMap,
	      &ChannelData, &roadarea);

  Mass.StartWaterStorage =
    Total.Soil.IExcess + Total.CanopyWater + Total.SoilWater + Total.Snow.Swq +
    Total.Soil.SatFlow;
  Mass.OldWaterStorage = Mass.StartWaterStorage;

  if (Options.Sediment) {
    Mass.StartChannelSedimentStorage = Total.ChannelSedimentStorage;
    Mass.LastChannelSedimentStorage = Mass.StartChannelSedimentStorage;
  }

  /* computes the number of grid cell contributing to one segment */
  if (Options.StreamTemp) 
	Init_segment_ncell(TopoMap, ChannelData.stream_map, Map.NY, Map.NX, ChannelData.streams);

/*****************************************************************************
  Perform Calculations 
*****************************************************************************/
  while (Before(&(Time.Current), &(Time.End)) ||
	 IsEqualTime(&(Time.Current), &(Time.End))) {
    ResetAggregate(&Soil, &Veg, &Total, &Options);

    if (IsNewMonth(&(Time.Current), Time.Dt))
      InitNewMonth(&Time, &Options, &Map, TopoMap, PrismMap, ShadowMap,
		   RadMap, &InFiles, Veg.NTypes, VType, NStats, Stat, 
		   Dump.InitStatePath);

    if (IsNewDay(Time.DayStep)) {
      InitNewDay(Time.Current.JDay, &SolarGeo);
      PrintDate(&(Time.Current), stdout);
      printf("\n");
    }

    /* determine surface erosion and routing scheme */
    SedimentFlag(&Options, &Time); 

    InitNewStep(&InFiles, &Map, &Time, Soil.MaxLayers, &Options, NStats, Stat,
		InFiles.RadarFile, &Radar, RadarMap, &SolarGeo, TopoMap, RadMap,
        SoilMap, MM5Input, WindModel, &MM5Map);

    /* initialize channel/road networks for time step */
    if (Options.HasNetwork) {
      channel_step_initialize_network(ChannelData.streams);
      channel_step_initialize_network(ChannelData.roads);
    }

    for (y = 0; y < Map.NY; y++) {
      for (x = 0; x < Map.NX; x++) {
	    if (INBASIN(TopoMap[y][x].Mask)) {
		  if (Options.Shading)
	        LocalMet =
	        MakeLocalMetData(y, x, &Map, Time.DayStep, &Options, NStats,
			       Stat, MetWeights[y][x], TopoMap[y][x].Dem,
			       &(RadMap[y][x]), &(PrecipMap[y][x]), &Radar,
			       RadarMap, PrismMap, &(SnowMap[y][x]),
			       SnowAlbedo, MM5Input, WindModel, PrecipLapseMap,
			       &MetMap, NGraphics, Time.Current.Month,
			       SkyViewMap[y][x], ShadowMap[Time.DayStep][y][x],
			       SolarGeo.SunMax, SolarGeo.SineSolarAltitude);
		  else
	        LocalMet =
	        MakeLocalMetData(y, x, &Map, Time.DayStep, &Options, NStats,
			       Stat, MetWeights[y][x], TopoMap[y][x].Dem,
			       &(RadMap[y][x]), &(PrecipMap[y][x]), &Radar,
			       RadarMap, PrismMap, &(SnowMap[y][x]),
			       SnowAlbedo, MM5Input, WindModel, PrecipLapseMap,
			       &MetMap, NGraphics, Time.Current.Month, 0.0,
			       0.0, SolarGeo.SunMax,
			       SolarGeo.SineSolarAltitude);
		  
		  for (i = 0; i < Soil.MaxLayers; i++) {
	        if (Options.HeatFlux == TRUE) {
	          if (Options.MM5 == TRUE)
		        SoilMap[y][x].Temp[i] =
				MM5Input[shade_offset + i + N_MM5_MAPS][y][x];
			  else
		        SoilMap[y][x].Temp[i] = Stat[0].Data.Tsoil[i];
			}
	        else
	          SoilMap[y][x].Temp[i] = LocalMet.Tair;
		  }
		  
		  MassEnergyBalance(&Options, y, x, SolarGeo.SineSolarAltitude, Map.DX, Map.DY, 
			    Time.Dt, Options.HeatFlux, Options.CanopyRadAtt, Options.RoadRouting, 
			    Options.Infiltration, Veg.MaxLayers, &LocalMet, &(Network[y][x]), 
			    &(PrecipMap[y][x]), &(VType[VegMap[y][x].Veg-1]), &(VegMap[y][x]),
			    &(SType[SoilMap[y][x].Soil-1]), &(SoilMap[y][x]), &(SnowMap[y][x]), 
				&(EvapMap[y][x]), &(Total.Rad), &ChannelData, SkyViewMap);
		 
		  PrecipMap[y][x].SumPrecip += PrecipMap[y][x].Precip;
		}
	  }
    }

	/* Average all RBM inputs over each segment */
	if (Options.StreamTemp) {
	  channel_grid_avg(ChannelData.streams);
	}

 #ifndef SNOW_ONLY

    /* set sediment inflows to zero - they are incremented elsewhere */
    if ((Options.HasNetwork) && (Options.Sediment)){ 
      InitChannelSedInflow(ChannelData.streams);
      InitChannelSedInflow(ChannelData.roads);
	}
    
    RouteSubSurface(Time.Dt, &Map, TopoMap, VType, VegMap, Network,
		    SType, SoilMap, &ChannelData, &Time, &Options, Dump.Path,
		    SedMap, FineMap, SedType, MaxStreamID, SnowMap);

    if (Options.HasNetwork)
      RouteChannel(&ChannelData, &Time, &Map, TopoMap, SoilMap, &Total, 
		   &Options, Network, SType, PrecipMap, SedMap,
		   LocalMet.Tair, LocalMet.Rh, SedDiams);

    /* Sediment Routing in Channel and output to sediment files */
    if ((Options.HasNetwork) && (Options.Sediment)){
      SPrintDate(&(Time.Current), buffer);
      flag = IsEqualTime(&(Time.Current), &(Time.Start));

      if (Options.ChannelRouting){
	    if (ChannelData.roads != NULL) {
	      RouteChannelSediment(ChannelData.roads, Time, &Dump, &Total, SedDiams);
	      channel_save_sed_outflow_text(buffer, ChannelData.roads,
					ChannelData.sedroadout,
					ChannelData.sedroadflowout, flag);
		  RouteCulvertSediment(&ChannelData, &Map, TopoMap, SedMap, 
			       &Total, SedDiams);
		}
	    RouteChannelSediment(ChannelData.streams, Time, &Dump, &Total, SedDiams);
 	    channel_save_sed_outflow_text(buffer, ChannelData.streams,
				      ChannelData.sedstreamout,
				      ChannelData.sedstreamflowout, flag);
	  }
      else {
	    if (ChannelData.roads != NULL) {
			channel_save_sed_inflow_text(buffer, ChannelData.roads,
			ChannelData.sedroadinflow, SedDiams,flag);
		}
	    channel_save_sed_inflow_text(buffer, ChannelData.streams,
			ChannelData.sedstreaminflow, SedDiams,flag);
      }
      SaveChannelSedInflow(ChannelData.roads, &Total);
      SaveChannelSedInflow(ChannelData.streams, &Total);
    }
    
    if (Options.Extent == BASIN)
      RouteSurface(&Map, &Time, TopoMap, SoilMap, &Options,
		   UnitHydrograph, &HydrographInfo, Hydrograph,
		   &Dump, VegMap, VType, SType, &ChannelData, SedMap,
		   PrecipMap, SedType, LocalMet.Tair, LocalMet.Rh, SedDiams);

#endif

    if (NGraphics > 0)
      draw(&(Time.Current), IsEqualTime(&(Time.Current), &(Time.Start)),
	   Time.DayStep, &Map, NGraphics, which_graphics, VType,
	   SType, SnowMap, SoilMap, SedMap, FineMap, VegMap, TopoMap, PrecipMap,
	   PrismMap, SkyViewMap, ShadowMap, EvapMap, RadMap, MetMap, Network,
	   &Options);
    
    Aggregate(&Map, &Options, TopoMap, &Soil, &Veg, VegMap, EvapMap, PrecipMap,
	      RadMap, SnowMap, SoilMap, &Total, VType, Network, SedMap, FineMap,
	      &ChannelData, &roadarea);
    
    MassBalance(&(Time.Current), &(Dump.Balance), &(Dump.SedBalance), &Total, 
		&Mass, &Options);

    ExecDump(&Map, &(Time.Current), &(Time.Start), &Options, &Dump, TopoMap,
	     EvapMap, RadiationMap, PrecipMap, RadMap, SnowMap, MetMap, VegMap, &Veg, 
		 SoilMap, SedMap, Network, &ChannelData, FineMap, &Soil, &Total, 
		 &HydrographInfo,Hydrograph);
	
    IncreaseTime(&Time);
	t += 1;
  }

  ExecDump(&Map, &(Time.Current), &(Time.Start), &Options, &Dump, TopoMap,
	   EvapMap, RadiationMap, PrecipMap, RadMap, SnowMap, MetMap, VegMap, &Veg, SoilMap,
	   SedMap, Network, &ChannelData, FineMap, &Soil, &Total, &HydrographInfo, Hydrograph);

  FinalMassBalance(&(Dump.FinalBalance), &Total, &Mass, &Options, roadarea);

  /*printf("\nSTARTING CLEANUP\n\n");
  cleanup(&Dump, &ChannelData, &Options);*/
  printf("\nEND OF MODEL RUN\n\n");

  /* record the run time at the end of each time loop */
  finish1 = clock ();
  runtime = (finish1-start)/CLOCKS_PER_SEC;
  printf("***********************************************************************************");
  printf("\nRuntime Summary:\n");
  printf("%6.2f hours elapsed for the simulation period of %d hours (%.1f days) \n", 
	  runtime/3600, t*Time.Dt/3600, (float)t*Time.Dt/3600/24);

  return EXIT_SUCCESS;
}
示例#22
0
void MainWindow::OnNetInit()
{
	InitNetwork();
}
示例#23
0
int main (int argc, char* argv[])
{
  int i,j ;
  char *RetVal ;
  char *Hue ;
  char *Sat ;
  char *Val ;
  char *White ;
  unsigned char Data[8] ; 
  int R,G,B,W ;
  int H,S,V ;
  ULONG CanID ;
  char Var[256] ;
  FILE *Dat ;
  clock_t start,end ;

  usleep(1) ;
  InitNetwork () ;

 
  Dat = fopen("LED","r") ;
  if (Dat!=NULL) {
    fscanf (Dat,"%d %d %d %d\n",&H,&S,&V,&W) ;
    fclose (Dat) ;
  } ;

  RetVal = getenv("QUERY_STRING") ;
  if (RetVal==NULL) {
    printf ("Content-type: text/html\n\n") ;
    printf ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n") ;
    printf ("<html><head><title>Umgebungsvariablen</title></head><body>\n");
    
    printf ("No Query String\n") ;
    printf ("</html>") ;  
    exit(0);
  } ;
  Hue = strstr(RetVal,"Hue.x=") ;
  if (Hue!=NULL) {
    sscanf (Hue,"Hue.x=%d",&H) ;
  } ;
  Sat = strstr(RetVal,"Sat.x=") ;
  if (Sat!=NULL) {
    sscanf (Sat,"Sat.x=%d",&S) ;
  } ;

  Val = strstr(RetVal,"Val.x=") ;
  if (Val!=NULL) {
    sscanf (Val,"Val.x=%d",&V) ;
  } ;

  Val = strstr(RetVal,"White.x=") ;
  if (Val!=NULL) {
    sscanf (Val,"White.x=%d",&W) ;
  } ;

  Val = strstr(RetVal,"An") ;
  if (Val!=NULL) {
    V = 255 ;
    S = 0 ;
    W = 255 ;
  } ;
  
  Val = strstr(RetVal,"Aus") ;
  if (Val!=NULL) {
    V = 0 ;
    W = 0 ;
  } ;

  Val = strstr(RetVal,"KH") ;
  if (Val!=NULL) {
    Rolladen (1,1,101,1) ;
  } ;

  Val = strstr(RetVal,"KR") ;
  if (Val!=NULL) {
    Rolladen (-1,1,101,1) ;
  } ;

  Val = strstr(RetVal,"KS") ;
  if (Val!=NULL) {
    Rolladen (0,1,101,1) ;
  } ;

  Val = strstr(RetVal,"WAH") ;
  if (Val!=NULL) {
    Jalousie (-1) ;
  } ;

  Val = strstr(RetVal,"WAR") ;
  if (Val!=NULL) {
    Jalousie (1) ;
  } ;

  Val = strstr(RetVal,"WAS") ;
  if (Val!=NULL) {
    Jalousie (0) ;
  } ;

  Val = strstr(RetVal,"WOH") ;
  if (Val!=NULL) {
    Rolladen (-1,3,104,4) ;
  } ;

  Val = strstr(RetVal,"WOR") ;
  if (Val!=NULL) {
    Rolladen (1,3,104,4) ;
  } ;

  Val = strstr(RetVal,"WOS") ;
  if (Val!=NULL) {
    Rolladen (0,3,104,4) ;
  } ;

  Val = strstr(RetVal,"WLH") ;
  if (Val!=NULL) {
    Rolladen (-1,3,104,1) ;
  } ;

  Val = strstr(RetVal,"WLR") ;
  if (Val!=NULL) {
    Rolladen (1,3,104,1) ;
  } ;

  Val = strstr(RetVal,"WLS") ;
  if (Val!=NULL) {
    Rolladen (0,3,104,1) ;
  } ;

  Val = strstr(RetVal,"WMH") ;
  if (Val!=NULL) {
    Rolladen (-1,3,104,3) ;
  } ;

  Val = strstr(RetVal,"WMR") ;
  if (Val!=NULL) {
    Rolladen (1,3,104,3) ;
  } ;

  Val = strstr(RetVal,"WMS") ;
  if (Val!=NULL) {
    Rolladen (0,3,104,3) ;
  } ;

  Val = strstr(RetVal,"WRH") ;
  if (Val!=NULL) {
    Rolladen (-1,3,104,5) ;
  } ;

  Val = strstr(RetVal,"WRR") ;
  if (Val!=NULL) {
    Rolladen (1,3,104,5) ;
  } ;

  Val = strstr(RetVal,"WRS") ;
  if (Val!=NULL) {
    Rolladen (0,3,104,5) ;
  } ;

  Val = strstr(RetVal,"WAO") ;
  if (Val!=NULL) {
    Jalousie(-1);
    usleep(500000);
    Jalousie(0);
  } ;


  Val = strstr(RetVal,"EH") ;
  if (Val!=NULL) {
    Rolladen (1,1,103,3) ;
  } ;

  Val = strstr(RetVal,"ER") ;
  if (Val!=NULL) {
    Rolladen (-1,1,103,3) ;
  } ;

  Val = strstr(RetVal,"ES") ;
  if (Val!=NULL) {
    Rolladen (0,1,103,3) ;
  } ;

  Val = strstr(RetVal,"WLAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,100,0) ;
    Data [0] = 30 ;
    Data [1] = 9;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"WLAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,100,0) ;
    Data [0] = 31 ;
    Data [1] = 9;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"BLAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 30 ;
    Data [1] = 8;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"BLAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 31 ;
    Data [1] = 8;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"FLAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 30 ;
    Data [1] = 2;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"FLAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 31 ;
    Data [1] = 2;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"SWZFRAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,103,0) ;
    Data [0] = 30 ;
    Data [1] = 1;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"SWZFRAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,103,0) ;
    Data [0] = 31 ;
    Data [1] = 1;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"SWZFLAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,100,0) ;
    Data [0] = 30 ;
    Data [1] = 5;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
    CanID = BuildCANId (0,0,0,1,1,100,0) ;
    Data [0] = 30 ;
    Data [1] = 10;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"SWZFLAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,100,0) ;
    Data [0] = 31 ;
    Data [1] = 5;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
    CanID = BuildCANId (0,0,0,1,1,100,0) ;
    Data [0] = 31 ;
    Data [1] = 10;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"SEZFLAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,103,0) ;
    Data [0] = 30 ;
    Data [1] = 7;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"SEZFLAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,103,0) ;
    Data [0] = 31 ;
    Data [1] = 7;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"SEZFTAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,103,0) ;
    Data [0] = 30 ;
    Data [1] = 4;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"SEZFTAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,103,0) ;
    Data [0] = 31 ;
    Data [1] = 4;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"KFSMAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 30 ;
    Data [1] = 9;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"KFSMAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 31 ;
    Data [1] = 9;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"KFSSAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 30 ;
    Data [1] = 4;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"KFSSAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 31 ;
    Data [1] = 4;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"GLAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 30 ;
    Data [1] = 6;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"GLAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,102,0) ;
    Data [0] = 31 ;
    Data [1] = 6;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"KLAn") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,101,0) ;
    Data [0] = 30 ;
    Data [1] = 5;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
    CanID = BuildCANId (0,0,0,1,1,100,0) ;
    Data [0] = 30 ;
    Data [1] = 2;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"KLAus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,1,101,0) ;
    Data [0] = 31 ;
    Data [1] = 5;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
    CanID = BuildCANId (0,0,0,1,1,100,0) ;
    Data [0] = 31 ;
    Data [1] = 2;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"KBAL1An") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 30 ;
    Data [1] = 3;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"KBAL1Aus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 31 ;
    Data [1] = 3;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"BL1An") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 30 ;
    Data [1] = 6;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"BL1Aus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 31 ;
    Data [1] = 6;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"BL2An") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 30 ;
    Data [1] = 1;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"BL2Aus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 31 ;
    Data [1] = 1;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"NL1An") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 30 ;
    Data [1] = 7;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"NL1Aus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 31 ;
    Data [1] = 7;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"NL2An") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 30 ;
    Data [1] = 2;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"NL2Aus") ;
  if (Val!=NULL) {
    CanID = BuildCANId (0,0,0,1,3,102,0) ;
    Data [0] = 31 ;
    Data [1] = 2;
    SendCANMessage (CanID, 2 ,Data) ;
    usleep(50000) ;
  } ;

  Val = strstr(RetVal,"BRH") ;
  if (Val!=NULL) {
    Beckiefenster (-1) ;
  } ;

  Val = strstr(RetVal,"BRR") ;
  if (Val!=NULL) {
    Beckiefenster (1) ;
  } ;

  Val = strstr(RetVal,"BRS") ;
  if (Val!=NULL) {
    Beckiefenster (0) ;
  } ;

  Val = strstr(RetVal,"NRH") ;
  if (Val!=NULL) {
    Niklasfenster (-1) ;
  } ;

  Val = strstr(RetVal,"NRR") ;
  if (Val!=NULL) {
    Niklasfenster (1) ;
  } ;

  Val = strstr(RetVal,"NRS") ;
  if (Val!=NULL) {
    Niklasfenster (0) ;
  } ;

  Val = strstr(RetVal,"DAH") ;
  if (Val!=NULL) {
    Elternfenster (-1,0) ;
  } ;

  Val = strstr(RetVal,"DAR") ;
  if (Val!=NULL) {
    Elternfenster (1,0) ;
  } ;

  Val = strstr(RetVal,"DAS") ;
  if (Val!=NULL) {
    Elternfenster (0,0) ;
  } ;

  Val = strstr(RetVal,"DGGH") ;
  if (Val!=NULL) {
    Elternfenster (-1,2) ;
  } ;

  Val = strstr(RetVal,"DGGR") ;
  if (Val!=NULL) {
    Elternfenster (1,2) ;
  } ;

  Val = strstr(RetVal,"DGGS") ;
  if (Val!=NULL) {
    Elternfenster (0,2) ;
  } ;

  Val = strstr(RetVal,"DGVH") ;
  if (Val!=NULL) {
    Elternfenster (-1,1) ;
  } ;

  Val = strstr(RetVal,"DGVR") ;
  if (Val!=NULL) {
    Elternfenster (1,1) ;
  } ;

  Val = strstr(RetVal,"DGVS") ;
  if (Val!=NULL) {
    Elternfenster (0,1) ;
  } ;

  Val = strstr(RetVal,"DG1H") ;
  if (Val!=NULL) {
    Rolladen (1,3,100,1) ;
  } ;

  Val = strstr(RetVal,"DG1R") ;
  if (Val!=NULL) {
    Rolladen (-1,3,100,1) ;
  } ;

  Val = strstr(RetVal,"DG1S") ;
  if (Val!=NULL) {
    Rolladen (0,3,100,1) ;
  } ;

  Val = strstr(RetVal,"DG2H") ;
  if (Val!=NULL) {
    Rolladen (1,3,100,3) ;
  } ;

  Val = strstr(RetVal,"DG2R") ;
  if (Val!=NULL) {
    Rolladen (-1,3,100,3) ;
  } ;

  Val = strstr(RetVal,"DG2S") ;
  if (Val!=NULL) {
    Rolladen (0,3,100,3) ;
  } ;

  Val = strstr(RetVal,"DG3H") ;
  if (Val!=NULL) {
    Rolladen (1,3,100,4) ;
  } ;

  Val = strstr(RetVal,"DG3R") ;
  if (Val!=NULL) {
    Rolladen (-1,3,100,4) ;
  } ;

  Val = strstr(RetVal,"DG3S") ;
  if (Val!=NULL) {
    Rolladen (0,3,100,4) ;
  } ;

  Val = strstr(RetVal,"DG4H") ;
  if (Val!=NULL) {
    Rolladen (1,3,100,5) ;
  } ;

  Val = strstr(RetVal,"DG4R") ;
  if (Val!=NULL) {
    Rolladen (-1,3,100,5) ;
  } ;

  Val = strstr(RetVal,"DG4S") ;
  if (Val!=NULL) {
    Rolladen (0,3,100,5) ;
  } ;

  Val = strstr(RetVal,"DG5H") ;
  if (Val!=NULL) {
    Rolladen (1,3,101,4) ;
  } ;

  Val = strstr(RetVal,"DG5R") ;
  if (Val!=NULL) {
    Rolladen (-1,3,101,4) ;
  } ;

  Val = strstr(RetVal,"DG5S") ;
  if (Val!=NULL) {
    Rolladen (0,3,101,4) ;
  } ;

  Val = strstr(RetVal,"DG6H") ;
  if (Val!=NULL) {
    Rolladen (1,3,101,5) ;
  } ;

  Val = strstr(RetVal,"DG6R") ;
  if (Val!=NULL) {
    Rolladen (-1,3,101,5) ;
  } ;

  Val = strstr(RetVal,"DG6S") ;
  if (Val!=NULL) {
    Rolladen (0,3,101,5) ;
  } ;

  Val = strstr(RetVal,"KBH") ;
  if (Val!=NULL) {
    Rolladen (1,3,105,5) ;
  } ;

  Val = strstr(RetVal,"KBR") ;
  if (Val!=NULL) {
    Rolladen (-1,3,105,5) ;
  } ;

  Val = strstr(RetVal,"KBS") ;
  if (Val!=NULL) {
    Rolladen (0,3,105,5) ;
  } ;

  Dat = fopen("LED","w") ;
  fprintf (Dat,"%d %d %d %d\n",H,S,V,W) ;
  fclose (Dat) ;
  

  /*  Data[0] = 10 ;
      Data[1] = (unsigned char)H ;
      Data[2] = (unsigned char)S ;
      Data[3] = (unsigned char)V ;
      Data[4] = (unsigned char)W ;
      
      Val = strstr(RetVal,"Disko") ;
      if (Val!=NULL) {
      for (i=0;i<20;i++) {
      Data[0] = 19 ;
      Data[1] = i ;
      CanID = BuildCANId (0,0,0,1,1,23,0) ;
      SendCANMessage (CanID, 2 ,Data) ; 
      usleep(100000) ;
      } ;
      } else if (strstr(RetVal,"DAus")) {
      Data[0] = 20 ;
      Data[1] = 22 ;
      CanID = BuildCANId (0,0,0,1,1,23,0) ;
      SendCANMessage (CanID, 2 ,Data) ; 
      } else if (strstr(RetVal,"LED=7")!=NULL) {
      CanID = BuildCANId (0,0,0,1,1,23,0) ;
      SendCANMessage (CanID, 5 ,Data) ;
      } else {
      for (i=0;i<7;i++) {
      sprintf (Var,"LED=%d",i) ;
      if (strstr(RetVal,Var)!=NULL) {
      CanID = BuildCANId (0,0,0,1,1,16+i,0) ;
      SendCANMessage (CanID, 5 ,Data) ;
      usleep(1000) ;
      } ;
      } ;
      } ;
  */

  printf ("Content-type: text/html\n\n") ;
  printf ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n") ;
  printf ("<html><head><title>Umgebungsvariablen</title></head><body>\n");

  //  printf ("%s\n",RetVal) ;
  printf ("<script type=\"text/javascript\">\n") ;
  printf ("history.back();\n") ;
  printf ("</script>") ;
  printf ("</html>") ;
  CloseNetwork () ;
}
示例#24
0
/**
 * @ingroup SipStack
 * @brief SIP stack 을 시작한다. SIP stack 쓰레드와 network 수신 쓰레드를 시작한다.
 * @param clsSetup SIP stack 설정 항목 저장 객체
 * @returns 성공하면 true 를 리턴하고 실패하면 false 를 리턴한다.
 */
bool CSipStack::Start( CSipStackSetup & clsSetup )
{
	if( m_bStarted || m_bStopEvent ) return false;
	if( clsSetup.Check() == false ) return false;

	m_clsSetup = clsSetup;
	m_clsICT.SetTimerD( m_clsSetup.m_iTimerD );
	m_clsNIST.SetTimerJ( m_clsSetup.m_iTimerJ );
	m_clsTcpConnectMap.SetStateful( m_clsSetup.m_bStateful );

#ifdef USE_TLS
	m_clsTlsConnectMap.SetStateful( m_clsSetup.m_bStateful );
#endif

	InitNetwork();

	if( m_clsSetup.m_iLocalUdpPort > 0 )
	{
		m_hUdpSocket = UdpListen( m_clsSetup.m_iLocalUdpPort, NULL, m_clsSetup.m_bIpv6 );
		if( m_hUdpSocket == INVALID_SOCKET ) return false;
	}

	if( m_clsSetup.m_iLocalTcpPort > 0 )
	{
		m_hTcpSocket = TcpListen( m_clsSetup.m_iLocalTcpPort, 255, NULL, m_clsSetup.m_bIpv6 );
		if( m_hTcpSocket == INVALID_SOCKET ) 
		{
			CLog::Print( LOG_ERROR, "TcpListen(%d) error", m_clsSetup.m_iLocalTcpPort );
			_Stop();
			return false;
		}

		m_clsTcpThreadList.SetMaxSocketPerThread( m_clsSetup.m_iTcpMaxSocketPerThread );
		if( m_clsTcpThreadList.Init( m_clsSetup.m_iTcpThreadCount, m_clsSetup.m_iTcpThreadCount, SipTcpThread, this ) == false )
		{
			_Stop();
			return false;
		}

		if( StartSipTcpListenThread( this ) == false )
		{
			_Stop();
			return false;
		}
	}

#ifdef USE_TLS
	if( m_clsSetup.m_iLocalTlsPort > 0 )
	{
		if( SSLServerStart( m_clsSetup.m_strCertFile.c_str(), m_clsSetup.m_strCaCertFile.c_str() ) == false )
		{
			_Stop();
			return false;
		}

		m_hTlsSocket = TcpListen( m_clsSetup.m_iLocalTlsPort, 255, NULL, m_clsSetup.m_bIpv6 );
		if( m_hTlsSocket == INVALID_SOCKET ) 
		{
				CLog::Print( LOG_ERROR, "TcpListen(%d) error", m_clsSetup.m_iLocalTlsPort );
			_Stop();
			return false;
		}

		m_clsTlsThreadList.SetMaxSocketPerThread( m_clsSetup.m_iTcpMaxSocketPerThread );
		if( m_clsTlsThreadList.Init( m_clsSetup.m_iTcpThreadCount, m_clsSetup.m_iTcpThreadCount, SipTlsThread, this ) == false )
		{
			_Stop();
			return false;
		}

		if( StartSipTlsListenThread( this ) == false )
		{
			_Stop();
			return false;
		}
	}
	else if( m_clsSetup.m_bTlsClient )
	{
		if( SSLClientStart( ) == false )
		{
			_Stop();
			return false;
		}

		m_clsTlsThreadList.SetMaxSocketPerThread( m_clsSetup.m_iTcpMaxSocketPerThread );
		if( m_clsTlsThreadList.Init( m_clsSetup.m_iTcpThreadCount, m_clsSetup.m_iTcpThreadCount, SipTlsThread, this ) == false )
		{
			_Stop();
			return false;
		}
	}
#endif

	if( m_clsSetup.m_iLocalUdpPort > 0 )
	{
		if( StartSipUdpThread( this ) == false )
		{
			_Stop();
			return false;
		}
	}

	if( m_clsSetup.m_bStateful )
	{
		if( StartSipStackThread( this ) == false )
		{
			_Stop();
			return false;
		}
	}

	if( m_clsSetup.m_iTcpCallBackThreadCount > 0 )
	{
		for( int i = 0; i < m_clsSetup.m_iTcpCallBackThreadCount; ++i )
		{
			if( StartSipQueueThread( this ) == false )
			{
				_Stop();
				return false;
			}
		}
	}

	m_bStarted = true;

	return true;
}
示例#25
0
文件: main.c 项目: max1325/uae-wii
int main (int argc, char **argv)
{
	
	#ifdef GEKKO
	
	printf("\x1b[2;0H");

	//initialize libfat library
	if (fatInitDefault())
		printf("FAT subsytem initialized\n\n");
	else
		{
		printf("Couldn't initialize FAT subsytem\n\n");
		sleep(3);
		exit(0);
		}
		
	DIR *dp;
    
	dp = opendir ("sd:/");
	if (dp) sdismount = 1; else sdismount = 0;
	
	if (sdismount)
		printf("SD FAT subsytem initialized\n\n");
	else
		printf("Couldn't initialize SD fat subsytem\n\n");
 	
	if (sdismount) closedir (dp);
	
	usbismount = InitUSB();
	

    default_prefs (&currprefs, 0);
	cfgfile_load (&currprefs, SMBFILENAME, 0);
	printf("\n");
	
	if (currprefs.smb_enable) networkisinit = InitNetwork();
	
	if (networkisinit && currprefs.smb_enable) ConnectShare(); 

	sleep(2);

	if (!(log_quiet = !currprefs.write_logfile)) set_logfile("/uae/uae.log");
	
	#endif
	
	write_log("main started\n");
    init_sdl ();
	write_log("sdl inited\n");
    gui_init (argc, argv);
	write_log("Starting real main\n");
    real_main (argc, argv);
	
	#ifdef GEKKO
	if (smbismount) CloseShare ();
	DeInitUSB();
	fatUnmount(0);
	#endif

    return 0;
}