X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fnet%2Fafsk_test.c;h=cb7d2cd13feb02838192f61720390a1a7026ae7c;hb=b30ca67e54f665181d85a49bff3af2862e86601e;hp=e0b80ef6aeea59834c4cfd5a7d6c5c92c6346f8b;hpb=66b147c758f5e892fa209141e5a052935e607887;p=bertos.git diff --git a/bertos/net/afsk_test.c b/bertos/net/afsk_test.c index e0b80ef6..cb7d2cd1 100644 --- a/bertos/net/afsk_test.c +++ b/bertos/net/afsk_test.c @@ -32,11 +32,13 @@ * * \brief AFSK demodulator test. * - * \version $Id$ * \author Francesco Sacchi * $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 */ @@ -48,6 +50,7 @@ #include #include +#include #include @@ -58,143 +61,161 @@ 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; +KFileDebug dbg; int msg_cnt; -static void message_hook(UNUSED_ARG(struct AX25Msg *, msg)) +static void message_hook(struct AX25Msg *msg) { msg_cnt++; + ax25_print(&dbg.fd, msg); } -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", 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", 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", 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", 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", channels); + kprintf("AU file channels: %ld\n", (long)channels); ASSERT(channels == 1); #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(); + kfiledebug_init(&dbg); + 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; + afsk_init(&afsk_fd, 0 ,0); ax25_init(&ax25, &afsk_fd.fd, message_hook); return 0; } +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; while ((c = fgetc(fp_adc)) != EOF) { - afsk_adc_val = (int8_t)c; - afsk_adc_isr(); + afsk_adc_isr(&afsk_fd, (int8_t)c); 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); + char buf[256]; + for (unsigned i = 0; i < sizeof(buf); i++) + buf[i] = i; - 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++) + ax25_send(&ax25, AX25_CALL("abcdef", 0), AX25_CALL("123456", 1), buf, sizeof(buf)); + + do { - 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); + int8_t val = afsk_dac_isr(&afsk_fd) - 128; + ASSERT(fwrite(&val, 1, sizeof(val), fp_dac) == sizeof(val)); + data_written++; } + while (afsk_fd.sending); - kfile_putc(0xE0, &afsk_fd.fd); - kfile_putc(0x03, &afsk_fd.fd); + #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); - kfile_putc(HDLC_FLAG, &afsk_fd.fd); + fp_adc = afsk_fileOpen("test/afsk_test_out.au"); + ax25_init(&ax25, &afsk_fd.fd, messageout_hook); - while (afsk_tx_test) - afsk_dac_isr(); + while ((c = fgetc(fp_adc)) != EOF) + { + afsk_adc_isr(&afsk_fd, (int8_t)c); + + ax25_poll(&ax25); + } - #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); }