BeRTOS
Functions
pocketcmd.c File Reference

pocketBus protocol Command layer implementation. More...

#include "pocketcmd.h"
#include "pocketbus.h"
#include "cfg/cfg_pocketbus.h"
#include <cfg/log.h>
#include <cfg/debug.h>
#include <cfg/macros.h>
#include <cfg/module.h>
#include <drv/timer.h>
#include <cpu/byteorder.h>
#include <cpu/detect.h>
#include <string.h>

Go to the source code of this file.

Functions

void pocketcmd_poll (struct PocketCmdCtx *ctx)
 pocketBus Command poll function.
bool pocketcmd_recv (struct PocketCmdCtx *ctx, PocketCmdMsg *recv_msg)
 pocketBus Command recv function.
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.
void pocketcmd_init (struct PocketCmdCtx *ctx, struct PocketBusCtx *bus_ctx, pocketbus_addr_t addr, pocketcmd_lookup_t search)
 Init pocketBus command layer.
void pocketcmd_replyAck (struct PocketCmdMsg *msg)
 Helper function used to reply to master with an ACK.
void pocketcmd_replyNak (struct PocketCmdMsg *msg)
 Helper function used to reply to master with a NAK.

Detailed Description

pocketBus protocol Command layer implementation.

This module implements command layer over pocketBus protocol. Payload packets received by pocketBus are first checked for address matching. If a packet is addressed to us we look for a suitable callback function to call.

The received payload format is as follows:

 +----------------------------------------+
 |  CMD |            DATA                 |
 +----------------------------------------+
 |      |                                 |
 +  2B  +           0..N Byte             +
 

The CMD ID used is the same supplied by the master when the command was sent.

Author:
Francesco Sacchi <batt@develer.com>

Definition in file pocketcmd.c.


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.