-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remember busspeed #457
Open
consp
wants to merge
4
commits into
collin80:master
Choose a base branch
from
consp:remember-busspeed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Remember busspeed #457
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c5e0488
Added method for storing the bus speeds
consp 0f7ed9a
Added the update bus speed to canconnection to support updating it fr…
consp 05c3b5d
Fixed error in case too many busses are attempted to be restored
consp 6c639ec
Fixed bug where stored data would not be loaded correctly due to miss…
consp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,7 +258,8 @@ void ConnectionWindow::handleNewConn() | |
newType = thisDialog->getConnectionType(); | ||
newPort = thisDialog->getPortName(); | ||
newDriver = thisDialog->getDriverName(); | ||
conn = create(newType, newPort, newDriver); | ||
QVector<int> newBusSpeed; | ||
conn = create(newType, newPort, newDriver, 0, newBusSpeed); | ||
if (conn) | ||
{ | ||
connModel->add(conn); | ||
|
@@ -293,6 +294,8 @@ void ConnectionWindow::handleResetConn() | |
{ | ||
QString port, driver; | ||
CANCon::type type; | ||
int busnums; | ||
QVector<int> busSpeeds; | ||
|
||
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row(); | ||
if (selIdx <0) return; | ||
|
@@ -305,13 +308,19 @@ void ConnectionWindow::handleResetConn() | |
type = conn_p->getType(); | ||
port = conn_p->getPort(); | ||
driver = conn_p->getDriver(); | ||
busnums = conn_p->getNumBuses(); | ||
for (int i = 0; i < busnums; i++) { | ||
CANBus bus; | ||
conn_p->getBusSettings(i, bus); | ||
busSpeeds.append(bus.getSpeed()); | ||
} | ||
|
||
/* stop and delete connection */ | ||
conn_p->stop(); | ||
|
||
conn_p = nullptr; | ||
|
||
conn_p = create(type, port, driver); | ||
conn_p = create(type, port, driver, busnums, busSpeeds); | ||
if (conn_p) connModel->replace(selIdx, conn_p); | ||
} | ||
|
||
|
@@ -476,7 +485,7 @@ void ConnectionWindow::handleSendText() { | |
emit sendDebugData(bytes); | ||
} | ||
|
||
CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QString pDriver) | ||
CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QString pDriver, int busNum, QVector<int> busSpeeds) | ||
{ | ||
CANConnection* conn_p; | ||
|
||
|
@@ -492,8 +501,18 @@ CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QS | |
//set up the debug console to operate if we've selected it. Doing so here allows debugging right away during set up | ||
connect(conn_p, SIGNAL(debugOutput(QString)), this, SLOT(getDebugText(QString))); | ||
} | ||
/*TODO add return value and checks */ | ||
|
||
conn_p->start(); | ||
|
||
connect(this, SIGNAL(updateBusSpeed(int, int)), conn_p, SLOT(updateBusSpeed(int, int))); | ||
// if portNum == 0 will skip | ||
for (int i = 0; i < busNum && i < busSpeeds.count(); i++) { | ||
CANBus bus; | ||
bus.setSpeed(busSpeeds[i]); | ||
emit updateBusSpeed(i, busSpeeds[i]); | ||
} | ||
disconnect(this, SIGNAL(updateBusSpeed(int, int)), conn_p, SLOT(updateBusSpeed(int, int))); | ||
/*TODO add return value and checks */ | ||
} | ||
return conn_p; | ||
} | ||
|
@@ -510,13 +529,37 @@ void ConnectionWindow::loadConnections() | |
QVector<QString> portNames = settings.value("connections/portNames").value<QVector<QString>>(); | ||
QVector<QString> driverNames = settings.value("connections/driverNames").value<QVector<QString>>(); | ||
QVector<int> devTypes = settings.value("connections/types").value<QVector<int>>(); | ||
QVector<int> busNums = settings.value("connections/busNums").value<QVector<int>>(); | ||
QVector<int> busSpeedsT = settings.value("connections/busSpeeds").value<QVector<int>>(); | ||
QVector<QVector<int>> busSpeeds; | ||
|
||
// if values not present (e.g. when you update the program) | ||
if (busNums.count() != driverNames.count()) { | ||
busNums = QVector<int>(driverNames.count()); | ||
busSpeedsT = QVector<int>(0); | ||
} | ||
|
||
//don't load the connections if the three setting arrays above aren't all the same size. | ||
if (portNames.count() != driverNames.count() || devTypes.count() != driverNames.count()) return; | ||
if (portNames.count() != driverNames.count() || devTypes.count() != driverNames.count() || driverNames.count() != busNums.count()) return; | ||
|
||
// connect tthe bus get/set | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: tthe -> the |
||
|
||
qDebug() << "Loading connections"; | ||
// demangle bus speeds | ||
for (int i = 0, j = 0; i < busNums.count(); i++) { | ||
QVector<int> busSpeed; | ||
for (int k = 0; k < busNums[i] && j+k < busSpeedsT.count(); k++) { | ||
busSpeed.append(busSpeedsT[j+k]); | ||
qDebug() << "Speed " << busSpeedsT[j+k]; | ||
} | ||
busSpeeds.append(busSpeed); | ||
qDebug() << "Load speed" << busNums[i]; | ||
j += busNums[i]; | ||
} | ||
|
||
for(int i = 0 ; i < portNames.count() ; i++) | ||
{ | ||
CANConnection* conn_p = create((CANCon::type)devTypes[i], portNames[i], driverNames[i]); | ||
CANConnection* conn_p = create((CANCon::type)devTypes[i], portNames[i], driverNames[i], busNums[i], busSpeeds[i]); | ||
/* add connection to model */ | ||
connModel->add(conn_p); | ||
} | ||
|
@@ -534,18 +577,29 @@ void ConnectionWindow::saveConnections() | |
QVector<QString> portNames; | ||
QVector<int> devTypes; | ||
QVector<QString> driverNames; | ||
QVector<int> busNums; | ||
QVector<int> busSpeeds; | ||
|
||
/* save connections */ | ||
foreach(CANConnection* conn_p, conns) | ||
{ | ||
portNames.append(conn_p->getPort()); | ||
devTypes.append(conn_p->getType()); | ||
driverNames.append(conn_p->getDriver()); | ||
busNums.append(conn_p->getNumBuses()); | ||
for (int i = 0; i < conn_p->getNumBuses(); i++) { | ||
CANBus bus; | ||
conn_p->getBusSettings(i, bus); | ||
busSpeeds.append(bus.getSpeed()); | ||
qDebug() << "Bus speed " << bus.getSpeed(); | ||
} | ||
} | ||
|
||
settings.setValue("connections/portNames", QVariant::fromValue(portNames)); | ||
settings.setValue("connections/types", QVariant::fromValue(devTypes)); | ||
settings.setValue("connections/driverNames", QVariant::fromValue(driverNames)); | ||
settings.setValue("connections/busNums", QVariant::fromValue(busNums)); | ||
settings.setValue("connections/busSpeeds", QVariant::fromValue(busSpeeds)); | ||
} | ||
|
||
void ConnectionWindow::moveConnUp() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connect(this, &ConnectionWindow::updateBusSpeed, conn_p, &CANConnection::updateBusSpeed);
Gives errors during compile time instead of runtime.