Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions lib/cpp/mjbots/moteus/moteus_multiplex.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

#pragma once

#include <iomanip>
#include <iostream>

#include <math.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -303,19 +300,20 @@ class MultiplexParser {
uint16_t value = 0;
Resolution resolution = kIgnore;
int8_t command = 0;
int8_t count = 0;

Result(bool done_in, uint16_t value_in, Resolution resolution_in,
int8_t command_in)
int8_t command_in, int8_t count_in)
: done(done_in), value(value_in), resolution(resolution_in),
command(command_in) {}
command(command_in), count(count_in) {}

Result() {}
};

Result next() {
if (offset_ >= size_) {
// We are done.
return Result(true, 0, Resolution::kInt8, Multiplex::kNop);
return Result(true, 0, Resolution::kInt8, Multiplex::kNop, 0);
}

if (remaining_) {
Expand All @@ -324,11 +322,11 @@ class MultiplexParser {

// Do we actually have enough data?
if (offset_ + ResolutionSize(current_resolution_) > size_) {
return Result(true, 0, Resolution::kInt8, Multiplex::kNop);
return Result(true, 0, Resolution::kInt8, Multiplex::kNop, 0);
}

return Result(false, this_register, current_resolution_,
current_command_);
return Result(false, this_register, current_resolution_, current_command_,
remaining_);
}

// We need to look for another command.
Expand Down Expand Up @@ -375,32 +373,31 @@ class MultiplexParser {
// Empty, guess we can ignore.
continue;
}

current_register_ = ReadVaruint();

// If it's a read registry we do not need to look further.
if (current_command_ >= 0x10 && current_command_ < 0x20) {
remaining_ = 0;
return Result(false, current_register_++, current_resolution_,
current_command_);
current_command_, count);
}

remaining_ = count - 1;

if (offset_ + ResolutionSize(current_resolution_) > size_) {
return Result(true, 0, Resolution::kInt8, Multiplex::kNop);
return Result(true, 0, Resolution::kInt8, Multiplex::kNop, 0);
}

return Result(false, current_register_++, current_resolution_,
current_command_);
current_command_, count);
}

// For anything else, we'll just assume it is an error of some
// sort and stop parsing.
offset_ = size_;
break;
}
return Result(true, 0, Resolution::kInt8, Multiplex::kNop);
return Result(true, 0, Resolution::kInt8, Multiplex::kNop, 0);
}

template <typename T> T Read() {
Expand Down
Loading