Ejemplo n.º 1
0
    void handleIncomingTransfer(uavcan::IncomingTransfer& transfer)
    {
        const Transfer rx(transfer, Base::getDataTypeDescriptor());
        transfers_.push(rx);
        std::cout << "Received transfer: " << rx.toString() << std::endl;

        const bool single_frame = dynamic_cast<uavcan::SingleFrameIncomingTransfer*>(&transfer) != NULL;

        const bool anonymous = single_frame &&
                               transfer.getSrcNodeID().isBroadcast() &&
                               (transfer.getTransferType() == uavcan::TransferTypeMessageBroadcast);

        ASSERT_EQ(anonymous, transfer.isAnonymousTransfer());
    }
Ejemplo n.º 2
0
 Transfer(const uavcan::IncomingTransfer& tr, const uavcan::DataTypeDescriptor& data_type)
     : ts_monotonic(tr.getMonotonicTimestamp())
     , ts_utc(tr.getUtcTimestamp())
     , priority(tr.getPriority())
     , transfer_type(tr.getTransferType())
     , transfer_id(tr.getTransferID())
     , src_node_id(tr.getSrcNodeID())
     , dst_node_id() // default is invalid
     , data_type(data_type)
 {
     unsigned offset = 0;
     while (true)
     {
         uint8_t buf[256];
         int res = tr.read(offset, buf, sizeof(buf));
         if (res < 0)
         {
             std::cout << "IncomingTransferContainer: read failure " << res << std::endl;
             exit(1);
         }
         if (res == 0)
         {
             break;
         }
         payload += std::string(reinterpret_cast<const char*>(buf), unsigned(res));
         offset += unsigned(res);
     }
 }
Ejemplo n.º 3
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);
}