Add TryReceive
This commit is contained in:
+12
-1
@@ -230,9 +230,20 @@ HalStatus MMR_CAN_Send(CanHandle *hcan, MmrCanPacket packet);
|
|||||||
*/
|
*/
|
||||||
HalStatus MMR_CAN_SendNoTamper(CanHandle *hcan, MmrCanPacket packet);
|
HalStatus MMR_CAN_SendNoTamper(CanHandle *hcan, MmrCanPacket packet);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* Receives a can message from the network.
|
* Tries to receive a message.
|
||||||
|
*/
|
||||||
|
MmrResult MMR_CAN_TryReceive(CanHandle *hcan, MmrCanMessage *result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Reads a CAN message and stores it inside the
|
||||||
|
* given MmrCanMessage struct.
|
||||||
|
*
|
||||||
|
* If a multi-frame message is received, this function will block
|
||||||
|
* and read every frame for that particular message.
|
||||||
*/
|
*/
|
||||||
HalStatus MMR_CAN_Receive(CanHandle *hcan, MmrCanMessage *result);
|
HalStatus MMR_CAN_Receive(CanHandle *hcan, MmrCanMessage *result);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
* MMR_CAN_MESSAGE_ID_POINT might be interpreted as
|
* MMR_CAN_MESSAGE_ID_POINT might be interpreted as
|
||||||
* a message carrying a struct Point { int x; int y; };,
|
* a message carrying a struct Point { int x; int y; };,
|
||||||
* and thus deserialized accordingly.
|
* and thus deserialized accordingly.
|
||||||
|
*
|
||||||
|
* You can find a table with more in-depth explanations on
|
||||||
|
* Google Drive:
|
||||||
|
* https://docs.google.com/spreadsheets/d/1GIC0_FuhCjXfBOg_dUWzoEsl5TG7SEOR
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef INC_MMR_CAN_MESSAGE_ID_H_
|
#ifndef INC_MMR_CAN_MESSAGE_ID_H_
|
||||||
@@ -22,8 +26,8 @@
|
|||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* Message ids are 10 bits wide
|
* Message ids are 10 bits wide
|
||||||
* The first 3 bits determine the message id type, while
|
* The first 5 bits determine the message id type, while
|
||||||
* the other 7 determine the subtype.
|
* the other 5 determine the subtype.
|
||||||
*
|
*
|
||||||
* Ids scheme:
|
* Ids scheme:
|
||||||
*
|
*
|
||||||
|
|||||||
+5
-5
@@ -73,11 +73,11 @@
|
|||||||
*
|
*
|
||||||
* Asynchronous logic can be easily implemented using State Machines
|
* Asynchronous logic can be easily implemented using State Machines
|
||||||
*/
|
*/
|
||||||
typedef enum MmrAsyncResult {
|
typedef enum MmrResult {
|
||||||
MMR_ASYNC_RESULT_ERROR,
|
MMR_RESULT_ERROR,
|
||||||
MMR_ASYNC_RESULT_PENDING,
|
MMR_RESULT_PENDING,
|
||||||
MMR_ASYNC_RESULT_COMPLETED,
|
MMR_RESULT_COMPLETED,
|
||||||
} MmrAsyncResult;
|
} MmrResult;
|
||||||
|
|
||||||
|
|
||||||
#endif /* INC_MMR_CAN_UTIL_H_ */
|
#endif /* INC_MMR_CAN_UTIL_H_ */
|
||||||
|
|||||||
+14
-8
@@ -20,14 +20,20 @@ static HalStatus receiveAll(ReceptionParams *rp);
|
|||||||
static bool headerIsMultiFrame(MmrCanHeader header, CanId targetId);
|
static bool headerIsMultiFrame(MmrCanHeader header, CanId targetId);
|
||||||
|
|
||||||
|
|
||||||
/**
|
MmrResult MMR_CAN_TryReceive(CanHandle *hcan, MmrCanMessage *result) {
|
||||||
* @brief
|
size_t pendingMessages =
|
||||||
* Reads a CAN message and stores it inside the
|
HAL_CAN_GetRxFifoFillLevel(hcan, MMR_CAN_RX_FIFO);
|
||||||
* given MmrCanMessage struct.
|
|
||||||
*
|
if (pendingMessages > 0) {
|
||||||
* If a multi-frame message is received, this function will block
|
return MMR_CAN_Receive(hcan, result) != HAL_OK
|
||||||
* and read every frame for that particular message.
|
? MMR_RESULT_COMPLETED
|
||||||
*/
|
: MMR_RESULT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MMR_RESULT_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HalStatus MMR_CAN_Receive(CanHandle *hcan, MmrCanMessage *result) {
|
HalStatus MMR_CAN_Receive(CanHandle *hcan, MmrCanMessage *result) {
|
||||||
ReceptionParams rp = {
|
ReceptionParams rp = {
|
||||||
.handle = hcan,
|
.handle = hcan,
|
||||||
|
|||||||
Reference in New Issue
Block a user