Skip to content

Commit

Permalink
Tab -> 2 Space conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
szabolor committed Aug 20, 2016
1 parent 0004961 commit 4d7cb63
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 164 deletions.
76 changes: 38 additions & 38 deletions smog_uplink_packet/uplink_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,64 +129,64 @@ void decode_data(uint8_t *encoded, uint8_t *data, int *error_count, int *fatal)
memset(data, 0, MSG_LEN);

for (word_idx = 0, data_idx = 0; word_idx < WORD_COUNT; ++word_idx) {
current_word = 0;
current_word = 0;

// Deinterleave
for (bit_idx = 0; bit_idx < 24; ++bit_idx) {
if (encoded[bit_counter >> 3] & ( 1 << (bit_counter & 7) ) ) {
current_word |= ( 1 << bit_idx );
} // it's already zero, so don't handle that!
// Deinterleave
for (bit_idx = 0; bit_idx < 24; ++bit_idx) {
if (encoded[bit_counter >> 3] & ( 1 << (bit_counter & 7) ) ) {
current_word |= ( 1 << bit_idx );
} // it's already zero, so don't handle that!

bit_counter += INTERLEAVER_STEP_SIZE;
if (bit_counter >= INTERLEAVER_SIZE) {
bit_counter -= (INTERLEAVER_SIZE - 1);
}
}
bit_counter += INTERLEAVER_STEP_SIZE;
if (bit_counter >= INTERLEAVER_SIZE) {
bit_counter -= (INTERLEAVER_SIZE - 1);
}
}


// Decoding
errs = correct_errors(&current_word);
// Decoding
errs = correct_errors(&current_word);
#if (DEBUG > 1)
printf("[dec] %06x\n", current_word);
printf("[dec] %06x\n", current_word);
#endif
if (errs > 3)
if (errs > 3)
*fatal = 1;
*error_count += errs;

// Deinterleaving 12 bits to 8 bits (bytes)

if (word_idx & 1) { // Odd words
data[data_idx++] |= (current_word >> 4) & 0xf0;
data[data_idx++] = current_word & 0xff;
} else { // Even words
// 0xff is not needed, just in case
data[data_idx] = (current_word >> 4) & 0xff;
data[++data_idx] = current_word & 0x0f;
}
if (word_idx & 1) { // Odd words
data[data_idx++] |= (current_word >> 4) & 0xf0;
data[data_idx++] = current_word & 0xff;
} else { // Even words
// 0xff is not needed, just in case
data[data_idx] = (current_word >> 4) & 0xff;
data[++data_idx] = current_word & 0x0f;
}
}
}

