unsigned char array

Dependents:   MGC3130 SmartLabXBeeCore

Committer:
yangcq88517
Date:
Thu Nov 12 02:41:54 2015 +0000
Revision:
2:765da30c4d9b
Parent:
1:77c1ea04eb5a
bug fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yangcq88517 0:b35da77c40ca 1 #ifndef UK_AC_HERTS_SMARTLAB_XBEE_BufferedArray
yangcq88517 0:b35da77c40ca 2 #define UK_AC_HERTS_SMARTLAB_XBEE_BufferedArray
yangcq88517 0:b35da77c40ca 3
yangcq88517 0:b35da77c40ca 4 #include "mbed.h"
yangcq88517 0:b35da77c40ca 5
yangcq88517 0:b35da77c40ca 6 /**
yangcq88517 0:b35da77c40ca 7 * Represent a generic, dynamic-length raw binary data buffer.
yangcq88517 0:b35da77c40ca 8 */
yangcq88517 0:b35da77c40ca 9 class BufferedArray
yangcq88517 0:b35da77c40ca 10 {
yangcq88517 0:b35da77c40ca 11 protected :
yangcq88517 0:b35da77c40ca 12 /// initial size and automatically increase length.
yangcq88517 2:765da30c4d9b 13 unsigned int expandSize;
yangcq88517 0:b35da77c40ca 14
yangcq88517 0:b35da77c40ca 15 /// Raw data
yangcq88517 0:b35da77c40ca 16 unsigned char * data;
yangcq88517 0:b35da77c40ca 17
yangcq88517 0:b35da77c40ca 18 /// Current index of the data, could also used as data lendth.
yangcq88517 2:765da30c4d9b 19 unsigned long index;
yangcq88517 0:b35da77c40ca 20
yangcq88517 0:b35da77c40ca 21 /// Max data size that the raw data can hold.
yangcq88517 2:765da30c4d9b 22 unsigned long max;
yangcq88517 0:b35da77c40ca 23
yangcq88517 2:765da30c4d9b 24 void expandSpace(unsigned long length);
yangcq88517 0:b35da77c40ca 25
yangcq88517 0:b35da77c40ca 26 public:
yangcq88517 2:765da30c4d9b 27 BufferedArray(unsigned int initialLength, unsigned int expandSize);
yangcq88517 0:b35da77c40ca 28
yangcq88517 0:b35da77c40ca 29 BufferedArray(BufferedArray * bufferedArray);
yangcq88517 0:b35da77c40ca 30
yangcq88517 0:b35da77c40ca 31 ~BufferedArray();
yangcq88517 0:b35da77c40ca 32
yangcq88517 0:b35da77c40ca 33 /** Get the raw data.
yangcq88517 0:b35da77c40ca 34 * @returns unsigned char array.
yangcq88517 0:b35da77c40ca 35 */
yangcq88517 0:b35da77c40ca 36 unsigned char * gets();
yangcq88517 0:b35da77c40ca 37
yangcq88517 0:b35da77c40ca 38 /** Get the raw data from a specific location.
yangcq88517 0:b35da77c40ca 39 *
yangcq88517 0:b35da77c40ca 40 * @param position where to retrieve
yangcq88517 0:b35da77c40ca 41 *
yangcq88517 0:b35da77c40ca 42 * @returns unsigned char array.
yangcq88517 0:b35da77c40ca 43 */
yangcq88517 2:765da30c4d9b 44 unsigned char * gets(unsigned long position);
yangcq88517 0:b35da77c40ca 45
yangcq88517 0:b35da77c40ca 46 /** Get 1 byte data from a specific location.
yangcq88517 0:b35da77c40ca 47 *
yangcq88517 0:b35da77c40ca 48 * @param position where to retrieve
yangcq88517 0:b35da77c40ca 49 *
yangcq88517 0:b35da77c40ca 50 * @returns unsigned char.
yangcq88517 0:b35da77c40ca 51 */
yangcq88517 2:765da30c4d9b 52 unsigned char get(unsigned long position);
yangcq88517 0:b35da77c40ca 53
yangcq88517 0:b35da77c40ca 54 /** Get the current index.
yangcq88517 0:b35da77c40ca 55 * @returns unsigned char array.
yangcq88517 0:b35da77c40ca 56 */
yangcq88517 0:b35da77c40ca 57 int getPosition();
yangcq88517 0:b35da77c40ca 58
yangcq88517 0:b35da77c40ca 59 /** Set the index within the max length of raw data.
yangcq88517 0:b35da77c40ca 60 * @param position where to begin read and write
yangcq88517 0:b35da77c40ca 61 */
yangcq88517 2:765da30c4d9b 62 void setPosition(unsigned long position);
yangcq88517 0:b35da77c40ca 63
yangcq88517 0:b35da77c40ca 64 /** Reset the raw data.
yangcq88517 0:b35da77c40ca 65 * @param length current max size for the raw data
yangcq88517 0:b35da77c40ca 66 */
yangcq88517 2:765da30c4d9b 67 void allocate(unsigned long length);
yangcq88517 0:b35da77c40ca 68
yangcq88517 0:b35da77c40ca 69 /** Reset the position and does not affect the content of the data.
yangcq88517 0:b35da77c40ca 70 * @param length current max size for the raw data
yangcq88517 0:b35da77c40ca 71 */
yangcq88517 0:b35da77c40ca 72 void rewind();
yangcq88517 0:b35da77c40ca 73
yangcq88517 0:b35da77c40ca 74 /** Write 8-bit data into current posiston and increase by 1.
yangcq88517 0:b35da77c40ca 75 * @param value sigle byte
yangcq88517 0:b35da77c40ca 76 */
yangcq88517 0:b35da77c40ca 77 void set(unsigned char value);
yangcq88517 0:b35da77c40ca 78
yangcq88517 0:b35da77c40ca 79 /** Write array of data into current posiston, and increase by the lenght.
yangcq88517 0:b35da77c40ca 80 * @param value array of byte
yangcq88517 0:b35da77c40ca 81 * @param offset start point of the data
yangcq88517 0:b35da77c40ca 82 * @param length length to write
yangcq88517 0:b35da77c40ca 83 */
yangcq88517 2:765da30c4d9b 84 void sets(const unsigned char * value, unsigned long offset, unsigned long length);
yangcq88517 0:b35da77c40ca 85
yangcq88517 0:b35da77c40ca 86 /** Write 8-bit data into specific posiston and deos not affect the current position.
yangcq88517 0:b35da77c40ca 87 * @param position where to write
yangcq88517 0:b35da77c40ca 88 * @param value sigle byte
yangcq88517 0:b35da77c40ca 89 */
yangcq88517 2:765da30c4d9b 90 void set(unsigned long position, unsigned char value);
yangcq88517 0:b35da77c40ca 91
yangcq88517 0:b35da77c40ca 92 /** Write array of data into specific posiston and deos not affect the current position.
yangcq88517 0:b35da77c40ca 93 * @param position where to write
yangcq88517 0:b35da77c40ca 94 * @param value array of byte
yangcq88517 0:b35da77c40ca 95 * @param offset start point of the data
yangcq88517 0:b35da77c40ca 96 * @param length length to write
yangcq88517 0:b35da77c40ca 97 */
yangcq88517 2:765da30c4d9b 98 void sets(unsigned long position, const unsigned char * value, unsigned long offset, unsigned long length);
yangcq88517 2:765da30c4d9b 99 };
yangcq88517 0:b35da77c40ca 100
yangcq88517 0:b35da77c40ca 101 #endif