#include "legato.h"
#include "interfaces.h"
static const char * PsapNumber = NULL;
static le_ecall_CallRef_t LastTestECallRef = NULL;
static le_audio_StreamRef_t FeOutRef = NULL;
static le_audio_StreamRef_t FileAudioRef = NULL;
static le_audio_ConnectorRef_t AudioOutputConnectorRef = NULL;
static le_audio_MediaHandlerRef_t MediaHandlerRef = NULL;
static const char AudioFilePath[] = "/male.wav";
static int AudioFileFd = -1;
static void DisconnectAudio
(
void
)
{
if(AudioOutputConnectorRef)
{
if(FileAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", FileAudioRef, AudioOutputConnectorRef);
}
if(FeOutRef)
{
LE_INFO(
"Disconnect %p from connector.%p", FeOutRef, AudioOutputConnectorRef);
}
}
if(AudioOutputConnectorRef)
{
AudioOutputConnectorRef = NULL;
}
if(FileAudioRef)
{
FileAudioRef = NULL;
}
if(FeOutRef)
{
FeOutRef = NULL;
}
if(MediaHandlerRef)
{
MediaHandlerRef = NULL;
}
}
static void MyMediaEventHandler
(
le_audio_StreamRef_t streamRef,
le_audio_MediaEvent_t event,
void* contextPtr
)
{
switch(event)
{
case LE_AUDIO_MEDIA_ENDED:
LE_INFO(
"File event is LE_AUDIO_MEDIA_ENDED.");
{
return;
}
else
{
}
break;
case LE_AUDIO_MEDIA_ERROR:
LE_INFO(
"File event is LE_AUDIO_MEDIA_ERROR.");
break;
case LE_AUDIO_MEDIA_NO_MORE_SAMPLES:
LE_INFO(
"File event is LE_AUDIO_MEDIA_NO_MORE_SAMPLES.");
break;
default:
LE_INFO(
"File event is %d", event);
break;
}
}
static void ConnectAudio
(
void
)
{
if (FeOutRef == NULL)
{
LE_INFO(
"Switching to I2S interface...");
if (FeOutRef==NULL)
{
}
else
{
LE_INFO(
"Open I2S: FeOutRef.%p", FeOutRef);
}
}
else
{
LE_INFO(
"Open Speaker: FeOutRef.%p", FeOutRef);
}
LE_ERROR_IF((AudioOutputConnectorRef==NULL),
"AudioOutputConnectorRef is NULL!");
{
"Failed to connect I2S TX on Output connector!");
}
LE_ERROR_IF((FileAudioRef==NULL),
"OpenFilePlayback returns NULL!");
MyMediaEventHandler,
NULL);
{
LE_ERROR(
"Failed to connect FilePlayback on output connector!");
return;
}
if ((AudioFileFd=open(AudioFilePath, O_RDONLY)) == -1)
{
DisconnectAudio();
exit(0);
}
else
{
LE_INFO(
"Open file %s with AudioFileFd.%d", AudioFilePath, AudioFileFd);
}
{
return;
}
}
static void MyECallEventHandler
(
le_ecall_CallRef_t eCallRef,
le_ecall_State_t state,
void* contextPtr
)
{
LE_INFO(
"eCall TEST: New eCall state: %d for eCall ref.%p", state, eCallRef);
switch(state)
{
case LE_ECALL_STATE_STARTED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_STARTED.");
break;
}
case LE_ECALL_STATE_CONNECTED:
{
LE_INFO(
"Mute audio interface and voice prompt.");
LE_INFO(
"eCall state is LE_ECALL_STATE_CONNECTED.");
break;
}
case LE_ECALL_STATE_DISCONNECTED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_DISCONNECTED.");
break;
}
case LE_ECALL_STATE_WAITING_PSAP_START_IND:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_WAITING_PSAP_START_IND.");
break;
}
case LE_ECALL_STATE_PSAP_START_IND_RECEIVED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_PSAP_START_IND_RECEIVED.");
{
}
break;
}
case LE_ECALL_STATE_MSD_TX_STARTED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_MSD_TX_STARTED.");
break;
}
case LE_ECALL_STATE_LLNACK_RECEIVED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_LLNACK_RECEIVED.");
break;
}
case LE_ECALL_STATE_LLACK_RECEIVED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_LLACK_RECEIVED.");
break;
}
case LE_ECALL_STATE_MSD_TX_COMPLETED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_MSD_TX_COMPLETED.");
break;
}
case LE_ECALL_STATE_MSD_TX_FAILED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_MSD_TX_FAILED.");
break;
}
case LE_ECALL_STATE_ALACK_RECEIVED_POSITIVE:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_ALACK_RECEIVED_POSITIVE.");
break;
}
case LE_ECALL_STATE_ALACK_RECEIVED_CLEAR_DOWN:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_ALACK_RECEIVED_CLEAR_DOWN.");
break;
}
case LE_ECALL_STATE_STOPPED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_STOPPED.");
LE_INFO(
"Unmute audio interface and voice prompt.");
break;
}
case LE_ECALL_STATE_RESET:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_RESET.");
LE_INFO(
"Unmute audio interface and voice prompt.");
break;
}
case LE_ECALL_STATE_COMPLETED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_COMPLETED.");
break;
}
case LE_ECALL_STATE_FAILED:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_FAILED.");
LE_INFO(
"Unmute audio interface and voice prompt.");
break;
}
case LE_ECALL_STATE_END_OF_REDIAL_PERIOD:
{
LE_INFO(
"eCall state is LE_ECALL_STATE_END_OF_REDIAL_PERIOD.");
break;
}
case LE_ECALL_STATE_UNKNOWN:
default:
{
break;
}
}
}
static void StartTestECall
(
void
)
{
le_ecall_State_t state = LE_ECALL_STATE_UNKNOWN;
le_ecall_StateChangeHandlerRef_t stateChangeHandlerRef = 0x00;
ConnectAudio();
LE_ASSERT(((state>=LE_ECALL_STATE_STARTED) && (state<=LE_ECALL_STATE_FAILED)));
}
static void SigHandler
(
int sigNum
)
{
LE_INFO(
"End and delete last test eCall");
DisconnectAudio();
exit(EXIT_SUCCESS);
}
static void PrintUsage()
{
int idx;
bool sandboxed = (getuid() != 0);
const char * usagePtr[] = {
"Usage of the eCallWPrompt is:",
" eCallWPrompt <PSAP number>",
};
{
if(sandboxed)
{
}
else
{
fprintf(stderr, "%s\n", usagePtr[idx]);
}
}
}
{
{
signal(SIGINT, SigHandler);
LE_INFO(
"======== Start eCallWPrompt Test with PSAP.%s========",
PsapNumber);
StartTestECall();
LE_INFO(
"======== eCallWPrompt Test SUCCESS ========");
}
else
{
PrintUsage();
exit(EXIT_FAILURE);
}
}