Skip to content

Commit

Permalink
Merge pull request #480 from Luos-io/fix/Gate_autoUpdate
Browse files Browse the repository at this point in the history
Adapt Gate to multi auto-update feature and boost it.
  • Loading branch information
nicolas-rabault authored Mar 22, 2024
2 parents 5c39cf9 + 189c93c commit ae64e6e
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion engine/core/src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ uint16_t Service_GetIndex(service_t *service)
******************************************************************************/
void Service_AddAutoUpdateTarget(service_t *service, uint16_t target, uint16_t time_ms)
{
LUOS_ASSERT(service && (time_ms > 0) && (target != 0));
LUOS_ASSERT(service && (target != 0));
for (uint16_t i = 0; i < MAX_AUTO_REFRESH_NUMBER; i++)
{
if (service_ctx.auto_refresh[i].time_ms == 0)
Expand Down
5 changes: 5 additions & 0 deletions network/robus_network/HAL/STM32F0/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ void RobusHAL_Loop(void)
******************************************************************************/
void RobusHAL_ComInit(uint32_t Baudrate)
{
HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ);
HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ);
ROBUS_COM_CLOCK_ENABLE();

LL_USART_InitTypeDef USART_InitStruct;
Expand Down Expand Up @@ -468,6 +470,9 @@ static void RobusHAL_GPIOInit(void)
RobusHAL_RegisterPTP();
for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */
{
// Disable IT for PTP
HAL_NVIC_DisableIRQ(PTP[i].IRQ);
HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ);
GPIO_InitStruct.Pin = PTP[i].Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
Expand Down
5 changes: 5 additions & 0 deletions network/robus_network/HAL/STM32F4/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void RobusHAL_Loop(void)
******************************************************************************/
void RobusHAL_ComInit(uint32_t Baudrate)
{
HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ);
HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ);
ROBUS_COM_CLOCK_ENABLE();

LL_USART_InitTypeDef USART_InitStruct;
Expand Down Expand Up @@ -472,6 +474,9 @@ static void RobusHAL_GPIOInit(void)
RobusHAL_RegisterPTP();
for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */
{
// Disable IT for PTP
HAL_NVIC_DisableIRQ(PTP[i].IRQ);
HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ);
GPIO_InitStruct.Pin = PTP[i].Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
Expand Down
5 changes: 5 additions & 0 deletions network/robus_network/HAL/STM32G4/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void RobusHAL_Loop(void)
******************************************************************************/
void RobusHAL_ComInit(uint32_t Baudrate)
{
HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ);
HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ);
ROBUS_COM_CLOCK_ENABLE();

LL_USART_InitTypeDef USART_InitStruct;
Expand Down Expand Up @@ -469,6 +471,9 @@ static void RobusHAL_GPIOInit(void)
RobusHAL_RegisterPTP();
for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */
{
// Disable IT for PTP
HAL_NVIC_DisableIRQ(PTP[i].IRQ);
HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ);
GPIO_InitStruct.Pin = PTP[i].Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
Expand Down
5 changes: 5 additions & 0 deletions network/robus_network/HAL/STM32L0/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ void RobusHAL_Loop(void)
******************************************************************************/
void RobusHAL_ComInit(uint32_t Baudrate)
{
HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ);
HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ);
ROBUS_COM_CLOCK_ENABLE();

LL_USART_InitTypeDef USART_InitStruct;
Expand Down Expand Up @@ -467,6 +469,9 @@ static void RobusHAL_GPIOInit(void)
RobusHAL_RegisterPTP();
for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */
{
// Disable IT for PTP
HAL_NVIC_DisableIRQ(PTP[i].IRQ);
HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ);
GPIO_InitStruct.Pin = PTP[i].Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
Expand Down
5 changes: 5 additions & 0 deletions network/robus_network/HAL/STM32L4/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void RobusHAL_Loop(void)
******************************************************************************/
void RobusHAL_ComInit(uint32_t Baudrate)
{
HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ);
HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ);
ROBUS_COM_CLOCK_ENABLE();

LL_USART_InitTypeDef USART_InitStruct;
Expand Down Expand Up @@ -469,6 +471,9 @@ static void RobusHAL_GPIOInit(void)
RobusHAL_RegisterPTP();
for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */
{
// Disable IT for PTP
HAL_NVIC_DisableIRQ(PTP[i].IRQ);
HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ);
GPIO_InitStruct.Pin = PTP[i].Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
Expand Down
7 changes: 0 additions & 7 deletions test/tests_core/test_service/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,6 @@ void unittest_Service_AddAutoUpdateTarget(void)
}
TEST_ASSERT_TRUE(IS_ASSERT());
END_TRY;

TRY
{
Service_AddAutoUpdateTarget(&service_ctx.list[0], 1, 0);
}
TEST_ASSERT_TRUE(IS_ASSERT());
END_TRY;
}
NEW_TEST_CASE("Test Service_AddAutoUpdateTarget");
{
Expand Down
7 changes: 6 additions & 1 deletion tool_services/gate/TinyJSON/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,12 @@ void Convert_JsonToMsg(service_t *service, uint16_t id, luos_type_t type, char *
{
if (type != GATE_TYPE)
{
// this should be a function because it is frequently used
// 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
time = TimeOD_TimeFrom_s((float)json_getReal(jobj));
TimeOD_TimeToMsg(&time, &msg);
msg.header.cmd = UPDATE_PUB;
Expand Down
6 changes: 6 additions & 0 deletions tool_services/gate/data_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ void DataManager_collect(service_t *service)
#endif
#else
// This service is a sensor so create a msg to enable auto update
// First remove any auto update
time_luos_t reset_time = {.raw = 0};
update_msg.header.target = result.result_table[i]->id;
TimeOD_TimeToMsg(&reset_time, &update_msg);
update_msg.header.cmd = UPDATE_PUB;
Luos_SendMsg(service, &update_msg);

TimeOD_TimeToMsg(&update_time, &update_msg);
update_msg.header.cmd = UPDATE_PUB;
Luos_SendMsg(service, &update_msg);
Expand Down
8 changes: 5 additions & 3 deletions tool_services/gate/gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ void Gate_Init(void)
******************************************************************************/
void Gate_Loop(void)
{
#ifndef GATE_POLLING
static uint32_t last_time = 0;
#endif

// Check the detection status.
if (Luos_IsDetected() == false)
Expand All @@ -68,11 +70,11 @@ void Gate_Loop(void)
if (gate_running == RUNNING)
{
// Manage input and output data
DataManager_Run(gate);
#ifndef GATE_POLLING
if ((Luos_GetSystick() - last_time >= TimeOD_TimeTo_ms(update_time)) && (Luos_GetSystick() > last_time))
{
last_time = Luos_GetSystick();
DataManager_Run(gate);
#ifndef GATE_POLLING
if (first_conversion == true)
{
// This is the first time we perform a convertion
Expand All @@ -95,8 +97,8 @@ void Gate_Loop(void)
DataManager_collect(gate);
first_conversion = false;
}
#endif
}
#endif
}
else
{
Expand Down
17 changes: 12 additions & 5 deletions tool_services/pipe/SERIAL/serial_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ static inline void SerialProtocol_Init(void)
static inline void SerialProtocol_CreateTxMsg(void)
{
// Evaluate size
uint16_t size = (Streaming_GetAvailableSampleNB(serialTx_StreamChannel) - sizeof(SerialHeader_t));
// We want to evaluate the size of the last message only. To do that we create a fake StreamChannel with the same properties as the serialTx_StreamChannel but with the sample_ptr pointing to the begining of our message.
streaming_channel_t fake_StreamChannel = *serialTx_StreamChannel;
memcpy(&fake_StreamChannel, serialTx_StreamChannel, sizeof(streaming_channel_t));
fake_StreamChannel.sample_ptr = size_to_update; // We make it point to the size
uint16_t size = Streaming_GetAvailableSampleNB(&fake_StreamChannel) - 2; // We remove the size bytes from the calculated size.
// Update size
if ((size_to_update + 2) > (uint8_t *)((int)serialTx_StreamChannel->end_ring_buffer))
{
Expand All @@ -65,7 +69,6 @@ static inline void SerialProtocol_CreateTxMsg(void)
size_to_update[0] = size & 0xFF;
size_to_update[1] = size >> 8;
}

// Write footer and header + size of the next message into the buffer
SerialProtocol_t SerialProtocol = {
SERIAL_FOOTER,
Expand All @@ -91,13 +94,17 @@ static inline void SerialProtocol_CreateTxMsg(void)

static inline uint16_t SerialProtocol_GetSizeToSend(void)
{
if ((Streaming_GetAvailableSampleNB(serialTx_StreamChannel) - sizeof(SerialHeader_t)) > Streaming_GetAvailableSampleNBUntilEndBuffer(serialTx_StreamChannel))
// We want to evaluate the size of the last message only. To do that we create a fake StreamChannel with the same properties as the serialTx_StreamChannel but with the sample_ptr pointing to the begining of our message.
streaming_channel_t fake_StreamChannel = *serialTx_StreamChannel;
memcpy(&fake_StreamChannel, serialTx_StreamChannel, sizeof(streaming_channel_t));
fake_StreamChannel.data_ptr = size_to_update; // We the end of the data point to the size
if ((Streaming_GetAvailableSampleNB(&fake_StreamChannel) - 1) > Streaming_GetAvailableSampleNBUntilEndBuffer(&fake_StreamChannel))
{
return Streaming_GetAvailableSampleNBUntilEndBuffer(serialTx_StreamChannel);
return Streaming_GetAvailableSampleNBUntilEndBuffer(&fake_StreamChannel);
}
else
{
return Streaming_GetAvailableSampleNB(serialTx_StreamChannel) - sizeof(SerialHeader_t);
return Streaming_GetAvailableSampleNB(&fake_StreamChannel) - 1;
}
}

Expand Down

0 comments on commit ae64e6e

Please sign in to comment.