Browse Source

Coordinate update

Tom Remeeus 11 years ago
parent
commit
b2cf48fe80
3 changed files with 82 additions and 12 deletions
  1. 5 3
      Aansturing.java
  2. 68 1
      Bluetooth.java
  3. 9 8
      BoeBot.java

+ 5 - 3
Aansturing.java

@@ -144,10 +144,12 @@ public class Aansturing
        }
        return "bestemming bereikt " + geefCoordinaten();
    }
-   public char[] berekenRoute(int eindx, int eindy, int beginx, int beginy, int rotatie, int maxy1, int maxx1)
+   
+   public char[] berekenRoute(int eindx, int eindy, int beginx, int beginy, int rotatie, int maxxInput, int maxyInput)
    {
-		maxx = maxx1;
-		maxy = maxy1;
+	   maxx = maxxInput;
+	   maxy = maxyInput;
+
        char[] route = new char[40];
        int teller = 0;
        int links = 0;

+ 68 - 1
Bluetooth.java

@@ -38,7 +38,29 @@ public class Bluetooth
             i ++;
           }
         }
-      }
+		
+		if (tempChar == '!')
+		{
+			int i = 0;
+			clearRoute();
+
+			while (true)
+			{
+			  if (rxUart.byteAvailable())
+			  {
+				tempChar = (char)rxUart.receiveByte();
+
+				if(tempChar == '!')
+				{
+				  route[i] = tempChar;
+				  return 3;
+				}
+
+				route[i] = tempChar;
+				i ++;
+			  }
+			}
+		}
 
       else if ((tempChar == 'a') || (tempChar =='v') || (tempChar == 'l') || (tempChar == 'r') || (tempChar == 's'))
       {
@@ -56,6 +78,51 @@ public class Bluetooth
   {
     return route;
   }
+  
+  public int[] getCoordinates()
+  {
+	String[] dataString = new String[40];
+    int[] dataInt = new int[7];
+    String coordinate = "";
+    int StringArrayCount = 0;
+    int intArrayCount = 0;
+	
+	for (int i = 0; route.length > i; i ++)
+    { 
+      if (route[i] != ',' && route[i] != '!')
+      {
+        coordinate += String.valueOf(route[i]);
+      }
+
+      if (route[i] == ',')
+      {
+        dataString[StringArrayCount] = coordinate;
+        coordinate = "";
+        StringArrayCount ++;
+      }
+      
+      if (route[i] == '!')
+      {
+          i = route.length;
+		  StringArrayCount = 0;
+      }
+    }
+
+    for (int i = 0; dataString.length > i; i ++)
+    {
+        if (dataString[i] != null)
+        {
+            dataInt[intArrayCount] = Integer.parseInt(dataString[i]);
+            intArrayCount ++;
+        }
+        
+        if (dataString[i] == null)
+        {
+			intArrayCount = 0;
+			return dataInt;
+        }
+    }
+  }
 
   public int getromoteControl()
   {

+ 9 - 8
BoeBot.java

@@ -13,6 +13,7 @@ public class BoeBot{
         boolean routeAfgerond;
 
         char[] route;
+		int[] coordinates;
         static int currentCase = 4;
         static int currentStep = 0;
 
@@ -36,15 +37,15 @@ public class BoeBot{
                 boolean sparcours = false;
                 int btcode = 0;
                 while(true){
-                        btcode = bluetooth.checkBt();
-						if (btcode == 3)
-						{
+                        btcode = bluetooth.checkBt();
+						if(btcode == 3){
 							System.out.println("Coördinaten ontvangen!");
-							bluetooth.filterData();
-						}
-							
-                        else if(btcode == 2){
-                          System.out.println("Route ontvangen!");
+							coordinates = bluetooth.getCoordinates();
+							aansturing.berekenRoute(coordinats[0], coordinats[1], coordinats[2], coordinats[3], coordinats[4], coordinats[5], coordinats[6]);
+							routeAfgerond = true;
+							currentStep = 0;
+                        }else if(btcode == 2){
+						  System.out.println("Route ontvangen!");
                           route = bluetooth.getRoute();
                           routeAfgerond = true;
                           currentStep = 0;