Skip to content

Commit

Permalink
Add mobile tcp connection
Browse files Browse the repository at this point in the history
  • Loading branch information
walmis committed Dec 20, 2019
1 parent 9e22edc commit fb94f8c
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 37 deletions.
72 changes: 36 additions & 36 deletions android/src/com/vedder/vesc/VForegroundService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.app.NotificationChannel;
import android.app.NotificationManager;
//import android.app.NotificationChannel;
//import android.app.NotificationManager;
import android.os.Build;

import vedder.vesctool.R;
Expand Down Expand Up @@ -72,44 +72,44 @@ public int onStartCommand(Intent intent, int flags, int startId) {

private void startForegroundService()
{
// Create notification default intent.
Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

Notification.Builder builder;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = "VESC_CHANNEL";
NotificationChannel channel = new NotificationChannel(channelId, "VESC", NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("VESC GNSS");
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
builder = new Notification.Builder(this, channelId);
} else {
builder = new Notification.Builder(this);
}

builder.setContentTitle("VESC Tool GNSS");
builder.setContentText("VESC Tool is keeping GNSS alive.");

builder.setWhen(System.currentTimeMillis());
builder.setSmallIcon(R.drawable.icon);

// builder.setFullScreenIntent(pendingIntent, true);

Intent stopIntent = new Intent(this, VForegroundService.class);
stopIntent.setAction(ACTION_STOP);
PendingIntent pendingPrevIntent = PendingIntent.getService(this, 0, stopIntent, 0);
Notification.Action prevAction = new Notification.Action(android.R.drawable.ic_media_pause, "Stop", pendingPrevIntent);
builder.addAction(prevAction);

startForeground(1, builder.build());
// // Create notification default intent.
// Intent intent = new Intent();
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

// Notification.Builder builder;

// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// String channelId = "VESC_CHANNEL";
// NotificationChannel channel = new NotificationChannel(channelId, "VESC", NotificationManager.IMPORTANCE_DEFAULT);
// channel.setDescription("VESC GNSS");
// NotificationManager notificationManager = getSystemService(NotificationManager.class);
// notificationManager.createNotificationChannel(channel);
// builder = new Notification.Builder(this, channelId);
// } else {
// builder = new Notification.Builder(this);
// }

// builder.setContentTitle("VESC Tool GNSS");
// builder.setContentText("VESC Tool is keeping GNSS alive.");

// builder.setWhen(System.currentTimeMillis());
// builder.setSmallIcon(R.drawable.icon);

//// builder.setFullScreenIntent(pendingIntent, true);

// Intent stopIntent = new Intent(this, VForegroundService.class);
// stopIntent.setAction(ACTION_STOP);
// PendingIntent pendingPrevIntent = PendingIntent.getService(this, 0, stopIntent, 0);
// Notification.Action prevAction = new Notification.Action(android.R.drawable.ic_media_pause, "Stop", pendingPrevIntent);
// builder.addAction(prevAction);

// startForeground(1, builder.build());
}

private void stopForegroundService()
{
stopForeground(true);
stopSelf();
// stopForeground(true);
// stopSelf();
}
}

86 changes: 86 additions & 0 deletions mobile/ConnectBle.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Item {
contentWidth: parent.width
clip: true



GridLayout {
id: grid
anchors.fill: parent
Expand All @@ -55,6 +57,84 @@ Item {
source: "qrc:/res/logo_white.png"
}

GroupBox {
id: tcpConnBox
title: qsTr("TCP Connection")

Layout.fillWidth: true
Layout.columnSpan: 1

GridLayout {
anchors.topMargin: -5
anchors.bottomMargin: -5
anchors.fill: parent

clip: false
visible: true
rowSpacing: -10
columnSpacing: 5
rows: 5
columns: 6


Rectangle {
Layout.fillWidth: true
Layout.columnSpan: 5
Layout.topMargin: 6
Layout.bottomMargin: 6
Layout.preferredWidth:500
height: rtLogFileText.implicitHeight + 14
border.width: 2
border.color: "#8d8d8d"
color: "#33a8a8a8"
radius: 3

TextInput {
color: "white"
id: tcpServer
anchors.fill: parent
anchors.margins: 7
font.pointSize: 12
text: VescIf.getLastTcpServer()
}
}

Rectangle {
Layout.fillWidth: true
Layout.columnSpan: 1
Layout.topMargin: 6
Layout.bottomMargin: 6
Layout.preferredWidth:100
height: tcpPort.implicitHeight + 14
border.width: 2
border.color: "#8d8d8d"
color: "#33a8a8a8"
radius: 3

TextInput {
color: "white"
id: tcpPort
anchors.fill: parent
anchors.margins: 7
font.pointSize: 12
text: VescIf.getLastTcpPort()
}

}

Button {
Layout.fillWidth: true
Layout.preferredWidth:500
Layout.columnSpan: 6
text: "Connect"

onClicked: {
VescIf.connectTcp(tcpServer.text, parseInt(tcpPort.text))
}
}
}
}

GroupBox {
id: bleConnBox
title: qsTr("BLE Connection")
Expand Down Expand Up @@ -572,3 +652,9 @@ Item {
}
}
}

/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/
2 changes: 1 addition & 1 deletion vescinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ VescInterface::VescInterface(QObject *parent) : QObject(parent)
mTcpConnected = false;
mLastTcpServer = QSettings().value("tcp_server", "").toString();
mLastTcpPort = QSettings().value("tcp_port", 65102).toInt();

mTcpSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
connect(mTcpSocket, SIGNAL(readyRead()), this, SLOT(tcpInputDataAvailable()));
connect(mTcpSocket, SIGNAL(connected()), this, SLOT(tcpInputConnected()));
connect(mTcpSocket, SIGNAL(disconnected()),
Expand Down

0 comments on commit fb94f8c

Please sign in to comment.