/*
 * AppFuncLib.c
 *
 *  Created on: 2022年1月21日
 *      Author: QiXiang_CHENJIE
 */

#include "AppFuncLib.h"
uint16 ATstrdel(char *str)
{
    char *p = str;
    bool flag = false;
    while (*str)
    {
        if (*str > 0x20)
        {
            *(p) = *str;
            p = p + 1;
            flag = false;
        }
        else
        {
            if (!flag)
            {
                *(p) = ',';
                p = p + 1;
                flag = true;
            }
        }
        str++;
    }
    *p = '\0';
    return 0;
}
uint16 mstrlen(const char *s)
{
    const char *ss = s;
    while (*ss)
        ss++;
    return (ss - s);
}
int mstrncmp(const char *s1, const char *s2, int n)
{
    const unsigned char *c1 = (const unsigned char *)s1;
    const unsigned char *c2 = (const unsigned char *)s2;
    unsigned char ch;
    int d = 0;
    while (n--)
    {
        d = (int)(ch = *c1++) - (int)*c2++;
        if (d || !ch)
            break;
    }
    return d;
}
unsigned char HexToChar(unsigned char bHex)
{
    if ((bHex >= 0) && (bHex <= 9))
        bHex += 0x30;
    else if ((bHex >= 10) && (bHex <= 15)) //大写字母
        bHex += 0x37;
    else
        bHex = 0xff;
    return bHex;
}
unsigned char CharToHex(unsigned char bChar)
{
    if ((bChar >= 0x30) && (bChar <= 0x39))
        bChar -= 0x30;
    else if ((bChar >= 0x41) && (bChar <= 0x46)) //大写字母
        bChar -= 0x37;
    else if ((bChar >= 0x61) && (bChar <= 0x66)) //小写字母
        bChar -= 0x57;
    else
        bChar = 0xff;
    return bChar;
}
