Пример #1
0
// Init
// returns ERROR (255) if the TP-UART is not in INIT state, else returns OK (0)
// Init must be called after every reset() execution
byte KnxTpUart::Init(void)
{
  byte tpuartCmd[3];

  if ((_rx.state!=RX_INIT) || (_tx.state!=TX_INIT)) return KNX_TPUART_ERROR_NOT_INIT_STATE;

  // BUS MONITORING MODE in case it is selected
  if (_mode == BUS_MONITOR)
  {
    _serial.write(TPUART_ACTIVATEBUSMON_REQ); // Send bus monitoring activation request
    DebugInfo("Init : Monitoring mode started\n");
  }
  else // NORMAL mode by default
  {
    if (_comObjectsList == NULL)  DebugInfo("Init : warning : empty object list!\n");
    if (_evtCallbackFct == NULL) return KNX_TPUART_ERROR_NULL_EVT_CALLBACK_FCT;
    if (_tx.ackFctPtr == NULL) return KNX_TPUART_ERROR_NULL_ACK_CALLBACK_FCT;

    // Set Physical address. This allows to activate address evaluation by the TPUART
    tpuartCmd[0] = TPUART_SET_ADDR_REQ;
    tpuartCmd[1] = (byte)(_physicalAddr>>8);
    tpuartCmd[2] = (byte)_physicalAddr;
    _serial.write(tpuartCmd,3);
  
    // Call U_State.request-Service in order to have the field _stateIndication up-to-date
    _serial.write(TPUART_STATE_REQ);

    _rx.state = RX_IDLE_WAITING_FOR_CTRL_FIELD;
    _tx.state = TX_IDLE;
    DebugInfo("Init : Normal mode started\n");
  }
  return KNX_TPUART_OK;
}
Пример #2
0
bool CPlayer::CanKillNow()
{
	DebugInfo("CanKillNow Start Socket=%d PID=%d",reinterpret_cast<int>(m_pClientSocket),m_PID);

	if ( m_pRoom )
	{
		if ( m_RoomID == m_pRoom->GetRoomID() )
		{
			if ( m_pTable )
			{
				if ( m_TableID == m_pTable->GetTableID() )
				{
					if ( m_pTable->GetTableState()==TABLE_ST_PLAYING && this->IsPlaying() )
					{
						return false;
					}
				}
				else
				{
					DebugError("CPlayer::CanKillNow PID=%d,TableID=%d",m_PID,m_TableID);
				}
			}
		}
		else
		{
			DebugError("CPlayer::CanKillNow PID=%d,RoomID=%d",m_PID,m_RoomID);
		}
	}

	DebugInfo("CanKillNow End Socket=%d PID=%d",reinterpret_cast<int>(m_pClientSocket),m_PID);

	return true;
}
Пример #3
0
// calculate distance between two points in earth
// will not 100% accurate
double GeoCalc::geodeticDistance(double lat1, double lon1, double alt1, double lat2, double lon2, double alt2)
{
	bool isInputError = false;

	// Check inputs
	// http://docs.obspy.org/coverage/_opt_obspy_python_src_obspy_obspy_signal_obspy_signal_rotate.html
	if (lat1 > 90 || lat1 < -90)
	{
		DebugInfo("Latitude of point 1 out of bounds (-90 <= lat1 <=90)", DebugInfo::Warning);
		isInputError = true;
	}
	while (lon1 > 180)
		lon1 -= 360;
	while (lon1 < -180) 
		lon1 += 360;
	if (lat2 > 90 || lat2 < -90)
	{
		DebugInfo("Latitude of point 2 out of bounds (-90 <= lat2 <=90)", DebugInfo::Warning);
		isInputError = true;
	}
	while (lon2 > 180)
		lon2 -= 360;
	while (lon2 < -180)
		lon2 += 360;

	// ardhi's
	if(alt1 < -6340000) // approximate earth's core depth
	{
		DebugInfo("Altitude of point 1 out of bounds (alt1 >= -6340000)", DebugInfo::Warning);
		isInputError = true;
	}
	if(alt2 < -6340000) // approximate earth's core depth
	{
		DebugInfo("Altitude of point 2 out of bounds (alt1 >= -6340000)", DebugInfo::Warning);
		isInputError = true;
	}

	if(isInputError)
		return -1;

	if ((abs(lat1 - lat2) < 1e-8) && (abs(lon1 - lon2) < 1e-8) && (abs(alt1 - alt1) < 1e-8)) // 1e8 = 0.00000001  
		return 0.0f;

	/* http://www.faqs.org/faqs/geography/infosystems-faq/
	Pythagorean Theorem
	d = sqrt((X2 - X1)^2 + (Y2 - Y1)^2)
	will result in an error of
	less than 30 meters (100 ft) for latitudes less than 70 degrees
	less than 20 meters ( 66 ft) for latitudes less than 50 degrees
	less than  9 meters ( 30 ft) for latitudes less than 30 degrees
	*/
	if(lat1 > 30 || lat1 < -30 || lat2 > 30 || lat2 < -30) // vector based distance will results calculation error > 9 meters if latitude is < 30 degrees
		return greatCircleDistanceHaversine(lat1, lon1, lat2, lon2);

	if(vectorDistance(lat1, lon1, 0, lat2, lon2, 0) > 5000) // is distance > 5 km, use haversine method, but neglects altitude
		return greatCircleDistanceHaversine(lat1, lon1, lat2, lon2);

	return vectorDistance(lat1, lon1, alt1, lat2, lon2, alt2);
}
Пример #4
0
int main( int argc, char* argv[] )
{
	//string sAppDir = GetUntilLast( argv[0], "\\" );

	/* This is a hacky thing to avoid messing with the command line arguments. Remove for normal usage.	*/
	//argc = 2; argv[1] = "wikiadventure://";
	/* End of hack thing. */

	char czFullName[ MAX_PATH + 1 ];
	GetModuleFileName( NULL, czFullName, MAX_PATH );
	
	g_sAppDir = GetUntilLast( czFullName, "\\" );

	DebugInfo( TypeInfo, string("Application directory: " + g_sAppDir).c_str() );

	// Init the debug log, if it is activated
#ifdef DEBUG_APP_LOG
	pDebugLog = new CDebugLogHandler( g_sAppDir +  "\\Log\\Debug.xml" );
	
	pDebugLog->AddTagTree( "Project" );
	pDebugLog->AddTag( "Name", "WikiDialog Reader" );
	pDebugLog->AddTag( "MainSourceDir", GetUntilLast( __FILE__, "\\" ) );
	pDebugLog->AddTag( "Compiled", COMPILE_TIMESTAMP );

	pDebugLog->AddTagTree( "CmdArguments" );
	for ( int i = 0; i < argc; ++i )
        pDebugLog->AddTag( "CmdArgument", argv[i] );
	pDebugLog->CloseTagTree(); // CmdArguments

	pDebugLog->AddTagTree( "LogEntries" );
#endif

	for ( int i = 0; i < argc; ++i )
		DebugInfo( TypeInfo, string("Command line: " + string(argv[i])).c_str() );

	if ( argc != 2 ) {
		DebugInfo( TypeWarning, "Application is called with an invalid number of arguments." );
		argc = 2; argv[1] = "";
	}

	string sGamePage = GetAfterLast( argv[1], "//" );
	// Remove "/" from text and replace "_" with a space
	sGamePage = ReplaceInText( RemoveFromText( sGamePage, "/" ), "_", " " );

	DebugInfo(TypeInfo, string("Game page: " + sGamePage).c_str() );

	pEngine = new CMyEngine;
	
	LoadGames( sGamePage );

	// Terminate the debug log, if is it activated
#ifdef DEBUG_APP_LOG
	if ( pDebugLog != 0 )
		delete pDebugLog;
#endif

	return 0;
}
Пример #5
0
// Destructor
KnxTpUart::~KnxTpUart()
{
  if (_orderedIndexTable) free(_orderedIndexTable);
  // close the serial communication if opened
  if ( (_rx.state > RX_RESET) || (_tx.state > TX_RESET) ) 
  {
    _serial.end();
    DebugInfo("Destructor: connection closed, byebye\n");
  }
  else DebugInfo("Desctructor: byebye\n");
}
Пример #6
0
void CPlayer::DisAttachSocket()
{
	DebugInfo("DisAttachSocket Start Socket=%d PID=%d",reinterpret_cast<int>(m_pClientSocket),m_PID);

	if( this->m_pClientSocket )
	{
		this->m_pClientSocket->Close();
		this->m_pClientSocket = NULL;
	}
	m_SocketCloseTime = GetCurTime();

	DebugInfo("DisAttachSocket End");
}
Пример #7
0
CSDLStateShowText::CSDLStateShowText( const string& sText, const string& sOnExitScript )
{
	DebugInfo( TypeCreate, "Creating text box." );
	m_sOnExitScript = sOnExitScript;

	m_pText = new CSDLMultilineTextObject( string("Dialog"), sText );
	
	SDL_Color stBlueish = { 100, 100, 255 };
	SDL_Color stWhite	= { 255, 255, 255 };

	m_pButtonOkay = new CSDLCenterTextObject( "GameDefault", "Close", stBlueish, stWhite );

	int iWidth = m_pText->GetWidth();
	int iHeight = m_pText->GetHeight();

	SetPosX( (800 / 2) - (iWidth / 2) );
	SetPosY( (600 / 2) - ((iHeight + 10 + m_pButtonOkay->GetHeight()) / 2) );

	m_pText->SetPos( GetPosX(), GetPosY() );

	int iButtonTop = (m_iPosY + iHeight) + 10;
	if ( (iButtonTop + m_pButtonOkay->GetHeight()) > 600 )
		iButtonTop = 600 - m_pButtonOkay->GetHeight() - 5;

	m_pButtonOkay->SetPos( GetPosX() + iWidth / 2, iButtonTop );
	m_pButtonOkay->SetCallbackContainer( this );

	m_stContainerRect = m_pText->GetRect();
	m_stContainerRect.x -= 5;
	m_stContainerRect.y -= 5;
	m_stContainerRect.w += 10;
	m_stContainerRect.h = m_pButtonOkay->GetButtom() + 5 - m_stContainerRect.y;
}
Пример #8
0
CSDLStateHandler::CSDLStateHandler()
{
	DebugInfo( TypeCreate, "Creating state handler." );

	bNewLayerNextFrame = false;
	iDelayedPop = 0;
}
Пример #9
0
int Database::coutTables() throw()
{
	if(dbStatus != SQLITE_OK)
		throw DatabaseNotOpenException() << DebugInfo(TRACE(), DebugInfo::Error);

	DatabaseResult res;
	int tableCount = -1;

	try
	{
		res = exec("SELECT COUNT(name) FROM ("
			"SELECT name FROM sqlite_master "
			"WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' "
			"UNION ALL "
			"SELECT name FROM sqlite_temp_master "
			"WHERE type IN ('table','view') )");
		tableCount = res.getRowData().at(0).getColumnData().at(0).getIntData();

	} catch (...)
	{
		throw;
	}

	return tableCount;
}
Пример #10
0
CSDLStateLoading::~CSDLStateLoading()
{
	DebugInfo( TypeDelete, "Deleting loading screen." );

	if ( m_pLoadText != 0 )
		delete m_pLoadText;
}
Пример #11
0
////FUNCTIONS//////////////////
//-----------------------------------------------------------------------------
// Name: Main()
// Desc: Where all work is done
//-----------------------------------------------------------------------------
bool main()
{
	static int nFrames = 0;
	//static CVECTOR shipsVelVector(0.f,0.f,0.f);
	
	if(GetKeyStatus(VK_ESCAPE) == true)
		return(0);
	
	//Clear the surface
	if(!ClrS(lpddsSecondary,&wndRect))//can't be within a lock-Unlock block or u can't blt
		return(0);
	
	DynamicStarField(NULL,800,Sprites[0].physProp.VelVector,nFrames);
	//Sprites[0].DrawSprite(lpddsSecondary);
	MoveShip();
	
	if(bDebugMode)
		DebugInfo(nFrames);
	
	//Flip primary and secondary surfaces
	Flip();
	//Sleep(1000);
	fFrameTime = frameTimer.EndTimerAndRestart();
	nFrames++;
	return(1);
}
Пример #12
0
void Task::AddIntoProcesser(Processer *proc, char* shared_stack, uint32_t shared_stack_cap)
{
    assert(!proc_);
    proc_ = proc;
    if (-1 == getcontext(&ctx_)) {
        state_ = TaskState::fatal;
        fprintf(stderr, "task(%s) init, getcontext error:%s\n",
                DebugInfo(), strerror(errno));
        return ;
    }

    ctx_.uc_stack.ss_sp = shared_stack;
    ctx_.uc_stack.ss_size = shared_stack_cap;
    ctx_.uc_link = NULL;
    makecontext(&ctx_, (void(*)(void))&C_func, 1, this);

    // save coroutine stack first 16 bytes.
    assert(!stack_);
    stack_size_ = 16;
    stack_capacity_ = std::max<uint32_t>(16, g_Scheduler.GetOptions().init_stack_size);
    stack_ = (char*)malloc(stack_capacity_);
    memcpy(stack_, shared_stack + shared_stack_cap - stack_size_, stack_size_);

    state_ = TaskState::runnable;
}
Пример #13
0
CGameObject::CGameObject()
{
    DebugInfo( TypeCreate, "Creating game." );

    m_pImageHandler		= 0;
    m_pFontHandler		= 0;
    m_pLocationHandler	= 0;
}
Пример #14
0
void CFileHandler::DownloadFile( const string& sWikiFileName, const string& sSaveToFileName )
{
	CWebPage Webpage;
	if ( Webpage.DownloadWebPage( "http://www.gpwiki.org/index.php/Files:" + sWikiFileName ) == false )
	{
		DebugInfo( TypeError, 
			string( "Error occurred while trying to download web page.\nError: " + Webpage.GetError()).c_str() );
	}

	string sFileUrl = GetTaggedText( Webpage.GetContents(), "<a href=\"", "\"" );

	if ( sFileUrl.length() == 0 )
		DebugInfo( TypeError, "Error extracting the physical file URL." );

	sFileUrl = "http://www.gpwiki.org" + sFileUrl;
	
	Webpage.DownloadFile( sFileUrl, sSaveToFileName );
}
Пример #15
0
	static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr<Expression>& filter,
		const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
		const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
	{
		ApplyRule::AddRule(type, target, name, expression, filter, package, fkvar,
		    fvvar, fterm, debugInfo, EvaluateClosedVars(frame, closedVars));

		return Empty;
	}
