コード例 #1
0
static bool match(const uavcan::IncomingTransfer& it, const uavcan::RxFrame& frame,
                  const uint8_t* payload, unsigned payload_len)
{
    // Fields extracted from the frame struct
    EXPECT_EQ(it.getMonotonicTimestamp(), frame.getMonotonicTimestamp());
    EXPECT_EQ(it.getUtcTimestamp(),       frame.getUtcTimestamp());
    EXPECT_EQ(it.getSrcNodeID(),          frame.getSrcNodeID());
    EXPECT_EQ(it.getTransferID(),         frame.getTransferID());
    EXPECT_EQ(it.getTransferType(),       frame.getTransferType());

    // Payload comparison
    static const unsigned BUFLEN = 1024;
    uint8_t buf_reference[BUFLEN], buf_actual[BUFLEN];

    if (payload_len > BUFLEN)
    {
        std::cout << "match(): Payload is too long" << std::endl;
        exit(1);
    }

    std::fill(buf_reference, buf_reference + BUFLEN, 0);
    std::fill(buf_actual, buf_actual + BUFLEN, 0);
    std::copy(payload, payload + payload_len, buf_reference);

    EXPECT_EQ(payload_len, it.read(0, buf_actual, payload_len * 3));
    EXPECT_EQ(0, it.read(payload_len, buf_actual, payload_len * 3));

    return std::equal(buf_reference, buf_reference + BUFLEN, buf_actual);
}
コード例 #2
0
ファイル: can.hpp プロジェクト: BillTian/uavcan
 void pushRx(const uavcan::RxFrame& frame)
 {
     uavcan::CanFrame can_frame;
     EXPECT_TRUE(frame.compile(can_frame));
     rx.push(FrameWithTime(can_frame, frame.getMonotonicTimestamp(), frame.getUtcTimestamp()));
 }