diff --git a/gex/gex_client.c b/gex/gex_client.c index c4c9fba..8649d64 100644 --- a/gex/gex_client.c +++ b/gex/gex_client.c @@ -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, diff --git a/gex/gex_defines.h b/gex/gex_defines.h index d544713..1491de4 100644 --- a/gex/gex_defines.h +++ b/gex/gex_defines.h @@ -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 }; /** diff --git a/gex/gex_unit.c b/gex/gex_unit.c index adf8b8c..f23f814 100644 --- a/gex/gex_unit.c +++ b/gex/gex_unit.c @@ -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); diff --git a/gex/gex_unit.h b/gex/gex_unit.h index 073fccc..ca2ef2f 100644 --- a/gex/gex_unit.h +++ b/gex/gex_unit.h @@ -13,14 +13,51 @@ #include #include -/** 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