📄 mmiutil.c
字号:
#define MMIUTIL_C
#include "mmiutil.h"
#include "mmi_osbridge.h"
/*-------------------------------------------------------------------------*/
/* TYPES/CONSTANTS */
/*-------------------------------------------------------------------------*/
#define STD_TRUE 1
/*-------------------------------------------------------------------------*/
/* FUNCTIONS */
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/* VARIABLES */
/*-------------------------------------------------------------------------*/
/****************************************************************************/
/* Function : mmi_GetBcdLen( ) */
/*--------------------------------------------------------------------------*/
/* Scope : Get bcd number length. */
/* Return : none */
/* Interface : */
/*--------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Use */
/*--------------------+---+---+---+-----------------------------------------*/
/* bcdFmt | * | | | bcd code format. */
/*--------------------+---+---+---+-----------------------------------------*/
/* pBcd | * | | | the pointer of bcd code. */
/*--------------------+---+---+---+-----------------------------------------*/
/* pLen | | * | | bcd code length. */
/*--------------------+---+---+---+-----------------------------------------*/
/****************************************************************************/
void
mmi_GetBcdLen(uint8 bcdFmt,uint8 *pBcd,uint8 *pLen)
{
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() */
/****************************************************************************/
/* Function : mmi_BcdToStr( ) */
/*--------------------------------------------------------------------------*/
/* Scope : Convert bcd code to ascii code. */
/* Return : none */
/* Interface : */
/*--------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Use */
/*--------------------+---+---+---+-----------------------------------------*/
/* bcdFmt | * | | | bcd code format. */
/*--------------------+---+---+---+-----------------------------------------*/
/* pBcd | * | | | the pointer of bcd code. */
/*--------------------+---+---+---+-----------------------------------------*/
/* bcdLen | * | | | bcd code length. */
/*--------------------+---+---+---+-----------------------------------------*/
/* str | | * | | the pointer of output string. */
/*--------------------+---+---+---+-----------------------------------------*/
/****************************************************************************/
void
mmi_BcdToStr(uint8 bcdFmt,uint8 *pBcd,uint8 bcdLen,char *str)
{
/* 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() */
/****************************************************************************/
/* Function : mmi_BcdLfToStr( ) */
/*--------------------------------------------------------------------------*/
/* Scope : Convert LSB format bcd code to ascii code. */
/* Return : none */
/* Interface : */
/*--------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Use */
/*--------------------+---+---+---+-----------------------------------------*/
/* pBcd | * | | | the pointer of bcd code. */
/*--------------------+---+---+---+-----------------------------------------*/
/* bcdLen | * | | | bcd code length. */
/*--------------------+---+---+---+-----------------------------------------*/
/* str | | * | | the pointer of output string. */
/*--------------------+---+---+---+-----------------------------------------*/
/****************************************************************************/
void
mmi_BcdLfToStr(uint8 *pBcd,uint8 bcdLen,char *str)
{ /*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( ) --*/
/****************************************************************************/
/* Function : mmi_BcdMfToStr( ) */
/*--------------------------------------------------------------------------*/
/* Scope : Convert MSB format bcd code to ascii code. */
/* Return : none */
/* Interface : */
/*--------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Use */
/*--------------------+---+---+---+-----------------------------------------*/
/* pBcd | * | | | the pointer of bcd code. */
/*--------------------+---+---+---+-----------------------------------------*/
/* bcdLen | * | | | bcd code length. */
/*--------------------+---+---+---+-----------------------------------------*/
/* str | | * | | the pointer of output string. */
/*--------------------+---+---+---+-----------------------------------------*/
/****************************************************************************/
void
mmi_BcdMfToStr(uint8 *pBcd,uint8 bcdLen,char *str)
{ /*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( ) --*/
/****************************************************************************/
/* Function : mmi_BcdUpToStr( ) */
/*--------------------------------------------------------------------------*/
/* Scope : Convert unpacked format bcd code to ascii code. */
/* Return : none */
/* Interface : */
/*--------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Use */
/*--------------------+---+---+---+-----------------------------------------*/
/* pBcd | * | | | the pointer of bcd code. */
/*--------------------+---+---+---+-----------------------------------------*/
/* bcdLen | * | | | bcd code length. */
/*--------------------+---+---+---+-----------------------------------------*/
/* str | | * | | the pointer of output string. */
/*--------------------+---+---+---+-----------------------------------------*/
/****************************************************************************/
void
mmi_BcdUpToStr(uint8 *pBcd,uint8 bcdLen,char *str)
{ /*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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -