mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-24 15:40:31 +08:00
Revise VescWritableInterface
This commit is contained in:
@@ -122,13 +122,7 @@ size_t VescDriver::sendPacket(const uint8_t *payload, uint16_t payload_length, c
|
||||
packet_buffer[index++] = 3;
|
||||
|
||||
// Write bytes out through callback interface
|
||||
size_t ret{0};
|
||||
|
||||
if (_vesc_writable) {
|
||||
ret = _vesc_writable->writeCallback(packet_buffer, index);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return _vesc_writable.writeCallback(packet_buffer, index);
|
||||
}
|
||||
|
||||
void VescDriver::parseInputByte(uint8_t byte)
|
||||
|
||||
@@ -41,14 +41,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "VescProtocol.h"
|
||||
#include "VescWritable.hpp"
|
||||
#include "VescWritableInterface.hpp"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
class VescDriver
|
||||
{
|
||||
public:
|
||||
VescDriver(VescWritable *vesc_writable) : _vesc_writable(vesc_writable) {};
|
||||
VescDriver(VescWritableInterface &vesc_writable) : _vesc_writable(vesc_writable) {};
|
||||
~VescDriver() = default;
|
||||
|
||||
void commandDutyCycle(float duty_cycle, const uint8_t forward_can_id = 0);
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
float extractFloat32(const uint8_t *buffer, uint16_t &index);
|
||||
|
||||
// Write access to device through callback
|
||||
VescWritable *_vesc_writable;
|
||||
VescWritableInterface &_vesc_writable;
|
||||
|
||||
// Input packet parsing
|
||||
size_t _input_byte_index{0}; ///< keeps track of the input packets parsing state
|
||||
|
||||
+2
-6
@@ -32,7 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file VescWritable.hpp
|
||||
* @file VescWritableInterface.hpp
|
||||
* @brief Interface calls defining the write callback for VESC communication
|
||||
* @details To keep the driver cross-platform compatible the device owner class
|
||||
* needs to implement this interface and pass itself to the driver via constructor
|
||||
@@ -43,12 +43,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
class VescWritable
|
||||
class VescWritableInterface
|
||||
{
|
||||
public:
|
||||
VescWritable() = default;
|
||||
~VescWritable() = default;
|
||||
virtual size_t writeCallback(const uint8_t *buffer, const uint16_t length) = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
@@ -45,7 +45,7 @@ using namespace time_literals;
|
||||
|
||||
VescDevice::VescDevice(const char *port) :
|
||||
ScheduledWorkItem(MODULE_NAME, px4::serial_port_to_wq(port)),
|
||||
_vesc_driver(this)
|
||||
_vesc_driver(*this)
|
||||
{
|
||||
// Store port name
|
||||
strncpy(_port, port, sizeof(_port) - 1);
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include "VescDriver/VescDriver.hpp"
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
|
||||
class VescDevice : public px4::ScheduledWorkItem, public VescWritable
|
||||
class VescDevice : public px4::ScheduledWorkItem, public VescWritableInterface
|
||||
{
|
||||
public:
|
||||
VescDevice(const char *port);
|
||||
|
||||
Reference in New Issue
Block a user