bit_stream.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #ifndef UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED
6 #define UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED
7 
8 #include <cassert>
9 #include <uavcan/std.hpp>
12 #include <uavcan/build_config.hpp>
13 
14 namespace uavcan
15 {
24 void bitarrayCopy(const unsigned char* src_org, std::size_t src_offset, std::size_t src_len,
25  unsigned char* dst_org, std::size_t dst_offset);
26 
32 {
33  static const unsigned MaxBytesPerRW = 16;
34 
36  unsigned bit_offset_;
38 
39  static inline unsigned bitlenToBytelen(unsigned bits) { return (bits + 7) / 8; }
40 
41  static inline void copyBitArrayAlignedToUnaligned(const uint8_t* src_org, unsigned src_len,
42  uint8_t* dst_org, unsigned dst_offset)
43  {
44  bitarrayCopy(reinterpret_cast<const unsigned char*>(src_org), 0, src_len,
45  reinterpret_cast<unsigned char*>(dst_org), dst_offset);
46  }
47 
48  static inline void copyBitArrayUnalignedToAligned(const uint8_t* src_org, unsigned src_offset, unsigned src_len,
49  uint8_t* dst_org)
50  {
51  bitarrayCopy(reinterpret_cast<const unsigned char*>(src_org), src_offset, src_len,
52  reinterpret_cast<unsigned char*>(dst_org), 0);
53  }
54 
55 public:
56  static const unsigned MaxBitsPerRW = MaxBytesPerRW * 8;
57 
58  enum
59  {
60  ResultOutOfBuffer = 0,
61  ResultOk = 1
62  };
63 
64  explicit BitStream(ITransferBuffer& buf)
65  : buf_(buf)
66  , bit_offset_(0)
67  , byte_cache_(0)
68  {
69  StaticAssert<sizeof(uint8_t) == 1>::check();
70  }
71 
83  int write(const uint8_t* bytes, const unsigned bitlen);
84  int read(uint8_t* bytes, const unsigned bitlen);
85 
86 #if UAVCAN_TOSTRING
87  std::string toString() const;
88 #endif
89 };
90 
91 }
92 
93 #endif // UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED
check
ROSCPP_DECL bool check()
uavcan::BitStream
Definition: bit_stream.hpp:31
templates.hpp
std::size_t
unsigned long size_t
Definition: coverity_scan_model.cpp:19
uavcan::BitStream::byte_cache_
uint8_t byte_cache_
Definition: bit_stream.hpp:37
uavcan::ITransferBuffer
Definition: abstract_transfer_buffer.hpp:16
uavcan::bitarrayCopy
void bitarrayCopy(const unsigned char *src_org, std::size_t src_offset, std::size_t src_len, unsigned char *dst_org, std::size_t dst_offset)
Definition: uc_bit_array_copy.cpp:12
uavcan::StaticAssert
struct UAVCAN_EXPORT StaticAssert
Definition: templates.hpp:29
std.hpp
uavcan::BitStream::buf_
ITransferBuffer & buf_
Definition: bit_stream.hpp:35
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
uavcan::BitStream::BitStream
BitStream(ITransferBuffer &buf)
Definition: bit_stream.hpp:64
toString
static std::string toString(long x)
Definition: multiset.cpp:16
UAVCAN_EXPORT
#define UAVCAN_EXPORT
Definition: libuavcan/libuavcan/include/uavcan/build_config.hpp:108
uavcan::BitStream::bitlenToBytelen
static unsigned bitlenToBytelen(unsigned bits)
Definition: bit_stream.hpp:39
build_config.hpp
abstract_transfer_buffer.hpp
uavcan::BitStream::copyBitArrayUnalignedToAligned
static void copyBitArrayUnalignedToAligned(const uint8_t *src_org, unsigned src_offset, unsigned src_len, uint8_t *dst_org)
Definition: bit_stream.hpp:48
buf_
Item buf_[UAVCAN_LPC11C24_RX_QUEUE_LEN]
Definition: can.cpp:81
uavcan::BitStream::bit_offset_
unsigned bit_offset_
Definition: bit_stream.hpp:36
uavcan::BitStream::copyBitArrayAlignedToUnaligned
static void copyBitArrayAlignedToUnaligned(const uint8_t *src_org, unsigned src_len, uint8_t *dst_org, unsigned dst_offset)
Definition: bit_stream.hpp:41
uavcan
Definition: libuavcan/libuavcan/include/uavcan/build_config.hpp:204


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:02