⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csmcodec.h

📁 一个通过串口连接手机发短信的程序。
💻 H
字号:
#ifndef _SMSCODEC_H_
#define _SMSCODEC_H_

#include "dxApi.h"
#include "Couse_typ.h"

//////-----------------------------------------------------------------------
#define GSM_CHARACTER_SET_SIZE          0x80
#define GSM_GREEK_CAPITAL_LETTER_DELTA  0x10
#define NON_GSM                         GSM_CHARACTER_SET_SIZE
#define UCS2_TO_GSM_LOOKUP_TABLE_SIZE   0x100
#define CHAR_TO_GSM_LOOKUP_TABLE_SIZE   0x80
#define UCS2_GREEK_CAPITAL_LETTER_GAMMA 0x0393
#define UCS2_GCL_RANGE                  22
#define MAX_LEN_UCS2_DEBUG_STRING       100
#define EXTENDED_ALPHABET_TABLE         0x1B
#define SPACE 							0x20



#define     SMS_MAX_ADDR_LEN            20
#define     TIMESTAMP_SIZE              14
#define     SMS_MAX_CMD_LEN             157
#define     SMS_MAX_MSG_LEN             160
#define     SMS_MAX_PDU_DATA_LEN        140

//****************************************************************************/

#define UPGRADE_SIM_APP_TOOLKIT
#define USE_ABSM2
#define UPGRADE_SAT97

typedef enum SmsStatusOfReportTag
{
   TRANSFER_OK                  =   0,
   TRANSFER_ERROR
}SmsStatusOfReport;

typedef enum SimatMeProblemAddInfoTag
{
    SIMAT_INFO_NO_CAUSE_GIVEN           = 0x00,
    SIMAT_INFO_SCREEN_BUSY              = 0x01,
    SIMAT_INFO_ME_BUSY_ON_CALL          = 0x02,
    SIMAT_INFO_ME_BUSY_ON_SS            = 0x03,
    SIMAT_INFO_NO_SERVICE               = 0x04,
    SIMAT_INFO_ACC_CONT_CLASS_BAR       = 0x05,
    SIMAT_INFO_RAD_RES_NOT_GRANTED      = 0x06,
#if defined (UPGRADE_SAT97)
    SIMAT_INFO_NOT_IN_SPEECH_CALL       = 0x07,
    SIMAT_INFO_ME_BUSY_ON_USSD          = 0x08
#else
    SIMAT_INFO_NOT_IN_SPEECH_CALL       = 0x07
#endif
}SimatMeProblemAddInfo;

typedef struct RpCauseElementTag
{
    GsmCause                        cause;
    Int8                            diagnostic;
}RpCauseElement;

typedef enum TypeOfNumberTag
{
   NUM_UNKNOWN                      =   0,
   NUM_INTERNATIONAL,
   NUM_NATIONAL,
   NUM_NETWORK_SPEC,
   NUM_SUBSCRIBER,
   NUM_ALPHANUMERIC,
   NUM_ABBREVIATED,
   NUM_RESERVED
}TypeOfNumber;

typedef enum NumberingPlanTag
{
   PLAN_UNKNOWN                     =   0,
   PLAN_ISDN                        =   1,
   PLAN_DATA                        =   3,
   PLAN_TELEX                       =   4,
   PLAN_NATIONAL                    =   8,
   PLAN_PRIVATE                     =   9,
   PLAN_ERMES                       =   10,
   PLAN_RESERVED                    =   15
}NumberingPlan;

typedef enum TpFailureCauseTag
{
   /*
   ** Protocol Id Errors
   */
   TP_TELEMATIC_NOT_SUPPORTED        =   0x80,
   TP_MSG_TYPE0_NOT_SUPPORTED,
   TP_CANT_REPLACE_SHORT_MSG,
   TP_UNSPECIFIED_TPPID_ERROR        =   0x8F,
   /*
   ** Data Coding Scheme Errors
   */
   TP_ALPHABET_NOT_SUPPORTED         =   0x90,
   TP_MSG_CLASS_NOT_SUPPORTED,
   TP_UNSPECIFIED_DATA_CODING_ERROR  =   0x9F,
   /*
   ** Command Errors
   */
   TP_CANT_ACTION_COMMAND            =   0xA0,
   TP_UNSUPPORTED_COMMAND,
   TP_UNSPECIFIED_COMMAND_ERROR      =   0xAF,
   /*
   ** Other Errors
   */
   TP_TPDU_NOT_SUPPORTED             =   0xB0,
   TP_SC_BUSY                        =   0xC0,
   TP_NO_SC_SUBSCRIPTION,
   TP_SC_SYSTEM_FAILURE,
   TP_INVALID_SME_ADDRESS,
   TP_DESTINATION_SME_BARRED,
   TP_SM_REJECTED_DUPLICATE_SM,
   TP_SIM_STORAGE_FULL               =   0xD0,
   TP_SIM_NO_SMS_CAPABILITY,
   TP_SIM_NO_CAPACITY                =   0xD1,   /* REDUNDANT Do not use */
   TP_ERROR_IN_MS,
   TP_MEMORY_CAPACITY_EXCEEDED,
   TP_SIM_APPLICATION_TOOLKIT_BUSY,
#if defined (UPGRADE_SAT97)
   TP_SIM_DATA_DOWNLOAD_ERROR,
#endif
   TP_UNSPECIFIED_ERROR              =   0xFF,
   TP_NO_ERROR                       =   0x100   /* internal code */
}TpFailureCause;

typedef Int8 SmsTimeStamp[TIMESTAMP_SIZE];

typedef struct SmsAddressTag
{
   Int8                             length;
   TypeOfNumber                     typeOfNumber;
   NumberingPlan                    numberingPlan;
   Int8                             addressValue[SMS_MAX_ADDR_LEN];
}SmsAddress;

typedef enum SmRequestStatusTag
{
  SM_REQ_OK,                 /* request successful */
  SM_REQ_SM_NOT_READY,       /* Short message procedure is not ready */
#if defined (USE_ABSM2)
  SM_REQ_SM_SEND_READY,
  SM_REQ_SM_SNDRCV_READY,
#endif
  SM_REQ_RECORD_NOT_FOUND,   /* requested record not found or invalid */
  SM_REQ_SIM_ERROR,          /* Sim has reported error */
  SM_REQ_PS_ERROR,           /* PS has reported error */
  SM_REQ_NO_MSG_ID,          /*  Out of message IDs */
  SM_REQ_INVALID_RECORD,     /* record number to delete or to send from SIM */
                             /* was not the start of a concatenated SMS     */
  SM_REQ_CONCAT_LINK_ERROR,  /* out of sequence when storing concat SMS to  */
                             /* SIM or space has already been allocated     */
  SM_REQ_NOT_SUBMIT_RECORD,  /* A record asked to be 'sent from SIM'        */
                             /* was not of 'submit' type                    */
  SM_REQ_SEND_FROM_SIM_IN_PROGRESS,   /* A sendFromSim request is already in progress */
                                      /* and we can't do another until it's finished  */
#if defined (USE_ABSM2)
  SM_REQ_RECORD_BUSY,        /* A transaction is already being performed on this record */
#endif

  SM_REQ_NRAM_ERROR,         /* ANRM has reported error */
  SM_REQ_INVALID_COMMAND,    /* Command too long etc 20460 */
  SM_REQ_FDN_FAILURE         /*job100892*/
}SmRequestStatus;

typedef enum SmsCommandTag
{
   SMS_CMD_ENQUIRY              =   0,
   SMS_CMD_CANCEL,
   SMS_CMD_DELETE,
   SMS_CMD_ENABLE_SRR
}
SmsCommand;

typedef enum SmsStatusTag
{
   ST_SM_RECEIVED_BY_SME        =   0,
   ST_SM_FORWARDED_TO_SME,
   ST_SM_REPLACED_BY_SC,

   ST_TA_CONGESTION             =   32,
   ST_TA_SME_BUSY,
   ST_TA_NO_RESPONSE,
   ST_TA_SERVICE_REJ,
   ST_TA_QUAL_SER_NAV,
   ST_TA_ERR_IN_SME,

   ST_P_REM_PROC_ERR            =   64,
   ST_P_INCOMPAT_DEST,
   ST_P_CONN_REJ_BY_SME,
   ST_P_NOT_OBTAINABLE,
   ST_P_QUAL_SER_NAV,
   ST_P_NO_IWORK_AV,
   ST_P_SM_VALIDITY_EXPIRED,
   ST_P_SM_DEL_BY_ORIG_SME,
   ST_P_SM_DEL_BY_SC_ADMIN,
   ST_P_SM_NOT_EXIST,

   ST_TI_CONGESTION             =   96,
   ST_TI_SME_BUSY,
   ST_TI_NO_RESPONSE,
   ST_TI_SERVICE_REJ,
   ST_TI_QUAL_SER_NAV,
   ST_TI_ERR_IN_SME,

   ST_ACK                       =   128,
   ST_NACK
}
SmsStatus;

typedef enum VpFormatTag
{
   VP_NOT_PRESENT               =   0,
   VP_RESERVED,
   VP_INTEGER_FORMAT,
   VP_SEMI_OCTET
}
VpFormat;

