示例#1
0
// Transmits an entire frame of imagery to the client
int sendFullFrame(SOCKET &clientSocket) {
	int status = 0;
	FIBITMAP *fiImage;
	FIMEMORY *fiBuffer;

	// Signal that a new frame is required and wait for frame
	InterlockedExchange( &g_lRequestFlag, TRUE );
	g_pRequestEvent->waitFor();
	
	// Enter critical section for frame buffer from UT2004
	// and copy new raw image to local buffer
	EnterCriticalSection( &g_CriticalSection );
	{
		fiImage = FreeImage_ConvertTo24Bits(g_fiImage);
	} 
	LeaveCriticalSection( &g_CriticalSection );

	// Create memory reference
	fiBuffer = FreeImage_OpenMemory();

	// Convert a raw frame to a useful image
	status = writeFrame( fiBuffer, fiImage, g_iImageType );
	if (status != 1) status = 0; // TODO: handle error here
	
	// Transmit frame over socket
	status = transmitFrame( fiBuffer, clientSocket, g_iImageType );

	// Delete memory references
	FreeImage_Unload( fiImage );
	FreeImage_CloseMemory( fiBuffer );

	return status;
}
示例#2
0
//--------------------------------------------------------------
void GenericClientManager::update() {

    //check for serverMessages
    if (useServer) {
        this->checkServerMessages();
    }

    if (this->newFps!=this->appFps) {
        this->appFps=this->newFps;
        ofSetFrameRate(this->appFps);
    }

    this->specific->update();

    if (transmitEnabled && useServer) {
        transmitFrame();
    }

}
示例#3
0
文件: mac.c 项目: kapaA/OpenSensor
/*==============================================================================
** Function...: channelAccess
** Return.....: GLOB_RET
** Description: dataLink
** Created....: 24.08.2012 by Achuthan
** Modified...: dd.mm.yyyy by nn
==============================================================================*/
GLOB_RET channelAccess(frame tempFrame, unsigned char retCode)
{
    GLOB_RET ret = GLOB_FAILURE;

    switch (retCode)
    {
        //Wait DIFS period, if there is CD then freez the coutner
        case WAIT_DIFS:
            START_DIFS_TIMER;
            ret = DATA_LINK_DIFS_WAIT_OK;
            while(difsTimer<DIFS)
            {
                if(CD)
                {
                    while(CD)
                    {
                        //copyPacketIBtoKB();
                    } //
                    START_DIFS_TIMER;
                }
            }
            break;

        case PERFORM_BACKOFF:
            if(backOff())
            {
                //if CD then return:
                return DATA_LINK_CARRIER_DETECTED;
            }
            else
            {
                 //else no CD then do the transmit 
                ret = DATA_LINK_BACKOFF_OK;
            }
            break;

        case SEND_PAY:
            // if it is NC we set the NC flag
            if(tempFrame.payload.isncHeader.codedPacket == CODING)
            {
                tempFrame.type = NC_PAY;    
            }
            // else we set the normal flag
            else
            {
                tempFrame.type = PAY;
            }
            // signal the Driver to clock in and tx the payload
            tempFrame.payload.isncHeader.optimalCWmin_A = Log.nodeCWminUpdate_A;
            tempFrame.payload.isncHeader.optimalCWmin_B = Log.nodeCWminUpdate_B;

            Log.avrCWmin_R2A = Log.avrCWmin_R2A + Log.nodeCWminUpdate_A;
            Log.avrCWmin_R2B = Log.avrCWmin_R2B + Log.nodeCWminUpdate_B;

            ret = transmitFrame(tempFrame, PACKET_SIZE);
            
            break;

        case WAIT_FOR_ACK:
            START_ACK_TIMER;
            //Block untill ACK is received or timeout
            while( ackTimer < ACK_TIMEOUT && gotACK == NO );
            // ACK received
            if(gotACK)
            {
                ret = DATA_LINK_GOT_ACK;
                 Log.ackRcv_cnt++;
            }
            else
            {
                ret = DATA_LINK_ACK_TIMEOUT;
            }
            break;

        default:
            ret = GLOB_ERROR_INVALID_PARAM;
            break;
    }
    return ret;
}