NPC Arduino API

The following is the class structure for the library. This documents all the user-facing functions and members.

class NullPacketComms

Serial connection object to be handled via NPC protocol.

Public Functions

NullPacketComms()

Constructor to initialise the wrapper.

bool begin(uint32_t baud_rate)

Opens the connection to the UART port.

Parameters:

baud_rate – Standard UART baud rate to use.

Returns:

true if opened, false if unsupported baud.

void end()

Closes the connection to the UART port.

int available()

Number bytes waiting in the serial buffer.

Returns:

number of bytes.

bool readPacket(bool manual_ack = false)

Reads the next packet from the serial buffer.

Parameters:

manual_ack – (optional) Set true to respond ACK in client code.

Returns:

true if read success, false otherwise.

uint8_t writePacket(uint8_t target, uint8_t data[], uint8_t data_len)

Builds a data packet and sends it to the host system.

Parameters:
  • target – Of the system to respond to.

  • data – Payload array to populate into the packet.

  • data_len – Length of the payload array.

Returns:

Number of bytes successfully sent.

bool writeAck(uint8_t target, uint8_t ack_code)

Sends an ack packet in response to a resolved rx packet.

Parameters:
  • target – Address of system we are responding from.

  • ack_code – NACK error code or 0 for ACK.

Returns:

true if ack was sent successfully, else false.

Public Members

uint8_t target_

Stores the to address of the last rx packet.

uint8_t len_

Stores the payload length populated with the last rx packet.

uint8_t payload_[58]

Stores the payload from the last rx packet.