forked from arduino/ArduinoCore-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCanMsgRingbuffer.cpp
62 lines (48 loc) · 1.68 KB
/
CanMsgRingbuffer.cpp
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
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include "CanMsgRingbuffer.h"
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
namespace arduino
{
/**************************************************************************************
* CTOR/DTOR
**************************************************************************************/
CanMsgRingbuffer::CanMsgRingbuffer()
: _head{0}
, _tail{0}
, _num_elems{0}
{
}
/**************************************************************************************
* PUBLIC MEMBER FUNCTIONS
**************************************************************************************/
void CanMsgRingbuffer::enqueue(CanMsg const & msg)
{
if (isFull())
return;
_buf[_head] = msg;
_head = next(_head);
_num_elems = _num_elems + 1;
}
CanMsg CanMsgRingbuffer::dequeue()
{
if (isEmpty())
return CanMsg();
CanMsg const msg = _buf[_tail];
_tail = next(_tail);
_num_elems = _num_elems - 1;
return msg;
}
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
} /* arduino */