Huseyin Berkay Berabi / GA-Final

Dependencies:   mbed-dev

Fork of GA-Berkay_Alex by Alejandro Ungria Hirte

Revision:
4:120ff05a7c27
Parent:
3:8bee1711d186
--- a/main_minimal.cpp	Wed Feb 28 16:10:21 2018 +0000
+++ b/main_minimal.cpp	Wed Feb 28 17:06:22 2018 +0000
@@ -43,7 +43,7 @@
 
 BusIn adressInput(PA_9,PA_8,PB_10,PB_4,PB_5,PB_3,PA_10); // first seven 7 bit for ID settings, most left bit = most significant bit
 PC          pc(USBTX, USBRX, 921600);           // USB UART Terminal
-DigitalIn anchorInput(PC_7); // usage of last bit as deciding bit for: anchor or beacon
+DigitalIn anchorInput(PC_7); // usage of last bit as deciding bit for: anchor or beacon (most right bit on chip !)
 Watchdog    wdt = Watchdog();
 BeaconNode  beaconNode(decaWave);
 AnchorNode  anchorNode(decaWave);
@@ -71,10 +71,12 @@
   //modeInput.mode(PullDown);
   wait_ms(50);
   
+  //you can google bit masking for details
     baseStationNode.setAddress(adressInput & adressInput.mask());  
     anchorNode.setAddress(adressInput & adressInput.mask());  
     beaconNode.setAddress(adressInput & adressInput.mask());  
     
+    //if adress == 15
     if((adressInput & adressInput.mask()) == BASE_STATION_ADDR){
         node = &baseStationNode; 
         pc.printf("This node is the Base Station, Adress: %d \r\n \r\n \r\n", node->getAddress());        
@@ -101,7 +103,7 @@
     char command_str[30];
     
     while(1) {
-        
+        //all chips stay in this while loop while listening, when they get a frame they process it and then come back here again !  
         // Choose between what to execte based on whether this device is a:
         // BEACON
         // BASESTATION
@@ -127,12 +129,12 @@
                 wait_ms(8);
             }
             wdt.kick(); 
+            //after processing, tag is resetted
         } 
         else if (node->isBaseStation()){
              
              // EXECUTE THIS IF A BASE STATION
             pc.readcommand(executeOrder);
-            //wdt.kick();
         }
         else { // All Anchor Action is in the Interrupt functions!
             // EXECUTE THIS IF AN ANCHOR
@@ -148,27 +150,29 @@
 void executeOrder(char* command){
 
 
-    int repetitions = command[3]*100 + command[4]*10 + command[5] - 5328;
+    int repetitions = command[3]*100 + command[4]*10 + command[5] - 5328; //the number 5328 come from ascii
     //uint8_t dest1 = command[7] - 48;
-    uint8_t dest2 = command[8] - 48;
+    uint8_t dest2 = command[8] - 48; // -48 comes from ascii
     uint8_t dest3 = command[9] - 48;
     uint8_t dest1=0;
   
+  
     
    
     
-    if(command[7] == 0 && command[8] == 0)
+    if(command[7] == 0 && command[8] == 0) //anchor id in command has is 1 digit number for example 008
     {
     dest1 =    command[9] - 48;
     }
-    else if (command[7] == 0 && command[8] != 0)
+    else if (command[7] == 0 && command[8] != 0) //anchor id is 2 digit number for example 017
     {
     dest1 =     command[8] * 10 + command[9] - 528;
     }
-    else if (command[7] != 0 && command[8] != 0) 
+    else if (command[7] != 0 && command[8] != 0) //anchor id is 3 digit number: 123 
     {
     dest1 = command[7] * 100 + command[8] * 10 + command[9] - 5328;
     }
+    //again all offsets comes from ascii
     
     if (strncmp(command, "reset", 5) == 0){ // This command is implemented in order to be able to reset BaseStation from Matlab. 
         wdt.kick();            // Set up WatchDog   
@@ -179,11 +183,11 @@
         baseStationNode.sendOrder(0,dest1,RANGE_INT,repetitions, Node::BASE_ORDER);
         // pc.print("Mode: Range interval \r\n");
         }
-    else if (strncmp(command, "all", 3) == 0){
+    else if (strncmp(command, "all", 3) == 0){ //range all
         baseStationNode.sendOrder(0, NOT_USED, RANGE_ALL, repetitions, Node::BASE_ORDER); 
        // pc.printf("Mode: Range all \r\n");
     }
-    else if (strncmp(command, "one", 3) == 0){
+    else if (strncmp(command, "one", 3) == 0){ //range one
         
         
         
@@ -198,7 +202,7 @@
         }
     }
     
-    else if (strncmp(command, "bea", 3) == 0){
+    else if (strncmp(command, "bea", 3) == 0){ //makes an antenna tag
         if(dest1 < 15)        
             baseStationNode.sendOrder(dest1, NOT_USED, BECOME_BEACON, NOT_USED, Node::SWITCH_TYPE);
         else
@@ -206,14 +210,22 @@
          
     }
     
-    else if (strncmp(command, "anc", 3) == 0){
-        if(dest1 < 15)   
+    else if (strncmp(command, "anc", 3) == 0){ //makes an antenna anchor
+        if(dest1 < 15)  //that should be if dest1 != 0 since we have 128 anchors right now 
             baseStationNode.sendOrder(dest1, NOT_USED, BECOME_ANCHOR, NOT_USED, Node::SWITCH_TYPE); 
         else
             baseStationNode.sendOrder(0, NOT_USED, BECOME_ANCHOR, NOT_USED, Node::SWITCH_TYPE); 
     }
     
-    else if (strncmp(command, "tri", 3) == 0){
+    else if (strncmp(command, "tri", 3) == 0){ //makes a trilateration but does not work anymore since in our project we only use
+    // one destination(dest1). the command and the code should be changed so that 3 destination can be given where all of them can be a 3 digit number ! in our code
+    // tri001-123 would not work since we take dest1 = 123 as coded above. where actually tri001-123 a triangulation between ancors 1,2,3 sybolizes
+    
+    //ideally one should extend the command and the code like this:
+    //action(3 chars) repetitions(3chars) - dest1(3 chars) - dest2(3 chars) - dest3(3 chars) so that every action could work indepently, we ignored tri since we did ni=ot need it in our project
+    //for example one002-121-000-000 == range with anchor 121 2 time
+    //tri002-121-004-056 == triangulation between anchors 121 4 and 56
+    
         // Switch them in correct modes (should already be the case)
         baseStationNode.sendOrder(dest1, NOT_USED, BECOME_BEACON, NOT_USED, Node::SWITCH_TYPE);
         baseStationNode.sendOrder(dest2, NOT_USED, BECOME_ANCHOR, NOT_USED, Node::SWITCH_TYPE);