Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

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