-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
399 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "Hamlib"] | ||
path = Hamlib | ||
url = https://github.com/Hamlib/Hamlib.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(androtator LANGUAGES CXX) | ||
|
||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
|
||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
# QtCreator supports the following variables for Android, which are identical to qmake Android variables. | ||
# Check https://doc.qt.io/qt/deployment-android.html for more information. | ||
# They need to be set before the find_package( ...) calls below. | ||
|
||
#if(ANDROID) | ||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") | ||
# if (ANDROID_ABI STREQUAL "armeabi-v7a") | ||
# set(ANDROID_EXTRA_LIBS | ||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so | ||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) | ||
# endif() | ||
#endif() | ||
|
||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Hamlib/include") | ||
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/Hamlib/libs/${ANDROID_ABI}/") | ||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/Hamlib/libs/${ANDROID_ABI}/libhamlib.so" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/android-build/libs/${ANDROID_ABI}/") | ||
|
||
find_package(QT NAMES Qt6 COMPONENTS Widgets Charts Network REQUIRED) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Charts Network REQUIRED) | ||
|
||
set(PROJECT_SOURCES | ||
main.cpp | ||
widget.cpp | ||
widget.h | ||
widget.ui | ||
polarwidget.cpp | ||
polarwidget.h | ||
) | ||
|
||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) | ||
qt_add_executable(androtator | ||
${PROJECT_SOURCES} | ||
) | ||
else() | ||
if(ANDROID) | ||
add_library(androtator SHARED | ||
${PROJECT_SOURCES} | ||
) | ||
else() | ||
add_executable(androtator | ||
${PROJECT_SOURCES} | ||
) | ||
endif() | ||
endif() | ||
|
||
target_link_libraries( | ||
androtator PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Charts | ||
Qt${QT_VERSION_MAJOR}::Network | ||
hamlib | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
# androtator | ||
Androtator helps you keep your antenna pointing to the satellite. Working with GPredict. | ||
# Androtator | ||
Androtator helps you keep your antenna pointing to the satellite. It run on Android 6 or later, and working with GPredict. | ||
|
||
## How to build | ||
1. Please put your NDK path after the "PATH" env, we need `ndk-build` to build Hamlib. | ||
|
||
`PATH=$PATH:<sdk path>/<ndk path>/<ndk version>` | ||
|
||
2. Build Hamlib. | ||
|
||
`./build_hamlib.sh` | ||
|
||
3. Build Androtaor using your Qt Creator. | ||
4. Open an issue tell me, if you get any errors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
cd Hamlib | ||
|
||
#help us get "hamlibdatetime.h" file | ||
./bootstrap | ||
./configure | ||
make | ||
|
||
#build it. | ||
android/hamlib-compile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "widget.h" | ||
|
||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
Widget w; | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "polarwidget.h" | ||
|
||
PolarWidget::PolarWidget(QWidget *parent) : QChartView(parent) | ||
{ | ||
chart = new QPolarChart(); | ||
|
||
angularAxis = new QValueAxis(); | ||
angularAxis->setTickCount(9); // First and last ticks are co-located on 0/360 angle. | ||
angularAxis->setLabelFormat("%.1f"); | ||
angularAxis->setShadesVisible(true); | ||
angularAxis->setShadesBrush(QBrush(QColor(249, 249, 255))); | ||
angularAxis->setRange(angularMin, angularMax); | ||
chart->addAxis(angularAxis, QPolarChart::PolarOrientationAngular); | ||
|
||
radialAxis = new QValueAxis(); | ||
radialAxis->setTickCount(4); | ||
radialAxis->setLabelsVisible(false); | ||
radialAxis->setRange(radialMin, radialMax); | ||
chart->addAxis(radialAxis, QPolarChart::PolarOrientationRadial); | ||
|
||
crosshair = new QScatterSeries(); | ||
chart->addSeries(crosshair); | ||
crosshair->setName("ANT"); | ||
crosshair->attachAxis(radialAxis); | ||
crosshair->attachAxis(angularAxis); | ||
|
||
circle = new QScatterSeries(); | ||
chart->addSeries(circle); | ||
circle->setName("SATE"); | ||
circle->attachAxis(radialAxis); | ||
circle->attachAxis(angularAxis); | ||
|
||
this->setChart(chart); | ||
this->setRenderHint(QPainter::Antialiasing); | ||
} | ||
|
||
void PolarWidget::setCrosshairPoint(float yaw, float pitch) | ||
{ | ||
crosshair->clear(); | ||
|
||
if(yaw < angularMin) | ||
yaw += angularMax - angularMin; | ||
if(yaw > angularMax) | ||
yaw -= angularMax - angularMin; | ||
if(pitch<radialMin) | ||
{ | ||
pitch = radialMin; | ||
crosshair->setColor(QColor("red")); | ||
} | ||
else | ||
crosshair->setColor(QColor("blue")); | ||
|
||
crosshair->append(yaw, pitch * -1 + radialMax); | ||
} | ||
|
||
void PolarWidget::setCirclePoint(float yaw, float pitch) | ||
{ | ||
circle->clear(); | ||
|
||
if(yaw < angularMin) | ||
yaw += angularMax - angularMin; | ||
if(yaw > angularMax) | ||
yaw -= angularMax - angularMin; | ||
pitch = pitch<radialMin ? radialMin : pitch; | ||
|
||
circle->append(yaw, pitch * -1 + radialMax); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef POLARWIDGET_H | ||
#define POLARWIDGET_H | ||
|
||
#include <QWidget> | ||
#include <QtCharts/QChartView> | ||
#include <QtCharts/QPolarChart> | ||
#include <QtCharts/QValueAxis> | ||
#include <QtCharts/QScatterSeries> | ||
|
||
class PolarWidget : public QChartView | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit PolarWidget(QWidget *parent = nullptr); | ||
|
||
private: | ||
const qreal angularMin = 0; | ||
const qreal angularMax = 360; | ||
const qreal radialMin = 0; | ||
const qreal radialMax = 90; | ||
|
||
QPolarChart *chart; | ||
QValueAxis *angularAxis; | ||
QValueAxis *radialAxis; | ||
|
||
QScatterSeries *crosshair; | ||
QScatterSeries *circle; | ||
|
||
signals: | ||
|
||
public slots: | ||
void setCrosshairPoint(float yaw, float pitch); | ||
void setCirclePoint(float yaw, float pitch); | ||
}; | ||
|
||
#endif // POLARWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "widget.h" | ||
#include "./ui_widget.h" | ||
|
||
#include <unistd.h> | ||
|
||
Widget::Widget(QWidget *parent) | ||
: QWidget(parent) | ||
, ui(new Ui::Widget) | ||
{ | ||
ui->setupUi(this); | ||
|
||
pipe(rot_in); | ||
pipe(rot_out); | ||
|
||
rot_model_t rotModel = ROT_MODEL_ANDROIDSENSOR; | ||
rot = rot_init(rotModel); | ||
|
||
timer = new QTimer(this); | ||
connect(timer, &QTimer::timeout, this, &Widget::timeout); | ||
timer->start(20); | ||
|
||
server = new QTcpServer(this); | ||
connect(server, &QTcpServer::newConnection, this, &Widget::serverNewConnection); | ||
server->listen(QHostAddress::Any, 4533); | ||
|
||
client = NULL; | ||
} | ||
|
||
Widget::~Widget() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void Widget::serverNewConnection() | ||
{ | ||
while (server->hasPendingConnections()) { | ||
if(client != NULL) { | ||
disconnect(client, &QTcpSocket::readyRead, this, &Widget::clientReadyRead); | ||
client->close(); | ||
client->deleteLater(); | ||
} | ||
|
||
client = server->nextPendingConnection(); | ||
connect(client, &QTcpSocket::readyRead, this, &Widget::clientReadyRead); | ||
} | ||
} | ||
|
||
void Widget::clientReadyRead() | ||
{ | ||
float az, el; | ||
|
||
QTextStream readText(client->readAll()); | ||
|
||
char head = readText.read(1).toLatin1().at(0); | ||
switch (head) { | ||
case 'P':{ | ||
readText >> az >> el; | ||
rot->caps->set_position(rot, az, el); | ||
client->write("RPRT 0\n"); | ||
break; | ||
} | ||
case 'p': | ||
{ | ||
rot->caps->get_position(rot, &az, &el); | ||
QString writeText = QString::number(az,'f',2) + "\n" + QString::number(el,'f',2) + "\n"; | ||
client->write(writeText.toLatin1()); | ||
break; | ||
} | ||
default: | ||
{ | ||
client->write("RPRT -1\n"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
||
void Widget::timeout() | ||
{ | ||
struct androidsensor_rot_priv_data | ||
{ | ||
void *imu; | ||
azimuth_t target_az; | ||
elevation_t target_el; | ||
}; | ||
|
||
struct androidsensor_rot_priv_data *priv = (struct androidsensor_rot_priv_data*)rot->state.priv; | ||
|
||
float az, el; | ||
rot->caps->get_position(rot, &az, &el); | ||
|
||
ui->polarWidget->setCrosshairPoint(az, el); | ||
ui->polarWidget->setCirclePoint(priv->target_az, priv->target_el); | ||
} | ||
|
||
void Widget::on_pushButton_clicked() | ||
{ | ||
server->close(); | ||
server->listen(QHostAddress::Any, ui->lineEdit->text().toUInt()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef WIDGET_H | ||
#define WIDGET_H | ||
|
||
#include <QWidget> | ||
#include <QTimer> | ||
#include <QtNetwork/QTcpServer> | ||
#include <QtNetwork/QTcpSocket> | ||
|
||
#include <hamlib/rotator.h> | ||
|
||
QT_BEGIN_NAMESPACE | ||
namespace Ui { class Widget; } | ||
QT_END_NAMESPACE | ||
|
||
class Widget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
Widget(QWidget *parent = nullptr); | ||
~Widget(); | ||
|
||
private slots: | ||
void serverNewConnection(); | ||
void clientReadyRead(); | ||
void timeout(); | ||
|
||
void on_pushButton_clicked(); | ||
|
||
private: | ||
Ui::Widget *ui; | ||
QTimer *timer; | ||
QTcpServer *server; | ||
QTcpSocket *client; | ||
ROT *rot; /* handle to rot (instance) */ | ||
int rot_in[2], rot_out[2]; | ||
}; | ||
#endif // WIDGET_H |
Oops, something went wrong.