blob: 8388a6f6475ce6dd3b1cba9bc9a1863696fdbcd5 [file] [log] [blame]
piotrfaacc722014-07-20 23:48:32 +02001//TODO: this file shouldn't be part of the GSM Receiver
2#include <stdlib.h>
3#include <stdio.h>
4#include "interleave.h"
5
6int
7interleave_init(INTERLEAVE_CTX *ictx, int size, int block_size)
8{
9 ictx->trans_size = size;
10 ictx->trans = (unsigned short *)malloc(size * sizeof *ictx->trans);
11
12// DEBUGF("size: %d\n", size);
13// DEBUGF("Block size: %d\n", block_size);
14 int j, k, B;
15 for (k = 0; k < size; k++)
16 {
17 B = k % 4;
18 j = 2 * ((49 * k) % 57) + ((k % 8) / 4);
19 ictx->trans[k] = B * block_size + j;
20 /* Mapping: pos1 goes to pos2: pos1 -> pos2 */
21 //printf("%d -> %d\n", ictx->trans[k], k);
22 }
23// exit(0);
24 return 0;
25}
26
27int
28interleave_init_facch_f(INTERLEAVE_CTX *ictx, int size, int block_size, int block_offset)
29{
30 ictx->trans_size = size;
31 ictx->trans = (unsigned short *)malloc(size * sizeof *ictx->trans);
32
33// DEBUGF("size: %d\n", size);
34// DEBUGF("Block size: %d\n", block_size);
35 int j, k, B;
36 for (k = 0; k < size; k++)
37 {
38 B = (k + block_offset) % 8;
39 j = 2 * ((49 * k) % 57) + ((k % 8) / 4);
40 ictx->trans[k] = B * block_size + j;
41 /* Mapping: pos1 goes to pos2: pos1 -> pos2 */
42// DEBUGF("%d -> %d\n", ictx->trans[k], k);
43 }
44// exit(0);
45 return 0;
46}
47
48int
49interleave_deinit(INTERLEAVE_CTX *ictx)
50{
51 if (ictx->trans != NULL)
52 {
53 free(ictx->trans);
54 ictx->trans = NULL;
55 }
56
57 return 0;
58}
59
60void
61interleave_decode(INTERLEAVE_CTX *ictx, unsigned char *dst, unsigned char *src)
62{
63 printf("Lol\n");
64 int k;
65 for (k = 0; k < ictx->trans_size; k++)
66 {
67 printf("k=%d, ictx->trans[k]=%d\n", k, ictx->trans[k]);
68 dst[k] = src[ictx->trans[k]];
69 }
70}
71