예제 #1
0
파일: ext_qnx_svr.c 프로젝트: kyak/qnx_ert
/* Function: GetPkt ============================================================
 * Abstract:
 *  Receive nBytes from the host.  Return a buffer containing the bytes or
 *  NULL if an error occurs.  Note that the pointer returned is that of the
 *  global pktBuf.  If the buf needs to be grown to accommodate the package,
 *  it is realloc'd.  This function will try to get the requested number
 *  of bytes indefinitely - it is assumed that the data is either already there,
 *  or will show up in a "reasonable" amount of time.
 */
PRIVATE const char *GetPkt(const int pktSize)
{
    int_T     nGot;
    boolean_T error     = EXT_NO_ERROR;
    int_T     nGotTotal = 0;

    error = GrowRecvBufIfNeeded(pktSize);
    if (error != EXT_NO_ERROR) {
        fprintf(stderr,"Previous pkt from host thrown away due to lack of memory.\n");
        ClearPkt(pktSize);
        goto EXIT_POINT;
    }
    
    /* Get the data. */
    while(nGotTotal < pktSize) {
        error = ExtGetHostPkt(extUD,
            pktSize - nGotTotal, &nGot, (char_T *)(pktBuf + nGotTotal));
        if (error) {
	    fprintf(stderr,"ExtGetHostPkt() failed.\n");
            goto EXIT_POINT;
	}

	nGotTotal += nGot;
    }

EXIT_POINT:
    return((error == EXT_NO_ERROR) ? pktBuf : NULL);
} /* end GetPkt */
/* Function: GetPkt ============================================================
 * Abstract:
 *  Receive nBytes from the host.  Return a buffer containing the bytes or
 *  NULL if an error occurs.  Note that the pointer returned is that of the
 *  global pktBuf.  If the buf needs to be grown to accommodate the package,
 *  it is realloc'd.  This function will try to get the requested number
 *  of bytes indefinitely - it is assumed that the data is either already there,
 *  or will show up in a "reasonable" amount of time.
 */
PRIVATE const char *GetPkt(const int pktSize)
{
    int_T     nGot;
    boolean_T error     = EXT_NO_ERROR;
    int_T     nGotTotal = 0; 
	int AR_Drone_EXT_Time_Out = 0;
	
    error = GrowRecvBufIfNeeded(pktSize);
   
    if (error != EXT_NO_ERROR) {
#ifndef EXTMODE_DISABLEPRINTF            
        fprintf(stderr,"Previous pkt from host thrown away due to lack of memory.\n");
#endif
        ClearPkt(pktSize);
        goto EXIT_POINT;
    }
	
    //usleep(AR_DRONE_GET_PKT_DELAY); //375000L
    printf("Updating parameters! \n");
    //usleep(AR_DRONE_GET_PKT_DELAY); //375000L
    /* Get/ the data. */
    while(nGotTotal < pktSize) {
	    AR_Drone_EXT_Time_Out++;
		
        error = ExtGetHostPkt(extUD,
            pktSize - nGotTotal, &nGot, (char_T *)(pktBuf + nGotTotal));
			
        if (error) {
#ifndef EXTMODE_DISABLEPRINTF                
	    fprintf(stderr,"ExtGetHostPkt() failed.\n");
#endif
            goto EXIT_POINT;
		}

		nGotTotal += nGot;
		if (AR_Drone_EXT_Time_Out>10)
		{
			printf("Failed to get host packets after 100 ticks \n");
			return (NULL);
		}
	printf("pktSize value is : %d \n", pktSize);
	usleep(AR_DRONE_GET_PKT_DELAY); //375000L
    }

EXIT_POINT:
    return((error == EXT_NO_ERROR) ? pktBuf : NULL);
} /* end GetPkt */