mirror of
https://github.com/cagnulein/qdomyos-zwift.git
synced 2026-02-18 00:17:41 +01:00
Compare commits
13 Commits
build-1014
...
ios_adb_th
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1ea0e18a1 | ||
|
|
34025b2542 | ||
|
|
85f5275342 | ||
|
|
e25ea93c38 | ||
|
|
26e8da19f2 | ||
|
|
2c5f5b5554 | ||
|
|
984ccef3d6 | ||
|
|
ff8b917744 | ||
|
|
f1134b1c51 | ||
|
|
766faeb9b5 | ||
|
|
98bf761c87 | ||
|
|
2922d231be | ||
|
|
43772ea906 |
@@ -114,6 +114,9 @@
|
||||
7EC1321DD83EAAFAA2B7109C /* domyosbike.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 7944A61A6F17291731CE6F84 /* domyosbike.cpp */; settings = {ATTRIBUTES = (); }; };
|
||||
8556B13A3D02D52A21FC5E3E /* bluetooth.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = B0BE11FB9531A6AD480B20E7 /* bluetooth.cpp */; settings = {ATTRIBUTES = (); }; };
|
||||
868B65D0AB5114A4A0D5479E /* qmldbg_messages in Link Binary With Libraries */ = {isa = PBXBuildFile; fileRef = 008F20821C7E4D5F7DB55754 /* qmldbg_messages */; };
|
||||
8701142A2B14D5A800193FC6 /* moc_eliteariafan.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 870114292B14D5A800193FC6 /* moc_eliteariafan.cpp */; };
|
||||
8701142D2B14D5C600193FC6 /* eliteariafan.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 8701142C2B14D5C600193FC6 /* eliteariafan.cpp */; };
|
||||
870114302B14D5F400193FC6 /* ios_eliteariafan.mm in Compile Sources */ = {isa = PBXBuildFile; fileRef = 8701142E2B14D5F400193FC6 /* ios_eliteariafan.mm */; };
|
||||
8703BAEB273C67A90058E206 /* pafersbike.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 8703BAE9273C67A90058E206 /* pafersbike.cpp */; };
|
||||
8703BAED273C67B60058E206 /* moc_pafersbike.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 8703BAEC273C67B50058E206 /* moc_pafersbike.cpp */; };
|
||||
87061390286D8B4F00D2446E /* libQt5PositioningQuick.a in Link Binary With Libraries */ = {isa = PBXBuildFile; fileRef = 8706138F286D8B4F00D2446E /* libQt5PositioningQuick.a */; };
|
||||
@@ -824,6 +827,11 @@
|
||||
867187CB3CB3703D1925C88A /* fit_weather_conditions_mesg_listener.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = fit_weather_conditions_mesg_listener.hpp; path = "/Users/cagnulein/qdomyos-zwift/src/fit-sdk/fit_weather_conditions_mesg_listener.hpp"; sourceTree = "<absolute>"; };
|
||||
86DD72842A64993F31E31719 /* fit_ant_rx_mesg_listener.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = fit_ant_rx_mesg_listener.hpp; path = "/Users/cagnulein/qdomyos-zwift/src/fit-sdk/fit_ant_rx_mesg_listener.hpp"; sourceTree = "<absolute>"; };
|
||||
86F10E1AE2D47520E65C0543 /* fit_dive_summary_mesg_listener.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = fit_dive_summary_mesg_listener.hpp; path = "/Users/cagnulein/qdomyos-zwift/src/fit-sdk/fit_dive_summary_mesg_listener.hpp"; sourceTree = "<absolute>"; };
|
||||
870114292B14D5A800193FC6 /* moc_eliteariafan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = moc_eliteariafan.cpp; sourceTree = "<group>"; };
|
||||
8701142B2B14D5C600193FC6 /* eliteariafan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = eliteariafan.h; path = ../src/eliteariafan.h; sourceTree = "<group>"; };
|
||||
8701142C2B14D5C600193FC6 /* eliteariafan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = eliteariafan.cpp; path = ../src/eliteariafan.cpp; sourceTree = "<group>"; };
|
||||
8701142E2B14D5F400193FC6 /* ios_eliteariafan.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ios_eliteariafan.mm; path = ../src/ios/ios_eliteariafan.mm; sourceTree = "<group>"; };
|
||||
8701142F2B14D5F400193FC6 /* ios_eliteariafan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ios_eliteariafan.h; path = ../src/ios/ios_eliteariafan.h; sourceTree = "<group>"; };
|
||||
8703BAE9273C67A90058E206 /* pafersbike.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = pafersbike.cpp; path = ../src/pafersbike.cpp; sourceTree = "<group>"; };
|
||||
8703BAEA273C67A90058E206 /* pafersbike.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pafersbike.h; path = ../src/pafersbike.h; sourceTree = "<group>"; };
|
||||
8703BAEC273C67B50058E206 /* moc_pafersbike.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = moc_pafersbike.cpp; sourceTree = "<group>"; };
|
||||
|
||||
@@ -49,6 +49,9 @@ public class QZAdbRemote implements DeviceConnectionListener {
|
||||
|
||||
private static QZAdbRemote INSTANCE;
|
||||
|
||||
private static String receiveBuffer = "";
|
||||
private static String receiveOldBuffer = "";
|
||||
|
||||
public static QZAdbRemote getInstance() {
|
||||
if(INSTANCE == null) {
|
||||
INSTANCE = new QZAdbRemote();
|
||||
@@ -93,7 +96,6 @@ public class QZAdbRemote implements DeviceConnectionListener {
|
||||
|
||||
@Override
|
||||
public void receivedData(DeviceConnection devConn, byte[] data, int offset, int length) {
|
||||
Log.i(LOG_TAG, data.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,7 +105,8 @@ public class QZAdbRemote implements DeviceConnectionListener {
|
||||
|
||||
@Override
|
||||
public void consoleUpdated(DeviceConnection devConn, ConsoleBuffer console) {
|
||||
|
||||
receiveBuffer += new String(console.buffer);
|
||||
Log.i(LOG_TAG, new String(console.buffer));
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +198,12 @@ public class QZAdbRemote implements DeviceConnectionListener {
|
||||
}
|
||||
}
|
||||
|
||||
static public String getReceiveData() {
|
||||
receiveOldBuffer = receiveBuffer;
|
||||
receiveBuffer = "";
|
||||
return receiveOldBuffer;
|
||||
}
|
||||
|
||||
static public void sendCommand(String command) {
|
||||
Log.d(LOG_TAG, "sendCommand " + ADBConnected + " " + command);
|
||||
if(ADBConnected) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.cgutman.androidremotedebugger.console;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ConsoleBuffer {
|
||||
private char[] buffer;
|
||||
public char[] buffer;
|
||||
private int amountPopulated;
|
||||
|
||||
public ConsoleBuffer(int bufferSize)
|
||||
|
||||
@@ -62,7 +62,7 @@ class lockscreen {
|
||||
|
||||
//adb
|
||||
void adb_connect(const char* IP);
|
||||
void adb_sendcommand(const char* command);
|
||||
int adb_sendcommand(const char* command, unsigned char** buffer);
|
||||
|
||||
// Elite Aria Fan
|
||||
void eliteAriaFan();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <QDebug>
|
||||
#include "ios/AdbClient.h"
|
||||
#include "ios/ios_eliteariafan.h"
|
||||
#import <dispatch/dispatch.h>
|
||||
|
||||
@class virtualbike_ios_swift;
|
||||
@class virtualbike_zwift;
|
||||
@@ -270,6 +271,9 @@ void lockscreen::debug(const char* debugstring) {
|
||||
}
|
||||
|
||||
void lockscreen::adb_connect(const char* IP) {
|
||||
|
||||
qDebug() << "adb_connect" << IP << _adb;
|
||||
|
||||
if(_adb == 0) return;
|
||||
|
||||
[_adb connect:[NSString stringWithCString:IP encoding:NSASCIIStringEncoding] didResponse:^(BOOL succ, NSString *result) {
|
||||
@@ -279,16 +283,48 @@ void lockscreen::adb_connect(const char* IP) {
|
||||
}];
|
||||
}
|
||||
|
||||
void lockscreen::adb_sendcommand(const char* command) {
|
||||
if(_adb == 0) return;
|
||||
int lockscreen::adb_sendcommand(const char* command, unsigned char** outBuffer) {
|
||||
qDebug() << "adb_sendcommand" << command << _adb;
|
||||
|
||||
if(_adb == 0) return -1; // or some error code
|
||||
|
||||
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
|
||||
|
||||
qDebug() << "adb_sendcommand after semaphore";
|
||||
|
||||
__block int resultStatus = 0; // Use this to store the result status
|
||||
__block NSUInteger length = 0;
|
||||
|
||||
[_adb shell:[NSString stringWithCString:command encoding:NSASCIIStringEncoding] didResponse:^(BOOL succ, NSString *result) {
|
||||
|
||||
qDebug() << result;
|
||||
NSUInteger length = [result lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
// Allocate memory for the unsigned char*
|
||||
*outBuffer = (unsigned char *)malloc(length + 1);
|
||||
|
||||
// Copy the string into the buffer
|
||||
if (*outBuffer) {
|
||||
BOOL resultCopy = [result getCString:(char *)*outBuffer maxLength:length + 1 encoding:NSUTF8StringEncoding];
|
||||
if (!resultCopy) {
|
||||
// Handle the error if the string couldn't be copied
|
||||
free(*outBuffer);
|
||||
*outBuffer = NULL;
|
||||
resultStatus = -2; // or some error code
|
||||
}
|
||||
} else {
|
||||
resultStatus = -3; // or some error code
|
||||
}
|
||||
|
||||
dispatch_semaphore_signal(sem);
|
||||
}];
|
||||
|
||||
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
void lockscreen::eliteAriaFan() {
|
||||
ios_eliteAriaFan = [[ios_eliteariafan alloc] init];
|
||||
}
|
||||
|
||||
@@ -19,7 +19,20 @@ nordictrackifitadbbikeLogcatAdbThread::nordictrackifitadbbikeLogcatAdbThread(QSt
|
||||
void nordictrackifitadbbikeLogcatAdbThread::run() {
|
||||
QSettings settings;
|
||||
QString ip = settings.value(QZSettings::tdf_10_ip, QZSettings::default_tdf_10_ip).toString();
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject IP = QAndroidJniObject::fromString(ip).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote", "createConnection",
|
||||
"(Ljava/lang/String;Landroid/content/Context;)V",
|
||||
IP.object<jstring>(), QtAndroid::androidContext().object());
|
||||
#elif defined Q_OS_WIN
|
||||
runAdbCommand("connect " + ip);
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h = new lockscreen();
|
||||
h->adb_connect(ip.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
runAdbTailCommand("logcat");
|
||||
@@ -43,10 +56,32 @@ QString nordictrackifitadbbikeLogcatAdbThread::runAdbCommand(QString command) {
|
||||
|
||||
emit debug("adb << OUT " + out);
|
||||
emit debug("adb << ERR" + err);
|
||||
#else
|
||||
QString out;
|
||||
#endif
|
||||
|
||||
return out;
|
||||
#elif defined Q_OS_ANDROID
|
||||
qDebug() << "adbLogCat >> " << command;
|
||||
QAndroidJniObject c = QAndroidJniObject::fromString(command).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote",
|
||||
"sendCommand", "(Ljava/lang/String;)V",
|
||||
c.object<jstring>());
|
||||
QThread:msleep(100);
|
||||
QAndroidJniObject recv = QAndroidJniObject::callStaticObjectMethod<jstring>(
|
||||
"org/cagnulen/qdomyoszwift/QZAdbRemote", "getReceiveData");
|
||||
QString r = recv.toString();
|
||||
return r;
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
qDebug() << "adb >> " << command;
|
||||
unsigned char* tailMemoryBuffer = nullptr;
|
||||
int size = h->adb_sendcommand(command.toStdString().c_str(), &tailMemoryBuffer);
|
||||
if(tailMemoryBuffer) {
|
||||
QString output = QString::fromUtf8((const char*)tailMemoryBuffer);
|
||||
delete tailMemoryBuffer;
|
||||
return output;
|
||||
}
|
||||
return "";
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool nordictrackifitadbbikeLogcatAdbThread::runCommand(QString command) {
|
||||
@@ -99,6 +134,86 @@ void nordictrackifitadbbikeLogcatAdbThread::runAdbTailCommand(QString command) {
|
||||
emit debug("adbLogCat >> " + command);
|
||||
process->start("adb/adb.exe", QStringList(command.split(' ')));
|
||||
process->waitForFinished(-1);
|
||||
#elif defined Q_OS_ANDROID
|
||||
qDebug() << "adbLogCat >> " << command;
|
||||
QAndroidJniObject c = QAndroidJniObject::fromString(command).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote",
|
||||
"sendCommand", "(Ljava/lang/String;)V",
|
||||
c.object<jstring>());
|
||||
QString r = "";
|
||||
do {
|
||||
QAndroidJniObject recv = QAndroidJniObject::callStaticObjectMethod<jstring>(
|
||||
"org/cagnulen/qdomyoszwift/QZAdbRemote", "getReceiveData");
|
||||
r = recv.toString();
|
||||
QString output = r;
|
||||
QStringList lines = output.split('\n', Qt::SplitBehaviorFlags::SkipEmptyParts);
|
||||
bool wattFound = false;
|
||||
bool hrmFound = false;
|
||||
foreach (QString line, lines) {
|
||||
if (line.contains("Changed KPH")) {
|
||||
emit debug(line);
|
||||
speed = line.split(' ').last().toDouble();
|
||||
} else if (line.contains("Changed Grade")) {
|
||||
emit debug(line);
|
||||
inclination = line.split(' ').last().toDouble();
|
||||
} else if (line.contains("Changed Watts")) {
|
||||
emit debug(line);
|
||||
watt = line.split(' ').last().toDouble();
|
||||
wattFound = true;
|
||||
} else if (line.contains("HeartRateDataUpdate")) {
|
||||
emit debug(line);
|
||||
QStringList splitted = line.split(' ', Qt::SkipEmptyParts);
|
||||
if (splitted.length() > 14) {
|
||||
hrm = splitted[14].toInt();
|
||||
hrmFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
emit onSpeedInclination(speed, inclination);
|
||||
if (wattFound)
|
||||
emit onWatt(watt);
|
||||
if (hrmFound)
|
||||
emit onHRM(hrm);
|
||||
} while (r.length());
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
qDebug() << "adbLogCat >> " << command;
|
||||
unsigned char* tailMemoryBuffer = nullptr;
|
||||
int size = h->adb_sendcommand("logcat", &tailMemoryBuffer);
|
||||
|
||||
if(tailMemoryBuffer) {
|
||||
QString output = QString::fromUtf8((const char*)tailMemoryBuffer);
|
||||
QStringList lines = output.split('\n', Qt::SplitBehaviorFlags::SkipEmptyParts);
|
||||
bool wattFound = false;
|
||||
bool hrmFound = false;
|
||||
foreach (QString line, lines) {
|
||||
if (line.contains("Changed KPH")) {
|
||||
emit debug(line);
|
||||
speed = line.split(' ').last().toDouble();
|
||||
} else if (line.contains("Changed Grade")) {
|
||||
emit debug(line);
|
||||
inclination = line.split(' ').last().toDouble();
|
||||
} else if (line.contains("Changed Watts")) {
|
||||
emit debug(line);
|
||||
watt = line.split(' ').last().toDouble();
|
||||
wattFound = true;
|
||||
} else if (line.contains("HeartRateDataUpdate")) {
|
||||
emit debug(line);
|
||||
QStringList splitted = line.split(' ', Qt::SkipEmptyParts);
|
||||
if (splitted.length() > 14) {
|
||||
hrm = splitted[14].toInt();
|
||||
hrmFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
emit onSpeedInclination(speed, inclination);
|
||||
if (wattFound)
|
||||
emit onWatt(watt);
|
||||
if (hrmFound)
|
||||
emit onHRM(hrm);
|
||||
delete tailMemoryBuffer;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -154,12 +269,6 @@ nordictrackifitadbbike::nordictrackifitadbbike(bool noWriteResistance, bool noHe
|
||||
// ********************************************************************************************************
|
||||
|
||||
if (nordictrack_ifit_adb_remote) {
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject IP = QAndroidJniObject::fromString(ip).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote", "createConnection",
|
||||
"(Ljava/lang/String;Landroid/content/Context;)V",
|
||||
IP.object<jstring>(), QtAndroid::androidContext().object());
|
||||
#elif defined Q_OS_WIN
|
||||
logcatAdbThread = new nordictrackifitadbbikeLogcatAdbThread("logcatAdbThread");
|
||||
/*connect(logcatAdbThread, &nordictrackifitadbbikeLogcatAdbThread::onSpeedInclination, this,
|
||||
&nordictrackifitadbbike::onSpeedInclination);
|
||||
@@ -168,11 +277,6 @@ nordictrackifitadbbike::nordictrackifitadbbike(bool noWriteResistance, bool noHe
|
||||
connect(logcatAdbThread, &nordictrackifitadbbikeLogcatAdbThread::onHRM, this, &nordictrackifitadbbike::onHRM);
|
||||
connect(logcatAdbThread, &nordictrackifitadbbikeLogcatAdbThread::debug, this, &nordictrackifitadbbike::debug);
|
||||
logcatAdbThread->start();
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h->adb_connect(ip.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,19 +396,9 @@ void nordictrackifitadbbike::processPendingDatagrams() {
|
||||
lastCommand = "input swipe " + QString::number(x1) + " " + QString::number(y1Resistance) + " " +
|
||||
QString::number(x1) + " " + QString::number(y2) + " 200";
|
||||
qDebug() << " >> " + lastCommand;
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject command = QAndroidJniObject::fromString(lastCommand).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote",
|
||||
"sendCommand", "(Ljava/lang/String;)V",
|
||||
command.object<jstring>());
|
||||
#elif defined(Q_OS_WIN)
|
||||
|
||||
if (logcatAdbThread)
|
||||
logcatAdbThread->runCommand("shell " + lastCommand);
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h->adb_sendcommand(lastCommand.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,19 +431,10 @@ void nordictrackifitadbbike::processPendingDatagrams() {
|
||||
lastCommand = "input swipe " + QString::number(x1) + " " + QString::number(y1Resistance) + " " +
|
||||
QString::number(x1) + " " + QString::number(y2) + " 200";
|
||||
qDebug() << " >> " + lastCommand;
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject command = QAndroidJniObject::fromString(lastCommand).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote",
|
||||
"sendCommand", "(Ljava/lang/String;)V",
|
||||
command.object<jstring>());
|
||||
#elif defined(Q_OS_WIN)
|
||||
|
||||
if (logcatAdbThread)
|
||||
logcatAdbThread->runCommand("shell " + lastCommand);
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h->adb_sendcommand(lastCommand.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// this bike has both inclination and resistance, let's try to handle both
|
||||
if(freemotion_coachbike_b22_7) {
|
||||
int x1 = 75;
|
||||
@@ -359,19 +444,9 @@ void nordictrackifitadbbike::processPendingDatagrams() {
|
||||
lastCommand = "input swipe " + QString::number(x1) + " " + QString::number(y1Resistance) + " " +
|
||||
QString::number(x1) + " " + QString::number(y2) + " 200";
|
||||
qDebug() << " >> " + lastCommand;
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject command = QAndroidJniObject::fromString(lastCommand).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote",
|
||||
"sendCommand", "(Ljava/lang/String;)V",
|
||||
command.object<jstring>());
|
||||
#elif defined(Q_OS_WIN)
|
||||
|
||||
if (logcatAdbThread)
|
||||
logcatAdbThread->runCommand("shell " + lastCommand);
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h->adb_sendcommand(lastCommand.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +53,12 @@ class nordictrackifitadbbikeLogcatAdbThread : public QThread {
|
||||
QDateTime date;
|
||||
QString name;
|
||||
};
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
lockscreen *h = 0;
|
||||
#endif
|
||||
|
||||
void runAdbTailCommand(QString command);
|
||||
void runAdbTailCommand(QString command);
|
||||
};
|
||||
|
||||
class nordictrackifitadbbike : public bike {
|
||||
@@ -99,7 +103,7 @@ class nordictrackifitadbbike : public bike {
|
||||
#ifdef Q_OS_IOS
|
||||
lockscreen *h = 0;
|
||||
#endif
|
||||
|
||||
|
||||
signals:
|
||||
void disconnected();
|
||||
void debug(QString string);
|
||||
|
||||
@@ -20,20 +20,29 @@ nordictrackifitadbtreadmillLogcatAdbThread::nordictrackifitadbtreadmillLogcatAdb
|
||||
void nordictrackifitadbtreadmillLogcatAdbThread::run() {
|
||||
QSettings settings;
|
||||
QString ip = settings.value(QZSettings::nordictrack_2950_ip, QZSettings::default_nordictrack_2950_ip).toString();
|
||||
runAdbCommand("connect " + ip);
|
||||
|
||||
while (!stop)
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject IP = QAndroidJniObject::fromString(ip).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote", "createConnection",
|
||||
"(Ljava/lang/String;Landroid/content/Context;)V",
|
||||
IP.object<jstring>(), QtAndroid::androidContext().object());
|
||||
#elif defined Q_OS_WIN
|
||||
runAdbCommand("connect " + ip);
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h = new lockscreen();
|
||||
h->adb_connect(ip.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
runAdbTailCommand("logcat");
|
||||
#ifndef Q_OS_WINDOWS
|
||||
if(adbCommandPending.length() != 0) {
|
||||
runAdbCommand(adbCommandPending);
|
||||
adbCommandPending = "";
|
||||
}
|
||||
msleep(100);
|
||||
#endif
|
||||
msleep(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString nordictrackifitadbtreadmillLogcatAdbThread::runAdbCommand(QString command) {
|
||||
@@ -48,10 +57,32 @@ QString nordictrackifitadbtreadmillLogcatAdbThread::runAdbCommand(QString comman
|
||||
|
||||
emit debug("adb << OUT " + out);
|
||||
emit debug("adb << ERR" + err);
|
||||
#else
|
||||
QString out;
|
||||
#endif
|
||||
|
||||
return out;
|
||||
#elif defined Q_OS_ANDROID
|
||||
qDebug() << "adbLogCat >> " << command;
|
||||
QAndroidJniObject c = QAndroidJniObject::fromString(command).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote",
|
||||
"sendCommand", "(Ljava/lang/String;)V",
|
||||
c.object<jstring>());
|
||||
QThread:msleep(100);
|
||||
QAndroidJniObject recv = QAndroidJniObject::callStaticObjectMethod<jstring>(
|
||||
"org/cagnulen/qdomyoszwift/QZAdbRemote", "getReceiveData");
|
||||
QString r = recv.toString();
|
||||
return r;
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
qDebug() << "adb >> " << command;
|
||||
unsigned char* tailMemoryBuffer = nullptr;
|
||||
int size = h->adb_sendcommand(command.toStdString().c_str(), &tailMemoryBuffer);
|
||||
if(tailMemoryBuffer) {
|
||||
QString output = QString::fromUtf8((const char*)tailMemoryBuffer);
|
||||
delete tailMemoryBuffer;
|
||||
return output;
|
||||
}
|
||||
return "";
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool nordictrackifitadbtreadmillLogcatAdbThread::runCommand(QString command) {
|
||||
@@ -104,6 +135,87 @@ void nordictrackifitadbtreadmillLogcatAdbThread::runAdbTailCommand(QString comma
|
||||
emit debug("adbLogCat >> " + command);
|
||||
process->start("adb/adb.exe", QStringList(command.split(' ')));
|
||||
process->waitForFinished(-1);
|
||||
#elif defined Q_OS_ANDROID
|
||||
qDebug() << "adbLogCat >> " << command;
|
||||
QAndroidJniObject c = QAndroidJniObject::fromString(command).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote",
|
||||
"sendCommand", "(Ljava/lang/String;)V",
|
||||
c.object<jstring>());
|
||||
QString r = "";
|
||||
do {
|
||||
QAndroidJniObject recv = QAndroidJniObject::callStaticObjectMethod<jstring>(
|
||||
"org/cagnulen/qdomyoszwift/QZAdbRemote", "getReceiveData");
|
||||
r = recv.toString();
|
||||
qDebug() << " << " << r;
|
||||
QString output = r;
|
||||
QStringList lines = output.split('\n', Qt::SplitBehaviorFlags::SkipEmptyParts);
|
||||
bool wattFound = false;
|
||||
bool hrmFound = false;
|
||||
foreach (QString line, lines) {
|
||||
if (line.contains("Changed KPH")) {
|
||||
emit debug(line);
|
||||
speed = line.split(' ').last().toDouble();
|
||||
} else if (line.contains("Changed Grade")) {
|
||||
emit debug(line);
|
||||
inclination = line.split(' ').last().toDouble();
|
||||
} else if (line.contains("Changed Watts")) {
|
||||
emit debug(line);
|
||||
watt = line.split(' ').last().toDouble();
|
||||
wattFound = true;
|
||||
} else if (line.contains("HeartRateDataUpdate")) {
|
||||
emit debug(line);
|
||||
QStringList splitted = line.split(' ', Qt::SkipEmptyParts);
|
||||
if (splitted.length() > 14) {
|
||||
hrm = splitted[14].toInt();
|
||||
hrmFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
emit onSpeedInclination(speed, inclination);
|
||||
if (wattFound)
|
||||
emit onWatt(watt);
|
||||
if (hrmFound)
|
||||
emit onHRM(hrm);
|
||||
} while (r.length());
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
qDebug() << "adbLogCat >> " << command;
|
||||
unsigned char* tailMemoryBuffer = nullptr;
|
||||
int size = h->adb_sendcommand("logcat", &tailMemoryBuffer);
|
||||
|
||||
if(tailMemoryBuffer) {
|
||||
QString output = QString::fromUtf8((const char*)tailMemoryBuffer);
|
||||
QStringList lines = output.split('\n', Qt::SplitBehaviorFlags::SkipEmptyParts);
|
||||
bool wattFound = false;
|
||||
bool hrmFound = false;
|
||||
foreach (QString line, lines) {
|
||||
if (line.contains("Changed KPH")) {
|
||||
emit debug(line);
|
||||
speed = line.split(' ').last().toDouble();
|
||||
} else if (line.contains("Changed Grade")) {
|
||||
emit debug(line);
|
||||
inclination = line.split(' ').last().toDouble();
|
||||
} else if (line.contains("Changed Watts")) {
|
||||
emit debug(line);
|
||||
watt = line.split(' ').last().toDouble();
|
||||
wattFound = true;
|
||||
} else if (line.contains("HeartRateDataUpdate")) {
|
||||
emit debug(line);
|
||||
QStringList splitted = line.split(' ', Qt::SkipEmptyParts);
|
||||
if (splitted.length() > 14) {
|
||||
hrm = splitted[14].toInt();
|
||||
hrmFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
emit onSpeedInclination(speed, inclination);
|
||||
if (wattFound)
|
||||
emit onWatt(watt);
|
||||
if (hrmFound)
|
||||
emit onHRM(hrm);
|
||||
delete tailMemoryBuffer;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -131,38 +243,14 @@ nordictrackifitadbtreadmill::nordictrackifitadbtreadmill(bool noWriteResistance,
|
||||
QString ip = settings.value(QZSettings::nordictrack_2950_ip, QZSettings::default_nordictrack_2950_ip).toString();
|
||||
|
||||
refresh->start(200ms);
|
||||
{
|
||||
socket = new QUdpSocket(this);
|
||||
bool result = socket->bind(QHostAddress::AnyIPv4, 8002);
|
||||
qDebug() << result;
|
||||
processPendingDatagrams();
|
||||
connect(socket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));
|
||||
}
|
||||
#ifdef Q_OS_WIN32
|
||||
{
|
||||
logcatAdbThread = new nordictrackifitadbtreadmillLogcatAdbThread("logcatAdbThread");
|
||||
connect(logcatAdbThread, &nordictrackifitadbtreadmillLogcatAdbThread::onSpeedInclination, this,
|
||||
&nordictrackifitadbtreadmill::onSpeedInclination);
|
||||
connect(logcatAdbThread, &nordictrackifitadbtreadmillLogcatAdbThread::onWatt, this,
|
||||
&nordictrackifitadbtreadmill::onWatt);
|
||||
connect(logcatAdbThread, &nordictrackifitadbtreadmillLogcatAdbThread::debug, this,
|
||||
&nordictrackifitadbtreadmill::debug);
|
||||
logcatAdbThread->start();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (nordictrack_ifit_adb_remote) {
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject IP = QAndroidJniObject::fromString(ip).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote", "createConnection",
|
||||
"(Ljava/lang/String;Landroid/content/Context;)V",
|
||||
IP.object<jstring>(), QtAndroid::androidContext().object());
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h->adb_connect(ip.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
logcatAdbThread = new nordictrackifitadbtreadmillLogcatAdbThread("logcatAdbThread");
|
||||
connect(logcatAdbThread, &nordictrackifitadbtreadmillLogcatAdbThread::onSpeedInclination, this,
|
||||
&nordictrackifitadbtreadmill::onSpeedInclination);
|
||||
connect(logcatAdbThread, &nordictrackifitadbtreadmillLogcatAdbThread::onWatt, this,
|
||||
&nordictrackifitadbtreadmill::onWatt);
|
||||
connect(logcatAdbThread, &nordictrackifitadbtreadmillLogcatAdbThread::debug, this,
|
||||
&nordictrackifitadbtreadmill::debug);
|
||||
logcatAdbThread->start();
|
||||
|
||||
initRequest = true;
|
||||
|
||||
@@ -283,18 +371,9 @@ void nordictrackifitadbtreadmill::processPendingDatagrams() {
|
||||
lastCommand = "input swipe " + QString::number(x1) + " " + QString::number(y1Speed) + " " +
|
||||
QString::number(x1) + " " + QString::number(y2) + " 200";
|
||||
qDebug() << " >> " + lastCommand;
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject command = QAndroidJniObject::fromString(lastCommand).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote", "sendCommand",
|
||||
"(Ljava/lang/String;)V", command.object<jstring>());
|
||||
#elif defined(Q_OS_WIN)
|
||||
if (logcatAdbThread)
|
||||
logcatAdbThread->runCommand("shell " + lastCommand);
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h->adb_sendcommand(lastCommand.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
if (logcatAdbThread)
|
||||
logcatAdbThread->runCommand("shell " + lastCommand);
|
||||
|
||||
requestSpeed = -1;
|
||||
} else if (currentRequestInclination != -100) {
|
||||
requestInclination = inc;
|
||||
@@ -312,18 +391,10 @@ void nordictrackifitadbtreadmill::processPendingDatagrams() {
|
||||
lastCommand = "input swipe " + QString::number(x1) + " " + QString::number(y1Inclination) + " " +
|
||||
QString::number(x1) + " " + QString::number(y2) + " 200";
|
||||
qDebug() << " >> " + lastCommand;
|
||||
#ifdef Q_OS_ANDROID
|
||||
QAndroidJniObject command = QAndroidJniObject::fromString(lastCommand).object<jstring>();
|
||||
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/QZAdbRemote", "sendCommand",
|
||||
"(Ljava/lang/String;)V", command.object<jstring>());
|
||||
#elif defined(Q_OS_WIN)
|
||||
if (logcatAdbThread)
|
||||
logcatAdbThread->runCommand("shell " + lastCommand);
|
||||
#elif defined Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
h->adb_sendcommand(lastCommand.toStdString().c_str());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (logcatAdbThread)
|
||||
logcatAdbThread->runCommand("shell " + lastCommand);
|
||||
|
||||
requestInclination = -100;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,18 +39,24 @@ class nordictrackifitadbtreadmillLogcatAdbThread : public QThread {
|
||||
void onSpeedInclination(double speed, double inclination);
|
||||
void debug(QString message);
|
||||
void onWatt(double watt);
|
||||
void onHRM(int hrm);
|
||||
|
||||
private:
|
||||
QString adbCommandPending = "";
|
||||
double speed = 0;
|
||||
double inclination = 0;
|
||||
double watt = 0;
|
||||
int hrm = 0;
|
||||
QString name;
|
||||
struct adbfile {
|
||||
QDateTime date;
|
||||
QString name;
|
||||
};
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
lockscreen *h = 0;
|
||||
#endif
|
||||
|
||||
QString runAdbCommand(QString command);
|
||||
void runAdbTailCommand(QString command);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user