Skip to content

Commit

Permalink
Merge pull request #40 from chikuta/fix-mcp-multi-communication
Browse files Browse the repository at this point in the history
Fix mcp multi communication
  • Loading branch information
chikuta authored Oct 7, 2024
2 parents 2354223 + 624d0c8 commit ec53eb3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cybergear_can_interface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public:
virtual bool send_message(uint32_t id, const uint8_t * data, uint8_t len, bool ext) = 0;
virtual bool read_message(unsigned long & id, uint8_t * data, uint8_t & len) = 0;
virtual bool available() = 0;
virtual bool support_interrupt() = 0;
};

#endif // CYBERGEAR_CAN_INTERFACE_HH
2 changes: 2 additions & 0 deletions src/cybergear_can_interface_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ bool CybergearCanInterfaceEsp32::available()
CG_DEBUG_FUNC
return (buffer.isEmpty() == false);
}

bool CybergearCanInterfaceEsp32::support_interrupt() { return true; }
1 change: 1 addition & 0 deletions src/cybergear_can_interface_esp32.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public:
virtual bool send_message(uint32_t id, const uint8_t * data, uint8_t len, bool ext);
virtual bool read_message(unsigned long & id, uint8_t * data, uint8_t & len);
virtual bool available();
virtual bool support_interrupt();

private:
uint8_t receive_buffer_[64]; //!< receive buffer
Expand Down
2 changes: 2 additions & 0 deletions src/cybergear_can_interface_mcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ bool CybergearCanInterfaceMcp::available()
}
return true;
}

bool CybergearCanInterfaceMcp::support_interrupt() { return false; }
1 change: 1 addition & 0 deletions src/cybergear_can_interface_mcp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public:
virtual bool send_message(uint32_t id, const uint8_t * data, uint8_t len, bool ext);
virtual bool read_message(unsigned long & id, uint8_t * data, uint8_t & len);
virtual bool available();
virtual bool support_interrupt();

private:
MCP_CAN * pcan_ = nullptr;
Expand Down
24 changes: 24 additions & 0 deletions src/cybergear_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ bool CybergearController::set_run_mode(
bool ret = true;
for (uint8_t idx = 0; idx < ids.size(); ++idx) {
ret &= set_run_mode(ids[idx], modes[idx]);
if (!can_->support_interrupt()) {
process_packet();
}
}
return ret;
}
Expand All @@ -73,6 +76,9 @@ bool CybergearController::set_run_mode(uint8_t mode)
{
for (uint8_t idx = 0; idx < motor_ids_.size(); ++idx) {
drivers_[motor_ids_[idx]].set_run_mode(mode);
if (!can_->support_interrupt()) {
process_packet();
}
}
return true;
}
Expand Down Expand Up @@ -168,6 +174,9 @@ bool CybergearController::enable_motors()
{
for (uint8_t idx = 0; idx < motor_ids_.size(); ++idx) {
drivers_[motor_ids_[idx]].enable_motor();
if (!can_->support_interrupt()) {
process_packet();
}
}
return true;
}
Expand All @@ -183,6 +192,9 @@ bool CybergearController::reset_motors()
{
for (uint8_t idx = 0; idx < motor_ids_.size(); ++idx) {
drivers_[motor_ids_[idx]].reset_motor();
if (!can_->support_interrupt()) {
process_packet();
}
}
return true;
}
Expand All @@ -198,6 +210,9 @@ bool CybergearController::send_motion_command(
bool ret = true;
for (uint8_t idx = 0; idx < ids.size(); ++idx) {
ret &= send_motion_command(ids[idx], cmds[idx]);
if (!can_->support_interrupt()) {
process_packet();
}
}
return ret;
}
Expand Down Expand Up @@ -228,6 +243,9 @@ bool CybergearController::send_position_command(
bool ret = true;
for (uint8_t idx = 0; idx < ids.size(); ++idx) {
ret &= send_position_command(ids[idx], positions[idx]);
if (!can_->support_interrupt()) {
process_packet();
}
}
return ret;
}
Expand All @@ -251,6 +269,9 @@ bool CybergearController::send_speed_command(
bool ret = true;
for (uint8_t idx = 0; idx < ids.size(); ++idx) {
ret &= send_speed_command(ids[idx], speeds[idx]);
if (!can_->support_interrupt()) {
process_packet();
}
}
return ret;
}
Expand All @@ -274,6 +295,9 @@ bool CybergearController::send_current_command(
bool ret = true;
for (uint8_t idx = 0; idx < ids.size(); ++idx) {
ret &= send_current_command(ids[idx], currents[idx]);
if (!can_->support_interrupt()) {
process_packet();
}
}
return ret;
}
Expand Down

0 comments on commit ec53eb3

Please sign in to comment.