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

pybricks / pybricks-micropython / 9659196825

25 Jun 2024 08:35AM UTC coverage: 56.592% (+10.5%) from 46.065%
9659196825

push

github

laurensvalk
pybricks.hubs: Add update_heading_correction method to imu.

3760 of 6644 relevant lines covered (56.59%)

20292085.46 hits per line

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

52.94
/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

10
#include <pbsys/storage.h>
11

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

17
/**
18
 * Parses binary data for command and dispatches handler for command.
19
 * @param [in]  data    The raw command data.
20
 * @param [in]  size    The size of @p data in bytes.
21
 */
22
pbio_pybricks_error_t pbsys_command(const uint8_t *data, uint32_t size) {
1✔
23
    assert(data);
1✔
24
    assert(size);
1✔
25

26
    pbio_pybricks_command_t cmd = data[0];
1✔
27

28
    switch (cmd) {
1✔
29
        case PBIO_PYBRICKS_COMMAND_STOP_USER_PROGRAM:
30
            pbsys_program_stop(false);
31
            return PBIO_PYBRICKS_ERROR_OK;
32
        case PBIO_PYBRICKS_COMMAND_START_USER_PROGRAM:
33
            return pbio_pybricks_error_from_pbio_error(pbsys_user_program_start_program());
×
34
        case PBIO_PYBRICKS_COMMAND_START_REPL:
35
            return pbio_pybricks_error_from_pbio_error(pbsys_user_program_start_repl());
×
36
        case PBIO_PYBRICKS_COMMAND_WRITE_USER_PROGRAM_META:
×
37
            return pbio_pybricks_error_from_pbio_error(pbsys_storage_set_program_size(
×
38
                pbio_get_uint32_le(&data[1])));
39
        case PBIO_PYBRICKS_COMMAND_WRITE_USER_RAM:
×
40
            return pbio_pybricks_error_from_pbio_error(pbsys_storage_set_program_data(
×
41
                pbio_get_uint32_le(&data[1]), &data[5], size - 5));
42
        case PBIO_PYBRICKS_COMMAND_REBOOT_TO_UPDATE_MODE:
43
            pbdrv_reset(PBDRV_RESET_ACTION_RESET_IN_UPDATE_MODE);
44
            return PBIO_PYBRICKS_ERROR_OK;
45
        case PBIO_PYBRICKS_COMMAND_WRITE_STDIN:
1✔
46
            #if PBSYS_CONFIG_BLUETOOTH
47
            if (pbsys_bluetooth_rx_get_free() < size - 1) {
1✔
48
                return PBIO_PYBRICKS_ERROR_BUSY;
49
            }
50
            pbsys_bluetooth_rx_write(&data[1], size - 1);
1✔
51
            #endif
52
            // If no consumers are configured, goes to "/dev/null" without error
53
            return PBIO_PYBRICKS_ERROR_OK;
1✔
54
        default:
×
55
            return PBIO_PYBRICKS_ERROR_INVALID_COMMAND;
×
56
    }
57
}
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