Skip to content

Incorrect code samples #333

@KamilPogorzelski2

Description

@KamilPogorzelski2

The example code in sil-kit/docs/code-samples/eth/ETH_Sender_Receiver.cpp looks incorrect to me.

Original:

// ------------------------------------------------------------
// Send an Ethernet message
const std::array<uint8_t, 6> destinationAddress{0xf6, 0x04, 0x68, 0x71, 0xaa, 0xc2};
const std::array<uint8_t, 6> sourceAddress{0xf6, 0x04, 0x68, 0x71, 0xaa, 0xc1};
const std::array<uint8_t, 4> vlanTag{0x81, 0x00, 0x00, 0x00};  // optional
const std::array<uint8_t, 2> etherType{0x08, 0x00};
const std::array<uint8_t, 4> frameCheckSequence{0x00, 0x00, 0x00, 0x00};  // optional

const std::string message{"Ensure that the payload is at least 46 bytes to constitute "
                    "a valid Ethernet frame ------------------------------"};
const std::vector<uint8_t> payload{message.begin(), message.end()};

const std::array<uint8_t, 2> frameCheckSequence{0x00, 0x00};  // optional for 

EthernetFrame frame{};
std::copy(destinationAddress.begin(), destinationAddress.end(), std::back_inserter(frame));
std::copy(sourceAddress.begin(), sourceAddress.end(), std::back_inserter(frame));
std::copy(vlanTag.begin(), vlanTag.end(), std::back_inserter(frame));
std::copy(etherType.begin(), etherType.end(), std::back_inserter(frame));
std::copy(payload.begin(), payload.end(), std::back_inserter(frame));
std::copy(frameCheckSequence.begin(), frameCheckSequence.end(), std::back_inserter(frame));

// The returned transmitId can be used to check if the ethernetFrameTransmitEvent
// that should be triggered after a successful reception has the same transmitId.
auto transmitId = ethernetSender->SendFrame(frame);

should look more like

   // ------------------------------------------------------------
    // Send an Ethernet message
    const std::array<uint8_t, 6> destinationAddress{ 0xf6, 0x04, 0x68, 0x71, 0xaa, 0xc2 };
    const std::array<uint8_t, 6> sourceAddress{ 0xf6, 0x04, 0x68, 0x71, 0xaa, 0xc1 };
    const std::array<uint8_t, 4> vlanTag{ 0x81, 0x00, 0x00, 0x00 };  // optional
    const std::array<uint8_t, 2> etherType{ 0x08, 0x00 };
    const std::array<uint8_t, 4> frameCheckSequence{ 0x00, 0x00, 0x00, 0x00 };  // optional

    const std::string message{ "Ensure that the payload is at least 46 bytes to constitute "
                        "a valid Ethernet frame ------------------------------" };
    const std::vector<uint8_t> payload{ message.begin(), message.end() };

    std::vector<uint8_t> raw;
    std::copy(destinationAddress.begin(), destinationAddress.end(), std::back_inserter(raw));
    std::copy(sourceAddress.begin(), sourceAddress.end(), std::back_inserter(raw));
    std::copy(vlanTag.begin(), vlanTag.end(), std::back_inserter(raw));
    std::copy(etherType.begin(), etherType.end(), std::back_inserter(raw));
    std::copy(payload.begin(), payload.end(), std::back_inserter(raw));
    std::copy(frameCheckSequence.begin(), frameCheckSequence.end(), std::back_inserter(raw));

    EthernetFrame frame{ raw };

    // The returned transmitId can be used to check if the ethernetFrameTransmitEvent
    // that should be triggered after a successful reception has the same transmitId.
    auto transmitId = ethernetSender->SendFrame(frame);

Similar issue exists also in ETH_Erroneous_Transmissions.cpp and sil-kit/docs/api/services/ethernet.rst

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions