03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

iSmsMsg-<br />

>SmsPDU().SetServiceCenterAddressL(KServiceCenterNumber);<br />

// Convert data into unicode as CSmsBuffer will convert to<br />

appropriate<br />

// format for us.<br />

TBuf buf;<br />

buf.Copy(aData);<br />

// Insert our SMS pattern header so that our receiver is able<br />

to detect<br />

// the incoming message, and then append the data.<br />

smsBuffer->InsertL(0, KGdpSmsHeaderTag);<br />

smsBuffer->InsertL(KGdpSmsPatternLen, buf);<br />

iRetries = KGdpSmsSendRetries;<br />

Reset();<br />

ReEnterCurrentState(); // Kick us off again.<br />

}<br />

If we're already busy sending an SMS message, we simply give up on this new request and<br />

return – it is up to the client to ensure we're not given more packets than we can cope with.<br />

We create a CSmsBuffer object to contain the text contents of our message. CSmsBuffer<br />

maintains the text content of the message in an array of TText objects, and provides<br />

functions to modify the content.<br />

We then create a CSmsMessage object. This object helps to hide the underlying complexity<br />

of ensuring that the message is structured in the correct network format of an SMS<br />

message. TSmsUserDataSettings allows us to specify that the message is stored in 7-bit<br />

format. SMS supports both 7-bit and 8-bit data transport, but only 7-bit is universally<br />

implemented, so that's what I've chosen to use here. SMS supports a maximum message<br />

length of 160 7-bit characters.<br />

aAddress contains the telephone number of the receiver. The only test we do with this<br />

number is to see that it does not exceed a certain size.<br />

Interestingly, CSmsMessage accepts a Unicode string for the address to which the SMS will<br />

be sent, so we must convert the address from narrow text. We can do this by copying it into<br />

a Unicode descriptor. We then set the service center number.<br />

Before inserting aData into the CSmsBuffer object, we have to ensure that we first insert<br />

the pattern that will enable the receiver to recognize the message as a GDP SMS message.<br />

We then set up how many times we're going to retry sending if the first attempt fails and then<br />

set the state machine going.<br />

The first time a packet is sent, the current state (iState) will already be set to<br />

TSendMsgState, so ReEnterCurrentState() will cause us to enter that state:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!