2023-05-21 22:57:51 -03:00
|
|
|
/*
|
|
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Oliver Walters / Currawong Engineering Pty Ltd
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_CANManager/AP_CANManager.h>
|
|
|
|
|
2023-05-21 23:05:49 -03:00
|
|
|
#ifndef HAL_PICCOLO_CAN_ENABLE
|
2023-06-07 23:00:51 -03:00
|
|
|
#define HAL_PICCOLO_CAN_ENABLE HAL_NUM_CAN_IFACES
|
2023-05-21 23:05:49 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAL_PICCOLO_CAN_ENABLE
|
|
|
|
|
2024-02-13 13:44:08 -04:00
|
|
|
//! Piccolo message groups form part of the CAN ID of each frame
|
2023-05-21 22:57:51 -03:00
|
|
|
enum class PiccoloCAN_MessageGroup : uint8_t {
|
2024-02-13 13:44:08 -04:00
|
|
|
SIMULATOR = 0x00, //!< Simulator messages
|
|
|
|
SENSOR = 0x04, //!< External sensors
|
|
|
|
ACTUATOR = 0x07, //!< Actuators (e.g. ESC / servo)
|
|
|
|
ECU_OUT = 0x08, //!< Messages *from* an ECU
|
|
|
|
ECU_IN = 0x09, //!< Message *to* an ECU
|
2023-05-21 22:57:51 -03:00
|
|
|
|
2024-02-13 13:44:08 -04:00
|
|
|
SYSTEM = 0x19, //!< System messages (e.g. bootloader)
|
2023-05-21 22:57:51 -03:00
|
|
|
};
|
|
|
|
|
2024-02-13 13:44:08 -04:00
|
|
|
//! Piccolo actuator types differentiate between actuator frames
|
2023-05-21 22:57:51 -03:00
|
|
|
enum class PiccoloCAN_ActuatorType : uint8_t {
|
|
|
|
SERVO = 0x00,
|
|
|
|
ESC = 0x20,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic PiccoloCAN device class implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
class AP_PiccoloCAN_Device
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool handle_can_frame(AP_HAL::CANFrame &frame) = 0;
|
|
|
|
|
|
|
|
// Determine if this device is "enabled" (default implementation returns false)
|
|
|
|
virtual bool is_enabled(void) const { return false; }
|
|
|
|
|
|
|
|
// Determine if this device has been seen within a specified timeframe
|
2024-10-09 01:15:44 -03:00
|
|
|
virtual bool is_connected(uint32_t timeout_us) const {
|
2023-05-21 22:57:51 -03:00
|
|
|
uint64_t now = AP_HAL::micros64();
|
|
|
|
|
2024-10-09 01:15:44 -03:00
|
|
|
return now < (last_msg_timestamp + timeout_us);
|
2023-05-21 22:57:51 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the received message timestamp
|
|
|
|
void reset_rx_timestamp() {
|
|
|
|
last_msg_timestamp = AP_HAL::micros64();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Timestamp of most recently received CAN message
|
|
|
|
uint64_t last_msg_timestamp = 0;
|
2023-05-21 23:05:49 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HAL_PICCOLO_CAN_ENABLE
|