Esempio n. 1
0
	void OnTimeout()
	{
		PTimeInterval duration = PTime() - con->GetConnectionStartTime();
		int rest = duration.GetSeconds();
		int hour, min, sec;

		hour = rest / 3600; rest = rest % 3600;
		min = rest / 60; rest = rest % 60;
		sec = rest;

		char buf[9];
		if( hour )
			sprintf(buf, "%02d:%02d:%02d", hour, min, sec );
		else
			sprintf(buf, "%02d:%02d", min, sec );
		ancaInfo->set( CALL_DURATION, buf );
	}
Esempio n. 2
0
void CMyPhoneEndPoint::OnRTPStatistics(const H323Connection & connection,
									   const RTP_Session & session) const
{
	// Lock mutex
	if(!(((CMyPhoneEndPoint *)this)->m_StatLock.Lock(10))) return;
	// Reset statistic 
	m_stat.ibSent = m_stat.ibRcvd =0;
    // Getting Audio statistic part
	RTP_Session * asession = connection.GetSession(RTP_Session::DefaultAudioSessionID);
	if (asession != NULL)
	{
		int abSent=0, abRcvd=0;
		// If not sending or receiving Audio, memory read error happens.
		try{	abSent = asession->GetOctetsSent();	} catch(...) {abSent = 0;}
		try{	abRcvd = asession->GetOctetsReceived(); } catch(...) {abRcvd = 0;}
		m_stat.ibSent = abSent;
		m_stat.ibRcvd = abRcvd;
	}
	
	// Getting Video statistic part
	RTP_Session * vsession = connection.GetSession(RTP_Session::DefaultVideoSessionID);
	if (vsession != NULL)
	{
		int vbSent=0, vbRcvd=0;
		// If not sending or receiving Vidio 
		// mamory read error happends.
		try{	vbSent = vsession->GetOctetsSent();	} catch(...) {vbSent = 0;}
		try{	vbRcvd = vsession->GetOctetsReceived(); } catch(...) {vbRcvd = 0;}
		m_stat.ibSent += vbSent;
		m_stat.ibRcvd += vbRcvd;
	}
	
	m_stat.iDelay = connection.GetRoundTripDelay().GetInterval();
	
	m_stat.iSecs = (PTime() - connection.GetConnectionStartTime()).GetSeconds();
	//
	// Release mutex
	((CMyPhoneEndPoint *)this)->m_StatLock.Unlock();
}
Esempio n. 3
0
int Execute( int argc , char* argv[] )
{
    Reset< Real >();
    int i;
    int paramNum = sizeof(params)/sizeof(cmdLineReadable*);
    int commentNum=0;
    char **comments;

    comments = new char*[paramNum+7];
    for( i=0 ; i<paramNum+7 ; i++ ) comments[i] = new char[1024];

    if( Verbose.set ) echoStdout=1;

    XForm4x4< Real > xForm , iXForm;
    if( XForm.set )
    {
        FILE* fp = fopen( XForm.value , "r" );
        if( !fp )
        {
            fprintf( stderr , "[WARNING] Could not read x-form from: %s\n" , XForm.value );
            xForm = XForm4x4< Real >::Identity();
        }
        else
        {
            for( int i=0 ; i<4 ; i++ ) for( int j=0 ; j<4 ; j++ )
            {
                float f;
                fscanf( fp , " %f " , &f );
                xForm(i,j) = (Real)f;
            }
            fclose( fp );
        }
    }
    else xForm = XForm4x4< Real >::Identity();
    iXForm = xForm.inverse();

    DumpOutput2( comments[commentNum++] , "Running Screened Poisson Reconstruction (Version 6.13)\n" );
    char str[1024];
    for( int i=0 ; i<paramNum ; i++ )
        if( params[i]->set )
        {
            params[i]->writeValue( str );
            if( strlen( str ) ) DumpOutput2( comments[commentNum++] , "\t--%s %s\n" , params[i]->name , str );
            else                DumpOutput2( comments[commentNum++] , "\t--%s\n" , params[i]->name );
        }

    double t;
    double tt=PTime();
    Real isoValue = 0;

    Octree< Real > tree;
    tree.threads = Threads.value;
    if( !In.set )
    {
        ShowUsage(argv[0]);
        return 0;
    }
    if( !MaxSolveDepth.set ) MaxSolveDepth.value = Depth.value;

    OctNode< TreeNodeData >::SetAllocator( MEMORY_ALLOCATOR_BLOCK_SIZE );

    t=PTime();
    int kernelDepth = KernelDepth.set ?  KernelDepth.value : Depth.value-2;
    if( kernelDepth>Depth.value )
    {
        fprintf( stderr,"[ERROR] %s can't be greater than %s: %d <= %d\n" , KernelDepth.name , Depth.name , KernelDepth.value , Depth.value );
        return EXIT_FAILURE;
    }

    double maxMemoryUsage;
    t=PTime() , tree.maxMemoryUsage=0;
    typename Octree< Real >::PointInfo* pointInfo = new typename Octree< Real >::PointInfo();
    typename Octree< Real >::NormalInfo* normalInfo = new typename Octree< Real >::NormalInfo();
    std::vector< Real >* kernelDensityWeights = new std::vector< Real >();
    std::vector< Real >* centerWeights = new std::vector< Real >();
    PointStream< float >* pointStream;
    char* ext = GetFileExtension( In.value );
    if     ( !strcasecmp( ext , "bnpts" ) ) pointStream = new BinaryPointStream< float >( In.value );
    else if( !strcasecmp( ext , "ply"   ) ) pointStream = new    PLYPointStream< float >( In.value );
    else                                    pointStream = new  ASCIIPointStream< float >( In.value );
    delete[] ext;
    int pointCount = tree.template SetTree< float >( pointStream , MinDepth.value , Depth.value , FullDepth.value , kernelDepth , Real(SamplesPerNode.value) , Scale.value , Confidence.set , NormalWeights.set , PointWeight.value , AdaptiveExponent.value , *pointInfo , *normalInfo , *kernelDensityWeights , *centerWeights , BoundaryType.value , xForm , Complete.set );
    if( !Density.set ) delete kernelDensityWeights , kernelDensityWeights = NULL;

    DumpOutput2( comments[commentNum++] , "#             Tree set in: %9.1f (s), %9.1f (MB)\n" , PTime()-t , tree.maxMemoryUsage );
    DumpOutput( "Input Points: %d\n" , pointCount );
    DumpOutput( "Leaves/Nodes: %d/%d\n" , tree.tree.leaves() , tree.tree.nodes() );
    DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );

    maxMemoryUsage = tree.maxMemoryUsage;
    t=PTime() , tree.maxMemoryUsage=0;
    Pointer( Real ) constraints = tree.SetLaplacianConstraints( *normalInfo );
    delete normalInfo;
    DumpOutput2( comments[commentNum++] , "#      Constraints set in: %9.1f (s), %9.1f (MB)\n" , PTime()-t , tree.maxMemoryUsage );
    DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage())/(1<<20) );
    maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );

    t=PTime() , tree.maxMemoryUsage=0;
    Pointer( Real ) solution = tree.SolveSystem( *pointInfo , constraints , ShowResidual.set , Iters.value , MaxSolveDepth.value , CGDepth.value , CSSolverAccuracy.value );
    delete pointInfo;
    FreePointer( constraints );
    DumpOutput2( comments[commentNum++] , "# Linear system solved in: %9.1f (s), %9.1f (MB)\n" , PTime()-t , tree.maxMemoryUsage );
    DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );
    maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );

    CoredFileMeshData< Vertex > mesh;

    if( Verbose.set ) tree.maxMemoryUsage=0;
    t=PTime();
    isoValue = tree.GetIsoValue( solution , *centerWeights );
    delete centerWeights;
    DumpOutput( "Got average in: %f\n" , PTime()-t );
    DumpOutput( "Iso-Value: %e\n" , isoValue );

    if( VoxelGrid.set )
    {
        double t = PTime();
        FILE* fp = fopen( VoxelGrid.value , "wb" );
        if( !fp ) fprintf( stderr , "Failed to open voxel file for writing: %s\n" , VoxelGrid.value );
        else
        {
            int res;
            Pointer( Real ) values = tree.Evaluate( solution , res , isoValue , VoxelDepth.value );
            fwrite( &res , sizeof(int) , 1 , fp );
            if( sizeof(Real)==sizeof(float) ) fwrite( values , sizeof(float) , res*res*res , fp );
            else
            {
                float *fValues = new float[res*res*res];
                for( int i=0 ; i<res*res*res ; i++ ) fValues[i] = float( values[i] );
                fwrite( fValues , sizeof(float) , res*res*res , fp );
                delete[] fValues;
            }
            fclose( fp );
            DeletePointer( values );
        }
        DumpOutput( "Got voxel grid in: %f\n" , PTime()-t );
    }

    if( Out.set )
    {
        t = PTime() , tree.maxMemoryUsage = 0;
        tree.GetMCIsoSurface( kernelDensityWeights ? GetPointer( *kernelDensityWeights ) : NullPointer< Real >() , solution , isoValue , mesh , true , !NonManifold.set , PolygonMesh.set );
        if( PolygonMesh.set ) DumpOutput2( comments[commentNum++] , "#         Got polygons in: %9.1f (s), %9.1f (MB)\n" , PTime()-t , tree.maxMemoryUsage );
        else                  DumpOutput2( comments[commentNum++] , "#        Got triangles in: %9.1f (s), %9.1f (MB)\n" , PTime()-t , tree.maxMemoryUsage );
        maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );
        DumpOutput2( comments[commentNum++],"#             Total Solve: %9.1f (s), %9.1f (MB)\n" , PTime()-tt , maxMemoryUsage );

        if( NoComments.set )
        {
            if( ASCII.set ) PlyWritePolygons( Out.value , &mesh , PLY_ASCII         , NULL , 0 , iXForm );
            else            PlyWritePolygons( Out.value , &mesh , PLY_BINARY_NATIVE , NULL , 0 , iXForm );
        }
        else
        {
            if( ASCII.set ) PlyWritePolygons( Out.value , &mesh , PLY_ASCII         , comments , commentNum , iXForm );
            else            PlyWritePolygons( Out.value , &mesh , PLY_BINARY_NATIVE , comments , commentNum , iXForm );
        }
        DumpOutput( "Vertices / Polygons: %d / %d\n" , mesh.outOfCorePointCount()+mesh.inCorePoints.size() , mesh.polygonCount() );
    }
    FreePointer( solution );
    return 1;
}
Esempio n. 4
0
    {
        SIZE_T peakMemory = 1;
        peakMemory <<= 30;
        peakMemory *= MAX_MEMORY_GB;
        printf( "Limiting memory usage to %.2f GB\n" , float( peakMemory>>30 ) );
        HANDLE h = CreateJobObject( NULL , NULL );
        AssignProcessToJobObject( h , GetCurrentProcess() );

        JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
        jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_JOB_MEMORY;
        jeli.JobMemoryLimit = peakMemory;
        if( !SetInformationJobObject( h , JobObjectExtendedLimitInformation , &jeli , sizeof( jeli ) ) )
            fprintf( stderr , "Failed to set memory limit\n" );
    }
