Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UAVCAN UAVCAN_Subscriber
frame.hpp
00001 /* 00002 * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com> 00003 */ 00004 00005 #ifndef UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED 00006 #define UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED 00007 00008 #include <cassert> 00009 #include <uavcan/transport/transfer.hpp> 00010 #include <uavcan/transport/can_io.hpp> 00011 #include <uavcan/build_config.hpp> 00012 #include <uavcan/data_type.hpp> 00013 00014 namespace uavcan 00015 { 00016 00017 class UAVCAN_EXPORT Frame 00018 { 00019 enum { PayloadCapacity = 7 }; // Will be redefined when CAN FD is available 00020 00021 uint8_t payload_[PayloadCapacity]; 00022 TransferPriority transfer_priority_; 00023 TransferType transfer_type_; 00024 DataTypeID data_type_id_; 00025 uint_fast8_t payload_len_; 00026 NodeID src_node_id_; 00027 NodeID dst_node_id_; 00028 TransferID transfer_id_; 00029 bool start_of_transfer_; 00030 bool end_of_transfer_; 00031 bool toggle_; 00032 00033 public: 00034 Frame() : 00035 transfer_type_(TransferType(NumTransferTypes)), // Invalid value 00036 payload_len_(0), 00037 start_of_transfer_(false), 00038 end_of_transfer_(false), 00039 toggle_(false) 00040 { } 00041 00042 Frame(DataTypeID data_type_id, 00043 TransferType transfer_type, 00044 NodeID src_node_id, 00045 NodeID dst_node_id, 00046 TransferID transfer_id) : 00047 transfer_priority_(TransferPriority::Default), 00048 transfer_type_(transfer_type), 00049 data_type_id_(data_type_id), 00050 payload_len_(0), 00051 src_node_id_(src_node_id), 00052 dst_node_id_(dst_node_id), 00053 transfer_id_(transfer_id), 00054 start_of_transfer_(false), 00055 end_of_transfer_(false), 00056 toggle_(false) 00057 { 00058 UAVCAN_ASSERT((transfer_type == TransferTypeMessageBroadcast) == dst_node_id.isBroadcast()); 00059 UAVCAN_ASSERT(data_type_id.isValidForDataTypeKind(getDataTypeKindForTransferType(transfer_type))); 00060 UAVCAN_ASSERT(src_node_id.isUnicast() ? (src_node_id != dst_node_id) : true); 00061 } 00062 00063 void setPriority(TransferPriority priority) { transfer_priority_ = priority; } 00064 TransferPriority getPriority() const { return transfer_priority_; } 00065 00066 /** 00067 * Max payload length depends on the transfer type and frame index. 00068 */ 00069 uint8_t getPayloadCapacity() const { return PayloadCapacity; } 00070 uint8_t setPayload(const uint8_t* data, unsigned len); 00071 00072 unsigned getPayloadLen() const { return payload_len_; } 00073 const uint8_t* getPayloadPtr() const { return payload_; } 00074 00075 TransferType getTransferType() const { return transfer_type_; } 00076 DataTypeID getDataTypeID() const { return data_type_id_; } 00077 NodeID getSrcNodeID() const { return src_node_id_; } 00078 NodeID getDstNodeID() const { return dst_node_id_; } 00079 TransferID getTransferID() const { return transfer_id_; } 00080 00081 void setStartOfTransfer(bool x) { start_of_transfer_ = x; } 00082 void setEndOfTransfer(bool x) { end_of_transfer_ = x; } 00083 00084 bool isStartOfTransfer() const { return start_of_transfer_; } 00085 bool isEndOfTransfer() const { return end_of_transfer_; } 00086 00087 void flipToggle() { toggle_ = !toggle_; } 00088 bool getToggle() const { return toggle_; } 00089 00090 bool parse(const CanFrame& can_frame); 00091 bool compile(CanFrame& can_frame) const; 00092 00093 bool isValid() const; 00094 00095 bool operator!=(const Frame& rhs) const { return !operator==(rhs); } 00096 bool operator==(const Frame& rhs) const; 00097 00098 #if UAVCAN_TOSTRING 00099 std::string toString() const; 00100 #endif 00101 }; 00102 00103 00104 class UAVCAN_EXPORT RxFrame : public Frame 00105 { 00106 MonotonicTime ts_mono_; 00107 UtcTime ts_utc_; 00108 uint8_t iface_index_; 00109 00110 public: 00111 RxFrame() 00112 : iface_index_(0) 00113 { } 00114 00115 RxFrame(const Frame& frame, MonotonicTime ts_mono, UtcTime ts_utc, uint8_t iface_index) 00116 : ts_mono_(ts_mono) 00117 , ts_utc_(ts_utc) 00118 , iface_index_(iface_index) 00119 { 00120 *static_cast<Frame*>(this) = frame; 00121 } 00122 00123 bool parse(const CanRxFrame& can_frame); 00124 00125 /** 00126 * Can't be zero. 00127 */ 00128 MonotonicTime getMonotonicTimestamp() const { return ts_mono_; } 00129 00130 /** 00131 * Can be zero if not supported by the platform driver. 00132 */ 00133 UtcTime getUtcTimestamp() const { return ts_utc_; } 00134 00135 uint8_t getIfaceIndex() const { return iface_index_; } 00136 00137 #if UAVCAN_TOSTRING 00138 std::string toString() const; 00139 #endif 00140 }; 00141 00142 } 00143 00144 #endif // UAVCAN_TRANSPORT_FRAME_HPP_INCLUDED
Generated on Tue Jul 12 2022 17:17:32 by
