Skip to content

Commit

Permalink
intial
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarpicva committed Nov 8, 2022
0 parents commit 6ec2b00
Show file tree
Hide file tree
Showing 6 changed files with 569 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------

*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash

# qtcreator generated files
*.pro.user*

# xemacs temporary files
*.flc

# Vim temporary files
.*.swp

# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*

# MinGW generated files
*.Debug
*.Release

# Python byte code
*.pyc

# Binaries
# --------
*.dll
*.exe

24 changes: 24 additions & 0 deletions PicoAPRSTrackerConfig.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
QT += core gui serialport

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
main.cpp \
picoaprstrackerconfig.cpp

HEADERS += \
picoaprstrackerconfig.h

FORMS += \
picoaprstrackerconfig.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
11 changes: 11 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "picoaprstrackerconfig.h"

#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
PicoAPRSTrackerConfig w;
w.show();
return a.exec();
}
168 changes: 168 additions & 0 deletions picoaprstrackerconfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#include "picoaprstrackerconfig.h"
#include "ui_picoaprstrackerconfig.h"

#include <QInputDialog>
#include <QMessageBox>
#include <QRegularExpression>
#include <QSerialPortInfo>
#include <QTimer>

PicoAPRSTrackerConfig::PicoAPRSTrackerConfig(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::PicoAPRSTrackerConfig)
{
ui->setupUi(this);

QTimer::singleShot(100, this, &PicoAPRSTrackerConfig::connectToDevice);
}

PicoAPRSTrackerConfig::~PicoAPRSTrackerConfig()
{
delete ui;
}

void PicoAPRSTrackerConfig::connectToDevice()
{
if(sport) {
sport->close();
disconnect(sport, 0, 0, 0);
}
else {
sport = new QSerialPort(this);
}
QStringList items;
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
foreach(QSerialPortInfo p, ports)
items<<p.portName();
s_portName = QInputDialog::getItem(this, "Choose Port", "Choose the serial port of the Tracker device.", items, 3, false);
if(s_portName.isEmpty()) {
QMessageBox::warning(this, "Must Chooose Port", "A serial port must be chosen first!");
return;
}
sport->setPortName(s_portName);
if(sport->open(QSerialPort::ReadWrite)) {
sport->setBaudRate(QSerialPort::Baud115200);
connect(sport, &QSerialPort::readyRead, this, &PicoAPRSTrackerConfig::on_readyRead);
sport->write("READCONFIG|\r");
}
else {
QMessageBox::warning(this, "Unable to Connect", "Unable to connect to the chosen serial port.");
}
}

void PicoAPRSTrackerConfig::on_readyRead()
{
inbytes.append(sport->readAll());
if(inbytes.count('|') == 5) { // six delimited fields
ui->plainTextEdit->appendPlainText(inbytes);
const QString tmp = inbytes;
const QStringList tmpl = tmp.split("|");
ui->sourceCallLineEdit->setText(tmpl.at(0));
ui->digi1LineEdit->setText(tmpl.at(1));
ui->digi2LineEdit->setText(tmpl.at(2));
ui->commentLineEdit->setText(tmpl.at(3));
ui->intervalComboBox->setCurrentText(tmpl.at(4));
ui->aprsSymbolComboBox->setCurrentText(tmpl.at(5));
inbytes.clear();
}
}

void PicoAPRSTrackerConfig::on_actionE_xit_triggered()
{
close();
}

