Skip to content

Commit

Permalink
[Polling] Mechanism to search and pull only messages of specific topic
Browse files Browse the repository at this point in the history
…fix #250
  • Loading branch information
BiliouriV committed Aug 1, 2022
1 parent a7ec2b0 commit 92c623c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions engine/core/inc/luos_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ void Luos_SetExternId(service_t *service, target_mode_t target_mode, uint16_t ta
// *** Receive
error_return_t Luos_ReadMsg(service_t *service, msg_t **returned_msg);
error_return_t Luos_ReadFromService(service_t *service, int16_t id, msg_t **returned_msg);
error_return_t Luos_ReadTopicMsg(service_t *service, int16_t topic_id, msg_t **returned_msg);
int Luos_ReceiveData(service_t *service, msg_t *msg, void *bin_data);
error_return_t Luos_ReceiveStreaming(service_t *service, msg_t *msg, streaming_channel_t *stream);
uint16_t Luos_NbrAvailableMsg(void);
uint8_t Luos_FindTopicMsg(service_t *service, uint16_t topic_id);
uint32_t Luos_GetSystick(void);
error_return_t Luos_TxComplete(void);
void Luos_Flush(void);
Expand Down
38 changes: 38 additions & 0 deletions engine/core/src/luos_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,28 @@ error_return_t Luos_ReadFromService(service_t *service, short id, msg_t **return
}
return FAILED;
}
/******************************************************************************
* @brief read msg of specific topic and pass it to user if exists
* @param service who receive the message we are looking for
* @param topic_id of message we are searching
* @param returned_msg message of the service
* @return FAILED if no message available
******************************************************************************/
error_return_t Luos_ReadTopicMsg(service_t *service, int16_t topic_id, msg_t **returned_msg)
{
uint16_t luos_task_id = 0;
// see if we have a msg topic for this service
if (MsgAlloc_SearchLuosTaskTopic(service->ll_service, &luos_task_id, topic_id) == SUCCEED)
{
// if yes pull it and stock it in returned_msg
MsgAlloc_PullMsgFromLuosTask(luos_task_id, returned_msg);
// remove it from the message buffer
MsgAlloc_ClearMsgFromLuosTasks(*returned_msg);

return SUCCEED;
}
return FAILED;
}
/******************************************************************************
* @brief Send large among of data and formating to send into multiple msg
* @param Service who send
Expand Down Expand Up @@ -1033,6 +1055,22 @@ uint16_t Luos_NbrAvailableMsg(void)
{
return MsgAlloc_LuosTasksNbr();
}
/******************************************************************************
* @brief check if message of a specific topic is available
* @param service pointer
* @param topic_id
* @return true or false
******************************************************************************/
uint8_t Luos_FindTopicMsg(service_t *service, uint16_t topic_id)
{
uint16_t luos_task_id = 0;
// search in msg alloc if we have a msg_task of a topic for this service
if (MsgAlloc_SearchLuosTaskTopic(service->ll_service, &luos_task_id, topic_id) == SUCCEED)
{
return true;
}
return false;
}
/******************************************************************************
* @brief Get tick number
* @param None
Expand Down
1 change: 1 addition & 0 deletions network/robus/inc/msg_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void MsgAlloc_LuosTaskAlloc(ll_service_t *service_concerned_by_current_msg, msg_
error_return_t MsgAlloc_PullMsg(ll_service_t *target_service, msg_t **returned_msg);
error_return_t MsgAlloc_PullMsgFromLuosTask(uint16_t luos_task_id, msg_t **returned_msg);
error_return_t MsgAlloc_LookAtLuosTask(uint16_t luos_task_id, ll_service_t **allocated_service);
error_return_t MsgAlloc_SearchLuosTaskTopic(ll_service_t *ll_service, uint16_t *luos_task_id, uint16_t topic_id);
error_return_t MsgAlloc_GetLuosTaskSourceId(uint16_t luos_task_id, uint16_t *source_id);
error_return_t MsgAlloc_GetLuosTaskCmd(uint16_t luos_task_id, uint8_t *cmd);
error_return_t MsgAlloc_GetLuosTaskSize(uint16_t luos_task_id, uint16_t *size);
Expand Down
22 changes: 22 additions & 0 deletions network/robus/src/msg_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,28 @@ error_return_t MsgAlloc_LookAtLuosTask(uint16_t luos_task_id, ll_service_t **all
//
return FAILED;
}

/******************************************************************************
* @brief Find a luos task of a specific topic
* @param luos_task_id : Pointer to Id of the allocator slot
* @param topic_id : the topic we search
* @return error_return_t : Fail is there is no more message available.
******************************************************************************/
error_return_t MsgAlloc_SearchLuosTaskTopic(ll_service_t *ll_service, uint16_t *luos_task_id, uint16_t topic_id)
{
// search all luos_tasks
for (uint16_t i = 0; i < luos_tasks_stack_id; i++)
{
// check msg topic, and if it is for service
if ((luos_tasks[i].msg_pt->header.target_mode == TOPIC) && (luos_tasks[i].msg_pt->header.target == topic_id) && (luos_tasks[i].ll_service_pt == ll_service))
{
// keep the index of this message in luos_tasks
*luos_task_id = i;
return SUCCEED;
}
}
return FAILED;
}
/******************************************************************************
* @brief get back a specific slot message command
* @param luos_task_id : Id of the allocator slot
Expand Down

0 comments on commit 92c623c

Please sign in to comment.