void handleTimerEvent(const uavcan::TimerEvent&) final override { if (!read_client_.hasPendingCalls()) { uavcan::protocol::file::Read::Request req; req.path.path = source_path_; req.offset = image_.size(); const int res = read_client_.call(source_node_id_, req); if (res < 0) { std::cerr << "Read call failed: " << res << std::endl; } } }
/** * Download will start immediately upon construction. * Destroy the object to cancel the process. */ FirmwareLoader(uavcan::INode& node, uavcan::NodeID source_node_id, const uavcan::protocol::file::Path::FieldTypes::path& source_path) : uavcan::TimerBase(node), source_node_id_(source_node_id), source_path_(source_path), read_client_(node) { image_.reserve(1024); // Arbitrary value /* * According to the specification, response priority equals request priority. * Typically, file I/O should be executed at a very low priority level. */ read_client_.setPriority(uavcan::TransferPriority::OneHigherThanLowest); read_client_.setCallback(ReadResponseCallback(this, &FirmwareLoader::handleReadResponse)); /* * Rate-limiting is necessary to avoid bus congestion. * The exact rate depends on the application's requirements and CAN bit rate. */ uavcan::TimerBase::startPeriodic(uavcan::MonotonicDuration::fromMSec(200)); }
can_driver_s(): speed_pid_client(getNode()), position_pid_client(getNode()), current_pid_client(getNode()), config_client(getNode()), enable_client(getNode()), feedback_stream_pub(getNode()), velocity_pub(getNode()), position_pub(getNode()), torque_pub(getNode()), voltage_pub(getNode()), trajectory_pub(getNode()) { speed_pid_client.init(); speed_pid_client.setCallback(speed_pid_client_cb); position_pid_client.init(); position_pid_client.setCallback(position_pid_client_cb); current_pid_client.init(); current_pid_client.setCallback(current_pid_client_cb); config_client.init(); config_client.setCallback(config_client_cb); enable_client.init(); enable_client.setCallback(enable_client_cb); feedback_stream_pub.init(); feedback_stream_pub.setCallback(feedback_stream_pub_cb); enabled = false; last_setpoint_update = timestamp_get(); }