xbee communication for UWB quadcopter project Originally by Greg Abdo Forking to reduce impact of interrupt by moving packetbuilder out of the interrupt and letting be handled in the main loop

Fork of com by Prosper Van

Committer:
oprospero
Date:
Sun Nov 02 19:18:11 2014 +0000
Revision:
22:0e8e22f161ff
Parent:
17:acef0fb07510
Clean up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
oprospero 17:acef0fb07510 1 /*************************** queue.cpp ***************************************/
oprospero 17:acef0fb07510 2 /* */
oprospero 17:acef0fb07510 3 /*****************************************************************************/
oprospero 17:acef0fb07510 4
oprospero 17:acef0fb07510 5 #include "queueChar.h"
oprospero 17:acef0fb07510 6
oprospero 17:acef0fb07510 7 /***************************** constructor ***********************************/
oprospero 17:acef0fb07510 8 /* Description: */
oprospero 17:acef0fb07510 9 /*****************************************************************************/
oprospero 17:acef0fb07510 10
oprospero 17:acef0fb07510 11 queueChar::queueChar()
oprospero 17:acef0fb07510 12 {
oprospero 17:acef0fb07510 13 front = 0;
oprospero 17:acef0fb07510 14 end = 0;
oprospero 17:acef0fb07510 15 lengthVar = 0;
oprospero 17:acef0fb07510 16 for (int i = 0; i < MAXQUEUECHARLENGTH; i++)
oprospero 17:acef0fb07510 17 {
oprospero 17:acef0fb07510 18 buffer[i] = 0;
oprospero 17:acef0fb07510 19 }
oprospero 17:acef0fb07510 20 }
oprospero 17:acef0fb07510 21
oprospero 17:acef0fb07510 22 /******************************* distructor **********************************/
oprospero 17:acef0fb07510 23 /* Description: */
oprospero 17:acef0fb07510 24 /*****************************************************************************/
oprospero 17:acef0fb07510 25
oprospero 17:acef0fb07510 26 queueChar::~queueChar()
oprospero 17:acef0fb07510 27 {
oprospero 17:acef0fb07510 28 clear(); // Clear the entire queue.
oprospero 17:acef0fb07510 29 }
oprospero 17:acef0fb07510 30
oprospero 17:acef0fb07510 31 /*****************************************************************************/
oprospero 17:acef0fb07510 32 /* Description: */
oprospero 17:acef0fb07510 33 /* Accepts: */
oprospero 17:acef0fb07510 34 /* Returns: */
oprospero 17:acef0fb07510 35 /*****************************************************************************/
oprospero 17:acef0fb07510 36
oprospero 17:acef0fb07510 37 bool queueChar::isEmpty()
oprospero 17:acef0fb07510 38 {
oprospero 17:acef0fb07510 39 bool empty = front == end;
oprospero 17:acef0fb07510 40 if (empty) lengthVar = 0;
oprospero 17:acef0fb07510 41 return empty;
oprospero 17:acef0fb07510 42 }
oprospero 17:acef0fb07510 43
oprospero 17:acef0fb07510 44 /*****************************************************************************/
oprospero 17:acef0fb07510 45 /* Description: */
oprospero 17:acef0fb07510 46 /* Accepts: */
oprospero 17:acef0fb07510 47 /* Returns: */
oprospero 17:acef0fb07510 48 /*****************************************************************************/
oprospero 17:acef0fb07510 49
oprospero 17:acef0fb07510 50 void queueChar::clear()
oprospero 17:acef0fb07510 51 {
oprospero 17:acef0fb07510 52 lengthVar = 0;
oprospero 17:acef0fb07510 53 front = 0;
oprospero 17:acef0fb07510 54 end = 0;
oprospero 17:acef0fb07510 55 }
oprospero 17:acef0fb07510 56
oprospero 17:acef0fb07510 57 /*****************************************************************************/
oprospero 17:acef0fb07510 58 /* Description: */
oprospero 17:acef0fb07510 59 /* Accepts: */
oprospero 17:acef0fb07510 60 /* Returns: */
oprospero 17:acef0fb07510 61 /*****************************************************************************/
oprospero 17:acef0fb07510 62
oprospero 17:acef0fb07510 63 void queueChar::add( char data )
oprospero 17:acef0fb07510 64 {
oprospero 17:acef0fb07510 65 buffer[front] = data;
oprospero 17:acef0fb07510 66 front = nextIndex(front);
oprospero 17:acef0fb07510 67 if (front == end)
oprospero 17:acef0fb07510 68 end = nextIndex(end);
oprospero 17:acef0fb07510 69 else
oprospero 17:acef0fb07510 70 lengthVar++;
oprospero 17:acef0fb07510 71 }
oprospero 17:acef0fb07510 72
oprospero 17:acef0fb07510 73 /*****************************************************************************/
oprospero 17:acef0fb07510 74 /* Description: */
oprospero 17:acef0fb07510 75 /* Accepts: */
oprospero 17:acef0fb07510 76 /* Returns: */
oprospero 17:acef0fb07510 77 /*****************************************************************************/
oprospero 17:acef0fb07510 78
oprospero 17:acef0fb07510 79 char queueChar::pop()
oprospero 17:acef0fb07510 80 {
oprospero 17:acef0fb07510 81 if (isEmpty())
oprospero 17:acef0fb07510 82 return 255;
oprospero 17:acef0fb07510 83 else
oprospero 17:acef0fb07510 84 {
oprospero 17:acef0fb07510 85 lengthVar--;
oprospero 17:acef0fb07510 86 char data = buffer[end];
oprospero 17:acef0fb07510 87 end = nextIndex(end);
oprospero 17:acef0fb07510 88 return data;
oprospero 17:acef0fb07510 89 }
oprospero 17:acef0fb07510 90 }
oprospero 17:acef0fb07510 91
oprospero 17:acef0fb07510 92 /*****************************************************************************/
oprospero 17:acef0fb07510 93 /* Description: */
oprospero 17:acef0fb07510 94 /* Accepts: */
oprospero 17:acef0fb07510 95 /* Returns: */
oprospero 17:acef0fb07510 96 /*****************************************************************************/
oprospero 17:acef0fb07510 97
oprospero 17:acef0fb07510 98 char queueChar::peek()
oprospero 17:acef0fb07510 99 {
oprospero 17:acef0fb07510 100 // return front;
oprospero 17:acef0fb07510 101 char data = buffer[end];
oprospero 17:acef0fb07510 102 return data;
oprospero 17:acef0fb07510 103 }
oprospero 17:acef0fb07510 104
oprospero 17:acef0fb07510 105 /*****************************************************************************/
oprospero 17:acef0fb07510 106 /* Description: */
oprospero 17:acef0fb07510 107 /* Accepts: */
oprospero 17:acef0fb07510 108 /* Returns: */
oprospero 17:acef0fb07510 109 /*****************************************************************************/
oprospero 17:acef0fb07510 110
oprospero 17:acef0fb07510 111 char queueChar::length()
oprospero 17:acef0fb07510 112 {
oprospero 17:acef0fb07510 113 short diff = front - end;
oprospero 17:acef0fb07510 114 if (diff < 0)
oprospero 17:acef0fb07510 115 diff += MAXQUEUECHARLENGTH;
oprospero 17:acef0fb07510 116 // diff = diff % MAXQUEUECHARLENGTH;
oprospero 17:acef0fb07510 117 return diff;
oprospero 17:acef0fb07510 118 // if (diff == lengthVar)
oprospero 17:acef0fb07510 119 // return lengthVar;
oprospero 17:acef0fb07510 120 // else
oprospero 17:acef0fb07510 121 // lengthVar = diff;
oprospero 17:acef0fb07510 122 // return 255;
oprospero 17:acef0fb07510 123 }
oprospero 17:acef0fb07510 124
oprospero 17:acef0fb07510 125
oprospero 17:acef0fb07510 126 char queueChar::nextIndex(char index)
oprospero 17:acef0fb07510 127 {
oprospero 17:acef0fb07510 128 index++;
oprospero 17:acef0fb07510 129 if (index >= MAXQUEUECHARLENGTH)
oprospero 17:acef0fb07510 130 index = 0;
oprospero 17:acef0fb07510 131 return index;
oprospero 17:acef0fb07510 132 }