Skip to content

Commit

Permalink
wip test read only rpm
Browse files Browse the repository at this point in the history
Change-Id: Ie80b95b50b330f7f79680f9b854e2321ba13797c
  • Loading branch information
oliverlee committed Jul 28, 2023
1 parent d0e7603 commit 0b4b19a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion examples/vesc_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include <fmt/core.h>
#include <thread>

#include <array>
#include <cstdint>

auto payload_buffer = std::array<std::uint8_t, 256>{};

auto main() -> int
{
const auto current = -10.0F;
Expand All @@ -16,7 +21,8 @@ auto main() -> int
fmt::print("current: {}\n", std::int16_t(current));

const auto start = std::chrono::steady_clock::now();
fmt::print("rpm: {}\n", ::vesc::extra::read_rpm());
//fmt::print("rpm: {}\n", ::vesc::extra::read_rpm());
::vesc::extra::read_payload(std::span{payload_buffer});

const auto elapsed = std::chrono::steady_clock::now() - start;
fmt::print("{}\n", std::chrono::duration<float>{elapsed}.count());
Expand Down
13 changes: 11 additions & 2 deletions third_party/vesc_uart/src/extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
#include <cstddef>
#include <cstring>

#include <iostream>

namespace {

static constexpr auto serial_device = 0;

auto payload_buffer = std::array<std::uint8_t, 256>{};

auto cmd_get_values = std::uint8_t{COMM_GET_VALUES};
// try to use COMM_GET_VALUES_SELECTIVE
constexpr std::uint8_t rpm_bit = 1U << 7;
auto cmd_get_values = std::array<std::uint8_t, 5>{
COMM_GET_VALUES, rpm_bit, 0x00, 0x00, 0x00
};
// auto cmd_get_values = std::uint8_t{COMM_GET_VALUES, 0xFF, 0xFF, 0xFF, 0xFF};

} // namespace

Expand All @@ -24,7 +31,7 @@ namespace vesc::extra {

auto read_payload(std::span<std::uint8_t> buf) -> void
{
::PackSendPayload(&cmd_get_values, sizeof(cmd_get_values), serial_device);
::PackSendPayload(cmd_get_values.data(), sizeof(cmd_get_values), serial_device);

{
[[maybe_unused]] const auto version = Serial.read();
Expand All @@ -39,6 +46,8 @@ auto read_payload(std::span<std::uint8_t> buf) -> void
"`buf` is not large enough to hold "
"message");

std::cout << "payload size: " << static_cast<int>(payload_size) << '\n';

const auto message =
std::span{buf.data(), std::size_t(payload_size + footer_size)};
Serial.read(message);
Expand Down

0 comments on commit 0b4b19a

Please sign in to comment.