# help to understand code...

**URL:** <https://forum.sierrawireless.com/t/help-to-understand-code/3602>\
**Category:** Around the water cooler\
**Created:** [September 2, 2009, 6:55am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602 "2009-09-02T06:55:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 2, 2009, 6:55am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/1 "2009-09-02T06:55:44Z")

</div>

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;  
}

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 2, 2009, 8:41am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/2 "2009-09-02T08:41:43Z")

</div>

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](http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?f=24&t=27)

---

<div class="post-metadata">

**Author:** ![kiranreddysingareddy](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@kiranreddysingareddy](https://forum.sierrawireless.com/u/kiranreddysingareddy)\
**Post date:** [September 2, 2009, 8:53am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/3 "2009-09-02T08:53:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fer.caballero](https://avatars.discourse-cdn.com/v4/letter/f/ba9def/32.png) [@fer.caballero](https://forum.sierrawireless.com/u/fer.caballero)\
**Post date:** [September 2, 2009, 9:18am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/4 "2009-09-02T09:18:43Z")

</div>

Does the code give any compilation error?

---

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 2, 2009, 9:55am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/5 "2009-09-02T09:55:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 2, 2009, 10:09am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/6 "2009-09-02T10:09:42Z")

</div>

> [@Shafeer](#):
>
> i dont even know how to compile a code in m2m studio…

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

---

<div class="post-metadata">

**Author:** ![blackyblack](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@blackyblack](https://forum.sierrawireless.com/u/blackyblack)\
**Post date:** [September 2, 2009, 10:43am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/7 "2009-09-02T10:43:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 2, 2009, 3:09pm UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/8 "2009-09-02T15:09:00Z")

</div>

ok will try…thnx for advice

---

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 3, 2009, 6:13am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/9 "2009-09-03T06:13:20Z")

</div>

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.

```auto
/* 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?

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 3, 2009, 7:03am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/10 "2009-09-03T07:03:24Z")

</div>

> [@Shafeer](#):
>
> ```auto
> static s8 chk = "toaster"; //This is the string to check
> ```
> 
> ```auto
> 
> 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)
> ```
> 
> Firstly is this correct?

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…

---

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 3, 2009, 8:50am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/11 "2009-09-03T08:50:10Z")

</div>

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

anyway ive modified it…is it correct now?

```auto
/* 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);
}
```

---

<div class="post-metadata">

**Author:** ![blackyblack](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@blackyblack](https://forum.sierrawireless.com/u/blackyblack)\
**Post date:** [September 3, 2009, 10:09am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/12 "2009-09-03T10:09:50Z")

</div>

Looks fine but still won’t compile.

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

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

---

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 3, 2009, 4:00pm UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/13 "2009-09-03T16:00:42Z")

</div>

replaced it with this, no compile error now

```auto
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

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 3, 2009, 4:52pm UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/14 "2009-09-03T16:52:35Z")

</div>

> [@Shafeer](#):
>
> send a bit 1 on any of the serial pins

Pardon ❓😕

---

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 3, 2009, 10:09pm UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/15 "2009-09-03T22:09:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 3, 2009, 10:47pm UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/16 "2009-09-03T22:47:26Z")

</div>

> [@Shafeer](#):
>
> send a “high” bit on any of the serial port pins on the wavecom modem.

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

---

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 4, 2009, 6:08am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/17 "2009-09-04T06:08:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 4, 2009, 8:13am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/18 "2009-09-04T08:13:31Z")

</div>

> [@Shafeer](#):
>
> but my power connector occupies the 4 pins totally

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

> [@](#):
>
> …i cannot connect a wire to any of that pins

You Distributor should be able to supply a suitable cable…

> [@](#):
>
> and are the output voltages similar to the serial pins?

No - see the User Guide for specifications!

---

<div class="post-metadata">

**Author:** ![Shafeer](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shafeer](https://forum.sierrawireless.com/u/Shafeer)\
**Post date:** [September 4, 2009, 9:30am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/19 "2009-09-04T09:30:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 4, 2009, 10:05am UTC](https://forum.sierrawireless.com/t/help-to-understand-code/3602/20 "2009-09-04T10:05:00Z")

</div>

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…

[Next page](https://forum.sierrawireless.com/t/help-to-understand-code/3602.md?page=2)
