Colin Stearns / Mbed 2 deprecated qcControl

Dependencies:   mbed

Fork of dgps by Colin Stearns

Revision:
21:c546eab07e28
Parent:
16:4f5d20b87dc3
Child:
22:9880a26886db
--- a/main.cpp	Sat Apr 19 14:39:19 2014 +0000
+++ b/main.cpp	Mon Apr 21 13:54:55 2014 +0000
@@ -4,6 +4,7 @@
 #include "adapt/usb.h"
 #include "handle/handleCamera.h"
 #include "handle/handleGPS.h"
+#include "mavcontrol.h"
 
 Serial pc(USBTX,USBRX);
 Serial xbee(p9,p10);//tx, rx
@@ -100,9 +101,102 @@
 //    }
 //}
 
+typedef struct MAV_REQUEST_LIST_S{
+    char targSys;
+    char targComp;
+}MAV_REQUEST_LIST;
+
+typedef struct MAV_COUNT_S{
+    char targSys;
+    char targComp;
+    uint16_t count; 
+}MAV_COUNT;
+
+typedef struct mav_APM_S{
+    float parm1;
+    float parm2;
+    float parm3;
+    float parm4;
+    float parm5;
+    float parm6;
+    float parm7;
+    uint16_t cmd; 
+    uint8_t targSys;
+    uint8_t targComp;
+    uint8_t confirm;
+} mav_APM;
 
 int main()
 {
+    char input[9];
+    input[0]=0x00;
+    input[1]=0x00;
+    input[2]=0x00;
+    input[3]=0x00;
+    input[4]=0x02;
+    input[5]=0x03;
+    input[6]=0x51;
+    input[7]=0x04;
+    input[8]=0x03;
+    /*
+    while(true){
+        char input[9];
+        input[0]=0x00;
+        input[1]=0x00;
+        input[2]=0x00;
+        input[3]=0x00;
+        input[4]=0x02;
+        input[5]=0x03;
+        input[6]=0x51;
+        input[7]=0x04;
+        input[8]=0x03;
+        Mav::sendOutput(0,input,9);
+        wait_ms(50);
+    }
+    */
+    //Mav::sendOutput(MAV_CMD_NAV_TAKEOFF,NULL,0);
+    //Mav::sendOutput(MAVLINK_MSG_ID_LOITERU,NULL,0);
+    //Mav::sendOutput(MAVLINK_MSG_ID_LOITERU,NULL,0);
+    //Mav::sendOutput(MAV_CMD_NAV_LAND,NULL,0);
+    //Mav::sendOutput(MAVLINK_MSG_ID_REQUEST_LIST,NULL,0);
+    USB::getSerial().printf("System startup...\n");
+    char nextCmd[512+1];
+    int readIndex=0;
+    bool reading=false;
+    
+    MAV_REQUEST_LIST req;req.targSys=1;req.targComp=1;
+    mav_APM issueCmd;
+    issueCmd.targSys=1;issueCmd.targComp=1;issueCmd.cmd=17;issueCmd.parm1=76;issueCmd.parm2=5.0f;issueCmd.parm2=6.0f;issueCmd.parm3=7.0f;
+    while(true){
+        if(Mav::getSerial().readable()>0){
+            char input=Mav::getSerial().getc();
+            USB::getSerial().printf("> %x\n",input);
+            if(input==0xFE){
+                reading=true;
+                readIndex=1;
+            }else if(reading){
+                nextCmd[std::min(readIndex++,512)]=input;
+            }
+        }
+        // Output debug info
+        if(readIndex==1&&reading){
+            USB::getSerial().printf("Got CMD len %d messageid %d \n",nextCmd[1],nextCmd[5]);
+            if(nextCmd[5]==0){
+                //Mav::sendOutput(0,input,9);
+                //Mav::sendOutput(MAVLINK_MSG_ID_LOITERU,(char*)&issueCmd,sizeof(mav_APM));
+                Mav::sendOutput(MAVLINK_MSG_ID_REQUEST_LIST,(char*)&req,sizeof(MAV_REQUEST_LIST));
+                //Mav::sendOutput(MAVLINK_MSG_ID_REQUEST_LIST,(char*)&req,sizeof(MAV_REQUEST_LIST));
+            }
+        }
+    }
+    
+    int outLength;
+    char* output=Mav::generatePacket(MAVLINK_MSG_ID_REQUEST_LIST,NULL,0,&outLength);
+    for(int i=0;i<outLength;i++){
+        Mav::getSerial().putc(output[i]);
+    }
+    while(1){}
+    
     //getPS().sendPacket(0,NULL,0,PT_EMPTY);getPS().sendPacket(55,NULL,0,PT_IMAGE);
     //char output[256];for(int i=0;i<256;i++){output[i]=i;}getPS().sendPacket(0,NULL,0,PT_IMAGE);getPS().sendPacket(55,output,256);getPS().sendPacket(55,output,5);getPS().sendPacket(55,NULL,0,PT_END);
     //while(true){}