-
Notifications
You must be signed in to change notification settings - Fork 1
/
fault.c
51 lines (44 loc) · 1.36 KB
/
fault.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "general.h"
#include "fault.h"
#include <stdint.h>
static uint8_t fault_query_ndx = 0;
/*---------------------------------------------------------------------*
* FUNCTION: Fault_Msg_Query()
*
* Test_Result: a bit mapped 16 bit value, where 1's represent set bits
* *buf: output buffer where error message is placed
* *msg: pointer to the list of possible error messages
*
* fault_query_index: a static variable that points to the specific
* bit being processed
*----------------------------------------------------------------------*/
int Fault_Msg_Query(int Test_Result, char *buf, char *msg) {
uint8_t i;
int j=1;
if (Test_Result == 0)
return FALSE;
i = 0;
if (fault_query_ndx > 15)
fault_query_ndx = 0;
while (!(Test_Result & j<<fault_query_ndx)) {
fault_query_ndx++;
if (fault_query_ndx >= NUM_MSG || i++ >= NUM_MSG) {
fault_query_ndx = 0;
return FALSE;
}
//if( i++ >= NUM_MSG )
// return( FALSE );
}
if (*(msg+MSG_LEN*fault_query_ndx) == NULL_CHAR) {
fault_query_ndx++;
buf[0] = NULL_CHAR;
return( FALSE );
}
for (i=0; i<MSG_LEN; i++) {
buf[i] = *(msg+MSG_LEN*fault_query_ndx+i);
if (buf[i] == NULL_CHAR)
break;
}
fault_query_ndx++;
return TRUE;
}