cleaning and added prototypes for bulk ops

master
Ondřej Hruška 7 years ago
parent 92eab30c77
commit a40e32d322
  1. 1
      gex/gex_client.c
  2. 12
      gex/gex_defines.h
  3. 10
      gex/gex_unit.c
  4. 55
      gex/gex_unit.h

@ -50,7 +50,6 @@ static TF_Result unit_report_lst(TinyFrame *tf, TF_Msg *msg)
};
GexMsg gexMsg = {
.session = msg->frame_id,
.payload = (uint8_t *) (msg->data + 2),
.len = (uint32_t) (msg->len - 2),
.type = rpt_type,

@ -28,14 +28,10 @@ typedef void (*GexEventListener)(GexMsg msg);
* Contains all needed information to lead a multi-part dialogue.
*/
struct gex_msg {
GexUnit *unit;
uint8_t *payload;
uint32_t len;
GexSession session;
union {
uint8_t cmd;
uint8_t type;
};
GexUnit *unit; //!< Unit this message belongs to
uint8_t *payload; //!< Useful payload
uint32_t len; //!< Payload length
uint8_t type; //!< Message type (e.g. MSG_ERROR), or report type in event handler
};
/**

@ -20,7 +20,7 @@
* @param lst - TF listener to handle the response, can be NULL
* @param userdata2 userdata2 argument for the TF listener's message
*/
static void GEX_LL_Query(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t len, TF_Listener lst, void *userdata2)
static void GEX_LL_Query(GexUnit *unit, uint8_t cmd, const uint8_t *payload, uint32_t len, TF_Listener lst, void *userdata2)
{
assert(unit != NULL);
assert(unit->gex != NULL);
@ -51,7 +51,7 @@ static void GEX_LL_Query(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t
}
/** Send with no listener, don't wait for response */
void GEX_Send(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t len)
void GEX_Send(GexUnit *unit, uint8_t cmd, const uint8_t *payload, uint32_t len)
{
assert(unit != NULL);
assert(unit->gex != NULL);
@ -67,7 +67,6 @@ static TF_Result sync_query_lst(TinyFrame *tf, TF_Msg *msg)
// clone the message
gex->sync_query_response.len = msg->len;
gex->sync_query_response.session = msg->frame_id;
gex->sync_query_response.unit = msg->userdata;
gex->sync_query_response.type = msg->type;
// clone the buffer
@ -78,7 +77,7 @@ static TF_Result sync_query_lst(TinyFrame *tf, TF_Msg *msg)
}
/** Static query */
GexMsg GEX_Query(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t len)
GexMsg GEX_Query(GexUnit *unit, uint8_t cmd, const uint8_t *payload, uint32_t len)
{
assert(unit != NULL);
assert(unit->gex != NULL);
@ -89,7 +88,6 @@ GexMsg GEX_Query(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t len)
// Default response that will be used if nothing is received
gex->sync_query_response.unit = unit;
gex->sync_query_response.session = 0;
gex->sync_query_response.type = MSG_ERROR;
sprintf((char *) gex->sync_query_buffer, "TIMEOUT");
gex->sync_query_response.len = (uint32_t) strlen("TIMEOUT");
@ -125,7 +123,7 @@ static TF_Result async_query_lst(TinyFrame *tf, TF_Msg *msg)
}
/** Sync query, without poll */
void GEX_QueryAsync(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t len, GexEventListener lst)
void GEX_QueryAsync(GexUnit *unit, uint8_t cmd, const uint8_t *payload, uint32_t len, GexEventListener lst)
{
assert(unit != NULL);
assert(unit->gex != NULL);

@ -13,14 +13,51 @@
#include <stdint.h>
#include <stdbool.h>
/** Send with no listener, don't wait for response */
void GEX_Send(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t len);
/** Static query */
GexMsg GEX_Query(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t len);
/** Sync query, without poll */
void GEX_QueryAsync(GexUnit *unit, uint8_t cmd, uint8_t *payload, uint32_t len, GexEventListener lst);
/** Send a command with no listener */
void GEX_Send(GexUnit *unit, uint8_t cmd, const uint8_t *payload, uint32_t len);
/** Send a command with no payload or listener */
static inline void GEX_Send0(GexUnit *unit, uint8_t cmd)
{
GEX_Send(unit, cmd, NULL, 0);
}
/** Static query, send a command and wait for the response */
GexMsg GEX_Query(GexUnit *unit, uint8_t cmd, const uint8_t *payload, uint32_t len);
/** Asynchronous query with an async listener */
void GEX_QueryAsync(GexUnit *unit, uint8_t cmd, const uint8_t *payload, uint32_t len, GexEventListener lst);
/**
* Bulk read from a unit, synchronous
*
* @param unit - the unit to target
* @param cmd - initial request command
* @param payload - initial request payload
* @param len - initial request payload length
* @param buffer - destination buffer
* @param capacity - size of the buffer, max nr of bytes to receive
* @return actual number of bytes received.
*/
uint32_t GEX_BulkRead(GexUnit *unit, uint8_t cmd,
const uint8_t *payload, uint32_t len,
uint8_t *buffer, uint32_t capacity);
/**
* Bulk write to a unit, synchronous
*
* @param unit - the unit to target
* @param cmd - initial request command
* @param payload - initial request payload
* @param len - initial request payload length
* @param buffer - destination buffer
* @param capacity - size of the buffer, max nr of bytes to receive
* @return true on success
*/
bool GEX_BulkWrite(GexUnit *unit, uint8_t cmd,
const uint8_t *payload, uint32_t len,
const uint8_t *buffer, uint32_t capacity);
#endif //GEX_CLIENT_GEX_UNIT_H

Loading…
Cancel
Save