Changeset 5283

Show
Ignore:
Timestamp:
10/09/07 09:44:48 (6 years ago)
Author:
jgaeddert
Message:

fixing bug; flags/counters not set properly. Packetizer/depacketizer now works properly for situations with bit inversions

Location:
experimental/components/Packetizer/trunk/Packetizer-metadata
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • experimental/components/Packetizer/trunk/Packetizer-metadata/src/PacketizerDSP.cpp

    r5282 r5283  
    207207        if ( abs(rxy) > correlator_threshold ) { 
    208208            //printf("\nPN sync code found!!\n\n"); 
     209            invert_bits = ( rxy < 0 ) ? true : false; 
    209210            num_bits_read = i+1; 
    210211            num_control_codes_extracted = 0; 
     
    253254                ConfigurePacketType( (PacketType) new_packet_type ); 
    254255                num_bits_read = i+1; 
     256                num_subheader_bits_read = 0; 
    255257                return true; 
    256258            } 
  • experimental/components/Packetizer/trunk/Packetizer-metadata/tests/Depacketizer_testsuite.h

    r5281 r5283  
    4949    } 
    5050 
     51    // 
     52    // Basic test for creating and extracting a packet of type PACKET_RAW_400 
     53    //  
    5154    void test_ExtractPacketHeader_01() { 
    5255        // generate input buffer 
     
    125128    } 
    126129 
     130    // 
     131    // Test extracting a packet with bit inversion 
     132    //  
     133    void test_ExtractPacketHeader_02() { 
     134        // generate input buffer 
     135        char * input; 
     136        input = (char*) calloc( 400, sizeof(char) ); 
     137        input[0] = 1; 
     138        input[1] = 0; 
     139        input[2] = 1; 
     140 
     141        // generate packet buffer 
     142        char * packet; 
     143        packet = (char*) calloc( 1024, sizeof(char) ); 
     144        memset( packet, 0x01, 1024*sizeof(char) ); 
     145 
     146        // generate output buffer 
     147        char * output; 
     148        output = (char*) calloc( 1024, sizeof(char) ); 
     149        memset( output, 0x01, 1024*sizeof(char) ); 
     150 
     151        bool found_header; 
     152        bool packet_type_extracted; 
     153        bool packet_subheader_extracted; 
     154        bool packet_data_extracted; 
     155        unsigned int n; 
     156 
     157        // assemble packet 
     158        unsigned int packet_length(1024); 
     159        AssemblePacket( input, 400, packet, packet_length, PACKET_RAW_400 ); 
     160 
     161        // flip all the bits 
     162        for (unsigned int i=0; i<1024; i++) 
     163            packet[i] = 1-packet[i]; 
     164 
     165        // try to extract packet header 
     166        unsigned int N(0);                      // total bits read from input 
     167        found_header = ExtractPacketHeader( packet+N, 1024, n ); 
     168        N += n; 
     169        TS_ASSERT_EQUALS(found_header, true);       // should have found header 
     170        TS_ASSERT_EQUALS(n, PN_SYNC_CODE_LENGTH);   // should have only read 63 values 
     171        TS_ASSERT_EQUALS(rxy, -PN_SYNC_CODE_LENGTH);// correlator should be negative 
     172 
     173        // try to extract packet type 
     174        packet_type_extracted = ExtractPacketType( packet+N, 500, n ); 
     175        N += n; 
     176        TS_ASSERT_EQUALS(packet_type_extracted, true); 
     177        TS_ASSERT_EQUALS(n, NUM_CONTROL_CODES*PN_CONTROL_CODE_LENGTH);    // should have read control codes 
     178        TS_ASSERT_EQUALS( N, PN_SYNC_CODE_LENGTH + NUM_CONTROL_CODES*PN_CONTROL_CODE_LENGTH); 
     179 
     180        TS_ASSERT_EQUALS(new_packet_type, 0); 
     181 
     182        // try to extract the subheader 
     183        packet_subheader_extracted = ExtractPacketSubheader( packet+N, 500, n ); 
     184        N += n; 
     185        TS_ASSERT_EQUALS(packet_subheader_extracted, true); 
     186        TS_ASSERT_EQUALS(n, 21); 
     187        TS_ASSERT_EQUALS(N, 112); 
     188 
     189        // try to extract packet data 
     190        n = 1024; 
     191        packet_data_extracted = ExtractPacketData( packet+N, 400, output, n ); 
     192        N += n; 
     193        TS_ASSERT_EQUALS( packet_data_extracted, true ); 
     194        TS_ASSERT_EQUALS( n, 400 ); 
     195 
     196        // output data should be the same, even though the packet was decoded with bit inversions; 
     197        // the P/N sync correlator should have detected this and corrected for it appropriately 
     198        TS_ASSERT_SAME_DATA( input, output, 400 ); 
     199         
     200        free(input); 
     201        free(packet); 
     202        free(output); 
     203    } 
     204 
    127205}; 
    128206