4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
33 * \brief AFSK demodulator test.
36 * \author Francesco Sacchi <batt@develer.com>
37 * $test$: cp bertos/cfg/cfg_ax25.h $cfgdir/
38 * $test$: echo "#undef AX25_LOG_LEVEL" >> $cfgdir/cfg_ax25.h
39 * $test$: echo "#define AX25_LOG_LEVEL LOG_LVL_INFO" >> $cfgdir/cfg_ax25.h
44 #include "cfg/cfg_afsk.h"
46 #include <drv/timer.h>
50 #include <cfg/debug.h>
52 #include <cpu/byteorder.h>
60 uint32_t data_written;
68 static void message_hook(UNUSED_ARG(struct AX25Msg *, msg))
73 int afsk_testSetup(void)
76 fp_adc = fopen("test/afsk_test.au", "rb");
80 ASSERT(fread(snd, 1, 4, fp_adc) == 4);
82 ASSERT(strcmp(snd, ".snd") == 0);
85 ASSERT(fread(&offset, 1, sizeof(offset), fp_adc) == sizeof(offset));
86 offset = be32_to_cpu(offset);
87 kprintf("AU file offset: %d\n", offset);
90 ASSERT(fread(&data_size, 1, sizeof(data_size), fp_adc) == sizeof(data_size));
91 data_size = be32_to_cpu(data_size);
92 kprintf("AU file data_size: %d\n", data_size);
96 ASSERT(fread(&encoding, 1, sizeof(encoding), fp_adc) == sizeof(encoding));
97 encoding = be32_to_cpu(encoding);
98 kprintf("AU file encoding: %d\n", encoding);
99 ASSERT(encoding == 2); // 8 bit linear PCM
101 uint32_t sample_rate;
102 ASSERT(fread(&sample_rate, 1, sizeof(sample_rate), fp_adc) == sizeof(sample_rate));
103 sample_rate = be32_to_cpu(sample_rate);
104 kprintf("AU file sample_rate: %d\n", sample_rate);
105 ASSERT(sample_rate == 9600);
108 ASSERT(fread(&channels, 1, sizeof(channels), fp_adc) == sizeof(channels));
109 channels = be32_to_cpu(channels);
110 kprintf("AU file channels: %d\n", channels);
111 ASSERT(channels == 1);
113 ASSERT(fseek(fp_adc, offset, SEEK_SET) == 0);
116 fp_dac = fopen("test/afsk_test_out.au", "w+b");
118 #define FS_HH ((CONFIG_AFSK_DAC_SAMPLERATE) >> 24)
119 #define FS_HL (((CONFIG_AFSK_DAC_SAMPLERATE) >> 16) & 0xff)
120 #define FS_LH (((CONFIG_AFSK_DAC_SAMPLERATE) >> 8) & 0xff)
121 #define FS_LL ((CONFIG_AFSK_DAC_SAMPLERATE) & 0xff)
123 uint8_t snd_header[] = { '.','s','n','d', 0,0,0,24, 0,0,0,0, 0,0,0,2, FS_HH,FS_HL,FS_LH,FS_LL, 0,0,0,1};
125 ASSERT(fwrite(snd_header, 1, sizeof(snd_header), fp_dac) == sizeof(snd_header));
129 afsk_fd.fd.error = kfile_genericClose;
130 ax25_init(&ax25, &afsk_fd.fd, message_hook);
135 int afsk_testRun(void)
138 while ((c = fgetc(fp_adc)) != EOF)
140 afsk_adc_val = (int8_t)c;
145 kprintf("Messages correctly received: %d\n", msg_cnt);
146 ASSERT(msg_cnt >= 15);
149 for (int i = 0; i < 75; i++)
150 kfile_putc(HDLC_FLAG, &afsk_fd.fd);
154 0x92, 0xAE, 0x6A, 0x84, 0x9C, 0xB2, 0xF2, 0x92, 0xA4, 0x6A, 0xA0, 0x40, 0xC0, 0xE1, 0xAE, 0x92,
155 0x88, 0x8A, 0x6E, 0x40, 0x6B, 0x03, 0xF0, 0x60, 0x27, 0x5B, 0x1E, 0x6C, 0x23, 0x43, 0x6A, 0x2F,
156 0x5D, 0x22, 0x35, 0x70, 0x7D, 0x6F, 0x70, 0x2E, 0x52, 0x4F, 0x42, 0x45, 0x52, 0x54, 0x4F, 0x2C,
157 0x5F, 0x51, 0x52, 0x56, 0x3A, 0x34, 0x33, 0x30, 0x2E, 0x31, 0x36, 0x32, 0x2C, 0x35, 0x0D, 0x09,
161 for (int i = 0; i < sizeof(tst); i++)
163 if (tst[i] == AFSK_ESC || tst[i] == HDLC_FLAG || tst[i] == HDLC_RESET)
164 kfile_putc(AFSK_ESC, &afsk_fd.fd);
165 kfile_putc(tst[i], &afsk_fd.fd);
168 kfile_putc(0xE0, &afsk_fd.fd);
169 kfile_putc(0x03, &afsk_fd.fd);
171 kfile_putc(HDLC_FLAG, &afsk_fd.fd);
180 #define SND_DATASIZE_OFF 8
182 int afsk_testTearDown(void)
185 ASSERT(fseek(fp_dac, SND_DATASIZE_OFF, SEEK_SET) == 0);
186 data_written = cpu_to_be32(data_written);
187 ASSERT(fwrite(&data_written, 1, sizeof(data_written), fp_dac) == sizeof(data_written));
188 return fclose(fp_adc) + fclose(fp_dac);
190 return fclose(fp_adc);