diff --git a/AndroidManifest.xml b/AndroidManifest.xml index bce1ee6..4dadd63 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -17,8 +17,8 @@ + android:versionCode="140404" + android:versionName="14.04.04" > 0) msg[0] |= MotorMasks.DIRECTION; + // Set the recenter bits. + msg[0] |= (event.getMotor() == motor_t.RECENTER) ? MotorMasks.RECENTER : 0; + if((msg[0] & MotorMasks.RECENTER) > 0) + Logger.log_i(TAG, CLASS_NAME + ".run(): Recenter received."); + + // Set the power byte. + msg[1] = (byte)Math.abs(event.getPower()); + + // Send the message. + btComm.writeMessage(msg); Logger.log_i(TAG, CLASS_NAME + ".run() :: Message sent to the robot."); try{ sleep(40); }catch(InterruptedException ie){ } @@ -87,10 +90,6 @@ public class LCPThread extends Thread{ }catch(IOException io){ Logger.log_e(TAG, CLASS_NAME + ".run() :: IOException sending message to the robot: " + io.getMessage()); } - - if(reportSensors){ - - } }else{ Logger.log_e(TAG, CLASS_NAME + ".run() :: The robot disconnected or was never available."); break; diff --git a/src/ve/ucv/ciens/ccg/nxtcam/network/SensorReportThread.java b/src/ve/ucv/ciens/ccg/nxtcam/network/SensorReportThread.java index 5bff72e..32d9cc6 100644 --- a/src/ve/ucv/ciens/ccg/nxtcam/network/SensorReportThread.java +++ b/src/ve/ucv/ciens/ccg/nxtcam/network/SensorReportThread.java @@ -1,7 +1,7 @@ package ve.ucv.ciens.ccg.nxtcam.network; import java.io.IOException; -import java.io.ObjectOutputStream; +import java.io.OutputStream; import java.net.Socket; import ve.ucv.ciens.ccg.nxtcam.utils.Logger; @@ -14,21 +14,36 @@ public class SensorReportThread extends Thread{ private Socket socket; private String serverIp; private boolean done; - private ObjectOutputStream writer; + private OutputStream writer; private boolean connected; + private BTCommunicator btComm; public SensorReportThread(String serverIp){ super("Sensor Report Thread"); this.serverIp = serverIp; done = false; connected = false; + btComm = BTCommunicator.getInstance(); } @Override public void run(){ + byte[] lightReading; + if(connectToServer()){ while(!done){ - + if(btComm.isBTEnabled() && btComm.isConnected()){ + try{ + lightReading = btComm.readMessage(1); + writer.write(lightReading); + }catch(IOException io){ + Logger.log_e(TAG, CLASS_NAME + "run(): IOException: " + io.getMessage()); + done = true; + } + }else{ + Logger.log_e(TAG, CLASS_NAME + ".run() :: The robot disconnected or was never available."); + break; + } } }else{ Logger.log_e(TAG, CLASS_NAME + ".run() :: Could not connect to the server."); @@ -43,7 +58,7 @@ public class SensorReportThread extends Thread{ boolean connected; try{ socket = new Socket(serverIp, ProjectConstants.SENSOR_REPORT_PORT); - writer = new ObjectOutputStream(socket.getOutputStream()); + writer = socket.getOutputStream(); connected = true; }catch(IOException io){ Logger.log_e(TAG, CLASS_NAME + ".connectToServer() :: IOException caught: " + io.getMessage()); diff --git a/src/ve/ucv/ciens/ccg/nxtcam/network/VideoStreamingThread.java b/src/ve/ucv/ciens/ccg/nxtcam/network/VideoStreamingThread.java index fb2f565..91bdf27 100644 --- a/src/ve/ucv/ciens/ccg/nxtcam/network/VideoStreamingThread.java +++ b/src/ve/ucv/ciens/ccg/nxtcam/network/VideoStreamingThread.java @@ -107,7 +107,7 @@ public class VideoStreamingThread extends Thread{ imageSize = camMonitor.getImageParameters(); yuvImage = new YuvImage(image, ImageFormat.NV21, imageSize.width(), imageSize.height(), null); - yuvImage.compressToJpeg(imageSize, 100, outputStream); + yuvImage.compressToJpeg(imageSize, 90, outputStream); message = new VideoFrameDataMessage(); message.data = outputStream.toByteArray(); diff --git a/src/ve/ucv/ciens/ccg/nxtcam/network/protocols/MotorMasks.java b/src/ve/ucv/ciens/ccg/nxtcam/network/protocols/MotorMasks.java new file mode 100644 index 0000000..1c0bd61 --- /dev/null +++ b/src/ve/ucv/ciens/ccg/nxtcam/network/protocols/MotorMasks.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 Miguel Angel Astor Romero + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ve.ucv.ciens.ccg.nxtcam.network.protocols; + +/** + *

Bit masks used to code/decode the control instructions sent by NxtAR-cam to + * NxtAR-bot.

+ *

Expansions 1-3 are currently unused.

+ */ +public abstract class MotorMasks { + public static final byte MOTOR_A = (byte)0x01; + public static final byte MOTOR_B = (byte)0x02; + public static final byte MOTOR_C = (byte)0x04; + public static final byte DIRECTION = (byte)0x08; + public static final byte RECENTER = (byte)0x10; + public static final byte EXPANSION_1 = (byte)0x20; + public static final byte EXPANSION_2 = (byte)0x20; + public static final byte EXPANSION_3 = (byte)0x20; +}