Changeset 5183
- Timestamp:
- 10/03/07 14:10:35 (6 years ago)
- Location:
- experimental/components/Packetizer/trunk/Packetizer-metadata/src
- Files:
-
- 2 modified
-
binary_sequence.c (modified) (3 diffs)
-
binary_sequence.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
experimental/components/Packetizer/trunk/Packetizer-metadata/src/binary_sequence.c
r5182 r5183 22 22 #include "binary_sequence.h" 23 23 24 signed 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 24 43 binary_sequence_t * binary_sequence_create() 25 44 { … … 41 60 printf("ERROR! binary sequence already initialized!\n"); 42 61 43 // initialize length 62 // 63 bs->num_bits = num_bits; 64 65 // initialize array length 44 66 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 } 45 75 46 76 // initialze array with zeros … … 49 79 50 80 81 void 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 } 51 93 94 signed 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 34 34 typedef struct binary_sequence binary_sequence_t; 35 35 36 extern signed int c_bits[16]; 37 36 38 struct binary_sequence { 37 39 /// sequence array 38 40 UINT8 * s; 39 41 42 /// 43 unsigned int num_bits; 44 45 /// 46 UINT8 bit_mask_last_block; 47 40 48 /// length of array 41 49 unsigned int s_len; … … 46 54 void binary_sequence_initialize(binary_sequence_t * bs, unsigned int num_bits); 47 55 48 void binary_sequence_destroy(binary_sequence_t * s);56 void binary_sequence_destroy(binary_sequence_t * bs); 49 57 50 void binary_sequence_push( BIT b);58 void binary_sequence_push(binary_sequence_t * bs, BIT b); 51 59 52 signed int binary_sequence_correlate(binary_sequence_t * s1, binary_sequence_t *s2);60 signed int binary_sequence_correlate(binary_sequence_t * bs1, binary_sequence_t * bs2); 53 61 54 62 #endif