Library to easily communicate with XBee modules.

Dependencies:   DigiLogger

Dependents:   WaterLogger XbeeGateway XBee_Cooker ProjetReceiver ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FrameBuffer.h Source File

FrameBuffer.h

00001 /**
00002  * Copyright (c) 2015 Digi International Inc.,
00003  * All rights not expressly granted are reserved.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
00007  * You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
00010  * =======================================================================
00011  */
00012 
00013 #if !defined(__FRAME_BUFFER_H_)
00014 #define __FRAME_BUFFER_H_
00015 
00016 #include "config.h"
00017 #include "mbed.h"
00018 #include "Frames/ApiFrame.h"
00019 
00020 #if FRAME_BUFFER_SIZE > 255
00021 # error "FRAME_BUFFER_SIZE must be lower than 256"
00022 #endif
00023 
00024 typedef struct element {
00025     ApiFrame    *frame;
00026     uint8_t     status;
00027 } buf_element_t;
00028 
00029 /**
00030  *  @class FrameBuffer
00031  *  @brief storage class for incoming frames
00032  */
00033 class FrameBuffer
00034 {
00035     public:
00036         /** Constructor */
00037         FrameBuffer(uint8_t size, uint16_t max_payload_len);
00038 
00039         FrameBuffer(const FrameBuffer& other); /* Intentionally not implemented */
00040         /** Destructor */
00041         ~FrameBuffer();
00042 
00043         /** get_next_free_frame returns the next free frame
00044          *
00045          * @returns a pointer to the next free frame */
00046         ApiFrame *get_next_free_frame();
00047 
00048         /** complete_frame sets the status of the frame to complete once the
00049          *                      data has been set in the buffer.
00050          *
00051          * @param pointer to the buffer we want to set as complete
00052          * @returns true on success, false otherwise
00053          */
00054         bool complete_frame(ApiFrame *frame);
00055 
00056         /** free_frame makes the frame available to be reused in future
00057          *
00058          * @param frame to release */
00059         bool free_frame(ApiFrame *frame);
00060 
00061         /** get_next_complete_frame returns the pointer to the next complete frame
00062          *
00063          * @returns the pointer to the selected buffer
00064          */
00065         ApiFrame *get_next_complete_frame();
00066 
00067         /** get_dropped_frames_count returns the number of dropped frames since latest call to this method
00068          *
00069          * @returns the number of dropped frames since latest call to this method
00070          */
00071         uint32_t get_dropped_frames_count();
00072 
00073 protected:
00074 
00075         /** frame status */
00076         enum FrameStatus {
00077             FrameStatusFree = 0,   /**< Free */
00078             FrameStatusAssigned,   /**< Assigned */
00079             FrameStatusComplete    /**< Complete */
00080         };
00081 
00082         /** buffer array */
00083         buf_element_t   * _frm_buf;
00084 
00085         uint8_t          _size;
00086         
00087 
00088         /** head frame index */
00089         uint8_t         _head;
00090 
00091         /** tail frame index for application */
00092         uint8_t         _tail;
00093 
00094         /** dropped frames */
00095         uint32_t        _dropped_frames;
00096 };
00097 
00098 #endif /* __FRAME_BUFFER_H_ */