#endif // defined(WIN32) && defined(MAX_MEMORY_GB)
    double t = PTime();

    cmdLineParse( argc-1 , &argv[1] , sizeof(params)/sizeof(cmdLineReadable*) , params , 1 );
    if( Density.set )
        if( Double.set ) Execute< double , PlyValueVertex< float > >( argc , argv );
        else             Execute< float  , PlyValueVertex< float > >( argc , argv );
    else
        if( Double.set ) Execute< double , PlyVertex< float > >( argc , argv );
        else             Execute< float  , PlyVertex< float > >( argc , argv );
#ifdef _WIN32
    if( Performance.set )
    {
        HANDLE cur_thread=GetCurrentThread();
        FILETIME tcreat, texit, tkernel, tuser;
        if( GetThreadTimes( cur_thread , &tcreat , &texit , &tkernel , &tuser ) )
            printf( "Time (Wall/User/Kernel): %.2f / %.2f / %.2f\n" , PTime()-t , to_seconds( tuser ) , to_seconds( tkernel ) );
/** OnConnectionCleared callback function is called upon the dropping of an established
  * H323 connection. 
  */
void MyH323EndPoint::OnConnectionCleared(H323Connection & connection, const PString & clearedCallToken)
{
	PString remoteName = connection.GetRemotePartyName();

	switch (connection.GetCallEndReason()) {
		case H323Connection::EndedByCallForwarded:
			if (h323debug) {
				cout << "-- " << remoteName << " has forwarded the call" << endl;
			}
			break;
		case H323Connection::EndedByRemoteUser:
			if (h323debug) {
				cout << "-- " << remoteName << " has cleared the call" << endl;
			}
			break;
		case H323Connection::EndedByCallerAbort:
			if (h323debug) {
				cout << "-- " << remoteName << " has stopped calling" << endl;
			}
			break;
		case H323Connection::EndedByRefusal:
			if (h323debug) {
				cout << "-- " << remoteName << " did not accept your call" << endl;
			}
			break;
		case H323Connection::EndedByRemoteBusy:
			if (h323debug) {
				cout << "-- " << remoteName << " was busy" << endl;
			}
			break;
		case H323Connection::EndedByRemoteCongestion:
			if (h323debug) {
				cout << "-- Congested link to " << remoteName << endl;
			}
			break;
		case H323Connection::EndedByNoAnswer:
			if (h323debug) {
				cout << "-- " << remoteName << " did not answer your call" << endl;
			}
			break;
		case H323Connection::EndedByTransportFail:
			if (h323debug) {
				cout << "-- Call with " << remoteName << " ended abnormally" << endl;
			}
			break;
		case H323Connection::EndedByCapabilityExchange:
			if (h323debug) {
				cout << "-- Could not find common codec with " << remoteName << endl;
			}
			break;
		case H323Connection::EndedByNoAccept:
			if (h323debug) {
				cout << "-- Did not accept incoming call from " << remoteName << endl;
			}
			break;
		case H323Connection::EndedByAnswerDenied:
			if (h323debug) {
				cout << "-- Refused incoming call from " << remoteName << endl;
			}
			break;
		case H323Connection::EndedByNoUser:
			if (h323debug) {
				cout << "-- Remote endpoint could not find user: "******"-- Call to " << remoteName << " aborted, insufficient bandwidth." << endl;
			}
			break;
		case H323Connection::EndedByUnreachable:
			if (h323debug) {
				cout << "-- " << remoteName << " could not be reached." << endl;
			}
			break;
		case H323Connection::EndedByHostOffline:
			if (h323debug) {
				cout << "-- " << remoteName << " is not online." << endl;
			}
			break;
		case H323Connection::EndedByNoEndPoint:
			if (h323debug) {
				cout << "-- No phone running for " << remoteName << endl;
			}
			break;
		case H323Connection::EndedByConnectFail:
			if (h323debug) {
				cout << "-- Transport error calling " << remoteName << endl;
			}
			break;
		default:
			if (h323debug)
				cout << " -- Call with " << remoteName << " completed (" << connection.GetCallEndReason() << ")" << endl;

	}

	if (connection.IsEstablished()) {
		if (h323debug) {
			cout << "\t-- Call duration " << setprecision(0) << setw(5) << (PTime() - connection.GetConnectionStartTime()) << endl;
		}
	}	
	/* Invoke the PBX application registered callback */
	on_connection_cleared(connection.GetCallReference(), clearedCallToken);
	return;
}
Esempio n. 6
0
void ControllerThread::Main() {
    PTime tBase; // base time for tStep multiplier
    PTimeInterval tStep(1); // 1ms, loop step (1Hz); up to 14 bytes per step for 115200 serial line
    PTime tNow; // current time
    PTime tThen; // expected execution time
    unsigned short i = 0; // multiplier for tStep

    // initialize
    PTRACE(1, "Arduino initialization");
    char buffer[256];
    PINDEX iRead = 0;
    PINDEX len   = 0;
    // reset serial port
    pserial->ClearDTR();
    pserial->ClearRTS();
    pserial->ClearBreak();
    pserial->SetDTR();
    pserial->SetRTS();

    // drop junk from serial port
    do {
        if (shutdown.Wait(0)) {
            return;
        };
        pserial->Read(buffer, 256); // flush serial data
    } while (pserial->GetLastReadCount());
    memset(buffer, 0, 256);

    // waiting for 3 heat beat
    do {
        if (shutdown.Wait(0)) {
            return;
        };
        pserial->Read(buffer, 256);
        iRead = pserial->GetLastReadCount();
        if (iRead == 2 && buffer[0] == 0 && buffer[1] == 0) {
            len += iRead;
            PTRACE(1, "HeatBeat from Arduino #" << len/2);
        };
    } while(len < 6);
    PTRACE(1, "Arduino initialization done");
    fReady = PTrue;

    // reset Arduino
    pushAction(0xFF, CMD_RESET);
    pushAction(0xFF, CMD_SETBASE0); // X1
    pushAction(0xFF, calibrationTable[0]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE1); // Y1
    pushAction(0xFF, calibrationTable[1]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE2); // X2
    pushAction(0xFF, calibrationTable[2]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE3); // Y2
    pushAction(0xFF, calibrationTable[3]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE4); // LT
    pushAction(0xFF, calibrationTable[4]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE5); // RT
    pushAction(0xFF, calibrationTable[5]->GetAt(10000));
    pushAction(0xFF, CMD_RESET);
    // main loop
    do {
        bool fNewActions = false;
        BYTE naction;
        PInt32l value;
        /*
         * get x, y, button and other events
         */
        PTRACE(6, "Main\t" << dumpAction("actions before population: "));
        while(popAction(&naction, &value)) {
            PIntArray *actionQueue = actionQueuePool[naction];

            fNewActions = true;
            PTRACE(6, "Main\tadd new value to actionQueuePool[" << (int)naction << "] with queue size " << actionQueue->GetSize());
            actionQueue->SetAt(actionQueue->GetSize(), value);
        };
        if (fNewActions) {
            PTRACE(6, "Main\t" << dumpAction("actions after population: "));
            summarizeActions(); // summarize action events by type
            PTRACE(6, "Main\t" << dumpAction("actions after summarization: "));
        };
        /*
         * process actions:
         * send current state to arduino
         * then receive state from arduino
         * and update actions after sucsessful transmit
         */
        processActions();
        /*
         * wait next tStep ms
         */
        i++;
        tThen = tBase + tStep * i;
        tNow = PTime();
        // reset multiplier
        if (i >= 255) {
            i = 0;
            tBase = tThen;
        };
        // step was too long (tThen less than tNow)
        if (tNow.Compare(tThen) != LessThan) {
            PTRACE(6, "Main\tnow: " << tNow.AsString("h:m:s.uuuu") << " then: " << tThen.AsString("h:m:s.uuuu") << " i: " << (int)i << " diff: " << (tNow - tThen).GetMilliSeconds() << "ms");
            i += (tNow - tThen).GetMilliSeconds() / tStep.GetMilliSeconds() + 1; // number of steps + 1 step
            tThen = tBase + tStep * i;
            PTRACE(6, "Main\tcorrected then: " << tThen.AsString("h:m:s.uuuu") << " i: " << (int)i);
        };
        PTRACE(7, "Main\tstep " << (tThen - tNow).GetMilliSeconds() << "ms"); 
    } while(!shutdown.Wait((tThen - tNow).GetMilliSeconds()));
}
Esempio n. 7
0
/** OnConnectionCleared callback function is called upon the dropping of an established
  * H323 connection. 
  */
void MyH323EndPoint::OnConnectionCleared(H323Connection & connection, const PString & clearedCallToken)
{
	PString remoteName;
	call_details_t cd;
        PIPSocket::Address Ip;
	WORD sourcePort;

	remoteName = connection.GetRemotePartyName();

	cd.call_reference = connection.GetCallReference();
	cd.call_token = strdup((const char *)clearedCallToken);
	cd.call_source_aliases = strdup((const char *)connection.GetRemotePartyName());
	
  	connection.GetSignallingChannel()->GetRemoteAddress().GetIpAndPort(Ip, sourcePort);
	cd.sourceIp = strdup((const char *)Ip.AsString());
	
	/* Convert complex strings */
	char *s;
	if ((s = strchr(cd.call_source_aliases, ' ')) != NULL)
		*s = '\0';

	switch (connection.GetCallEndReason()) {
		case H323Connection::EndedByCallForwarded :
			if (h323debug)
				cout << " -- " << remoteName << " has forwarded the call" << endl;
			break;
		case H323Connection::EndedByRemoteUser :
			if (h323debug)
				cout << " -- " << remoteName << " has cleared the call" << endl;
			break;
		case H323Connection::EndedByCallerAbort :
			if (h323debug)
				cout << " -- " << remoteName << " has stopped calling" << endl;
			break;
		case H323Connection::EndedByRefusal :
			if (h323debug)
				cout << " -- " << remoteName << " did not accept your call" << endl;
			break;
		case H323Connection::EndedByRemoteBusy :
			if (h323debug)
			cout << " -- " << remoteName << " was busy" << endl;
			break;
		case H323Connection::EndedByRemoteCongestion :
			if (h323debug)
				cout << " -- Congested link to " << remoteName << endl;
			break;
		case H323Connection::EndedByNoAnswer :
			if (h323debug)
				cout << " -- " << remoteName << " did not answer your call" << endl;
			break;
		case H323Connection::EndedByTransportFail :
			if (h323debug)
				cout << " -- Call with " << remoteName << " ended abnormally" << endl;
			break;
		case H323Connection::EndedByCapabilityExchange :
			if (h323debug)
				cout << " -- Could not find common codec with " << remoteName << endl;
			break;
		case H323Connection::EndedByNoAccept :
			if (h323debug)
				cout << " -- Did not accept incoming call from " << remoteName << endl;
			break;
		case H323Connection::EndedByAnswerDenied :
			if (h323debug)
				cout << " -- Refused incoming call from " << remoteName << endl;
			break;
		case H323Connection::EndedByNoUser :
			if (h323debug)
				cout << " -- Remote endpoint could not find user: "******" -- Call to " << remoteName << " aborted, insufficient bandwidth." << endl;
			break;
		case H323Connection::EndedByUnreachable :
			if (h323debug)
				cout << " -- " << remoteName << " could not be reached." << endl;
			break;
		case H323Connection::EndedByHostOffline :
			if (h323debug)
				cout << " -- " << remoteName << " is not online." << endl;
			break;
		case H323Connection::EndedByNoEndPoint :
			if (h323debug)
				cout << " -- No phone running for " << remoteName << endl;
			break;
		case H323Connection::EndedByConnectFail :
			if (h323debug)
				cout << " -- Transport error calling " << remoteName << endl;
			break;
		default :
			if (h323debug)
				cout << " -- Call with " << remoteName << " completed (" << connection.GetCallEndReason() << ")" << endl;

	}

	if(connection.IsEstablished()) 
		if (h323debug)
			cout << "	 -- Call duration " << setprecision(0) << setw(5) << (PTime() - connection.GetConnectionStartTime()) << endl;

	/* Invoke the PBX application registered callback */
	on_connection_cleared(cd);

	return;
}