pocketcmd.h File Reference
PocketBus command abstraction layer. More...
#include "pocketbus.h"#include <cfg/compiler.h>Go to the source code of this file.
Data Structures | |
| struct | PocketCmdHdr |
| Header for transmitted pocketBus Commands. More... | |
| struct | PocketCmdMsg |
| pocketBus command message structure. More... | |
| struct | PocketCmdCtx |
| pocketBus context for command layer communications. More... | |
Defines | |
| #define | PKTCMD_NULL 0 |
| pocketBus Null command | |
Typedefs | |
| typedef uint16_t | pocketcmd_t |
| Type for Command IDs. | |
| typedef void(* | pocketcmd_hook_t )(struct PocketCmdMsg *cmd_msg) |
| Type for command hooks. | |
| typedef pocketcmd_hook_t(* | pocketcmd_lookup_t )(pocketcmd_t cmd) |
| Type for lookup function hooks. | |
Functions | |
| void | pocketcmd_setAddr (struct PocketCmdCtx *ctx, pocketbus_addr_t addr) |
| Set slave address addr for pocketBus command layer. | |
| void | pocketcmd_init (struct PocketCmdCtx *ctx, struct PocketBusCtx *bus_ctx, pocketbus_addr_t addr, pocketcmd_lookup_t search) |
| Init pocketBus command layer. | |
| void | pocketcmd_poll (struct PocketCmdCtx *ctx) |
| pocketBus Command poll function. | |
| bool | pocketcmd_send (struct PocketCmdCtx *ctx, pocketcmd_t cmd, const void *buf, size_t len, bool has_replay) |
| Send command cmd to/from slave adding len arguments in buf. | |
| bool | pocketcmd_recv (struct PocketCmdCtx *ctx, PocketCmdMsg *recv_msg) |
| pocketBus Command recv function. | |
| void | pocketcmd_replyNak (struct PocketCmdMsg *msg) |
| Helper function used to reply to master with a NAK. | |
| void | pocketcmd_replyAck (struct PocketCmdMsg *msg) |
| Helper function used to reply to master with an ACK. | |
| bool | pocketcmd_masterSend (struct PocketCmdCtx *ctx, pocketbus_addr_t addr, pocketcmd_t cmd, const void *buf, size_t len) |
| Helper function used by master to send a command to slave addr. | |
| bool | pocketcmd_slaveReply (struct PocketCmdCtx *ctx, pocketcmd_t cmd, const void *buf, size_t len) |
| Helper function used by slave to reply to a master command. | |
| bool | pocketcmd_checkNak (struct PocketCmdMsg *msg) |
| Return true if message contain NAK. | |
| STATIC_ASSERT (sizeof(pocketcmd_t)==sizeof(uint16_t)) | |
| This ensure that endianess convertion functions work on the right data size. | |
Detailed Description
PocketBus command abstraction layer.
Definition in file pocketcmd.h.
Function Documentation
| void pocketcmd_init | ( | struct PocketCmdCtx * | ctx, | |
| struct PocketBusCtx * | bus_ctx, | |||
| pocketbus_addr_t | addr, | |||
| pocketcmd_lookup_t | search | |||
| ) |
Init pocketBus command layer.
ctx is pocketBus command layer context. bus_ctx is pocketBus context. addr is slave address (see pocketcmd_setAddr for details.) search is the lookup function used to search command ID callbacks.
Definition at line 197 of file pocketcmd.c.
| void pocketcmd_poll | ( | struct PocketCmdCtx * | ctx | ) |
pocketBus Command poll function.
Call it to read and process pocketBus commands.
Definition at line 80 of file pocketcmd.c.
| bool pocketcmd_recv | ( | struct PocketCmdCtx * | ctx, | |
| PocketCmdMsg * | recv_msg | |||
| ) |
pocketBus Command recv function.
Call it to read and process pocketBus commands.
Definition at line 100 of file pocketcmd.c.
| bool pocketcmd_send | ( | struct PocketCmdCtx * | ctx, | |
| pocketcmd_t | cmd, | |||
| const void * | buf, | |||
| size_t | len, | |||
| bool | wait_reply | |||
| ) |
Send command cmd to/from slave adding len arguments in buf.
Address used is contained in ctx->addr . If we are master and the message has a reply, you must set wait_reply to true.
- Returns:
- true if all is ok, false if we are already waiting a replay from another slave.
Definition at line 154 of file pocketcmd.c.
| void pocketcmd_setAddr | ( | struct PocketCmdCtx * | ctx, | |
| pocketbus_addr_t | addr | |||
| ) | [inline] |
Set slave address addr for pocketBus command layer.
If we are a slave this is *our* address. If we are the master this is the slave address to send messages to.
Definition at line 107 of file pocketcmd.h.
