|
|
Classification: |
C++ |
Category: |
Telephony (ETel) |
Created: |
03/13/2000 |
Modified: |
09/02/2001 |
Number: |
FAQ-0475 |
Platform: |
ER5 |
|
Question: How can I send an SMS?
Answer: The code below should demonstrate how to send an SMS (and it should work on both MARM and WINS with an IR pod): #include "eustd.h" #include "etel.h" #include "etelbgsm.h" #include "BSCGSMCS.H" #include "SMSSERV.H" _LIT(KSmsPhoneModuleName, "GSMBSC"); _LIT(KSmsPhoneName, "GsmPhone1"); _LIT(KCommModuleName,"ECUART.CSY"); // Vodafone #+44 (0) aabbccddee, Vodafone ServiceCentre +44 385 016 005 // Test PDU - Validity Period == AD (7days) // Type 145 // Message = "TESTING" const TText8 MyPdu[]={0x0B,0x91, 0x44,0x83,0x05,0x61,0x00,0xF5, /*Service centre*/ 0x11,0x00,0x0C,0x91, 0x44,0xaa,0xbb,0xcc,0xdd,0xee,/*Destination*/ 0x00,0x00,0xAD,0x07,0xD4,0xE2,0x94,0x9A,0x74,0x1E,0x01}; const TUint TestLengthA = 29; void UnloadCommModule(TAny* aCommServer) { STATIC_CAST(RCommServ*, aCommServer)->UnloadCommModule(KCommModuleName); }
void UnloadPhoneModule(TAny* aTelServer) { STATIC_CAST(RTelServer*, aTelServer)->UnloadPhoneModule(KSmsPhoneModuleName); }
// do the example LOCAL_C void doExampleL() { _LIT(KIntroText,"SMS Send Test\n"); console->Printf(KIntroText);
TInt r=0; #if defined (__EPOC32__) r=StartC32(); if ((r!=KErrNone) && (r!=KErrAlreadyExists)) console->Printf(_L("Failed to start C32 %d\n\r"),r); #endif
console->Printf(_L("Opening & connecting to servers...\n")); // Open and connect to required servers, etc. RCommServ commServer; User::LeaveIfError(commServer.Connect()); CleanupClosePushL(commServer); r=commServer.LoadCommModule(KCommModuleName); CleanupStack::PushL(TCleanupItem(UnloadCommModule,&commServer)); if ((r!=KErrNone) && (r!=KErrAlreadyExists)) User::Leave(r); RTelServer telServer; RBasicGsmPhone phone; RSmsMessaging messaging; User::LeaveIfError(telServer.Connect()); CleanupClosePushL(telServer); User::LeaveIfError(telServer.LoadPhoneModule(KSmsPhoneModuleName)); CleanupStack::PushL(TCleanupItem(UnloadPhoneModule,&telServer)); User::LeaveIfError(phone.Open(telServer, KSmsPhoneName)); CleanupClosePushL(phone); User::LeaveIfError(messaging.Open(phone)); CleanupClosePushL(messaging); console->Printf(_L("Initialising phone...\n")); // Initialise phone TRequestStatus status; phone.Initialise(status); User::WaitForRequest(status); User::LeaveIfError(status.Int());
console->Printf(_L("Creating a TSms from MyPdu...\n")); // Create an TSms from a PDU TPtrC8 pduPtrA(MyPdu,TestLengthA); TSms::TPdu pduBufA(pduPtrA); TSms sms(pduBufA); sms.SetUseDefaultSca(EFalse);
console->Printf(_L("Sending SMS\n")); // Send SMS TUint uint; messaging.SendMessage(status,uint,sms); User::WaitForRequest(status); User::LeaveIfError(status.Int());
console->Printf(_L("Done\n"));
// Close & tidy up CleanupStack::PopAndDestroy(6); }
|
|
|