Пример #16
0
CSDLBaseState::CSDLBaseState()
{
	DebugInfo( TypeCreate, "Creating base state." );
	m_iObjectsWithFocus = 0;
	m_pBackground = 0;
	m_pDescription = 0;

	m_iPosX = 100;
	m_iPosY = 190;
}
Пример #17
0
void Task::DecrementRef()
{
    DebugPrint(dbg_task, "task(%s) DecrementRef ref=%d",
            DebugInfo(), (int)ref_count_);
    if (--ref_count_ == 0) {
        std::unique_lock<LFLock> lock(s_delete_list_lock);
        assert(!this->prev);
        assert(!this->next);
        assert(!this->check_);
        s_delete_list.push_back(this);
    }
}
Пример #18
0
void SdlPlatform::Compile(Image *obj)
{
	bfs::create_directories(obj->GetOutputPath().parent_path());

	std::ostringstream cmd;
	cmd << PLATFORM_SDL_COPY_COMMAND << " \"" << obj->GetInputPath().string() << "\""; // directory_string
	cmd << " \"" << obj->GetOutputPath().string() << "\""; // directory_string
	cmd << " " << PLATFORM_SDL_COPY_OVERWRITE_PARAM;
	RUN_COMMAND(cmd);

	DebugInfo("IMAGE: %s\n", cmd.str().c_str());
}
Пример #19
0
bool Database::openDB(const char *filePath) throw()
{
	sqliteStatus = sqlite3_open_v2(filePath, &db,  SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, 0);
	if(sqliteStatus == SQLITE_ERROR)
	{
		sqlite3_close(db);
		throw DatabaseOpenFailedException() << DebugInfo(TRACE(), DebugInfo::Error);
		return false;
	}
	dbStatus = DBOk;
	return true;
}
Пример #20
0
CSDLBaseState::~CSDLBaseState()
{
	DebugInfo( TypeDelete, "Unloading base state." );

	if ( m_pDescription != 0 )
		delete m_pDescription;
	m_pDescription = 0;

	if ( m_pBackground != 0 )
		delete m_pBackground;
	m_pBackground = 0;
}
Пример #21
0
CSDLStateShowText::~CSDLStateShowText()
{
	DebugInfo( TypeDelete, "Deleting text box." );

	if ( m_pButtonOkay != 0 )
		delete m_pButtonOkay;
	m_pButtonOkay = 0;

	if ( m_sOnExitScript.length() > 0 ) {
		pEngine->GetLuaScriptHandler()->DoLuaScript( m_sOnExitScript );
	}
}
Пример #22
0
void CPlayer::AddGameMoney(INT64 nMoney)
{
	DebugInfo("AddGameMoney PID=%d GameMoney=%s AddMoney=%s",m_PID,N2S(m_nGameMoney).c_str(),N2S(nMoney).c_str());

	m_nGameMoney += nMoney;
	if ( m_nGameMoney < 0 )
	{
		DebugError("AddGameMoney PID=%-10d m_nGameMoney=%s nMoney=%s",m_PID,Tool::N2S(m_nGameMoney).c_str(),Tool::N2S(nMoney).c_str() );

		m_nGameMoney = 0;		
	}
}
Пример #23
0
bool CRecordSet::ThrowError(void)
{
	char sErrorMsg[1024];

	if(GetErrorMessage(sErrorMsg, sizeof(sErrorMsg)))
	{
		//MessageBox(GetActiveWindow(), sErrorMsg, "CRecordSet::Error", MB_ICONERROR);
		DebugInfo("CRecordSet::Error",99);
		return true;
	}

	return false;
}
Пример #24
0
void Task::AddIntoProcesser(Processer *proc, char* shared_stack, uint32_t shared_stack_cap)
{
    assert(!proc_);
    proc_ = proc;
    if (!ctx_.Init([this]{C_func(this);}, shared_stack, shared_stack_cap)) {
        state_ = TaskState::fatal;
        fprintf(stderr, "task(%s) init, getcontext error:%s\n",
                DebugInfo(), strerror(errno));
        return ;
    }

    state_ = TaskState::runnable;
}
Пример #25
0
void CPlayer::AttachSocket( GameServerSocket* pcs )
{
	DebugInfo("AttachSocket Start old_Socket=%d new_Socket=%d",reinterpret_cast<int>(m_pClientSocket),reinterpret_cast<int>(pcs) );

	if ( pcs == m_pClientSocket && pcs )
	{
		DebugError("AttachSocket 相同的SOCKET pcs=%d",reinterpret_cast<int>(pcs) );
	}

	m_KillTime = 0;
	m_SocketCloseTime = 0;	
	m_mapRoomTime.clear();

	if( this->m_pClientSocket )
	{
		Game_MsgFlag msgFlag;
		msgFlag.m_Flag = msgFlag.LAND_OTHER_PLACE;
		msgFlag.m_nValue = pcs->GetPeerLongIp();
		this->m_pClientSocket->SendMsg(msgFlag);

		this->m_pClientSocket->SetPlayer(NULL);
		this->m_pClientSocket->Stop(GetCurTime());
		//this->m_pClientSocket->Close();
		//this->m_pClientSocket = NULL;
	}

	if( pcs && pcs->GetConnect() )
	{
		m_pClientSocket = pcs;
		pcs->SetPlayer(this);		
	}
	else
	{
		DebugError("CPlayer::Attach");
		assert(0);
	}

	DebugInfo("AttachSocket End");
}
Пример #26
0
void CGameObject::LoadContents( CWikiContent& rRawContents, const string& sGamePage )
{
    m_sWikiSubpage = sGamePage;

    m_sAuthors = ReplaceInText( rRawContents.GetParameter( "Author: " ), "<br>", "\n" );
    m_sAgeRating = ReplaceInText( rRawContents.GetParameter( "Age Rating: " ), "<br>", "\n" );
    m_sStartLocation = rRawContents.GetParameter( "StartLocation: " );

    DebugInfo( TypeInfo, "Parsing game images data" );
    string sRawImageText = CWikiContent( rRawContents.GetTagText(), "Images" ).GetTagText();
    m_pImageHandler = new CImageHandler;
    m_pImageHandler->LoadContents( sRawImageText );

    DebugInfo( TypeInfo, "Parsing game fonts data" );
    string sRawFontText = CWikiContent( rRawContents.GetTagText(), "Fonts" ).GetTagText();
    m_pFontHandler = new CFileHandler;
    m_pFontHandler->LoadContents( sRawFontText );

    DebugInfo( TypeInfo, "Parsing game locations data" );
    string sRawLocationText = CWikiContent( rRawContents.GetTagText(), "Locations" ).GetTagText();
    m_pLocationHandler = new CLocationHandler;
    m_pLocationHandler->LoadContents( sRawLocationText, sGamePage );
}
Пример #27
0
CSDLStateLoading::CSDLStateLoading()
{
	DebugInfo( TypeCreate, "Creating loading screen." );

	m_iPosX = 400;
	m_iPosY = 250;

	m_pBackground = new CSDLBaseObject;
	m_pBackground->LoadImageFromFile( g_sAppDir + "\\Media\\WikiAdventure\\Loading.jpg" );

	m_pLoadText = new CSDLSizedQueueList;
	m_pLoadText->SetPos( m_iPosX, m_iPosY );
	m_pLoadText->AddObject( new CSDLCenterTextObject( "Default", "WikiAdventure is loading..." ) );
	m_pLoadText->AddObject( new CSDLCenterTextObject( "Default", "Please wait." ) );
}
Пример #28
0
 DebugRenderer::Job::DebugInfo DebugRenderer::Job::contribution(const Scene &scene, const WavelengthSamples &initWLs, const Ray &initRay,
                                                                IndependentLightPathSampler &pathSampler, ArenaAllocator &mem) const {
     Ray ray = initRay;
     SurfacePoint surfPt;
     
     DebugInfo ret;
     
     Intersection isect;
     if (!scene.intersect(ray, &isect))
         return DebugInfo();
     isect.getSurfacePoint(&surfPt);
     ret.surfPt = surfPt;
     
     return ret;
 }
Пример #29
0
CGameObject::~CGameObject()
{
    DebugInfo( TypeDelete, "Unloading game, clearing allocated resources." );

    if ( m_pLocationHandler != 0 )
        delete m_pLocationHandler;
    m_pLocationHandler = 0;

    if ( m_pFontHandler != 0 )
        delete m_pFontHandler;
    m_pFontHandler = 0;

    if ( m_pImageHandler != 0 )
        delete m_pImageHandler;
    m_pImageHandler = 0;
}
Пример #30
0
std::string AbstractExpression::Debug(const std::string &spacer) const {
  std::ostringstream buffer;
  buffer << spacer << "+ " << Debug() << "\n";

  std::string info_spacer = spacer + "   ";
  buffer << DebugInfo(info_spacer);

  // process children
  if (m_left != NULL || m_right != NULL) {
    buffer << info_spacer << "left:  "
           << (m_left != NULL ? "\n" + m_left->Debug(info_spacer) : "<NULL>\n");
    buffer << info_spacer
           << "right: " << (m_right != NULL ? "\n" + m_right->Debug(info_spacer)
                                            : "<NULL>\n");
  }
  return (buffer.str());
}