Commit 30c9678b authored by Matej Frančeškin's avatar Matej Frančeškin

Microhard improvements

Added Configuration Username
Report Login Error on incorrect configuration username/password 
parent 78922bd8
......@@ -13,7 +13,6 @@
#include "VideoManager.h"
QGC_LOGGING_CATEGORY(MicrohardLog, "MicrohardLog")
QGC_LOGGING_CATEGORY(MicrohardVerbose, "MicrohardVerbose")
//-----------------------------------------------------------------------------
MicrohardHandler::MicrohardHandler(QObject* parent)
......@@ -53,10 +52,10 @@ MicrohardHandler::_start(uint16_t port, QHostAddress addr)
qCDebug(MicrohardLog) << "Connecting to" << addr;
_tcpSocket->connectToHost(addr, port);
if (!_tcpSocket->waitForConnected(1000)) {
emit connected(0);
close();
return false;
}
emit connected();
return true;
}
......@@ -17,7 +17,6 @@
#define MICROHARD_SETTINGS_PORT 23
Q_DECLARE_LOGGING_CATEGORY(MicrohardLog)
Q_DECLARE_LOGGING_CATEGORY(MicrohardVerbose)
class MicrohardHandler : public QObject
{
......@@ -36,7 +35,7 @@ protected slots:
virtual void _readBytes () = 0;
signals:
void connected ();
void connected (int status);
void rssiUpdated (int rssi);
protected:
......
......@@ -22,6 +22,7 @@ static const char *kMICROHARD_GROUP = "Microhard";
static const char *kLOCAL_IP = "LocalIP";
static const char *kREMOTE_IP = "RemoteIP";
static const char *kNET_MASK = "NetMask";
static const char *kCFG_USERNAME = "ConfigUserName";
static const char *kCFG_PASSWORD = "ConfigPassword";
static const char *kENC_KEY = "EncryptionKey";
......@@ -38,6 +39,7 @@ MicrohardManager::MicrohardManager(QGCApplication* app, QGCToolbox* toolbox)
_localIPAddr = settings.value(kLOCAL_IP, QString("192.168.168.1")).toString();
_remoteIPAddr = settings.value(kREMOTE_IP, QString("192.168.168.2")).toString();
_netMask = settings.value(kNET_MASK, QString("255.255.255.0")).toString();
_configUserName = settings.value(kCFG_USERNAME, QString("admin")).toString();
_configPassword = settings.value(kCFG_PASSWORD, QString("admin")).toString();
_encryptionKey = settings.value(kENC_KEY, QString("1234567890")).toString();
settings.endGroup();
......@@ -73,9 +75,9 @@ void
MicrohardManager::_reset()
{
_close();
_isConnected = false;
_connectedStatus = 0;
emit connectedChanged();
_linkConnected = false;
_linkConnectedStatus = 0;
emit linkConnectedChanged();
if(!_appSettings) {
_appSettings = _toolbox->settingsManager()->appSettings();
......@@ -114,10 +116,10 @@ MicrohardManager::setToolbox(QGCToolbox* toolbox)
//-----------------------------------------------------------------------------
bool
MicrohardManager::setIPSettings(QString localIP_, QString remoteIP_, QString netMask_, QString cfgPassword_, QString encryptionKey_)
MicrohardManager::setIPSettings(QString localIP_, QString remoteIP_, QString netMask_, QString cfgUserName_, QString cfgPassword_, QString encryptionKey_)
{
if (_localIPAddr != localIP_ || _remoteIPAddr != remoteIP_ || _netMask != netMask_ ||
_configPassword != cfgPassword_ || _encryptionKey != encryptionKey_)
_configUserName != cfgUserName_ || _configPassword != cfgPassword_ || _encryptionKey != encryptionKey_)
{
if (_mhSettingsLoc && _encryptionKey != encryptionKey_) {
_mhSettingsLoc->setEncryptionKey(encryptionKey_);
......@@ -126,6 +128,7 @@ MicrohardManager::setIPSettings(QString localIP_, QString remoteIP_, QString net
_localIPAddr = localIP_;
_remoteIPAddr = remoteIP_;
_netMask = netMask_;
_configUserName = cfgUserName_;
_configPassword = cfgPassword_;
_encryptionKey = encryptionKey_;
......@@ -134,6 +137,7 @@ MicrohardManager::setIPSettings(QString localIP_, QString remoteIP_, QString net
settings.setValue(kLOCAL_IP, localIP_);
settings.setValue(kREMOTE_IP, remoteIP_);
settings.setValue(kNET_MASK, netMask_);
settings.setValue(kCFG_USERNAME, cfgUserName_);
settings.setValue(kCFG_PASSWORD, cfgPassword_);
settings.setValue(kENC_KEY, encryptionKey_);
settings.endGroup();
......@@ -172,20 +176,20 @@ MicrohardManager::_setEnabled()
//-----------------------------------------------------------------------------
void
MicrohardManager::_connectedLoc()
MicrohardManager::_connectedLoc(int status)
{
qCDebug(MicrohardLog) << "GND Microhard Settings Connected";
_isConnected = true;
_connectedStatus = status;
_locTimer.start(LONG_TIMEOUT);
emit connectedChanged();
}
//-----------------------------------------------------------------------------
void
MicrohardManager::_connectedRem()
MicrohardManager::_connectedRem(int status)
{
qCDebug(MicrohardLog) << "AIR Microhard Settings Connected";
_linkConnected = true;
_linkConnectedStatus = status;
_remTimer.start(LONG_TIMEOUT);
emit linkConnectedChanged();
}
......@@ -217,7 +221,7 @@ void
MicrohardManager::_locTimeout()
{
_locTimer.stop();
_isConnected = false;
_connectedStatus = 0;
if(_mhSettingsLoc) {
_mhSettingsLoc->close();
_mhSettingsLoc->deleteLater();
......@@ -231,7 +235,7 @@ void
MicrohardManager::_remTimeout()
{
_remTimer.stop();
_linkConnected = false;
_linkConnectedStatus = 0;
if(_mhSettingsRem) {
_mhSettingsRem->close();
_mhSettingsRem->deleteLater();
......@@ -250,16 +254,16 @@ MicrohardManager::_checkMicrohard()
return;
}
if(!_isConnected) {
if(_connectedStatus <= 0) {
_mhSettingsLoc->start();
} else {
_mhSettingsLoc->getStatus();
}
if(!_linkConnected) {
if(_linkConnectedStatus <= 0) {
_mhSettingsRem->start();
} else {
_mhSettingsRem->getStatus();
}
}
_workTimer.start(_isConnected ? SHORT_TIMEOUT : LONG_TIMEOUT);
_workTimer.start(_connectedStatus > 0 ? SHORT_TIMEOUT : LONG_TIMEOUT);
}
......@@ -26,30 +26,32 @@ class MicrohardManager : public QGCTool
Q_OBJECT
public:
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
Q_PROPERTY(bool linkConnected READ linkConnected NOTIFY linkConnectedChanged)
Q_PROPERTY(int connected READ connected NOTIFY connectedChanged)
Q_PROPERTY(int linkConnected READ linkConnected NOTIFY linkConnectedChanged)
Q_PROPERTY(int uplinkRSSI READ uplinkRSSI NOTIFY linkChanged)
Q_PROPERTY(int downlinkRSSI READ downlinkRSSI NOTIFY linkChanged)
Q_PROPERTY(QString localIPAddr READ localIPAddr NOTIFY localIPAddrChanged)
Q_PROPERTY(QString remoteIPAddr READ remoteIPAddr NOTIFY remoteIPAddrChanged)
Q_PROPERTY(QString netMask READ netMask NOTIFY netMaskChanged)
Q_PROPERTY(QString configUserName READ configUserName NOTIFY configUserNameChanged)
Q_PROPERTY(QString configPassword READ configPassword NOTIFY configPasswordChanged)
Q_PROPERTY(QString encryptionKey READ encryptionKey NOTIFY encryptionKeyChanged)
Q_INVOKABLE bool setIPSettings (QString localIP, QString remoteIP, QString netMask, QString cfgPassword, QString encyrptionKey);
Q_INVOKABLE bool setIPSettings (QString localIP, QString remoteIP, QString netMask, QString cfgUserName, QString cfgPassword, QString encyrptionKey);
explicit MicrohardManager (QGCApplication* app, QGCToolbox* toolbox);
~MicrohardManager () override;
void setToolbox (QGCToolbox* toolbox) override;
bool connected () { return _isConnected && _mhSettingsLoc && _mhSettingsLoc->loggedIn(); }
bool linkConnected () { return _linkConnected && _mhSettingsRem && _mhSettingsRem->loggedIn(); }
int connected () { return _connectedStatus; }
int linkConnected () { return _linkConnectedStatus; }
int uplinkRSSI () { return _downlinkRSSI; }
int downlinkRSSI () { return _uplinkRSSI; }
QString localIPAddr () { return _localIPAddr; }
QString remoteIPAddr () { return _remoteIPAddr; }
QString netMask () { return _netMask; }
QString configUserName () { return _configUserName; }
QString configPassword () { return _configPassword; }
QString encryptionKey () { return _encryptionKey; }
......@@ -60,13 +62,14 @@ signals:
void localIPAddrChanged ();
void remoteIPAddrChanged ();
void netMaskChanged ();
void configUserNameChanged ();
void configPasswordChanged ();
void encryptionKeyChanged ();
private slots:
void _connectedLoc ();
void _connectedLoc (int status);
void _rssiUpdatedLoc (int rssi);
void _connectedRem ();
void _connectedRem (int status);
void _rssiUpdatedRem (int rssi);
void _checkMicrohard ();
void _setEnabled ();
......@@ -79,21 +82,22 @@ private:
FactMetaData *_createMetadata (const char *name, QStringList enums);
private:
bool _isConnected = false;
AppSettings* _appSettings = nullptr;
MicrohardSettings* _mhSettingsLoc = nullptr;
MicrohardSettings* _mhSettingsRem = nullptr;
bool _enabled = true;
bool _linkConnected = false;
QTimer _workTimer;
QTimer _locTimer;
QTimer _remTimer;
int _downlinkRSSI = 0;
int _uplinkRSSI = 0;
QString _localIPAddr;
QString _remoteIPAddr;
QString _netMask;
QString _configPassword;
QString _encryptionKey;
QTime _timeoutTimer;
int _connectedStatus = 0;
AppSettings* _appSettings = nullptr;
MicrohardSettings* _mhSettingsLoc = nullptr;
MicrohardSettings* _mhSettingsRem = nullptr;
bool _enabled = true;
int _linkConnectedStatus = 0;
QTimer _workTimer;
QTimer _locTimer;
QTimer _remTimer;
int _downlinkRSSI = 0;
int _uplinkRSSI = 0;
QString _localIPAddr;
QString _remoteIPAddr;
QString _netMask;
QString _configUserName;
QString _configPassword;
QString _encryptionKey;
QTime _timeoutTimer;
};
......@@ -45,7 +45,7 @@ MicrohardSettings::setEncryptionKey(QString key)
{
QString cmd = "AT+MWVENCRYPT=1," + key + "\n";
_tcpSocket->write(cmd.toStdString().c_str());
qCDebug(MicrohardLog) << "setEncryptionKey: " << cmd;
qCDebug(MicrohardLog) << "Set encryption key.";
}
//-----------------------------------------------------------------------------
......@@ -54,7 +54,7 @@ MicrohardSettings::_readBytes()
{
QByteArray bytesIn = _tcpSocket->read(_tcpSocket->bytesAvailable());
// qCDebug(MicrohardVerbose) << "Read bytes: " << bytesIn;
//qCDebug(MicrohardLog) << "Read bytes: " << bytesIn;
if (_loggedIn) {
int i1 = bytesIn.indexOf("RSSI (dBm)");
......@@ -69,16 +69,20 @@ MicrohardSettings::_readBytes()
}
}
}
} else if (bytesIn.contains("UserDevice login:")) {
_tcpSocket->write("admin\n");
} else if (bytesIn.contains("login:")) {
std::string userName = qgcApp()->toolbox()->microhardManager()->configUserName().toStdString() + "\n";
_tcpSocket->write(userName.c_str());
} else if (bytesIn.contains("Password:")) {
std::string pwd = qgcApp()->toolbox()->microhardManager()->configPassword().toStdString() + "\n";
_tcpSocket->write(pwd.c_str());
} else if (bytesIn.contains("UserDevice>")) {
} else if (bytesIn.contains("Login incorrect")) {
emit connected(-1);
} else if (bytesIn.contains("Entering")) {
if (!loggedIn() && _setEncryptionKey) {
setEncryptionKey(qgcApp()->toolbox()->microhardManager()->encryptionKey());
}
_loggedIn = true;
emit connected(1);
}
emit rssiUpdated(_rssiVal);
......
......@@ -121,16 +121,32 @@ Rectangle {
Layout.minimumWidth: _labelWidth
}
QGCLabel {
text: QGroundControl.microhardManager.connected ? qsTr("Connected") : qsTr("Not Connected")
color: QGroundControl.microhardManager.connected ? qgcPal.colorGreen : qgcPal.colorRed
function getStatus(status) {
if (status === 1)
return qsTr("Connected");
else if (status === -1)
return qsTr("Login Error")
else
return qsTr("Not Connected")
}
text: getStatus(QGroundControl.microhardManager.connected)
color: QGroundControl.microhardManager.connected === 1 ? qgcPal.colorGreen : qgcPal.colorRed
Layout.minimumWidth: _valueWidth
}
QGCLabel {
text: qsTr("Air Unit:")
}
QGCLabel {
text: QGroundControl.microhardManager.linkConnected ? qsTr("Connected") : qsTr("Not Connected")
color: QGroundControl.microhardManager.linkConnected ? qgcPal.colorGreen : qgcPal.colorRed
function getStatus(status) {
if (status === 1)
return qsTr("Connected");
else if (status === -1)
return qsTr("Login Error")
else
return qsTr("Not Connected")
}
text: getStatus(QGroundControl.microhardManager.linkConnected)
color: QGroundControl.microhardManager.linkConnected === 1 ? qgcPal.colorGreen : qgcPal.colorRed
}
QGCLabel {
text: qsTr("Uplink RSSI:")
......@@ -210,7 +226,16 @@ Rectangle {
Layout.minimumWidth: _valueWidth
}
QGCLabel {
text: qsTr("Configuration password:")
text: qsTr("Configuration User Name:")
}
QGCTextField {
id: configUserName
text: QGroundControl.microhardManager.configUserName
enabled: true
Layout.minimumWidth: _valueWidth
}
QGCLabel {
text: qsTr("Configuration Password:")
}
QGCTextField {
id: configPassword
......@@ -244,6 +269,7 @@ Rectangle {
if(localIP.text === QGroundControl.microhardManager.localIPAddr &&
remoteIP.text === QGroundControl.microhardManager.remoteIPAddr &&
netMask.text === QGroundControl.microhardManager.netMask &&
configUserName.text === QGroundControl.microhardManager.configUserName &&
configPassword.text === QGroundControl.microhardManager.configPassword &&
encryptionKey.text === QGroundControl.microhardManager.encryptionKey)
return false
......@@ -256,7 +282,7 @@ Rectangle {
text: qsTr("Apply")
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
QGroundControl.microhardManager.setIPSettings(localIP.text, remoteIP.text, netMask.text, configPassword.text, encryptionKey.text)
QGroundControl.microhardManager.setIPSettings(localIP.text, remoteIP.text, netMask.text, configUserName.text, configPassword.text, encryptionKey.text)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment