解释下面代码static UINT8 libTXT2PDU( UINT8* msgData, UINT16 msgLen, UINT8* pTpdu, AtciMsgInfo *pAtSmsMessage, AtciCharacterSet chset_type ) { UINT8 offset = 0; UINT16 len=0; //CPUartLogPrintf("%s: enter", __FUNCTION__); //int i; //for(i=0;i<msgLen;i++) //CPUartLogPrintf("%s: msgData[%d] %d 0x%x", __FUNCTION__, i, msgData[i], msgData[i]); /* Copy the first octet */ /*SIMCom xiaokai.yang sync sms code @2023-02-06 begin*/ #ifdef FEATURE_SIMCOM_SMS char headbuf[PDU_HEAD_SIZE] = {0x05,0x00,0x03}; scCmssexInfoT* p_CmgsexInfo = (scCmssexInfoT*)getCmgsexInfoInd(); if(pAtSmsMessage->udhPresent) { pTpdu[ offset++ ] = (pAtSmsMessage->fo)|(0x1<<6); } else #endif /*SIMCom xiaokai.yang sync sms code @2023-02-06 end*/ pTpdu[ offset++ ] = pAtSmsMessage->fo; /* Message Reference */ pTpdu[ offset++ ] = pAtSmsMessage->msgRef; /* Originating Address (TP-OA) */ { UINT8 idx; UINT8 *data; data = pTpdu + offset; /* Set the Address Length octet */ *data++ = strlen( (char *)pAtSmsMessage->destAddr ); #ifdef FEATURE_SIMCOM_SMS PAL_LogIo(SC_MODULE_SMS,PAL_DBG_LEVEL_INFO,"destAddr [%s]",( (char *)pAtSmsMessage->destAddr )); #endif /* Format the TON/NPI octet */ *data++ = (UINT8)((pAtSmsMessage->addrType << 4) | pAtSmsMessage->addrPlan | 0x80); /* Format the BCD digits */ for ( idx = 0; idx < strlen( (char *)pAtSmsMessage->destAddr ); idx++ ) { libPutPackedBcd( data, idx, pAtSmsMessage->destAddr[ idx ], TRUE ); } /* check if we need to tack on a filler */ if( idx & 0x01 ) { /* Yup -- do it! , reversed nibbles */ libPutPackedBcd( data, idx, ATCI_BCD_FILLER, TRUE ); ++idx; } /* We're done -- update the PDU byte index */ offset += idx/2 + ATCI_SMS_BCD_POS; } /* Protocol Identifier (TP-PID) */ pTpdu[ offset++ ] = pAtSmsMessage->pid; /* Data Coding Scheme (TP-DCS) */ pTpdu[ offset++ ] = pAtSmsMessage->dcs; if(((pAtSmsMessage->fo&ATCI_TP_MTI_MASK)==ATCI_SMS_SUBMIT_MTI)&&((pAtSmsMessage->fo&ATCI_SMS_TP_VPF)==0x10)) { pTpdu[ offset++ ] = pAtSmsMessage->vp; } /*SIMCom xiaokai.yang sync sms code @2023-02-06 begin*/ #ifdef FEATURE_SIMCOM_SMS if(pAtSmsMessage->udhPresent) { headbuf[3] = p_CmgsexInfo->mr; headbuf[4] = p_CmgsexInfo->msg_total; headbuf[5] = p_CmgsexInfo->msg_seg; memmove(msgData+PDU_HEAD_SIZE,msgData,msgLen); memcpy(msgData, headbuf, PDU_HEAD_SIZE); msgLen+=PDU_HEAD_SIZE; } PAL_LogIo(SC_MODULE_SMS,PAL_DBG_LEVEL_INFO,"offset1 [%d],msgLen=%d",offset,msgLen);//274 #endif /*SIMCom xiaokai.yang sync sms code @2023-02-06 end*/ /* Now for the Message Data (TP-UDL + TP-UD) */ //ScShowDataByHex((char *)pTpdu, offset); //CPUartLogPrintf("[sms]msgLen=%d",msgLen); libMsgEncodeUserData( pAtSmsMessage->udhPresent, pAtSmsMessage->dcs, pTpdu, msgData, msgLen, offset, &len,chset_type); return len; }
时间: 2024-04-22 10:28:35 浏览: 171
这段代码是一个函数,名为libTXT2PDU,其作用是将短信数据从文本格式转化为PDU格式。它的参数包括短信数据的指针msgData、短信数据长度msgLen、PDU数据的指针pTpdu、AtciMsgInfo结构体指针pAtSmsMessage和字符集类型chset_type。函数内部定义了一个偏移量变量offset和一个长度变量len,并且初始化为0。接下来通过判断宏定义FEATURE_SIMCOM_SMS是否被定义,如果被定义则会执行一些与SIM卡相关的代码。然后根据短信数据的格式对PDU数据进行逐个赋值,包括格式、消息参考、源地址、协议标识、数据编码方式等。最后通过调用libMsgEncodeUserData函数对短信数据进行编码,并返回编码后的长度。
阅读全文