From 947ce9dea6e1afc8d14ab3423d8f3874688bd4b2 Mon Sep 17 00:00:00 2001 From: Decareme Date: Mon, 15 Jan 2024 10:29:55 +0100 Subject: [PATCH] Adjusted sendCommand Method --- lib/ZumoOta/src/FlashManager.cpp | 32 ++++++++++++++++++------ lib/ZumoOta/src/FlashManager.h | 2 +- lib/ZumoOta/src/WebServerCustom.cpp | 16 ------------ lib/ZumoOta/src/Zumo32U4Specifications.h | 5 ++-- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/lib/ZumoOta/src/FlashManager.cpp b/lib/ZumoOta/src/FlashManager.cpp index 18cebbd2..53ed2565 100644 --- a/lib/ZumoOta/src/FlashManager.cpp +++ b/lib/ZumoOta/src/FlashManager.cpp @@ -61,7 +61,8 @@ const uint8_t NEXT_SERIAL_SEND_DELAY_MS = 10; /****************************************************************************** * Local Variables *****************************************************************************/ -const uint16_t WAIT_TIME_MS = 500U; +/*Delay before processing the response. +const uint8_t AWAIT_RESPONSE_DELAY_MS = 50U;*/ /** Specifies the number of bytes stored in one Zumo bootloader/flash memory page.*/ static const uint16_t PAGE_SIZE_BYTES = 128U; @@ -80,10 +81,10 @@ FlashManager::~FlashManager() { } -void FlashManager::readToRobotFlash(size_t expectedsize) +bool FlashManager::readToRobotFlash(size_t expectedsize) { + bool retCode = false; Stream& deviceStream = Board::getInstance().getDevice().getStream(); - Board::getInstance().getDevice().process(); int availableBytes = deviceStream.available(); if (0 < availableBytes) @@ -114,23 +115,40 @@ void FlashManager::readToRobotFlash(size_t expectedsize) Serial.print(" "); } Serial.println(); + retCode = true; } else { LOG_INFO("Failure!"); } } + return retCode; } void FlashManager ::sendCommand(const uint8_t command[]) { + const uint16_t WRITE_BUFFER_SIZE = 256; + uint8_t writeBuffer[WRITE_BUFFER_SIZE]; Stream& deviceStream = Board::getInstance().getDevice().getStream(); - size_t commandsize = sizeof(command[0]); - size_t mysize= deviceStream.write(command, commandsize); - - readToRobotFlash(mysize); + /*Size of array*/ + size_t commandsize = sizeof(command); + /* Copy the command OpCode into buffer */ + memcpy(writeBuffer, command, commandsize); + + /* Send the OpCode and command data to Zumo robot */ + size_t bytesWritten= deviceStream.write(command, commandsize); + if(bytesWritten == commandsize) + { + /* Await response */ + delay(50); + readToRobotFlash(commandsize); + } + else + { + LOG_ERROR("Could not send data packet to Zumo robot. Aborting now"); + } } void FlashManager:: enterBootloadermode() diff --git a/lib/ZumoOta/src/FlashManager.h b/lib/ZumoOta/src/FlashManager.h index b5a0a327..d024ec86 100644 --- a/lib/ZumoOta/src/FlashManager.h +++ b/lib/ZumoOta/src/FlashManager.h @@ -63,7 +63,7 @@ class FlashManager * This function reads data from the provided stream and writes it to * the robot's flash memory. */ - void readToRobotFlash(size_t expectedsize); + bool readToRobotFlash(size_t expectedsize); /** * @brief exit the bootloader mode. diff --git a/lib/ZumoOta/src/WebServerCustom.cpp b/lib/ZumoOta/src/WebServerCustom.cpp index e4b53aa0..de15317e 100644 --- a/lib/ZumoOta/src/WebServerCustom.cpp +++ b/lib/ZumoOta/src/WebServerCustom.cpp @@ -167,15 +167,6 @@ void WebServerCustom::init() } }); - /*server.on("/changeProfile", HTTP_GET, [](AsyncWebServerRequest *request) - { - - request->send(LittleFS, "/login.html","text/html"); - });*/ - - - - server.on("/uploadFirmware", HTTP_GET, [](AsyncWebServerRequest *request) { @@ -190,13 +181,6 @@ void WebServerCustom::init() }); -/*server.on("/performFirmwareUpdate", HTTP_POST, [](AsyncWebServerRequest* request) -{ - { - request->send(200, "text/plain", "Firmware update successful!"); - - } -});*/ diff --git a/lib/ZumoOta/src/Zumo32U4Specifications.h b/lib/ZumoOta/src/Zumo32U4Specifications.h index e3975bd5..c88c50ad 100644 --- a/lib/ZumoOta/src/Zumo32U4Specifications.h +++ b/lib/ZumoOta/src/Zumo32U4Specifications.h @@ -72,7 +72,7 @@ namespace Zumo32U4Specification /** Command for reading the software ID */ static const uint8_t READ_SW_ID_COMMAND[] = {0x53}; - /** Command for reading the software version * + /** Command for reading the software version */ static const uint8_t READ_SW_VERSION[] = {0x56}; /** Command for reading the hardware version */ @@ -129,7 +129,6 @@ namespace Zumo32U4Specification /** The expected bootloader ID string */ static const uint8_t EXPECTED_SOFTWARE_ID[] = {'C', 'A', 'T', 'E', 'R', 'I', 'N', '\0'}; - /** The expected bootloader version */ static const uint8_t EXPECTED_SW_VERSION[] = {0x31, 0x30}; @@ -161,4 +160,6 @@ namespace Zumo32U4Specification /** The expected signature value */ static const uint8_t EXPECTED_SIGNATURE[] = {0x87, 0x95, 0x1E}; }; + #endif /** __ZUMO32U4Specification_H__ */ +/** @} */