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 "binary.h"
30#include "iterator.h"
31#include "static_assert.h"
32#include "type_traits.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 //***********************************
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>
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)
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
Definition frame_check_sequence.h:51
ETL_CONSTEXPR14 void add(uint8_t value_)
Definition frame_check_sequence.h:159
ETL_CONSTEXPR14 void add(TIterator begin, const TIterator end)
Definition frame_check_sequence.h:145
ETL_CONSTEXPR14 void reset()
Resets the FCS to the initial state.
Definition frame_check_sequence.h:134
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:183
ETL_CONSTEXPR14 value_type value() const
Gets the FCS value.
Definition frame_check_sequence.h:167
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition iterator.h:967
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition iterator.h:997
iterator
Definition iterator.h:424