vghjvghi
Fork of XBeeLib3 by
Diff: FrameBuffer/FrameBuffer.h
- Revision:
- 0:fcaad0dfa051
- Child:
- 3:8662ebe83570
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FrameBuffer/FrameBuffer.h Fri May 08 11:50:56 2015 +0200 @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2015 Digi International Inc., + * All rights not expressly granted are reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 + * ======================================================================= + */ + +#if !defined(__FRAME_BUFFER_H_) +#define __FRAME_BUFFER_H_ + +#include "config.h" +#include "mbed.h" +#include "Frames/ApiFrame.h" + +#if FRAME_BUFFER_SIZE > 255 +# error "FRAME_BUFFER_SIZE must be lower than 256" +#endif + +typedef struct element { + ApiFrame *frame; + uint8_t status; +} buf_element_t; + +/** + * @class FrameBuffer + * @brief storage class for incoming frames + */ +class FrameBuffer +{ + public: + /** Constructor */ + FrameBuffer(); + + FrameBuffer(const FrameBuffer& other); /* Intentionally not implemented */ + /** Destructor */ + ~FrameBuffer(); + + /** get_next_free_frame returns the next free frame + * + * @returns a pointer to the next free frame */ + ApiFrame *get_next_free_frame(); + + /** complete_frame sets the status of the frame to complete once the + * data has been set in the buffer. + * + * @param pointer to the buffer we want to set as complete + * @returns true on success, false otherwise + */ + bool complete_frame(ApiFrame *frame); + + /** free_frame makes the frame available to be reused in future + * + * @param frame to release */ + bool free_frame(ApiFrame *frame); + + /** get_next_complete_frame_app returns the pointer to the next complete frame using _tail_app + * + * @returns the pointer to the selected buffer + */ + ApiFrame *get_next_complete_frame_app(); + + /** get_next_complete_frame_syncr returns the pointer to the next complete frame using _tail_syncr + * + * @returns the pointer to the selected buffer + */ + ApiFrame *get_next_complete_frame_syncr(); + + /** get_dropped_frames_count returns the number of dropped frames since latest call to this method + * + * @returns the number of dropped frames since latest call to this method + */ + uint32_t get_dropped_frames_count(); + + +protected: + + /** frame status */ + enum FrameStatus { + FrameStatusFree = 0, /**< Free */ + FrameStatusAssigned, /**< Assigned */ + FrameStatusComplete /**< Complete */ + }; + + /** buffer array */ + buf_element_t _frm_buf[FRAME_BUFFER_SIZE]; + + /** head frame index */ + uint8_t _head; + + /** tail frame index for application */ + uint8_t _tail_app; + + /** tail frame index for syncronous operations */ + uint8_t _tail_syncr; + + /** dropped frames */ + uint32_t _dropped_frames; + + /** get_next_complete_frame returns the pointer to the next complete frame + * + * @param tail tail index to use (either _tail_app or _tail_syncr) + * @returns the pointer to the selected buffer + */ + ApiFrame *get_next_complete_frame(uint8_t* tail); +}; + +#endif /* __FRAME_BUFFER_H_ */ + +