56 #define SEGMENT_FIRST 0x20
57 #define SEGMENT_LAST 0x10
59 #define SEGMENT_MIDDLE 0x00
61 #define SEQ_NUM_MASK 0x07
66 std::iostream(this), _address(address), _in_first_segment(true), _out_stat(
SEGMENT_FIRST), in_buf_(BUFF_SIZE),
67 in_buf_len(0), in_buf_free(true), out_buf_(BUFF_SIZE+2), out2_buf_(BUFF_SIZE),
68 in_seq_num_(0), out_seq_num_(0), out_seq_num_global(0), _abort(false), callback(callback)
72 setp(&out_buf_[1], &out_buf_[
BUFF_SIZE - 1]);
104 if (in_seq_num_ != seq_num)
106 IBRCOMMON_LOGGER_TAG(
"lowpanstream",
error) <<
"Received frame with out of bound sequence number (" << seq_num <<
" expected " << (int)in_seq_num_ <<
")"<< IBRCOMMON_LOGGER_ENDL;
119 in_seq_num_ =
static_cast<uint8_t
>((in_seq_num_ + 1) % 8);
123 if (_in_first_segment)
126 if (!(buf[0] & SEGMENT_LAST)) _in_first_segment =
false;
134 memcpy(&in_buf_[0], buf + 1, len - 1);
135 in_buf_len = len - 1;
147 int ret = std::char_traits<char>::eq_int_type(this->
overflow(
148 std::char_traits<char>::eof()), std::char_traits<char>::eof()) ? -1
158 char *ibegin = &out_buf_[0];
164 setp(&out_buf_[1], &out_buf_[
BUFF_SIZE - 1]);
166 if (!std::char_traits<char>::eq_int_type(c, std::char_traits<char>::eof()))
168 *iend++ = std::char_traits<char>::to_char_type(c);
172 size_t bytes = (iend - ibegin);
178 return std::char_traits<char>::not_eof(c);
182 out_buf_[0] = 0x07 & out_seq_num_;
183 out_buf_[0] |= _out_stat;
185 out_seq_num_global++;
186 out_seq_num_ =
static_cast<uint8_t
>((out_seq_num_ + 1) % 8);
204 return std::char_traits<char>::not_eof(c);
218 memcpy(&out2_buf_[0] , &in_buf_[0], in_buf_len);
225 setg(&out2_buf_[0], &out2_buf_[0], &out2_buf_[0] + in_buf_len);
227 return std::char_traits<char>::not_eof(out2_buf_[0]);