Skip to content

Commit eec7b8e

Browse files
committed
Hang FakeCANBoard
1 parent 72ea7fe commit eec7b8e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/CAN/FakeCANBoard.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ int prompt(std::string_view message) {
3131
return val;
3232
}
3333

34+
bool correct = false;
35+
3436
int main() {
3537
can::initCAN();
3638

@@ -66,6 +68,24 @@ int main() {
6668
int state = prompt(state_msg.str().c_str());
6769
can::motor::axis_state_t motor_state = static_cast<can::motor::axis_state_t>(state);
6870
board->setMotorState(motor_state);
71+
72+
correct = false;
73+
if (nlohmann::json endpoint = can::getEndpoint(board->getBoardID(), "axis0.current_state"); endpoint != nullptr) {
74+
uint16_t endpoint_id = endpoint["id"];
75+
can::addDirectReadCallback(board->getDevice(), endpoint_id, [board, motor_state, endpoint_id](auto decoded) {
76+
if (decoded.value_uint8 != static_cast<uint8_t>(can::motor::axis_state_t::idle)) {
77+
LOG_F(ERROR, "0x%x DID NOT LISTEN AND IS NOT STATE %d", board->getDevice().deviceUUID, motor_state);
78+
board->setMotorState(motor_state);
79+
} else {
80+
can::removeDirectReadCallback(board->getDevice(), endpoint_id);
81+
correct = true;
82+
}
83+
});
84+
85+
board->read(endpoint_id);
86+
}
87+
88+
while (!correct);
6989
} else if (testMode == TestMode::Power) {
7090
std::string input;
7191
std::cout << "Enter power [-1.0, 1.0]: ";

0 commit comments

Comments
 (0)