Sample code for Mobile Terminated SMS message
#include "legato.h"
#include "interfaces.h"
#include "smsSample.h"
#define MESSAGE_FEEDBACK "Message from %s received"
//--------------------------------------------------------------------------------------------------
//--------------------- -----------------------------------------------------------------------------
static void RxMessageHandler
(
void* contextPtr
)
{
char timestamp[LE_SMS_TIMESTAMP_MAX_BYTES] = {0};
char text[LE_SMS_TEXT_MAX_BYTES] = {0};
char textReturn[LE_SMS_TEXT_MAX_BYTES] = {0};
LE_INFO("A New SMS message is received with ref.%p", msgRef);
{
res = le_sms_GetSenderTel(msgRef, tel, sizeof(tel));
if(res != LE_OK)
{
LE_ERROR("le_sms_GetSenderTel has failed (res.%d)!", res);
}
else
{
LE_INFO("Message is received from %s.", tel);
}
res = le_sms_GetTimeStamp(msgRef, timestamp, sizeof(timestamp));
if(res != LE_OK)
{
LE_ERROR("le_sms_GetTimeStamp has failed (res.%d)!", res);
}
else
{
LE_INFO("Message timestamp is %s.", timestamp);
}
res = le_sms_GetText(msgRef, text, sizeof(text));
if(res != LE_OK)
{
LE_ERROR("le_sms_GetText has failed (res.%d)!", res);
}
else
{
LE_INFO("Message content: \"%s\"", text);
}
snprintf(textReturn, sizeof(textReturn), MESSAGE_FEEDBACK, tel);
// Return a message to sender with phone number include (see smsMO.c file)
res = smsmo_SendMessage(tel, textReturn);
if (res != LE_OK)
{
LE_ERROR("SmsMoMessage has failed (res.%d)!", res);
}
else
{
LE_INFO("the message has been successfully sent.");
}
res = le_sms_DeleteFromStorage(msgRef);
if(res != LE_OK)
{
LE_ERROR("le_sms_DeleteFromStorage has failed (res.%d)!", res);
}
else
{
LE_INFO("the message has been successfully deleted from storage.");
}
}
else
{
LE_WARN("Warning! I read only Text messages!");
}
le_sms_Delete(msgRef);
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
le_result_t smsmt_Receiver
(
void
)
{
HdlrRef = le_sms_AddRxMessageHandler(RxMessageHandler, NULL);
if (!HdlrRef)
{
LE_ERROR("le_sms_AddRxMessageHandler has failed!");
return LE_FAULT;
}
else
{
return LE_OK;
}
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
void smsmt_HandlerRemover
(
void
)
{
}