Service discovery and tcp connections work now.

This commit is contained in:
2013-11-26 17:59:21 -04:30
parent 569889ab83
commit 8ef038fe53
5 changed files with 25 additions and 8 deletions

View File

@@ -27,5 +27,7 @@
<string name="conn_failed">No se pudo conectar con el robot</string>
<string name="bt_wait">Por favor espere por la conexión</string>
<string name="serv_wait">Por favor espere, buscando dispositivo de control</string>
<string name="serv_connected">Conectado con el dispositivo de control</string>
<string name="serv_fail">Falló la conexión con el dispositivo de control</string>
</resources>

View File

@@ -27,5 +27,7 @@
<string name="conn_failed">Could not connect with the robot</string>
<string name="bt_wait">Please wait for the connection</string>
<string name="serv_wait">Please wait, looking for control device</string>
<string name="serv_connected">Connected with the control device</string>
<string name="serv_fail">Could no connect with the control device</string>
</resources>

View File

@@ -120,6 +120,8 @@ public class CamActivity extends Activity{
@Override
protected void onPostExecute(Camera result) {
super.onPostExecute(result);
hwCamera = result;
if(result != null){
Logger.log_d(TAG, CLASS_NAME + ".onPostExecute() :: Camera successfully opened");
@@ -128,8 +130,6 @@ public class CamActivity extends Activity{
Toast.makeText(getApplicationContext(), R.string.camera_failure, Toast.LENGTH_LONG).show();
}
startCameraPreview();
super.onPostExecute(result);
}
};
}

View File

@@ -4,6 +4,7 @@ import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.Socket;
import ve.ucv.ciens.ccg.nxtcam.dialogs.ConnectRobotDialog;
import ve.ucv.ciens.ccg.nxtcam.dialogs.ConnectRobotDialog.ConnectRobotDialogListener;
@@ -314,7 +315,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
@Override
protected Boolean doInBackground(Void... params){
boolean result, done = false;
byte[] buffer = (new String("Server is here")).getBytes();
byte[] buffer = (new String("NxtAR server here!")).getBytes();
// Create a buffer and tell Android we want to receive multicast datagrams.
packet = new DatagramPacket(buffer, buffer.length);
@@ -330,8 +331,14 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
udpSocket.receive(packet);
Logger.log_d(TAG, CLASS_NAME + ".run() :: Found a server at " + packet.getAddress().getHostAddress());
String received = new String(packet.getData());
Logger.log_d(TAG, CLASS_NAME + ".doInBackground() :: Packet payload is\n" + received);
if(received.compareTo("NxtAR server here!") == 0)
done = true;
Socket client1, client2;
client1 = new Socket(packet.getAddress(), ProjectConstants.SERVER_TCP_PORT_1);
client1.close();
client2 = new Socket(packet.getAddress(), ProjectConstants.SERVER_TCP_PORT_2);
client2.close();
}
result = true;
}catch(IOException io){
@@ -356,10 +363,15 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
progressDialog = null;
// If a server was found then start the next activity.
if(packet != null)
startCamActivity(result, packet.getAddress().getHostAddress());
else
startCamActivity(false, null);
startButton.setEnabled(false);
if(packet != null){
showToast(R.string.serv_connected, Toast.LENGTH_SHORT);
// startCamActivity(result, packet.getAddress().getHostAddress());
}else{
showToast(R.string.serv_fail, Toast.LENGTH_SHORT);
// startCamActivity(false, null);
}
}
}
@@ -406,6 +418,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
if(result){
Logger.log_d(TAG, CLASS_NAME + "doInBackground() :: Connection successful.");
showToast(R.string.conn_established, Toast.LENGTH_SHORT);
startButton.setEnabled(true);
}else{
Logger.log_d(TAG, CLASS_NAME + "doInBackground() :: Connection failed.");
showToast(R.string.conn_failed, Toast.LENGTH_LONG);

View File

@@ -20,7 +20,7 @@ import android.util.Log;
* @since 2012-10-15
*/
public class BTCommunicator{
private static final String TAG = "NXT_TEST_BTCOMM";
private static final String TAG = "NXTCAM_BTCOMM";
private final String CLASS_NAME = BTCommunicator.class.getSimpleName();
private boolean connected;