-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Summary Dimos should now broadcast CAN properly. ### Changelist - Main Window CAN broadcasting in time - Mutex locking for CAN tables ### Testing Done - DevIO console logging ### Resolved Issues ### Checklist *Please change `[ ]` to `[x]` when you are ready.* - [x] I have read and followed the code conventions detailed in [README.md](../README.md) (*This will save time for both you and the reviewer!*). - [x] If this pull request is longer then **500** lines, I have provided *explicit* justification in the summary above explaining why I *cannot* break this up into multiple pull requests (*Small PR's are faster and less painful for everyone involved!*). --------- Co-authored-by: peterjinweigu <[email protected]>
- Loading branch information
1 parent
4188410
commit cb34abb
Showing
6 changed files
with
103 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
{} | ||
{ | ||
"CommitInfo": { | ||
"msg_id": 819, | ||
"cycle_time": 100, | ||
"description": "Dimos Current Running Commit Info", | ||
"signals": { | ||
"Hash": { | ||
"bits": 32 | ||
}, | ||
"Clean": { | ||
"bits": 1 | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,14 +1,22 @@ | ||
#include "can.h" | ||
#include <iostream> | ||
#include <thread> | ||
#include <chrono> | ||
|
||
using std::cout, std::endl; | ||
|
||
Result<std::monostate, CanConnectionError> Can_Init() { | ||
cout << "Can Initialized" << endl; | ||
return std::monostate{}; | ||
} | ||
|
||
Result<CanMsg, CanReadError> Can_Read() { | ||
return CanMsg{}; | ||
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); | ||
cout << "Can Read Requested" << endl; | ||
return CanMsg{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
} | ||
|
||
Result<std::monostate, CanWriteError> Can_Write(const CanMsg *msg) { | ||
cout << "Can with id " << msg->std_id << " Written" << endl; | ||
return std::monostate{}; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,63 @@ | ||
#include <iostream> | ||
#include <QThread> | ||
#include <chrono> | ||
|
||
#include "mainwindow.h" | ||
#include "ui_mainwindow.h" | ||
#include "can.h" | ||
|
||
using std::cout, std::endl; | ||
extern "C" { | ||
#include "Io_CanTx.h" | ||
#include "Io_CanRx.h" | ||
} | ||
|
||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { | ||
// CANTX TASK | ||
tx100Hz.setInterval(10); | ||
tx100Hz.setSingleShot(false); | ||
QTimer::connect(&tx100Hz, &QTimer::timeout, Io_CanTx_Enqueue100HzMsgs); | ||
tx100Hz.start(); | ||
|
||
tx1Hz.setInterval(1000); | ||
tx1Hz.setSingleShot(false); | ||
QTimer::connect(&tx1Hz, &QTimer::timeout, Io_CanTx_Enqueue1HzMsgs); | ||
tx1Hz.start(); | ||
|
||
CanRxTaskThread = QThread::create(&MainWindow::CanRXTask); | ||
CanTxPeriodicTaskThread = QThread::create(&MainWindow::CanPeriodicTXTask); | ||
CanRxTaskThread->start(); | ||
CanTxPeriodicTaskThread->start(); | ||
|
||
ui->setupUi(this); | ||
} | ||
|
||
MainWindow::~MainWindow() = default; | ||
[[noreturn]] void MainWindow::CanRXTask() { | ||
while (true) { | ||
Result<CanMsg, CanReadError> res = Can_Read(); | ||
if (res.index() == 1) { | ||
switch (get<CanReadError>(res)) { | ||
case ReadInterfaceNotCreated: | ||
break; | ||
case SocketReadError: | ||
case IncompleteCanFrame: | ||
continue; | ||
} | ||
continue; | ||
} | ||
|
||
// success | ||
CanMsg message = get<CanMsg>(res); | ||
// acquire lock | ||
Io_CanRx_UpdateRxTableWithMessage(&message); | ||
// release lock | ||
} | ||
} | ||
|
||
[[noreturn]] void MainWindow::CanPeriodicTXTask() { | ||
using namespace std::chrono; | ||
while (true) { | ||
auto ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch()); | ||
Io_CanTx_EnqueueOtherPeriodicMsgs(ms.count()); | ||
} | ||
} | ||
|
||
MainWindow::~MainWindow() = default; |
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