From: batt Date: Fri, 9 Oct 2009 21:49:27 +0000 (+0000) Subject: Add test for afsk transmitter (the modulator). X-Git-Tag: 2.3.0~29 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=83341ac21b1a3ec29c962bc168b801eb888c90ad;p=bertos.git Add test for afsk transmitter (the modulator). git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3054 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/net/afsk_test.c b/bertos/net/afsk_test.c index cdbf19c2..d835d628 100644 --- a/bertos/net/afsk_test.c +++ b/bertos/net/afsk_test.c @@ -37,6 +37,9 @@ * $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 + * $test$: cp bertos/cfg/cfg_afsk.h $cfgdir/ + * $test$: echo "#undef CONFIG_AFSK_TX_BUFLEN" >> $cfgdir/cfg_afsk.h + * $test$: echo "#define CONFIG_AFSK_TX_BUFLEN 512" >> $cfgdir/cfg_afsk.h */ @@ -70,46 +73,47 @@ static void message_hook(UNUSED_ARG(struct AX25Msg *, msg)) msg_cnt++; } -int afsk_testSetup(void) +static FILE *afsk_fileOpen(const char *name) { - kdbg_init(); + FILE *fp = 0; #if CPU_AVR + (void)name; #warning TODO: open the file? #else - fp_adc = fopen("test/afsk_test.au", "rb"); + fp = fopen(name, "rb"); #endif - ASSERT(fp_adc); + ASSERT(fp); char snd[5]; - ASSERT(fread(snd, 1, 4, fp_adc) == 4); + ASSERT(fread(snd, 1, 4, fp) == 4); snd[4] = 0; ASSERT(strcmp(snd, ".snd") == 0); uint32_t offset; - ASSERT(fread(&offset, 1, sizeof(offset), fp_adc) == sizeof(offset)); + ASSERT(fread(&offset, 1, sizeof(offset), fp) == sizeof(offset)); offset = be32_to_cpu(offset); kprintf("AU file offset: %ld\n", (long)offset); ASSERT(offset >= 24); - ASSERT(fread(&data_size, 1, sizeof(data_size), fp_adc) == sizeof(data_size)); + ASSERT(fread(&data_size, 1, sizeof(data_size), fp) == sizeof(data_size)); data_size = be32_to_cpu(data_size); kprintf("AU file data_size: %ld\n", (long)data_size); ASSERT(data_size); uint32_t encoding; - ASSERT(fread(&encoding, 1, sizeof(encoding), fp_adc) == sizeof(encoding)); + ASSERT(fread(&encoding, 1, sizeof(encoding), fp) == sizeof(encoding)); encoding = be32_to_cpu(encoding); kprintf("AU file encoding: %ld\n", (long)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)); + ASSERT(fread(&sample_rate, 1, sizeof(sample_rate), fp) == sizeof(sample_rate)); sample_rate = be32_to_cpu(sample_rate); kprintf("AU file sample_rate: %ld\n", (long)sample_rate); ASSERT(sample_rate == 9600); uint32_t channels; - ASSERT(fread(&channels, 1, sizeof(channels), fp_adc) == sizeof(channels)); + ASSERT(fread(&channels, 1, sizeof(channels), fp) == sizeof(channels)); channels = be32_to_cpu(channels); kprintf("AU file channels: %ld\n", (long)channels); ASSERT(channels == 1); @@ -117,21 +121,30 @@ int afsk_testSetup(void) #if CPU_AVR #warning TODO: fseek? #else - ASSERT(fseek(fp_adc, offset, SEEK_SET) == 0); + ASSERT(fseek(fp, offset, SEEK_SET) == 0); #endif + return fp; +} - #if 0 - fp_dac = fopen("test/afsk_test_out.au", "w+b"); +int afsk_testSetup(void) +{ + kdbg_init(); + fp_adc = afsk_fileOpen("test/afsk_test.au"); + #if CPU_AVR + #warning TODO: open the file? + #else + fp_dac = fopen("test/afsk_test_out.au", "w+b"); + #endif 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) + #define FS_HH (((uint32_t)CONFIG_AFSK_DAC_SAMPLERATE) >> 24) + #define FS_HL ((((uint32_t)CONFIG_AFSK_DAC_SAMPLERATE) >> 16) & 0xff) + #define FS_LH ((((uint32_t)CONFIG_AFSK_DAC_SAMPLERATE) >> 8) & 0xff) + #define FS_LL (((uint32_t)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; @@ -140,6 +153,19 @@ int afsk_testSetup(void) } +static void messageout_hook(struct AX25Msg *msg) +{ + ASSERT(strncmp(msg->dst.call, "ABCDEF", 6) == 0); + ASSERT(strncmp(msg->src.call, "123456", 6) == 0); + ASSERT(msg->src.ssid == 1); + ASSERT(msg->dst.ssid == 0); + ASSERT(msg->ctrl == AX25_CTRL_UI); + ASSERT(msg->pid == AX25_PID_NOLAYER3); + ASSERT(msg->len == 256); + for (int i = 0; i < 256; i++) + ASSERT(msg->info[i] == i); +} + int afsk_testRun(void) { int c; @@ -152,49 +178,43 @@ int afsk_testRun(void) } 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); + char buf[256]; + for (unsigned i = 0; i < sizeof(buf); i++) + buf[i] = i; - kfile_putc(HDLC_FLAG, &afsk_fd.fd); + ax25_send(&ax25, AX25_CALL("abcdef", 0), AX25_CALL("123456", 1), buf, sizeof(buf)); while (afsk_tx_test) afsk_dac_isr(); + + #define SND_DATASIZE_OFF 8 + #if CPU_AVR + #warning TODO: fseek? + #else + ASSERT(fseek(fp_dac, SND_DATASIZE_OFF, SEEK_SET) == 0); #endif + data_written = cpu_to_be32(data_written); + ASSERT(fwrite(&data_written, 1, sizeof(data_written), fp_dac) == sizeof(data_written)); + ASSERT(fclose(fp_adc) + fclose(fp_dac) == 0); + + fp_adc = afsk_fileOpen("test/afsk_test_out.au"); + ax25_init(&ax25, &afsk_fd.fd, messageout_hook); + + while ((c = fgetc(fp_adc)) != EOF) + { + afsk_adc_val = (int8_t)c; + afsk_adc_isr(); + + ax25_poll(&ax25); + } + 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); }