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)
77 #warning TODO: open the file?
79 fp_adc = fopen("test/afsk_test.au", "rb");
84 ASSERT(fread(snd, 1, 4, fp_adc) == 4);
86 ASSERT(strcmp(snd, ".snd") == 0);
89 ASSERT(fread(&offset, 1, sizeof(offset), fp_adc) == sizeof(offset));
90 offset = be32_to_cpu(offset);
91 kprintf("AU file offset: %ld\n", (long)offset);
94 ASSERT(fread(&data_size, 1, sizeof(data_size), fp_adc) == sizeof(data_size));
95 data_size = be32_to_cpu(data_size);
96 kprintf("AU file data_size: %ld\n", (long)data_size);
100 ASSERT(fread(&encoding, 1, sizeof(encoding), fp_adc) == sizeof(encoding));
101 encoding = be32_to_cpu(encoding);
102 kprintf("AU file encoding: %ld\n", (long)encoding);
103 ASSERT(encoding == 2); // 8 bit linear PCM
105 uint32_t sample_rate;
106 ASSERT(fread(&sample_rate, 1, sizeof(sample_rate), fp_adc) == sizeof(sample_rate));
107 sample_rate = be32_to_cpu(sample_rate);
108 kprintf("AU file sample_rate: %ld\n", (long)sample_rate);
109 ASSERT(sample_rate == 9600);
112 ASSERT(fread(&channels, 1, sizeof(channels), fp_adc) == sizeof(channels));
113 channels = be32_to_cpu(channels);
114 kprintf("AU file channels: %ld\n", (long)channels);
115 ASSERT(channels == 1);
118 #warning TODO: fseek?
120 ASSERT(fseek(fp_adc, offset, SEEK_SET) == 0);
124 fp_dac = fopen("test/afsk_test_out.au", "w+b");
126 #define FS_HH ((CONFIG_AFSK_DAC_SAMPLERATE) >> 24)
127 #define FS_HL (((CONFIG_AFSK_DAC_SAMPLERATE) >> 16) & 0xff)
128 #define FS_LH (((CONFIG_AFSK_DAC_SAMPLERATE) >> 8) & 0xff)
129 #define FS_LL ((CONFIG_AFSK_DAC_SAMPLERATE) & 0xff)
131 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};
133 ASSERT(fwrite(snd_header, 1, sizeof(snd_header), fp_dac) == sizeof(snd_header));
137 afsk_fd.fd.error = kfile_genericClose;
138 ax25_init(&ax25, &afsk_fd.fd, message_hook);
143 int afsk_testRun(void)
146 while ((c = fgetc(fp_adc)) != EOF)
148 afsk_adc_val = (int8_t)c;
153 kprintf("Messages correctly received: %d\n", msg_cnt);
154 ASSERT(msg_cnt >= 15);
157 for (int i = 0; i < 75; i++)
158 kfile_putc(HDLC_FLAG, &afsk_fd.fd);
162 0x92, 0xAE, 0x6A, 0x84, 0x9C, 0xB2, 0xF2, 0x92, 0xA4, 0x6A, 0xA0, 0x40, 0xC0, 0xE1, 0xAE, 0x92,
163 0x88, 0x8A, 0x6E, 0x40, 0x6B, 0x03, 0xF0, 0x60, 0x27, 0x5B, 0x1E, 0x6C, 0x23, 0x43, 0x6A, 0x2F,
164 0x5D, 0x22, 0x35, 0x70, 0x7D, 0x6F, 0x70, 0x2E, 0x52, 0x4F, 0x42, 0x45, 0x52, 0x54, 0x4F, 0x2C,
165 0x5F, 0x51, 0x52, 0x56, 0x3A, 0x34, 0x33, 0x30, 0x2E, 0x31, 0x36, 0x32, 0x2C, 0x35, 0x0D, 0x09,
169 for (int i = 0; i < sizeof(tst); i++)
171 if (tst[i] == AFSK_ESC || tst[i] == HDLC_FLAG || tst[i] == HDLC_RESET)
172 kfile_putc(AFSK_ESC, &afsk_fd.fd);
173 kfile_putc(tst[i], &afsk_fd.fd);
176 kfile_putc(0xE0, &afsk_fd.fd);
177 kfile_putc(0x03, &afsk_fd.fd);
179 kfile_putc(HDLC_FLAG, &afsk_fd.fd);
188 #define SND_DATASIZE_OFF 8
190 int afsk_testTearDown(void)
193 ASSERT(fseek(fp_dac, SND_DATASIZE_OFF, SEEK_SET) == 0);
194 data_written = cpu_to_be32(data_written);
195 ASSERT(fwrite(&data_written, 1, sizeof(data_written), fp_dac) == sizeof(data_written));
196 return fclose(fp_adc) + fclose(fp_dac);
198 return fclose(fp_adc);