Skip to content

Commit 7390004

Browse files
korjaa-nordickartben
authored andcommitted
shell: modules: devmem: fix devmem load occasionally losing bytes
Changed devmem load to process all characters from the *recv buffer. Signed-off-by: Jaakko Korhonen <[email protected]>
1 parent 84c2f87 commit 7390004

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

subsys/shell/modules/devmem_service.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,25 @@ static void bypass_cb(const struct shell *sh, uint8_t *recv, size_t len)
175175
static uint8_t tail;
176176
uint8_t byte;
177177

178-
if (tail == CHAR_CAN && recv[0] == CHAR_DC1) {
179-
escape = true;
180-
} else {
181-
for (int i = 0; i < (len - 1); i++) {
182-
if (recv[i] == CHAR_CAN && recv[i + 1] == CHAR_DC1) {
183-
escape = true;
184-
break;
185-
}
178+
for (size_t i = 0; i < len; i++) {
179+
if (tail == CHAR_CAN && recv[i] == CHAR_DC1) {
180+
escape = true;
181+
tail = 0;
182+
break;
183+
}
184+
tail = recv[i];
185+
186+
if (is_ascii(recv[i])) {
187+
chunk[chunk_element] = recv[i];
188+
chunk_element++;
189+
}
190+
191+
if (chunk_element == 2) {
192+
byte = (uint8_t)strtoul(chunk, NULL, 16);
193+
*bytes = byte;
194+
bytes++;
195+
sum++;
196+
chunk_element = 0;
186197
}
187198
}
188199

@@ -206,21 +217,6 @@ static void bypass_cb(const struct shell *sh, uint8_t *recv, size_t len)
206217
}
207218
return;
208219
}
209-
210-
tail = recv[len - 1];
211-
212-
if (is_ascii(*recv)) {
213-
chunk[chunk_element] = *recv;
214-
chunk_element++;
215-
}
216-
217-
if (chunk_element == 2) {
218-
byte = (uint8_t)strtoul(chunk, NULL, 16);
219-
*bytes = byte;
220-
bytes++;
221-
sum++;
222-
chunk_element = 0;
223-
}
224220
}
225221

226222
static int cmd_load(const struct shell *sh, size_t argc, char **argv)

0 commit comments

Comments
 (0)