diff --git a/main/adapter/lib/ChessnutConverter.cpp b/main/adapter/lib/ChessnutConverter.cpp index deb9947..5cf296b 100644 --- a/main/adapter/lib/ChessnutConverter.cpp +++ b/main/adapter/lib/ChessnutConverter.cpp @@ -22,22 +22,24 @@ static std::vector dateTime() { } void ChessnutConverter::process(const std::array& board) { - std::array converted{}; - converted[0] = 0x01; - converted[1] = 0x24; - int j = 33; - for (int i = 0; i < 64; i += 2) { - converted[j] = setUpperNibble(converted[j], stoneToChessnutStone(board[i])); - converted[j] = setLowerNibble(converted[j], stoneToChessnutStone(board[i + 1])); - j--; + if (realTimeMode) { + std::array converted{}; + converted[0] = 0x01; + converted[1] = 0x24; + int j = 33; + for (int i = 0; i < 64; i += 2) { + converted[j] = setUpperNibble(converted[j], stoneToChessnutStone(board[i])); + converted[j] = setLowerNibble(converted[j], stoneToChessnutStone(board[i + 1])); + j--; + } + // add time + std::vector convertedSeconds = dateTime(); + converted[34] = convertedSeconds[0]; + converted[35] = convertedSeconds[1]; + converted[36] = convertedSeconds[2]; + converted[37] = convertedSeconds[3]; + boardCallback(converted.data(), 38); } - // add time - std::vector convertedSeconds = dateTime(); - converted[34] = convertedSeconds[0]; - converted[35] = convertedSeconds[1]; - converted[36] = convertedSeconds[2]; - converted[37] = convertedSeconds[3]; - boardCallback(converted.data(), 38); } uint8_t ChessnutConverter::setLowerNibble(uint8_t orig, uint8_t nibble) { @@ -80,9 +82,11 @@ std::vector eboard::ChessnutConverter::chessnutToCertaboCommand(uint8_t std::vector received(&data[0], &data[data_len]); if (received.size() >= 3 && received[0] == 0x21 && received[1] == 0x01 && received[2] == 0x00) { // real time mode infoCallback(ack.data(), ack.size()); + realTimeMode = true; } else if (received.size() >= 3 && received[0] == 0x21 && received[1] == 0x01 && received[2] == 0x01) { // upload mode infoCallback(ack.data(), ack.size()); + realTimeMode = false; } else if (received.size() >= 3 && received[0] == 0x29 && received[1] == 0x01 && received[2] == 0x00) { // battery status auto result = std::vector{0x2a, 0x02, 0x64, 0x00}; // battery full, not loading diff --git a/main/adapter/lib/ChessnutConverter.h b/main/adapter/lib/ChessnutConverter.h index 51bc57b..44f5460 100644 --- a/main/adapter/lib/ChessnutConverter.h +++ b/main/adapter/lib/ChessnutConverter.h @@ -58,6 +58,7 @@ class ChessnutConverter { ConverterCallbackFunction boardCallback; ConverterCallbackFunction infoCallback; + bool realTimeMode = false; }; } // namespace eboard diff --git a/main/adapter/test/ChessnutAdapterTest.cpp b/main/adapter/test/ChessnutAdapterTest.cpp index 7e27c06..2976fcc 100644 --- a/main/adapter/test/ChessnutAdapterTest.cpp +++ b/main/adapter/test/ChessnutAdapterTest.cpp @@ -42,6 +42,10 @@ class ChessnutAdapterTest : public ::testing::Test { // toBle toBleData = std::vector(&data[0], &data[data_len]); }); + // init with real time mode + std::vector realTimeMode{0x21, 0x01, 0x00}; + adapter->fromBle(&realTimeMode.front(), realTimeMode.size()); + toBleData.clear(); } void givenCalibrationDataIsReceived() { diff --git a/main/adapter/test/ChessnutConverterTest.cpp b/main/adapter/test/ChessnutConverterTest.cpp index 3ecf2f2..352ee8b 100644 --- a/main/adapter/test/ChessnutConverterTest.cpp +++ b/main/adapter/test/ChessnutConverterTest.cpp @@ -18,6 +18,7 @@ class ChessnutConverterTest : public ::testing::Test { [this](uint8_t* data, size_t data_len) { convertedInfo = std::vector(&data[0], &data[data_len]); }); + whenChessnutToCertaboCommandIsCalledWith({0x21, 0x01, 0x00}); // enable real-time mode } void whenConvertingBoard(std::array const& board) {