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

pybricks / pybricks-micropython / 10047310602

22 Jul 2024 07:41PM UTC coverage: 56.042% (-0.6%) from 56.592%
10047310602

Pull #246

github

laurensvalk
!WIP pybricks.tools.AppData: Implement write.
Pull Request #246: pybricks.tools: Add hostbuffer to receive IDE data

9 of 80 new or added lines in 5 files covered. (11.25%)

12 existing lines in 5 files now uncovered.

3766 of 6720 relevant lines covered (56.04%)

20062093.59 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 <pbsys/storage.h>
12

13
#include "./bluetooth.h"
14
#include "./storage.h"
15
#include "./program_stop.h"
16
#include "./user_program.h"
17

18
static pbsys_command_write_app_data_callback_t write_app_data_callback = NULL;
19

20
/**
21
 * Sets callback for the write program data buffer command.
22
 *
23
 * @param [in]  callback  The callback to set or @c NULL to unset.
24
 */
NEW
25
void pbsys_command_set_write_app_data_callback(pbsys_command_write_app_data_callback_t callback) {
×
NEW
26
    write_app_data_callback = callback;
×
NEW
27
}
×
28

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

38
    pbio_pybricks_command_t cmd = data[0];
1✔
39

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