This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.c
63 lines (54 loc) · 1.78 KB
/
error.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
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "error.h"
#include "serialize.h"
#include "can_common.h"
#include "can_tx_buffer.h"
#include "pic18_time.h"
static char
err_msg_ring_buf[ERROR_MESSAGE_RING_BUFFER_SIZE][ERROR_COMMAND_LENGTH];
static uint8_t err_msg_buf_size = 0;
static uint8_t err_msg_buf_write = 0;
static uint8_t err_msg_buf_read = 0;
void report_error(uint8_t board_id,
enum BOARD_STATUS error_type,
uint8_t byte4, uint8_t byte5,
uint8_t byte6, uint8_t byte7)
{
// Check if the buffer is full
if (err_msg_buf_size == ERROR_MESSAGE_RING_BUFFER_SIZE)
return;
error_t err;
err.board_id = board_id;
err.err_type = error_type;
err.byte4 = byte4;
err.byte5 = byte5;
err.byte6 = byte6;
err.byte7 = byte7;
char *serialized_error = err_msg_ring_buf[err_msg_buf_write];
serialize_error(&err, serialized_error);
++err_msg_buf_size;
++err_msg_buf_write;
err_msg_buf_write %= ERROR_MESSAGE_RING_BUFFER_SIZE;
//if this error was generated by the radio board, we should send the
//error out over CAN so that logger has a chance to record it
if (board_id == BOARD_UNIQUE_ID) {
can_msg_t to_send;
uint8_t error_data[4];
error_data[0] = byte4;
error_data[1] = byte5;
error_data[2] = byte6;
error_data[3] = byte7;
build_board_stat_msg(millis(), error_type, error_data, 4, &to_send);
txb_enqueue(&to_send);
}
}
bool get_next_serialized_error(char *output)
{
if (err_msg_buf_size == 0)
return false;
char *serialized_error = err_msg_ring_buf[err_msg_buf_read];
memcpy(output, serialized_error, ERROR_COMMAND_LENGTH);
++err_msg_buf_read;
err_msg_buf_read %= ERROR_MESSAGE_RING_BUFFER_SIZE;
--err_msg_buf_size;
return true;
}