• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pybricks / pybricks-micropython / 19016791193

02 Nov 2025 06:40PM UTC coverage: 57.167% (-2.6%) from 59.744%
19016791193

Pull #406

github

laurensvalk
bricks/virtualhub: Replace with embedded simulation.

Instead of using the newly introduced simhub alongside the virtualhub, we'll just replace the old one entirely now that it has reached feature parity. We can keep calling it the virtualhub.
Pull Request #406: New virtual hub for more effective debugging

41 of 48 new or added lines in 7 files covered. (85.42%)

414 existing lines in 53 files now uncovered.

4479 of 7835 relevant lines covered (57.17%)

17178392.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.45
/lib/pbio/src/logger.c
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) 2018-2023 The Pybricks Authors
3

4
#include <pbio/config.h>
5

6
#if PBIO_CONFIG_LOGGER
7

8
#include <stdlib.h>
9
#include <stdbool.h>
10
#include <inttypes.h>
11

12
#include <pbdrv/clock.h>
13
#include <pbio/config.h>
14
#include <pbio/error.h>
15
#include <pbio/logger.h>
16

17
/**
18
 * Starts logging in the background.
19
 *
20
 * @param [in]  log         Pointer to log.
21
 * @param [in]  buf         Array large enough to hold @p num_rows rows of data.
22
 * @param [in]  num_rows    Maximum number of rows that can be logged.
23
 * @param [in]  num_cols    Number of entries in one row.
24
 * @param [in]  down_sample For every @p down_sample of update calls, only one row is logged.
25
 */
26
void pbio_logger_start(pbio_log_t *log, int32_t *buf, uint32_t num_rows, uint8_t num_cols, int32_t down_sample) {
×
27
    // (re-)initialize logger status.
28
    log->num_rows_used = 0;
×
29
    log->skipped_samples = 0;
×
30
    log->data = buf;
×
31
    log->num_rows = num_rows;
×
32
    log->num_cols = num_cols;
×
33
    log->down_sample = down_sample;
×
34
    log->start_time = pbdrv_clock_get_ms();
×
35

36
    // Data may now be logged.
37
    log->active = true;
×
38
}
×
39

40
/**
41
 * Stops accepting new data from background loops.
42
 *
43
 * @param [in]  log         Pointer to log.
44
 */
45
void pbio_logger_stop(pbio_log_t *log) {
×
46
    log->active = false;
×
47
}
×
48

49
/**
50
 * Checks if log is active (data can be added).
51
 *
52
 * @param [in]  log         Pointer to log.
53
 * @return                  True if pbio_logger_add_row may be called, else false.
54
 */
55
bool pbio_logger_is_active(const pbio_log_t *log) {
101,382✔
56
    return log->active;
101,382✔
57
}
58

59
/**
60
 * Add new data from a background loop.
61
 *
62
 * @param [in]  log         Pointer to log.
63
 * @param [in]  row_data    Data to be added.
64
 */
65
void pbio_logger_add_row(pbio_log_t *log, const int32_t *row_data) {
×
66

67
    // Skip logging if we are not yet at a multiple of down_sample.
68
    if (++log->skipped_samples != log->down_sample) {
×
UNCOV
69
        return;
×
70
    }
71
    log->skipped_samples = 0;
×
72

73
    // Exit if log is full.
74
    if (log->num_rows_used >= log->num_rows) {
×
75
        log->active = false;
×
76
        return;
×
77
    }
78

79
    // Write time of logging.
80
    log->data[log->num_rows_used * log->num_cols] = pbdrv_clock_get_ms() - log->start_time;
×
81

82
    // Write the data.
83
    for (uint8_t i = PBIO_LOGGER_NUM_DEFAULT_COLS; i < log->num_cols; i++) {
×
84
        log->data[log->num_rows_used * log->num_cols + i] = row_data[i - PBIO_LOGGER_NUM_DEFAULT_COLS];
×
85
    }
86

87
    // Increment used row counter.
88
    log->num_rows_used++;
×
89

90
    return;
×
91
}
92

93
/**
94
 * Gets number of used (filled) rows in the log.
95
 *
96
 * @param [in]  log         Pointer to log.
97
 * @return                  Number of used rows.
98
 */
99
uint32_t pbio_logger_get_num_rows_used(const pbio_log_t *log) {
×
100
    return log->num_rows_used;
×
101
}
102

103
/**
104
 * Gets row from the log. Caller must ensure that valid index is used.
105
 *
106
 * @param [in]  log         Pointer to log.
107
 * @return                  Pointer to row data.
108
 */
109
int32_t *pbio_logger_get_row_data(const pbio_log_t *log, uint32_t index) {
×
110
    return log->data + index * log->num_cols;
×
111
}
112

113
#endif // PBIO_CONFIG_LOGGER
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc