Colin Stearns / Mbed 2 deprecated qcControl

Dependencies:   mbed

Fork of dgps by Colin Stearns

Revision:
13:a6d3cf2b018e
Parent:
12:e42985e3ea64
Child:
14:6be57da62283
--- a/packet.h	Sat Apr 05 22:27:18 2014 +0000
+++ b/packet.h	Mon Apr 07 01:30:04 2014 +0000
@@ -5,7 +5,7 @@
 // Packet 2. (SuperPackid=5,type=PT_DEFAULT,size=1024)
 // Packet 3. (SuperPackid=5,type=PT_DEFAULT,size=1000)
 // Packet 4. (SuperPackid=5,type=PT_END,size=0)
-
+#define XBEEON
 enum PACKET_TYPE{
     PT_DEFAULT=0,
     PT_END,
@@ -13,7 +13,7 @@
     PT_SIZE
 };
 typedef struct PacketStruct{
-    PACKET_TYPE type;
+    unsigned int type;
     unsigned int size;// Number of valid bits
     char data[PACKETSIZE];
     unsigned int superPackID;// 
@@ -24,11 +24,18 @@
     unsigned int superID;
     public:
     unsigned int getSuperID(){return superID++;}
-    PacketSender():superID(0),outputDevice(USB::getSerial()){}
+    PacketSender():superID(0),outputDevice(
+        #ifdef XBEEON
+        XBEE::getSerial()
+        #else
+        USB::getSerial()
+        #endif
+    ){}
     Serial& outputDevice;
     void sendPacket(PacketStruct& output){
         for(int a=0;a<sizeof(PacketStruct);a++){
             outputDevice.putc(((char*)(&output))[a]);
+            //USB::getSerial().putc(((char*)(&output))[a]);
         }
     }
     unsigned int min(unsigned int a,unsigned int b){
@@ -36,7 +43,7 @@
     }
     void sendPacket(unsigned int superPackID,char* data,unsigned int size,PACKET_TYPE type = PT_END){
         if(data!=NULL && size>0){
-            for(int i=0;i<=size/PACKETSIZE;i++){
+            for(int i=0;i<=(size-1)/PACKETSIZE;i++){
                 PacketStruct output;
                 output.type=PT_DEFAULT;
                 output.superPackID=superPackID;
@@ -45,7 +52,7 @@
                     //USB::getSerial().printf(">>%d/%d - %d\n",a,size,output.size);
                     output.data[a]=data[a-i*PACKETSIZE];
                 }
-                
+                for(int a=output.size;a<PACKETSIZE;a++){output.data[a]='\0';}
                 //memcpy(output.data,&(data[i*PACKETSIZE]),min(PACKETSIZE,size-i*PACKETSIZE));
                 sendPacket(output);
             }
@@ -53,7 +60,9 @@
         }else{
             PacketStruct output;
             output.type=type;
+            output.size=0;
             output.superPackID=superPackID;
+            for(int a=0;a<PACKETSIZE;a++){output.data[a]=a;}
             sendPacket(output);
         }
     }