1818
1919#include <stdio.h>
2020#include <stdbool.h>
21+ #include <string.h>
22+ #include "RTE_Components.h"
2123#include "cmsis_os2.h"
2224#include "cmsis_vio.h"
2325#include "sds_main.h"
2426#include "sds_control.h"
2527#include "sds_rec_play.h"
28+ #ifdef RTE_SDS_IO_SOCKET
29+ #include "sdsio_config_socket.h"
30+ #endif
2631
2732
2833// AlgorithmThread thread attributes
@@ -53,25 +58,35 @@ static void rec_play_event_callback (sdsRecPlayId_t id, uint32_t event) {
5358}
5459
5560#ifdef SIMULATOR
61+ static uint32_t key_cnt = 0U ;
62+
5663// Simulate keypress
5764static uint32_t simGetSignal (uint32_t mask ) {
58- static uint32_t key_cnt = 0U ;
59- uint32_t ret = 0U ;
65+ uint32_t ret = 0U ;
6066
6167 switch (key_cnt ) {
68+ #ifdef SDS_PLAY
6269 case 20U : // At 2 seconds
6370 ret = mask ; // Simulate keypress
6471 break ;
65- #ifndef SDS_PLAY
66- case 120U : // At 12 seconds
72+
73+ case 1000U : // At 100 seconds
74+ putchar (0x04 ); // Send signal to simulator to shutdown
75+ break ;
76+ #else
77+ case 10U : // At 1 second
6778 ret = mask ; // Simulate keypress
6879 break ;
69- #endif
70- case 150U : // At 15 seconds
80+
81+ case 110U : // At 11 seconds
82+ ret = mask ; // Simulate keypress
83+ break ;
84+
85+ case 120U : // At 12 seconds
7186 putchar (0x04 ); // Send signal to simulator to shutdown
7287 break ;
88+ #endif
7389 }
74-
7590 key_cnt ++ ;
7691
7792 return ret ;
@@ -88,16 +103,68 @@ __NO_RETURN void sdsControlThread (void *argument) {
88103 uint8_t led0_val = 0U ;
89104 uint32_t no_load_cnt , prev_cnt ;
90105 uint32_t interval_time , cnt = 0U ;
106+ int32_t ret ;
91107
92108 // Initialize idle counter
93109 idle_cnt = 0U ;
94110 osDelay (10U );
95111 no_load_cnt = idle_cnt ;
96112
97113 // Initialize SDS recorder/player
98- if (sdsRecPlayInit (rec_play_event_callback ) != SDS_REC_PLAY_OK ) {
99- printf ("SDS initialization failed!\n" );
100- printf ("For Network and USB SDSIO Interfaces ensure that SDSIO Server is running and restart the application!\n" );
114+ ret = sdsRecPlayInit (rec_play_event_callback );
115+
116+ // Output a diagnostic message about initialization to the STDOUT channel
117+ switch (ret ) {
118+ case SDS_REC_PLAY_OK :
119+ #if defined(RTE_SDS_IO_VSI )
120+ printf ("SDS I/O VSI interface initialized successfully\n" );
121+ #elif defined(RTE_SDS_IO_SOCKET )
122+ printf ("Connection to SDSIO-Server at %s:%d established\n" , SDSIO_SOCKET_SERVER_IP , SDSIO_SOCKET_SERVER_PORT );
123+ #elif defined(RTE_SDS_IO_USB )
124+ printf ("Connection to SDSIO-Server established via USB interface\n" );
125+ #elif defined(RTE_SDS_IO_SERIAL_CMSIS_USART )
126+ printf ("Connection to SDSIO-Server established via USART interface\n" );
127+ #elif defined(RTE_SDS_IO_CUSTOM )
128+ printf ("Connection to SDSIO-Server established via custom interface\n" );
129+ #elif defined(RTE_SDS_IO_FILE_SYSTEM_MDK_FS )
130+ printf ("SDS I/O File System (MDK-FS) interface initialized successfully\n" );
131+ #elif defined(RTE_SDS_IO_FILE_SYSTEM_SEMIHOSTING )
132+ printf ("SDS I/O File System (SemiHosting) interface initialized successfully\n" );
133+ #endif
134+ break ;
135+
136+ case SDS_REC_PLAY_ERROR_IO :
137+ #if defined(RTE_SDS_IO_VSI )
138+ printf ("SDS I/O VSI interface initialization failed!\n" );
139+ #elif defined(RTE_SDS_IO_SOCKET )
140+ if (strcmp (SDSIO_SOCKET_SERVER_IP , "0.0.0.0" ) == 0 ) {
141+ printf ("SDSIO_SOCKET_SERVER_IP address not configured (see sdsio_config_socket.h)!\n" );
142+ } else {
143+ 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 );
144+ printf ("Ensure that SDSIO-Server is running, then restart the application!\n" );
145+ }
146+ #elif defined(RTE_SDS_IO_USB )
147+ printf ("SDS I/O USB interface initialization failed or 'sdsio-server usb' unavailable!\n" );
148+ printf ("Ensure that SDSIO-Server is running, then restart the application!\n" );
149+ #elif defined(RTE_SDS_IO_SERIAL_CMSIS_USART )
150+ printf ("SDS I/O USART interface initialization failed or 'sdsio-server serial' unavailable!\n" );
151+ printf ("Ensure that SDSIO-Server is running, then restart the application!\n" );
152+ #elif defined(RTE_SDS_IO_CUSTOM )
153+ printf ("SDS I/O Custom interface initialization failed!\n" );
154+ #elif defined(RTE_SDS_IO_FILE_SYSTEM_MDK_FS )
155+ printf ("SDS I/O File System MDK-FS interface initialization failed!\n" );
156+ #elif defined(RTE_SDS_IO_FILE_SYSTEM_SEMIHOSTING )
157+ printf ("SDS I/O File System SemiHosting interface initialization failed!\n" );
158+ #endif
159+ break ;
160+
161+ case SDS_REC_PLAY_ERROR :
162+ printf ("SDS initialization failed to create necessary threads or event flags!\n" );
163+ break ;
164+
165+ default :
166+ printf ("SDS initialization failed with error code: %d\n" , ret );
167+ break ;
101168 }
102169
103170 // Create algorithm thread
@@ -144,6 +211,19 @@ __NO_RETURN void sdsControlThread (void *argument) {
144211 vioSetSignal (vioLED1 , vioLEDoff );
145212 sdsStreamingState = SDS_STREAMING_INACTIVE ;
146213 }
214+ #ifdef SDS_PLAY
215+ #ifdef SIMULATOR
216+ // Start next SDS stream
217+ key_cnt = 0U ;
218+ #endif
219+ #endif
220+ break ;
221+
222+ case SDS_STREAMING_END :
223+ #ifdef SIMULATOR
224+ // Send signal to simulator to shutdown
225+ putchar (0x04 );
226+ #endif
147227 break ;
148228 }
149229
0 commit comments