Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

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