views:

878

answers:

3

I wonder if anyone has managed to create a working code for sending out binary messages (to configure Symbian phones) and have also some binary data sample. So far all the samples I have found fail to leave the Outbox or never return.

// Current entry is the Draft folder.
    iSmsMtm->SwitchCurrentEntryL( KMsvDraftEntryId );
    // Create a new SMS message entry as a child of the current context.
    iSmsMtm->CreateMessageL( KUidMsgTypeSMS.iUid );
    CMsvEntry& serverEntry = iSmsMtm->Entry();
    TMsvEntry entry( serverEntry.Entry() );

    /* Send Binary SMS */
    CSmsHeader &hdr = iSmsMtm->SmsHeader(); 
    CSmsMessage &msg = hdr.Message(); 
    CSmsPDU &pdu = msg.SmsPDU(); 
    CSmsUserData &userdata = pdu.UserData(); 

    // Set the DCS byte
    pdu.SetBits7To4(TSmsDataCodingScheme::ESmsDCSTextUncompressedWithNoClassInfo);
    pdu.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabet8Bit);
    pdu.SetClass(ETrue, TSmsDataCodingScheme::ESmsClass2);

    char buf[]= {...}; //my binary data, 247 bytes long

    // Construct a dummy message
    HBufC8 * iMessage = HBufC8::NewL(300);

    TPtr8 TempUDHBufDesc((TUint8*)buf,247,247);
    iMessage->Des().Copy(TempUDHBufDesc);
    _LOGFENTRY1(_L("mess length %d"),iMessage->Des().Length());
    userdata.SetBodyL(*iMessage); 
    delete iMessage; 

    // Message will be sent immediately.
    entry.SetSendingState( KMsvSendStateWaiting );

    entry.iDate.UniversalTime(); // insert current time //Solution for HomeTime()
    // Set the SMS message settings for the message.
    CSmsHeader& header = iSmsMtm->SmsHeader();
    CSmsSettings* settings = CSmsSettings::NewL();
    CleanupStack::PushL( settings );

    settings->CopyL( iSmsMtm->ServiceSettings() ); // restore settings
    settings->SetDelivery( ESmsDeliveryImmediately ); // to be delivered immediately
    settings->SetDeliveryReport(EFalse);
    settings->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet8Bit); // IMPORTANT! For sending binary SMS
    header.SetSmsSettingsL( *settings ); // new settings

    // Let's check if there is a service center address.
    if ( header.Message().ServiceCenterAddress().Length() == 0 )
    {
     // No, there isn't. We assume there is at least one service center
     // number set and use the default service center number.
     CSmsSettings* serviceSettings = &( iSmsMtm->ServiceSettings() );
     // Check if number of service center addresses in the list is null.
     if ( !serviceSettings->ServiceCenterCount() )
     {   _LOGENTRY("No SC");
      return ; // quit creating the message
     }
     else
     {
      CSmsNumber* smsCenter= CSmsNumber::NewL();
      CleanupStack::PushL(smsCenter);
      smsCenter->SetAddressL((serviceSettings->GetServiceCenter( serviceSettings->DefaultServiceCenter())).Address());
      header.Message().SetServiceCenterAddressL( smsCenter->Address() );
      CleanupStack::PopAndDestroy(smsCenter);
     }
    }

    CleanupStack::PopAndDestroy( settings );

    // Recipient number is displayed also as the recipient alias.
    entry.iDetails.Set( _L("+3725038xxx") );
    iSmsMtm->AddAddresseeL( _L("+3725038xxx") , entry.iDetails );

    // Validate message.
    if ( !ValidateL() )
    {  _LOGENTRY("Not valid");
     return ;
    }

    entry.SetVisible( ETrue ); // set message as visible
    entry.SetInPreparation( EFalse ); // set together with the visibility flag
    serverEntry.ChangeL( entry ); // commit changes 
    iSmsMtm->SaveMessageL(); // save message

    TMsvSelectionOrdering selection;
    CMsvEntry* parentEntry = CMsvEntry::NewL( iSmsMtm->Session(), KMsvDraftEntryId, selection );
    CleanupStack::PushL( parentEntry );

    // Move message to Outbox.
    iOperation =parentEntry->MoveL( entry.Id(), KMsvGlobalOutBoxIndexEntryId, iStatus );

    CleanupStack::PopAndDestroy( parentEntry );

    iState = EWaitingForMoving;
    SetActive();

Mostly I'm not sure about the correct values for port and class . Also some correct binary string would be nice to have for testing. Now I'm not sure if thecode is bad or the data.

+1  A: 

Use the JSR120 specification and the wireless toolkit. they contain java example code that will work for sure.

These are implemented directly using RSocket objects in Symbian C++.

If you really want to do it in C++, the simplest way is to copy your TMsvEntry to the entry of the sms service. In your code above, that means using "iSmsMtm->ServiceId()" instead of "KMsvGlobalOutBoxIndexEntryId". also, just copy the message to the service but do move it to the outbox after it has been successfully sent.

shameless plug : http://www.quickrecipesonsymbianos.com will contain an explanation of the Symbian C++ messaging API will simple and reusable example code.

QuickRecipesOnSymbianOS
Yes, I have to do it in C++ and I know that in Java it's just a small tweak to normal messaging.I know how to create normal SMS with messaging API or RSocket, I just fail in sending out the binary stuff.
Riho
Well, the binary messages go out, but they also arrive in the same way. What I expect is to see some message that is used to set Bookmark or something.
Riho
A: 

If you want to send the SMS silently (and avoid the complexity of using the messaging APIs), you should send it via an RSocket: http://wiki.forum.nokia.com/index.php/How_to_send_an_SMS_using_sockets

Depending on your needs this might be more suitable than using the messaging APIs.

KevinD
I don't care about the noise. I just want binary SMSs out.
Riho
A: 

The solution that worked is to use RComm and "DATAPORT::1" to send out the binary SMS using AT commands (like using a modem).

Riho