📄 mmi_common.c
字号:
/****************************************************************************
** File Name: mmk_app.c *
** Author: Great.Tian *
** Date: 17/12/2003 *
** Copyright: 2003 Spreatrum, Incoporated. All Rights Reserved. *
** Description: This file is used to describe the application modual. *
/****************************************************************************
** Important Edit History *
** ------------------------------------------------------------------------*
** DATE NAME DESCRIPTION *
** 12/2003 Great.Tian Create
**
****************************************************************************/
#define MMI_COMMON_C
/**---------------------------------------------------------------------------*
** Dependencies *
**---------------------------------------------------------------------------*/
#include "mmi_common.h"
#include "mmk_type.h"
/**---------------------------------------------------------------------------*
** Macro Declaration *
**---------------------------------------------------------------------------*/
#define STD_TRUE 1
#define YEAR_START 2000
#define MONTH_START 1
/**---------------------------------------------------------------------------*
** Constant Variables *
**---------------------------------------------------------------------------*/
const uint16 dayfrom2000year[51] =
{0,365+1,365*2+1,365*3+1,365*4+1,
365*5+2,365*6+2,365*7+2,365*8+2,
365*9+3,365*10+3,365*11+3,365*12+3,
365*13+4,365*14+4,365*15+4,365*16+4,
365*17+5,365*18+5,365*19+5,365*20+5,
365*21+6,365*22+6,365*23+6,365*24+6,
365*25+7,365*26+7,365*27+7,365*28+7,
365*29+8,365*30+8,365*31+8,365*32+8,
365*33+9,365*34+9,365*35+9,365*36+9,
365*37+10,365*38+10,365*39+10,365*40+10,
365*41+11,365*42+11,365*43+11,365*44+11,
365*45+12,365*46+12,365*47+12,365*48+12,
365*49+13,365*50+13};
const uint16 dayfromjan1[13] =
{0,31,59,90,120,151,181,212,243,273,304,334,365};
const uint16 dayfromjan1run[13] =
{0,31,60,91,121,152,182,213,244,274,305,335,366};
const uint16 dayofleapyear[13] =
{0,31,60,91,121,152,182,213,244,274,305,335,366};
//the table is for changing from 03.38 alphabet table to ASCII alphabet table
//add by sunsome.ju
const unsigned char default_to_ascii_table[128] =
{
0x40,0x20,0x24,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x5F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x21,0x22,0x23,0x20,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
0x20,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20,0x20,0x20,0x20,0x20,
0x20,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x20,0x20,0x20,0x20,0x20
};
const unsigned char default_to_ascii_extension_table[128] =
{
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x5e,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7B,0x7D,0x20,0x20,0x20,0x20,0x20,0x5c,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5B,0x7e,0x5D,0x20,
0x7c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20
};
//the table is for changing from ASCII alphabet table to 03.38 alphabet table
//add by sunsome.ju
const unsigned char ascii_to_default_table[128] =
{
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x21,0x22,0x23,0x02,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
0x00,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20,0x20,0x20,0x20,0x11,
0x20,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x20,0x20,0x20,0x20,0x20
};
/**---------------------------------------------------------------------------*
** Functions *
**---------------------------------------------------------------------------*/
/*****************************************************************************/
// Description : get the length of the bcd code
// Global resource dependence :
// Author: Great.Tian
// Note:
/*****************************************************************************/
void MMI_GetBcdLen(
uint8 bcdFmt, // BCD码的类型,目前有三种: PACKED_LSB_FIRST, PACKED_MSB_FIRST, UNPACKED
uint8 *pBcd, // BCD码的头指针
uint8 *pLen // 返回BCD码的长度
)
{
uint8 i;
uint8 bcdLen = 0;
/* BCD format is defined in applayer.h */
/* NOTE: LSB first 1234 = 0x21 0x43, bcdLen = 4 */
/* 123 = 0x21 0xf3, bcdLen = 3 */
/* MSB first 1234 = 0x12 0x34, bcdLen = 4 */
/* 123 = 0x12 0x3f, bcdLen = 3 */
/* unpacked 1234 = 0x01 0x02 0x03 0x04, bcdLen = 4 */
switch(bcdFmt)
{
case PACKED_LSB_FIRST:
bcdLen = 0;
for(i=0;STD_TRUE;i++)
{
if(((pBcd[i/2]>>(((i+1)&1)?0:4))&0x0f) == 0x0f)
{ /* NOTE: BCD is end by 0x0f */
break;
}
bcdLen ++;
}
bcdLen = i;
break;
case PACKED_MSB_FIRST:
bcdLen = 0;
for(i=0;STD_TRUE;i++)
{
if(((pBcd[i/2]>>((i&1)?0:4))&0x0f) == 0x0f)
{
break;
}
bcdLen ++;
}
bcdLen = i;
break;
case UNPACKED :
bcdLen = 0;
for(i=0;pBcd[i] != 0xff && pBcd[i] != 0x0f;i++) NULL;
bcdLen = i;
break;
default:
// DevFail("wrong bcd format");
break;
}
*pLen = bcdLen;
} /* End Of mmi_GetBcdLen() */
/*****************************************************************************/
// Description : convert the bcd code to string
// Global resource dependence :
// Author: Great.Tian
// Note:
/*****************************************************************************/
void MMI_BcdToStr(
uint8 bcdFmt, // BCD码的类型,目前有三种: PACKED_LSB_FIRST, PACKED_MSB_FIRST, UNPACKED
uint8 *pBcd, // BCD码的头指针
uint8 bcdLen, // BCD码的长度
char* str // 转换后String的头指针
)
{
/* BCD format is defined in applayer.h */
/* NOTE: LSB first 1234 = 0x21 0x43, bcdLen = 4 */
/* 123 = 0x21 0xf3, bcdLen = 3 */
/* MSB first 1234 = 0x12 0x34, bcdLen = 4 */
/* 123 = 0x12 0x3f, bcdLen = 3 */
/* unpacked 1234 = 0x01 0x02 0x03 0x04, bcdLen = 4 */
switch(bcdFmt)
{
case PACKED_LSB_FIRST:
MMI_BcdLfToStr(pBcd,bcdLen,str);
break;
case PACKED_MSB_FIRST:
MMI_BcdMfToStr(pBcd,bcdLen,str);
break;
case UNPACKED :
MMI_BcdUpToStr(pBcd,bcdLen,str);
break;
default:
// DevFail("wrong bcd format");
break;
}
} /* End Of mmi_BcdToStr() */
/*****************************************************************************/
// Description : convert the bcd code(PACKED_LSB_FIRST) to the string
// Global resource dependence :
// Author: Great.Tian
// Note:
/*****************************************************************************/
void MMI_BcdLfToStr(
uint8 *pBcd, // BCD码的头指针
uint8 bcdLen, // BCD码的长度
char* str // 转换后String的头指针
)
{ /*BCD format - LSB first (1234 = 0x21, 0x43)*/
uint8 i;
uint8 bcdCode;
uint8 ascCode;
for(i = 0;i < bcdLen; i++)
{
bcdCode = (pBcd[i/2] >> (((i+1) & 1) ? 0 : 4)) & 0x0F;
if(bcdCode == DIALBCD_FILLER)
{
break;
}
ascCode = (bcdCode == DIALBCD_STAR) ? '*':
(bcdCode == DIALBCD_HASH) ? '#':
(bcdCode == DIALBCD_PAUSE)? 'P':
(bcdCode == DIALBCD_WILD) ? 'w': (bcdCode + '0');
if(!((ascCode >= '0' && ascCode <= '9')||ascCode == '*'||
ascCode == '#'||(ascCode == 'P'||ascCode == 'p')||
ascCode == 'W'||ascCode == 'w'))
ascCode = 0;
str[i] = ascCode;
}
str[i] = 0;
} /*-- End of MMI_BcdLfToStr( ) --*/
/*****************************************************************************/
// Description : convert the bcd code(PACKED_MSB_FIRST) to the string
// Global resource dependence :
// Author: Great.Tian
// Note:
/*****************************************************************************/
void MMI_BcdMfToStr(
uint8 *pBcd, // BCD码的头指针
uint8 bcdLen, // BCD码的长度
char* str // 转换后String的头指针
)
{ /*BCD format - MSB first (1234 = 0x12 0x34)*/
uint8 i;
uint8 bcdCode;
uint8 ascCode;
for(i = 0;i < bcdLen; i++)
{
bcdCode = (pBcd[i/2] >> ((i & 1) ? 0 : 4)) & 0x0F;
if(bcdCode == 0x0f) break;
ascCode = (bcdCode == DIALBCD_STAR) ? '*':
(bcdCode == DIALBCD_HASH) ? '#':
(bcdCode == DIALBCD_PAUSE)? 'P':
(bcdCode == DIALBCD_WILD) ? 'w': (bcdCode + '0');
if(!((ascCode >= '0' && ascCode <= '9')||ascCode == '*'||
ascCode == '#'||(ascCode == 'P'||ascCode == 'p')||
ascCode == 'W'||ascCode == 'w'))
ascCode = 0;
str[i] = ascCode;
}
str[i] = 0;
} /*-- End of MMI_BcdMfToStr( ) --*/
/*****************************************************************************/
// Description : convert the bcd code(UNPACKED) to the string
// Global resource dependence :
// Author: Great.Tian
// Note:
/*****************************************************************************/
void MMI_BcdUpToStr(
uint8 *pBcd, // BCD码的头指针
uint8 bcdLen, // BCD码的长度
char *str // 转换后String的头指针
)
{ /*BCD format - unpacked (1 digit per byte)*/
uint8 i;
uint8 bcdCode;
uint8 ascCode;
for(i = 0;i < bcdLen; i++)
{
bcdCode = pBcd[i];
ascCode = (bcdCode == DIALBCD_STAR) ? '*':
(bcdCode == DIALBCD_HASH) ? '#':
(bcdCode == DIALBCD_PAUSE)? 'P':
(bcdCode == DIALBCD_WILD) ? 'w': (bcdCode + '0');
if(!((ascCode >= '0' && ascCode <= '9')||ascCode == '*'||
ascCode == '#'||(ascCode == 'P'||ascCode == 'p')||
ascCode == 'W'||ascCode == 'w'))
ascCode = 0;
str[i] = ascCode;
}
str[i] = 0;
} /*-- End of MMI_BcdUpToStr( ) --*/
/*****************************************************************************/
// Description : convert the string to the bcd code
// Global resource dependence :
// Author: Great.Tian
// Note:
/*****************************************************************************/
void MMI_StrToBcd(
uint8 bcdFmt, // BCD码的类型,目前有三种: PACKED_LSB_FIRST, PACKED_MSB_FIRST, UNPACKED
char *pStr, // String的头指针
uint8 *pBcd // 转换后BCD码的头指针
)
{
uint8 strLen;
strLen = strlen(pStr);
switch(bcdFmt)
{
case PACKED_LSB_FIRST:
MMI_StrToBcdLf(pStr,strLen,pBcd);
break;
case PACKED_MSB_FIRST:
MMI_StrToBcdMf(pStr,strLen,pBcd);
break;
case UNPACKED :
MMI_StrToBcdUp(pStr,strLen,pBcd);
break;
default:
// DevFail("Wrong bcd format");
break;
}
} /* End Of mmi_StrToBcd() */
/*****************************************************************************/
// Description : convert the string to the bcd code(PACKED_LSB_FIRST)
// Global resource dependence :
// Author: Great.Tian
// Note:
/*****************************************************************************/
void MMI_StrToBcdLf(
char *pStr, // String的头指针
uint8 strLen, // String的长度
uint8 *pBcd // 转换后BCD码的头指针
)
{
uint8 bcdCode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -