Embedded Template Library 1.0
Loading...
Searching...
No Matches
frame_check_sequence.h
Go to the documentation of this file.
1
2/******************************************************************************
3The MIT License(MIT)
4Embedded Template Library.
5https://github.com/ETLCPP/etl
6https://www.etlcpp.com
7Copyright(c) 2014 John Wellbelove
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files(the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions :
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23******************************************************************************/
24
25#ifndef ETL_FRAME_CHECK_SEQUENCE_INCLUDED
26#define ETL_FRAME_CHECK_SEQUENCE_INCLUDED
27
28#include "platform.h"
29#include "static_assert.h"
30#include "type_traits.h"
31#include "binary.h"
32#include "iterator.h"
33
34#include <stdint.h>
35
36ETL_STATIC_ASSERT(ETL_USING_8BIT_TYPES, "This file does not currently support targets with no 8bit type");
37
40
41namespace 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 //***********************************
80 {
81 p_fcs->add(value);
82 return *this;
83 }
84
85 private:
86
88 };
89 }
90
91 //***************************************************************************
95 //***************************************************************************
96 template <typename TPolicy>
98 {
99 public:
100
101 typedef TPolicy policy_type;
102 typedef typename policy_type::value_type value_type;
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) : frame_check()
123 {
124 ETL_STATIC_ASSERT(sizeof(typename etl::iterator_traits<TIterator>::value_type) == 1, "Type not supported");
125
126 reset();
127 add(begin, end);
128 }
129
130 //*************************************************************************
132 //*************************************************************************
133 ETL_CONSTEXPR14 void reset()
134 {
135 frame_check = policy.initial();
136 }
137
138 //*************************************************************************
142 //*************************************************************************
143 template<typename TIterator>
144 ETL_CONSTEXPR14 void add(TIterator begin, const TIterator end)
145 {
146 ETL_STATIC_ASSERT(sizeof(typename etl::iterator_traits<TIterator>::value_type) == 1, "Type not supported");
147
148 while (begin != end)
149 {
150 frame_check = policy.add(frame_check, *begin);
151 ++begin;
152 }
153 }
154
155 //*************************************************************************
157 //*************************************************************************
158 ETL_CONSTEXPR14 void add(uint8_t value_)
159 {
160 frame_check = policy.add(frame_check, value_);
161 }
162
163 //*************************************************************************
165 //*************************************************************************
166 ETL_CONSTEXPR14 value_type value() const
167 {
168 return policy.final(frame_check);
169 }
170
171 //*************************************************************************
173 //*************************************************************************
174 ETL_CONSTEXPR14 operator value_type () const
175 {
176 return policy.final(frame_check);
177 }
178
179 //*************************************************************************
181 //*************************************************************************
182 ETL_CONSTEXPR14 add_insert_iterator input()
183 {
184 return add_insert_iterator(*this);
185 }
186
187 private:
188
189 value_type frame_check;
190 policy_type policy;
191 };
192}
193
194#endif
Definition frame_check_sequence.h:51
ETL_CONSTEXPR14 void add(uint8_t value_)
Definition frame_check_sequence.h:158
ETL_CONSTEXPR14 void add(TIterator begin, const TIterator end)
Definition frame_check_sequence.h:144
ETL_CONSTEXPR14 void reset()
Resets the FCS to the initial state.
Definition frame_check_sequence.h:133
ETL_CONSTEXPR14 frame_check_sequence(TIterator begin, const TIterator end)
Definition frame_check_sequence.h:122
ETL_CONSTEXPR14 frame_check_sequence()
Default constructor.
Definition frame_check_sequence.h:110
ETL_CONSTEXPR14 add_insert_iterator input()
Gets an add_insert_iterator for input.
Definition frame_check_sequence.h:182
ETL_CONSTEXPR14 value_type value() const
Gets the FCS value.
Definition frame_check_sequence.h:166
Definition frame_check_sequence.h:98
is_unsigned
Definition type_traits_generator.h:1016
bitset_ext
Definition absolute.h:38
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition iterator.h:962
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition iterator.h:992
iterator
Definition iterator.h:399
pair holds two objects of arbitrary type
Definition utility.h:164