Skip to content

Commit

Permalink
fix reqTest consistent with APIv6
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mpr1c3 committed Oct 18, 2023
1 parent df5c27c commit a6899a5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
12 changes: 3 additions & 9 deletions src/ayab/com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void Com::onPacketReceived(const uint8_t *buffer, size_t size) {
break;

case static_cast<uint8_t>(AYAB_API::reqTest):
h_reqTest(buffer, size);
h_reqTest();
break;

case static_cast<uint8_t>(AYAB_API::helpCmd):
Expand Down Expand Up @@ -316,14 +316,8 @@ void Com::h_reqInfo() const {
* \param buffer A pointer to a data buffer.
* \param size The number of bytes in the data buffer.
*/
void Com::h_reqTest(const uint8_t *buffer, size_t size) const {
if (size < 2U) {
// message is too short
send_cnfTest(ErrorCode::expected_longer_message);
return;
}

auto machineType = static_cast<Machine_t>(buffer[1]);
void Com::h_reqTest() const {
auto machineType = static_cast<Machine_t>(GlobalKnitter::getMachineType());

// Note (August 2020): the return value of this function has changed.
// Previously, it returned `true` for success and `false` for failure.
Expand Down
2 changes: 1 addition & 1 deletion src/ayab/com.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Com : public ComInterface {
void h_reqStart(const uint8_t *buffer, size_t size);
void h_cnfLine(const uint8_t *buffer, size_t size);
void h_reqInfo() const;
void h_reqTest(const uint8_t *buffer, size_t size) const;
void h_reqTest() const;
void h_unrecognized() const;

void send_cnfInfo() const;
Expand Down
14 changes: 2 additions & 12 deletions test/test_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,10 @@ TEST_F(ComTest, test_reqInit_checksum_error) {
ASSERT_TRUE(Mock::VerifyAndClear(fsmMock));
}

TEST_F(ComTest, test_reqtest_fail) {
// no machineType
TEST_F(ComTest, test_reqtest) {
uint8_t buffer[] = {static_cast<uint8_t>(AYAB_API::reqTest)};
EXPECT_CALL(*fsmMock, setState(OpState::test)).Times(0);
expected_write_onPacketReceived(buffer, sizeof(buffer), true);

// test expectations without destroying instance
ASSERT_TRUE(Mock::VerifyAndClear(fsmMock));
}

TEST_F(ComTest, test_reqtest_success_KH270) {
uint8_t buffer[] = {static_cast<uint8_t>(AYAB_API::reqTest), static_cast<uint8_t>(Machine_t::Kh270)};
EXPECT_CALL(*fsmMock, setState(OpState::test));
EXPECT_CALL(*knitterMock, setMachineType(Machine_t::Kh270));
EXPECT_CALL(*knitterMock, setMachineType(Machine_t::Kh910));
EXPECT_CALL(*arduinoMock, millis);
expected_write_onPacketReceived(buffer, sizeof(buffer), false);

Expand Down

0 comments on commit a6899a5

Please sign in to comment.