2015-12-02 05:59:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-12-08 23:28:33 +00:00
|
|
|
#include "ert_app.hpp"
|
2015-12-02 05:59:47 +00:00
|
|
|
|
2016-01-13 23:46:04 +00:00
|
|
|
#include "event_m0.hpp"
|
|
|
|
|
2015-12-02 05:59:47 +00:00
|
|
|
#include "portapack.hpp"
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
#include "manchester.hpp"
|
|
|
|
|
2015-12-07 19:38:35 +00:00
|
|
|
#include "crc.hpp"
|
2015-12-06 23:32:21 +00:00
|
|
|
#include "string_format.hpp"
|
|
|
|
|
2016-01-24 05:46:41 +00:00
|
|
|
namespace ert {
|
|
|
|
|
|
|
|
namespace format {
|
|
|
|
|
|
|
|
std::string type(Packet::Type value) {
|
|
|
|
switch(value) {
|
|
|
|
default:
|
|
|
|
case Packet::Type::Unknown: return "???";
|
|
|
|
case Packet::Type::IDM: return "IDM";
|
|
|
|
case Packet::Type::SCM: return "SCM";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string id(ID value) {
|
|
|
|
return to_string_dec_uint(value, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string consumption(Consumption value) {
|
|
|
|
return to_string_dec_uint(value, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace format */
|
|
|
|
|
|
|
|
} /* namespace ert */
|
|
|
|
|
2016-01-24 05:17:04 +00:00
|
|
|
void ERTLogger::on_packet(const ert::Packet& packet) {
|
2015-12-07 23:31:01 +00:00
|
|
|
if( log_file.is_ready() ) {
|
|
|
|
const auto formatted = packet.symbols_formatted();
|
|
|
|
log_file.write_entry(packet.received_at(), formatted.data + "/" + formatted.errors);
|
|
|
|
}
|
2015-12-02 05:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2016-01-24 05:17:04 +00:00
|
|
|
ERTView::ERTView() {
|
2016-01-13 23:46:04 +00:00
|
|
|
EventDispatcher::message_map().register_handler(Message::ID::ERTPacket,
|
2015-12-02 05:59:47 +00:00
|
|
|
[this](Message* const p) {
|
|
|
|
const auto message = static_cast<const ERTPacketMessage*>(p);
|
2015-12-12 19:37:30 +00:00
|
|
|
const ert::Packet packet { message->type, message->packet };
|
2016-01-24 05:17:04 +00:00
|
|
|
this->on_packet(packet);
|
2015-12-02 05:59:47 +00:00
|
|
|
}
|
|
|
|
);
|
2016-01-24 05:17:04 +00:00
|
|
|
|
|
|
|
receiver_model.set_baseband_configuration({
|
|
|
|
.mode = 6,
|
|
|
|
.sampling_rate = 4194304,
|
|
|
|
.decimation_factor = 1,
|
|
|
|
});
|
|
|
|
receiver_model.set_baseband_bandwidth(2500000);
|
2015-12-02 05:59:47 +00:00
|
|
|
}
|
|
|
|
|
2016-01-24 05:17:04 +00:00
|
|
|
ERTView::~ERTView() {
|
2016-01-13 23:46:04 +00:00
|
|
|
EventDispatcher::message_map().unregister_handler(Message::ID::ERTPacket);
|
2015-12-02 05:59:47 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 23:32:21 +00:00
|
|
|
void ERTView::on_packet(const ert::Packet& packet) {
|
2016-01-24 05:17:04 +00:00
|
|
|
logger.on_packet(packet);
|
|
|
|
|
|
|
|
if( packet.crc_ok() ) {
|
2016-01-24 05:46:41 +00:00
|
|
|
std::string msg { ert::format::type(packet.type()) };
|
|
|
|
|
2016-01-24 05:17:04 +00:00
|
|
|
switch(packet.type()) {
|
|
|
|
case ert::Packet::Type::SCM:
|
|
|
|
case ert::Packet::Type::IDM:
|
2016-01-24 05:46:41 +00:00
|
|
|
msg += " " + ert::format::id(packet.id());
|
|
|
|
msg += " " + ert::format::consumption(packet.consumption());
|
2016-01-24 05:17:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-12-06 23:32:21 +00:00
|
|
|
|
2016-01-24 05:17:04 +00:00
|
|
|
writeln(msg);
|
|
|
|
}
|
2015-12-02 05:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|