void PicoAPRSTrackerConfig::on_action_Write_to_Device_triggered()
{
// gather, evaluate and build the output string to send to the Pico to write to flash
out.clear();
QString tmp;
QRegularExpression good = QRegularExpression("[0-9A-Z-]");
tmp = ui->sourceCallLineEdit->text().trimmed().toUpper();
if(tmp.length() > 4 && tmp.length() < 10) // must include the "-<ssid>" characters, so min of 3 call sign + 2 "-<ssid".
{
if(tmp.count(good) != tmp.length()) {

QMessageBox::warning(this, "Bad Characters", "Some of the characters are not valid for a call sign.\n\n0-9, A-Z, - and / only.");
return;
}
ui->plainTextEdit->appendPlainText("Valid Call Sign");
if(!tmp.contains('-')) {
if(tmp.length() > 6) {
QMessageBox::warning(this, "Bad Characters", "Some of the characters are not valid for a call sign.\n\n0-9, A-Z, and \"-\" only.");
return;
}
else {
tmp.append("-12"); // default to a tracker device SSID
}
}
out<<tmp;
}
tmp = ui->digi1LineEdit->text().trimmed().toUpper();
if(tmp.length() > 2 && tmp.length() < 10) // OK!
{
if(tmp.count(good) != tmp.length()) {

QMessageBox::warning(this, "Bad Characters", "Some of the characters are not valid for a call sign.\n\n0-9, A-Z, and \"-\" only.");
return;
}
ui->plainTextEdit->appendPlainText("Valid Call Sign");
out<<tmp;
}
else {
out << "WIDE1-1";
}
tmp = ui->digi2LineEdit->text().trimmed().toUpper();
if(tmp.length() > 2 && tmp.length() < 10) // OK!
{
if(tmp.count(good) != tmp.length()) {

QMessageBox::warning(this, "Bad Characters", "Some of the characters are not valid for a call sign.\n\n0-9, A-Z, and \"-\" only.");
return;
}
ui->plainTextEdit->appendPlainText("Valid Call Sign");
out<<tmp;
}
else {
out << "WIDE2-1";
}
// comment
out<<ui->commentLineEdit->text().trimmed();
// beacon interval
out<< ui->intervalComboBox->currentText();
// APRS symbol
out<< ui->aprsSymbolComboBox->currentText().trimmed();
ui->plainTextEdit->appendPlainText(out.join("|"));
}

void PicoAPRSTrackerConfig::on_action_Read_from_Device_triggered()
{
if(sport) {
sport->write("READCONFIG|\r");
}
}

void PicoAPRSTrackerConfig::on_action_Serial_Port_triggered()
{
connectToDevice();
}

void PicoAPRSTrackerConfig::on_sourceCallLineEdit_returnPressed()
{
on_action_Write_to_Device_triggered();
}

void PicoAPRSTrackerConfig::on_writeConfigButton_clicked()
{
on_action_Write_to_Device_triggered();
if(QMessageBox::question(this, "Write Config?", "Write the configuration:\n\n" + out.join("|") + "\n\n to the device?") == QMessageBox::Yes)
if(sport) {
sport->write("WRITECONFIG|" + out.join("|").toLatin1() + "\r");
}
}

void PicoAPRSTrackerConfig::on_readConfigButton_clicked()
{
on_action_Read_from_Device_triggered();
}

37 changes: 37 additions & 0 deletions picoaprstrackerconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef PICOAPRSTRACKERCONFIG_H
#define PICOAPRSTRACKERCONFIG_H

#include <QMainWindow>
#include <QSerialPort>

QT_BEGIN_NAMESPACE
namespace Ui { class PicoAPRSTrackerConfig; }
QT_END_NAMESPACE

class PicoAPRSTrackerConfig : public QMainWindow
{
Q_OBJECT

public:
PicoAPRSTrackerConfig(QWidget *parent = nullptr);
~PicoAPRSTrackerConfig();

private slots:
void on_actionE_xit_triggered();
void on_action_Write_to_Device_triggered();
void on_action_Read_from_Device_triggered();
void on_action_Serial_Port_triggered();
void connectToDevice();
void on_readyRead();
void on_sourceCallLineEdit_returnPressed();
void on_writeConfigButton_clicked();
void on_readConfigButton_clicked();

private:
Ui::PicoAPRSTrackerConfig *ui;
QSerialPort *sport = nullptr;
QByteArray inbytes;
QString s_portName;
QStringList out; // holds the configuration values
};
#endif // PICOAPRSTRACKERCONFIG_H
Loading

0 comments on commit 6ec2b00

Please sign in to comment.