Skip to content

MacAddress

Namespace: CtrlDS4 | Inherits from: Printable

struct MacAddress : public Printable

MAC address the controller reports to the host.

Hosts use it to tell controllers apart, so each controller connected to the same host needs its own address.

It can be printed directly, as six hexadecimal bytes separated by colons:

Serial.println(controller.getMacAddress());  // Prints e.g. 02:1A:2B:3C:4D:5E

Constructors

MacAddress()

MacAddress() = default

Builds the address 00:00:00:00:00:00.

MacAddress(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)

MacAddress(uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4, uint8_t byte5)

Builds an address from its bytes, in the order they are printed.

CtrlDS4::MacAddress address(0x02, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E);  // 02:1A:2B:3C:4D:5E

To avoid using the address of a real device, set bit 1 of the first byte (locally administered address). Keep bit 0 cleared, since it marks multicast addresses, which a device can't use.

Parameters

  • byte0: First byte.
  • byte1: Second byte.
  • byte2: Third byte.
  • byte3: Fourth byte.
  • byte4: Fifth byte.
  • byte5: Last byte.

Fields

bytes

uint8_t bytes[MAC_ADDRESS_SIZE] = {}

Bytes of the address, in the order they are printed.

Methods

printTo(Print &)

size_t printTo(Print &output) const override

Prints the address as six hexadecimal bytes separated by colons.

Parameters

  • output: Where to print the address (e.g. Serial).

Returns

Number of characters printed.