Style fixes

This commit is contained in:
Pavel Kirienko
2014-03-24 23:17:05 +04:00
parent 42b80da0dd
commit 41a145424b
4 changed files with 58 additions and 55 deletions
@@ -14,7 +14,7 @@ namespace uavcan
class ITransferBuffer;
void bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, unsigned char *dst_org, int dst_offset);
void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, unsigned char* dst_org, int dst_offset);
class BitStream
{
@@ -27,10 +27,10 @@ class BitStream
static inline unsigned int bitlenToBytelen(unsigned int bits) { return (bits + 7) / 8; }
static inline void copyBitArray(const uint8_t* src_org, int src_offset, int src_len,
uint8_t* dst_org, int dst_offset)
uint8_t* dst_org, int dst_offset)
{
bitarray_copy(reinterpret_cast<const unsigned char*>(src_org), src_offset, src_len,
reinterpret_cast<unsigned char*>(dst_org), dst_offset);
bitarrayCopy(reinterpret_cast<const unsigned char*>(src_org), src_offset, src_len,
reinterpret_cast<unsigned char*>(dst_org), dst_offset);
}
public:
+44 -42
View File
@@ -22,22 +22,17 @@
namespace uavcan
{
void
bitarray_copy(const unsigned char *src_org, int src_offset, int src_len,
unsigned char *dst_org, int dst_offset)
void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, unsigned char* dst_org, int dst_offset)
{
using namespace std;
static const unsigned char reverse_mask[] = { 0x55, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
static const unsigned char reverse_mask_xor[] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00 };
static const unsigned char reverse_mask[] =
{ 0x55, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
static const unsigned char reverse_mask_xor[] =
{ 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00 };
if (src_len > 0) {
const unsigned char *src;
unsigned char *dst;
int src_offset_modulo,
dst_offset_modulo;
if (src_len > 0)
{
const unsigned char* src;
unsigned char* dst;
int src_offset_modulo;
int dst_offset_modulo;
src = src_org + (src_offset / CHAR_BIT);
dst = dst_org + (dst_offset / CHAR_BIT);
@@ -45,14 +40,13 @@ bitarray_copy(const unsigned char *src_org, int src_offset, int src_len,
src_offset_modulo = src_offset % CHAR_BIT;
dst_offset_modulo = dst_offset % CHAR_BIT;
if (src_offset_modulo == dst_offset_modulo) {
int byte_len;
int src_len_modulo;
if (src_offset_modulo) {
unsigned char c;
c = reverse_mask_xor[dst_offset_modulo] & *src++;
if (src_offset_modulo == dst_offset_modulo)
{
int byte_len;
int src_len_modulo;
if (src_offset_modulo)
{
unsigned char c = reverse_mask_xor[dst_offset_modulo] & *src++;
PREPARE_FIRST_COPY();
*dst++ |= c;
}
@@ -60,37 +54,43 @@ bitarray_copy(const unsigned char *src_org, int src_offset, int src_len,
byte_len = src_len / CHAR_BIT;
src_len_modulo = src_len % CHAR_BIT;
if (byte_len) {
memcpy(dst, src, byte_len);
if (byte_len)
{
std::memcpy(dst, src, byte_len);
src += byte_len;
dst += byte_len;
}
if (src_len_modulo) {
*dst &= reverse_mask_xor[src_len_modulo];
*dst |= reverse_mask[src_len_modulo] & *src;
if (src_len_modulo)
{
*dst &= reverse_mask_xor[src_len_modulo];
*dst |= reverse_mask[src_len_modulo] & *src;
}
} else {
int bit_diff_ls,
bit_diff_rs;
int byte_len;
int src_len_modulo;
unsigned char c;
}
else
{
int bit_diff_ls;
int bit_diff_rs;
int byte_len;
int src_len_modulo;
unsigned char c;
/*
* Begin: Line things up on destination.
*/
if (src_offset_modulo > dst_offset_modulo) {
if (src_offset_modulo > dst_offset_modulo)
{
bit_diff_ls = src_offset_modulo - dst_offset_modulo;
bit_diff_rs = CHAR_BIT - bit_diff_ls;
c = *src++ << bit_diff_ls;
c |= *src >> bit_diff_rs;
c &= reverse_mask_xor[dst_offset_modulo];
} else {
c &= reverse_mask_xor[dst_offset_modulo];
}
else
{
bit_diff_rs = dst_offset_modulo - src_offset_modulo;
bit_diff_ls = CHAR_BIT - bit_diff_rs;
c = *src >> bit_diff_rs &
reverse_mask_xor[dst_offset_modulo];
c = *src >> bit_diff_rs & reverse_mask_xor[dst_offset_modulo];
}
PREPARE_FIRST_COPY();
*dst++ |= c;
@@ -100,7 +100,8 @@ bitarray_copy(const unsigned char *src_org, int src_offset, int src_len,
*/
byte_len = src_len / CHAR_BIT;
while (--byte_len >= 0) {
while (--byte_len >= 0)
{
c = *src++ << bit_diff_ls;
c |= *src >> bit_diff_rs;
*dst++ = c;
@@ -110,12 +111,13 @@ bitarray_copy(const unsigned char *src_org, int src_offset, int src_len,
* End: copy the remaing bits;
*/
src_len_modulo = src_len % CHAR_BIT;
if (src_len_modulo) {
if (src_len_modulo)
{
c = *src++ << bit_diff_ls;
c |= *src >> bit_diff_rs;
c &= reverse_mask[src_len_modulo];
c &= reverse_mask[src_len_modulo];
*dst &= reverse_mask_xor[src_len_modulo];
*dst &= reverse_mask_xor[src_len_modulo];
*dst |= c;
}
}
+4 -3
View File
@@ -42,7 +42,7 @@ void DynamicTransferBufferManagerEntry::Block::destroy(Block*& obj, IAllocator&
}
void DynamicTransferBufferManagerEntry::Block::read(uint8_t*& outptr, unsigned int target_offset,
unsigned int& total_offset, unsigned int& left_to_read)
unsigned int& total_offset, unsigned int& left_to_read)
{
assert(outptr);
for (int i = 0; (i < Block::Size) && (left_to_read > 0); i++, total_offset++)
@@ -56,7 +56,7 @@ void DynamicTransferBufferManagerEntry::Block::read(uint8_t*& outptr, unsigned i
}
void DynamicTransferBufferManagerEntry::Block::write(const uint8_t*& inptr, unsigned int target_offset,
unsigned int& total_offset, unsigned int& left_to_write)
unsigned int& total_offset, unsigned int& left_to_write)
{
assert(inptr);
for (int i = 0; (i < Block::Size) && (left_to_write > 0); i++, total_offset++)
@@ -72,7 +72,8 @@ void DynamicTransferBufferManagerEntry::Block::write(const uint8_t*& inptr, unsi
/*
* DynamicTransferBuffer
*/
DynamicTransferBufferManagerEntry* DynamicTransferBufferManagerEntry::instantiate(IAllocator& allocator, unsigned int max_size)
DynamicTransferBufferManagerEntry* DynamicTransferBufferManagerEntry::instantiate(IAllocator& allocator,
unsigned int max_size)
{
void* const praw = allocator.allocate(sizeof(DynamicTransferBufferManagerEntry));
if (praw == NULL)
@@ -87,10 +87,10 @@ bool TransferReceiver::writePayload(const RxFrame& frame, ITransferBuffer& buf)
const uint8_t* const payload = frame.getPayloadPtr();
const int payload_len = frame.getPayloadLen();
if (frame.isFirst()) // First frame contains CRC, we need to extract it now
if (frame.isFirst()) // First frame contains CRC, we need to extract it now
{
if (frame.getPayloadLen() < TransferCRC::NumBytes) // Must have been validated earlier though. I think I'm paranoid.
return false;
if (frame.getPayloadLen() < TransferCRC::NumBytes)
return false; // Must have been validated earlier though. I think I'm paranoid.
this_transfer_crc_ = (payload[0] & 0xFF) | (uint16_t(payload[1] & 0xFF) << 8); // Little endian.
@@ -191,9 +191,9 @@ TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame, Tr
if (need_restart)
{
UAVCAN_TRACE("TransferReceiver",
"Restart [not_inited=%i, iface_timeout=%i, recv_timeout=%i, same_iface=%i, first_frame=%i, tid_rel=%i], %s",
int(not_initialized), int(iface_timed_out), int(receiver_timed_out), int(same_iface), int(first_fame),
int(tid_rel), frame.toString().c_str());
"Restart [not_inited=%i, iface_timeout=%i, recv_timeout=%i, same_iface=%i, first_frame=%i, tid_rel=%i], %s",
int(not_initialized), int(iface_timed_out), int(receiver_timed_out), int(same_iface),
int(first_fame), int(tid_rel), frame.toString().c_str());
tba.remove();
iface_index_ = frame.getIfaceIndex();
tid_ = frame.getTransferID();