Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
frame_check_sequence.h
Go to the documentation of this file.
1
2
/******************************************************************************
3
The MIT License(MIT)
4
Embedded Template Library.
5
https://github.com/ETLCPP/etl
6
https://www.etlcpp.com
7
Copyright(c) 2014 John Wellbelove
8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files(the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions :
14
The above copyright notice and this permission notice shall be included in all
15
copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
SOFTWARE.
23
******************************************************************************/
24
25
#ifndef ETL_FRAME_CHECK_SEQUENCE_INCLUDED
26
#define ETL_FRAME_CHECK_SEQUENCE_INCLUDED
27
28
#include "
platform.h
"
29
#include "
binary.h
"
30
#include "
iterator.h
"
31
#include "static_assert.h"
32
#include "
type_traits.h
"
33
34
#include <stdint.h>
35
36
ETL_STATIC_ASSERT(ETL_USING_8BIT_TYPES,
"This file does not currently support targets with no 8bit type"
);
37
40
41
namespace
etl
42
{
43
namespace
private_frame_check_sequence
44
{
45
//***************************************************
48
//***************************************************
49
template
<
typename
TFrame_Check_Sequence>
50
class
add_insert_iterator :
public
etl::iterator
<ETL_OR_STD::output_iterator_tag, typename TFrame_Check_Sequence::value_type>
51
{
52
public
:
53
54
//***********************************
55
explicit
add_insert_iterator(TFrame_Check_Sequence& fcs) ETL_NOEXCEPT
56
: p_fcs(&fcs)
57
{
58
}
59
60
//***********************************
61
add_insert_iterator& operator*() ETL_NOEXCEPT
62
{
63
return
*
this
;
64
}
65
66
//***********************************
67
add_insert_iterator& operator++() ETL_NOEXCEPT
68
{
69
return
*
this
;
70
}
71
72
//***********************************
73
add_insert_iterator& operator++(
int
) ETL_NOEXCEPT
74
{
75
return
*
this
;
76
}
77
78
//***********************************
79
add_insert_iterator& operator=(uint8_t value)
80
{
81
p_fcs->add(value);
82
return
*
this
;
83
}
84
85
private
:
86
87
TFrame_Check_Sequence* p_fcs;
88
};
89
}
// namespace private_frame_check_sequence
90
91
//***************************************************************************
95
//***************************************************************************
96
template
<
typename
TPolicy>
97
class
frame_check_sequence
98
{
99
public
:
100
101
typedef
TPolicy policy_type;
102
typedef
typename
policy_type::value_type value_type;
103
typedef
private_frame_check_sequence::add_insert_iterator< frame_check_sequence<TPolicy>
> add_insert_iterator;
104
105
ETL_STATIC_ASSERT(etl::is_unsigned<value_type>::value,
"Signed frame check type not supported"
);
106
107
//*************************************************************************
109
//*************************************************************************
110
ETL_CONSTEXPR14
frame_check_sequence
()
111
: frame_check()
112
{
113
reset
();
114
}
115
116
//*************************************************************************
120
//*************************************************************************
121
template
<
typename
TIterator>
122
ETL_CONSTEXPR14
frame_check_sequence
(TIterator
begin
,
const
TIterator
end
)
123
: frame_check()
124
{
125
ETL_STATIC_ASSERT(
sizeof
(
typename
etl::iterator_traits<TIterator>::value_type) == 1,
"Type not supported"
);
126
127
reset
();
128
add
(
begin
,
end
);
129
}
130
131
//*************************************************************************
133
//*************************************************************************
134
ETL_CONSTEXPR14
void
reset
()
135
{
136
frame_check = policy.initial();
137
}
138
139
//*************************************************************************
143
//*************************************************************************
144
template
<
typename
TIterator>
145
ETL_CONSTEXPR14
void
add
(TIterator
begin
,
const
TIterator
end
)
146
{
147
ETL_STATIC_ASSERT(
sizeof
(
typename
etl::iterator_traits<TIterator>::value_type) == 1,
"Type not supported"
);
148
149
while
(
begin
!=
end
)
150
{
151
frame_check = policy.add(frame_check,
static_cast<
uint8_t
>
(*
begin
));
152
++
begin
;
153
}
154
}
155
156
//*************************************************************************
158
//*************************************************************************
159
ETL_CONSTEXPR14
void
add
(uint8_t value_)
160
{
161
frame_check = policy.add(frame_check, value_);
162
}
163
164
//*************************************************************************
166
//*************************************************************************
167
ETL_CONSTEXPR14 value_type
value
()
const
168
{
169
return
policy.final(frame_check);
170
}
171
172
//*************************************************************************
174
//*************************************************************************
175
ETL_CONSTEXPR14
operator
value_type()
const
176
{
177
return
policy.final(frame_check);
178
}
179
180
//*************************************************************************
182
//*************************************************************************
183
ETL_CONSTEXPR14 add_insert_iterator
input
()
184
{
185
return
add_insert_iterator(*
this
);
186
}
187
188
private
:
189
190
value_type
frame_check;
191
policy_type policy;
192
};
193
}
// namespace etl
194
195
#endif
binary.h
etl::private_frame_check_sequence::add_insert_iterator
Definition
frame_check_sequence.h:51
etl::frame_check_sequence::add
ETL_CONSTEXPR14 void add(uint8_t value_)
Definition
frame_check_sequence.h:159
etl::frame_check_sequence::add
ETL_CONSTEXPR14 void add(TIterator begin, const TIterator end)
Definition
frame_check_sequence.h:145
etl::frame_check_sequence::reset
ETL_CONSTEXPR14 void reset()
Resets the FCS to the initial state.
Definition
frame_check_sequence.h:134
etl::frame_check_sequence::frame_check_sequence
ETL_CONSTEXPR14 frame_check_sequence(TIterator begin, const TIterator end)
Definition
frame_check_sequence.h:122
etl::frame_check_sequence::frame_check_sequence
ETL_CONSTEXPR14 frame_check_sequence()
Default constructor.
Definition
frame_check_sequence.h:110
etl::frame_check_sequence::input
ETL_CONSTEXPR14 add_insert_iterator input()
Gets an add_insert_iterator for input.
Definition
frame_check_sequence.h:183
etl::frame_check_sequence::value
ETL_CONSTEXPR14 value_type value() const
Gets the FCS value.
Definition
frame_check_sequence.h:167
iterator.h
etl
Definition
absolute.h:40
etl::end
TContainer::iterator end(TContainer &container)
Definition
iterator.h:1166
etl::begin
TContainer::iterator begin(TContainer &container)
Definition
iterator.h:1136
platform.h
etl::value_type
etl::iterator
iterator
Definition
iterator.h:482
type_traits.h
include
etl
frame_check_sequence.h
Generated on
for Embedded Template Library by
1.17.0