#include #include #include #include #include "utils.h" #include "packet_mod.h" #include "config.h" #include "preamble.h" #include "transmission.h" int main(void) { uint8_t msg_org[] = "Hello Liquid! This is the message to transmit. Hopefully it can be decoded correctly..."; fec q = fec_create(CHANNEL_CODE, NULL); modem demod = modem_create(MODULATION); channel_cccf channel = channel_cccf_create(); float snr = 20.0f; channel_cccf_add_awgn(channel, -snr, snr); unsigned int k = fec_get_enc_msg_length(CHANNEL_CODE, sizeof(msg_org)); packet_mod_ctx_t pmod; packet_mod_init(&pmod); packet_mod_set_data(&pmod, msg_org, sizeof(msg_org)); packet_mod_encode(&pmod); packet_mod_modulate(&pmod); packet_mod_add_header(&pmod); packet_mod_add_preamble(&pmod); size_t nsyms; packet_mod_get_result_cf(&pmod, NULL, &nsyms); // determine number of symbols for allocation float complex msg_mod[nsyms]; packet_mod_get_result_cf(&pmod, msg_mod, &nsyms); // get the data size_t burst_len = 0; float complex whole_burst[65536]; size_t len; transmission_ctx_t transm; transmission_init(&transm); len = 65536-burst_len; if(transmission_ramp_up(&transm, whole_burst+burst_len, &len) != OK) { printf("Ramp-up requires %zd symbols at offset %zd.\n", len, burst_len); return 1; } burst_len += len; len = 65536-burst_len; if(transmission_filter_packet(&transm, msg_mod, nsyms, whole_burst+burst_len, &len) != OK) { printf("Packet requires %zd symbols at offset %zd.\n", len, burst_len); return 1; } burst_len += len; len = 65536-burst_len; if(transmission_ramp_down(&transm, whole_burst+burst_len, &len) != OK) { printf("Ramp-down requires %zd symbols at offset %zd.\n", len, burst_len); return 1; } burst_len += len; dump_array_cf(whole_burst, burst_len, 1.0f, "/tmp/tx.cpx"); #if 0 // channel float complex msg_received[nsyms]; nsyms = nsyms - 63 - 16; //memcpy(msg_received, msg_mod, sizeof(msg_received)); // no noise in channel channel_cccf_execute_block(channel, msg_mod + 63 + 16, nsyms, msg_received); dump_array_cf(msg_received, nsyms, 1.0f, "/tmp/rx.cpx"); // demodulate unsigned int bps = modem_get_bps(demod); unsigned char msg_demod_syms[nsyms]; unsigned char msg_demod[k+1]; for(size_t i = 0; i < nsyms; i++) { unsigned int symbol; modem_demodulate(demod, msg_received[i], &symbol); msg_demod_syms[i] = symbol; } unsigned int received_bytes; liquid_repack_bytes(msg_demod_syms, bps, nsyms, msg_demod, 8, sizeof(msg_demod), &received_bytes); //assert(received_bytes == k); // decode uint8_t msg_dec[sizeof(msg_org)]; //memcpy(msg_dec, msg_enc, sizeof(msg_dec)); fec_decode(q, sizeof(msg_dec), msg_demod, msg_dec); // compare original to decoded message for(size_t i = 0; i < sizeof(msg_org); i++) { printf("%02x => %02x", msg_org[i], msg_dec[i]); if(msg_org[i] != msg_dec[i]) { printf(" <<< !!!\n"); } else { printf("\n"); } } unsigned int bit_errors = count_bit_errors_array(msg_org, msg_dec, sizeof(msg_org)); printf("%u bit errors detected.\n", bit_errors); #endif fec_destroy(q); modem_destroy(demod); channel_cccf_destroy(channel); printf("Done.\n"); }