Commit bfdf5567 authored by 陈家乐's avatar 陈家乐

🐞 fix:故障码增加空指针处理

parent e9ded3f2
......@@ -349,6 +349,10 @@ void FaultCode_Service(uint16_t Cycle)
#if 1
uint8_t List_Init(FaultCodeList_t *CodeList, uint16_t Arr[], uint8_t Len)
{
if((CodeList == NULL) || (Arr == NULL))
{
return 2;//空指针,初始化失败
}
if(Len < 1)
{
return 1;//列表空
......@@ -364,6 +368,10 @@ uint8_t List_Init(FaultCodeList_t *CodeList, uint16_t Arr[], uint8_t Len)
uint8_t List_Find(FaultCodeList_t *CodeList, uint16_t FaultCode)
{
if(CodeList == NULL)
{
return 2;
}
for(int i=CodeList->hade; i<CodeList->tail; i++)
{
if(CodeList->code_list[i] == FaultCode)
......@@ -376,6 +384,10 @@ uint8_t List_Find(FaultCodeList_t *CodeList, uint16_t FaultCode)
uint8_t List_add(FaultCodeList_t *CodeList, uint16_t FaultCode)
{
if(CodeList == NULL)
{
return 3;
}
if((CodeList->tail+1) >= CodeList->len)
{
return 1;//列表满
......@@ -395,6 +407,10 @@ uint8_t List_add(FaultCodeList_t *CodeList, uint16_t FaultCode)
uint8_t List_Clear(FaultCodeList_t *CodeList)
{
if(CodeList == NULL)
{
return 2;
}
CodeList->hade = 0;
CodeList->tail = 0;
//CodeList->disp = 0;
......@@ -403,6 +419,10 @@ uint8_t List_Clear(FaultCodeList_t *CodeList)
}
uint8_t List_GetNum(FaultCodeList_t *CodeList)
{
if(CodeList == NULL)
{
return 0;
}
return CodeList->tail - CodeList->hade;
}
......@@ -439,15 +459,19 @@ void FaultCode_Servers(void)
}
uint16_t List_Display(FaultCodeList_t *CodeList, uint16_t TimeCount)
uint16_t List_Display(FaultCodeList_t *CodeList, uint16_t *TimeCount)
{
if(CodeList->hade == CodeList->tail)
if((CodeList == NULL) || (TimeCount == NULL))
{
return 0;
}
if(List_GetNum(CodeList) == 0)
{
return 0;
}
if(TimeCount >= 500)
if(*TimeCount >= 500)
{
FaultTimeCount = 0;
*TimeCount = 0;
if(++(CodeList->disp) >= (CodeList->tail))
{
CodeList->disp = CodeList->hade;
......@@ -465,7 +489,7 @@ uint16_t List_Display(FaultCodeList_t *CodeList, uint16_t TimeCount)
uint32_t Get_Current_FaultCode(void)
{
//return stFaultCode[0].u16FaultCode;
return List_Display(&FaultCode_t, FaultTimeCount);
return List_Display(&FaultCode_t, &FaultTimeCount);
}
// uint8_t Get_FaultCode_Valid(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment