Merge branch 'pr/325' into next

This commit is contained in:
eried
2021-04-14 09:30:53 +02:00
18 changed files with 1722 additions and 16 deletions

View File

@@ -0,0 +1,27 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* 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.
*/
#include "aprs_packet.hpp"
namespace aprs {
} /* namespace zwave */

View File

@@ -0,0 +1,495 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* 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.
*/
#ifndef __APRS_PACKET_H__
#define __APRS_PACKET_H__
#include <cstdint>
#include <cstddef>
#include <cctype>
#include "baseband.hpp"
namespace aprs {
const int APRS_MIN_LENGTH = 18; //14 bytes address, control byte and pid. 2 CRC.
struct aprs_pos{
float latitude;
float longitude;
uint8_t symbol_code;
uint8_t sym_table_id;
};
enum ADDRESS_TYPE {
SOURCE,
DESTINATION,
REPEATER
};
class APRSPacket {
public:
void set_timestamp(const Timestamp& value) {
timestamp_ = value;
}
Timestamp timestamp() const {
return timestamp_;
}
void set(const size_t index, const uint8_t data) {
payload[index] = data;
if(index + 1 > payload_size){
payload_size = index + 1;
}
}
uint32_t operator[](const size_t index) const {
return payload[index];
}
uint8_t size() const {
return payload_size;
}
void set_valid_checksum(const bool valid) {
valid_checksum = valid;
}
bool is_valid_checksum() const {
return valid_checksum;
}
uint64_t get_source(){
uint64_t source = 0x0;
for(uint8_t i = SOURCE_START; i < SOURCE_START + ADDRESS_SIZE; i++){
source |= ( ((uint64_t)payload[i]) << ((i - SOURCE_START) * 8));
}
return source;
}
std::string get_source_formatted(){
parse_address(SOURCE_START, SOURCE);
return std::string(address_buffer);
}
std::string get_destination_formatted(){
parse_address(DESTINATION_START, DESTINATION);
return std::string(address_buffer);
}
std::string get_digipeaters_formatted(){
uint8_t position = DIGIPEATER_START;
bool has_more = parse_address(SOURCE_START, REPEATER);
std::string repeaters = "";
while(has_more){
has_more = parse_address(position, REPEATER);
repeaters += std::string(address_buffer);
position += ADDRESS_SIZE;
if(has_more){
repeaters += ">";
}
}
return repeaters;
}
uint8_t get_number_of_digipeaters(){
uint8_t position = DIGIPEATER_START;
bool has_more = parse_address(SOURCE_START, REPEATER);
uint8_t repeaters = 0;
while(has_more){
has_more = parse_address(position, REPEATER);
position += ADDRESS_SIZE;
repeaters++;
}
return repeaters;
}
uint8_t get_information_start_index(){
return DIGIPEATER_START + (get_number_of_digipeaters() * ADDRESS_SIZE) + 2;
}
std::string get_information_text_formatted(){
std::string information_text = "";
for(uint8_t i = get_information_start_index(); i < payload_size - 2; i++){
information_text += payload[i];
}
return information_text;
}
std::string get_stream_text(){
std::string stream = get_source_formatted() + ">" + get_destination_formatted() + ";" + get_digipeaters_formatted() + ";" + get_information_text_formatted();
return stream;
}
char get_data_type_identifier(){
char ident = '\0';
for(uint8_t i = get_information_start_index(); i < payload_size - 2; i++){
ident = payload[i];
break;
}
return ident;
}
bool has_position(){
char ident = get_data_type_identifier();
return
ident == '!' ||
ident == '=' ||
ident == '/' ||
ident == '@' ||
ident == ';' ||
ident == '`' ||
ident == '\''||
ident == 0x1d||
ident == 0x1c;
}
aprs_pos get_position(){
aprs::aprs_pos pos;
char ident = get_data_type_identifier();
std::string info_text = get_information_text_formatted();
std::string lat_str, lng_str;
char first;
//bool supports_compression = true;
bool is_mic_e_format = false;
std::string::size_type start;
switch(ident){
case '/':
case '@':
start = 8;
break;
case '=':
case '!':
start = 1;
break;
case ';':
start = 18;
//supports_compression = false;
break;
case '`':
case '\'':
case 0x1c:
case 0x1d:
is_mic_e_format = true;
break;
default:
return pos;
}
if(is_mic_e_format){
parse_mic_e_format(pos);
}
else {
if(start < info_text.size()){
first = info_text.at(start);
if(std::isdigit(first)){
if(start + 18 < info_text.size()){
lat_str = info_text.substr(start, 8);
pos.sym_table_id = info_text.at(start + 8);
lng_str = info_text.substr(start + 9, 9);
pos.symbol_code = info_text.at(start + 18);
pos.latitude = parse_lat_str(lat_str);
pos.longitude = parse_lng_str(lng_str);
}
}
else {
if(start + 9 < info_text.size()){
pos.sym_table_id = info_text.at(start);
lat_str = info_text.substr(start + 1, 4);
lng_str = info_text.substr(start + 5, 4);
pos.symbol_code = info_text.at(start + 9);
pos.latitude = parse_lat_str_cmp(lat_str);
pos.longitude = parse_lng_str_cmp(lng_str);
}
}
}
}
return pos;
}
void clear() {
payload_size = 0;
}
private:
const uint8_t DIGIPEATER_START = 14;
const uint8_t SOURCE_START = 7;
const uint8_t DESTINATION_START = 0;
const uint8_t ADDRESS_SIZE = 7;
bool valid_checksum = false;
uint8_t payload[256];
char address_buffer[15];
uint8_t payload_size;
Timestamp timestamp_ { };
float parse_lat_str_cmp(const std::string& lat_str){
return 90.0 - ( (lat_str.at(0) - 33) * (91*91*91) + (lat_str.at(1) - 33) * (91*91) + (lat_str.at(2) - 33) * 91 + (lat_str.at(3)) ) / 380926.0;
}
float parse_lng_str_cmp(const std::string& lng_str){
return -180.0 + ( (lng_str.at(0) - 33) * (91*91*91) + (lng_str.at(1) - 33) * (91*91) + (lng_str.at(2) - 33) * 91 + (lng_str.at(3)) ) / 190463.0;
}
uint8_t parse_digits(const std::string& str){
if(str.at(0) == ' '){
return 0;
}
uint8_t end = str.find_last_not_of(' ') + 1;
std::string sub = str.substr(0, end);
if(!is_digits(sub)){
return 0;
}
else {
return std::stoi(sub);
}
}
bool is_digits(const std::string& str){
return str.find_last_not_of("0123456789") == std::string::npos;
}
float parse_lat_str(const std::string& lat_str){
float lat = 0.0;
std::string str_lat_deg = lat_str.substr(0, 2);
std::string str_lat_min = lat_str.substr(2, 2);
std::string str_lat_hund = lat_str.substr(5, 2);
std::string dir = lat_str.substr(7, 1);
uint8_t lat_deg = parse_digits(str_lat_deg);
uint8_t lat_min = parse_digits(str_lat_min);
uint8_t lat_hund = parse_digits(str_lat_hund);
lat += lat_deg;
lat += (lat_min + (lat_hund/ 100.0))/60.0;
if(dir.c_str()[0] == 'S'){
lat = -lat;
}
return lat;
}
float parse_lng_str(std::string& lng_str){
float lng = 0.0;
std::string str_lng_deg = lng_str.substr(0, 3);
std::string str_lng_min = lng_str.substr(3, 2);
std::string str_lng_hund = lng_str.substr(6, 2);
std::string dir = lng_str.substr(8, 1);
uint8_t lng_deg = parse_digits(str_lng_deg);
uint8_t lng_min = parse_digits(str_lng_min);
uint8_t lng_hund = parse_digits(str_lng_hund);
lng += lng_deg;
lng += (lng_min + (lng_hund/ 100.0))/60.0;
if(dir.c_str()[0] == 'W'){
lng = -lng;
}
return lng;
}
void parse_mic_e_format(aprs::aprs_pos& pos){
std::string lat_str = "";
std::string lng_str = "";
bool is_north;
bool is_west;
uint8_t lng_offset;
for(uint8_t i = DESTINATION_START; i < DESTINATION_START + ADDRESS_SIZE - 1; i++){
uint8_t ascii = payload[i] >> 1;
lat_str += get_mic_e_lat_digit(ascii);
if(i - DESTINATION_START == 3){
lat_str += ".";
}
if(i - DESTINATION_START == 3){
is_north = is_mic_e_lat_N(ascii);
}
if(i - DESTINATION_START == 4){
lng_offset = get_mic_e_lng_offset(ascii);
}
if(i - DESTINATION_START == 5){
is_west = is_mic_e_lng_W(ascii);
}
}
if(is_north){
lat_str += "N";
}
else {
lat_str += "S";
}
pos.latitude = parse_lat_str(lat_str);
float lng = 0.0;
uint8_t information_start = get_information_start_index() + 1;
for(uint8_t i = information_start; i < information_start + 3 && i < payload_size - 2; i++){
uint8_t ascii = payload[i];
if(i - information_start == 0){ //deg
ascii -=28;
ascii += lng_offset;
if(ascii >= 180 && ascii <= 189){
ascii -= 80;
}
else if (ascii >= 190 && ascii <= 199){
ascii -= 190;
}
lng += ascii;
}
else if(i - information_start == 1){ //min
ascii -= 28;
if(ascii >= 60){
ascii -= 60;
}
lng += ascii/60.0;
}
else if(i - information_start == 2){ //hundredth minutes
ascii -= 28;
lng += (ascii/100.0)/60.0;
}
}
if(is_west){
lng = -lng;
}
pos.longitude = lng;
}
uint8_t get_mic_e_lat_digit(uint8_t ascii){
if(ascii >= '0' && ascii <= '9'){
return ascii;
}
if(ascii >= 'A' && ascii <= 'J'){
return ascii - 17;
}
if(ascii >= 'P' && ascii <='Y'){
return ascii - 32;
}
if(ascii == 'K' || ascii == 'L' || ascii == 'Z'){
return ' ';
}
return '\0';
}
bool is_mic_e_lat_N(uint8_t ascii){
if(ascii >= 'P' && ascii <='Z'){
return true;
}
return false; //not technical definition, but the other case is invalid
}
bool is_mic_e_lng_W(uint8_t ascii){
if(ascii >= 'P' && ascii <='Z'){
return true;
}
return false; //not technical definition, but the other case is invalid
}
uint8_t get_mic_e_lng_offset(uint8_t ascii){
if(ascii >= 'P' && ascii <='Z'){
return 100;
}
return 0; //not technical definition, but the other case is invalid
}
bool parse_address(uint8_t start, ADDRESS_TYPE address_type){
uint8_t byte = 0;
uint8_t has_more = false;
uint8_t ssid = 0;
uint8_t buffer_index = 0;
for(uint8_t i = start; i < start + ADDRESS_SIZE && i < payload_size - 2; i++){
byte = payload[i];
if(i - start == 6){
has_more = (byte & 0x1) == 0;
ssid = (byte >> 1) & 0x0F;
if(ssid != 0 || address_type == REPEATER){
address_buffer[buffer_index++] = '-';
if(ssid < 10){
address_buffer[buffer_index++] = '0' + ssid;
address_buffer[buffer_index++] = '\0';
}
else {
address_buffer[buffer_index++] = '1';
address_buffer[buffer_index++] = '0' + ssid - 10;
address_buffer[buffer_index++] = '\0';
}
}
else {
address_buffer[buffer_index++] = '\0';
}
}
else {
byte >>= 1;
if(byte != ' '){
address_buffer[buffer_index++] = byte;
}
}
}
return has_more;
}
};
} /* namespace aprs */
#endif/*__APRS_PACKET_H__*/

