mirror of
https://github.com/djhackersdev/bemanitools.git
synced 2024-09-24 02:48:21 +02:00
refactor(p3io/cmd): Add and improve p3io command helper functions
With the overhaul of commands, some helpers needed tweaks while new ones were added to abstract p3io command details with a common interface, e.g. dealing with the command length field.
This commit is contained in:
parent
5ef190f0af
commit
c5bba84940
@ -4,25 +4,49 @@
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
uint8_t p3io_req_cmd(const union p3io_req_any *src)
|
||||
uint8_t p3io_get_full_req_size(const union p3io_req_any *req)
|
||||
{
|
||||
log_assert(src != NULL);
|
||||
/* Length byte in this packet format counts everything from the length
|
||||
byte onwards. The length byte itself occurs at the start of the frame. */
|
||||
|
||||
/* In requests, the command byte is the first byte after the header. */
|
||||
|
||||
return src->raw[sizeof(struct p3io_hdr)];
|
||||
return req->hdr.nbytes + 1;
|
||||
}
|
||||
|
||||
void p3io_resp_init(
|
||||
struct p3io_hdr *dest, size_t nbytes, const struct p3io_hdr *req)
|
||||
uint8_t p3io_get_full_resp_size(const union p3io_resp_any *resp)
|
||||
{
|
||||
log_assert(dest != NULL);
|
||||
log_assert(req != NULL);
|
||||
log_assert(nbytes < 0x100);
|
||||
/* Length byte in this packet format counts everything from the length
|
||||
byte onwards. The length byte itself occurs at the start of the frame. */
|
||||
|
||||
return resp->hdr.nbytes + 1;
|
||||
}
|
||||
|
||||
void p3io_req_hdr_init(
|
||||
struct p3io_hdr *req_hdr, uint8_t seq_no, uint8_t cmd, size_t size)
|
||||
{
|
||||
log_assert(req_hdr != NULL);
|
||||
log_assert(size < P3IO_MAX_MESSAGE_SIZE);
|
||||
|
||||
memset(req_hdr, 0, sizeof(struct p3io_hdr));
|
||||
|
||||
/* Length byte in this packet format counts everything from the length
|
||||
byte onwards. The length byte itself occurs at the start of the frame. */
|
||||
|
||||
dest->nbytes = nbytes - 1;
|
||||
dest->seq_no = req->seq_no;
|
||||
req_hdr->nbytes = size - 1;
|
||||
req_hdr->seq_no = seq_no;
|
||||
req_hdr->cmd = cmd;
|
||||
}
|
||||
|
||||
void p3io_resp_hdr_init(
|
||||
struct p3io_hdr *resp_hdr, size_t nbytes, const struct p3io_hdr *req_hdr)
|
||||
{
|
||||
log_assert(resp_hdr != NULL);
|
||||
log_assert(req_hdr != NULL);
|
||||
log_assert(nbytes < P3IO_MAX_MESSAGE_SIZE);
|
||||
|
||||
/* Length byte in this packet format counts everything from the length
|
||||
byte onwards. The length byte itself occurs at the start of the frame. */
|
||||
|
||||
resp_hdr->nbytes = nbytes - 1;
|
||||
resp_hdr->seq_no = req_hdr->seq_no;
|
||||
resp_hdr->cmd = req_hdr->cmd;
|
||||
}
|
||||
|
@ -293,9 +293,14 @@ union p3io_resp_any {
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
uint8_t p3io_req_cmd(const union p3io_req_any *src);
|
||||
uint8_t p3io_get_full_req_size(const union p3io_req_any *req);
|
||||
|
||||
void p3io_resp_init(
|
||||
struct p3io_hdr *dest, size_t nbytes, const struct p3io_hdr *req);
|
||||
uint8_t p3io_get_full_resp_size(const union p3io_resp_any *resp);
|
||||
|
||||
void p3io_req_hdr_init(
|
||||
struct p3io_hdr *hdr, uint8_t seq_no, uint8_t cmd, size_t size);
|
||||
|
||||
void p3io_resp_hdr_init(
|
||||
struct p3io_hdr *resp_hdr, size_t nbytes, const struct p3io_hdr *req_hdr);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user