2015-11-20 06:59:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
2016-07-27 19:26:03 +00:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-11-20 06:59:09 +00:00
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program 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, 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; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2016-07-27 19:26:03 +00:00
|
|
|
#include "proc_afsk.hpp"
|
2015-11-20 06:59:09 +00:00
|
|
|
#include "portapack_shared_memory.hpp"
|
2016-07-27 19:26:03 +00:00
|
|
|
#include "sine_table_int8.hpp"
|
2016-07-27 01:03:40 +00:00
|
|
|
#include "event_m4.hpp"
|
2015-11-20 06:59:09 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2016-07-27 19:26:03 +00:00
|
|
|
void AFSKProcessor::execute(const buffer_c8_t& buffer) {
|
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
// This is called at 2.28M/2048 = 1113Hz
|
2016-07-27 19:26:03 +00:00
|
|
|
|
|
|
|
if (!configured) return;
|
2015-11-20 06:59:09 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i<buffer.count; i++) {
|
2016-08-06 06:49:45 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
// Tone synthesis at 2.28M/10 = 228kHz
|
2016-08-06 06:49:45 +00:00
|
|
|
if (s >= (5 - 1)) {
|
|
|
|
s = 0;
|
|
|
|
|
2016-07-27 19:26:03 +00:00
|
|
|
if (sample_count >= afsk_samples_per_bit) {
|
2016-08-02 10:44:31 +00:00
|
|
|
if (configured) {
|
2016-08-06 06:49:45 +00:00
|
|
|
cur_byte = shared_memory.tx_data[byte_pos];
|
|
|
|
ext_byte = shared_memory.tx_data[byte_pos + 1];
|
2016-08-02 10:44:31 +00:00
|
|
|
|
2016-07-29 02:52:51 +00:00
|
|
|
if (!(cur_byte | ext_byte)) {
|
2016-08-02 10:44:31 +00:00
|
|
|
// End of data
|
2016-07-27 22:08:05 +00:00
|
|
|
if (repeat_counter < afsk_repeat) {
|
2016-08-02 10:44:31 +00:00
|
|
|
// Repeat
|
2016-07-27 22:08:05 +00:00
|
|
|
bit_pos = 0;
|
|
|
|
byte_pos = 0;
|
2016-08-06 06:49:45 +00:00
|
|
|
cur_byte = shared_memory.tx_data[0];
|
|
|
|
ext_byte = shared_memory.tx_data[1];
|
2016-07-27 22:08:05 +00:00
|
|
|
message.n = repeat_counter + 1;
|
|
|
|
shared_memory.application_queue.push(message);
|
|
|
|
repeat_counter++;
|
|
|
|
} else {
|
2016-08-02 10:44:31 +00:00
|
|
|
// Stop
|
2016-07-27 22:08:05 +00:00
|
|
|
cur_byte = 0;
|
|
|
|
ext_byte = 0;
|
2016-08-02 10:44:31 +00:00
|
|
|
message.n = 0;
|
|
|
|
shared_memory.application_queue.push(message);
|
2016-07-27 22:08:05 +00:00
|
|
|
configured = false;
|
|
|
|
}
|
2015-11-20 06:59:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
if (afsk_format == 0) {
|
2016-07-25 14:21:27 +00:00
|
|
|
// 0bbbbbbbp1
|
|
|
|
// Start, 7-bit data, parity, stop
|
2016-08-02 10:44:31 +00:00
|
|
|
gbyte = (cur_byte << 1) | 1;
|
|
|
|
} else if (afsk_format == 1) {
|
2016-07-29 02:52:51 +00:00
|
|
|
// 0bbbbbbbbp
|
|
|
|
// Start, 8-bit data, parity
|
2016-08-02 10:44:31 +00:00
|
|
|
gbyte = (cur_byte << 1) | (ext_byte & 1);
|
2016-07-25 14:21:27 +00:00
|
|
|
}
|
2015-11-20 06:59:09 +00:00
|
|
|
|
2016-07-25 14:21:27 +00:00
|
|
|
cur_bit = (gbyte >> (9 - bit_pos)) & 1;
|
2015-11-20 06:59:09 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
if (bit_pos >= 9) {
|
2015-11-20 06:59:09 +00:00
|
|
|
bit_pos = 0;
|
2016-08-02 10:44:31 +00:00
|
|
|
if (afsk_format == 0)
|
2016-07-25 14:21:27 +00:00
|
|
|
byte_pos++;
|
2016-08-02 10:44:31 +00:00
|
|
|
else if (afsk_format == 1)
|
2016-07-25 14:21:27 +00:00
|
|
|
byte_pos += 2;
|
2015-11-20 06:59:09 +00:00
|
|
|
} else {
|
|
|
|
bit_pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sample_count = 0;
|
|
|
|
} else {
|
|
|
|
sample_count++;
|
|
|
|
}
|
|
|
|
if (cur_bit)
|
2016-07-27 19:26:03 +00:00
|
|
|
tone_phase += afsk_phase_inc_mark;
|
2015-11-20 06:59:09 +00:00
|
|
|
else
|
2016-07-27 19:26:03 +00:00
|
|
|
tone_phase += afsk_phase_inc_space;
|
2015-11-20 06:59:09 +00:00
|
|
|
} else {
|
2016-08-02 10:44:31 +00:00
|
|
|
s--;
|
2015-11-20 06:59:09 +00:00
|
|
|
}
|
2016-08-06 06:49:45 +00:00
|
|
|
|
|
|
|
//tone_phase += 432759; // 1981Hz
|
2015-11-20 06:59:09 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
tone_sample = (sine_table_i8[(tone_phase & 0x03FC0000) >> 18]);
|
2015-11-20 06:59:09 +00:00
|
|
|
|
2016-07-27 19:26:03 +00:00
|
|
|
// FM
|
|
|
|
// 1<<18 = 262144
|
2016-08-26 06:11:24 +00:00
|
|
|
// m = (262144 * a) / 2280000
|
|
|
|
// a = 262144 / 2280000 (*1000 = 115, see ui_lcr afsk_bw setting)
|
2016-07-27 19:26:03 +00:00
|
|
|
frq = tone_sample * afsk_bw;
|
2015-11-20 06:59:09 +00:00
|
|
|
|
|
|
|
phase = (phase + frq);
|
2016-08-02 10:44:31 +00:00
|
|
|
sphase = phase + (64 << 18);
|
2015-11-20 06:59:09 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
re = (sine_table_i8[(sphase & 0x03FC0000) >> 18]);
|
|
|
|
im = (sine_table_i8[(phase & 0x03FC0000) >> 18]);
|
2015-11-20 06:59:09 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
buffer.p[i] = {(int8_t)re, (int8_t)im};
|
2015-11-20 06:59:09 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-27 01:03:40 +00:00
|
|
|
|
2016-08-17 00:55:34 +00:00
|
|
|
void AFSKProcessor::on_message(const Message* const msg) {
|
|
|
|
const auto message = *reinterpret_cast<const AFSKConfigureMessage*>(msg);
|
2016-08-02 10:44:31 +00:00
|
|
|
|
2016-07-27 19:26:03 +00:00
|
|
|
if (message.id == Message::ID::AFSKConfigure) {
|
2016-08-06 06:49:45 +00:00
|
|
|
afsk_samples_per_bit = message.samples_per_bit;
|
|
|
|
afsk_phase_inc_mark = message.phase_inc_mark;
|
|
|
|
afsk_phase_inc_space = message.phase_inc_space;
|
|
|
|
afsk_repeat = message.repeat - 1;
|
|
|
|
afsk_bw = message.bw;
|
|
|
|
afsk_format = message.format;
|
2016-07-27 19:26:03 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
s = 0;
|
2016-07-29 02:52:51 +00:00
|
|
|
sample_count = afsk_samples_per_bit;
|
2016-07-27 22:08:05 +00:00
|
|
|
repeat_counter = 0;
|
2016-07-27 19:26:03 +00:00
|
|
|
bit_pos = 0;
|
|
|
|
byte_pos = 0;
|
|
|
|
cur_byte = 0;
|
|
|
|
ext_byte = 0;
|
|
|
|
cur_bit = 0;
|
|
|
|
configured = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 01:03:40 +00:00
|
|
|
int main() {
|
2016-07-27 19:26:03 +00:00
|
|
|
EventDispatcher event_dispatcher { std::make_unique<AFSKProcessor>() };
|
2016-07-27 01:03:40 +00:00
|
|
|
event_dispatcher.run();
|
|
|
|
return 0;
|
|
|
|
}
|