Thanx trthaithong ,
We use following code to receive SMS. We think the Sim doesn’t full initialized.
#include "adl_global.h"
u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );
static s8 sms_automaton_Handle_txt;
static s8 test_Handle_txt;
static u8 AUTO_TRACE_LEVEL;
static const ascii * smsauto_NameBuffer = "Wavecom SMS Automaton";
/***************************************************************************/
/* Local functions */
/***************************************************************************/
bool SMS_AUTO_Handler( ascii * SmsTel, ascii * SmsTimeOrLength, ascii * SmsText)
{
bool sms_tobe_fwd = TRUE;
adl_atSendResponse ( ADL_AT_RSP, "\r\nHey boy, I am here!\r\n" );
adl_atSendResponse ( ADL_AT_UNS, "\r\n Salam\r\n" );
return sms_tobe_fwd;
}
/*::::::::::::*******/
void SMS_AUTO_ctrl_Handler(u8 Event, u16 Nb)
{
adl_atSendResponse ( ADL_AT_UNS, "\r\nHey boy, I am here in empty function!\r\n" );
}
void TimerHandler ( u8 ID )
{
TRACE (( 1, "Embedded : Hello World" ));
adl_atSendResponse ( ADL_AT_UNS, "\r\nHey boy, i'm here in timer handler\r\n" );
return;
}
void SimHandler ( u8 Event )
{
ascii Tel[14] = "+989370738188", Message[6] = "salam";
TRACE (( 1, "Embedded : Hello World" ));
adl_atSendResponse ( ADL_AT_UNS, "\r\nHey boy, i'm here in sim handler\r\n" );
adl_simState_e t = adl_simGetState();
if(ADL_SIM_EVENT_PIN_OK)
{
adl_atSendResponse ( ADL_AT_UNS, "\r\nsuccessful\r\n" );
}
else
{
adl_atSendResponse ( ADL_AT_UNS, "\r\nunsuccessful\r\n" );
}
if(t == ADL_SIM_STATE_FULL_INIT)
{
adl_atSendResponse ( ADL_AT_UNS, "\r\nsim is in full state\r\n" );
}
adl_smsSend((u8)sms_automaton_Handle_txt,Tel,Message,ADL_SMS_MODE_TEXT);
return;
}
bool textprocess(void)
{
bool sms_tobe_fwd = TRUE;
ascii *tag_in, *tag_out, *text, *unso;
ascii *UserId, *Passw, *Cmmd, *RcvCmd;
u16 pos_sms = 0, pos, len;
u16 match_tag_in, match_tag_out;
ascii * SmsText;
ascii UnsoRsp [ 50 ];
adl_atSendResponse ( ADL_AT_RSP, "\r\nHey boy, I am here in processor1!\r\n" );
//wm_sprintf ( SmsText,"#marsus#marsus#control#");
SmsText = "#marsus#marsus#control#";
adl_atSendResponse ( ADL_AT_RSP, "\r\nHey boy, I am here in processor2!\r\n" );
while ( (SmsText[pos_sms] != '#') && (pos_sms < wm_strlen(SmsText)) )//finding the first # sign
{
adl_atSendResponse ( ADL_AT_UNS, "\r\nin first while!\r\n" );
pos_sms++;
}//end of while
pos = pos_sms+1; //getting the first part containing the user id
adl_atSendResponse ( ADL_AT_RSP, "\r\nHey boy, I am here in processor3!\r\n" );
while ((SmsText[++pos_sms] != '#') && (pos_sms < wm_strlen(SmsText)));//finding the end of user id
if(pos_sms >= wm_strlen(SmsText))
{
TRACE (( AUTO_TRACE_LEVEL, "SMS AUTOMATON : '#' not found, End of process"));
return sms_tobe_fwd;
}
adl_atSendResponse ( ADL_AT_RSP, "\r\nHey boy, I am here in processor4!\r\n" );
len = pos_sms-pos;
UserId = (ascii *)adl_memGet((u16)(len+1));
wm_strncpy( UserId, SmsText+pos, len);
UserId[len] = 0;
pos = pos_sms+1; //getting the second part containing the password
adl_atSendResponse ( ADL_AT_RSP, "\r\nHey boy, I am here in processor5!\r\n" );
while ((SmsText[++pos_sms] != '#') && (pos_sms < wm_strlen(SmsText)));//finding the end of password
if(pos_sms >= wm_strlen(SmsText))
{
TRACE (( AUTO_TRACE_LEVEL, "SMS AUTOMATON : '#' not found"));
return sms_tobe_fwd;
}
adl_atSendResponse ( ADL_AT_RSP, "\r\nHey boy, I am here in processor6!\r\n" );
len = pos_sms-pos;
Passw = (ascii *)adl_memGet((u16)(len+1));
wm_strncpy( Passw, SmsText+pos, len);
Passw[len] = 0;
adl_atSendResponse ( ADL_AT_RSP, "\r\nHey boy, I am here in processor7!\r\n" );
//TODO: HERE WE SHOULD CHECK THE USER ID AND PASSWORD TO AUTHENTICATION AND CREATE LIST IF ALLOWED
while ( (SmsText[pos_sms] == '#') && (pos_sms < wm_strlen(SmsText)) )
{
TRACE (( AUTO_TRACE_LEVEL, "SMS AUTOMATON "));
adl_atSendResponse ( ADL_AT_RSP, "\r\nWe want to start to parsing sms\r\n" );
pos = pos_sms+1;
while ((SmsText[++pos_sms] != '#') && (pos_sms < wm_strlen(SmsText)));//finding the end of first
if(pos_sms >= wm_strlen(SmsText))
{
TRACE (( AUTO_TRACE_LEVEL, "SMS AUTOMATON : '#' not found"));
break;
}
len = pos_sms-pos;
Cmmd = (ascii *)adl_memGet((u16)(len+1));
wm_strncpy( Cmmd, SmsText+pos, len);
Cmmd[len] = 0;
adl_atSendResponse ( ADL_AT_RSP, "\r\n Salam\r\n" );
wm_sprintf ( UnsoRsp, "\r\n%s\r\n", Passw );
// Send unsolicited
adl_atSendResponse ( ADL_AT_RSP, UnsoRsp );
}
return sms_tobe_fwd;
}
void adl_main ( adl_InitType_e InitType )
{
ascii Tel[14] = "+989370738188", Message[6] = "salam";
s8 t;
TRACE (( 1, "Embedded Application : Main" ));
adl_atSendResponse ( ADL_AT_UNS, "\r\nWe want to start to recieve sms\r\n" );
// TO DO : Add your initialization code here
adl_tmrSubscribe ( TRUE, 100, ADL_TMR_TYPE_100MS,TimerHandler );
adl_simSubscribe (SimHandler,NULL);
sms_automaton_Handle_txt = adl_smsSubscribe(SMS_AUTO_Handler, SMS_AUTO_ctrl_Handler, ADL_SMS_MODE_TEXT);
if(sms_automaton_Handle_txt == ADL_RET_ERR_PARAM){
adl_atSendResponse ( ADL_AT_UNS, "\r\nCan't subscribe to the sms\r\n" );
}
else
{
adl_atCmdCreate ( "AT+CNMI=0,1,0,0,0", FALSE, ( adl_atRspHandler_t ) NULL, NULL );
t = adl_smsSend((u8)sms_automaton_Handle_txt,Tel,Message,ADL_SMS_MODE_TEXT);
adl_atSendResponse ( ADL_AT_UNS, "\r\nSubscribed\r\n" );
adl_atCmdCreate ( "AT+CNMI=0,1,0,0,0", FALSE, ( adl_atRspHandler_t ) NULL, NULL );
adl_atCmdCreate ( "AT+CSMP=17,169,0,0", FALSE, ( adl_atRspHandler_t ) NULL, NULL );
adl_atCmdCreate ( "AT+CMGF=1", FALSE, ( adl_atRspHandler_t ) NULL, NULL );
adl_atCmdCreate ( "AT+CSCA=\"+989350001400\"", FALSE, ( adl_atRspHandler_t ) NULL, NULL );
adl_atCmdCreate ( "AT+CMGS=+989370738188", FALSE, ( adl_atRspHandler_t ) NULL, NULL );
adl_atCmdCreate ( "Salam, man applicationam ke sms mizanam /032", FALSE, ( adl_atRspHandler_t ) NULL, NULL );
//wm_atSendCommand(45,WM_AT_SEND_RSP_TO_EMBEDDED,"at_cmgs=\"+989370738188\">Good Morning\"1A\"\r");
if(t == OK){
adl_atSendResponse ( ADL_AT_UNS, "\r\nsending process is successful\r\n" );
}
else if(t == ADL_RET_ERR_UNKNOWN_HDL){
adl_atSendResponse ( ADL_AT_UNS, "\r\n Unknown handler\r\n" );
}
else if(t == ADL_RET_ERR_PARAM){
adl_atSendResponse ( ADL_AT_UNS, "\r\n Parameter error\r\n" );
}
else if(t == ADL_RET_ERR_BAD_STATE){
adl_atSendResponse ( ADL_AT_UNS, "\r\n bad state\r\n" );
}
else {
adl_atSendResponse ( ADL_AT_UNS, "\r\n failed to send\r\n" );
}
}
textprocess();
}
Which additional initialization should be set?
ThX you!