代码拉取完成,页面将自动刷新
同步操作将从 vtor3478/vtor_elec_module 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "vtor_string.h"
#ifdef __VTOR_STRING__
#ifdef __VTOR_STRING_CONFIG_PRINT_RESERVE__
uint16_t VtorString_Print(int8_t* str)
{
}
#endif // __VTOR_STRING_CONFIG_PRINT_RESERVE__
void VtorString_AppendChar(int8_t* str, char ch)
{
uint16_t len = VtorString_Length(str);
str[len++] = ch;
if(len > (128-2))
{
len=0;//接收数据即将溢出,重新开始接收
}
str[len] = '\0'; // 清空下一字符,方便计算字符串长度
if(len > 2) //已经可以实现长度校验时,进行校验
{
if(str[len - 2] == 0x0d && str[len - 1] == 0x0a)
{
str[len - 2] = '\0';
// 启动回调函数设置标志位,主程序中处理字符串
VtorString_AppendCharCpltCallback(str);
//VtorTimer_Start(VtorShell_Task, 0);
}
}
}
void VtorString_AppendFloat(int8_t* str, float num)
{
int d = 6;
// 整数部分按int方法
while (*str)
{
str++;
}
if (num < 0)
{
num = -num;
*str++ = '-';
}
VtorString_AppendInt(str, (int32_t)num);
float fractionNum = num - (int32_t)num; // 小数
while (*str)
{
str++;
}
*str++ = '.';
while (d--)
{
fractionNum *= 10;
*str++ = (int32_t)fractionNum % 10 + '0';
}
*str++ = '\0';
}
void VtorString_AppendInt(int8_t* str, int32_t num)
{
while (*str)
{
str++;
}
if (num < 0)
{
*str++ = '-';
num = -num;
}
if (0 == num)
{
*str++ = '0';
*str++ = '\0';
return;
}
int8_t* startStr = str;
while (num)
{
int singleNum = num % 10;
*str++ = singleNum + '0';
num /= 10;
}
*str = '\0';
str--;
while (startStr < str)
{
int8_t ch = *str;
*str = *startStr;
*startStr = ch;
startStr++;
str--;
}
}
void VtorString_AppendHex(int8_t* str, int32_t num)
{
while (*str)
{
str++;
}
*str++ = '0';
*str++ = 'x';
if (0 == num)
{
*str++ = '0';
*str++ = '\0';
return;
}
int8_t* startStr = str;
while (num)
{
int singleNum = num & 0x0f;
int8_t singleNumChar
= (singleNum < 10)
? (singleNum + '0')
: (singleNum + 'a' - 10);
*str++ = singleNumChar;
num >>= 4;
}
*str = '\0';
str--;
while (startStr < str)
{
int8_t ch = *str;
*str = *startStr;
*startStr = ch;
startStr++;
str--;
}
}
void VtorString_AppendMemory(int8_t* str, void* mem, int16_t cnt, int8_t width)
{
int8_t* byteMem = (int8_t*)mem;
#ifdef __VTOR_STRING_CONFIG_LITTLE_ENDIAN__
byteMem += width;
#endif
while (*str)
{
str++;
}
while(cnt--)
{
int i;
*str++ = '0';
*str++ = 'x';
for(i = 0; i < width; i++)
{
#ifdef __VTOR_STRING_CONFIG_LITTLE_ENDIAN__
uint8_t byteValue = *--byteMem;
#else
uint8_t byteValue = *byteMem++;
#endif
*str++ = (byteValue >> 4) < 10
? ((byteValue >> 4) + '0')
: ((byteValue >> 4) - 10 + 'a');
*str++ = (byteValue & 0x0f) < 10
? ((byteValue & 0x0f) + '0')
: ((byteValue & 0x0f) - 10 + 'a');
}
#ifdef __VTOR_STRING_CONFIG_LITTLE_ENDIAN__
byteMem += (width << 1);
#endif
*str++ = ' ';
}
*(str - 1) = '\0';
}
int8_t VtorString_GetDataType(int8_t* str)
{
int8_t dataType = DATA_TYPE_VOID;
while (*str)
{
if ('\'' == *str)
{
dataType = DATA_TYPE_CHAR;
break;
}
if ('"' == *str)
{
dataType = DATA_TYPE_STRING;
break;
}
if ('0' == *str
&&('x' == *(str + 1) || ('X' == *(str + 1))))
{
dataType = DATA_TYPE_INT;
break;
}
if ('0' <= *str && *str <= '9')
{
dataType = DATA_TYPE_INT;
}
if (dataType == DATA_TYPE_INT)
{
if ('.' == *str)
{
dataType = DATA_TYPE_FLOAT;
break;
}
// 整形数据结束了,认为是整形属性
if (*str < '0' || '9' < *str)
{
break;
}
}
str++;
}
return dataType;
}
void VtorString_AppendString(int8_t* str, const int8_t* str2)
{
while (*str)
{
str++;
}
while (*str2)
{
*str++ = *str2++;
}
*str++ = '\0';
}
int8_t VtorString_CmpString(const int8_t* str1, const int8_t* str2)
{
while (*str1 && *str2)
{
if (*str1 > *str2)
return 1;
else if (*str1 < *str2)
return -1;
str1++;
str2++;
}
return 0;
}
int8_t* VtorString_FindFloat(int8_t* str, float* num)
{
int32_t signBit = 1;
int32_t base = 10;
int32_t wholeNum = 0; // 整数
float fractionNum = 0.0f; // 小数
float fractionNumFactor = 1.0f;
// 找到第一个有效数字0~9,或者+-
while (*str)
{
if ('0' <= *str && *str <= '9')
{
break;
}
if (*str == '-')
{
signBit = -1;
str++;
break;
}
str++;
}
// 找出整数部分(十进制)
while (1)
{
int singleNum = 0;
if ('0' <= *str && *str <= '9')
{
singleNum = *str - '0';
}
else
{
break;
}
wholeNum *= base;
wholeNum += singleNum;
str++;
}
// 如果有小数点,挑出小数部分
if ('.' == *str)
{
str++;
while (1)
{
int singleNum = 0;
if ('0' <= *str && *str <= '9')
{
singleNum = *str - '0';
}
else
{
break;
}
fractionNumFactor *= base;
fractionNum *= base;
fractionNum += singleNum;
str++;
}
fractionNum /= fractionNumFactor;
}
*num = wholeNum + fractionNum;
*num *= signBit;
return str;
}
int8_t* VtorString_FindInt(int8_t* str, int32_t* num)
{
int32_t signBit = 1;
int32_t base = 10;
*num = 0;
// 找到第一个有效数字0~9,或者+-
while(*str)
{
if('0' <= *str && *str <= '9')
{
break;
}
if(*str == '-')
{
signBit = -1;
str++;
break;
}
str++;
}
if('0' == *str && ('x' == *(str+1) || 'X' == *(str+1)))
{
base = 16;
str += 2;
}
while(1)
{
int singleNum = 0;
if(10 == base)
{
if('0' <= *str && *str <= '9')
{
singleNum = *str - '0';
}
else
{
break;
}
}
if(16 == base)
{
if('0' <= *str && *str <= '9')
{
singleNum = *str - '0';
}
else if('a' <= *str && *str <= 'f')
{
singleNum = *str - 'a' + 10;
}
else if('A' <= *str && *str <= 'F')
{
singleNum = *str - 'A' + 10;
}
else
{
break;
}
}
*num *= base;
*num += singleNum;
str++;
}
*num *= signBit;
return str;
}
void VtorString_Clear(int8_t* str)
{
*str = '\0';
}
int32_t VtorString_Length(const int8_t* str)
{
const int8_t *ptr=str;
while(*str++!='\0');
return str-ptr-1;
}
// 预处理,截断注释
int8_t* VtorString_Preprocess(int8_t* str)
{
while(*str)
{
if('/' == *str
&& '/' == *(str+1))
{
*str = '\0';
break;
}
str++;
}
return str;
}
int8_t* VtorString_FindString(int8_t* str, int8_t* dstStr)
{
uint16_t pos;
while (*str)
{
if (*str != *dstStr)
{
str++;
continue;
}
for (pos = 0; *(dstStr + pos); pos++)
{
if (*(str + pos) != *(dstStr + pos))
{
break;
}
}
if ('\0' == *(dstStr + pos))
{
break;
}
str++;
}
return str;
}
#endif // __VTOR_STRING__
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。