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

pybricks / pybricks-micropython / 9014798693

09 May 2024 08:47AM UTC coverage: 56.205% (-0.4%) from 56.563%
9014798693

Pull #246

github

laurensvalk
pybricks.tools.HostBuffer: Unpack values.
Pull Request #246: pybricks.tools: Add hostbuffer to receive IDE data

0 of 42 new or added lines in 3 files covered. (0.0%)

9 existing lines in 3 files now uncovered.

3750 of 6672 relevant lines covered (56.21%)

20206426.09 hits per line

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

34.62
/lib/pbio/sys/command.c
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) 2022-2023 The Pybricks Authors
3

4
#include <assert.h>
5
#include <stdint.h>
6

7
#include <pbdrv/reset.h>
8
#include <pbio/protocol.h>
9
#include <pbsys/command.h>
10

11
#include "./bluetooth.h"
12
#include "./program_load.h"
13
#include "./program_stop.h"
14

15
static pbsys_command_write_program_data_buffer_callback_t write_program_data_buffer_callback = NULL;
16

17
/**
18
 * Sets callback for the write program data buffer command.
19
 *
20
 * @param [in]  callback  The callback to set or @c NULL to unset.
21
 */
NEW
22
void pbsys_command_set_write_program_data_buffer_callback(pbsys_command_write_program_data_buffer_callback_t callback) {
×
NEW
23
    write_program_data_buffer_callback = callback;
×
NEW
24
}
×
25

26
/**
27
 * Parses binary data for command and dispatches handler for command.
28
 * @param [in]  data    The raw command data.
29
 * @param [in]  size    The size of @p data in bytes.
30
 */
31
pbio_pybricks_error_t pbsys_command(const uint8_t *data, uint32_t size) {
1✔
32
    assert(data);
1✔
33
    assert(size);
1✔
34

35
    pbio_pybricks_command_t cmd = data[0];
1✔
36

37
    switch (cmd) {
1✔
38
        case PBIO_PYBRICKS_COMMAND_STOP_USER_PROGRAM:
39
            pbsys_program_stop(false);
40
            return PBIO_PYBRICKS_ERROR_OK;
41
        case PBIO_PYBRICKS_COMMAND_START_USER_PROGRAM:
42
            return pbio_pybricks_error_from_pbio_error(pbsys_program_load_start_user_program());
×
43
        case PBIO_PYBRICKS_COMMAND_START_REPL:
44
            return pbio_pybricks_error_from_pbio_error(pbsys_program_load_start_repl());
×
45
        case PBIO_PYBRICKS_COMMAND_WRITE_USER_PROGRAM_META:
×
46
            return pbio_pybricks_error_from_pbio_error(pbsys_program_load_set_program_size(
×
47
                pbio_get_uint32_le(&data[1])));
48
        case PBIO_PYBRICKS_COMMAND_WRITE_USER_RAM:
×
49
            return pbio_pybricks_error_from_pbio_error(pbsys_program_load_set_program_data(
×
50
                pbio_get_uint32_le(&data[1]), &data[5], size - 5));
51
        case PBIO_PYBRICKS_COMMAND_REBOOT_TO_UPDATE_MODE:
52
            pbdrv_reset(PBDRV_RESET_ACTION_RESET_IN_UPDATE_MODE);
53
            return PBIO_PYBRICKS_ERROR_OK;
54
        case PBIO_PYBRICKS_COMMAND_WRITE_STDIN:
1✔
55
            #if PBSYS_CONFIG_BLUETOOTH
56
            if (pbsys_bluetooth_rx_get_free() < size - 1) {
1✔
57
                return PBIO_PYBRICKS_ERROR_BUSY;
58
            }
59
            pbsys_bluetooth_rx_write(&data[1], size - 1);
1✔
60
            #endif
61
            // If no consumers are configured, goes to "/dev/null" without error
62
            return PBIO_PYBRICKS_ERROR_OK;
1✔
NEW
63
        case PBIO_PYBRICKS_COMMAND_WRITE_PROGRAM_DATA_BUFFER:
×
NEW
64
            if (write_program_data_buffer_callback && size > 3) {
×
NEW
65
                uint16_t offset = pbio_get_uint16_le(&data[1]);
×
NEW
66
                uint16_t data_size = size - 3;
×
NEW
67
                const uint8_t *data_write = &data[3];
×
NEW
68
                write_program_data_buffer_callback(offset, data_size, data_write);
×
69
            }
70
            // If no consumers are configured, goes to "/dev/null" without error
71
            return PBIO_PYBRICKS_ERROR_OK;
72
        default:
×
73
            return PBIO_PYBRICKS_ERROR_INVALID_COMMAND;
×
74
    }
75
}
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