397 lines
14 KiB
C
397 lines
14 KiB
C
|
#include "syslib.h"
|
|||
|
#include <string.h>
|
|||
|
#include "usart.h"
|
|||
|
#include "sysport.h"
|
|||
|
|
|||
|
/********************************************************************************
|
|||
|
* @file syslib.c
|
|||
|
* @author <EFBFBD>̳ϿƼ<EFBFBD> Mr.Wang
|
|||
|
* @version V1.0.0
|
|||
|
* @date 11-Dec-2018
|
|||
|
* @brief <EFBFBD>ṩ<EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩ֡<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
******************************************************************************
|
|||
|
*******************************************************************************/
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>void InitQueueMem(FrameQueue_s* sFrame)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *sFrame FrameQueue_s<EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*************************************************************************************************/
|
|||
|
void InitQueueMem(FrameQueue_s* sFrame)
|
|||
|
{
|
|||
|
sFrame->getIndex = 0;
|
|||
|
sFrame->insertIndex = 0;
|
|||
|
sFrame->hasDataLen = 0;
|
|||
|
memset(sFrame->dataBuf, 0 , MAX_QUEUE_LEN) ;
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>uint8_t InsertQueueMemData(FrameQueue_s *sFrame, char *data, uint16_t len)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HEAD1<EFBFBD><EFBFBD>HEAD2Ϊ֡ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>TAIL1<EFBFBD><EFBFBD>TAIL2Ϊ֡β
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *sFrame FrameQueue_s<EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* @param2 *data <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* @param3 len <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FULL_ERROR/RW_OK
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*************************************************************************************************/
|
|||
|
uint8_t InsertQueueMemData(FrameQueue_s *sFrame, char *data, uint16_t len) //<2F><><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>0x1234,0x5678 4<><34><EFBFBD>ֽڷֱ<DAB7><D6B1><EFBFBD>Ϊ֡ͷ<D6A1><CDB7>֡β д<>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
if((sFrame->hasDataLen+len+4) >= MAX_QUEUE_LEN ) /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ռ䲻<D5BC><E4B2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>4<EFBFBD>ֽ<EFBFBD>֡ͷ֡β*/
|
|||
|
{
|
|||
|
return FULL_ERROR;
|
|||
|
}
|
|||
|
else /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ռ乻<D5BC><E4B9BB><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>֡*/
|
|||
|
{
|
|||
|
sFrame->dataBuf[sFrame->insertIndex] = HEAD1 ; //<2F><><EFBFBD><EFBFBD>֡ͷ<D6A1><CDB7>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>HEAD1
|
|||
|
sFrame->insertIndex = (sFrame->insertIndex+1) % MAX_QUEUE_LEN; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬ʵ<E4A3AC><CAB5><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>д<EFBFBD>룬һ<EBA3AC><D2BB>ָ<EFBFBD>뵽MAX_QUEUE_LENλ<4E>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ִ<EFBFBD>0<EFBFBD><30>ʼд<CABC>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
|||
|
sFrame->dataBuf[sFrame->insertIndex] = HEAD2 ; //<2F><><EFBFBD><EFBFBD>֡ͷ<D6A1>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>ֽ<EFBFBD>HEAD2
|
|||
|
sFrame->insertIndex = (sFrame->insertIndex+1) % MAX_QUEUE_LEN; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬ʵ<E4A3AC><CAB5><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>д<EFBFBD>룬һ<EBA3AC><D2BB>ָ<EFBFBD>뵽MAX_QUEUE_LENλ<4E>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ִ<EFBFBD>0<EFBFBD><30>ʼд<CABC>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
for(int n=0; n<len; n++ ) //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
sFrame->dataBuf[sFrame->insertIndex] = *(data++) ;
|
|||
|
sFrame->insertIndex = (sFrame->insertIndex+1) % MAX_QUEUE_LEN; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬ʵ<E4A3AC><CAB5><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>д<EFBFBD>룬һ<EBA3AC><D2BB>ָ<EFBFBD>뵽MAX_QUEUE_LENλ<4E>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ִ<EFBFBD>0<EFBFBD><30>ʼд<CABC>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
sFrame->dataBuf[sFrame->insertIndex] = TAIL1 ; //<2F><><EFBFBD><EFBFBD>֡βTAIL1
|
|||
|
sFrame->insertIndex = (sFrame->insertIndex+1) % MAX_QUEUE_LEN; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬ʵ<E4A3AC><CAB5><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>д<EFBFBD>룬һ<EBA3AC><D2BB>ָ<EFBFBD>뵽MAX_QUEUE_LENλ<4E>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ִ<EFBFBD>0<EFBFBD><30>ʼд<CABC>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
|||
|
sFrame->dataBuf[sFrame->insertIndex] = TAIL2 ; //<2F><><EFBFBD><EFBFBD>֡βTAIL2
|
|||
|
sFrame->insertIndex = (sFrame->insertIndex+1) % MAX_QUEUE_LEN; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬ʵ<E4A3AC><CAB5><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>д<EFBFBD>룬һ<EBA3AC><D2BB>ָ<EFBFBD>뵽MAX_QUEUE_LENλ<4E>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ִ<EFBFBD>0<EFBFBD><30>ʼд<CABC>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
sFrame->hasDataLen+= (len+4) ; //<2F><><EFBFBD><EFBFBD>sFrame->hasDataLen <20>Ѿ<EFBFBD><D1BE>洢<EFBFBD><E6B4A2><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
if( sFrame->hasDataLen >= MAX_QUEUE_LEN) //δ֪<CEB4>쳣
|
|||
|
{
|
|||
|
InitQueueMem(sFrame) ;
|
|||
|
SysErr("") ;
|
|||
|
}
|
|||
|
return RW_OK;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>uint8_t GetQueueMemData(FrameQueue_s* sFrame, char* data, uint16_t* pLen)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>һ֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *sFrame FrameQueue_s<EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* @param2 *data ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ
|
|||
|
* @param3 len ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>EMPTY_ERROR/RW_OK
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*************************************************************************************************/
|
|||
|
uint8_t GetQueueMemData(FrameQueue_s* sFrame, char* data, uint16_t* pLen)
|
|||
|
{
|
|||
|
if(0 == sFrame->hasDataLen) /*֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><D5A3><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
{
|
|||
|
return EMPTY_ERROR;
|
|||
|
}
|
|||
|
else /*֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>*/
|
|||
|
{
|
|||
|
sFrame->getIndex = (sFrame->getIndex + 2) % MAX_QUEUE_LEN; //<2F><><EFBFBD><EFBFBD>֡ͷHEAD1<44><31>HEAD2 2<><32><EFBFBD>ֽ<EFBFBD>
|
|||
|
*pLen = 0 ; //pLen<65><6E>0
|
|||
|
while( (TAIL1 != sFrame->dataBuf[sFrame->getIndex])
|
|||
|
||((TAIL2 != sFrame->dataBuf[(sFrame->getIndex + 1) % MAX_QUEUE_LEN])) ) /*<2A><><EFBFBD><EFBFBD>֡β*/
|
|||
|
{
|
|||
|
(*pLen)++ ; //pLen<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
|
|||
|
*(data++) = sFrame->dataBuf[sFrame->getIndex] ; //<2F>Ƚ<EFBFBD>sFrame->dataBuf[sFrame->getIndex]<5D><>ֵ<EFBFBD><D6B5> *(data++)<29><><EFBFBD>ڽ<EFBFBD>dataָ<61><D6B8>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
|
|||
|
sFrame->getIndex = (sFrame->getIndex + 1) % MAX_QUEUE_LEN;
|
|||
|
if( (*pLen >= sFrame->hasDataLen) || (sFrame->getIndex >= MAX_QUEUE_LEN))//<2F>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
InitQueueMem(sFrame) ;
|
|||
|
SysErr("") ;
|
|||
|
return EMPTY_ERROR;
|
|||
|
}
|
|||
|
}
|
|||
|
sFrame->getIndex = (sFrame->getIndex + 2) % MAX_QUEUE_LEN; //<2F><><EFBFBD><EFBFBD>֡βTAIL1<4C><31>TAIL2 2<><32><EFBFBD>ֽ<EFBFBD>
|
|||
|
sFrame->hasDataLen -= (*pLen+4) ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>֡<EFBFBD><D6A1><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
return RW_OK;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void SysStrcat(char *dest, uint16_t destSize, char *src)
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>str<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD>ӵ<EFBFBD>dest<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *dest: Ŀ<EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
* @param2 destSize: Ŀ<EFBFBD>Ŀռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>size
|
|||
|
* @param3 *src: Դ<EFBFBD><EFBFBD>ַ
|
|||
|
****************************************************************************************************/
|
|||
|
void SysStrcat(char *dest, uint16_t destSize, char *src)
|
|||
|
{
|
|||
|
int dLen = strlen(dest) ;
|
|||
|
int sLen = strlen(src) ;
|
|||
|
|
|||
|
if( (dLen+sLen) >= destSize) //<2F>ַ<EFBFBD><D6B7><EFBFBD>ƴ<EFBFBD>Ӻ<D3BA><F3BDABB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
*(dest+destSize-sLen-1) = 0x00 ; //<2F><>Ŀ<EFBFBD><C4BF><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>β
|
|||
|
}
|
|||
|
strcat(dest, src) ; //<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ȫƴ<C8AB><C6B4><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> uint16_t CopyValues(uint8_t *dest, const uint8_t *src, uint8_t lot, uint8_t maxLen)
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>ַscr<EFBFBD><EFBFBD>Ŀ<EFBFBD>ĵ<EFBFBD>ַdst<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>lot<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯsrc<EFBFBD><EFBFBD><EFBFBD><EFBFBD>maxLen<EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *dest: Ŀ<EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
* @param2 *src: Դ<EFBFBD><EFBFBD>ַ
|
|||
|
* @param3 lot: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<EFBFBD><EFBFBD>־<EFBFBD>ַ<EFBFBD>
|
|||
|
* @param4 maxLen: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 uint16_t: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>lot<EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ƫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
************************************************************************************************************/
|
|||
|
uint16_t CopyValues(uint8_t *dest, uint8_t *src, uint8_t lot, uint16_t maxLen)
|
|||
|
{
|
|||
|
uint16_t i = 0;
|
|||
|
for(i = 0; *(src+i)!=lot; i++)
|
|||
|
{
|
|||
|
*(dest+i) = *(src+i);
|
|||
|
if(i >= (maxLen-1))
|
|||
|
break; //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><E0BFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|||
|
}
|
|||
|
return i ;
|
|||
|
//*(dest+i) = 0 ; //<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>β
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void CopyStr(char *dest, char *src, char startLot, char endLot, uint16_t maxLen)
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>ַscr<EFBFBD><EFBFBD>Ŀ<EFBFBD>ĵ<EFBFBD>ַdst<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>startLot(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>startLot)<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>endLotǰһ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯsrc<EFBFBD><EFBFBD><EFBFBD><EFBFBD>maxLen<EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *dest: Ŀ<EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
* @param2 *src: Դ<EFBFBD><EFBFBD>ַ
|
|||
|
* @param3 startLot: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>־<EFBFBD>ַ<EFBFBD>
|
|||
|
* @param4 endLot: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<EFBFBD><EFBFBD>־<EFBFBD>ַ<EFBFBD>
|
|||
|
* @param5 maxLen: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
************************************************************************************************************/
|
|||
|
void CopyStr(char *dest, char *src, char startLot, char endLot, uint16_t maxLen)
|
|||
|
{
|
|||
|
uint16_t j = 0;
|
|||
|
char *startAddr ;
|
|||
|
startAddr = strchr((const char *)src, startLot);
|
|||
|
for(j = 1; *(startAddr+j)!=endLot; j++)
|
|||
|
{
|
|||
|
*(dest+j-1) = *(startAddr+j);
|
|||
|
if(j > maxLen)
|
|||
|
break;//<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><E0BFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD>ѭ<EFBFBD><D1AD>
|
|||
|
}
|
|||
|
// *(dest+j) = *(startAddr+j);
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void HexConvertToString(uint8_t * dest, uint8_t * src, uint16_t length)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *dest: Ŀ<EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
* @param2 *src: Դ<EFBFBD><EFBFBD>ַ
|
|||
|
* @param3 length: Դ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>罫<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>{0x33,0x31}<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>31<EFBFBD><EFBFBD>
|
|||
|
*************************************************************************************************/
|
|||
|
void HexConvertToString(uint8_t * dest, uint8_t *src, uint16_t length)
|
|||
|
{
|
|||
|
uint8_t *xad;
|
|||
|
uint16_t i = 0;
|
|||
|
uint8_t ch;
|
|||
|
xad = src + length - 1;
|
|||
|
for(i = 0; i < length; i++,xad--)
|
|||
|
{
|
|||
|
ch = (*xad>>4)&0x0F;
|
|||
|
dest[i<<1] = ch+((ch<10)?'0':'7');
|
|||
|
ch = *xad & 0x0F;
|
|||
|
dest[(i<<1)+1] = ch + ((ch<10)?'0':'7');
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void ByteToHexStr( uint8_t* dest, const uint8_t* src, uint16_t sourceLen)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *dest: Ŀ<EFBFBD>ĵ<EFBFBD>ַ
|
|||
|
* @param2 *src: Դ<EFBFBD><EFBFBD>ַ
|
|||
|
* @param3 sourceLen: Դ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>{0x43,0x21}<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ{0x34,0x33,0x32,0x31}
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ByteToHexStr(macAddressBytes.bytes, macAddressNBytes, 12) ;
|
|||
|
*************************************************************************************************/
|
|||
|
void ByteToHexStr( uint8_t* dest, const uint8_t* src, uint16_t sourceLen)
|
|||
|
{
|
|||
|
uint16_t i;
|
|||
|
uint8_t highByte, lowByte;
|
|||
|
|
|||
|
for (i = 0; i < sourceLen; i++)
|
|||
|
{
|
|||
|
highByte = src[i] >> 4;
|
|||
|
lowByte = src[i] & 0x0f;
|
|||
|
|
|||
|
highByte += 0x30;
|
|||
|
|
|||
|
if (highByte > 0x39)
|
|||
|
dest[i * 2] = highByte + 0x07;
|
|||
|
else
|
|||
|
dest[i * 2] = highByte;
|
|||
|
|
|||
|
lowByte += 0x30;
|
|||
|
if (lowByte > 0x39)
|
|||
|
dest[i * 2 + 1] = lowByte + 0x07;
|
|||
|
else
|
|||
|
dest[i * 2 + 1] = lowByte;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> char *itoa(int value, char *string, int radix)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> int value, char *string, int radix
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> char *<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* radix=10 <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ʮ<EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0 ;
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>d=-379 ;ִ<EFBFBD><EFBFBD> itoa(d, buf, 10) ; <EFBFBD><EFBFBD>buf="-379"
|
|||
|
*************************************************************************************************/
|
|||
|
char *itoa(int value, char *string, int radix)
|
|||
|
{
|
|||
|
int i, d ;
|
|||
|
int flag = 0 ;
|
|||
|
char *ptr = string ;
|
|||
|
|
|||
|
/* This implementation only works for decimal numbers. */
|
|||
|
if (radix != 10)
|
|||
|
{
|
|||
|
*ptr = 0 ;
|
|||
|
return string ;
|
|||
|
}
|
|||
|
|
|||
|
if (!value)
|
|||
|
{
|
|||
|
*ptr++ = 0x30 ;
|
|||
|
*ptr = 0 ;
|
|||
|
return string ;
|
|||
|
}
|
|||
|
|
|||
|
/* if this is a negative value insert the minus sign. */
|
|||
|
if (value < 0)
|
|||
|
{
|
|||
|
*ptr++ = '-' ;
|
|||
|
|
|||
|
/* Make the value positive. */
|
|||
|
value *= -1 ;
|
|||
|
}
|
|||
|
|
|||
|
for (i = 10000; i > 0; i /= 10)
|
|||
|
{
|
|||
|
d = value / i ;
|
|||
|
|
|||
|
if (d || flag)
|
|||
|
{
|
|||
|
*ptr++ = (char)(d + 0x30) ;
|
|||
|
value -= (d * i) ;
|
|||
|
flag = 1 ;
|
|||
|
}
|
|||
|
}
|
|||
|
/* Null terminate the string. */
|
|||
|
*ptr = 0 ;
|
|||
|
|
|||
|
return string ;
|
|||
|
|
|||
|
} /* NCL_Itoa */
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> char * uitoa(unsigned int num, char *str)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת10<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> int value, char *string
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> char *<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
*************************************************************************************************/
|
|||
|
char *uitoa(unsigned int value, char *string)
|
|||
|
{
|
|||
|
unsigned char i = 0, index = 0 ;
|
|||
|
unsigned char temp = 0 ;
|
|||
|
unsigned int bottom = 10000 ;
|
|||
|
for(i = 0; i < 5; i++)
|
|||
|
{
|
|||
|
temp = value/bottom ;
|
|||
|
if(temp>0 || index>0) string[index++]=0x30+temp ;
|
|||
|
value %= bottom ;
|
|||
|
bottom /= 10 ;
|
|||
|
}
|
|||
|
if(index==0) string[index++]=0x30;
|
|||
|
|
|||
|
//string[index]='\0';
|
|||
|
return string;
|
|||
|
}
|
|||
|
|
|||
|
/**************************************************************************************************
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> int kmp(const char* _str, const char* _ptn)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>str<EFBFBD><EFBFBD>Ѱ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ptn, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 *src: Դ<EFBFBD><EFBFBD>ַ
|
|||
|
* @param2 *_ptn: ָ<EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param1 int:
|
|||
|
* @arg -1<EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>ַ<EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD>
|
|||
|
* @arg <EFBFBD><EFBFBD>-1<EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>ƫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*************************************************************************************************/
|
|||
|
int kmp(const char *_str, const char *_ptn)
|
|||
|
{
|
|||
|
uint16_t m = strlen((const char *)_str) ;
|
|||
|
uint16_t n = strlen((const char *)_ptn) ;
|
|||
|
uint16_t i = 0, j = 0 ;
|
|||
|
uint16_t loop = 0 ;
|
|||
|
|
|||
|
char* next = (char*)portMalloc((size_t)(n*sizeof(char))) ;
|
|||
|
kmp_next2(_ptn, next) ;
|
|||
|
i = 0 ; j = 0 ;
|
|||
|
while(i < m && j < n)
|
|||
|
{
|
|||
|
loop++ ;
|
|||
|
if(_str[i] == _ptn[j])
|
|||
|
{
|
|||
|
++i ;
|
|||
|
++j ;
|
|||
|
}
|
|||
|
else if(0 == j)
|
|||
|
++i ;
|
|||
|
else
|
|||
|
j = next[j] ;
|
|||
|
}
|
|||
|
|
|||
|
portFree(next) ; //next = NULL;
|
|||
|
|
|||
|
if(j >= n)
|
|||
|
return i-n ;
|
|||
|
else
|
|||
|
return -1 ;
|
|||
|
}
|
|||
|
|
|||
|
void kmp_next2(const char* _ptn, char* _next)
|
|||
|
{
|
|||
|
uint16_t n = strlen((const char *)_ptn) ;
|
|||
|
uint16_t i, j ;
|
|||
|
|
|||
|
if(n >= 1)
|
|||
|
_next[0] = 0 ;
|
|||
|
|
|||
|
i = 1 ;
|
|||
|
j = 0 ;
|
|||
|
while(i < n)
|
|||
|
{
|
|||
|
if(_ptn[i] == _ptn[j])
|
|||
|
{
|
|||
|
++i ;
|
|||
|
++j ;
|
|||
|
if(_ptn[i] != _ptn[j])
|
|||
|
_next[i] = j ;
|
|||
|
else
|
|||
|
_next[i] = _next[j] ;
|
|||
|
}
|
|||
|
else if(0 == j)
|
|||
|
_next[++i] = j ;
|
|||
|
else
|
|||
|
j = _next[j] ;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|