Skip to content

Commit

Permalink
Fix: add a function to sized luos_sendstreaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Salem-Tho committed Jan 12, 2022
1 parent 3e48187 commit 27a4cb4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions inc/luos.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ error_return_t Luos_ReadFromService(service_t *service, int16_t id, msg_t **retu
void Luos_SendData(service_t *service, msg_t *msg, void *bin_data, uint16_t size);
error_return_t Luos_ReceiveData(service_t *service, msg_t *msg, void *bin_data);
void Luos_SendStreaming(service_t *service, msg_t *msg, streaming_channel_t *stream);
void Luos_SendStreamingSize(service_t *service, msg_t *msg, streaming_channel_t *stream, uint32_t max_size);
error_return_t Luos_ReceiveStreaming(service_t *service, msg_t *msg, streaming_channel_t *stream);
void Luos_SendBaudrate(service_t *service, uint32_t baudrate);
void Luos_SetExternId(service_t *service, target_mode_t target_mode, uint16_t target, uint16_t newid);
Expand Down
59 changes: 59 additions & 0 deletions src/luos.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,65 @@ void Luos_SendStreaming(service_t *service, msg_t *msg, streaming_channel_t *str
}
}
}
/******************************************************************************
* @brief Send a number of datas of a streaming channel
* @param Service who send
* @param Message to send
* @param streaming channel pointer
* @param max_size maximum sample to send
* @return None
******************************************************************************/
void Luos_SendStreamingSize(service_t *service, msg_t *msg, streaming_channel_t *stream, uint32_t max_size)
{
// Compute number of message needed to send available datas on ring buffer
int msg_number = 1;
int data_size = Stream_GetAvailableSampleNB(stream);
if (data_size > max_size)
{
data_size = max_size;
}
const int max_data_msg_size = (MAX_DATA_MSG_SIZE / stream->data_size);
if (data_size > max_data_msg_size)
{
msg_number = (data_size / max_data_msg_size);
msg_number += ((msg_number * max_data_msg_size) < data_size);
}

// Send messages one by one
for (volatile uint16_t chunk = 0; chunk < msg_number; chunk++)
{
// compute chunk size
uint16_t chunk_size = 0;
if (data_size > max_data_msg_size)
{
chunk_size = max_data_msg_size;
}
else
{
chunk_size = data_size;
}

// Copy data into message
Stream_GetSample(stream, msg->data, chunk_size);
msg->header.size = data_size;

// Send message
while (Luos_SendMsg(service, msg) == FAILED)
{
Luos_Loop();
}

// check end of data
if (data_size > max_data_msg_size)
{
data_size -= max_data_msg_size;
}
else
{
data_size = 0;
}
}
}
/******************************************************************************
* @brief Receive a streaming channel datas
* @param Service who send
Expand Down

0 comments on commit 27a4cb4

Please sign in to comment.