1
|
/*
|
2
|
This is a test scratchpad to test the implementation of
|
3
|
new functions.
|
4
|
*/
|
5
|
|
6
|
#include <stdio.h>
|
7
|
#include <string.h>
|
8
|
#include <stdlib.h>
|
9
|
#include <unistd.h>
|
10
|
#include <stdint.h>
|
11
|
#include <libcodebananas/dspbanana.h>
|
12
|
#include <libcodebananas/toolbanana.h>
|
13
|
|
14
|
#include "v42bis.h"
|
15
|
#define BLOCK_SIZE 100
|
16
|
#define MAX_BLOCK_SIZE 2048
|
17
|
|
18
|
|
19
|
/* A simple testpattern generator */
|
20
|
int gen_test_pattern(uint8_t *data, int len)
|
21
|
{
|
22
|
int i;
|
23
|
|
24
|
printf("gen_test_pattern() len=%i\n",len);
|
25
|
|
26
|
for(i=0;i<len;i++)
|
27
|
{
|
28
|
data[i] = i & 0xF0;
|
29
|
}
|
30
|
|
31
|
hexBinAsciiDump((char*)data,len);
|
32
|
return len;
|
33
|
}
|
34
|
|
35
|
/* A struct to tell to capture the output data of compressor and decompressor */
|
36
|
struct v42bis_output_buffer_t
|
37
|
{
|
38
|
uint8_t *buf;
|
39
|
uint8_t *buf_pointer;
|
40
|
int len;
|
41
|
};
|
42
|
|
43
|
/* Handler to capture the output data from the compressor */
|
44
|
void tx_v42bis_frame_handler(void *user_data, const uint8_t *pkt, int len)
|
45
|
{
|
46
|
struct v42bis_output_buffer_t *output_buffer = (struct v42bis_output_buffer_t*) user_data;
|
47
|
memcpy(output_buffer->buf_pointer,pkt,len);
|
48
|
output_buffer->buf_pointer+=len;
|
49
|
output_buffer->len += len;
|
50
|
return;
|
51
|
}
|
52
|
|
53
|
/* Handler to capture the output data from the decompressor */
|
54
|
void tx_v42bis_data_handler(void *user_data, const uint8_t *buf, int len)
|
55
|
{
|
56
|
struct v42bis_output_buffer_t *output_buffer = (struct v42bis_output_buffer_t*) user_data;
|
57
|
memcpy(output_buffer->buf_pointer,buf,len);
|
58
|
output_buffer->buf_pointer+=len;
|
59
|
output_buffer->len += len;
|
60
|
return;
|
61
|
}
|
62
|
|
63
|
/* Handler to capture the output data from the compressor */
|
64
|
void rx_v42bis_frame_handler(void *user_data, const uint8_t *pkt, int len)
|
65
|
{
|
66
|
struct v42bis_output_buffer_t *output_buffer = (struct v42bis_output_buffer_t*) user_data;
|
67
|
memcpy(output_buffer->buf_pointer,pkt,len);
|
68
|
output_buffer->buf_pointer+=len;
|
69
|
output_buffer->len += len;
|
70
|
return;
|
71
|
}
|
72
|
|
73
|
/* Handler to capture the output data from the decompressor */
|
74
|
void rx_v42bis_data_handler(void *user_data, const uint8_t *buf, int len)
|
75
|
{
|
76
|
struct v42bis_output_buffer_t *output_buffer = (struct v42bis_output_buffer_t*) user_data;
|
77
|
memcpy(output_buffer->buf_pointer,buf,len);
|
78
|
output_buffer->buf_pointer+=len;
|
79
|
output_buffer->len += len;
|
80
|
return;
|
81
|
}
|
82
|
|
83
|
/* Main program */
|
84
|
int main(void)
|
85
|
{
|
86
|
v42bis_state_t *tx_state;
|
87
|
v42bis_state_t *rx_state;
|
88
|
|
89
|
uint8_t uncompressed_original[BLOCK_SIZE];
|
90
|
uint8_t compressed[BLOCK_SIZE];
|
91
|
uint8_t uncompressed[BLOCK_SIZE];
|
92
|
|
93
|
int rc;
|
94
|
struct v42bis_output_buffer_t compressed_data;
|
95
|
struct v42bis_output_buffer_t uncompressed_data;
|
96
|
|
97
|
|
98
|
/* Initalize */
|
99
|
tx_state = v42bis_init(NULL,3,MAX_BLOCK_SIZE,6,&tx_v42bis_frame_handler,NULL,MAX_BLOCK_SIZE,&tx_v42bis_data_handler,NULL,MAX_BLOCK_SIZE);
|
100
|
rx_state = v42bis_init(NULL,3,MAX_BLOCK_SIZE,6,&rx_v42bis_frame_handler,NULL,MAX_BLOCK_SIZE,&rx_v42bis_data_handler,NULL,MAX_BLOCK_SIZE);
|
101
|
v42bis_compression_control(tx_state, V42BIS_COMPRESSION_MODE_ALWAYS);
|
102
|
v42bis_compression_control(rx_state, V42BIS_COMPRESSION_MODE_ALWAYS);
|
103
|
|
104
|
|
105
|
/* Generate test pattern for input */
|
106
|
gen_test_pattern(uncompressed_original,sizeof(uncompressed_original));
|
107
|
printf(" * uncompressed_original=\n");
|
108
|
hexBinAsciiDump((char*)uncompressed_original,sizeof(uncompressed_original));
|
109
|
|
110
|
|
111
|
/* Run compressor */
|
112
|
compressed_data.buf = compressed;
|
113
|
compressed_data.buf_pointer = compressed;
|
114
|
compressed_data.len = 0;
|
115
|
tx_state->compress.user_data=&compressed_data;
|
116
|
rc = v42bis_compress(tx_state,uncompressed_original, sizeof(uncompressed_original));
|
117
|
printf("rc=%i\n",rc);
|
118
|
rc = v42bis_compress_flush(tx_state);
|
119
|
printf("rc=%i\n",rc);
|
120
|
|
121
|
|
122
|
/* Display result */
|
123
|
printf(" * compressed=\n");
|
124
|
hexBinAsciiDump((char*)compressed_data.buf,compressed_data.len);
|
125
|
|
126
|
|
127
|
printf("======COMPRESS======\n");
|
128
|
|
129
|
|
130
|
uncompressed_data.buf = uncompressed;
|
131
|
uncompressed_data.buf_pointer = uncompressed;
|
132
|
uncompressed_data.len = 0;
|
133
|
rx_state->decompress.user_data=&uncompressed_data;
|
134
|
rc = v42bis_decompress(rx_state,compressed_data.buf, compressed_data.len);
|
135
|
printf("rc=%i\n",rc);
|
136
|
rc = v42bis_decompress_flush(rx_state);
|
137
|
printf("rc=%i\n",rc);
|
138
|
|
139
|
printf(" * uncompressed=\n");
|
140
|
hexBinAsciiDump((char*)uncompressed_data.buf,uncompressed_data.len);
|
141
|
|
142
|
|
143
|
|
144
|
printf("======DECOMPRESS======\n");
|
145
|
|
146
|
printf(" * check:\n");
|
147
|
rc = memcmp(uncompressed,uncompressed_original,BLOCK_SIZE);
|
148
|
printf("rc=%i\n",rc);
|
149
|
|
150
|
return 0;
|
151
|
}
|
152
|
|
153
|
|
154
|
|
155
|
|
156
|
|