Skip to content

Commit 947ce9d

Browse files
committed
Adjusted sendCommand Method
1 parent 24eba00 commit 947ce9d

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

lib/ZumoOta/src/FlashManager.cpp

+25-7
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ const uint8_t NEXT_SERIAL_SEND_DELAY_MS = 10;
6161
/******************************************************************************
6262
* Local Variables
6363
*****************************************************************************/
64-
const uint16_t WAIT_TIME_MS = 500U;
64+
/*Delay before processing the response.
65+
const uint8_t AWAIT_RESPONSE_DELAY_MS = 50U;*/
6566

6667
/** Specifies the number of bytes stored in one Zumo bootloader/flash memory page.*/
6768
static const uint16_t PAGE_SIZE_BYTES = 128U;
@@ -80,10 +81,10 @@ FlashManager::~FlashManager()
8081
{
8182
}
8283

83-
void FlashManager::readToRobotFlash(size_t expectedsize)
84+
bool FlashManager::readToRobotFlash(size_t expectedsize)
8485
{
86+
bool retCode = false;
8587
Stream& deviceStream = Board::getInstance().getDevice().getStream();
86-
Board::getInstance().getDevice().process();
8788
int availableBytes = deviceStream.available();
8889
if (0 < availableBytes)
8990

@@ -114,23 +115,40 @@ void FlashManager::readToRobotFlash(size_t expectedsize)
114115
Serial.print(" ");
115116
}
116117
Serial.println();
118+
retCode = true;
117119
}
118120
else
119121
{
120122
LOG_INFO("Failure!");
121123
}
122124
}
125+
return retCode;
123126

124127
}
125128

126129
void FlashManager ::sendCommand(const uint8_t command[])
127130
{
131+
const uint16_t WRITE_BUFFER_SIZE = 256;
132+
uint8_t writeBuffer[WRITE_BUFFER_SIZE];
128133
Stream& deviceStream = Board::getInstance().getDevice().getStream();
129-
size_t commandsize = sizeof(command[0]);
130-
size_t mysize= deviceStream.write(command, commandsize);
131-
132-
readToRobotFlash(mysize);
134+
/*Size of array*/
135+
size_t commandsize = sizeof(command);
136+
/* Copy the command OpCode into buffer */
137+
memcpy(writeBuffer, command, commandsize);
138+
139+
/* Send the OpCode and command data to Zumo robot */
140+
size_t bytesWritten= deviceStream.write(command, commandsize);
133141

142+
if(bytesWritten == commandsize)
143+
{
144+
/* Await response */
145+
delay(50);
146+
readToRobotFlash(commandsize);
147+
}
148+
else
149+
{
150+
LOG_ERROR("Could not send data packet to Zumo robot. Aborting now");
151+
}
134152
}
135153

136154
void FlashManager:: enterBootloadermode()

lib/ZumoOta/src/FlashManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class FlashManager
6363
* This function reads data from the provided stream and writes it to
6464
* the robot's flash memory.
6565
*/
66-
void readToRobotFlash(size_t expectedsize);
66+
bool readToRobotFlash(size_t expectedsize);
6767

6868
/**
6969
* @brief exit the bootloader mode.

lib/ZumoOta/src/WebServerCustom.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,6 @@ void WebServerCustom::init()
167167
}
168168
});
169169

170-
/*server.on("/changeProfile", HTTP_GET, [](AsyncWebServerRequest *request)
171-
{
172-
173-
request->send(LittleFS, "/login.html","text/html");
174-
});*/
175-
176-
177-
178-
179170

180171
server.on("/uploadFirmware", HTTP_GET, [](AsyncWebServerRequest *request)
181172
{
@@ -190,13 +181,6 @@ void WebServerCustom::init()
190181
});
191182

192183

193-
/*server.on("/performFirmwareUpdate", HTTP_POST, [](AsyncWebServerRequest* request)
194-
{
195-
{
196-
request->send(200, "text/plain", "Firmware update successful!");
197-
198-
}
199-
});*/
200184

201185

202186

lib/ZumoOta/src/Zumo32U4Specifications.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace Zumo32U4Specification
7272
/** Command for reading the software ID */
7373
static const uint8_t READ_SW_ID_COMMAND[] = {0x53};
7474

75-
/** Command for reading the software version *
75+
/** Command for reading the software version */
7676
static const uint8_t READ_SW_VERSION[] = {0x56};
7777

7878
/** Command for reading the hardware version */
@@ -129,7 +129,6 @@ namespace Zumo32U4Specification
129129
/** The expected bootloader ID string */
130130
static const uint8_t EXPECTED_SOFTWARE_ID[] = {'C', 'A', 'T', 'E', 'R', 'I', 'N', '\0'};
131131

132-
133132
/** The expected bootloader version */
134133

135134
static const uint8_t EXPECTED_SW_VERSION[] = {0x31, 0x30};
@@ -161,4 +160,6 @@ namespace Zumo32U4Specification
161160
/** The expected signature value */
162161
static const uint8_t EXPECTED_SIGNATURE[] = {0x87, 0x95, 0x1E};
163162
};
163+
164164
#endif /** __ZUMO32U4Specification_H__ */
165+
/** @} */

0 commit comments

Comments
 (0)