Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Sending a Message

Objective

This topic shows how to send an SMS message.

Requirements

To send a SMS message, an application needs to:

  1. Create an ISMS object.
  2. Create an ISMSMSG object.
  3. Get the device payload encoding information.
  4. Get the MO SMS device information.
  5. Construct the message.
  6. Send the message.
  7. In the callback function, verify the message was sent.

Example

Create the ISMS object:

 if (SUCCESS != ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_SMS,  
                        (void **)&pMe->m_pISMS)) {  
    /* Handle error */  
 }

Create the ISMSMSG object:

 if (SUCCESS != ISHELL_CreateInstance(pMe->m_pIShell,AEECLSID_SMSMSG,   
                       (void **)&pMe->m_pISMSMsg)) {  
    /* Handle ISMSMsg error */  
 }

Determine the payload encoding supported by the device:

 if (SUCCESS == ISHELL_GetDeviceInfoEx(pMe->m_pIShell, AEE_DEVICEITEM_TAPI_SMS_ENCODING,   
              NULL, (int*)&nSize)) {  
    if ( NULL != (pMe->m_pPlEncodings = (uint32 *)MALLOC(nSize)) ) {  
       ISHELL_GetDeviceInfoEx(pMe->m_pIShell, AEE_DEVICEITEM_TAPI_SMS_ENCODING,  
                              pMe->m_pPlEncodings, (int*)&nSize);  
       // Assume the function call returns SUCCESS,  
       // Set the first value as the payload encoding value  
       pMe->m_payloadEncoding = (*pMe->m_pPlEncodings);  
    }  
}   
else {  
   // Handle error  
}

Determine the MO SMS encoding supported by the device:

 if (SUCCESS == ISMS_GetEncodingsAvailableForMOSMS(pMe->m_pISMS, NULL,   
                        (uint32*) &nSize)) {  
    if ( NULL != (pMe->m_pMOEncodings = (int *)MALLOC(nSize)) ) {  
       ISMS_GetEncodingsAvailableForMOSMS(pMe->m_pISMS, pMe->m_pMOEncodings,  
                        (uint32*) &nSize);  
       // Assume the function call returns SUCCESS  
       // Set the first value as the encoding value  
       pMe->m_moEncoding = *(pMe->m_pMOEncodings);  
    }  
 }  
 else {  
   // handle error  
}

Construct the message:

 SMSMsgOpt smo[2];  
  
 smo[1].nId = MSGOPT_END;  
 smo[1].pVal = NULL;  
  
 smo[0].nId = MSGOPT_PAYLOAD_ENCODING;  
 smo[0].pVal = (void *)pMe->m_payloadEncoding;  
 ISMSMSG_AddOpt(pMe->m_pISMSMsg,smo);  
  
 smo[0].nId = MSGOPT_MOSMS_ENCODING;  
 smo[0].pVal = (void *)pMe->m_moEncoding;  
 ISMSMSG_AddOpt(pMe->m_pISMSMsg,smo);

See the Brew MP API Reference for other message parameters and options. You can find a complete list of ISMSMSG message options in AEESMS.h.

To send the message, the application must register the callback function, then call ISMS_SendMsg.

 CALLBACK_Cancel(&pMe->m_callback);  
 CALLBACK_Init(&pMe->m_callback, (PFNNOTIFY)SendSMSCB, pMe);  
  
 ISMS_SendMsg(pMe->m_pISMS, pMe->m_pISMSMsg,&pMe->m_callback,&pMe->m_retVal);

In the callback function you can find that the message was sent successfully and check for errors.

 uint16 errType = AEESMS_GETERRORTYPE(pMe->m_retVal);  
 uint16 err = AEESMS_GETERROR(pMe->m_retVal);  
   
 switch (err){  
    case AEESMS_ERROR_NONE:  
       // Insert code to handle successful sending  
       break;  
    case AEESMS_ERROR_XXX:  
       // Insert code to handle error XXX  
       break;  
  
    // Handle other errors   
}

The list of possible errors can be found in AEESMS.h.