Skip to content

Commit

Permalink
Merge pull request #486 from Luos-io/fix/Gate_autoUpdate
Browse files Browse the repository at this point in the history
Make the Gate event based.
  • Loading branch information
nicolas-rabault authored May 14, 2024
2 parents 445f737 + eb9ade5 commit 6e08137
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 312 deletions.
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

0 comments on commit 6e08137

Please sign in to comment.