1#ifndef _DCC_DCC_TEST_UTILS_HXX_
2#define _DCC_DCC_TEST_UTILS_HXX_
7void PrintTo(
const DCCPacket &pkt, ::std::ostream *os)
14void PrintTo(
const Packet &pkt, ::std::ostream *os)
25std::vector<uint8_t> dcc_from(uint8_t d0, uint8_t d1,
int d2 = -1,
int d3 = -1,
int d4 = -1)
27 std::vector<uint8_t> ret;
36 ret.push_back(d0 ^ d1);
44 ret.push_back(d0 ^ d1 ^ ret[2]);
52 ret.push_back(d0 ^ d1 ^ ret[2] ^ ret[3]);
57dcc::Packet packet_from(uint8_t hdr, std::vector<uint8_t> payload)
60 pkt.header_raw_data = hdr;
61 pkt.
dlc = payload.size();
66MATCHER_P2(PacketIs, hdr, payload, PrintToString(packet_from(hdr, payload)))
71 vector<uint8_t> act_bytes(arg.payload, arg.payload + arg.dlc);
73 arg.packet_header.is_pkt == 0 && arg.packet_header.is_marklin == 0 &&
74 pkt.packet_header.
skip_ec != arg.packet_header.skip_ec)
79 if (pkt.packet_header.
skip_ec == 0)
82 for (uint8_t b : exp_bytes)
86 exp_bytes.push_back(ec);
89 if (arg.packet_header.skip_ec == 0)
92 for (uint8_t b : act_bytes)
96 act_bytes.push_back(ec);
99 return (pkt.header_raw_data == argc.header_raw_data &&
100 exp_bytes == act_bytes);
102 return (pkt.header_raw_data == arg.header_raw_data && pkt.
dlc == arg.dlc &&
103 memcmp(pkt.
payload, arg.payload, pkt.
dlc) == 0);
string packet_to_string(const DCCPacket &pkt, bool bin_payload)
Renders a DCC packet as a debug string.
uint8_t skip_ec
typically for DCC packets: 1: do NOT append an EC byte to the end of the packet.
uint8_t is_marklin
0: DCC packet, 1: motorola packet.
Stores a DCC packet in memory.
uint8_t payload[DCC_PACKET_MAX_PAYLOAD]
Packet payload bytes.
uint8_t dlc
Specifies the number of used payload bytes.
Represents a command to be sent to the track driver.