Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 90 additions & 10 deletions template/algorithm/sds_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "RTE_Components.h"
#include "cmsis_os2.h"
#include "cmsis_vio.h"
#include "sds_main.h"
#include "sds_control.h"
#include "sds_rec_play.h"
#ifdef RTE_SDS_IO_SOCKET
#include "sdsio_config_socket.h"
#endif


// AlgorithmThread thread attributes
Expand Down Expand Up @@ -53,25 +58,35 @@ static void rec_play_event_callback (sdsRecPlayId_t id, uint32_t event) {
}

#ifdef SIMULATOR
static uint32_t key_cnt = 0U;

// Simulate keypress
static uint32_t simGetSignal (uint32_t mask) {
static uint32_t key_cnt = 0U;
uint32_t ret = 0U;
uint32_t ret = 0U;

switch (key_cnt) {
#ifdef SDS_PLAY
case 20U: // At 2 seconds
ret = mask; // Simulate keypress
break;
#ifndef SDS_PLAY
case 120U: // At 12 seconds

case 1000U: // At 100 seconds
putchar(0x04); // Send signal to simulator to shutdown
break;
#else
case 10U: // At 1 second
ret = mask; // Simulate keypress
break;
#endif
case 150U: // At 15 seconds

case 110U: // At 11 seconds
ret = mask; // Simulate keypress
break;

case 120U: // At 12 seconds
putchar(0x04); // Send signal to simulator to shutdown
break;
#endif
}

key_cnt++;

return ret;
Expand All @@ -88,16 +103,68 @@ __NO_RETURN void sdsControlThread (void *argument) {
uint8_t led0_val = 0U;
uint32_t no_load_cnt, prev_cnt;
uint32_t interval_time, cnt = 0U;
int32_t ret;

// Initialize idle counter
idle_cnt = 0U;
osDelay(10U);
no_load_cnt = idle_cnt;

// Initialize SDS recorder/player
if (sdsRecPlayInit(rec_play_event_callback) != SDS_REC_PLAY_OK) {
printf("SDS initialization failed!\n");
printf("For Network and USB SDSIO Interfaces ensure that SDSIO Server is running and restart the application!\n");
ret = sdsRecPlayInit(rec_play_event_callback);

// Output a diagnostic message about initialization to the STDOUT channel
switch (ret) {
case SDS_REC_PLAY_OK:
#if defined(RTE_SDS_IO_VSI)
printf("SDS I/O VSI interface initialized successfully\n");
#elif defined(RTE_SDS_IO_SOCKET)
printf("Connection to SDSIO-Server at %s:%d established\n", SDSIO_SOCKET_SERVER_IP, SDSIO_SOCKET_SERVER_PORT);
#elif defined(RTE_SDS_IO_USB)
printf("Connection to SDSIO-Server established via USB interface\n");
#elif defined(RTE_SDS_IO_SERIAL_CMSIS_USART)
printf("Connection to SDSIO-Server established via USART interface\n");
#elif defined(RTE_SDS_IO_CUSTOM)
printf("Connection to SDSIO-Server established via custom interface\n");
#elif defined(RTE_SDS_IO_FILE_SYSTEM_MDK_FS)
printf("SDS I/O File System (MDK-FS) interface initialized successfully\n");
#elif defined(RTE_SDS_IO_FILE_SYSTEM_SEMIHOSTING)
printf("SDS I/O File System (SemiHosting) interface initialized successfully\n");
#endif
break;

case SDS_REC_PLAY_ERROR_IO:
#if defined(RTE_SDS_IO_VSI)
printf("SDS I/O VSI interface initialization failed!\n");
#elif defined(RTE_SDS_IO_SOCKET)
if (strcmp(SDSIO_SOCKET_SERVER_IP, "0.0.0.0") == 0) {
printf("SDSIO_SOCKET_SERVER_IP address not configured (see sdsio_config_socket.h)!\n");
} else {
printf("SDS I/O Network interface initialization failed or 'sdsio-server socket' unavailable at %s:%d !\n", SDSIO_SOCKET_SERVER_IP, SDSIO_SOCKET_SERVER_PORT);
printf("Ensure that SDSIO-Server is running, then restart the application!\n");
}
#elif defined(RTE_SDS_IO_USB)
printf("SDS I/O USB interface initialization failed or 'sdsio-server usb' unavailable!\n");
printf("Ensure that SDSIO-Server is running, then restart the application!\n");
#elif defined(RTE_SDS_IO_SERIAL_CMSIS_USART)
printf("SDS I/O USART interface initialization failed or 'sdsio-server serial' unavailable!\n");
printf("Ensure that SDSIO-Server is running, then restart the application!\n");
#elif defined(RTE_SDS_IO_CUSTOM)
printf("SDS I/O Custom interface initialization failed!\n");
#elif defined(RTE_SDS_IO_FILE_SYSTEM_MDK_FS)
printf("SDS I/O File System MDK-FS interface initialization failed!\n");
#elif defined(RTE_SDS_IO_FILE_SYSTEM_SEMIHOSTING)
printf("SDS I/O File System SemiHosting interface initialization failed!\n");
#endif
break;

case SDS_REC_PLAY_ERROR:
printf("SDS initialization failed to create necessary threads or event flags!\n");
break;

default:
printf("SDS initialization failed with error code: %d\n", ret);
break;
}

// Create algorithm thread
Expand Down Expand Up @@ -144,6 +211,19 @@ __NO_RETURN void sdsControlThread (void *argument) {
vioSetSignal(vioLED1, vioLEDoff);
sdsStreamingState = SDS_STREAMING_INACTIVE;
}
#ifdef SDS_PLAY
#ifdef SIMULATOR
// Start next SDS stream
key_cnt = 0U;
#endif
#endif
break;

case SDS_STREAMING_END:
#ifdef SIMULATOR
// Send signal to simulator to shutdown
putchar(0x04);
#endif
break;
}

Expand Down
1 change: 1 addition & 0 deletions template/algorithm/sds_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C"
#define SDS_STREAMING_ACTIVE 1 // Streaming is active, SDS streams are open and ready for read/write operations
#define SDS_STREAMING_STOP 2 // Request to stop streaming and close the open streams
#define SDS_STREAMING_STOP_SAFE 3 // Safe state for streaming to be stopped
#define SDS_STREAMING_END 4 // Request to end streaming (no more data)

// Assert macro
#define SDS_ASSERT(cond) \
Expand Down
55 changes: 35 additions & 20 deletions template/algorithm/sds_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <stdio.h>
#include "RTE_Components.h"
#include "cmsis_os2.h"
#include "sds_main.h"
#include "sds_control.h"
Expand Down Expand Up @@ -50,6 +51,8 @@ static sdsRecPlayId_t recIdDataInput = NULL;
#endif
static sdsRecPlayId_t recIdDataOutput = NULL;

// SDS file sequence number
static uint32_t sequence_num = 0;

// Public functions

Expand All @@ -67,7 +70,8 @@ int32_t OpenStreams (void) {
playIdDataInput = sdsPlayOpen("DataInput", sds_play_buf_data_in, sizeof(sds_play_buf_data_in));
SDS_ASSERT(playIdDataInput != NULL);
if (playIdDataInput == NULL) {
printf("Failed to open SDS stream for playback of input data!\n");
sdsStreamingState = SDS_STREAMING_END; // end simulation
printf("No more SDS data files for playback of input data!\n");
status = -1;
}
#else
Expand All @@ -80,27 +84,37 @@ int32_t OpenStreams (void) {
}
#endif

// Open stream for recording of output data
recIdDataOutput = sdsRecOpen("DataOutput", sds_rec_buf_data_out, sizeof(sds_rec_buf_data_out));
SDS_ASSERT(recIdDataOutput != NULL);
if (recIdDataOutput == NULL) {
printf("Failed to open SDS stream for recording of output data!\n");
status = -1;
if (status == 0) {
// Open stream for recording of output data
recIdDataOutput = sdsRecOpen("DataOutput", sds_rec_buf_data_out, sizeof(sds_rec_buf_data_out));
SDS_ASSERT(recIdDataOutput != NULL);
if (recIdDataOutput == NULL) {
printf("ERROR: Failed to open SDS stream for recording of output data!\n");
status = -1;
}
}

#ifdef SDS_PLAY
if (status == 0) {
printf("SDS playback and recording started\n");
printf("SDS playback and recording (#%d) started\n", sequence_num);
} else {
printf("SDS playback and recording start failed!\n");
printf("For Network and USB SDSIO Interfaces ensure that SDSIO Server is running and restart the application!\n");
if (sequence_num == 0) {
printf("ERROR: SDS playback and recording start failed!\n");
#if defined(RTE_SDS_IO_SOCKET) || defined(RTE_SDS_IO_USB) || defined(RTE_SDS_IO_SERIAL) || defined(RTE_SDS_IO_CUSTOM)
printf("Ensure that SDSIO Server is running and restart the application!\n");
#endif
}
}
#else
if (status == 0) {
printf("SDS recording started\n");
printf("SDS recording (#%d) started\n", sequence_num);
} else {
printf("SDS recording start failed!\n");
printf("For Network and USB SDSIO Interfaces ensure that SDSIO Server is running and restart the application!\n");
if (sequence_num == 0) {
printf("ERROR: SDS recording start failed!\n");
#if defined(RTE_SDS_IO_SOCKET) || defined(RTE_SDS_IO_USB) || defined(RTE_SDS_IO_SERIAL) || defined(RTE_SDS_IO_CUSTOM)
printf("Ensure that SDSIO Server is running and restart the application!\n");
#endif
}
}
#endif

Expand All @@ -120,15 +134,15 @@ int32_t CloseStreams (void) {
status = sdsPlayClose(playIdDataInput);
SDS_ASSERT(status == SDS_REC_PLAY_OK);
if (status != 0) {
printf("Failed to close SDS stream for playback of input data!\n");
printf("ERROR: Failed to close SDS stream for playback of input data!\n");
status = -1;
}
#else
// Close stream for recording of input data
status = sdsRecClose(recIdDataInput);
SDS_ASSERT(status == SDS_REC_PLAY_OK);
if (status != 0) {
printf("Failed to close SDS stream for recording of input data!\n");
printf("ERROR: Failed to close SDS stream for recording of input data!\n");
status = -1;
}
#endif
Expand All @@ -137,23 +151,24 @@ int32_t CloseStreams (void) {
status = sdsRecClose(recIdDataOutput);
SDS_ASSERT(status == SDS_REC_PLAY_OK);
if (status != 0) {
printf("Failed to close SDS stream for recording of output data!\n");
printf("ERROR: Failed to close SDS stream for recording of output data!\n");
status = -1;
}

#ifdef SDS_PLAY
if (status == 0) {
printf("SDS playback and recording stopped\n");
printf("SDS playback and recording (#%d) stopped\n====\n\n", sequence_num);
} else {
printf("SDS playback and recording stop failed!\n");
printf("ERROR: SDS playback and recording stop failed!\n====\n\n");
}
#else
if (status == 0) {
printf("SDS recording stopped\n");
printf("SDS recording (#%d) stopped\n====\n\n", sequence_num);
} else {
printf("SDS recording stop failed!\n");
printf("ERROR: SDS recording stop failed!\n====\n\n");
}
#endif
sequence_num++;

return status;
}
Expand Down
Loading
Loading