summaryrefslogtreecommitdiff
path: root/arduino_libs_0022/ByteBuffer/.svn
diff options
context:
space:
mode:
Diffstat (limited to 'arduino_libs_0022/ByteBuffer/.svn')
-rwxr-xr-xarduino_libs_0022/ByteBuffer/.svn/all-wcprops17
-rwxr-xr-xarduino_libs_0022/ByteBuffer/.svn/entries120
-rwxr-xr-xarduino_libs_0022/ByteBuffer/.svn/text-base/ByteBuffer.cpp.svn-base205
-rwxr-xr-xarduino_libs_0022/ByteBuffer/.svn/text-base/ByteBuffer.h.svn-base57
4 files changed, 399 insertions, 0 deletions
diff --git a/arduino_libs_0022/ByteBuffer/.svn/all-wcprops b/arduino_libs_0022/ByteBuffer/.svn/all-wcprops
new file mode 100755
index 0000000..de5c62d
--- /dev/null
+++ b/arduino_libs_0022/ByteBuffer/.svn/all-wcprops
@@ -0,0 +1,17 @@
+K 25
+svn:wc:ra_dav:version-url
+V 55
+/r/prg/!svn/ver/5368/trunk/arduino/libraries/ByteBuffer
+END
+ByteBuffer.h
+K 25
+svn:wc:ra_dav:version-url
+V 68
+/r/prg/!svn/ver/5368/trunk/arduino/libraries/ByteBuffer/ByteBuffer.h
+END
+ByteBuffer.cpp
+K 25
+svn:wc:ra_dav:version-url
+V 70
+/r/prg/!svn/ver/5812/trunk/arduino/libraries/ByteBuffer/ByteBuffer.cpp
+END
diff --git a/arduino_libs_0022/ByteBuffer/.svn/entries b/arduino_libs_0022/ByteBuffer/.svn/entries
new file mode 100755
index 0000000..4c4a628
--- /dev/null
+++ b/arduino_libs_0022/ByteBuffer/.svn/entries
@@ -0,0 +1,120 @@
+10
+
+dir
+5368
+https://svn.media.mit.edu/r/prg/trunk/arduino/libraries/ByteBuffer
+https://svn.media.mit.edu/r/prg
+
+
+
+2010-07-20T00:54:42.918731Z
+5368
+siggi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+bd000cc4-1869-4481-ad02-c3af97ea9c83
+
+ByteBuffer.h
+file
+
+
+
+
+2010-07-19T22:27:55.000000Z
+3b6d84df8e69905675772beb574cce67
+2010-07-20T00:54:42.918731Z
+5368
+siggi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+844
+
+SerialPacketHandler.cpp
+file
+5810
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+deleted
+
+ByteBuffer.cpp
+file
+5812
+
+
+
+2010-09-02T16:31:44.000000Z
+d95900d573ac73c8ccf95b384f8ec258
+2010-09-02T18:42:42.362483Z
+5812
+siggi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+3483
+
diff --git a/arduino_libs_0022/ByteBuffer/.svn/text-base/ByteBuffer.cpp.svn-base b/arduino_libs_0022/ByteBuffer/.svn/text-base/ByteBuffer.cpp.svn-base
new file mode 100755
index 0000000..b91a586
--- /dev/null
+++ b/arduino_libs_0022/ByteBuffer/.svn/text-base/ByteBuffer.cpp.svn-base
@@ -0,0 +1,205 @@
+/*
+ ByteBuffer.cpp - A circular buffer implementation for Arduino
+ Created by Sigurdur Orn, July 19, 2010.
+ */
+
+#include "WProgram.h"
+#include "ByteBuffer.h"
+
+
+ByteBuffer::ByteBuffer(){
+
+}
+
+void ByteBuffer::init(unsigned int buf_length){
+ data = (byte*)malloc(sizeof(byte)*buf_length);
+ float_bytes = (byte*)malloc(sizeof(byte)*8);
+ capacity = buf_length;
+ position = 0;
+ length = 0;
+}
+
+void ByteBuffer::clear(){
+ position = 0;
+ length = 0;
+}
+
+int ByteBuffer::getSize(){
+ return length;
+}
+
+int ByteBuffer::getCapacity(){
+ return capacity;
+}
+
+byte ByteBuffer::peek(unsigned int index){
+ byte b = data[(position+index)%capacity];
+ return b;
+}
+
+int ByteBuffer::put(byte in){
+ if(length < capacity){
+ // save data byte at end of buffer
+ data[(position+length) % capacity] = in;
+ // increment the length
+ length++;
+ return 1;
+ }
+ // return failure
+ return 0;
+}
+
+int ByteBuffer::putInFront(byte in){
+ if(length < capacity){
+ // save data byte at end of buffer
+ if( position == 0 )
+ position = capacity-1;
+ else
+ position = (position-1)%capacity;
+ data[position] = in;
+ // increment the length
+ length++;
+ return 1;
+ }
+ // return failure
+ return 0;
+}
+
+byte ByteBuffer::get(){
+ byte b = 0;
+ if(length > 0){
+ b = data[position];
+ // move index down and decrement length
+ position = (position+1)%capacity;
+ length--;
+ }
+
+ return b;
+}
+
+byte ByteBuffer::getFromBack(){
+ byte b = 0;
+ if(length > 0){
+ b = data[(position+length-1)%capacity];
+ length--;
+ }
+
+ return b;
+}
+
+//
+// Ints
+//
+
+int ByteBuffer::putIntInFront(int in){
+ byte *pointer = (byte *)&in;
+ putInFront(pointer[0]);
+ putInFront(pointer[1]);
+}
+
+int ByteBuffer::putInt(int in){
+ byte *pointer = (byte *)&in;
+ put(pointer[1]);
+ put(pointer[0]);
+}
+
+
+int ByteBuffer::getInt(){
+ int ret;
+ byte *pointer = (byte *)&ret;
+ pointer[1] = get();
+ pointer[0] = get();
+ return ret;
+}
+
+int ByteBuffer::getIntFromBack(){
+ int ret;
+ byte *pointer = (byte *)&ret;
+ pointer[0] = getFromBack();
+ pointer[1] = getFromBack();
+ return ret;
+}
+
+//
+// Longs
+//
+
+int ByteBuffer::putLongInFront(long in){
+ byte *pointer = (byte *)&in;
+ putInFront(pointer[0]);
+ putInFront(pointer[1]);
+ putInFront(pointer[2]);
+ putInFront(pointer[3]);
+}
+
+int ByteBuffer::putLong(long in){
+ byte *pointer = (byte *)&in;
+ put(pointer[3]);
+ put(pointer[2]);
+ put(pointer[1]);
+ put(pointer[0]);
+}
+
+
+long ByteBuffer::getLong(){
+ long ret;
+ byte *pointer = (byte *)&ret;
+ pointer[3] = get();
+ pointer[2] = get();
+ pointer[1] = get();
+ pointer[0] = get();
+ return ret;
+}
+
+long ByteBuffer::getLongFromBack(){
+ long ret;
+ byte *pointer = (byte *)&ret;
+ pointer[0] = getFromBack();
+ pointer[1] = getFromBack();
+ pointer[2] = getFromBack();
+ pointer[3] = getFromBack();
+ return ret;
+}
+
+
+//
+// Floats
+//
+
+int ByteBuffer::putFloatInFront(float in){
+ byte *pointer = (byte *)&in;
+ putInFront(pointer[0]);
+ putInFront(pointer[1]);
+ putInFront(pointer[2]);
+ putInFront(pointer[3]);
+}
+
+int ByteBuffer::putFloat(float in){
+ byte *pointer = (byte *)&in;
+ put(pointer[3]);
+ put(pointer[2]);
+ put(pointer[1]);
+ put(pointer[0]);
+}
+
+float ByteBuffer::getFloat(){
+ float ret;
+ byte *pointer = (byte *)&ret;
+ pointer[3] = get();
+ pointer[2] = get();
+ pointer[1] = get();
+ pointer[0] = get();
+ return ret;
+}
+
+float ByteBuffer::getFloatFromBack(){
+ float ret;
+ byte *pointer = (byte *)&ret;
+ pointer[0] = getFromBack();
+ pointer[1] = getFromBack();
+ pointer[2] = getFromBack();
+ pointer[3] = getFromBack();
+ return ret;
+}
+
+
diff --git a/arduino_libs_0022/ByteBuffer/.svn/text-base/ByteBuffer.h.svn-base b/arduino_libs_0022/ByteBuffer/.svn/text-base/ByteBuffer.h.svn-base
new file mode 100755
index 0000000..b100c2f
--- /dev/null
+++ b/arduino_libs_0022/ByteBuffer/.svn/text-base/ByteBuffer.h.svn-base
@@ -0,0 +1,57 @@
+/*
+ ByteBuffer.h - A circular buffer implementation for Arduino
+ Created by Sigurdur Orn, July 19, 2010.
+ */
+#ifndef ByteBuffer_h
+#define ByteBuffer_h
+
+#include "WProgram.h"
+
+class ByteBuffer
+{
+public:
+ ByteBuffer();
+
+ void init(unsigned int buf_size);
+
+ void clear();
+ int getSize();
+ int getCapacity();
+
+ int putInFront(byte in);
+ int put(byte in);
+
+ byte get();
+ byte getFromBack();
+
+ byte peek(unsigned int index);
+
+ int putIntInFront(int in);
+ int putInt(int in);
+
+ int putLongInFront(long in);
+ int putLong(long in);
+
+ int getInt();
+ int getIntFromBack();
+
+ long getLong();
+ long getLongFromBack();
+
+ int putFloatInFront(float in);
+ int putFloat(float in);
+
+ float getFloat();
+ float getFloatFromBack();
+
+private:
+ byte* data;
+ byte* float_bytes;
+
+ unsigned int capacity;
+ unsigned int position;
+ unsigned int length;
+};
+
+#endif
+