typedef enum ProtocolMeaningTag
{
   PM_SM_AL_PROTOCOL            = 0x00,
   PM_TELEMATIC_INTERWORK       = 0x20,
   PM_SM_FUNCTIONS              = 0x40,
   PM_ME_FUNCTIONS              = 0x60,
   PM_RESERVED                  = 0x80,
   PM_SC_SPECIFIC               = 0xc0,
   PM_RAW_DATA           /* Internal value */
}
ProtocolMeaning;


typedef enum MsgCodingTag
{
   MSG_CODING_DEFAULT           = 0x00,
   MSG_CODING_8BIT              = 0x01,
   MSG_CODING_UCS2              = 0x02,
   MSG_CODING_RESERVED          = 0x03,

   MSG_CODING_NUM_OF
}
MsgCoding;

typedef enum MsgClassTag
{
   MSG_CLASS0                   = 0x00,
   MSG_CLASS1                   = 0x01,
   MSG_CLASS2                   = 0x02,
   MSG_CLASS3                   = 0x03,
   MSG_CLASS_NOT_GIVEN,

   MSG_CLASS_NUM_OF
}
MsgClass;

typedef enum ProtInterWorkingTag
{
   PID_IMPLICIT                 =   0,
   PID_TELEX,
   PID_GRP3_FAX,
   PID_GRP4_FAX,
   PID_VOICE,
   PID_ERMES,
   PID_NAT_PAGING,
   PID_VIDEOTEX,
   PID_UNSPEC_TELETEX,
   PID_PSPDN_TELETEX,
   PID_CSPDN_TELETEX,
   PID_PSTN_TELETEX,
   PID_ISDN_TELETEX,
   PID_UCI,

   PID_MSG_HANDLING             =   16,
   PID_X400,
   PID_INTERNET_EMAIL,

   PID_SC_SPECIFIC_1            =   24,
   PID_SC_SPECIFIC_2,
   PID_SC_SPECIFIC_3,
   PID_SC_SPECIFIC_4,
   PID_SC_SPECIFIC_5,
   PID_SC_SPECIFIC_6,
   PID_SC_SPECIFIC_7,
   PID_GSM_MS
}
ProtInterWorking;

typedef enum ProtScCommandTag
{
   PID_SM_TYPE0                 =   0,
   PID_REPLACE_SM_TYPE1,
   PID_REPLACE_SM_TYPE2,
   PID_REPLACE_SM_TYPE3,
   PID_REPLACE_SM_TYPE4,
   PID_REPLACE_SM_TYPE5,
   PID_REPLACE_SM_TYPE6,
   PID_REPLACE_SM_TYPE7,

   PID_RETURN_CALL_MSG          = 0x1F
}
ProtScCommand;

/* Required for case when PID byte has bit7 = 0 and bit6=1 (see GSM 03.40) */
typedef enum ProtMeCommandTag
{
   PID_DEPERSONALISATION_SM     = 0x00,//0x3E,
   PID_SIM_DATA_DOWNLOAD
}
ProtMeCommand;

typedef union ProtocolIdTag
{
   /* meaning = PM_SM_AL_PROTOCOL */
   ProtInterWorking                 protSmAlProtocol;
   /* meaning = PM_TELEMATIC_INTERWORK */
   ProtInterWorking                 protInterWorking;
   /* meaning = PM_SM_FUNCTIONS */
   ProtScCommand                    protScCommand;
   /* meaning = PM_ME_FUNCTIONS */
   ProtMeCommand                    protMeCommand;
   /* meaning = PM_RESERVED */
   Int8                             protReserved;
   /* meaning = PM_SC_SPECIFIC */
   Int8                             protScSpecific;
   /* raw data format */
   Int8                             data;
}
ProtocolId;

typedef struct SmsProtocolIdTag
{
   ProtocolMeaning                  protocolMeaning;
   ProtocolId                       protocolId;
}
SmsProtocolId;

typedef enum SmsIndTypeTag
{
    SMS_IND_VOICE_MESSAGE_WAITING  = 0x00,
    SMS_IND_FAX_MESSAGE_WAITING    = 0x01,
    SMS_IND_EMAIL_MESSAGE_WAITING  = 0x02,
    SMS_IND_OTHER_MESSAGE_WAITING  = 0x03,
    SMS_IND_NUM_OF_INDS

} SmsIndType;

typedef struct SmsMsgWaitingIndTag
{
    Boolean                         storeMessage;
    Boolean                         indActive;
    SmsIndType                      indType;

} SmsMsgWaitingInd;

