Add test for AFSK1200 modem driver.
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 4 Oct 2009 11:05:54 +0000 (11:05 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 4 Oct 2009 11:05:54 +0000 (11:05 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3009 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/net/afsk_test.c [new file with mode: 0644]
test/afsk_test.au [new file with mode: 0644]
test/run_tests.sh

diff --git a/bertos/net/afsk_test.c b/bertos/net/afsk_test.c
new file mode 100644 (file)
index 0000000..282c03d
--- /dev/null
@@ -0,0 +1,193 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief AFSK demodulator test.
+ *
+ * \version $Id$
+ * \author Francesco Sacchi <batt@develer.com>
+ * $test$: cp bertos/cfg/cfg_ax25.h $cfgdir/
+ * $test$: echo "#undef AX25_LOG_LEVEL" >> $cfgdir/cfg_ax25.h
+ * $test$: echo "#define AX25_LOG_LEVEL LOG_LVL_INFO" >> $cfgdir/cfg_ax25.h
+ */
+
+
+#include "afsk.h"
+#include "cfg/cfg_afsk.h"
+
+#include <drv/timer.h>
+#include <net/ax25.h>
+
+#include <cfg/test.h>
+#include <cfg/debug.h>
+
+#include <cpu/byteorder.h>
+
+#include <stdio.h>
+#include <string.h>
+
+FILE *fp_adc;
+FILE *fp_dac;
+uint32_t data_size;
+uint32_t data_written;
+bool afsk_tx_test;
+Afsk afsk_fd;
+AX25Ctx ax25;
+
+int8_t afsk_adc_val;
+
+int msg_cnt;
+static void message_hook(UNUSED_ARG(struct AX25Msg *, msg))
+{
+       msg_cnt++;
+}
+
+int afsk_testSetup(void)
+{
+       kdbg_init();
+       fp_adc = fopen("test/afsk_test.au", "rb");
+       ASSERT(fp_adc);
+
+       char snd[5];
+       ASSERT(fread(snd, 1, 4, fp_adc) == 4);
+       snd[4] = 0;
+       ASSERT(strcmp(snd, ".snd") == 0);
+
+       uint32_t offset;
+       ASSERT(fread(&offset, 1, sizeof(offset), fp_adc) == sizeof(offset));
+       offset = be32_to_cpu(offset);
+       kprintf("AU file offset: %d\n", offset);
+       ASSERT(offset >= 24);
+
+       ASSERT(fread(&data_size, 1, sizeof(data_size), fp_adc) == sizeof(data_size));
+       data_size = be32_to_cpu(data_size);
+       kprintf("AU file data_size: %d\n", data_size);
+       ASSERT(data_size);
+
+       uint32_t encoding;
+       ASSERT(fread(&encoding, 1, sizeof(encoding), fp_adc) == sizeof(encoding));
+       encoding = be32_to_cpu(encoding);
+       kprintf("AU file encoding: %d\n", encoding);
+       ASSERT(encoding == 2); // 8 bit linear PCM
+
+       uint32_t sample_rate;
+       ASSERT(fread(&sample_rate, 1, sizeof(sample_rate), fp_adc) == sizeof(sample_rate));
+       sample_rate = be32_to_cpu(sample_rate);
+       kprintf("AU file sample_rate: %d\n", sample_rate);
+       ASSERT(sample_rate == 9600);
+
+       uint32_t channels;
+       ASSERT(fread(&channels, 1, sizeof(channels), fp_adc) == sizeof(channels));
+       channels = be32_to_cpu(channels);
+       kprintf("AU file channels: %d\n", channels);
+       ASSERT(channels == 1);
+
+       ASSERT(fseek(fp_adc, offset, SEEK_SET) == 0);
+
+       #if 0
+       fp_dac = fopen("test/afsk_test_out.au", "w+b");
+       ASSERT(fp_dac);
+       #define FS_HH ((CONFIG_AFSK_DAC_SAMPLERATE) >> 24)
+       #define FS_HL (((CONFIG_AFSK_DAC_SAMPLERATE) >> 16) & 0xff)
+       #define FS_LH (((CONFIG_AFSK_DAC_SAMPLERATE) >> 8) & 0xff)
+       #define FS_LL ((CONFIG_AFSK_DAC_SAMPLERATE) & 0xff)
+
+       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};
+
+       ASSERT(fwrite(snd_header, 1, sizeof(snd_header), fp_dac) == sizeof(snd_header));
+       #endif
+       timer_init();
+       afsk_init(&afsk_fd);
+       afsk_fd.fd.error = kfile_genericClose;
+       ax25_init(&ax25, &afsk_fd.fd, message_hook);
+       return 0;
+}
+
+
+int afsk_testRun(void)
+{
+       int c;
+       while ((c = fgetc(fp_adc)) != EOF)
+       {
+               afsk_adc_val = (int8_t)c;
+               afsk_adc_isr();
+
+               ax25_poll(&ax25);
+       }
+       kprintf("Messages correctly received: %d\n", msg_cnt);
+       ASSERT(msg_cnt >= 15);
+       #if 0
+
+       for (int i = 0; i < 75; i++)
+               kfile_putc(HDLC_FLAG, &afsk_fd.fd);
+
+       uint8_t tst[] =
+       {
+               0x92, 0xAE, 0x6A, 0x84, 0x9C, 0xB2, 0xF2, 0x92, 0xA4, 0x6A, 0xA0, 0x40, 0xC0, 0xE1, 0xAE, 0x92,
+               0x88, 0x8A, 0x6E, 0x40, 0x6B, 0x03, 0xF0, 0x60, 0x27, 0x5B, 0x1E, 0x6C, 0x23, 0x43, 0x6A, 0x2F,
+               0x5D, 0x22, 0x35, 0x70, 0x7D, 0x6F, 0x70, 0x2E, 0x52, 0x4F, 0x42, 0x45, 0x52, 0x54, 0x4F, 0x2C,
+               0x5F, 0x51, 0x52, 0x56, 0x3A, 0x34, 0x33, 0x30, 0x2E, 0x31, 0x36, 0x32, 0x2C, 0x35, 0x0D, 0x09,
+               0xCB,
+       };
+
+       for (int i = 0; i < sizeof(tst); i++)
+       {
+               if (tst[i] == AFSK_ESC || tst[i] == HDLC_FLAG || tst[i] == HDLC_RESET)
+                       kfile_putc(AFSK_ESC, &afsk_fd.fd);
+               kfile_putc(tst[i], &afsk_fd.fd);
+       }
+
+       kfile_putc(0xE0, &afsk_fd.fd);
+       kfile_putc(0x03, &afsk_fd.fd);
+
+       kfile_putc(HDLC_FLAG, &afsk_fd.fd);
+
+       while (afsk_tx_test)
+               afsk_dac_isr();
+
+       #endif
+       return 0;
+}
+
+#define SND_DATASIZE_OFF 8
+
+int afsk_testTearDown(void)
+{
+       #if 0
+       ASSERT(fseek(fp_dac, SND_DATASIZE_OFF, SEEK_SET) == 0);
+       data_written = cpu_to_be32(data_written);
+       ASSERT(fwrite(&data_written, 1, sizeof(data_written), fp_dac) == sizeof(data_written));
+       return fclose(fp_adc) + fclose(fp_dac);
+       #endif
+       return fclose(fp_adc);
+}
+
+TEST_MAIN(afsk);
diff --git a/test/afsk_test.au b/test/afsk_test.au
new file mode 100644 (file)
index 0000000..7b12ce8
Binary files /dev/null and b/test/afsk_test.au differ
index 0662cc3fb133060af5239eb6f7d9f26774fd11eb..0d8855eb4f47a04076df114c9e23750390a099d2 100755 (executable)
@@ -28,7 +28,7 @@ TESTS=${TESTS:-`find . \
        -o -name "*_test.c" -print` }
 
 TESTOUT="testout"
-SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/struct/kfile_fifo.c bertos/fs/fatfs/ff.c bertos/emul/diskio_emul.c bertos/fs/fat.c bertos/emul/switch_ctx_emul.S bertos/mware/ini_reader.c bertos/emul/kfile_posix.c bertos/algo/crc_ccitt.c bertos/algo/crc.c bertos/struct/kfile_mem.c bertos/net/ax25.c"
+SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/struct/kfile_fifo.c bertos/fs/fatfs/ff.c bertos/emul/diskio_emul.c bertos/fs/fat.c bertos/emul/switch_ctx_emul.S bertos/mware/ini_reader.c bertos/emul/kfile_posix.c bertos/algo/crc_ccitt.c bertos/algo/crc.c bertos/struct/kfile_mem.c bertos/net/ax25.c bertos/net/afsk.c"
 
 buildout='/dev/null'
 runout='/dev/null'