37 #include "safec_lib.h"
39 #define MIN(a,b) (((a)<(b))?(a):(b))
42 #define DEFAULT_REMOTE_ID 12
43 #define DEFAULT_PCM_FILENAME "voice-cmd.raw"
45 static unsigned char remoteId = DEFAULT_REMOTE_ID;
46 static char currentCodec[] =
"PCM_16_16K";
47 static pthread_mutex_t tMutexLock;
49 static void safe_copy(
unsigned char *dst,
const char *src,
size_t len)
53 len = MIN(strlen(src), (len - 1));
56 *((
char *) mempcpy (dst, src, len)) =
'\0';
58 printf(
"len=%i, dst=<%s>, src=<%s>\n", len, (
char *)dst, src);
61 void send_file(
const char *filename)
65 FILE *fp = fopen(filename,
"r");
66 if (fp == NULL)
return;
69 int fragmentSizeRead = 0;
70 int readBytes =
sizeof(se->data.fragment.fragment);
74 eventData.data.speechEvent.type = IARM_BUS_VREXMGR_SPEECH_FRAGMENT;
77 fragmentSizeRead = fread(&se->data.fragment.fragment[0], 1, readBytes, fp);
78 se->data.fragment.length = fragmentSizeRead;
80 printf(
"<<<<<<< Send Speech Fragment Event len: <%i>>>>>>>>>\n", fragmentSizeRead);
82 (
void *)&eventData,
sizeof(eventData));
87 static void _eventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
97 unsigned char remoteId = vrexEventData->
remoteId;
101 case IARM_BUS_VREXMGR_EVENT_ERROR:
108 printf(
"\n_eventHandler unknown event type \n");
115 printf(
"_eventHandler event type not meant for me <%s>...\n", owner);
119 int main(
int argc,
char *argv[])
124 char filename[] = DEFAULT_PCM_FILENAME;
130 printf(
"Tring to initialize IARM..\n");
134 if(IARM_RESULT_SUCCESS != err)
136 printf(
"Error initialing IARM bus()... error code : %d\n",err);
140 printf(
"Trying to connect..\n");
144 if(IARM_RESULT_SUCCESS != err)
146 printf(
"Error connecting to IARM bus()... error code : %d\n",err);
155 printf(
"Enter command..\n");
156 printf(
"m - send motion event\n");
157 printf(
"v - send voice event(s)\n");
158 printf(
"r - randomize remoteId \n");
159 printf(
"c - switch codec\n");
160 printf(
"x - exit..\n");
168 if (currentCodec[0] ==
'P')
170 rc = strcpy_s(currentCodec,
sizeof(currentCodec),
"ADPCM");
178 rc = strcpy_s(currentCodec,
sizeof(currentCodec),
"PCM_16_16K");
184 printf(
"Codec is now: %s\n", currentCodec);
189 remoteId = rand() % 16;
190 printf(
"Remote ID is now: %i\n", (
int)remoteId);
198 eventData.data.motionEvent.x = 128;
199 eventData.data.motionEvent.y = 128;
200 eventData.data.motionEvent.z = 128;
202 printf(
"<<<<<<< Send Motion Event is >>>>>>>>\n");
213 eventData.data.speechEvent.type = IARM_BUS_VREXMGR_SPEECH_BEGIN;
214 safe_copy(eventData.data.speechEvent.data.begin.mimeType,
"\"audio/vnd.wave;codec=1\"",
sizeof(eventData.data.speechEvent.data.begin.mimeType));
216 safe_copy(eventData.data.speechEvent.data.begin.subType, currentCodec,
sizeof(eventData.data.speechEvent.data.begin.subType));
217 safe_copy(eventData.data.speechEvent.data.begin.language,
"en",
sizeof(eventData.data.speechEvent.data.begin.language));
218 printf(
"<<<<<<< Send Speech Begin Event >>>>>>>>\n");
223 printf(
"<<<<<<< Send Speech End Event >>>>>>>>\n");
224 eventData.data.speechEvent.type = IARM_BUS_VREXMGR_SPEECH_END;
225 eventData.data.speechEvent.data.end.reason = IARM_BUS_VREXMGR_SPEECH_DONE;
232 }
while(input !=
'x');