|
|
|
@ -452,9 +452,16 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
//设置自动工作按钮的点击监听器
|
|
|
|
mainBinding.btnBindAutoWork.setOnClickListener(v -> { |
|
|
|
Robot_AutoWork = 1; // 标志位置 1
|
|
|
|
updateAutoWorkButtonStyle(); // 变色
|
|
|
|
saveOperationLog("开启自动工作模式"); |
|
|
|
if (Robot_AutoWork == 0) { |
|
|
|
// 当前是停止状态 -> 切换为开启
|
|
|
|
Robot_AutoWork = 1; |
|
|
|
saveOperationLog("开启自动工作模式"); |
|
|
|
} else { |
|
|
|
// 当前是开启状态 -> 切换为停止(取消绑定)
|
|
|
|
Robot_AutoWork = 0; |
|
|
|
saveOperationLog("停止自动工作模式"); |
|
|
|
} |
|
|
|
updateAutoWorkButtonStyle(); // 更新按钮样式和文字
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@ -498,14 +505,14 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
deleteOldLogs(); |
|
|
|
|
|
|
|
/* NodePlayer 播放视频区域*/ |
|
|
|
NodePlayer nodePlayer0 = new NodePlayer(this); |
|
|
|
//NodePlayer nodePlayer0 = new NodePlayer(this);
|
|
|
|
// NodePlayer nodePlayer1=new NodePlayer(this);
|
|
|
|
|
|
|
|
//String address0 = "rtsp://192.168.1.168:8554/0";
|
|
|
|
// String address1 = "rtsp://192.168.1.169:8554/0";
|
|
|
|
|
|
|
|
//String addressTest = "rtsp://rtspstream:yEhp9qzAqveM9kHIE7GcL@zephyr.rtsp.stream/movie";
|
|
|
|
String address0 = "rtsp://192.168.144.25:8554/main.264"; |
|
|
|
//String address0 = "rtsp://192.168.144.25:8554/main.264";
|
|
|
|
/**/ |
|
|
|
//VideoPlayerHelper.startVedio(+mainBinding.nodePlayerView0,nodePlayer0,address0);
|
|
|
|
// VideoPlayerHelper.startVedio(mainBinding.nodePlayerView1,nodePlayer1,address1);
|
|
|
|
@ -524,7 +531,6 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
ModbusRtuSlaveService.ModbusRtuSlaveServiceIntialize(serialPortHelper); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int UARTSendCount = 0; |
|
|
|
public int USBSerialPortReceivedTimeCounter = 0; |
|
|
|
|
|
|
|
@ -534,6 +540,9 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
serialPortHelper.onStart(); |
|
|
|
UARTSendCount = 0; |
|
|
|
if (timer == null) { |
|
|
|
timer = new Timer(); |
|
|
|
} |
|
|
|
timer.schedule(new TimerTask() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
@ -552,13 +561,25 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
ModbusRtuSlaveService.holdingRegisters[18]= 1;//在线
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 使用安全的发送值获取方法(只在编辑完成后发送新值)
|
|
|
|
int chgLength = getSafeChgLengthForSending(); |
|
|
|
double manualSpeed = getSafeManualSpeedForSending(); |
|
|
|
double autoSpeed = getSafeAutoSpeedForSending(); |
|
|
|
int force = getSafeForceForSending(); |
|
|
|
|
|
|
|
// 在发送前进行范围限制(二次保障)
|
|
|
|
chgLength = Math.max(0, Math.min(1000, chgLength)); |
|
|
|
manualSpeed = Math.max(0, Math.min(30, manualSpeed)); |
|
|
|
autoSpeed = Math.max(0, Math.min(30, autoSpeed)); |
|
|
|
force = Math.max(300, Math.min(3000, force)); |
|
|
|
|
|
|
|
_toSendPV = _toSendPV.toBuilder() |
|
|
|
.setRobotChgLength(getSafeInt(mainBinding.tvRobotChgLength, 0)) |
|
|
|
.setRobotAutoSpeedBase(getSafeDouble(mainBinding.tvRobotAutoSpeed, 0.0)) |
|
|
|
.setRobotManualSpeedBase(getSafeDouble(mainBinding.tvRobotManualSpeed, 0.0)) |
|
|
|
.setRobotForce(getSafeInt(mainBinding.tvRobotForce, 0)) |
|
|
|
.setRobotChgLength(chgLength) |
|
|
|
.setRobotAutoSpeedBase(autoSpeed) |
|
|
|
.setRobotManualSpeedBase(manualSpeed) |
|
|
|
.setRobotLaneChangeDirection(laneChangeDirection) |
|
|
|
.setRobotForce(force) |
|
|
|
.setRobotAutoWork(Robot_AutoWork) |
|
|
|
.setTimeStamp(System.currentTimeMillis()) |
|
|
|
.build(); |
|
|
|
|
|
|
|
@ -574,6 +595,13 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
AndroidMCUCommunicationMethod = CommunicationMethond.Wired; |
|
|
|
} |
|
|
|
|
|
|
|
// 根据当前的连接方式更新 UI 显示
|
|
|
|
if (AndroidMCUCommunicationMethod == CommunicationMethond.Wired) { |
|
|
|
mainBinding.tvRobotConnect.setText("有线"); |
|
|
|
} else { |
|
|
|
mainBinding.tvRobotConnect.setText("无线"); |
|
|
|
} |
|
|
|
|
|
|
|
if (AndroidMCUCommunicationMethod == CommunicationMethond.Wireless) { |
|
|
|
|
|
|
|
//若sdk有数据返回,则停止发送
|
|
|
|
@ -595,6 +623,34 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
if (ttySerialPortHelper.IsAllButtonSendBack == false) { |
|
|
|
ttySerialPortHelper.SendData(ttySerialPortHelper.getAllChData_50Hz); |
|
|
|
} |
|
|
|
}else |
|
|
|
{ |
|
|
|
//无线模式发送
|
|
|
|
try { |
|
|
|
|
|
|
|
byte[] byteArray = _toSendPV.toByteArray(); |
|
|
|
byte[] sendByteArray = new byte[byteArray.length + 4]; |
|
|
|
byte[] sendByteArray3 = new byte[byteArray.length + 6]; |
|
|
|
|
|
|
|
if (byteArray.length != 0) { |
|
|
|
System.arraycopy(byteArray, 0, sendByteArray, 4, byteArray.length); |
|
|
|
} |
|
|
|
sendByteArray[0] = (byte) 0x55; |
|
|
|
sendByteArray[1] = (byte) 0x55; |
|
|
|
sendByteArray[2] = (byte) 0x01; |
|
|
|
sendByteArray[3] = (byte) 0x01; |
|
|
|
|
|
|
|
byte[] byteArray2 = ModbusCRC.calculateCRC(sendByteArray); |
|
|
|
|
|
|
|
System.arraycopy(sendByteArray, 0, sendByteArray3, 0, sendByteArray.length); |
|
|
|
System.arraycopy(byteArray2, 0, sendByteArray3, sendByteArray3.length - 2, 2); |
|
|
|
|
|
|
|
ttySerialPortHelper.SendData(sendByteArray3); |
|
|
|
|
|
|
|
runOnUiThread(() -> checkMotorErrors()); |
|
|
|
} catch (Exception e) { |
|
|
|
android.util.Log.e("MainActivity", "Error in startSending timer task", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -604,7 +660,7 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
}, 0, 250); // 延迟 0 毫秒,每隔 1000 毫秒执行一次
|
|
|
|
}, 0, 100); // 延迟 0 毫秒,每隔 1000 毫秒执行一次
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@ -629,7 +685,7 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
public void onResume() { |
|
|
|
super.onResume(); |
|
|
|
serialPortHelper.onResume(); |
|
|
|
|
|
|
|
// startSending();
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -707,7 +763,6 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
.setRobotLaneChangeDirection(laneChangeDirection) |
|
|
|
.setRobotForce(force) |
|
|
|
.setRobotAutoWork(Robot_AutoWork) |
|
|
|
.setTimeStamp(System.currentTimeMillis()) |
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
@ -785,11 +840,15 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
//
|
|
|
|
private void updateAutoWorkButtonStyle() { |
|
|
|
if (Robot_AutoWork == 1) { |
|
|
|
// 已开启自动模式:显示高亮颜色,文字变为“取消”
|
|
|
|
mainBinding.btnBindAutoWork.setText("取消自动作业"); |
|
|
|
mainBinding.btnBindAutoWork.setTextColor( |
|
|
|
ContextCompat.getColor(this, R.color.mediumvioletred)); |
|
|
|
mainBinding.btnBindAutoWork.setBackgroundResource(R.drawable.blue_rounded_rectangle); |
|
|
|
|
|
|
|
} else { |
|
|
|
// 未开启自动模式:显示默认颜色,文字变为“绑定”
|
|
|
|
mainBinding.btnBindAutoWork.setText("绑定自动作业"); |
|
|
|
mainBinding.btnBindAutoWork.setTextColor( |
|
|
|
ContextCompat.getColor(this, R.color.deepskyblue)); |
|
|
|
mainBinding.btnBindAutoWork.setBackgroundResource(R.drawable.blue_rounded_rectangle); |
|
|
|
|