Skip to content

Commit

Permalink
Merge pull request #2269 from erikboto/monark-updates
Browse files Browse the repository at this point in the history
Monark updates
  • Loading branch information
liversedge committed Dec 29, 2016
2 parents 62c34eb + f0d6ec1 commit 3d2bc56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
28 changes: 16 additions & 12 deletions src/Train/MonarkConnection.cpp
Expand Up @@ -66,7 +66,7 @@ int MonarkConnection::pollInterval()
* Private function that reads a complete reply and prepares if for
* processing by replacing \r with \0
*/
QByteArray MonarkConnection::readAnswer(int timeoutMs)
QString MonarkConnection::readAnswer(int timeoutMs)
{
QByteArray data;

Expand All @@ -81,7 +81,7 @@ QByteArray MonarkConnection::readAnswer(int timeoutMs)
} while (data.indexOf('\r') == -1);

data.replace("\r", "\0");
return data;
return QString(data);
}

/**
Expand Down Expand Up @@ -178,7 +178,7 @@ void MonarkConnection::requestPower()
// failure to write to device, bail out
this->exit(-1);
}
QByteArray data = readAnswer(500);
QString data = readAnswer(500);
m_readMutex.lock();
m_power = data.toInt();
m_readMutex.unlock();
Expand All @@ -193,7 +193,7 @@ void MonarkConnection::requestPulse()
// failure to write to device, bail out
this->exit(-1);
}
QByteArray data = readAnswer(500);
QString data = readAnswer(500);
m_readMutex.lock();
m_pulse = data.toInt();
m_readMutex.unlock();
Expand All @@ -208,7 +208,7 @@ void MonarkConnection::requestCadence()
// failure to write to device, bail out
this->exit(-1);
}
QByteArray data = readAnswer(500);
QString data = readAnswer(500);
m_readMutex.lock();
m_cadence = data.toInt();
m_readMutex.unlock();
Expand All @@ -223,8 +223,8 @@ int MonarkConnection::readConfiguredLoad()
// failure to write to device, bail out
this->exit(-1);
}
QByteArray data = readAnswer(500);
data.remove(0,1);
QString data = readAnswer(500);
//data.remove(0,1);
qDebug() << "Current configure load: " << data.toInt();
return data.toInt();
}
Expand All @@ -239,8 +239,7 @@ void MonarkConnection::identifyModel()
// failure to write to device, bail out
this->exit(-1);
}
QByteArray data = readAnswer(500);
m_id = QString(data);
m_id = readAnswer(500);

if (m_id.toLower().startsWith("novo"))
{
Expand All @@ -250,8 +249,7 @@ void MonarkConnection::identifyModel()
// failure to write to device, bail out
this->exit(-1);
}
QByteArray data = readAnswer(500);
servo = QString(data);
servo = readAnswer(500);
}


Expand All @@ -265,6 +263,9 @@ void MonarkConnection::identifyModel()
} else if (m_id.toLower().startsWith("novo") && servo != "manual") {
m_type = MONARK_LC_NOVO;
setLoad(100);
} else if (m_id.toLower().startsWith("mec")) {
m_type = MONARK_839E;
setLoad(100);
}

}
Expand Down Expand Up @@ -314,7 +315,8 @@ bool MonarkConnection::canDoLoad()
switch (m_type)
{
case MONARK_LC: // fall through
case MONARK_LC_NOVO:
case MONARK_LC_NOVO: // fall through
case MONARK_839E:
result = true;
break;
case MONARK_LT2: // fall through
Expand All @@ -337,6 +339,7 @@ bool MonarkConnection::canDoKp()
break;
case MONARK_LC: // fall through
case MONARK_LT2: // fall through
case MONARK_839E: // fall through
default:
result = false;
break;
Expand Down Expand Up @@ -384,6 +387,7 @@ bool MonarkConnection::discover(QString portName)
// Should check for all bike ids known to use this protocol
if (QString(id).toLower().contains("lt") ||
QString(id).toLower().contains("lc") ||
QString(id).toLower().contains("mec") ||
QString(id).toLower().contains("novo")) {
found = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Train/MonarkConnection.h
Expand Up @@ -56,7 +56,7 @@ public slots:
QString m_id;
void run();
QTimer *m_timer;
QByteArray readAnswer(int timeoutMs = -1);
QString readAnswer(int timeoutMs = -1);
QMutex m_mutex;
QMutex m_readMutex;
unsigned int m_load;
Expand All @@ -65,7 +65,7 @@ public slots:
double m_kpToWrite;
bool m_shouldWriteLoad;
bool m_shouldWriteKp;
enum MonarkType { MONARK_UNKNOWN, MONARK_LT2, MONARK_LC, MONARK_LC_NOVO } m_type;
enum MonarkType { MONARK_UNKNOWN, MONARK_LT2, MONARK_LC, MONARK_LC_NOVO, MONARK_839E } m_type;
bool canDoLoad();
bool canDoKp();
quint32 m_power;
Expand Down

0 comments on commit 3d2bc56

Please sign in to comment.