Xbee API Test 3

Dependencies:   XBee mbed

> help
h or help
m <status-in-hex>,. ... Modem status
l <cmd>,<val-in-hex>.   ... exec <cmd> (AT) at this host.
lset fid <val-in-hex>. ... set local frame id. default is 1.
lset cmd <val-in-hex>. ... set local command.
lset val <val-in-hex>. ... set local command value.
q <cmd>,<val-in-hex>.   ... set queue parameter value.
r <cmd>,<val-in-hex>.   ... exec <cmd> (AT)at remote host.
rset a16 <val-in-hex>. ... set remote address high.
rset a64 <val-in-hex>,<val-in-hex>.  ... set remote address low.
rset fid <val-in-hex>. ... set remote frame id. default is 1.

> l D4,0x05
cmd=D4 val=0x05
apiId=88

object 100008c8:35 01 00 10 88 00 05 FE 04 01 00 FF

l OK:

> l D4,0x04
cmd=D4 val=0x04
apiId=88

object 100008c8:35 01 00 10 88 00 05 FE 04 01 00 FF

l OK:

>
Revision:
0:3edcfa3aba71
diff -r 000000000000 -r 3edcfa3aba71 ResponseQueue.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ResponseQueue.cpp	Sat Jul 21 04:09:54 2012 +0000
@@ -0,0 +1,134 @@
+
+#include "XBee.h"
+#include "ResponseQueue.h"
+#include <stdio.h>
+
+    ResponseQueue::ResponseQueue(){
+       init();
+    }
+    void ResponseQueue::init() {
+         queueHead= 0;
+         queueTail= 0;
+         responseStoreMax=10;
+         responseStorePointer=0;
+         queueMax=10;
+         queue= &(new  (AtCommandResponse *)[queueMax]);
+         responseStore=&(new (AtCommandResponse *)[responseStoreMax]);
+         for(int i=0;i<queueMax;i++){
+            queue[i]=NULL;
+         }
+         /*
+         for(int i=0;i<5;i++){
+            AtCommandResponse *b= new AtCommandResponse();
+            collectResponse(b);
+         }
+         */
+    }
+    
+    AtCommandResponse* ResponseQueue::requestResponse(){
+//       printf("... requestBuffer ...start, bufferStoreMax=%d ",bufferStoreMax);
+       AtCommandResponse *b=NULL;
+       if(responseStorePointer==0){
+          b=new AtCommandResponse();
+//          printf(" ... return n=%d\n\r",b->getNumber());
+          return b;
+       }
+       if(responseStorePointer>0){
+          responseStorePointer--;
+          b=responseStore[responseStorePointer];
+//          printf(" ... return n=%d\n\r",b->getNumber());
+          return b;
+       }
+       return NULL;       
+    }
+    int ResponseQueue::collectResponse(AtCommandResponse *b){
+//       printf("... collectBuffer, bufferStoreMax=%d n=%d\n\r",bufferStoreMax,b->getNumber());
+       if(responseStorePointer<responseStoreMax){
+           responseStore[responseStorePointer]=b;
+           responseStorePointer++;
+           return 1;
+       }
+       return -1;
+    }
+    int ResponseQueue::putResponse(AtCommandResponse *b) {
+//       printf("... putBuffer %d..queueHead=%d queueTail=%d\n\r",b->getNumber(),queueHead,queueTail);
+       if(queueHead>queueMax) return -1;
+       if(queueTail>queueMax) return -1;
+       if(queueHead<0) return -1;
+       if(queueTail<0) return -1;
+       if(queueHead>=queueTail){
+         if(queueHead<queueMax){
+            queue[queueHead]=b;
+            queueHead++;
+            return 1;
+         }
+         else
+         if(queueHead==queueMax){
+            if(queueTail>0){
+               queue[0]=b;
+               queueHead=1;
+               return 1;
+            }
+         }
+         else{
+            return -1;
+         }
+       }
+       else{
+            queue[queueHead]=b;
+            queueHead++;
+            return 1;
+       }
+       return -1;
+    }
+    AtCommandResponse * ResponseQueue::getResponse(){
+//       printf("... getBuffer..queueHead=%d queueTail=%d ",queueHead,queueTail);
+       AtCommandResponse *b=NULL;
+       if(queueHead>queueMax) return NULL;
+       if(queueTail>queueMax) return NULL;
+       if(queueHead<0) return NULL;
+       if(queueTail<0) return NULL;
+       if(queueHead>queueTail){
+            b=queue[queueTail];
+            queueTail++;
+//            printf("buffer number=%d\n\r",b->getNumber());
+            return b;
+       }
+       if(queueHead==queueTail){
+            return NULL;
+       }
+       else{
+         if(queueTail<queueMax){
+            b=queue[queueTail];
+            queueTail++;
+//            printf("buffer number=%d\n\r",b->getNumber());
+            return b;
+         }
+         else
+         if(queueTail==queueMax){
+            if(queueHead>0){
+               queueTail=0;
+               b=queue[queueTail];
+               queueTail++;
+//               printf("buffer number=%d\n\r",b->getNumber());
+               return b;
+             }
+             else{
+                return NULL;
+             }
+         }
+         else{
+             return NULL;
+         }
+       }
+     }
+     int ResponseQueue::length(){
+          if(queueHead>=queueTail){
+             return queueHead-queueTail;
+          }
+          else{
+             int w=queueMax-queueTail;
+             return w+queueHead;
+          }
+      }
+