예제 #1
0
파일: fft_test.cpp 프로젝트: JiriVit/aec
/** Writes FFT output into a text file. */
static void fft_write_output(void)
{
	DEBUG_FILE *df;
	int i;

	df = debug_fopen("fft_out.txt", "wt");
	for (i = 0; i < FFT_SIZE; i++)
		debug_fprintf(df, "%f\n", fft_out[i]);
	debug_fclose(df);
}
예제 #2
0
static int create_output_fifos(int packet_id)
{
    int i,j;
    int ret;
    char output_file_name[CHANNEL_FILE_NAME_SIZE];

    //open a fifo for each channel and pol
    for(i=0; i<CHANNELS_PER_PACKET; i++)
    {
        for(j=0; j<2; j++)
        {
            snprintf(output_file_name,CHANNEL_FILE_NAME_SIZE, CHANNEL_FILE_BASE, i+packet_id*CHANNELS_PER_PACKET, j);
            debug_fprintf(stderr, "Creating fifo %s\n",output_file_name);
            ret = mkfifo(output_file_name,0666);
            if(ret == -1)
            {
                if(errno == EEXIST)
                {
                    debug_fprintf(stderr, "File already exists. Will attempt to open.\n");
                }
                else
                {
                    perror("Error creating fifo");
                    return -1;
                }
            }
            if(pasp_channel_enable[i+packet_id*CHANNELS_PER_PACKET][j])
            {
                //open the fifo
                debug_fprintf(stderr, "Opening fifo\n");
                channeldata_fifo[i][j] = open(output_file_name, O_WRONLY);
                if(channeldata_fifo[i][j] == -1)
                {
                    perror("Error opening fifo");
                    return -1;
                }
            }
        }
    }
    return 0;
}
예제 #3
0
static void cleanup(int signal)
{
    debug_fprintf(stderr, "Ctrl-C received... cleaning up\n");
    run_fifo_read = 0;
}
예제 #4
0
int main(int argc, char *argv[])
{
    // input fifo file info
    int input_fifo;
    int ret;

    // buffer for the next packet
    pasp_packet *nextpacket = malloc(PACKET_SIZE_BYTES);
    int numbytes=0;
    struct sigaction newact;
    int numpackets=0;
    long long totalbytes=0;
    long long packet_index;
    long long packet_id;

    pasp_channel_enable[8][0]=1;
    pasp_channel_enable[8][1]=1;

    //set up the signal handler
    newact.sa_handler = cleanup;
    sigemptyset(&newact.sa_mask);
    newact.sa_flags = 0;

    //start listening for Ctrl-C
    sigaction(SIGINT, &newact, NULL);

    // open the fifo with raw udp data
    debug_fprintf(stderr, "Opening fifo %s\n", RAW_UDP_FILE_NAME);
    input_fifo = open(RAW_UDP_FILE_NAME,O_RDONLY);

    //read a packet so we can open the appropriate channel buffers
    numbytes = read(input_fifo, (void *) nextpacket, PACKET_SIZE_BYTES);
    if(numbytes==-1 && run_fifo_read==1)
    {
        perror("Error reading from fifo");
        exit(0);
    }
    packet_index = ntohll(nextpacket->seq_no);
    packet_id = ntohll(nextpacket->id_no);

    ret = create_output_fifos(packet_id);
    // if something went wrong when we tried to create the fifos quit
    if(ret==-1)
    {
        exit(0);
    }


    debug_fprintf(stderr, "Waiting for data\n");
    while(run_fifo_read==1)
    {
        // read packet from fifo
        numbytes = read(input_fifo, (void *) nextpacket, PACKET_SIZE_BYTES);
        if(numbytes==-1 && run_fifo_read==1)
        {
            perror("Error reading from fifo");
            exit(0);
        }

        // process packet
        if(run_fifo_read==1 && numbytes!=0)
        {
            numpackets++;
            totalbytes+=numbytes;

            process_packet(nextpacket);
        }
    }

    debug_fprintf(stderr, "Received %d packets, %lld bytes\n", numpackets, totalbytes);
    debug_fprintf(stderr, "Closing fifo\n");
    close(input_fifo);
    free(nextpacket);
    return 0;
}
예제 #5
0
int hooked_open(const char *pathname, int flags, ...) {
    mode_t mode;
    int m = 0;
    int o;
    va_list ap;

    va_start( ap, flags );
    switch( sizeof( mode_t ) ) {
    case 1:
        mode = va_arg(ap, int);
        break;
    case 2:
        mode = va_arg(ap, int);
        break;
    case 4:
        mode = va_arg(ap, long);
        break;
    case 8:
        mode = va_arg(ap, long long);
        break;
    default:
        /* fatal error */
        errno = EOVERFLOW;
        return -1;
    }
    m = 1;
    va_end( ap );

    if( 1 == m ) {
        fprintf( stderr, "->  Intercepted three-arg open('%s', %d, %ju)", pathname, flags, CONVERT_TO_MAX(mode_t, mode) );
    } else {
        fprintf( stderr, "->  Intercepted two-arg open('%s', %d)", pathname, flags );
    }

    if( flags & O_CREAT ) {
#if DEBUG
        fprintf( stderr, ".\n--> File '%s' will be created\n", pathname );
#endif
    } else if( flags & ( O_CREAT | O_EXCL ) ) {
#if DEBUG
        fprintf( stderr, ".\n--> File '%s' will be created if it doesn't exist\n", pathname );
#endif
    } else {
        if( ( o = open_implementation( pathname, O_NONBLOCK | O_EVTONLY ) ) >= 0 ) {
            close( o );
#if DEBUG
            fprintf( stderr, ".\n--> File '%s' exists (%d)\n", pathname, o );
            fprintf( stderr, "--> open()" );
#endif
        } else {
            char *newpath;

            fprintf( stderr, ".\n--> File '%s' does not exist\n", pathname );

            if( capitalisepath( pathname, &newpath ) >= 0 ) {
                // debug_fprintf( stderr, "--> %s\n", "Got back" ); // must have >=3 args
                debug_fprintf( stderr, "--> Corrected path is '%s'\n", newpath );
                if( ( o = open_implementation( newpath, O_NONBLOCK | O_EVTONLY ) ) >= 0 ) {
                    close( o );
                    fprintf( stderr, "--> Corrected file '%s' exists\n", newpath );
                    pathname = newpath;
                } else {
                    fprintf( stderr, "--> Corrected file '%s' does not exist\n", newpath );
                }
            }
            fprintf( stderr, "--> open()" );
        }
    }

    if( 1 == m ) {
        o = open_implementation( pathname, flags, mode );
    } else {
        o = open_implementation( pathname, flags );
    }
    if( o >= 0 ) {
        fprintf( stderr, ": %d\n", o );
    } else {
        fprintf( stderr, ": %s\n", strerror( errno ) );
    }

    return o;
} // hooked_open
예제 #6
0
int capitalisepath(const char *string, char **result) {
    unsigned char lastchar = 0;
    unsigned long len;

    debug_fprintf( stderr, "capitalisepath starting with '%s'\n", string );

    /* strlen(string) should be less than PATH_MAX, but this isn't enforced
     * anywhere...
     */
    errno = 0;
    if(( *result = (char *)malloc( strlen( string ) + 1 ) )) {
        /* We can assume that the path won't be longer than 4 thousand million
         * characters... ?
         */
        unsigned int max;
        for( max = strlen( string ) - 1 ; max > 0 ; --max ) {
            unsigned char c = string[ max ];

            debug_fprintf( stderr, "capitalisepath read char %c\n", c );

            if( c == '/' )
                break;
        }

        debug_fprintf( stderr, "capitalisepath last separator is at %d\n", max );

        for( unsigned int n = 0 ; n < max ; n++ ) {
            unsigned char c = string[ n ];

            debug_fprintf( stderr, "capitalisepath read char %c\n", c );

            if( 0 == c )
                break;
            if( 0 == n ) {
                lastchar = c;
                if( lastchar != '/' )
                    (*result)[ n ] = toupper( c );
                else
                    (*result)[ n ] = c;
            } else {
                if( lastchar == '/' || lastchar == ' ' )
                    (*result)[ n ] = toupper( c );
                else
                    (*result)[ n ] = c;
                lastchar = c;

                debug_fprintf( stderr, "capitalisepath using char %c\n", (*result)[ n ] );
            }

            debug_fprintf( stderr, "capitalisepath lastchar is %c\n", lastchar );
        }
        for( ; max < strlen( string ) ; max++ ) {
            unsigned char c = string[ max ];
            (*result)[ max ] = c;

            debug_fprintf( stderr, "capitalisepath appending char %c\n", c );
        }
        (*result)[ strlen( string ) ] = '\0';

        debug_fprintf( stderr, "capitalisepath string is %s\n", *result );

        len = strlen( *result );

        debug_fprintf( stderr, "capitalisepath returning %lu\n", len );

        if( len > INT_MAX ) {
            return 0;
        } else {
            return (int)len;
        }
    } else {
        debug_fprintf( stderr, "capitalisepath malloc failed with error %d: %s\n", errno, strerror( errno ) );

        if( 0 == errno )
            errno = ENOMEM;
    }

    return -1;
}  // capitalisepath