generated from RIT-EVT/project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (44 loc) · 1.57 KB
/
main.cpp
File metadata and controls
58 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* This test demonstrates the functionality of the ResetHandler class. To fully
* test this, you will need to connect it to a CAN network and send it reset
* messages.
*/
#include <BMS.hpp>
#include <EVT/manager.hpp>
#include <EVT/utils/log.hpp>
#include <ResetHandler.hpp>
namespace DEV = EVT::core::DEV;
namespace IO = EVT::core::IO;
namespace log = EVT::core::log;
/**
* Interrupt handler for incoming CAN messages.
*
* @param priv[in] The private data (FixedQueue<CANOPEN_QUEUE_SIZE, CANMessage>)
*/
void canInterruptHandler(IO::CANMessage& message, void* priv) {
auto* resetHandler = (BMS::ResetHandler*) priv;
resetHandler->registerInput(message);
log::LOGGER.log(log::Logger::LogLevel::INFO, "Message received");
}
int main() {
EVT::core::platform::init();
IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200);
uart.printf("\r\n\r\nReset Handler Test\r\n");
log::LOGGER.setUART(&uart);
log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG);
BMS::ResetHandler resetHandler;
IO::CAN& can = IO::getCAN<BMS::BMS::CAN_TX_PIN, BMS::BMS::CAN_RX_PIN>();
can.addIRQHandler(canInterruptHandler, &resetHandler);
// Attempt to join the CAN network
IO::CAN::CANStatus result = can.connect(true);
if (result != IO::CAN::CANStatus::OK) {
uart.printf("Failed to connect to the CAN network\r\n");
return 1;
}
while (1) {
if (resetHandler.shouldReset()) {
log::LOGGER.log(log::Logger::LogLevel::INFO, "Reset triggered");
}
time::wait(1000);
}
}