Skip to content

Commit

Permalink
Init codes
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraRAS committed Oct 8, 2021
1 parent a7bdf9d commit 2e17e46
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
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
63 changes: 63 additions & 0 deletions CMakeLists.txt
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
)
1 change: 1 addition & 0 deletions Hamlib
Submodule Hamlib added at 210342
16 changes: 14 additions & 2 deletions README.md
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.
11 changes: 11 additions & 0 deletions build_hamlib.sh
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
11 changes: 11 additions & 0 deletions main.cpp
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();
}
67 changes: 67 additions & 0 deletions polarwidget.cpp
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);
}
36 changes: 36 additions & 0 deletions polarwidget.h
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
100 changes: 100 additions & 0 deletions widget.cpp
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());
}
38 changes: 38 additions & 0 deletions widget.h
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
Loading

0 comments on commit 2e17e46

Please # to comment.