Library to easily communicate with XBee modules.
Fork of XBeeLib by
FrameBuffer/FrameBuffer.h@4:629712865107, 2015-06-01 (annotated)
- Committer:
- spastor
- Date:
- Mon Jun 01 18:59:43 2015 +0200
- Revision:
- 4:629712865107
- Parent:
- 3:8662ebe83570
Automatic upload
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spastor | 0:fcaad0dfa051 | 1 | /** |
spastor | 0:fcaad0dfa051 | 2 | * Copyright (c) 2015 Digi International Inc., |
spastor | 0:fcaad0dfa051 | 3 | * All rights not expressly granted are reserved. |
spastor | 0:fcaad0dfa051 | 4 | * |
spastor | 0:fcaad0dfa051 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
spastor | 0:fcaad0dfa051 | 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
spastor | 0:fcaad0dfa051 | 7 | * You can obtain one at http://mozilla.org/MPL/2.0/. |
spastor | 0:fcaad0dfa051 | 8 | * |
spastor | 0:fcaad0dfa051 | 9 | * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
spastor | 0:fcaad0dfa051 | 10 | * ======================================================================= |
spastor | 0:fcaad0dfa051 | 11 | */ |
spastor | 4:629712865107 | 12 | |
spastor | 0:fcaad0dfa051 | 13 | #if !defined(__FRAME_BUFFER_H_) |
spastor | 0:fcaad0dfa051 | 14 | #define __FRAME_BUFFER_H_ |
spastor | 4:629712865107 | 15 | |
spastor | 0:fcaad0dfa051 | 16 | #include "config.h" |
spastor | 0:fcaad0dfa051 | 17 | #include "mbed.h" |
spastor | 0:fcaad0dfa051 | 18 | #include "Frames/ApiFrame.h" |
spastor | 0:fcaad0dfa051 | 19 | |
spastor | 0:fcaad0dfa051 | 20 | #if FRAME_BUFFER_SIZE > 255 |
spastor | 0:fcaad0dfa051 | 21 | # error "FRAME_BUFFER_SIZE must be lower than 256" |
spastor | 0:fcaad0dfa051 | 22 | #endif |
spastor | 0:fcaad0dfa051 | 23 | |
spastor | 0:fcaad0dfa051 | 24 | typedef struct element { |
spastor | 0:fcaad0dfa051 | 25 | ApiFrame *frame; |
spastor | 0:fcaad0dfa051 | 26 | uint8_t status; |
spastor | 0:fcaad0dfa051 | 27 | } buf_element_t; |
spastor | 0:fcaad0dfa051 | 28 | |
spastor | 0:fcaad0dfa051 | 29 | /** |
spastor | 0:fcaad0dfa051 | 30 | * @class FrameBuffer |
spastor | 4:629712865107 | 31 | * @brief storage class for incoming frames |
spastor | 4:629712865107 | 32 | */ |
spastor | 0:fcaad0dfa051 | 33 | class FrameBuffer |
spastor | 0:fcaad0dfa051 | 34 | { |
spastor | 0:fcaad0dfa051 | 35 | public: |
spastor | 0:fcaad0dfa051 | 36 | /** Constructor */ |
spastor | 4:629712865107 | 37 | FrameBuffer(uint8_t size, uint16_t max_payload_len); |
spastor | 4:629712865107 | 38 | |
spastor | 0:fcaad0dfa051 | 39 | FrameBuffer(const FrameBuffer& other); /* Intentionally not implemented */ |
spastor | 4:629712865107 | 40 | /** Destructor */ |
spastor | 0:fcaad0dfa051 | 41 | ~FrameBuffer(); |
spastor | 4:629712865107 | 42 | |
spastor | 4:629712865107 | 43 | /** get_next_free_frame returns the next free frame |
spastor | 0:fcaad0dfa051 | 44 | * |
spastor | 0:fcaad0dfa051 | 45 | * @returns a pointer to the next free frame */ |
spastor | 0:fcaad0dfa051 | 46 | ApiFrame *get_next_free_frame(); |
spastor | 0:fcaad0dfa051 | 47 | |
spastor | 4:629712865107 | 48 | /** complete_frame sets the status of the frame to complete once the |
spastor | 0:fcaad0dfa051 | 49 | * data has been set in the buffer. |
spastor | 0:fcaad0dfa051 | 50 | * |
spastor | 0:fcaad0dfa051 | 51 | * @param pointer to the buffer we want to set as complete |
spastor | 0:fcaad0dfa051 | 52 | * @returns true on success, false otherwise |
spastor | 0:fcaad0dfa051 | 53 | */ |
spastor | 0:fcaad0dfa051 | 54 | bool complete_frame(ApiFrame *frame); |
spastor | 4:629712865107 | 55 | |
spastor | 0:fcaad0dfa051 | 56 | /** free_frame makes the frame available to be reused in future |
spastor | 0:fcaad0dfa051 | 57 | * |
spastor | 0:fcaad0dfa051 | 58 | * @param frame to release */ |
spastor | 0:fcaad0dfa051 | 59 | bool free_frame(ApiFrame *frame); |
spastor | 0:fcaad0dfa051 | 60 | |
spastor | 4:629712865107 | 61 | /** get_next_complete_frame returns the pointer to the next complete frame |
spastor | 0:fcaad0dfa051 | 62 | * |
spastor | 0:fcaad0dfa051 | 63 | * @returns the pointer to the selected buffer |
spastor | 0:fcaad0dfa051 | 64 | */ |
spastor | 4:629712865107 | 65 | ApiFrame *get_next_complete_frame(); |
spastor | 0:fcaad0dfa051 | 66 | |
spastor | 0:fcaad0dfa051 | 67 | /** get_dropped_frames_count returns the number of dropped frames since latest call to this method |
spastor | 0:fcaad0dfa051 | 68 | * |
spastor | 0:fcaad0dfa051 | 69 | * @returns the number of dropped frames since latest call to this method |
spastor | 0:fcaad0dfa051 | 70 | */ |
spastor | 0:fcaad0dfa051 | 71 | uint32_t get_dropped_frames_count(); |
spastor | 0:fcaad0dfa051 | 72 | |
spastor | 0:fcaad0dfa051 | 73 | protected: |
spastor | 0:fcaad0dfa051 | 74 | |
spastor | 0:fcaad0dfa051 | 75 | /** frame status */ |
spastor | 0:fcaad0dfa051 | 76 | enum FrameStatus { |
spastor | 0:fcaad0dfa051 | 77 | FrameStatusFree = 0, /**< Free */ |
spastor | 0:fcaad0dfa051 | 78 | FrameStatusAssigned, /**< Assigned */ |
spastor | 0:fcaad0dfa051 | 79 | FrameStatusComplete /**< Complete */ |
spastor | 0:fcaad0dfa051 | 80 | }; |
spastor | 0:fcaad0dfa051 | 81 | |
spastor | 0:fcaad0dfa051 | 82 | /** buffer array */ |
spastor | 4:629712865107 | 83 | buf_element_t * _frm_buf; |
spastor | 4:629712865107 | 84 | |
spastor | 4:629712865107 | 85 | uint8_t _size; |
spastor | 4:629712865107 | 86 | |
spastor | 0:fcaad0dfa051 | 87 | |
spastor | 0:fcaad0dfa051 | 88 | /** head frame index */ |
spastor | 0:fcaad0dfa051 | 89 | uint8_t _head; |
spastor | 0:fcaad0dfa051 | 90 | |
spastor | 0:fcaad0dfa051 | 91 | /** tail frame index for application */ |
spastor | 4:629712865107 | 92 | uint8_t _tail; |
spastor | 0:fcaad0dfa051 | 93 | |
spastor | 0:fcaad0dfa051 | 94 | /** dropped frames */ |
spastor | 0:fcaad0dfa051 | 95 | uint32_t _dropped_frames; |
spastor | 4:629712865107 | 96 | }; |
spastor | 0:fcaad0dfa051 | 97 | |
spastor | 0:fcaad0dfa051 | 98 | #endif /* __FRAME_BUFFER_H_ */ |