Changeset 5183

Show
Ignore:
Timestamp:
10/03/07 14:10:35 (6 years ago)
Author:
jgaeddert
Message:

adding functionality to binary sequence

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

Legend:

Unmodified
Added
Removed
  • experimental/components/Packetizer/trunk/Packetizer-metadata/src/binary_sequence.c

    r5182 r5183  
    2222#include "binary_sequence.h" 
    2323 
     24signed int c_bits[16] = { 
     25    -4, // 0000 
     26    -2, // 0001 
     27    -2, // 0010 
     28     0, // 0011 
     29    -2, // 0100 
     30     0, // 0101 
     31     0, // 0110 
     32     2, // 0111 
     33    -2, // 1000 
     34     0, // 1001 
     35     0, // 1010 
     36     2, // 1011 
     37     0, // 1100 
     38     2, // 1101 
     39     2, // 1110 
     40     4  // 1111 
     41}; 
     42 
    2443binary_sequence_t * binary_sequence_create() 
    2544{ 
     
    4160        printf("ERROR! binary sequence already initialized!\n"); 
    4261 
    43     // initialize length 
     62    // 
     63    bs->num_bits = num_bits; 
     64     
     65    // initialize array length 
    4466    bs->s_len = num_bits / 8; 
     67 
     68    // initialize bit mask 
     69    bs->bit_mask_last_block = 0x00; 
     70    unsigned int i; 
     71    for (i=0; i<(num_bits % 8); i++) { 
     72        bs->bit_mask_last_block <<=1; 
     73        bs->bit_mask_last_block &= 0x01; 
     74    } 
    4575 
    4676    // initialze array with zeros 
     
    4979 
    5080 
     81void binary_sequence_push(binary_sequence_t * bs, BIT b) 
     82{ 
     83    // 
     84    BIT overflow; 
     85    int i; 
     86     
     87    for (i=bs->s_len; i>0; i--) { 
     88        overflow = ( (bs->s)[i] & 0x00f0 ) == 0 ? 0 : 1; 
     89        (bs->s)[i] <<= 1; 
     90        (bs->s)[i] |= overflow; 
     91    } 
     92} 
    5193 
     94signed int binary_sequence_correlate(binary_sequence_t * bs1, binary_sequence_t * bs2) 
     95{ 
     96    signed int rxy = 0; 
     97    unsigned int i; 
     98     
     99    if ( bs1->s_len != bs2->s_len ) { 
     100        printf("ERROR! binary_sequence_correlate(): binary sequences must be the same length!\n"); 
     101        // throw error 
     102    } 
     103    unsigned int c_bits_index; 
     104    for (i=0; i<(bs1->s_len); i++) { 
     105        // 
     106        c_bits_index = (bs1->s)[i] & (bs2->s)[i]; 
     107        if ( i == bs1->s_len ) 
     108            c_bits_index &= bs1->bit_mask_last_block; 
     109        rxy += c_bits[c_bits_index]; 
     110    } 
     111     
     112    return rxy; 
     113} 
     114 
     115 
  • experimental/components/Packetizer/trunk/Packetizer-metadata/src/binary_sequence.h

    r5182 r5183  
    3434typedef struct binary_sequence binary_sequence_t; 
    3535 
     36extern signed int c_bits[16]; 
     37 
    3638struct binary_sequence { 
    3739    /// sequence array 
    3840    UINT8 * s; 
    39  
     41     
     42    /// 
     43    unsigned int num_bits; 
     44     
     45    /// 
     46    UINT8 bit_mask_last_block; 
     47     
    4048    /// length of array 
    4149    unsigned int s_len; 
     
    4654void binary_sequence_initialize(binary_sequence_t * bs, unsigned int num_bits); 
    4755 
    48 void binary_sequence_destroy(binary_sequence_t * s); 
     56void binary_sequence_destroy(binary_sequence_t * bs); 
    4957 
    50 void binary_sequence_push(BIT b); 
     58void binary_sequence_push(binary_sequence_t * bs, BIT b); 
    5159 
    52 signed int binary_sequence_correlate(binary_sequence_t * s1, binary_sequence_t * s2); 
     60signed int binary_sequence_correlate(binary_sequence_t * bs1, binary_sequence_t * bs2); 
    5361 
    5462#endif