help to understand code...


#1

Ive seen a code of a fellow forumer and im building a application similar to him. However i have problems understanding some of the codes which are similar to sms_automation sample.

here is the code

void adl_main ( adl_InitType_e InitType )
{
TRACE (( 1, “Embedded Application : Main” ));
TRACE (( AUTO_TRACE_LEVEL, “Start SMS_Automaton application” ));
while(1){
// Subscribe to the SMS Service
sms_automaton_Handle_txt = adl_smsSubscribe(SMS_AUTO_Handler, SMS_AUTO_ctrl_Handler, ADL_SMS_MODE_TEXT);
adl_smsSend(sms_automaton_Handle_txt, *SmsTel_send, *data_txt, ADL_SMS_MODE_TEXT);
}
}

bool SMS_AUTO_Handler(ascii *SmsTel, ascii *SmsTimeOrLength, ascii *SmsText)
{
u16 pos_sms = 0;
bool sms_tobe_fwd = TRUE;
ascii * reply_text = “DATA from Wavecom Supreme”;
ascii Keyword_comp[wm_strlen(smsreply_keyword)]; //this is creating a new string with the same length as smsreply_keyword? i dont see //smsreply_keyword being declared anywhere

while ( (pos_sms+1) < wm_strlen(smsreply_keyword) )
{
TRACE (( AUTO_TRACE_LEVEL, "SMS searching "));

//read begining of SmsText for keyword

SmsText[pos_sms]=Keyword_comp[pos_sms];
pos_sms++;

}
//SMS contains Keyword(getdata)?
if(Keyword_comp==smsreply_keyword)
{
TRACE (( AUTO_TRACE_LEVEL, “Keyword match”));
*SmsTel=SmsTel_send; // what does this line do? i know *SmsTel is the phone number of the sms that was sent to the modem
}
else
{
TRACE (( AUTO_TRACE_LEVEL, "Keyword no match "));
sms_tobe_fwd=FALSE; //what does this forward function do?
}

return sms_tobe_fwd;
}


#2

Your post would be a lot easier to read if you used the proper ‘Code’ formatting.

Check it in the ‘Preview’ before you press the ‘Submit’ button…

There is a forum user guide here: viewtopic.php?f=24&t=27


#3

sorrry Shareef i am also working on the same code i am new to thisq2686 module. it get work i will inform to u… all the best


#4

Does the code give any compilation error?


#5

thnx awneli for the tip, just that i couldnt bold out anything that was in code tags

btw i dont even know how to compile a code in m2m studio…


#6

Then You really need to set this aside for a while and lay the basic foundations first!


#7

Sorry Shaffer, but this code is a total mess. You better start from the scratch (or wavecom sample) than using this.
As soon as program will start it will enter infinite loop, trying to subscribe to SMS service and to send an SMS (without even phone number and SMS text provided). This code is both syntactically and semantically wrong so you can trash it and forget about it.


#8

ok will try…thnx for advice


#9

ok ive done up my own code from the samples,

basically whenever my GSM modem recieves an sms it will check for a certain string and if its a match, it replies to the sender with “correct” and so does the opposite for no match.

/* includes */
#include "adl_global.h"

/* variables */
static s8 sms_automaton_Handle_txt;
static u8 AUTO_TRACE_LEVEL = 2;
static s8 chk = "toaster";   //This is the string to check

/* Constants */

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024;


/***************************************************************************/
/*  Function   : SMS_AUTO_ctrl_Handler                                     */
/*-------------------------------------------------------------------------*/
/*  Objet      : SMS Automaton SMS Service Event Handler                   */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  Event             |   |   |   |  Event from SMS Service                */
/*--------------------+---+---+---+----------------------------------------*/
/*  Nb                |   |   |   |  SMS location                          */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void SMS_AUTO_ctrl_Handler(u8 Event, u16 Nb)
{
    // Does nothing
}


/***************************************************************************/
/*  Function   : SIM_AUTO_handler                                          */
/*-------------------------------------------------------------------------*/
/*  Objet      : SMS Automaton SMS Service Data Handler                    */
/*                                                                         */
/*  Return     : sms_tobe_fwd to or not to forward the SMS                 */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  SmsTel            |   |   |   |  SMS Data                              */
/*--------------------+---+---+---+----------------------------------------*/
/*  SmsTimeOrLength   |   |   |   |  SMS Data                              */
/*--------------------+---+---+---+----------------------------------------*/
/*  SmsText           |   |   |   |  SMS Data                              */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
bool SMS_AUTO_Handler(ascii *SmsTel, ascii *SmsTimeOrLength, ascii *SmsText)
{          
    bool sms_tobe_fwd = TRUE;
    
    //check if SmsText is equals to string
    if(SmsText == chk){
    	adl_smsSend(sms_automaton_Handle_txt, SmsTel, "Correct", ADL_SMS_MODE_TEXT); //if it equals, reply sms with "correct"   	 
    }
    else{
    	adl_smsSend(sms_automaton_Handle_txt, SmsTel, "Wrong", ADL_SMS_MODE_TEXT);  //if it does not equals, reply sms with "Wrong"  
    }   

    return sms_tobe_fwd;
}


