From 04ab5f1aa1971a0c2dff6731a13e3fad54e25814 Mon Sep 17 00:00:00 2001 From: t0mpr1c3 Date: Wed, 18 Oct 2023 18:14:49 -0400 Subject: [PATCH] fix reqTest consistent with APIv6 --- src/ayab/com.cpp | 12 +++--------- src/ayab/com.h | 2 +- test/test_com.cpp | 14 ++------------ 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/ayab/com.cpp b/src/ayab/com.cpp index 1b680b94e..5aef63c50 100644 --- a/src/ayab/com.cpp +++ b/src/ayab/com.cpp @@ -140,7 +140,7 @@ void Com::onPacketReceived(const uint8_t *buffer, size_t size) { break; case static_cast(AYAB_API::reqTest): - h_reqTest(buffer, size); + h_reqTest(); break; case static_cast(AYAB_API::helpCmd): @@ -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(buffer[1]); +void Com::h_reqTest() const { + auto machineType = static_cast(GlobalKnitter::m_machineType); // Note (August 2020): the return value of this function has changed. // Previously, it returned `true` for success and `false` for failure. diff --git a/src/ayab/com.h b/src/ayab/com.h index 343c06fcf..5e95cca83 100644 --- a/src/ayab/com.h +++ b/src/ayab/com.h @@ -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; diff --git a/test/test_com.cpp b/test/test_com.cpp index 40bb329d7..f5021da42 100644 --- a/test/test_com.cpp +++ b/test/test_com.cpp @@ -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(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(AYAB_API::reqTest), static_cast(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);