View File

@@ -36,6 +36,7 @@
#include "adsb_frame.hpp"
#include "ert_packet.hpp"
#include "pocsag_packet.hpp"
#include "aprs_packet.hpp"
#include "sonde_packet.hpp"
#include "tpms_packet.hpp"
#include "jammer.hpp"
@@ -111,6 +112,8 @@ public:
AudioLevelReport = 51,
CodedSquelch = 52,
AudioSpectrum = 53,
APRSPacket = 54,
APRSRxConfigure = 55,
MAX
};
@@ -725,6 +728,18 @@ public:
const bool trigger_word;
};
class APRSRxConfigureMessage : public Message {
public:
constexpr APRSRxConfigureMessage(
const uint32_t baudrate
) : Message { ID::APRSRxConfigure },
baudrate(baudrate)
{
}
const uint32_t baudrate;
};
class BTLERxConfigureMessage : public Message {
public:
constexpr BTLERxConfigureMessage(
@@ -1014,6 +1029,19 @@ public:
const bool phase;
};
class APRSPacketMessage : public Message {
public:
constexpr APRSPacketMessage(
const aprs::APRSPacket& packet
) : Message { ID::APRSPacket },
packet { packet }
{
}
aprs::APRSPacket packet;
};
class ADSBConfigureMessage : public Message {
public:
constexpr ADSBConfigureMessage(

View File

@@ -77,6 +77,7 @@ private:
constexpr image_tag_t image_tag_acars { 'P', 'A', 'C', 'A' };
constexpr image_tag_t image_tag_adsb_rx { 'P', 'A', 'D', 'R' };
constexpr image_tag_t image_tag_afsk_rx { 'P', 'A', 'F', 'R' };
constexpr image_tag_t image_tag_aprs_rx { 'P', 'A', 'P', 'R' };
constexpr image_tag_t image_tag_btle_rx { 'P', 'B', 'T', 'R' };
constexpr image_tag_t image_tag_nrf_rx { 'P', 'N', 'R', 'R' };
constexpr image_tag_t image_tag_ais { 'P', 'A', 'I', 'S' };

View File

@@ -597,11 +597,14 @@ Console::Console(
void Console::clear(bool clear_buffer = false) {
if(clear_buffer)
buffer.clear();
display.fill_rectangle(
screen_rect(),
Color::black()
);
if(!hidden() && visible()){
display.fill_rectangle(
screen_rect(),
Color::black()
);
}
pos = { 0, 0 };
}
@@ -648,8 +651,7 @@ void Console::write(std::string message) {
}
void Console::writeln(std::string message) {
write(message);
write("\n");
write(message + "\n");
//crlf();
}
@@ -658,18 +660,31 @@ void Console::paint(Painter&) {
}
void Console::on_show() {
const auto screen_r = screen_rect();
display.scroll_set_area(screen_r.top(), screen_r.bottom());
display.scroll_set_position(0);
enable_scrolling(true);
clear();
//visible = true;
}
bool Console::scrolling_enabled = false;
void Console::enable_scrolling(bool enable){
if(enable){
const auto screen_r = screen_rect();
display.scroll_set_area(screen_r.top(), screen_r.bottom());
display.scroll_set_position(0);
scrolling_enabled = true;
}
else {
display.scroll_disable();
scrolling_enabled = false;
}
}
void Console::on_hide() {
/* TODO: Clear region to eliminate brief flash of content at un-shifted
* position?
*/
display.scroll_disable();
enable_scrolling(false);
//visible = false;
}
@@ -682,6 +697,9 @@ void Console::crlf() {
pos = { 0, pos.y() + line_height };
const int32_t y_excess = pos.y() + line_height - sr.height();
if( y_excess > 0 ) {
if(!scrolling_enabled){
enable_scrolling(true);
}
display.scroll(-y_excess);
pos = { pos.x(), pos.y() - y_excess };
@@ -1293,9 +1311,9 @@ size_t OptionsField::selected_index_value() const {
return options[selected_index_].second;
}
void OptionsField::set_selected_index(const size_t new_index) {
void OptionsField::set_selected_index(const size_t new_index, bool trigger_change) {
if( new_index < options.size() ) {
if( new_index != selected_index() ) {
if( new_index != selected_index() || trigger_change) {
selected_index_ = new_index;
if( on_change ) {
on_change(selected_index(), options[selected_index()].second);

View File

@@ -325,6 +325,7 @@ public:
void paint(Painter&) override;
void enable_scrolling(bool enable);
void on_show() override;
void on_hide() override;
@@ -332,6 +333,7 @@ private:
//bool visible = false;
Point pos { 0, 0 };
std::string buffer { };
static bool scrolling_enabled;
void crlf();
};
@@ -545,7 +547,7 @@ public:
size_t selected_index() const;
size_t selected_index_value() const;
void set_selected_index(const size_t new_index);
void set_selected_index(const size_t new_index, bool trigger_change = true);
void set_by_value(value_t v);