static inline void emulateSingleFrameBroadcastTransfer(CanDriver& can, uavcan::NodeID node_id, const MessageType& message, uavcan::TransferID tid) { uavcan::StaticTransferBuffer<100> buffer; uavcan::BitStream bitstream(buffer); uavcan::ScalarCodec codec(bitstream); // Manual message publication ASSERT_LT(0, MessageType::encode(message, codec)); ASSERT_GE(8, buffer.getMaxWritePos()); // DataTypeID data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id, // uint_fast8_t frame_index, TransferID transfer_id, bool last_frame uavcan::Frame frame(MessageType::DefaultDataTypeID, uavcan::TransferTypeMessageBroadcast, node_id, uavcan::NodeID::Broadcast, tid); frame.setStartOfTransfer(true); frame.setEndOfTransfer(true); ASSERT_EQ(buffer.getMaxWritePos(), frame.setPayload(buffer.getRawPtr(), buffer.getMaxWritePos())); uavcan::CanFrame can_frame; ASSERT_TRUE(frame.compile(can_frame)); can.pushRxToAllIfaces(can_frame); }
int init(DelayCallable delay_callable, uavcan::uint32_t& inout_bitrate = BitRateAutoDetect) { if (inout_bitrate > 0) { return driver.init(inout_bitrate, CanIface::NormalMode); } else { static const uavcan::uint32_t StandardBitRates[] = { 1000000, 500000, 250000, 125000 }; for (uavcan::uint8_t br = 0; br < sizeof(StandardBitRates) / sizeof(StandardBitRates[0]); br++) { inout_bitrate = StandardBitRates[br]; const int res = driver.init(inout_bitrate, CanIface::SilentMode); delay_callable(); if (res >= 0) { for (uavcan::uint8_t iface = 0; iface < driver.getNumIfaces(); iface++) { if (!driver.getIface(iface)->isRxBufferEmpty()) { // Re-initializing in normal mode return driver.init(inout_bitrate, CanIface::NormalMode); } } } } return -ErrBitRateNotDetected; } }
/** * This overload simply configures the provided bitrate. * Auto bit rate detection will not be performed. * Bitrate value must be positive. * @return Negative value on error; non-negative on success. Refer to constants Err*. */ int init(uavcan::uint32_t bitrate) { return driver.init(bitrate, CanIface::NormalMode); }
int init(const uavcan::uint32_t bitrate, const CanIface::OperatingMode mode, uavcan::uint8_t can_number) { return driver.init(bitrate, mode, can_number); }
int init(uavcan::uint32_t bitrate) { return driver.init(bitrate); }