2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 #define RANDOM_MAX 0x7fffffff
31 return (double) random() / (double) RANDOM_MAX;
35 gaussian_random(double mean, double dev)
37 static int save_x_valid = 0;
49 double normal_x1, normal_x2;
52 normal_x1 = 2 * rand_real () - 1;
53 normal_x2 = 2 * rand_real () - 1;
54 w = normal_x1*normal_x1 + normal_x2*normal_x2;
55 } while (w >= 1 || w < 1E-30);
57 w = sqrt(log(w)*(-2./w));
60 * normal_x1 and normal_x2 are independent normally
61 * distributed variates
65 /* save normal_x2 for next call */
66 save_x = normal_x2 * w;
69 return x * dev + mean;
72 #define PREPARE_LEN(input_len) ((input_len) + AO_FEC_PREPARE_EXTRA)
73 #define ENCODE_LEN(input_len) (PREPARE_LEN(input_len) * 2)
74 #define DECODE_LEN(input_len) ((input_len) + AO_FEC_PREPARE_EXTRA)
75 #define EXPAND_LEN(input_len) (ENCODE_LEN(input_len) * 8)
77 static uint8_t ao_bit(uint8_t b) {
84 ao_expand(uint8_t *bits, int bits_len, uint8_t *bytes)
89 for (i = 0; i < bits_len; i++) {
91 for (bit = 7; bit >= 0; bit--)
92 *bytes++ = ao_bit ((b >> bit) & 1);
99 ao_fuzz (uint8_t *in, int in_len, uint8_t *out, double dev)
105 for (i = 0; i < in_len; i++) {
106 double error = gaussian_random(0, dev);
107 uint8_t byte = in[i];
131 #define SAVE_MASK (((1 << SAVE) - 1) << (8 - SAVE))
134 for (s = SAVE; s < 8; s += SAVE)
143 ao_random_data(uint8_t *out, uint8_t out_len)
145 uint8_t len = random() % (out_len + 1);
148 for (i = 0; i < len; i++)
154 static uint8_t real_packet[] = {
155 0x40, 0x38, 0xcd, 0x38, 0x3d, 0x34, 0xca, 0x31, 0xc3, 0xc1, 0xc6, 0x35, 0xcc, 0x3a, 0x3c,
156 0x3c, 0x3d, 0x3c, 0x37, 0xc5, 0xc1, 0xc0, 0xc1, 0xc1, 0xc3, 0xc0, 0xc1, 0xc6, 0x38, 0x3b, 0xc6,
157 0xc0, 0xc6, 0x32, 0xc9, 0xc9, 0x34, 0xcf, 0x35, 0xcf, 0x3a, 0x3b, 0xc6, 0xc7, 0x35, 0xcf, 0x36,
158 0xce, 0x37, 0xc8, 0xc8, 0x3a, 0x3c, 0xc9, 0xc8, 0x3a, 0x3c, 0xcc, 0x32, 0xcd, 0x32, 0xce, 0x32,
159 0xc9, 0xc6, 0x37, 0x3e, 0x3d, 0xc8, 0xc3, 0xc6, 0x38, 0x3d, 0xcf, 0x34, 0x3d, 0x3b, 0xcb, 0x31,
160 0xca, 0x35, 0x38, 0xcb, 0x31, 0xcc, 0x31, 0x3b, 0xc7, 0xbf, 0xbe, 0xbe, 0xc3, 0x35, 0x38, 0xcb,
161 0x2f, 0xc9, 0xc2, 0x34, 0x3c, 0xcc, 0x31, 0xca, 0xc1, 0xc0, 0xc3, 0x33, 0x3f, 0x3f, 0x3e, 0x3c,
162 0xcc, 0x31, 0xcc, 0xc3, 0xc4, 0x32, 0xd1, 0x34, 0x3f, 0x3c, 0xcc, 0x31, 0xcc, 0xc3, 0x33, 0xd0,
163 0x31, 0xd1, 0x35, 0x3f, 0x3e, 0x3c, 0xca, 0xc5, 0x34, 0xcc, 0xc2, 0xc3, 0xc3, 0xc5, 0x36, 0x40,
164 0x3e, 0x41, 0x3e, 0x41, 0x3e, 0x3f, 0x41, 0x40, 0xce, 0xc5, 0x33, 0xcf, 0xc7, 0x36, 0xd2, 0x32,
165 0xd1, 0xc5, 0xc6, 0x35, 0xd4, 0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 0x33, 0xd0, 0xc5, 0xc4, 0x35, 0x40, 0x40, 0x3e, 0x41, 0x3e, 0xd2, 0x30, 0x3f,
275 0x3e, 0x3d, 0x21, 0xc8, 0x0d, 0x23, 0xec, 0xb1, 0x1a, 0xf0, 0xf3, 0x10, 0xc6, 0xbd, 0x5b, 0x0d,
276 0xff, 0xe2, 0xe6, 0xd4, 0x72, 0xe2, 0xda, 0x0c, 0xf8, 0x1b, 0x04, 0x0b, 0xf7, 0xb4, 0xf0, 0x44,
277 0xcd, 0xaf, 0x12, 0x1f, 0x11, 0xa1, 0x29, 0xb8, 0x1a, 0xdb, 0x09, 0x69, 0xf7, 0x20, 0xc4, 0x1c,
278 0xc0, 0xc8, 0x1d, 0x45, 0xd9, 0x30, 0xd8, 0x2e, 0xd8, 0x2e, 0xd6, 0x2c, 0xd5, 0x2d, 0xd4, 0x2b,
279 0xd5, 0x2b, 0xd1, 0x31, 0xd0, 0x32, 0xd2, 0x30, 0xd0, 0x31, 0xd0, 0x31, 0xce, 0x2f, 0xd3, 0x2e,
280 0xce, 0x2f, 0xd1, 0x31, 0x3c, 0xd1, 0x2d, 0xd0, 0xc0, 0x2e, 0x3c, 0x3d, 0xd1, 0xc3, 0x2c, 0xd2,
281 0xc3, 0xc5, 0x31, 0x40, 0x40, 0xd5, 0x2c, 0x3a, 0x3d, 0xd0, 0x2b, 0xd3, 0xc0, 0xc0, 0x2d, 0xd4,
282 0x2c, 0x3f, 0x3e, 0x3c, 0x3f, 0x3c, 0xd2, 0xc1, 0xc2, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0x2a,
292 ok = ao_fec_decode(real_packet, 576, decode, 34, NULL);
294 if (ok && decode[33] == AO_FEC_DECODE_CRC_OK) {
297 ao_fec_dump_bytes(decode, 34, "Decode");
299 printf ("actual packet crc error\n");
305 #define EXPECT_DECODE_FAIL 0
306 #define EXPECT_CRC_MISMATCH 6386
307 #define EXPECT_DATA_MISMATCH 0
308 #define NOISE_AMOUNT 0x50
311 main(int argc, char **argv)
315 uint8_t original[120];
316 uint8_t original_len;
318 uint8_t encode[ENCODE_LEN(sizeof(original))];
321 uint8_t transmit[EXPAND_LEN(sizeof(original))];
324 uint8_t receive[EXPAND_LEN(sizeof(original))];
327 uint8_t decode[DECODE_LEN(sizeof(original))];
332 int crc_mismatch = 0;
333 int data_mismatch = 0;
335 if (!ao_real_packet())
339 for (trial = 0; trial < 100000; trial++) {
341 /* Compute some random data */
342 original_len = ao_random_data(original, sizeof(original));
345 encode_len = ao_fec_encode(original, original_len, encode);
347 /* Expand from 1-bit-per-symbol to 1-byte-per-symbol */
348 transmit_len = ao_expand(encode, encode_len, transmit);
350 /* Add gaussian noise to the signal */
351 (void) ao_fuzz(transmit, transmit_len, receive, NOISE_AMOUNT);
352 receive_len = transmit_len;
355 decode_ok = ao_fec_decode(receive, receive_len, decode, original_len + 2, NULL);
357 /* Check to see if we received the right data */
361 else if (decode[original_len +1] != AO_FEC_DECODE_CRC_OK)
363 else if (memcmp(original, decode, original_len) != 0)
368 printf ("%d packets coded\n", trial);
369 printf ("decode_fail %d crc_mismatch %d data_mismatch %d\n",
370 decode_fail, crc_mismatch, data_mismatch);
371 if (decode_fail != EXPECT_DECODE_FAIL) {
372 printf ("expected %d decode failures\n", EXPECT_DECODE_FAIL);
375 if (crc_mismatch != EXPECT_CRC_MISMATCH) {
376 printf ("expected %d crc mismatch\n", EXPECT_CRC_MISMATCH);
379 if (data_mismatch != EXPECT_DATA_MISMATCH) {
380 printf ("expected %d data mismatch\n", EXPECT_DATA_MISMATCH);