/***************************************************************************/
/*  Function   : adl_main                                                  */
/*-------------------------------------------------------------------------*/
/*  Objet      : Customer ADL application initialisation                   */
/*                                                                         */
/*  Return     :                                                           */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  adlInitType       |   |   |   |  Application starting mode             */
/***************************************************************************/
void adl_main(adl_InitType_e adlInitType)
{            
    // SMS automaton test application
    TRACE (( 1, "SMS automaton sample main" ));
    TRACE (( 1, __DATE__ ));
    TRACE (( 1, __TIME__ ));
    
    TRACE (( AUTO_TRACE_LEVEL, "Start SMS_Automaton application" ));
    
    // Subscribe to the SMS Service
    sms_automaton_Handle_txt = adl_smsSubscribe(SMS_AUTO_Handler, SMS_AUTO_ctrl_Handler, ADL_SMS_MODE_TEXT);
}

Firstly is this correct? and i would like to know since my serial port on the modem is not being used, will it be idle for the whole period of time from modem startup?


#10

No, I’m afraid it’s not.

Nothing to do with Wavecom or Open-AT, but the basics of the ‘C’ programming language:

The ‘==’ operator cannot be used to compare strings like that!

I think it would probably be easier if you spend some time learning the ‘C’ programming language in a “conventional” environment before trying to apply it in Open-AT.
There are loads of books and tools for learning the ‘C’ programming language on the PC, etc…


#11

oops left out that small mistake, confusions btw c c++ and java

anyway ive modified it…is it correct now?

/* includes */
#include "adl_global.h"

/* variables */
static s8 sms_automaton_Handle_txt;
static u8 AUTO_TRACE_LEVEL = 2;
static s8 chk = "toaster";   //This is the string to check

/* Constants */

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024;


/***************************************************************************/
/*  Function   : SMS_AUTO_ctrl_Handler                                     */
/*-------------------------------------------------------------------------*/
/*  Objet      : SMS Automaton SMS Service Event Handler                   */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  Event             |   |   |   |  Event from SMS Service                */
/*--------------------+---+---+---+----------------------------------------*/
/*  Nb                |   |   |   |  SMS location                          */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void SMS_AUTO_ctrl_Handler(u8 Event, u16 Nb)
{
    // Does nothing
}


/***************************************************************************/
/*  Function   : SIM_AUTO_handler                                          */
/*-------------------------------------------------------------------------*/
/*  Objet      : SMS Automaton SMS Service Data Handler                    */
/*                                                                         */
/*  Return     : sms_tobe_fwd to or not to forward the SMS                 */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  SmsTel            |   |   |   |  SMS Data                              */
/*--------------------+---+---+---+----------------------------------------*/
/*  SmsTimeOrLength   |   |   |   |  SMS Data                              */
/*--------------------+---+---+---+----------------------------------------*/
/*  SmsText           |   |   |   |  SMS Data                              */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
bool SMS_AUTO_Handler(ascii *SmsTel, ascii *SmsTimeOrLength, ascii *SmsText)
{
    bool sms_tobe_fwd = TRUE;
    u16 diff = 0;
    diff = strcmp(SmsText, chk);
    //check if SmsText is equals to string
    if(diff == 0){
    	adl_smsSend(sms_automaton_Handle_txt, SmsTel, "Correct", ADL_SMS_MODE_TEXT); //if it equals, reply sms with "correct"
    }
    else{
    	adl_smsSend(sms_automaton_Handle_txt, SmsTel, "Wrong", ADL_SMS_MODE_TEXT);  //if it does not equals, reply sms with "Wrong"
    }

    return sms_tobe_fwd;
}


/***************************************************************************/
/*  Function   : adl_main                                                  */
/*-------------------------------------------------------------------------*/
/*  Objet      : Customer ADL application initialisation                   */
/*                                                                         */
/*  Return     :                                                           */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  adlInitType       |   |   |   |  Application starting mode             */
/***************************************************************************/
void adl_main(adl_InitType_e adlInitType)
{
    // SMS automaton test application
    TRACE (( 1, "SMS automaton sample main" ));
    TRACE (( 1, __DATE__ ));
    TRACE (( 1, __TIME__ ));

    TRACE (( AUTO_TRACE_LEVEL, "Start SMS_Automaton application" ));

    // Subscribe to the SMS Service
    sms_automaton_Handle_txt = adl_smsSubscribe(SMS_AUTO_Handler, SMS_AUTO_ctrl_Handler, ADL_SMS_MODE_TEXT);
}

#12

Looks fine but still won’t compile.

static s8 chk = "toaster";   //This is the string to check

This does not look as string initialisation since s8 means signed byte type.


#13

replaced it with this, no compile error now

if(strcmp(SmsText, "toaster") == 0){
    	adl_smsSend(sms_automaton_Handle_txt, SmsTel, "Correct", ADL_SMS_MODE_TEXT); //if it equals, reply sms with "correct"
    }

btw may i know any simple code to send a bit 1 on any of the serial pins available? this code im gonna put it in the if condition


#14

Pardon :question: :confused:


#15

hmm like send a “high” bit on any of the serial port pins on the wavecom modem.

that means if the lets say the IF condition matches, then one of the pins on the serial will emit a signal


#16

Wouldn’t one of the GPIO pins be more appropriate for that?


#17

but my power connector occupies the 4 pins totally…i cannot connect a wire to any of that pins

and are the output voltages similar to the serial pins?


#18

Look more carefully - you will see that it only actually uses 2 of the pins

You Distributor should be able to supply a suitable cable…

No - see the User Guide for specifications!


#19

so it isnt possible to use the serial ports???

btw my disto just told me to cut the power connector instead.

anyway if i were to use the GPIO’s what would the code be?

ive seen some but those are with event handlers, i am not needing an input…just an output that maintains a “high” state


#20

Serial ports, as the name suggests, are for Serial Data!

If you take a look at the ADL Open Device Service (specifically, the Open UART Interface) you might be able to do something with that - I’ve never tried it myself…