Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix size management of the result table during filtering #482

Closed
10 changes: 5 additions & 5 deletions engine/core/src/routing_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ search_result_t *RTFilter_ID(search_result_t *result, uint16_t id)
if (result->result_table[entry_nbr]->id != id)
{
// if we find an other id, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down Expand Up @@ -1006,7 +1006,7 @@ search_result_t *RTFilter_Type(search_result_t *result, luos_type_t type)
if (result->result_table[entry_nbr]->type != type)
{
// if we find an other type, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down Expand Up @@ -1042,7 +1042,7 @@ search_result_t *RTFilter_Node(search_result_t *result, uint16_t node_id)
if (RoutingTB_NodeIDFromID(result->result_table[entry_nbr]->id) != node_id)
{
// if we find an other node_id, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down Expand Up @@ -1078,7 +1078,7 @@ search_result_t *RTFilter_Alias(search_result_t *result, char *alias)
if (strstr(result->result_table[entry_nbr]->alias, alias) == 0)
{
// if we find an other node_id, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down Expand Up @@ -1114,7 +1114,7 @@ search_result_t *RTFilter_Service(search_result_t *result, service_t *service)
if (result->result_table[entry_nbr]->id != service->id)
{
// if we find an other id, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down
8 changes: 8 additions & 0 deletions engine/core/src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ void Service_AddAutoUpdateTarget(service_t *service, uint16_t target, uint16_t t
LUOS_ASSERT(service && (target != 0));
for (uint16_t i = 0; i < MAX_AUTO_REFRESH_NUMBER; i++)
{
// If this target ask something from this service just update the value
if ((service_ctx.auto_refresh[i].service == service) && (service_ctx.auto_refresh[i].target == target))
{
service_ctx.auto_refresh[i].time_ms = time_ms;
service_ctx.auto_refresh[i].last_update = LuosHAL_GetSystick();
return;
}
// If this slot is empty this mean that we didn't find the target in the list, just add it.
if (service_ctx.auto_refresh[i].time_ms == 0)
{
service_ctx.auto_refresh[i].service = service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void Convert_CustomJsonToMsg(service_t *service, uint16_t target_id, char *prope
// This function is called by the gate to convert a message into a piece of Json.
// This is typically used when a message is received by the gate with an unknown command.
// You can use it to compose your own piece of Json out of the message data.
void Convert_CustomMsgToJson(msg_t *msg, char *data)
void Convert_CustomMsgToJson(const msg_t *msg, char *data)
{
if (msg->header.cmd == LINEAR_POSITION_2D)
{
Expand Down
2 changes: 1 addition & 1 deletion tool_services/gate/TinyJSON/bootloader_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uint16_t Bootloader_StartData(char *data)
* @param service pointer, luos message
* @return None
******************************************************************************/
uint16_t Bootloader_LuosToJson(msg_t *msg, char *data)
uint16_t Bootloader_LuosToJson(const msg_t *msg, char *data)
{
uint16_t response_cmd = msg->header.cmd;
uint16_t node_id = RoutingTB_NodeIDFromID(msg->header.source);
Expand Down
2 changes: 1 addition & 1 deletion tool_services/gate/TinyJSON/bootloader_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/*******************************************************************************
* Function
******************************************************************************/
uint16_t Bootloader_LuosToJson(msg_t *, char *);
uint16_t Bootloader_LuosToJson(const msg_t *, char *);
void Bootloader_JsonToLuos(service_t *, char *, json_t const *);
uint16_t Bootloader_StartData(char *);
void Bootloader_EndData(service_t *, char *, char *);
Expand Down
23 changes: 6 additions & 17 deletions tool_services/gate/TinyJSON/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ __attribute__((weak)) void Convert_CustomJsonToMsg(service_t *service, uint16_t
* @param None
* @return None
******************************************************************************/
__attribute__((weak)) void Convert_CustomMsgToJson(msg_t *msg, char *data)
__attribute__((weak)) void Convert_CustomMsgToJson(const msg_t *msg, char *data)
{
return;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ void Convert_DataToMsg(service_t *service, char *data)
return;
}

json_t const *services = json_getProperty(root, "services");
json_t const *services = json_getProperty(root, "s");
// Get services
if (services != 0)
{
Expand Down Expand Up @@ -543,12 +543,7 @@ void Convert_JsonToMsg(service_t *service, uint16_t id, luos_type_t type, char *
{
if (type != GATE_TYPE)
{
// remove any current updates
time = TimeOD_TimeFrom_s(0);
TimeOD_TimeToMsg(&time, &msg);
msg.header.cmd = UPDATE_PUB;
Luos_SendMsg(service, &msg);
// configure the new update value
// Configure the new update value
time = TimeOD_TimeFrom_s((float)json_getReal(jobj));
TimeOD_TimeToMsg(&time, &msg);
msg.header.cmd = UPDATE_PUB;
Expand Down Expand Up @@ -736,8 +731,8 @@ void Convert_JsonToMsg(service_t *service, uint16_t id, luos_type_t type, char *
// This function start a Json structure and return the string size.
uint16_t Convert_StartData(char *data)
{
memcpy(data, "{\"services\":{", sizeof("{\"services\":{"));
return (sizeof("{\"services\":{") - 1);
memcpy(data, "{\"s\":{", sizeof("{\"s\":{"));
return (sizeof("{\"s\":{") - 1);
}
// This function start a Service into a Json structure and return the string size.
uint16_t Convert_StartServiceData(char *data, char *alias)
Expand All @@ -746,7 +741,7 @@ uint16_t Convert_StartServiceData(char *data, char *alias)
return (uint16_t)strlen(data);
}
// This function create the Json content from a message and return the string size.
uint16_t Convert_MsgToData(msg_t *msg, char *data)
uint16_t Convert_MsgToData(const msg_t *msg, char *data)
{
float fdata;
switch (msg->header.cmd)
Expand Down Expand Up @@ -1086,12 +1081,6 @@ void Convert_RoutingTableData(service_t *service)
*(--json_ptr) = '\0';
// End the Json message
sprintf(json_ptr, "]}\n");
// Run loop before to flush residual msg on the pipe
Luos_Loop();
// reset all the msg in pipe link
PipeLink_Reset(service);
// call Luos loop to generap a Luos Task with this msg
Luos_Loop();
// Send the message to pipe
PipeLink_Send(service, json, strlen(json));
}
Expand Down
2 changes: 1 addition & 1 deletion tool_services/gate/TinyJSON/custom-json.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
#include "luos_engine.h"

void Convert_CustomJsonToMsg(service_t *service, uint16_t target_id, char *property, const json_t *jobj, char *json_str);
void Convert_CustomMsgToJson(msg_t *msg, char *data);
void Convert_CustomMsgToJson(const msg_t *msg, char *data);
const char *Convert_CustomStringFromType(luos_type_t type);
2 changes: 1 addition & 1 deletion tool_services/gate/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void Convert_DataToMsg(service_t *service, char *data);
// Luos service information to Data convertion
uint16_t Convert_StartData(char *data);
uint16_t Convert_StartServiceData(char *data, char *alias);
uint16_t Convert_MsgToData(msg_t *msg, char *data);
uint16_t Convert_MsgToData(const msg_t *msg, char *data);
uint16_t Convert_EndServiceData(char *data);
void Convert_EndData(service_t *service, char *data, char *data_ptr);
void Convert_VoidData(service_t *service);
Expand Down
Loading
Loading