mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-04 13:10:34 +08:00
Minor source reorganization; few dangerous C functions replaced with safer std:: alternatives
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
namespace uavcan
|
||||
@@ -31,7 +31,7 @@ struct CanFrame
|
||||
: id(0)
|
||||
, dlc(0)
|
||||
{
|
||||
std::memset(data, 0, sizeof(data));
|
||||
std::fill(data, data + sizeof(data), 0);
|
||||
}
|
||||
|
||||
CanFrame(uint32_t id, const uint8_t* data, unsigned int dlc)
|
||||
@@ -39,13 +39,13 @@ struct CanFrame
|
||||
, dlc(dlc)
|
||||
{
|
||||
assert(data && dlc <= 8);
|
||||
std::memmove(this->data, data, dlc);
|
||||
std::copy(data, data + dlc, this->data);
|
||||
}
|
||||
|
||||
bool operator!=(const CanFrame& rhs) const { return !operator==(rhs); }
|
||||
bool operator==(const CanFrame& rhs) const
|
||||
{
|
||||
return (id == rhs.id) && (dlc == rhs.dlc) && (memcmp(data, rhs.data, dlc) == 0);
|
||||
return (id == rhs.id) && (dlc == rhs.dlc) && std::equal(data, data + dlc, rhs.data);
|
||||
}
|
||||
|
||||
bool isExtended() const { return id & FLAG_EFF; }
|
||||
|
||||
-1
@@ -6,7 +6,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <stdint.h>
|
||||
#include <uavcan/internal/linked_list.hpp>
|
||||
#include <uavcan/internal/dynamic_memory.hpp>
|
||||
@@ -18,6 +18,8 @@ namespace uavcan
|
||||
class ISystemClock
|
||||
{
|
||||
public:
|
||||
virtual ~ISystemClock() { }
|
||||
|
||||
/**
|
||||
* Monototic system clock in microseconds.
|
||||
* This shall never jump during UTC timestamp adjustments; the base time is irrelevant.
|
||||
|
||||
@@ -20,7 +20,7 @@ std::string CanFrame::toString(StringRepresentation mode) const
|
||||
|
||||
char buf[50];
|
||||
char* wpos = buf, *epos = buf + sizeof(buf);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
std::fill(buf, buf + sizeof(buf), 0);
|
||||
|
||||
if (id & FLAG_EFF)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <uavcan/internal/can_io.hpp>
|
||||
#include <uavcan/internal/transport/can_io.hpp>
|
||||
#include <uavcan/internal/debug.hpp>
|
||||
|
||||
namespace uavcan
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "common.hpp"
|
||||
#include <uavcan/can_driver.hpp>
|
||||
|
||||
TEST(CanFrame, FrameProperties)
|
||||
{
|
||||
@@ -1,10 +1,12 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
* Copyright (C) 2014 <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <uavcan/internal/can_io.hpp>
|
||||
#include <cassert>
|
||||
#include <uavcan/can_driver.hpp>
|
||||
#include <uavcan/system_clock.hpp>
|
||||
|
||||
class SystemClockMock : public uavcan::ISystemClock
|
||||
{
|
||||
@@ -47,32 +49,3 @@ static uavcan::CanFrame makeFrame(uint32_t id, const std::string& str_data, Fram
|
||||
id |= (type == EXT) ? uavcan::CanFrame::FLAG_EFF : 0;
|
||||
return uavcan::CanFrame(id, reinterpret_cast<const uint8_t*>(str_data.c_str()), str_data.length());
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
int getQueueLength(uavcan::CanTxQueue& queue)
|
||||
{
|
||||
const uavcan::CanTxQueue::Entry* p = queue.peek();
|
||||
int length = 0;
|
||||
while (p)
|
||||
{
|
||||
length++;
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
bool isInQueue(uavcan::CanTxQueue& queue, const uavcan::CanFrame& frame)
|
||||
{
|
||||
const uavcan::CanTxQueue::Entry* p = queue.peek();
|
||||
while (p)
|
||||
{
|
||||
if (frame == p->frame)
|
||||
return true;
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,9 @@
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <gtest/gtest.h>
|
||||
#include "common.hpp"
|
||||
#include <uavcan/internal/transport/can_io.hpp>
|
||||
#include "../../common.hpp"
|
||||
|
||||
|
||||
class CanIfaceMock : public uavcan::ICanIface
|
||||
{
|
||||
@@ -3,7 +3,33 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "common.hpp"
|
||||
#include <uavcan/internal/transport/can_io.hpp>
|
||||
#include "../../common.hpp"
|
||||
|
||||
|
||||
static int getQueueLength(uavcan::CanTxQueue& queue)
|
||||
{
|
||||
const uavcan::CanTxQueue::Entry* p = queue.peek();
|
||||
int length = 0;
|
||||
while (p)
|
||||
{
|
||||
length++;
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
static bool isInQueue(uavcan::CanTxQueue& queue, const uavcan::CanFrame& frame)
|
||||
{
|
||||
const uavcan::CanTxQueue::Entry* p = queue.peek();
|
||||
while (p)
|
||||
{
|
||||
if (frame == p->frame)
|
||||
return true;
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST(CanTxQueue, Qos)
|
||||
{
|
||||
Reference in New Issue
Block a user