The BERG Cloud connection library for mbed. This works in conjunction with the BERG Cloud Devshield available via http://bergcloud.com/platform/devkit/

Dependents:   LittleCounter-Example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BERGCloudMessageBuffer.h Source File

BERGCloudMessageBuffer.h

00001 /*
00002 
00003 Simple message buffer
00004 
00005 Copyright (c) 2013 BERG Cloud Ltd. http://bergcloud.com/
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023 THE SOFTWARE.
00024 
00025 */
00026 
00027 #ifndef BERGCLOUDMESSAGEBUFFER_H
00028 #define BERGCLOUDMESSAGEBUFFER_H
00029 
00030 #define __STDC_LIMIT_MACROS /* Include C99 stdint defines in C++ code */
00031 #include <stdint.h>
00032 
00033 /* Default buffer size */
00034 #ifndef BUFFER_SIZE_BYTES
00035 #define BUFFER_SIZE_BYTES 64
00036 #endif
00037 
00038 class BERGCloudMessageBuffer
00039 {
00040 public:
00041   BERGCloudMessageBuffer();
00042   uint16_t size(void);
00043   uint8_t *ptr(void);
00044   void clear(void);
00045 
00046   /* Methods for writing to the buffer */
00047   uint16_t used(void);
00048   void used(uint16_t used);
00049   uint16_t available(void);
00050   bool available(uint16_t required);
00051   void add(uint8_t data);
00052 
00053   /* Methods for reading from the buffer */
00054   bool peek(uint8_t *data);
00055   uint8_t read(void);
00056   uint16_t remaining(void);
00057   bool remaining(uint16_t required);
00058   void restart(void);
00059 
00060 protected:
00061   uint8_t buffer[BUFFER_SIZE_BYTES];
00062   uint16_t bytesWritten;
00063   uint16_t bytesRead;
00064 };
00065 
00066 #endif // #ifndef BERGCLOUDMESSAGEBUFFER_H
00067