#ifdef TEST_DECODE
int main() {
uint8_t data[MSG_LEN];
uint8_t encoded[ENC_LEN] = {0x0d,0x00,0x80,0x00,0x00,0x1c,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x14,0x00,0x80,0x01,0x00,0x28,0x00,0x00,0x00,0x00,0xc0,0x01,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uint8_t data[MSG_LEN];
uint8_t encoded[ENC_LEN] = {0x0d,0x00,0x80,0x00,0x00,0x1c,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x14,0x00,0x80,0x01,0x00,0x28,0x00,0x00,0x00,0x00,0xc0,0x01,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

int i;
int error_count, fatal;
int i;
int error_count, fatal;

decode_data(encoded, data, &error_count, &fatal);
decode_data(encoded, data, &error_count, &fatal);

for (i = 0; i < MSG_LEN; ++i) {
printf("%02x ('%c') ", data[i], data[i]);
if ((i & 0xf) == 0xf) {
printf("\n");
}
}
for (i = 0; i < MSG_LEN; ++i) {
printf("%02x ('%c') ", data[i], data[i]);
if ((i & 0xf) == 0xf) {
printf("\n");
}
}

if ((i & 0xf) == 0xf) {
printf("\n");
}
if ((i & 0xf) == 0xf) {
printf("\n");
}

return 0;
return 0;
}
#endif // TEST_DECODE
96 changes: 48 additions & 48 deletions smog_uplink_packet/uplink_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,64 +59,64 @@ void encode_data(uint8_t data[MSG_LEN], uint8_t encoded[ENC_LEN]) {
// 0 1

for (word_idx = 0, data_idx = 0; word_idx < WORD_COUNT; ++word_idx) {
current_word = 0;
if (word_idx & 1) { // Odd words
// Current word := (In[data_idx] & 0xf0) << 4 | In[data_idx+1]
current_word = (((uint32_t) data[data_idx] & 0xf0) << 4) | ((uint32_t) data[data_idx+1]);
data_idx += 2;
} else { // Even words
// Current word := In[data_idx] << 4 | In[data_idx+1] & 0x0f
current_word = ((uint32_t) data[data_idx] << 4) | ((uint32_t) data[data_idx+1] & 0x0f);
++data_idx;
}

// Encode assembled 12 bit width data into Golay(24, 12) codeword!
current_word = encode_word(current_word);
current_word = 0;
if (word_idx & 1) { // Odd words
// Current word := (In[data_idx] & 0xf0) << 4 | In[data_idx+1]
current_word = (((uint32_t) data[data_idx] & 0xf0) << 4) | ((uint32_t) data[data_idx+1]);
data_idx += 2;
} else { // Even words
// Current word := In[data_idx] << 4 | In[data_idx+1] & 0x0f
current_word = ((uint32_t) data[data_idx] << 4) | ((uint32_t) data[data_idx+1] & 0x0f);
++data_idx;
}

// Encode assembled 12 bit width data into Golay(24, 12) codeword!
current_word = encode_word(current_word);
#if (DEBUG > 0)
printf("[enc] %06x\n", current_word);
printf("[enc] %06x\n", current_word);
#endif
// Inlined interleaving:
// The interleaver forms a 24 row by 21 column matrix.
// It fills in the 21 encoded data word in the columns
// and reads out by the rows
// TODO: can be unrolled, but the whole encoding has a very low
// performance impact (0.01ms or 1ms is the same for this problem)
for (bit_idx = 0; bit_idx < 24; ++bit_idx) {
// interleave strating with LSB bit
if ( current_word & ( 1 << bit_idx ) ) {
// interleaved bit position is starting from LSB
encoded[bit_counter >> 3] |= ( 1 << (bit_counter & 7) );
}
// don't handle when the bit is zero, because
// the whole array is zero initialized

bit_counter += INTERLEAVER_STEP_SIZE;
if (bit_counter >= INTERLEAVER_SIZE) {
bit_counter -= (INTERLEAVER_SIZE - 1);
}
}
// Inlined interleaving:
// The interleaver forms a 24 row by 21 column matrix.
// It fills in the 21 encoded data word in the columns
// and reads out by the rows
// TODO: can be unrolled, but the whole encoding has a very low
// performance impact (0.01ms or 1ms is the same for this problem)
for (bit_idx = 0; bit_idx < 24; ++bit_idx) {
// interleave strating with LSB bit
if ( current_word & ( 1 << bit_idx ) ) {
// interleaved bit position is starting from LSB
encoded[bit_counter >> 3] |= ( 1 << (bit_counter & 7) );
}
// don't handle when the bit is zero, because
// the whole array is zero initialized

bit_counter += INTERLEAVER_STEP_SIZE;
if (bit_counter >= INTERLEAVER_SIZE) {
bit_counter -= (INTERLEAVER_SIZE - 1);
}
}
}
}

#ifdef TEST_ENCODE
int main() {
uint8_t data[MSG_LEN] = {'H', 'e', 'l', 'l', 'o', '!', 0};
uint8_t encoded[ENC_LEN] = {0};
int i;
uint8_t data[MSG_LEN] = {'H', 'e', 'l', 'l', 'o', '!', 0};
uint8_t encoded[ENC_LEN] = {0};
int i;

encode_data(data, encoded);
encode_data(data, encoded);

for (i = 0; i < ENC_LEN; ++i) {
printf("%02x ", encoded[i]);
if ((i & 0xf) == 0xf) {
printf("\n");
}
}
for (i = 0; i < ENC_LEN; ++i) {
printf("%02x ", encoded[i]);
if ((i & 0xf) == 0xf) {
printf("\n");
}
}

if ((i & 0xf) == 0xf) {
printf("\n");
}
if ((i & 0xf) == 0xf) {
printf("\n");
}

return 0;
return 0;
}
#endif // TEST_ENCODE
Loading

0 comments on commit 4d7cb63

Please sign in to comment.