cdms_i2c_hardware_test

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of standaloneworkingi2c_cdms by Team Fox

Revision:
159:390ca9b41d0e
Parent:
157:d99f525edc4c
Child:
160:25a01d8da5d4
--- a/COM_MNG_TMTC.h	Mon Jul 04 20:28:03 2016 +0000
+++ b/COM_MNG_TMTC.h	Mon Jul 04 20:58:30 2016 +0000
@@ -406,66 +406,56 @@
     {
         case 1: //apid=01 implies it corresponds to bae
         {
-            printf("Telecommand is for BAE\r\n");
-            //printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae
-
-            /*if(GETshort_or_long_tc(tc_ptr) == LONG_TC_CODE){}
-                //FCTN_I2C_WRITE((char*)tc_ptr->TC_string,TC_LONG_SIZE);
-            else 
-            {
-                //FCTN_I2C_WRITE((char*)tc_ptr->TC_string,TC_SHORT_SIZE);
-            }
-            */
-            
-            while(1)
+            //BAE_I2C_mutex.lock();
+            gPC.printf("Telecommand is for BAE\r\n");
+            bool y;
+            //gPC.printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae
+            y = FCTN_I2C_WRITE((char*)tc_ptr->TC_string,135);                         // Check for SHORT and LONG TC and then send
+                
+            if(y==1)                                                            
+            {                                                                               
+                //ACK_L234(tm_ptr_short,0x03,GETpacket_seq_count(tc_ptr));
+                //BAE_I2C_mutex.unlock();
+                //return tm_ptr_short;
+            } 
+            else if(y==0)
             {
-                wait(1); //TimeOut instead of wait
-                if(BAE_I2C_GPIO == 1)
+                //wait(0.2);
+                uint8_t poll=0;
+                while(poll<60 && BAE_I2C_GPIO==0)
                 {
+                    wait_ms(50);
+                    poll+=1;
+                }    
+                if(BAE_I2C_GPIO == 1)                                            //name to be changed later
+                {
+                    gPC.printf("BAE_I2C_GPIO is high\r\n");
                     
-                    //printf("receiving...\r\n");
-                    //FCTN_I2C_READ((char*)tm_pointer->TM_string,TM_LONG_SIZE);
-                    //printf("%s", tm_pointer->TM_string);
-                    received+=1;
-                    tm_pointer = tm_pointer->next_TM;
-                    break; //only for testing purpose
+                    y=FCTN_I2C_READ((char*)tm_pointer->TM_string,134);            //rify later about the size
+                    if(y==0)
+                    {
+                        tm_pointer->next_TM=NULL;
+                        //BAE_I2C_mutex.unlock();
+                        return tm_ptr;
+                    }
                 }
-                else
+                    /*else if(y==1)
+                    {
+                        ACK_L234(tm_ptr_short,0x85,GETpacket_seq_count(tc_ptr));                
+                        //gPC.printf("\n\rPTE->PDIR = 0x%08X",PTE->PDIR);
+                        BAE_I2C_mutex.unlock();
+                        return tm_ptr_short;
+                        break;  
+                    }*/
+                
+                /*else if(BAE_I2C_GPIO == 0)                                       //name to be changed later
                 {
-                    break;
-                }
+                    gPC.printf("BAE_I2C_GPIO is not high\r\n");                    
+                    //ACK_L234(tm_ptr_short,0x84,GETpacket_seq_count(tc_ptr));
+                    BAE_I2C_mutex.unlock();
+                    return tm_ptr_short;
+                }*/
             }
-//            if(received >= 1 )
-//            {
-//                //printf("Telemetry is received from BAE\r\n");
-//                Base_tm *tm_print = tm_ptr;
-//                for(uint8_t i=0;i<received;i++)
-//                {  
-//                    //printf("%s", tm_print->TM_string);
-//                    tm_print = tm_print->next_TM; //for check
-//                }
-//                received  = 0;
-//                tm_pointer->next_TM = NULL;                 return tm_ptr;
-//            }
-//            else
-//            {
-//                //printf("Telemetry is not received from BAE\r\n");
-//                //tm_pointer = new Short_tm;
-//                tm_pointer->TM_string[0] = 0xB0;
-//                tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
-//                tm_pointer->TM_string[2] = 0x01;
-//                tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
-//                tm_pointer->TM_string[4] = 0x01;
-//                for(uint8_t i=0;i<6;i++)
-//                {
-//                    tm_pointer->TM_string[i+5] = 0;
-//                }
-//                crc16 = crc16_gen(tm_ptr->TM_string,11);
-//                tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
-//                tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
-                //tm_pointer->next_TM = NULL;                 return tm_ptr;
-//            }
-            break;
         }
         case 2:
         {