Service discovery and tcp connections work now.
This commit is contained in:
@@ -27,5 +27,7 @@
|
|||||||
<string name="conn_failed">No se pudo conectar con el robot</string>
|
<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="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_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>
|
</resources>
|
||||||
|
@@ -27,5 +27,7 @@
|
|||||||
<string name="conn_failed">Could not connect with the robot</string>
|
<string name="conn_failed">Could not connect with the robot</string>
|
||||||
<string name="bt_wait">Please wait for the connection</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_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>
|
</resources>
|
@@ -120,6 +120,8 @@ public class CamActivity extends Activity{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Camera result) {
|
protected void onPostExecute(Camera result) {
|
||||||
|
super.onPostExecute(result);
|
||||||
|
|
||||||
hwCamera = result;
|
hwCamera = result;
|
||||||
if(result != null){
|
if(result != null){
|
||||||
Logger.log_d(TAG, CLASS_NAME + ".onPostExecute() :: Camera successfully opened");
|
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();
|
Toast.makeText(getApplicationContext(), R.string.camera_failure, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
startCameraPreview();
|
startCameraPreview();
|
||||||
|
|
||||||
super.onPostExecute(result);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtcam.dialogs.ConnectRobotDialog;
|
import ve.ucv.ciens.ccg.nxtcam.dialogs.ConnectRobotDialog;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.dialogs.ConnectRobotDialog.ConnectRobotDialogListener;
|
import ve.ucv.ciens.ccg.nxtcam.dialogs.ConnectRobotDialog.ConnectRobotDialogListener;
|
||||||
@@ -314,7 +315,7 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... params){
|
protected Boolean doInBackground(Void... params){
|
||||||
boolean result, done = false;
|
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.
|
// Create a buffer and tell Android we want to receive multicast datagrams.
|
||||||
packet = new DatagramPacket(buffer, buffer.length);
|
packet = new DatagramPacket(buffer, buffer.length);
|
||||||
@@ -330,8 +331,14 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
udpSocket.receive(packet);
|
udpSocket.receive(packet);
|
||||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Found a server at " + packet.getAddress().getHostAddress());
|
Logger.log_d(TAG, CLASS_NAME + ".run() :: Found a server at " + packet.getAddress().getHostAddress());
|
||||||
String received = new String(packet.getData());
|
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)
|
if(received.compareTo("NxtAR server here!") == 0)
|
||||||
done = true;
|
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;
|
result = true;
|
||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
@@ -356,10 +363,15 @@ public class MainActivity extends Activity implements WifiOnDialogListener, Conn
|
|||||||
progressDialog = null;
|
progressDialog = null;
|
||||||
|
|
||||||
// If a server was found then start the next activity.
|
// If a server was found then start the next activity.
|
||||||
if(packet != null)
|
startButton.setEnabled(false);
|
||||||
startCamActivity(result, packet.getAddress().getHostAddress());
|
|
||||||
else
|
if(packet != null){
|
||||||
startCamActivity(false, 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){
|
if(result){
|
||||||
Logger.log_d(TAG, CLASS_NAME + "doInBackground() :: Connection successful.");
|
Logger.log_d(TAG, CLASS_NAME + "doInBackground() :: Connection successful.");
|
||||||
showToast(R.string.conn_established, Toast.LENGTH_SHORT);
|
showToast(R.string.conn_established, Toast.LENGTH_SHORT);
|
||||||
|
startButton.setEnabled(true);
|
||||||
}else{
|
}else{
|
||||||
Logger.log_d(TAG, CLASS_NAME + "doInBackground() :: Connection failed.");
|
Logger.log_d(TAG, CLASS_NAME + "doInBackground() :: Connection failed.");
|
||||||
showToast(R.string.conn_failed, Toast.LENGTH_LONG);
|
showToast(R.string.conn_failed, Toast.LENGTH_LONG);
|
||||||
|
@@ -20,7 +20,7 @@ import android.util.Log;
|
|||||||
* @since 2012-10-15
|
* @since 2012-10-15
|
||||||
*/
|
*/
|
||||||
public class BTCommunicator{
|
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 final String CLASS_NAME = BTCommunicator.class.getSimpleName();
|
||||||
|
|
||||||
private boolean connected;
|
private boolean connected;
|
||||||
|
Reference in New Issue
Block a user