Skip to content

Commit cd7740c

Browse files
committed
More granular error reporting
1 parent 1d76e54 commit cd7740c

File tree

1 file changed

+21
-6
lines changed
  • firmware/nRF51/tag-proximity/src

1 file changed

+21
-6
lines changed

firmware/nRF51/tag-proximity/src/log.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ static void flash_log_block_commit(void)
161161
current_block = FLASH_LOG_FIRST_BLOCK;
162162
#else
163163
log_running = 0;
164+
status_flags |= ERROR_FLASH_FULL;
164165
#endif
165166
}
166167

@@ -223,8 +224,10 @@ static int flash_log_write(uint8_t flush_buf)
223224
sres = heatshrink_encoder_sink(&hse, buf_tail, chunk_size, &sink_sz);
224225

225226
/* handle encoder error */
226-
if (sres < 0)
227+
if (sres < 0) {
228+
status_flags |= ERROR_LOG_COMPRESS;
227229
goto cleanup;
230+
}
228231

229232
/* advance tail of ring buffer */
230233
buf_tail += sink_sz;
@@ -239,12 +242,21 @@ static int flash_log_write(uint8_t flush_buf)
239242
LOG_BLOCK_DATA_SIZE - LogBlock.env.len,
240243
&poll_sz);
241244

245+
/* update block length */
242246
LogBlock.env.len += poll_sz;
247+
248+
/* handle block buffer overflow */
249+
if (LogBlock.env.len >= LOG_BLOCK_DATA_SIZE) {
250+
status_flags |= ERROR_LOG_BLK_OVERFLOW;
251+
goto cleanup;
252+
}
243253
} while (pres == HSER_POLL_MORE);
244254

245255
/* handle encoder error */
246-
if (pres < 0)
256+
if (pres < 0) {
257+
status_flags |= ERROR_LOG_COMPRESS;
247258
goto cleanup;
259+
}
248260
}
249261

250262
/* if block buffer is almost full, or if we are flushing the ring buffer,
@@ -255,8 +267,10 @@ static int flash_log_write(uint8_t flush_buf)
255267
fres = heatshrink_encoder_finish(&hse);
256268

257269
/* handle encoder error */
258-
if (fres < 0)
270+
if (fres < 0) {
271+
status_flags |= ERROR_LOG_COMPRESS;
259272
goto cleanup;
273+
}
260274

261275
/* if necessary, pull out remaining compressed data */
262276
if (fres == HSER_FINISH_MORE)
@@ -280,8 +294,10 @@ static int flash_log_write(uint8_t flush_buf)
280294
}
281295

282296
/* handle encoder error */
283-
if (pres < 0)
297+
if (pres < 0) {
298+
status_flags |= ERROR_LOG_COMPRESS;
284299
goto cleanup;
300+
}
285301

286302
/* reset encoder */
287303
heatshrink_encoder_reset(&hse);
@@ -296,9 +312,8 @@ static int flash_log_write(uint8_t flush_buf)
296312
/* on error, reset all state */
297313
cleanup:
298314

299-
/* report error */
315+
/* log error */
300316
log_compression_error++;
301-
status_flags |= ERROR_LOG_COMPRESS;
302317

303318
/* clear block buffer */
304319
block_init();

0 commit comments

Comments
 (0)