I began work on this mostly for myself and beck, given our recent work on a lot of networked applications (TI-Trek, VPM/BPM, etc), but decided to release it for others. So far, only the outbound has been tested, and only on cemu; I will be testing inbound either later today or tomorrow.
This library contains a number of functions to help with forming and sending data in a standardized packet format so that end users don't have to worry about cross-compatibility. Right now, the lib maintains compatibility with the serial hardware as well as CEmu's pipe mode.
Here's a short overview of the API:
bool pl_InitSubsystem(uint8_t subsys, uint8_t *buf, size_t buf_size, size_t ms_delay);
This initializes the given subsystem (current options are serial device or CEmu pipes). Passes the given buffer of buffer size. The provided delay in milliseconds specifies a timeout after which to return an error. If other libs like TCP/IP are provided, they can be added as subsystems here as well.
size_t pl_JoinPacketSegments(uint8_t pid, ps_t *ps, uint8_t arr_len, uint8_t *packet);
This takes a packet id, an array of given length of pointer/len pairs, and a pointer to a buffer to write the packet to. This is a helper function.
size_t pl_SendPacket(uint8_t *data, size_t len);
This sends the given packet over the initialized subsystem. Depending on the size of the buffer, the function may not actually send all of `len`. It will only ever send the lesser of the length, or 3 less than half the buffer size initialized and that number is returned, making it possible to loop calls to send a full packet in frames. Each packet is prefixed with a header consisting of a 3-byte size word.
Code:
void pl_SetReadTimeout(size_t ms_delay);
Alters the timeout for the ReadPacket function (below). By default, the timeout is 0 for a non-blocking read. By specifying a non-zero timeout value, in milliseconds, it will become a blocking read that waits that time before returning an error.
size_t pl_ReadPacket(uint8_t *dest, size_t read_size);
Attempts to read the given size from the subsystem to the given pointed buffer. Returns the size read on success, or 0 on fail. Fails if the given size is not available.
Here's the current build with sending only tested: https://github.com/acagliano/packetlib
This library contains a number of functions to help with forming and sending data in a standardized packet format so that end users don't have to worry about cross-compatibility. Right now, the lib maintains compatibility with the serial hardware as well as CEmu's pipe mode.
Here's a short overview of the API:
bool pl_InitSubsystem(uint8_t subsys, uint8_t *buf, size_t buf_size, size_t ms_delay);
This initializes the given subsystem (current options are serial device or CEmu pipes). Passes the given buffer of buffer size. The provided delay in milliseconds specifies a timeout after which to return an error. If other libs like TCP/IP are provided, they can be added as subsystems here as well.
size_t pl_JoinPacketSegments(uint8_t pid, ps_t *ps, uint8_t arr_len, uint8_t *packet);
This takes a packet id, an array of given length of pointer/len pairs, and a pointer to a buffer to write the packet to. This is a helper function.
size_t pl_SendPacket(uint8_t *data, size_t len);
This sends the given packet over the initialized subsystem. Depending on the size of the buffer, the function may not actually send all of `len`. It will only ever send the lesser of the length, or 3 less than half the buffer size initialized and that number is returned, making it possible to loop calls to send a full packet in frames. Each packet is prefixed with a header consisting of a 3-byte size word.
Code:
#example of how to loop sendpacket for a multi-frame packet
for(size_t l = 0; l < packet_len;)
l += pl_SendPacket(&addr[l], packet_len - l);
void pl_SetReadTimeout(size_t ms_delay);
Alters the timeout for the ReadPacket function (below). By default, the timeout is 0 for a non-blocking read. By specifying a non-zero timeout value, in milliseconds, it will become a blocking read that waits that time before returning an error.
size_t pl_ReadPacket(uint8_t *dest, size_t read_size);
Attempts to read the given size from the subsystem to the given pointed buffer. Returns the size read on success, or 0 on fail. Fails if the given size is not available.
Here's the current build with sending only tested: https://github.com/acagliano/packetlib