typedef struct SmsDataCodingTag
{
   MsgCoding                        msgCoding;
   MsgClass                         msgClass;
   Boolean                          compressedText;
   Boolean                          msgWaitingIndPresent;
   SmsMsgWaitingInd                 msgWaitingInd;
}
SmsDataCoding;
typedef enum AlphaIdCodingSchemeTag
{
  OCTET_ALIGNED_GSM_7BIT,
  DOUBLE_OCTET_UCS2 = 0x80,
  SINGLE_OCTET_BASE_POINTER_COMBINED,
  DOUBLE_OCTET_BASE_POINTER_COMBINED
} AlphaIdCodingScheme;

typedef enum GsmCharTypeTag
{
  NON_GSM7BIT      	= 0,
  GSM7BIT	    	= 1,
  EXTENDED_GSM7BIT	= 2
}GsmCharType;


//----------------------------------------------------------------
	//----------------------------------------------------
	BOOL IsChinUnicode (Int16 uniCharCode);
	Int16 afsmSmsDataToUcs2 ( Int16      *usc2String_p,
                    Int16      maxLenUcs2,
                    const Int8 *smsData,
                    Int16      lenSmsData,
                    MsgCoding  msgCoding );

	Int16 afsmUcs2ToSmsData ( Int8        *smsData,
                    Int16       maxLenSms,
                    MsgCoding   *msgCoding_p,
                    const Int16 *ucs2String,
                    Int16       lenUcs2,
                    Int16       *numConverted_p );

	GsmCharType utSmsUcs2ToByteAlignedEGsm7Bit ( const Int16 *ucs2Str_p, Int16 ucs2Length, Int8 *gsmStr_p,
                                 Int16 *gsmLength_p, Int16 maxGsmLength, Boolean *gsmBufferTooSmall_p, Int16 *numConverted_p);
	Char * utUcs2StringToDebug ( const Int16 * strUcs2_p );
	Int16 utLengthAlphaIdToUcs2( const Int8 *alphaId,
                       Int16 alphaIdLen );
	Int16 utUcs2ToAlphaId ( Int8        *alphaId_p,
                  Int16       maxAlphaIdLen,
                  const Int16 *strSrc_p,
                  Int16       srcLen );

	Int16 utAlphaIdToUcs2 ( Int16      *strDst_p,
                  Int16      maxDstLen,
                  const Int8 *alphaId,
                  Int16      alphaIdLen );

	GsmCharType utIsUcs2StringAllEGsm(const Int16 *ucs2Str_p, Int16 ucs2Length);
	GsmCharType utUcs2ToByteAlignedEGsm7Bit(const Int16 *ucs2Str_p,
                            Int16 ucs2Length,
                            Int8 *gsmStr_p,
                            Int16 *gsmLength_p,
                            Int16 maxGsmLength,
                            Boolean *gsmBufferTooSmall_p);


	Int16 utUcs2ToChar ( Char * charStr,
               const Int16 *ucs2String,
               Int16 length);

	GsmCharType utByteAlignedEGsm7BitToUcs2(const Int8 *gsmStr_p,
                            Int16 gsmDataLength,
                            Int16 *ucs2Str_p,
                            Int16 *ucs2Length_p,
                            Int16 maxUcs2Len,
                            Boolean *ucs2BufferTooSmall_p);

	GsmCharType utSmsByteAlignedEGsm7BitToUcs2(const Int8 *gsmStr_p,
                               Int16 gsmDataLength,
                               Int16 *ucs2Str_p,
                               Int16 *ucs2Length_p,
                               Int16 maxUcs2Len,
                               Boolean *ucs2BufferTooSmall_p,
                               Int16 *numConverted_p);

	Int16 utByteAlignedGsm7BitToChar ( Char *charString,
                             const Int8 * gsmData,
                             Int16 length);

	void utDoubleOctetToUcs2 ( Int16      *ucs2String,
                      const Int8 *srcData_p,
                      Int16      length);

	void utUcs2ToDoubleOctet ( Int8        *dst_p,
                      const Int16 *ucs2String,
                      Int16       length);
	GsmCharType utGetEGsmLengthOfUcs2(const Int16 *ucs2Str_p, Int16 ucs2Length, Int16 *gsmLength_p);
	GsmCharType mapEGsmToUcs2(Int8 gsm1, Int8 gsm2, Int16 *ucs2_p);
	GsmCharType mapUcs2ToEGsm(Int16 ucs2, Int8 *gsm1_p, Int8 *gsm2_p);
	Char mapUcs2ToChar ( Int16 ucs2Char );
	Char mapGsmToChar ( Int8 gsmChar );
//-----------------------------------------------------------------
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -