diff --git a/app/build.gradle b/app/build.gradle
index 83ad04a3..431da601 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -131,6 +131,9 @@ dependencies {
//Modbus
implementation 'com.github.licheedev:Modbus4Android:2.0.2'
+ //Modbus server
+ implementation 'com.github.hwx95:ModbusTCP:v1.1'
+
//下载进度条
implementation 'com.github.Ccapton:Android-ColorfulProgressBar:1.0.5'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 72d75343..29a4e59f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -39,9 +39,6 @@
-
{
- Log.i("TAG", "onClick: 确认参数配置");
- DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
- });
-
- //参数配置界面取消按钮
- ButtonClickBinder(mParSetVisual, R.id.parset_cancel_btn, ()->{
- Log.i("TAG", "onClick: 退出参数配置");
- DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
- });
-
- DialogManager.getInstance().hide(mDialogVisual);//关闭商品选择窗口
- DialogManager.getInstance().show(mParSetVisual,R.id.parset_close_dialog); //打开参数设置窗口
-
- ParSetInit(R.id.location_selection,new String[] {"0", "1", "2", "3", "4","5","6"});
- ParSetInit(R.id.accessories_selection_1,new String[] {"0", "1", "2", "3", "4","5","6","7","8"});
- ParSetInit(R.id.accessories_selection_2,new String[] {"0", "1", "2", "3", "4","5","6","7","8"});
- }
- });
- DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
- }
- });
- }
-
- private void ParSetInit(int id,String[] args)
- {
- Spinner sp = mParSetVisual.findViewById(id);
- ArrayAdapter starAdapter = new ArrayAdapter(getBaseContext(), R.layout.select_item, args);
- sp.setAdapter(starAdapter);
- sp.setSelection(0);
- sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
-
- }
-
- @Override
- public void onNothingSelected(AdapterView> adapterView) {
-
- }
- });
- }
-
- /**
- * 弹框按钮事件绑定
- * @param dv 弹框页面
- * @param id 按钮id
- * @param action 执行委托
- */
- private void ButtonClickBinder(DialogView dv,int id, IRun action){
- if(dv!=null&& !dv.findViewById(id).hasOnClickListeners()){
- dv.findViewById(id).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if(action!=null) action.Run();
- }
- });
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/bonait/bnframework/business/AddressData.java b/app/src/main/java/com/bonait/bnframework/business/AddressData.java
new file mode 100644
index 00000000..0e34a0fd
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/business/AddressData.java
@@ -0,0 +1,95 @@
+package com.bonait.bnframework.business;
+
+public class AddressData {
+
+ /**
+ * 炒锅空闲状态
+ */
+ public static int FryingPanHide=1;
+
+ /**
+ * 炒锅出餐完成
+ */
+ public static int FryingPanDiningOut=2;
+
+ /**
+ * 炒锅投主料完成
+ */
+ public static int FryingPnaMainMaterialComplete=3;
+
+ /**
+ * 炒锅请求投辅料
+ */
+ public static int FryingPanRequestAccessories=4;
+
+ /**
+ * 商品数据验证
+ */
+ public static int GoodDataVery=5;
+
+ /**
+ * 投料机构状态
+ */
+ public static int FeedingMechanism=6;
+
+ /**
+ * 心跳状态
+ */
+ public static int Heartbeat=7;
+
+ /**
+ * 炒菜完成,请求出餐
+ */
+ public static int RequestingMeaDelivery=8;
+
+ /**
+ * 出餐减速到位
+ */
+ public static int DecelerationInPlace=9;
+
+ /**
+ * 投主料请求
+ */
+ public static int AddIngredientsRequest=10;
+
+ /**
+ * 炒锅强制结束信号
+ */
+ public static int FryingpanForceEnd=11;
+
+ /**
+ * 机器人放主料完成
+ */
+ public static int PutMainMaterial=51;
+
+ /**
+ * 机器人放辅料完成
+ */
+ public static int PutAccessories=52;
+
+ /**
+ * 机器人到达出餐位
+ */
+ public static int RobotServingSpace=53;
+
+ /**
+ * 商品下发
+ */
+ public static int GoodDown=54;
+
+ /**
+ * 机器人急停
+ */
+ public static int EStop=55;
+
+ /**
+ * 机器人投主料完成
+ */
+ public static int RobotPutIngredientsComplete=56;
+
+ /**
+ * 强制结束
+ */
+ public static int ForceEnd=57;
+
+}
diff --git a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java
index c9b5c021..23fb8a26 100644
--- a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java
+++ b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java
@@ -297,27 +297,55 @@ public class ConfigData {
OkGo.>get(ConfigName.getInstance().SaasAddress + ConfigName.getInstance().GetStore + ConfigName.getInstance().ClientAutoKey)
.tag(context)
.execute(new JsonDialogCallback>(context) {
- @Override
- public void onSuccess(Response> response) {
- ResAPI organize = response.body();
- if (organize.isSuccess) {
- ConfigName.getInstance().organizeMode = organize.data;
-
- OkGo.>get(String.format(ConfigName.getInstance().SaasAddress + ConfigName.getInstance().GetDeviceInformation, ConfigName.getInstance().organizeMode.id, ConfigName.getInstance().DeviceAutoKey)).tag(context).headers(new HttpHeaders("TenantId", ConfigName.getInstance().organizeMode.companyId)).execute(new JsonDialogCallback>(context) {
- @Override
- public void onSuccess(Response> response) {
- ResAPI deviceInformation = response.body();
- if (deviceInformation.succeeded) {
- ConfigName.getInstance().deviceInformation = deviceInformation.data;
- if (ConfigName.getInstance().deviceInformation != null) {
- ConfigName.getInstance().DeviceId = ConfigName.getInstance().deviceInformation.id;
+ @Override
+ public void onSuccess(Response> response) {
+ ResAPI organize = response.body();
+ if (organize.isSuccess) {
+ ConfigName.getInstance().organizeMode = organize.data;
+ OkGo.>get(String.format(ConfigName.getInstance().SaasAddress + ConfigName.getInstance().GetDeviceInformation, ConfigName.getInstance().organizeMode.id, ConfigName.getInstance().DeviceAutoKey)).tag(context).headers(new HttpHeaders("TenantId", ConfigName.getInstance().organizeMode.companyId)).execute(new JsonDialogCallback>(context) {
+ @Override
+ public void onSuccess(Response> response) {
+ ResAPI deviceInformation = response.body();
+ if (deviceInformation.succeeded) {
+ ConfigName.getInstance().deviceInformation = deviceInformation.data;
+ if (ConfigName.getInstance().deviceInformation != null) {
+ ConfigName.getInstance().DeviceId = ConfigName.getInstance().deviceInformation.id;
+ MessageManager.getInstance().sendMessage(MessageName.GetOrganize, "GetOrganize");
+ }
+ }
}
- }
+ });
}
- });
- }
- }
- });
+ }
+ });
+
+
+
+// //获取店铺信息
+// OkGo.>get(ConfigName.getInstance().SaasAddress + ConfigName.getInstance().GetStore + ConfigName.getInstance().ClientAutoKey)
+// .tag(context)
+// .execute(new JsonDialogCallback>(context) {
+// @Override
+// public void onSuccess(Response> response) {
+// ResAPI organize = response.body();
+// if (organize.isSuccess) {
+// ConfigName.getInstance().organizeMode = organize.data;
+//
+// OkGo.>get(String.format(ConfigName.getInstance().SaasAddress + ConfigName.getInstance().GetDeviceInformation, ConfigName.getInstance().organizeMode.id, ConfigName.getInstance().DeviceAutoKey)).tag(context).headers(new HttpHeaders("TenantId", ConfigName.getInstance().organizeMode.companyId)).execute(new JsonDialogCallback>(context) {
+// @Override
+// public void onSuccess(Response> response) {
+// ResAPI deviceInformation = response.body();
+// if (deviceInformation.succeeded) {
+// ConfigName.getInstance().deviceInformation = deviceInformation.data;
+// if (ConfigName.getInstance().deviceInformation != null) {
+// ConfigName.getInstance().DeviceId = ConfigName.getInstance().deviceInformation.id;
+// }
+// }
+// }
+// });
+// }
+// }
+// });
} else {
ToastUtils.warning("无网络,请先连接网络!!!");
}
diff --git a/app/src/main/java/com/bonait/bnframework/business/ControlBase.java b/app/src/main/java/com/bonait/bnframework/business/ControlBase.java
new file mode 100644
index 00000000..4817acd1
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/business/ControlBase.java
@@ -0,0 +1,414 @@
+package com.bonait.bnframework.business;
+
+import com.bonait.bnframework.common.ModbusSlave.ModbusTcpSlave;
+import com.bonait.bnframework.common.constant.ConfigName;
+import com.bonait.bnframework.common.db.res.UserLogEnum;
+import com.bonait.bnframework.common.helper.I.IThread;
+import com.bonait.bnframework.common.helper.MessageLog;
+import com.bonait.bnframework.common.helper.ThreadManager;
+import com.bonait.bnframework.common.modbus.IOperateResult;
+import com.bonait.bnframework.common.modbus.ModbusMaster;
+import com.bonait.bnframework.common.utils.ToastUtils;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+public abstract class ControlBase {
+
+ public void Init(){
+
+ RobotData.FryingStatus.put(1,new FryingPanData());
+ RobotData.FryingStatus.put(2,new FryingPanData());
+ RobotData.FryingStatus.put(3,new FryingPanData());
+ RobotData.FryingStatus.put(4,new FryingPanData());
+ HeartbeatStatusListen();
+ ConnectRobot();
+
+
+ ThreadManager.Get().StartLong("炒锅控制业务", true, new IThread() {
+ @Override
+ public void Run() throws InterruptedException {
+
+ Control();
+ Thread.sleep(100);
+ }
+
+ @Override
+ public void RunComplete() throws InterruptedException {
+
+ }
+ });
+
+ MbSlave.Init();
+ }
+
+ /**
+ * 根据炒锅编号解析对应的炒锅控制地址
+ * @param num
+ * @param offset
+ * @return
+ */
+ protected int GetAddress(int num,int offset)
+ {
+ return (num-1)*100+offset;
+ }
+
+ protected int GetHoldAdd(int num,int offset){
+ return (num-1)*20+offset;
+ }
+
+ protected Integer GetRobotAdd(int num,int offset){
+ //M500--4596
+// return "M"+ 500+offset+(num-1)*10;
+ return 4596+offset+(num-1)*10;
+ }
+
+ /**
+ * 获取心跳状态
+ * @param num
+ * @return
+ */
+ protected boolean GetHeartbeatStatus(int num){
+ return HeartbeatStatus[num-1];
+ }
+
+ /**
+ * 炒锅心跳状态
+ */
+ protected boolean[] HeartbeatStatus=new boolean[4];
+
+ /**
+ * 炒锅心跳时间
+ */
+ protected long[] StartTime=new long[4];
+
+ /**
+ * 强制结束信号
+ */
+ protected boolean[] ForceEnd =new boolean[4];//强制结束
+
+ /**
+ * 需要移除的任务
+ */
+ protected List RemoveId=new ArrayList();
+
+ /**
+ * 强制结束指定炒锅任务
+ * @param num
+ */
+ public void SetForceEnd(int num){
+ if(num>0){
+ ForceEnd[num-1]=true;
+ }
+ }
+
+ /**
+ * 复位强制结束信号
+ * @param num
+ */
+ private void resetForceEnd(int num){
+ if(num>0){
+ ForceEnd[num-1]=false;
+ }
+ }
+
+ /**
+ * 设备心跳超时时间
+ */
+ protected long TimeOut=5000;
+ public LinkedHashMap FryingPan=new LinkedHashMap<>();
+ protected ModbusTcpSlave MbSlave=new ModbusTcpSlave();
+
+ /**
+ * 机器人地址解析
+ * @param address
+ * @return
+ */
+ public String RobotAddress(String address){
+ if (address == null) return "";
+ if (address.length() > 0) {
+ address = address.trim();
+ if (address.toUpperCase().contains("M") &&address.length() >=2){
+ String res = address.substring(1);
+ if (res != null) {
+ try {
+ Integer tempAdd = Integer.parseInt(res);
+ if(tempAdd>=0){
+ return (tempAdd+4096)+"";
+ }
+ } catch (NumberFormatException e) {
+ return "";
+ }
+ }
+ }
+ }
+ return "";
+ }
+
+ protected void ConnectRobot(){
+ new Thread(()->{
+ try {
+ ModbusMaster.get().TcpConnect(ConfigName.getInstance().Address, ConfigName.getInstance().Post, new IOperateResult() {
+ @Override
+ public void onSuccess() {
+ ConfigName.getInstance().PlcIsConnect = true;
+ ThreadManager.Get().StartLong("机器人数据监听", true, new IThread() {
+ @Override
+ public void Run() throws InterruptedException {
+
+ RobotDataListen();
+ Thread.sleep(100);
+ }
+
+ @Override
+ public void RunComplete() throws InterruptedException {
+
+ }
+ });
+ }
+
+ @Override
+ public void onFailure(String message) {
+ ConfigName.getInstance().PlcIsConnect = false;
+// ToastUtils.info("设备 " + ConfigName.getInstance().Address + " 连接失败:" + message);
+ }
+
+ @Override
+ public void onFinally() {
+
+ }
+ });
+ }catch (Exception e )
+ {
+ MessageLog.ShowInfo("重新连接Modbus异常," + e.getMessage());
+ }
+ }).start();
+ }
+
+ /**
+ * 商品是否验证成功
+ * @param num
+ * @return
+ */
+ public boolean GetGoodVery(int num){
+ return MbSlave.ReadBoolean(GetAddress(num,AddressData.GoodDataVery));
+ }
+
+ /**
+ * 获取指定炒锅的状态
+ * @param num
+ * @return
+ */
+ public boolean GetFryingPan(int num){
+ return MbSlave.ReadBoolean(GetAddress(num,AddressData.FryingPanHide))&&GetHeartbeatStatus(num);
+ }
+
+ /**
+ * 商品下发
+ */
+ public void GoodDown(String id,int num){
+ MbSlave.WriteBoolean(GetAddress(num,AddressData.GoodDataVery),false);//复位商品验证
+ MbSlave.WriteBoolean(GetAddress(num,AddressData.PutMainMaterial),false);//复位放主料完成
+ MbSlave.WriteBoolean(GetAddress(num,AddressData.PutAccessories),false);//复位放辅料完成
+ MbSlave.WriteBoolean(GetAddress(num,AddressData.RobotServingSpace),false);//复位机器人到达出餐位
+ MbSlave.WriteString(id,GetHoldAdd(num,0));//写入商品ID
+ MbSlave.WriteBoolean(GetAddress(num,AddressData.GoodDown),true);//写入商品下发
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"写入的商品id"+id);
+ }
+
+ /**
+ * 强制结束信号检测
+ * @param num
+ * @return
+ */
+ protected boolean EndProcess(int num){
+ if(ForceEnd[num-1]||MbSlave.ReadBoolean(GetAddress(num,AddressData.FryingpanForceEnd))){
+ MbSlave.WriteBoolean(GetAddress(num,AddressData.ForceEnd),true);//强制结束
+ MbSlave.WriteBoolean(GetAddress(num,AddressData.FryingpanForceEnd),false);//复位炒锅强制结束信号
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,num+" 号炒锅取消任务");
+ if(FryingPan.containsKey(num))
+ RemoveId.add(num);
+ return true;
+ }
+ else return false;
+ }
+
+ protected int GetBooleanIndex(boolean[] bools,boolean value){
+ if(bools==null)return -1;
+ int index=-1;
+ for(int i=0;i=2000)
+ MbSlave.WriteBoolean(GetAddress(i+1,AddressData.Heartbeat),true);
+
+ HeartbeatStatus[i]=(System.currentTimeMillis()-StartTime[i])<=TimeOut;
+
+ if ( HeartbeatStatus[i]&&MbSlave.ReadBoolean(GetAddress(i+1,AddressData.FryingPanHide))){
+ status[i]="空闲中";
+ }
+ else{
+ status[i]="忙碌中";
+ }
+ }
+
+ if(statusNotify!=null)
+ statusNotify.OnStatusChanged(status[0],status[1],status[2],status[3]);
+ Thread.sleep(100);
+ }
+
+ @Override
+ public void RunComplete() throws InterruptedException {
+
+ }
+ });
+ }
+
+ /**
+ * 机器人投主料控制
+ * @param IngredientsLocs 主料位置
+ * @param FryingPanNum 炒锅位置
+ */
+ protected void RobotFeedingMainMaterials(short IngredientsLocs,short FryingPanNum){
+ try
+ {
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从"+IngredientsLocs+"号主料位,放主料到"+FryingPanNum + "号锅");
+ ModbusMaster.get().WriteShort("GI0",IngredientsLocs,1,null);//写入机器人主任务,指定主料位置
+ ModbusMaster.get().WriteShort("GI1",FryingPanNum,1,null);//写入机器人子任务,指定炒锅位置
+ ModbusMaster.get().WriteBool(GetRobotAdd(FryingPanNum,0).toString(),true,1,null);//写入机器人允许放料信号
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人放菜完成");
+ while(!RobotData.FryingStatus.get(FryingPanNum).PutMaterialComplete&&!ForceEnd[FryingPanNum-1]){Thread.sleep(100); }//等待放主料完成
+ if(EndProcess(FryingPanNum))return;
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人放菜完成");
+ MbSlave.WriteBoolean(GetAddress(FryingPanNum,AddressData.RobotPutIngredientsComplete),true);//机器人放主料完成
+ }
+ catch(InterruptedException ex){
+
+ }
+ }
+
+ /**
+ * 机器人投辅料控制
+ * @param AccessoriesLoc 辅料位置
+ * @param FryingPanNum 炒锅位置
+ */
+ protected void RobotFeedingAuxiliaryMaterials(short AccessoriesLoc,short FryingPanNum){
+ try
+ {
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从" +AccessoriesLoc+"号辅料位,放辅料到"+FryingPanNum + "号锅");
+ MbSlave.WriteBoolean(GetAddress(FryingPanNum,AddressData.FryingPanRequestAccessories),false);//复位投辅料请求信号
+ ModbusMaster.get().WriteShort("GI0",AccessoriesLoc,1,null);//写入机器人主任务,设置辅料位置
+ ModbusMaster.get().WriteShort("GI2",FryingPanNum,1,null);//写入机器人子任务,设置炒锅位置
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人倒调料完成");
+ while(!RobotData.FryingStatus.get(FryingPanNum).FallSeasoningComplete&&!ForceEnd[FryingPanNum-1]){Thread.sleep(100);}//等待机器人倒调料完成
+ MbSlave.WriteString(GetHoldAdd(FryingPanNum,0));//复位商品id
+ if(EndProcess(FryingPanNum))return;
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人倒调料完成");
+ MbSlave.WriteBoolean(GetAddress(FryingPanNum,AddressData.PutAccessories),true);//设置机器人放辅料完成信号
+ }
+ catch(InterruptedException ex){
+
+ }
+ }
+
+ /**
+ * 移除任务检测
+ */
+ protected void RemoveTask(){
+ for(Integer key:RemoveId){
+ if(FryingPan.containsKey(key))
+ {
+ FryingPan.remove(key);
+ resetForceEnd(key);
+ if (completeNotify!=null)
+ completeNotify.onComplete(key);
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"删除"+key+"号炒锅任务");
+ }
+ }
+ RemoveId.clear();
+ }
+
+ /**
+ * 机器人出餐控制
+ * @param FryingPanNum 炒锅位置
+ */
+ protected void RobotMealControl(int FryingPanNum){
+ try
+ {
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人到"+FryingPanNum+"号炒锅位置");
+ //等待机器人到达炒锅位置
+ while(!RobotData.FryingStatus.get(FryingPanNum).RequestDiningOut&&!ForceEnd[FryingPanNum-1]){Thread.sleep(100);}
+ if(EndProcess(FryingPanNum))return;
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人到"+FryingPanNum+"号炒锅位置");
+ MbSlave.WriteBoolean(GetAddress(FryingPanNum,AddressData.RobotServingSpace),true);//通知炒锅,机器人到达出餐位
+
+ //等待炒锅到达减速位
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人到"+FryingPanNum+"号炒锅减速位置");
+ while (!MbSlave.ReadBoolean(GetAddress(FryingPanNum,AddressData.DecelerationInPlace))&&!ForceEnd[FryingPanNum-1]){Thread.sleep(50);}
+ if(EndProcess(FryingPanNum)) return;
+ ModbusMaster.get().WriteBool(GetRobotAdd(FryingPanNum,1).toString(),true,1,null);//设置机器人炒锅减速到位
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人到达"+FryingPanNum+"号炒锅减速位置");
+
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待"+FryingPanNum+"号炒锅出餐完成");
+ //等待炒锅出餐完成
+ while (!MbSlave.ReadBoolean(GetAddress(FryingPanNum,AddressData.FryingPanDiningOut))&&!ForceEnd[FryingPanNum-1]){Thread.sleep(100);}
+ if(EndProcess(FryingPanNum)) return;
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,FryingPanNum+"号炒锅出餐完成");
+
+ //设置机器人出餐完成
+ ModbusMaster.get().WriteBool(GetRobotAdd(FryingPanNum,2).toString(),true,1,null);
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人出餐完成");
+ //等待机器人出餐完成
+ while(!RobotData.FryingStatus.get(FryingPanNum).DiningOutComplete&&!ForceEnd[FryingPanNum-1]){Thread.sleep(100);}
+ if(EndProcess(FryingPanNum)) return;
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人出餐完成");
+ MbSlave.WriteBoolean(GetAddress(FryingPanNum,AddressData.RequestingMeaDelivery),false);; //复位炒菜完成,出餐请求
+ MbSlave.WriteBoolean(GetAddress(FryingPanNum,AddressData.FryingPanDiningOut),false); //复位炒锅出餐完成信号
+
+ //通知界面可以继续下发任务
+ if (completeNotify!=null)
+ {
+ completeNotify.onComplete(FryingPanNum);
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"通知界面"+FryingPanNum+"号炒锅执行完成");
+ }
+
+ if(FryingPan.containsKey(FryingPanNum))
+ RemoveId.add(FryingPanNum);
+
+ }
+ catch(InterruptedException ex){
+
+ }
+ }
+
+ protected abstract void RobotDataListen()throws InterruptedException;
+
+ protected abstract void Control()throws InterruptedException;
+
+}
diff --git a/app/src/main/java/com/bonait/bnframework/business/DoubleFryingpanControl.java b/app/src/main/java/com/bonait/bnframework/business/DoubleFryingpanControl.java
new file mode 100644
index 00000000..e5ca0afa
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/business/DoubleFryingpanControl.java
@@ -0,0 +1,321 @@
+package com.bonait.bnframework.business;
+
+import android.util.Log;
+
+import com.bonait.bnframework.common.db.res.UserLogEnum;
+import com.bonait.bnframework.common.helper.MessageLog;
+import com.bonait.bnframework.common.modbus.ModbusMaster;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DoubleFryingpanControl extends ControlBase {
+ private static DoubleFryingpanControl mInstance; //实例变量设置私有,防止直接通过类名访问
+
+ public static synchronized DoubleFryingpanControl getInstance() { //静态同步方法作为唯一的实例对象获取方式
+ if (mInstance == null) {
+ mInstance = new DoubleFryingpanControl();
+ }
+ return mInstance;
+ }
+
+ private DoubleFryingpanControl() {
+
+ }
+
+ @Override
+ public void RobotDataListen()throws InterruptedException{
+ //机器人急停
+// ModbusMaster.get().ReadBool("M640",1,1, value->{
+// for (int i =0;i<4;i++){
+// MbSlave.WriteBoolean(GetAddress(i+1,AddressData.EStop),value[0]);
+// }
+// });
+
+ //机器人入库完成
+ ModbusMaster.get().ReadBool(RobotAddress("M620"),6,1,value->{
+ RobotData.RobotWarehousingComplete=value;
+ });
+
+ //指定位置有盆
+ ModbusMaster.get().ReadBool(RobotAddress("M630"),4,1,value->{
+ RobotData.WarehouseLocHavingBasin=value;
+ });
+
+ //机器人到达维护位
+ ModbusMaster.get().ReadBool(RobotAddress("M640"),1,1,value->{
+ RobotData.RobotReachTending=value[0];
+ });
+
+ //机器人原点位
+ ModbusMaster.get().ReadBool(RobotAddress("M660"),1,1,value->{
+ RobotData.RobotHome=value[0];
+ });
+
+ //机器人任务反馈
+ ModbusMaster.get().ReadShort("GI5",1,1,value->{
+ RobotData.RobotTaskFeedback=value[0];
+ });
+
+ //机器人1号炒锅完成
+ ModbusMaster.get().ReadBool(RobotAddress("M600"),4,1,value->{
+ RobotData.FryingStatus.get(1).PutMaterialComplete=value[0];
+ RobotData.FryingStatus.get(1).FallSeasoningComplete=value[1];
+ RobotData.FryingStatus.get(1).RequestDiningOut=value[2];
+ RobotData.FryingStatus.get(1).DiningOutComplete=value[3];
+ });
+
+ //机器人2号炒锅完成
+ ModbusMaster.get().ReadBool(RobotAddress("M610"),4,1,value->{
+ RobotData.FryingStatus.get(2).PutMaterialComplete=value[0];
+ RobotData.FryingStatus.get(2).FallSeasoningComplete=value[1];
+ RobotData.FryingStatus.get(2).RequestDiningOut=value[2];
+ RobotData.FryingStatus.get(2).DiningOutComplete=value[3];
+ });
+
+// RobotData.RobotIdle=RobotData.RobotHome&&RobotData.RobotTaskFeedback==0;//机器人空闲状态
+ RobotData.RobotIdle=true;//机器人空闲状态
+
+ }
+
+ @Override
+ public void Control()throws InterruptedException{
+ if (FryingPan.size()>0){
+
+ for(FryingPanPar item:FryingPan.values()){
+
+ if(RobotData.RobotIdle&&!item.IsPutIngredients ){
+ MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.PutMainMaterial),true);//写入商品ID
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"写入准备就绪信号给"+item.FryingPanNum+"号炒锅");
+ item.IsPutIngredients=true;
+ }
+
+ //准备就绪,准备投入主料
+ if(RobotData.RobotIdle && MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.AddIngredientsRequest))){
+
+ MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.AddIngredientsRequest),false);//复位投主料请求信号
+ RobotFeedingMainMaterials((short) item.IngredientsLocs[item.AddIngredientsCount],(short)item.FryingPanNum);//机器人投主料控制
+ item.AddIngredientsCount++;
+ }
+ if(EndProcess(item.FryingPanNum)) break;//强制结束检测
+
+ //投辅料请求
+ if(RobotData.RobotIdle&& MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanRequestAccessories))){
+ int tempLoc = item.AccessoriesLocs[item.AddAccessoriesCount]+10;
+ RobotFeedingAuxiliaryMaterials((short)tempLoc,(short) item.FryingPanNum);//机器人投辅料控制
+ item.AddAccessoriesCount++;
+ }
+ if(EndProcess(item.FryingPanNum)) break;//强制结束检测
+
+ //炒菜完成请求出餐
+ if(RobotData.RobotIdle&&MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.RequestingMeaDelivery))){
+
+ int index = GetBooleanIndex(RobotData.WarehouseLocHavingBasin,true);
+ if(index>=0&&index0){
+//
+//// List RemoveId=new ArrayList();
+//
+// for(FryingPanPar item:FryingPan.values()){
+//
+// if(RobotData.RobotIdle)//判断机器人是否OK
+// {
+// if(!item.IsPutIngredients ){
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.PutMainMaterial),true);//写入商品ID
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"写入准备就绪信号给"+item.FryingPanNum+"号炒锅");
+// item.IsPutIngredients=true;
+// }
+//
+// //准备就绪,准备投入主料
+// if(RobotData.RobotIdle && MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.AddIngredientsRequest))){
+//
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.AddIngredientsRequest),false);//复位投主料请求信号
+//// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从"+item.IngredientsLocs[item.AddIngredientsCount]+"号主料位,放主料到"+item.FryingPanNum + "号锅");
+//// ModbusMaster.get().WriteShort("GI0",(short) item.IngredientsLocs[item.AddIngredientsCount],1,null);//写入机器人主任务,指定主料位置
+//// ModbusMaster.get().WriteShort("GI1",(short) item.FryingPanNum,1,null);//写入机器人子任务,指定炒锅位置
+//// ModbusMaster.get().WriteBool(GetRobotAdd(item.FryingPanNum,0).toString(),true,1,null);//写入机器人允许放料信号
+////
+//// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人放菜完成");
+//
+// RobotFeedingMainMaterials((short) item.IngredientsLocs[item.AddIngredientsCount],(short)item.FryingPanNum);
+//
+// //等待放主料完成
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).PutMaterialComplete&&!ForceEnd[item.FryingPanNum-1]){Thread.sleep(100); }
+// if(EndProcess(item.FryingPanNum)) break;
+//// if(ForceEnd[item.FryingPanNum-1]){
+//// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.ForceEnd),true);//强制结束
+//// item.IsForceEnd=true;
+//// if(FryingPan.containsKey(item.FryingPanNum))
+//// RemoveId.add(item.FryingPanNum);
+//// break;
+//// }
+//
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人放菜完成");
+//
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.RobotPutIngredientsComplete),true);//机器人放主料完成
+// item.AddIngredientsCount++;
+// }
+// if(EndProcess(item.FryingPanNum)) break;
+//// if(ForceEnd[item.FryingPanNum-1]){
+//// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.ForceEnd),true);//强制结束
+//// item.IsForceEnd=true;
+//// if(FryingPan.containsKey(item.FryingPanNum))
+//// RemoveId.add(item.FryingPanNum);
+//// break;
+//// }
+//
+// //投辅料请求
+// if(RobotData.RobotIdle&& MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanRequestAccessories))){
+// int tempLoc = item.AccessoriesLocs[item.AddAccessoriesCount]+10;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从" +tempLoc+"号辅料位,放辅料到"+item.FryingPanNum + "号锅");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanRequestAccessories),false);//复位投辅料请求信号
+// ModbusMaster.get().WriteShort("GI0",(short) tempLoc,1,null);//写入机器人主任务,设置辅料位置
+// ModbusMaster.get().WriteShort("GI2",(short) item.FryingPanNum,1,null);//写入机器人子任务,设置炒锅位置
+// item.AddAccessoriesCount++;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人倒调料完成");
+// //等待机器人倒调料完成
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).FallSeasoningComplete&&!ForceEnd[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(EndProcess(item.FryingPanNum)) break;
+//// if(ForceEnd[item.FryingPanNum-1]){
+//// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.ForceEnd),true);//强制结束
+//// item.IsForceEnd=true;
+//// if(FryingPan.containsKey(item.FryingPanNum))
+//// RemoveId.add(item.FryingPanNum);
+//// break;
+//// }
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人倒调料完成");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.PutAccessories),true);//设置机器人放辅料完成信号
+// MbSlave.WriteString(GetHoldAdd(item.FryingPanNum,0));//复位商品id
+// }
+// if(EndProcess(item.FryingPanNum)) break;
+//// if(ForceEnd[item.FryingPanNum-1]){
+//// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.ForceEnd),true);//强制结束
+//// item.IsForceEnd=true;
+//// if(FryingPan.containsKey(item.FryingPanNum))
+//// RemoveId.add(item.FryingPanNum);
+//// break;
+//// }
+//
+// //炒菜完成请求出餐
+// if(RobotData.RobotIdle&&MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.RequestingMeaDelivery))){
+//
+// int index = GetBooleanIndex(RobotData.WarehouseLocHavingBasin,true);
+//
+// if(index>=0&&index FryingPan=new LinkedHashMap<>();
+// public ModbusTcpSlave MbSlave=new ModbusTcpSlave();
+
+
+// public void Init(){
+//
+// if (ConfigName.getInstance().versionSelectionEnum.equals("一拖四")){
+// RobotData.FryingStatus.put(1,new FryingPanData());
+// RobotData.FryingStatus.put(2,new FryingPanData());
+// RobotData.FryingStatus.put(3,new FryingPanData());
+// RobotData.FryingStatus.put(4,new FryingPanData());
+// HeartbeatStatusListen();
+// ConnectRobot();
+// Control();
+// MbSlave.Init();
+// }
+// else if (ConfigName.getInstance().versionSelectionEnum.equals("一拖二")){
+// MbSlave.Init();
+// }
+//
+//
+// }
+
+// public String RobotAddress(String address){
+// if (address == null) return "";
+// if (address.length() > 0) {
+// address = address.trim();
+// if (address.toUpperCase().contains("M") &&address.length() >=2){
+// String res = address.substring(1);
+// if (res != null) {
+// try {
+// Integer tempAdd = Integer.parseInt(res);
+// if(tempAdd>=0){
+// return (tempAdd+4096)+"";
+//}
+// } catch (NumberFormatException e) {
+// return "";
+// }
+// }
+// }
+// }
+// return "";
+// }
+//
+// public void ConnectRobot(){
+// new Thread(()->{
+// try {
+// ModbusMaster.get().TcpConnect(ConfigName.getInstance().Address, ConfigName.getInstance().Post, new IOperateResult() {
+// @Override
+// public void onSuccess() {
+// ConfigName.getInstance().PlcIsConnect = true;
+// RobotDataListen();
+// }
+//
+// @Override
+// public void onFailure(String message) {
+// ConfigName.getInstance().PlcIsConnect = false;
+// ToastUtils.info("设备 " + ConfigName.getInstance().Address + " 连接失败:" + message);
+// }
+//
+// @Override
+// public void onFinally() {
+//
+// }
+// });
+// }catch (Exception e )
+// {
+// MessageLog.ShowInfo("重新连接Modbus异常," + e.getMessage());
+// }
+// }).start();
+// }
+//
+// public boolean GetGoodVery(int num){
+// return MbSlave.ReadBoolean(GetAddress(num,AddressData.GoodDataVery));
+// }
+
+
+// /**
+// * 获取指定炒锅的状态
+// * @param num
+// * @return
+// */
+// public boolean GetFryingPan(int num){
+// return MbSlave.ReadBoolean(GetAddress(num,AddressData.FryingPanHide))&&GetHeartbeatStatus(num);
+// }
+//
+// /**
+// * 商品下发
+// */
+// public void GoodDown(String id,int num){
+// MbSlave.WriteBoolean(GetAddress(num,AddressData.PutMainMaterial),false);//复位放主料完成
+// MbSlave.WriteBoolean(GetAddress(num,AddressData.PutAccessories),false);//复位放辅料完成
+// MbSlave.WriteBoolean(GetAddress(num,AddressData.RobotServingSpace),false);//复位机器人到达出餐位
+// MbSlave.WriteString(id,GetHoldAdd(num,0));//写入商品ID
+// MbSlave.WriteBoolean(GetAddress(num,AddressData.GoodDown),true);//写入商品ID
+// }
+
+// public ICompleteNotify completeNotify;
+//
+// public IStatusNotify statusNotify;
+
+// /**
+// * 设备心跳监听
+// */
+// public void HeartbeatStatusListen(){
+// ThreadManager.Get().StartLong("设备心跳监听", true, new IThread() {
+// @Override
+// public void Run() throws InterruptedException {
+//
+// String[] status=new String[4];
+//
+// for (int i=0;i<4;i++){
+//
+// if (!MbSlave.ReadBoolean(GetAddress(i+1,AddressData.Heartbeat))){
+// StartTime[i]=System.currentTimeMillis();
+// }
+// MbSlave.WriteBoolean(GetAddress(i+1,AddressData.Heartbeat),true);
+//
+// HeartbeatStatus[i]=(System.currentTimeMillis()-StartTime[i])<=TimeOut;
+//
+// if ( HeartbeatStatus[i]&&MbSlave.ReadBoolean(GetAddress(i+1,AddressData.FryingPanHide))){
+// status[i]="空闲中";
+// }
+// else{
+// status[i]="忙碌中";
+// }
+// }
+//
+// if(statusNotify!=null)
+// statusNotify.OnStatusChanged(status[0],status[1],status[2],status[3]);
+// Thread.sleep(100);
+// }
+//
+// @Override
+// public void RunComplete() throws InterruptedException {
+//
+// }
+// });
+// }
+
+
+// @Override
+// public void RobotDataListen(){
+// ThreadManager.Get().StartLong("机器人数据监听", true, new IThread() {
+// @Override
+// public void Run() throws InterruptedException {
+//
+// //机器人急停
+// ModbusMaster.get().ReadBool("M640",1,1,value->{
+// for (int i =0;i<4;i++){
+// MbSlave.WriteBoolean(GetAddress(i+1,AddressData.EStop),value[0]);
+// }
+// });
+//
+//
+// //M640--1280--4736
+// ModbusMaster.get().ReadBool("4736",6,1,value->{
+// RobotData.PutEmptyBasinComplete=value;
+// });
+//
+// //M660--1294--4756
+// ModbusMaster.get().ReadBool("4756",1,1,value->{
+// RobotData.RobotHome=value[0];
+// });
+//
+// //GI5--5
+// ModbusMaster.get().ReadShort("5",1,1,value->{
+// RobotData.RobotTaskFeedback=value[0];
+// });
+//
+// //M600--1258-4696
+// ModbusMaster.get().ReadBool("4696",4,1,value->{
+// RobotData.FryingStatus.get(1).PutMaterialComplete=value[0];
+// RobotData.FryingStatus.get(1).FallSeasoningComplete=value[1];
+// RobotData.FryingStatus.get(1).RequestDiningOut=value[2];
+// RobotData.FryingStatus.get(1).DiningOutComplete=value[3];
+// });
+//
+// //M610--1262-4706
+// ModbusMaster.get().ReadBool("4706",4,1,value->{
+// RobotData.FryingStatus.get(2).PutMaterialComplete=value[0];
+// RobotData.FryingStatus.get(2).FallSeasoningComplete=value[1];
+// RobotData.FryingStatus.get(2).RequestDiningOut=value[2];
+// RobotData.FryingStatus.get(2).DiningOutComplete=value[3];
+// });
+//
+// //M620--126C-4716
+// ModbusMaster.get().ReadBool("4716",4,1,value->{
+// RobotData.FryingStatus.get(3).PutMaterialComplete=value[0];
+// RobotData.FryingStatus.get(3).FallSeasoningComplete=value[1];
+// RobotData.FryingStatus.get(3).RequestDiningOut=value[2];
+// RobotData.FryingStatus.get(3).DiningOutComplete=value[3];
+// });
+//
+// //M630--1276-4726
+// ModbusMaster.get().ReadBool("4726",4,1,value->{
+// RobotData.FryingStatus.get(4).PutMaterialComplete=value[0];
+// RobotData.FryingStatus.get(4).FallSeasoningComplete=value[1];
+// RobotData.FryingStatus.get(4).RequestDiningOut=value[2];
+// RobotData.FryingStatus.get(4).DiningOutComplete=value[3];
+// });
+//
+// Thread.sleep(100);
+// }
+//
+// @Override
+// public void RunComplete() throws InterruptedException {
+//
+// }
+// });
+// }
+//
+// @Override
+// public void Control(){
+// ThreadManager.Get().StartLong("炒锅控制业务", true, new IThread() {
+// @Override
+// public void Run() throws InterruptedException {
+//
+// if (FryingPan.size()>0){
+//
+// List RemoveId=new ArrayList();
+//
+// for(FryingPanPar item:FryingPan.values()){
+//
+// if(RobotData.RobotHome&&RobotData.RobotTaskFeedback==0)//判断机器人是否OK
+// {
+// //如果没有放主料,并且投料机构OK
+// if(!item.IsPutIngredients && MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FeedingMechanism))){
+// Log.e("TAG", "机器人从"+item.IngredientsLoc+"号主料位,放主料到"+item.FryingPanNum + "号锅");
+// item.IsPutIngredients=true;
+// Log.e("TAG", "写入的商品id"+item.GoodID);
+// ModbusMaster.get().WriteShort("GI0",(short) item.IngredientsLoc,1,null);//写入机器人主任务,指定主料位置
+// ModbusMaster.get().WriteShort("GI1",(short) item.FryingPanNum,1,null);//写入机器人子任务,指定炒锅位置
+// ModbusMaster.get().WriteBool(GetRobotAdd(item.FryingPanNum,0).toString(),true,1,null);//写入机器人允许放料信号
+//
+// Log.e("TAG", "等待机器人放菜完成");
+//
+// //等待放菜完成
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).PutMaterialComplete&&!qzjs[item.FryingPanNum-1]){Thread.sleep(100); }
+//
+// if(qzjs[item.FryingPanNum-1])return;
+//
+// Log.e("TAG", "机器人放菜完成");
+//
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.PutMainMaterial),true);//机器人放主料完成
+// }
+//
+// if(qzjs[item.FryingPanNum-1])return;
+//
+// //投辅料请求
+// boolean RobotHeid= RobotData.RobotHome&&RobotData.RobotTaskFeedback==0;//机器人空闲状态
+// if(RobotHeid&& MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanRequestAccessories))){
+// int tempLoc = item.AccessoriesLoc1+10;
+// if(item.AddAccessoriesCount==1)tempLoc=item.AccessoriesLoc2+10;
+// Log.e("TAG", "机器人从" +tempLoc+"号辅料位,放辅料到"+item.FryingPanNum + "号锅");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanRequestAccessories),false);//复位投辅料请求信号
+// ModbusMaster.get().WriteShort("GI0",(short) tempLoc,1,null);//写入机器人主任务,设置辅料位置
+// ModbusMaster.get().WriteShort("GI2",(short) item.FryingPanNum,1,null);//写入机器人子任务,设置炒锅位置
+// item.AddAccessoriesCount++;
+// Log.e("TAG", "等待机器人倒调料完成");
+// //等待机器人倒调料完成
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).FallSeasoningComplete&&!qzjs[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(qzjs[item.FryingPanNum-1])return;
+// Log.e("TAG", "机器人倒调料完成");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.PutAccessories),true);//设置机器人放辅料完成信号
+// MbSlave.WriteString(GetHoldAdd(item.FryingPanNum,0));//复位商品id
+// }
+//
+// if(qzjs[item.FryingPanNum-1])return;
+//
+// //倒主料完成,放主料盒子到货架请求
+// RobotHeid= RobotData.RobotHome&&RobotData.RobotTaskFeedback==0;
+// if(RobotHeid&&MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPnaMainMaterialComplete)))
+// {
+// Log.e("TAG", "机器人从" +item.FryingPanNum+"号炒锅取料盆到"+item.IngredientsLoc + "号货架");
+// ModbusMaster.get().WriteShort("GI0",(short) (item.FryingPanNum+20),1,null);//写入机器人主任务,指定锅号
+// ModbusMaster.get().WriteShort("GI3",(short) item.IngredientsLoc,1,null);//写入机器人子任务,指定货架位置
+// Log.e("TAG", "等待机器人放空盆完成");
+// //等待放空盆完成
+// while(!RobotData.PutEmptyBasinComplete[item.IngredientsLoc-1]&&!qzjs[item.FryingPanNum-1]) { Thread.sleep(100);}
+// if(qzjs[item.FryingPanNum-1])return;
+// Log.e("TAG", "机器人放空盆完成");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPnaMainMaterialComplete),false);//复位倒主料完成信号
+// }
+//
+// if(qzjs[item.FryingPanNum-1])return;
+//
+// //炒菜完成请求出餐
+// RobotHeid= RobotData.RobotHome&&RobotData.RobotTaskFeedback==0;
+// if(RobotHeid&&MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.RequestingMeaDelivery))){
+//
+// Log.e("TAG", "机器人从" +item.FryingPanNum+"号位置取空盆到"+item.FryingPanNum + "号炒锅");
+//
+// ModbusMaster.get().WriteShort("GI0",(short) (item.FryingPanNum+30),1,null);//写入机器人主任务,指定出餐空盆位置
+//
+// Log.e("TAG", "等待机器人到"+item.FryingPanNum+"号炒锅位置");
+// //等待机器人到达炒锅位置
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).RequestDiningOut&&!qzjs[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(qzjs[item.FryingPanNum-1])return;
+// Log.e("TAG", "机器人到"+item.FryingPanNum+"号炒锅位置");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.RobotServingSpace),true);//通知炒锅,机器人到达出餐位
+//
+// //等待炒锅到达减速位
+// while (!MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.DecelerationInPlace))&&!qzjs[item.FryingPanNum-1]){Thread.sleep(50);}
+// if(qzjs[item.FryingPanNum-1])return;
+//
+// Log.e("TAG", "等待机器人到"+item.FryingPanNum+"号炒锅减速位置");
+// //设置机器人炒锅减速到位
+// ModbusMaster.get().WriteBool(GetRobotAdd(item.FryingPanNum,1).toString(),true,1,null);
+// Log.e("TAG", "机器人到"+item.FryingPanNum+"号炒锅减速位置");
+//
+// Log.e("TAG", "等待"+item.FryingPanNum+"号炒锅出餐完成");
+// //等待炒锅出餐完成
+// while (!MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanDiningOut))&&!qzjs[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(qzjs[item.FryingPanNum-1])return;
+// Log.e("TAG", item.FryingPanNum+"号炒锅出餐完成");
+//
+// //设置机器人出餐完成
+// ModbusMaster.get().WriteBool(GetRobotAdd(item.FryingPanNum,2).toString(),true,1,null);
+//
+// Log.e("TAG", "等待机器人出餐完成");
+// //等待机器人出餐完成
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).DiningOutComplete&&!qzjs[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(qzjs[item.FryingPanNum-1])return;
+// Log.e("TAG", "机器人出餐完成");
+// //复位炒菜完成,出餐请求
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.RequestingMeaDelivery),false);;
+// //复位炒锅出餐完成信号
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanDiningOut),false);
+//
+// //通知界面可以继续下发任务
+// if (completeNotify!=null)
+// {
+// completeNotify.onComplete(item.FryingPanNum);
+// Log.e("TAG", "通知界面"+item.FryingPanNum+"号炒锅执行完成");
+// }
+//
+// item.IsComplete=true;
+// if(FryingPan.containsKey(item.FryingPanNum))
+// RemoveId.add(item.FryingPanNum);
+// }
+// }
+// }
+//
+// for(Integer key:RemoveId){
+// if(FryingPan.containsKey(key))
+// {
+// FryingPan.remove(key);
+// Log.e("TAG", "删除"+key+"号炒锅任务");
+// }
+// }
+//
+// }
+// Thread.sleep(100);
+// }
+//
+// @Override
+// public void RunComplete() throws InterruptedException {
+//
+// }
+// });
+// }
+
+
+ @Override
+ public void RobotDataListen()throws InterruptedException{
+ //机器人急停
+ ModbusMaster.get().ReadBool("M640",1,1,value->{
+ for (int i =0;i<4;i++){
+ MbSlave.WriteBoolean(GetAddress(i+1,AddressData.EStop),value[0]);
+ }
+ });
+
+ //M640--1280--4736
+ ModbusMaster.get().ReadBool("4736",6,1,value->{
+ RobotData.PutEmptyBasinComplete=value;
+ });
+
+ //M660--1294--4756
+ ModbusMaster.get().ReadBool("4756",1,1,value->{
+ RobotData.RobotHome=value[0];
+ });
+
+ //GI5--5
+ ModbusMaster.get().ReadShort("5",1,1,value->{
+ RobotData.RobotTaskFeedback=value[0];
+ });
+
+ //M600--1258-4696
+ ModbusMaster.get().ReadBool("4696",4,1,value->{
+ RobotData.FryingStatus.get(1).PutMaterialComplete=value[0];
+ RobotData.FryingStatus.get(1).FallSeasoningComplete=value[1];
+ RobotData.FryingStatus.get(1).RequestDiningOut=value[2];
+ RobotData.FryingStatus.get(1).DiningOutComplete=value[3];
+ });
+
+ //M610--1262-4706
+ ModbusMaster.get().ReadBool("4706",4,1,value->{
+ RobotData.FryingStatus.get(2).PutMaterialComplete=value[0];
+ RobotData.FryingStatus.get(2).FallSeasoningComplete=value[1];
+ RobotData.FryingStatus.get(2).RequestDiningOut=value[2];
+ RobotData.FryingStatus.get(2).DiningOutComplete=value[3];
+ });
+
+ //M620--126C-4716
+ ModbusMaster.get().ReadBool("4716",4,1,value->{
+ RobotData.FryingStatus.get(3).PutMaterialComplete=value[0];
+ RobotData.FryingStatus.get(3).FallSeasoningComplete=value[1];
+ RobotData.FryingStatus.get(3).RequestDiningOut=value[2];
+ RobotData.FryingStatus.get(3).DiningOutComplete=value[3];
+ });
+
+ //M630--1276-4726
+ ModbusMaster.get().ReadBool("4726",4,1,value->{
+ RobotData.FryingStatus.get(4).PutMaterialComplete=value[0];
+ RobotData.FryingStatus.get(4).FallSeasoningComplete=value[1];
+ RobotData.FryingStatus.get(4).RequestDiningOut=value[2];
+ RobotData.FryingStatus.get(4).DiningOutComplete=value[3];
+ });
+
+ RobotData.RobotIdle=RobotData.RobotHome&&RobotData.RobotTaskFeedback==0;//机器人空闲状态
+ }
+
+ @Override
+ public void Control()throws InterruptedException{
+ if (FryingPan.size()>0){
+ for(FryingPanPar item:FryingPan.values()){
+ //如果没有放主料,并且投料机构OK
+ if( RobotData.RobotIdle&&!item.IsPutIngredients && MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FeedingMechanism))){
+ item.IsPutIngredients=true;
+ RobotFeedingMainMaterials((short)item.IngredientsLocs[0],(short)item.FryingPanNum);
+ }
+ if(EndProcess(item.FryingPanNum)) break;//强制结束检测
+
+ //投辅料请求
+ if( RobotData.RobotIdle&& MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanRequestAccessories))){
+ int tempLoc = item.AccessoriesLocs[item.AddAccessoriesCount]+10;
+ RobotFeedingAuxiliaryMaterials((short)tempLoc,(short) item.FryingPanNum);//机器人投辅料控制
+ item.AddAccessoriesCount++;
+ }
+
+ if(EndProcess(item.FryingPanNum)) break;//强制结束检测
+
+ //倒主料完成,放主料盒子到货架请求
+ if( RobotData.RobotIdle&&MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPnaMainMaterialComplete)))
+ {
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从" +item.FryingPanNum+"号炒锅取料盆到"+item.IngredientsLocs[0] + "号货架");
+ ModbusMaster.get().WriteShort("GI0",(short) (item.FryingPanNum+20),1,null);//写入机器人主任务,指定锅号
+ ModbusMaster.get().WriteShort("GI3",(short) item.IngredientsLocs[0],1,null);//写入机器人子任务,指定货架位置
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人放空盆完成");
+ //等待放空盆完成
+ while(!RobotData.PutEmptyBasinComplete[item.IngredientsLocs[0]-1]&&!ForceEnd[item.FryingPanNum-1]) { Thread.sleep(100);}
+ if(EndProcess(item.FryingPanNum)) break;//强制结束检测
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "机器人放空盆完成");
+ MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPnaMainMaterialComplete),false);//复位倒主料完成信号
+ }
+ if(EndProcess(item.FryingPanNum)) break;//强制结束检测
+
+ //炒菜完成请求出餐
+ if( RobotData.RobotIdle&&MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.RequestingMeaDelivery))){
+
+ MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从" +item.FryingPanNum+"号位置取空盆到"+item.FryingPanNum + "号炒锅");
+ ModbusMaster.get().WriteShort("GI0",(short) (item.FryingPanNum+30),1,null);//写入机器人主任务,指定出餐空盆位置
+ RobotMealControl(item.FryingPanNum);//机器人出餐控制
+ }
+ }
+
+ RemoveTask();//移除任务检测
+ }
+ }
+
+
+
+
+// @Override
+// public void Control()throws InterruptedException{
+// if (FryingPan.size()>0){
+//
+// List RemoveId=new ArrayList();
+//
+// for(FryingPanPar item:FryingPan.values()){
+//
+// if(RobotData.RobotHome&&RobotData.RobotTaskFeedback==0)//判断机器人是否OK
+// {
+// //如果没有放主料,并且投料机构OK
+// if(!item.IsPutIngredients && MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FeedingMechanism))){
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "机器人从"+item.IngredientsLoc+"号主料位,放主料到"+item.FryingPanNum + "号锅");
+// item.IsPutIngredients=true;
+// ModbusMaster.get().WriteShort("GI0",(short) item.IngredientsLoc,1,null);//写入机器人主任务,指定主料位置
+// ModbusMaster.get().WriteShort("GI1",(short) item.FryingPanNum,1,null);//写入机器人子任务,指定炒锅位置
+// ModbusMaster.get().WriteBool(GetRobotAdd(item.FryingPanNum,0).toString(),true,1,null);//写入机器人允许放料信号
+//
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "等待机器人放菜完成");
+//
+// //等待放菜完成
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).PutMaterialComplete&&!ForceEnd[item.FryingPanNum-1]){Thread.sleep(100); }
+//
+// if(ForceEnd[item.FryingPanNum-1])return;
+//
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "机器人放菜完成");
+//
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.PutMainMaterial),true);//机器人放主料完成
+// }
+//
+// if(ForceEnd[item.FryingPanNum-1])return;
+//
+// //投辅料请求
+// boolean RobotHeid= RobotData.RobotHome&&RobotData.RobotTaskFeedback==0;//机器人空闲状态
+// if(RobotHeid&& MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanRequestAccessories))){
+// int tempLoc = item.AccessoriesLoc1+10;
+// if(item.AddAccessoriesCount==1)tempLoc=item.AccessoriesLoc2+10;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从" +tempLoc+"号辅料位,放辅料到"+item.FryingPanNum + "号锅");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanRequestAccessories),false);//复位投辅料请求信号
+// ModbusMaster.get().WriteShort("GI0",(short) tempLoc,1,null);//写入机器人主任务,设置辅料位置
+// ModbusMaster.get().WriteShort("GI2",(short) item.FryingPanNum,1,null);//写入机器人子任务,设置炒锅位置
+// item.AddAccessoriesCount++;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人倒调料完成");
+// //等待机器人倒调料完成
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).FallSeasoningComplete&&!ForceEnd[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(ForceEnd[item.FryingPanNum-1])return;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "机器人倒调料完成");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.PutAccessories),true);//设置机器人放辅料完成信号
+// MbSlave.WriteString(GetHoldAdd(item.FryingPanNum,0));//复位商品id
+// }
+//
+// if(ForceEnd[item.FryingPanNum-1])return;
+//
+// //倒主料完成,放主料盒子到货架请求
+// RobotHeid= RobotData.RobotHome&&RobotData.RobotTaskFeedback==0;
+// if(RobotHeid&&MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPnaMainMaterialComplete)))
+// {
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从" +item.FryingPanNum+"号炒锅取料盆到"+item.IngredientsLoc + "号货架");
+// ModbusMaster.get().WriteShort("GI0",(short) (item.FryingPanNum+20),1,null);//写入机器人主任务,指定锅号
+// ModbusMaster.get().WriteShort("GI3",(short) item.IngredientsLoc,1,null);//写入机器人子任务,指定货架位置
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待机器人放空盆完成");
+// //等待放空盆完成
+// while(!RobotData.PutEmptyBasinComplete[item.IngredientsLoc-1]&&!ForceEnd[item.FryingPanNum-1]) { Thread.sleep(100);}
+// if(ForceEnd[item.FryingPanNum-1])return;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "机器人放空盆完成");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPnaMainMaterialComplete),false);//复位倒主料完成信号
+// }
+//
+// if(ForceEnd[item.FryingPanNum-1])return;
+//
+// //炒菜完成请求出餐
+// RobotHeid= RobotData.RobotHome&&RobotData.RobotTaskFeedback==0;
+// if(RobotHeid&&MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.RequestingMeaDelivery))){
+//
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人从" +item.FryingPanNum+"号位置取空盆到"+item.FryingPanNum + "号炒锅");
+//
+// ModbusMaster.get().WriteShort("GI0",(short) (item.FryingPanNum+30),1,null);//写入机器人主任务,指定出餐空盆位置
+//
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "等待机器人到"+item.FryingPanNum+"号炒锅位置");
+// //等待机器人到达炒锅位置
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).RequestDiningOut&&!ForceEnd[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(ForceEnd[item.FryingPanNum-1])return;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人到"+item.FryingPanNum+"号炒锅位置");
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.RobotServingSpace),true);//通知炒锅,机器人到达出餐位
+//
+// //等待炒锅到达减速位
+// while (!MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.DecelerationInPlace))&&!ForceEnd[item.FryingPanNum-1]){Thread.sleep(50);}
+// if(ForceEnd[item.FryingPanNum-1])return;
+//
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "等待机器人到"+item.FryingPanNum+"号炒锅减速位置");
+// //设置机器人炒锅减速到位
+// ModbusMaster.get().WriteBool(GetRobotAdd(item.FryingPanNum,1).toString(),true,1,null);
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人到"+item.FryingPanNum+"号炒锅减速位置");
+//
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"等待"+item.FryingPanNum+"号炒锅出餐完成");
+// //等待炒锅出餐完成
+// while (!MbSlave.ReadBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanDiningOut))&&!ForceEnd[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(ForceEnd[item.FryingPanNum-1])return;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,item.FryingPanNum+"号炒锅出餐完成");
+//
+// //设置机器人出餐完成
+// ModbusMaster.get().WriteBool(GetRobotAdd(item.FryingPanNum,2).toString(),true,1,null);
+//
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 , "等待机器人出餐完成");
+// //等待机器人出餐完成
+// while(!RobotData.FryingStatus.get(item.FryingPanNum).DiningOutComplete&&!ForceEnd[item.FryingPanNum-1]){Thread.sleep(100);}
+// if(ForceEnd[item.FryingPanNum-1])return;
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"机器人出餐完成");
+// //复位炒菜完成,出餐请求
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.RequestingMeaDelivery),false);;
+// //复位炒锅出餐完成信号
+// MbSlave.WriteBoolean(GetAddress(item.FryingPanNum,AddressData.FryingPanDiningOut),false);
+//
+// //通知界面可以继续下发任务
+// if (completeNotify!=null)
+// {
+// completeNotify.onComplete(item.FryingPanNum);
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"通知界面"+item.FryingPanNum+"号炒锅执行完成");
+// }
+//
+// item.IsComplete=true;
+// if(FryingPan.containsKey(item.FryingPanNum))
+// RemoveId.add(item.FryingPanNum);
+// }
+// }
+// }
+//
+// for(Integer key:RemoveId){
+// if(FryingPan.containsKey(key))
+// {
+// FryingPan.remove(key);
+// MessageLog.ShowUserMessage( UserLogEnum.订单处理日志 ,"删除"+key+"号炒锅任务");
+// }
+// }
+//
+// }
+// }
+
+
+}
diff --git a/app/src/main/java/com/bonait/bnframework/business/RobotData.java b/app/src/main/java/com/bonait/bnframework/business/RobotData.java
new file mode 100644
index 00000000..cdaaeac1
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/business/RobotData.java
@@ -0,0 +1,59 @@
+package com.bonait.bnframework.business;
+
+import java.util.LinkedHashMap;
+
+public class RobotData {
+
+ /**
+ * 机器人原点位置
+ */
+ public static boolean RobotHome;
+
+ /**
+ * 机器人空闲状态
+ */
+ public static boolean RobotHeid;
+
+ /**
+ * 原料库空盆放回完成
+ */
+ public static boolean[] PutEmptyBasinComplete=new boolean[6];
+
+ /**
+ * 机器人入库完成
+ */
+ public static boolean[] RobotWarehousingComplete=new boolean[6];
+
+ /**
+ * 指定库位有盆
+ */
+ public static boolean[] WarehouseLocHavingBasin=new boolean[4];
+
+
+
+ /**
+ * 机器人到达维护位置
+ */
+ public static boolean RobotReachTending;
+
+ /**
+ * 机器人任务反馈
+ */
+ public static short RobotTaskFeedback;
+
+ /**
+ * 机器人空闲状态
+ */
+ public static boolean RobotIdle;
+
+ /**
+ * 炒锅状态
+ */
+ public static LinkedHashMap FryingStatus=new LinkedHashMap();
+
+
+
+
+
+
+}
diff --git a/app/src/main/java/com/bonait/bnframework/common/ModbusSlave/ModbusTcpSlave.java b/app/src/main/java/com/bonait/bnframework/common/ModbusSlave/ModbusTcpSlave.java
new file mode 100644
index 00000000..53fde63b
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/common/ModbusSlave/ModbusTcpSlave.java
@@ -0,0 +1,165 @@
+package com.bonait.bnframework.common.ModbusSlave;
+
+import android.util.Log;
+
+import com.bonait.bnframework.common.helper.DataFormat;
+import com.bonait.bnframework.common.modbus.ShortLib;
+
+import net.wimpi.modbus.ModbusCoupler;
+import net.wimpi.modbus.net.ModbusTCPListener;
+import net.wimpi.modbus.procimg.DigitalOut;
+import net.wimpi.modbus.procimg.Register;
+import net.wimpi.modbus.procimg.SimpleDigitalIn;
+import net.wimpi.modbus.procimg.SimpleDigitalOut;
+import net.wimpi.modbus.procimg.SimpleProcessImage;
+import net.wimpi.modbus.procimg.SimpleRegister;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.Enumeration;
+
+public class ModbusTcpSlave {
+ SimpleProcessImage spi = new SimpleProcessImage();
+ ModbusTCPListener listener = null;
+ int port = 30000;//Android 1024 以下端口属于系统端口,需要root权限
+
+ //参考连接
+ //https://www.geek-share.com/detail/2805846670.html
+
+ /**
+ * 寄存器地址注册,地址依次从 add 添加顺序为主
+ */
+ public void Register(){
+
+ //线圈寄存器(DO)
+ for (int i = 0; i <400;i++)
+ spi.addDigitalOut(new SimpleDigitalOut(false));
+
+ //保持寄存器(AO)
+ for (int i =0;i<100;i++)
+ spi.addRegister(new SimpleRegister(0));
+
+ //离散输入寄存器(DI)
+// spi.addDigitalIn(new SimpleDigitalIn(false));
+
+//输入寄存器(AI)
+// spi.addInputRegister(new SimpleInputRegister(45));
+
+ }
+
+ /**
+ * 寄存器注册
+ */
+ public void Init(){
+
+ Register();
+
+ ModbusCoupler.getReference().setProcessImage(spi);
+ ModbusCoupler.getReference().setMaster(false);//默认是true,这里需要设置为false
+ ModbusCoupler.getReference().setUnitID(1);//从站地址
+
+ new Thread(networkTask).start();
+ Log.e("TAG", "本机的IP = " + getHostIP());
+ }
+
+
+ /**
+ * 网络操作相关的子线程
+ */
+ Runnable networkTask = new Runnable() {
+
+ @Override
+ public void run() {
+ // TODO
+ // 在这里进行 http request.网络请求相关操作
+
+// byte[] bytes =new byte[4];
+// bytes[0]=(byte)192;
+// bytes[1]=(byte)168;
+// bytes[2]=(byte)6;
+// bytes[3]=(byte)105;
+//
+// InetAddress adder= null;
+// try {
+// adder = InetAddress.getByAddress(bytes);
+// } catch (UnknownHostException e) {
+// throw new RuntimeException(e);
+// }
+
+ listener = new ModbusTCPListener(3 );
+ listener.setPort(port);
+ listener.start();
+ }
+ };
+
+ public void WriteString(String str,int add){
+ short[] shorts = ShortLib.ToShorts(str.getBytes(), DataFormat.ABCD);
+ int tempAdd = add;
+ Log.e("TAG", "写入字长度: "+shorts.length);
+ for (int i = 0;i ias = ni.getInetAddresses();
+ while (ias.hasMoreElements()) {
+ ia = ias.nextElement();
+ if (ia instanceof Inet6Address) {
+ continue;// skip ipv6
+ }
+ String ip = ia.getHostAddress();
+ if (!"127.0.0.1".equals(ip)) {
+ hostIp = ia.getHostAddress();
+ break;
+ }
+ }
+ }
+ } catch (SocketException e) {
+ Log.i("yao", "SocketException");
+ e.printStackTrace();
+ }
+ return hostIp;
+ }
+}
+
+
diff --git a/app/src/main/java/com/bonait/bnframework/common/UDP/SendUdpMode.java b/app/src/main/java/com/bonait/bnframework/common/UDP/SendUdpMode.java
new file mode 100644
index 00000000..5f221f3f
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/common/UDP/SendUdpMode.java
@@ -0,0 +1,15 @@
+package com.bonait.bnframework.common.UDP;
+
+public class SendUdpMode {
+ public String ip;
+ public int port;
+ //数据格式
+ public String data;
+
+ public SendUdpMode(String _IP,int _PORT,String _DATA)
+ {
+ this.ip=_IP;
+ this.port=_PORT;
+ this.data=_DATA;
+ }
+}
diff --git a/app/src/main/java/com/bonait/bnframework/common/UDP/UdpHelper.java b/app/src/main/java/com/bonait/bnframework/common/UDP/UdpHelper.java
new file mode 100644
index 00000000..46483ded
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/common/UDP/UdpHelper.java
@@ -0,0 +1,192 @@
+package com.bonait.bnframework.common.UDP;
+import android.annotation.SuppressLint;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Log;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.nio.charset.Charset;
+import java.util.concurrent.ExecutorService;
+
+public class UdpHelper {
+ //region 变量
+ private static final String TAG = "UDP帮助";
+ /**
+ * 服务端口
+ */
+ public int ServerPort = 10000;
+ /**
+ * 是否启动监听
+ */
+ private volatile boolean isRuning = false;
+ /**
+ * 接收数据服务端
+ */
+ private DatagramSocket receiveSocket = null;
+ /**
+ * 反馈数据
+ */
+ public Handler myHandler = null;
+ /**
+ * 服务端
+ */
+ private ServerThread serverThread = new ServerThread();
+ /**
+ * 客户端
+ */
+ public ClientThread clientThread = new ClientThread();
+
+ //endregion
+
+ //region 外部调用
+
+ /**
+ * 服务启动监听
+ *
+ * @param port
+ */
+ public void Start(int port) {
+ ServerPort = port;
+ try {
+ receiveSocket = new DatagramSocket(port);
+ } catch (SocketException e) {
+ }
+ isRuning = true;
+ }
+
+ /**
+ * 停止监听
+ */
+ public void Stop() {
+ isRuning = false;
+ if(receiveSocket!=null)
+ {
+ receiveSocket.close();
+ }
+ }
+
+ /**
+ * 发送数据
+ *
+ * @param ip
+ * @param port
+ * @param data
+ */
+ public void SendData(String ip, int port, String data) {
+ Message msg = Message.obtain();
+ msg.obj = new SendUdpMode(ip, port, data);
+ msg.what = 1;
+ clientThread.mhandler.sendMessage(msg);
+ }
+ //endregion
+
+ //region 线程
+
+ /**
+ * 发送数据线程
+ */
+ public class ClientThread extends Thread {
+ private Handler mhandler = null;
+
+ @SuppressLint("HandlerLeak")
+ @Override
+ public void run() {
+ Looper.prepare();
+ mhandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ SendUdpMode message = (SendUdpMode) msg.obj;
+ byte[] data = message.data.getBytes(Charset.forName("GBK"));
+
+ DatagramPacket dpSend = null;
+ DatagramSocket sendSocket = null;
+ try {
+ InetAddress inetAddress = InetAddress.getByName(message.ip.toString().trim());
+ dpSend = new DatagramPacket(data, data.length, inetAddress, message.port);
+ } catch (UnknownHostException e) {
+ }
+ try {
+ double start = System.currentTimeMillis();
+ for (int i = 0; i < 1; i++) {
+ sendSocket = new DatagramSocket();
+ sendSocket.send(dpSend);
+ sendSocket.close();
+ Thread.sleep(80);
+ Log.i(TAG, "发送数据: " + new String(data));
+ }
+ double end = System.currentTimeMillis();
+ double times = end - start;
+ Log.i(TAG, "发送数据所用时间: " + times + "ms");
+ } catch (IOException e) {
+ Log.i(TAG, "发送数据异常: " + e.getMessage());
+ } catch (InterruptedException e) {
+ Log.i(TAG, "发送数据异常: " + e.getMessage());
+ } finally {
+ if (sendSocket != null) {
+ sendSocket.close();
+ }
+ }
+ }
+ };
+ Looper.loop();
+ }
+ }
+
+ /**
+ * 服务线程
+ */
+ private class ServerThread extends Thread {
+ @Override
+ public void run() {
+ while (true) {
+ if (isRuning) {
+ byte[] receiveData = new byte[1024];
+ DatagramPacket dpReceive = null;
+ dpReceive = new DatagramPacket(receiveData, receiveData.length);
+ try {
+ receiveSocket.receive(dpReceive);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ String recIp = dpReceive.getAddress().toString().substring(1);
+ String port = String.valueOf(dpReceive.getPort());
+ String content = "";
+ content = new String(receiveData, 0, dpReceive.getLength(), Charset.forName("GBK"));
+ if (dpReceive != null) {
+ Message revMessage = Message.obtain();
+ revMessage.what = 1;
+ revMessage.obj = "收到来自" + recIp + ":" + port + "的信息:" + content;
+ Log.i(TAG, "收到来自" + recIp + ":" + port + "的信息:" + content);
+ if (myHandler != null) {
+ myHandler.sendMessage(revMessage);
+ }
+ }
+ }
+ }
+ }
+ }
+ //endregion
+
+ //region 私有
+// private static UdpHelper mInstance; //实例变量设置私有,防止直接通过类名访问
+//
+// public static synchronized UdpHelper getInstance() { //静态同步方法作为唯一的实例对象获取方式
+// if (mInstance == null) {
+// mInstance = new UdpHelper();
+// }
+// return mInstance;
+// }
+//
+// private UdpHelper() { //默认构造函数私有,防止类外直接new创建对象
+// clientThread.start();
+// serverThread.start();
+// }
+ //endregion
+}
diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
index 18e8ed3f..b9ff2011 100644
--- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
+++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
@@ -1005,12 +1005,12 @@ public class ConfigName {
/**
* 版本信息
*/
- public String[] versionSelectionValues = new String[]{"奶茶机", "配料吧台","味魔方","调味吧台"};
+ public String[] versionSelectionValues = new String[]{"一拖四", "一拖二"};
/**
* 选配版本信息
*/
- public String versionSelectionEnum = "调味吧台";
+ public String versionSelectionEnum = "一拖四";
//endregion
//region 主页
diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/MessageName.java b/app/src/main/java/com/bonait/bnframework/common/constant/MessageName.java
index 73dedf75..1ba68131 100644
--- a/app/src/main/java/com/bonait/bnframework/common/constant/MessageName.java
+++ b/app/src/main/java/com/bonait/bnframework/common/constant/MessageName.java
@@ -21,6 +21,8 @@ public interface MessageName {
String ClickImage="ClickImage";//点击图标
+ String GetOrganize="GetOrganize";//获取组织信息
+
String UpdateGood="UpdateGood";//修改商品
String DeleteGood1="DeleteGood1";//删除商品
diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/MQTT.java b/app/src/main/java/com/bonait/bnframework/common/helper/MQTT.java
index 2c41d619..6ef8eb8a 100644
--- a/app/src/main/java/com/bonait/bnframework/common/helper/MQTT.java
+++ b/app/src/main/java/com/bonait/bnframework/common/helper/MQTT.java
@@ -90,7 +90,7 @@ public class MQTT {
MessageLog.ShowInfo("mqtt断开连接,尝试重新连接...");
if(Disconnect!=null)
{
- Disconnect.Run();
+ Disconnect.Run();
}
Reconnect();
}
@@ -193,7 +193,8 @@ public class MQTT {
IsConnect=true;
if(ConnectOk!=null)
{
- ConnectOk.Run();
+ ConnectOk.Run();
+
}
} catch (MqttException e) {
Log.i("MQTT", "mqtt重连接失败!"+e.getMessage());
diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/MessageLog.java b/app/src/main/java/com/bonait/bnframework/common/helper/MessageLog.java
index 8a11fdbb..0262e7ac 100644
--- a/app/src/main/java/com/bonait/bnframework/common/helper/MessageLog.java
+++ b/app/src/main/java/com/bonait/bnframework/common/helper/MessageLog.java
@@ -1,5 +1,7 @@
package com.bonait.bnframework.common.helper;
+import android.util.Log;
+
import com.bonait.bnframework.common.db.res.AlertLogEnum;
import com.bonait.bnframework.common.db.res.UserLogEnum;
import com.bonait.bnframework.common.helper.I.IMessageLogNotify;
@@ -41,6 +43,7 @@ public class MessageLog {
}
public static void ShowError(String msg) {
+ Log.e("error", "onFailure: "+msg );
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String tempMsg = formatter.format(date) + ":" + msg;
@@ -58,6 +61,7 @@ public class MessageLog {
*/
public static void ShowUserMessage(UserLogEnum type, String msg)
{
+ Log.e(type.toString(), msg);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String tempMsg = formatter.format(date) + ":" + msg;
@@ -83,6 +87,7 @@ public class MessageLog {
if (MsgNotify != null)
MsgNotify.AlertMsg(type,tempMsg);
if (AddNotify != null) AddNotify.Run();
+
}
diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/RTrig.java b/app/src/main/java/com/bonait/bnframework/common/helper/RTrig.java
index 72eb8f85..3a48b855 100644
--- a/app/src/main/java/com/bonait/bnframework/common/helper/RTrig.java
+++ b/app/src/main/java/com/bonait/bnframework/common/helper/RTrig.java
@@ -37,6 +37,7 @@ public class RTrig {
setIN(IN);
if (Q)
callback.Run();
+
}
}
diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/DataConvertLib.java b/app/src/main/java/com/bonait/bnframework/common/modbus/DataConvertLib.java
index 83cdcc57..9dd36144 100644
--- a/app/src/main/java/com/bonait/bnframework/common/modbus/DataConvertLib.java
+++ b/app/src/main/java/com/bonait/bnframework/common/modbus/DataConvertLib.java
@@ -193,7 +193,17 @@ public class DataConvertLib {
return -1;
}
}
- } else {
+ }else if (address.toUpperCase().contains("GI") &&address.length() >=3){
+ String res = address.substring(2);
+ if (res != null) {
+ try {
+ return Integer.parseInt(res);
+ } catch (NumberFormatException e) {
+ return -1;
+ }
+ }
+ }
+ else {
try {
return Integer.parseInt(address);
} catch (NumberFormatException e) {
diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ExceptionServer.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ExceptionServer.java
index c9f41879..78c4402b 100644
--- a/app/src/main/java/com/bonait/bnframework/common/modbus/ExceptionServer.java
+++ b/app/src/main/java/com/bonait/bnframework/common/modbus/ExceptionServer.java
@@ -21,20 +21,21 @@ public class ExceptionServer {
}
if (excpet!=null) excpet.onSuccess(add);
} catch (InterruptedException e) {
- MessageLog.ShowError("onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
- if (excpet!=null) excpet.onFailure(e.toString());
+ MessageLog.ShowError("InterruptedException,Address=" + Address + ",length=" + length + ",msg:" + e.getMessage());
+ if (excpet!=null) excpet.onFailure(e.getMessage());
} catch (ExecutionException e) {
- MessageLog.ShowError("onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
- if (excpet!=null) excpet.onFailure(e.toString());
+ MessageLog.ShowError("ExecutionException,Address=" + Address + ",length=" + length + ",msg:" + e.getMessage());
+ if (excpet!=null) excpet.onFailure(e.getMessage());
} catch (ModbusTransportException e) {
- MessageLog.ShowError("onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
- if (excpet!=null) excpet.onFailure(e.toString());
+ MessageLog.ShowError("ModbusTransportException,Address=" + Address + ",length=" + length + ",msg:" + e.getMessage());
+ if (excpet!=null) excpet.onFailure(e.getMessage());
} catch (ModbusInitException e) {
- MessageLog.ShowError("onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
- if (excpet!=null) excpet.onFailure(e.toString());
+ MessageLog.ShowError("ModbusInitException,Address=" + Address + ",length=" + length + ",msg:" + e.getMessage());
+ if (excpet!=null) excpet.onFailure(e.getMessage());
} catch (ModbusRespException e) {
- MessageLog.ShowError("onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
- if (excpet!=null) excpet.onFailure(e.toString());
+ MessageLog.ShowError("ModbusRespException,Address=" + Address + ",length=" + length + ",msg:" + e.getMessage());
+ if (excpet!=null) excpet.onFailure(e.getMessage());
}
+
}
}
diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusMaster.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusMaster.java
index d7089010..8c0efe68 100644
--- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusMaster.java
+++ b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusMaster.java
@@ -23,6 +23,7 @@ import com.licheedev.modbus4android.ModbusParam;
import com.licheedev.modbus4android.ModbusRespException;
import com.licheedev.modbus4android.param.SerialParam;
import com.licheedev.modbus4android.param.TcpParam;
+import com.serotonin.modbus4j.ModbusFactory;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.serotonin.modbus4j.msg.ReadCoilsResponse;
@@ -60,6 +61,10 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
private ModbusMaster() {
}
+ //https://blog.csdn.net/zgkxzx/article/details/71630301
+ ModbusFactory factory = new ModbusFactory();//使用该方法可以创建不同类型的modbus通讯
+
+
/**
* Ping PLC地址是否通畅
* @param address
@@ -98,6 +103,32 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
public boolean IsConnected=false;
+ private String TempIp;
+ private int TempPort;
+ private String TempCom;
+ private int TempBaudRate;
+
+ /**
+ * 连接类型,1=TCP,2=RUT
+ */
+ private int ConnectionType;
+
+ private void ReConnect(String error){
+ if(ConnectionType==1){
+ if(error.contains("Connection refused")){
+ IsConnected=false;
+ TcpConnect(TempIp,TempPort,null);
+ }
+ }
+ else if (ConnectionType==2){
+ if(error.contains("Connection refused")){
+ IsConnected=false;
+ RtuConnect(TempCom,TempBaudRate,null);
+ }
+ }
+
+ }
+
/**
* TCP 连接,连接时请用多线程的方式,否者有可能无法连接
* @param ip
@@ -106,7 +137,10 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
* @throws InterruptedException
*/
@Override
- public void TcpConnect(String ip, int port, IOperateResult result)throws InterruptedException {
+ public void TcpConnect(String ip, int port, IOperateResult result){
+ TempIp=ip;
+ TempPort=port;
+ ConnectionType=1;
MessageLog.ShowInfo("开始验证网络:"+ip );
boolean status = false;
while (!status) {
@@ -128,7 +162,6 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
.setKeepAlive(true);
while (IsConnected==false)
{
- MessageLog.ShowInfo("Modbus TCP 1111" );
ModbusBasis.get().init(param, new ModbusCallback() {
@Override
public void onSuccess(com.serotonin.modbus4j.ModbusMaster modbusMaster) {
@@ -147,7 +180,12 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
if(result!=null) result.onFinally();
}
});
- if(IsConnected==false) Thread.sleep(5000);
+ try
+ {
+ if(IsConnected==false) Thread.sleep(5000);
+ }catch(InterruptedException ex){
+
+ }
}
}
@@ -159,8 +197,11 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
* @throws InterruptedException
*/
@Override
- public void RtuConnect(String com, int baudRate, IOperateResult result)throws InterruptedException {
+ public void RtuConnect(String com, int baudRate, IOperateResult result){
MessageLog.ShowInfo("开始连接Modbus RTU" );
+ TempCom=com;
+ TempBaudRate=baudRate;
+ ConnectionType=2;
ModbusParam param=SerialParam.create(com, baudRate) // 串口地址和波特率
.setDataBits(8) // 数据位
.setParity(0) // 校验位
@@ -186,7 +227,11 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
if(result!=null) result.onFinally();
}
});
- if(IsConnected==false) Thread.sleep(5000);
+ try{
+ if(IsConnected==false) Thread.sleep(5000);
+ }catch (InterruptedException ex){
+
+ }
}
}
@@ -205,7 +250,8 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
+ ReConnect(error);
}
});
}
@@ -226,8 +272,8 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
-
+ public void onFailure(String error) {
+ ReConnect(error);
}
});
}
@@ -259,8 +305,8 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
-
+ public void onFailure(String error) {
+ ReConnect(error);
}
});
}
@@ -298,8 +344,8 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
-
+ public void onFailure(String error) {
+ ReConnect(error);
}
});
}
@@ -323,8 +369,8 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
-
+ public void onFailure(String error) {
+ ReConnect(error);
}
});
}
@@ -353,8 +399,8 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
-
+ public void onFailure(String error) {
+ ReConnect(error);
}
});
}
@@ -384,8 +430,9 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
@@ -404,8 +451,9 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
@@ -426,8 +474,9 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
@@ -446,8 +495,9 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
@@ -467,8 +517,9 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
@@ -497,8 +548,9 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
@@ -519,8 +571,9 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
@@ -541,8 +594,9 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
@@ -572,13 +626,12 @@ public class ModbusMaster implements IRead,IWrite,IModbusMaster {
}
@Override
- public void onFailure(String error){
+ public void onFailure(String error) {
if (callback != null)callback.onFailure(error);
+ ReConnect(error);
}
});
}
-
-
}
diff --git a/app/src/main/java/com/bonait/bnframework/common/tabbar/MainNavigateTabBar.java b/app/src/main/java/com/bonait/bnframework/common/tabbar/MainNavigateTabBar.java
index c93078d9..3965778a 100644
--- a/app/src/main/java/com/bonait/bnframework/common/tabbar/MainNavigateTabBar.java
+++ b/app/src/main/java/com/bonait/bnframework/common/tabbar/MainNavigateTabBar.java
@@ -41,7 +41,7 @@ public class MainNavigateTabBar extends LinearLayout implements View.OnClickList
private ColorStateList mSelectedTextColor;
private ColorStateList mNormalTextColor;
private float mTabTextSize;
- private int mDefaultSelectedTab = 2;
+ private int mDefaultSelectedTab = 0;
private int mCurrentSelectedTab;
public MainNavigateTabBar(Context context) {
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java
index 28c93b29..1177164f 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java
@@ -6,32 +6,26 @@ import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import android.util.Log;
-import com.bonait.bnframework.MainActivity;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
+import com.bonait.bnframework.business.DoubleFryingpanControl;
import com.bonait.bnframework.business.OrderServer;
+import com.bonait.bnframework.business.RobotControl;
+import com.bonait.bnframework.common.ModbusSlave.ModbusTcpSlave;
import com.bonait.bnframework.common.base.BaseActivity;
import com.bonait.bnframework.common.constant.ConfigName;
-import com.bonait.bnframework.common.helper.DataFormat;
-import com.bonait.bnframework.common.helper.I.IThread;
-import com.bonait.bnframework.common.helper.I.IWriteCallBack;
import com.bonait.bnframework.common.helper.MQTT;
import com.bonait.bnframework.common.helper.MediaPlayerHelper;
import com.bonait.bnframework.common.helper.MessageLog;
-import com.bonait.bnframework.common.helper.ThreadManager;
-import com.bonait.bnframework.common.modbus.ByteLib;
-import com.bonait.bnframework.common.modbus.FloatLib;
import com.bonait.bnframework.common.modbus.IOperateResult;
-import com.bonait.bnframework.common.modbus.ModbusClient;
import com.bonait.bnframework.common.modbus.ModbusMaster;
-import com.bonait.bnframework.common.modbus.ShortLib;
import com.bonait.bnframework.common.tabbar.MainNavigateTabBar;
import com.bonait.bnframework.common.utils.NetworkUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.modules.home.adapter.FragmentAdapter;
import com.bonait.bnframework.modules.home.fragment.DingDanfragment;
+import com.bonait.bnframework.modules.home.fragment.DoubleFryingpanFragment;
import com.bonait.bnframework.modules.home.fragment.GongnengFragment;
-import com.bonait.bnframework.modules.home.fragment.MakeGoodFragment;
import com.bonait.bnframework.modules.home.fragment.RobotMain;
import com.bonait.bnframework.modules.home.fragment.SheZhifragment;
import com.bonait.bnframework.modules.mine.fragment.MyFragment;
@@ -57,17 +51,23 @@ public class BottomNavigationMainActivity extends BaseActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_navigation_main);
- ButterKnife.bind(this);
- MediaPlayerHelper.getInstance().SetConText(getBaseContext());
- mNavigateTabBar.onRestoreInstanceState(savedInstanceState);
- mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.gongneng, R.mipmap.gongneng_selected, "功能"));
- mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.dingdan, R.mipmap.dingdan_selected, "订单"));
- mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(0, 0, ""));
- mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.shezhi, R.mipmap.shezhi_selected, "设置"));
- mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.comui_tab_person, R.mipmap.comui_tab_person_selected, "我的"));
- mNavigateTabBar.setTabSelectListener(mOnNavigationItemSelectedListener);
- initFragment();
- Init();
+ try {
+ ButterKnife.bind(this);
+ MediaPlayerHelper.getInstance().SetConText(getBaseContext());
+ mNavigateTabBar.onRestoreInstanceState(savedInstanceState);
+// mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.gongneng, R.mipmap.gongneng_selected, "功能"));
+// mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.dingdan, R.mipmap.dingdan_selected, "日志"));
+ mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(0, 0, ""));
+ mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.shezhi, R.mipmap.shezhi_selected, "设置"));
+// mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.comui_tab_person, R.mipmap.comui_tab_person_selected, "我的"));
+ mNavigateTabBar.setTabSelectListener(mOnNavigationItemSelectedListener);
+ initFragment();
+ Init();
+ }
+ catch (Exception e){
+ Log.i("TAG", "onCreate: "+e.getMessage());
+ }
+
}
@@ -88,21 +88,28 @@ public class BottomNavigationMainActivity extends BaseActivity {
*/
private void initFragment() {
fragmentList = new ArrayList<>();
- fragmentList.add(new GongnengFragment());
- fragmentList.add(new DingDanfragment());
+// fragmentList.add(new GongnengFragment());
+// fragmentList.add(new DingDanfragment());
+
+ if(ConfigName.getInstance().versionSelectionEnum.equals("一拖四")){
+ fragmentList.add(new RobotMain());
+ }
+ else if (ConfigName.getInstance().versionSelectionEnum.equals("一拖二")){
+ fragmentList.add(new DoubleFryingpanFragment());
+ }
+
// fragmentList.add(new MakeGoodFragment());//再来一单
- fragmentList.add(new RobotMain());
fragmentList.add(new SheZhifragment());
- fragmentList.add(new MyFragment());
+// fragmentList.add(new MyFragment());
ConfigName.getInstance().fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragmentList);
viewPager.setAdapter(ConfigName.getInstance().fragmentAdapter);
ConfigName.getInstance().fragmentAdapter.SetViewPage(viewPager);
//手指滑动
viewPager.addOnPageChangeListener(pageChangeListener);
// 设置viewPager缓存多少个fragment
- viewPager.setOffscreenPageLimit(5);
+ viewPager.setOffscreenPageLimit(2);
// 再来一单
- viewPager.setCurrentItem(2);
+ viewPager.setCurrentItem(0);
}
/**
@@ -115,42 +122,23 @@ public class BottomNavigationMainActivity extends BaseActivity {
//ConfigData.getInstance().GetOrganize(this);
//判断连接环境
ConfigData.getInstance().ToggleEnvironment();
+
+ if(ConfigName.getInstance().versionSelectionEnum.equals("一拖四")){
+ RobotControl.getInstance().Init();
+ }
+ else if (ConfigName.getInstance().versionSelectionEnum.equals("一拖二")){
+ DoubleFryingpanControl.getInstance().Init();
+ }
+
+
//2.初始化PLC
- ReconnectModbus();
+// ReconnectModbus();
//MQTT数据监听
- OrderServer.Get().MqttInit();
+// OrderServer.Get().MqttInit();
}
- /**
- * 重新连接plc
- */
- public void ReconnectModbus() {
- new Thread(()->{
- try {
- ModbusMaster.get().RtuConnect(ConfigName.getInstance().SerialPortName, 9600, new IOperateResult() {
- @Override
- public void onSuccess() {
- ConfigName.getInstance().PlcIsConnect = true;
- ConfigData.getInstance().PLC_Init();
- }
-
- @Override
- public void onFailure(String message) {
- ConfigName.getInstance().PlcIsConnect = false;
- ToastUtils.info("设备 " + ConfigName.getInstance().Address + " 连接失败:" + message);
- }
-
- @Override
- public void onFinally() {
-
- }
- });
- }catch (Exception e )
- {
- MessageLog.ShowInfo("重新连接Modbus异常," + e.getMessage());
- }
- }).start();
- }
+
+
/**
@@ -160,22 +148,40 @@ public class BottomNavigationMainActivity extends BaseActivity {
= new MainNavigateTabBar.OnTabSelectedListener() {
@Override
public void onTabSelected(MainNavigateTabBar.ViewHolder holder) {
- int _postion = 2;
+// int _postion = 2;
+// switch (holder.tag) {
+// case "功能":
+// _postion = 0;
+// break;
+// case "订单":
+// _postion = 1;
+// break;
+// case "设置":
+// _postion = 3;
+// break;
+// case "我的":
+// _postion = 4;
+// break;
+// case "":
+// _postion = 2;
+// break;
+// }
+ int _postion = 0;
switch (holder.tag) {
- case "功能":
- _postion = 0;
- break;
- case "订单":
- _postion = 1;
- break;
+// case "功能":
+// _postion = 0;
+// break;
+// case "订单":
+// _postion = 1;
+// break;
case "设置":
- _postion = 3;
- break;
- case "我的":
- _postion = 4;
+ _postion =1;
break;
+// case "我的":
+// _postion = 4;
+// break;
case "":
- _postion = 2;
+ _postion = 0;
break;
}
viewPager.setCurrentItem(_postion);
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/DoubleFryingpanFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/DoubleFryingpanFragment.java
new file mode 100644
index 00000000..720bf487
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/DoubleFryingpanFragment.java
@@ -0,0 +1,554 @@
+package com.bonait.bnframework.modules.home.fragment;
+
+import android.annotation.SuppressLint;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bonait.bnframework.R;
+import com.bonait.bnframework.business.ConfigData;
+import com.bonait.bnframework.business.DoubleFryingpanControl;
+import com.bonait.bnframework.business.FryingPanPar;
+import com.bonait.bnframework.business.ICompleteNotify;
+import com.bonait.bnframework.business.IStatusNotify;
+import com.bonait.bnframework.business.RobotControl;
+import com.bonait.bnframework.business.RobotData;
+import com.bonait.bnframework.common.base.BaseFragment;
+import com.bonait.bnframework.common.constant.ConfigName;
+import com.bonait.bnframework.common.constant.MessageName;
+import com.bonait.bnframework.common.db.QueryDB;
+import com.bonait.bnframework.common.db.mode.BPA_GOODS;
+import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
+import com.bonait.bnframework.common.helper.I.IRun;
+import com.bonait.bnframework.common.helper.MessageLog;
+import com.bonait.bnframework.common.linktab.LinkMode;
+import com.bonait.bnframework.common.linktab.makegood.MakeGoodRightAdapter;
+import com.bonait.bnframework.common.message.MessageLooper;
+import com.bonait.bnframework.common.message.MessageManager;
+import com.bonait.bnframework.common.modbus.ModbusMaster;
+import com.bonait.bnframework.common.model.mode.CloudGood;
+import com.bonait.bnframework.common.utils.AlertDialogUtils;
+import com.bonait.bnframework.dialog.DialogManager;
+import com.bonait.bnframework.dialog.DialogView;
+import com.qmuiteam.qmui.widget.QMUITopBarLayout;
+import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
+import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+public class DoubleFryingpanFragment extends BaseFragment {
+
+ @BindView(R.id.main_btn1)
+ Button btn1;
+
+ @BindView(R.id.main_btn2)
+ Button btn2;
+
+ @BindView(R.id.btn_warehousing)
+ Button btn_warehousing;
+
+ @BindView(R.id.btn_maintenance)
+ Button btn_maintenance;
+
+ @BindView(R.id.tv_Status1)
+ TextView tv_Status1;
+
+ @BindView(R.id.tv_Status2)
+ TextView tv_Status2;
+
+ @BindView(R.id.robot_topbar)
+ QMUITopBarLayout mTopBar;//顶部标题
+
+ RecyclerView material;
+
+ private DialogView mDialogVisual;
+ private DialogView mParSetVisual;
+ /**
+ * 库位选择
+ */
+ private DialogView mWarehouselocSelectVisual;
+
+
+ @Override
+ protected View onCreateView() {
+ View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_double_fryingpan, null);
+ ButterKnife.bind(this, root);
+ return root;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ OpenGoodSelectDialog();
+ Init();
+ DoubleFryingpanControl.getInstance().completeNotify= new ICompleteNotify() {
+ @Override
+ public void onComplete(int num) {
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (num==1){
+ btn1.setText("选择菜品");
+ btn1.setBackgroundResource(R.drawable.button4);
+ btn1.setVisibility(View.VISIBLE);
+ btn1.setTextColor(Color.parseColor("#000000"));
+ }
+ else if (num==2){
+ btn2.setText("选择菜品");
+ btn2.setBackgroundResource(R.drawable.button4);
+ btn2.setVisibility(View.VISIBLE);
+ btn2.setTextColor(Color.parseColor("#000000"));
+ }
+ }
+ });
+ }
+ };
+
+ String status = ModbusMaster.get().IsConnected?"已连接":"未连接";
+ mTopBar.setTitle("机器人连接状态:"+ status);
+
+ DoubleFryingpanControl.getInstance().statusNotify=new IStatusNotify() {
+ @Override
+ public void OnStatusChanged(String s1, String s2, String s3, String s4) {
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ tv_Status1.setText(s1);
+ tv_Status2.setText(s2);
+ String status = ModbusMaster.get().IsConnected?"已连接":"未连接";
+ mTopBar.setTitle("机器人连接状态:"+ status);
+
+ }
+ });
+ }
+ };
+
+
+ mDialogVisual= DialogManager.getInstance().initView(getContext(), R.layout.activity_material_view, Gravity.BOTTOM);
+ mParSetVisual = DialogManager.getInstance().initView(getContext(),R.layout.activity_par_set1,Gravity.BOTTOM);
+ mWarehouselocSelectVisual = DialogManager.getInstance().initView(getContext(),R.layout.activity_warehouseloc_select,Gravity.BOTTOM);
+
+ }
+
+ @SuppressLint("HandlerLeak")
+ private Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.obj.toString()== "MSG_REFRESH") {
+ if(ConfigName.getInstance().cloudGoods!=null && ConfigName.getInstance().cloudGoods.size()>0)
+ {
+// getActivity().runOnUiThread(new Runnable() {
+// @Override
+// public void run(){
+// ArrayList goods= QueryDB.GetGoodsALL();
+// ArrayList rec= QueryDB.GetGoodsSrecipeALL();
+// for (BPA_GOODS good:goods)
+// {
+// QueryDB.DeleteGoods(good);
+// }
+// for (BPA_GOODSRECIPE pf:rec)
+// {
+// QueryDB.DeleteGoodsSrecipe(pf);
+// }
+// for (CloudGood item : ConfigName.getInstance().cloudGoods) {
+// ConfigData.getInstance().GetGoodProcess(getContext(),item.id,false);
+// }
+// }
+// });
+
+ ArrayList goods= QueryDB.GetGoodsALL();
+ ArrayList rec= QueryDB.GetGoodsSrecipeALL();
+ for (BPA_GOODS good:goods)
+ {
+ QueryDB.DeleteGoods(good);
+ }
+ for (BPA_GOODSRECIPE pf:rec)
+ {
+ QueryDB.DeleteGoodsSrecipe(pf);
+ }
+ for (CloudGood item : ConfigName.getInstance().cloudGoods) {
+ ConfigData.getInstance().GetGoodProcess(getContext(),item.id,false);
+ }
+ LoadingGood();
+ }
+ MessageLog.ShowInfo( "handleMessage: 获取商品信息成功");
+ }
+ }
+ };
+
+ private void Init(){
+ MessageLog.ShowInfo("Init: 开始获取云端数据");
+ ConfigData.getInstance().GetOrganize(getContext());
+ ConfigData.getInstance().GetGevGood(getContext(),mHandler);
+ }
+
+ private void OpenParSet(){
+ //参数配置界面确认按钮
+ ButtonClickBinder(mParSetVisual, R.id.parset_ok_btn,()->{
+ MessageLog.ShowInfo( "onClick: 确认参数配置");
+
+ if(!ModbusMaster.get().IsConnected){
+ AlertDialogUtils.showDialog(getContext(),"提示","请先连接机器人");
+ return;
+ }
+
+ DoubleFryingpanControl.getInstance(). GoodDown(fry.GoodID,fry.FryingPanNum);
+
+ try {
+ long startTime=System.currentTimeMillis();
+ while(!DoubleFryingpanControl.getInstance().GetGoodVery(fry.FryingPanNum)&&(System.currentTimeMillis()-startTime)<=4000){
+ Thread.sleep(100);
+ }
+
+ if (DoubleFryingpanControl.getInstance().GetGoodVery(fry.FryingPanNum)){
+ if (fry.FryingPanNum==1){
+ btn1.setText("强制取消");
+ btn1.setBackgroundResource(R.drawable.button5);
+ btn1.setTextColor(Color.parseColor("#ffffff"));
+ }
+ else if (fry.FryingPanNum==2){
+ btn2.setText("强制取消");
+ btn2.setBackgroundResource(R.drawable.button5);
+ btn2.setTextColor(Color.parseColor("#ffffff"));
+ }
+
+ DoubleFryingpanControl.getInstance().FryingPan.put(fry.FryingPanNum,fry);
+ fry=new FryingPanPar();
+ DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
+ }
+ else{
+ AlertDialogUtils.showDialog(getContext(),"提示","商品验证失败");
+ }
+ }
+ catch (InterruptedException e) {
+
+ }
+ });
+
+ //参数配置界面取消按钮
+ ButtonClickBinder(mParSetVisual, R.id.parset_cancel_btn, ()->{
+ MessageLog.ShowInfo( "onClick: 退出参数配置");
+ fry=new FryingPanPar();
+ DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
+ });
+
+ DialogManager.getInstance().hide(mDialogVisual);//关闭商品选择窗口
+ DialogManager.getInstance().show(mParSetVisual,R.id.parset_close_dialog); //打开参数设置窗口
+ ParSetInit(R.id.location_selection_1,new String[] {"0", "1", "2", "3", "4","5","6"});
+ ParSetInit(R.id.location_selection_2,new String[] {"0", "1", "2", "3", "4","5","6"});
+ ParSetInit(R.id.accessories_selection_1,new String[] {"0", "1", "2", "3", "4","5"});
+ ParSetInit(R.id.accessories_selection_2,new String[] {"0", "1", "2", "3", "4","5"});
+ }
+
+ int Warehouseloc=0;
+
+ /**
+ * 手动入库
+ */
+ private void WarehouselocInit(){
+ ButtonClickBinder(mWarehouselocSelectVisual, R.id.parset_ok_btn,()->{
+ if(Warehouseloc>=1&&Warehouseloc<=6){
+ btn_warehousing.setEnabled(false);//禁用按钮
+ btn_warehousing.setText("入库中...");
+ ModbusMaster.get().WriteShort("GI0",(short) (Warehouseloc+30),1,null);//写入机器人主任务,指定入库位置
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ while(!RobotData.RobotWarehousingComplete[Warehouseloc-1]){
+ Thread.sleep(100);
+ }
+
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ btn_warehousing.setText("入库");
+ btn_warehousing.setEnabled(true);//禁用按钮
+ }
+ });
+
+ }catch(InterruptedException ex){
+
+ }
+
+ }
+ }).start();
+ }else{
+ AlertDialogUtils.showDialog(getContext(),"提示","错误的库位编号");
+ }
+ });
+
+ //参数配置界面取消按钮
+ ButtonClickBinder(mWarehouselocSelectVisual, R.id.parset_cancel_btn, ()->{
+ MessageLog.ShowInfo("onClick: 退出参数配置");
+ Warehouseloc=0;
+ DialogManager.getInstance().hide(mWarehouselocSelectVisual);//关闭参数设置窗口
+ });
+
+ String[] args=new String[] {"0", "1", "2", "3", "4","5","6"};
+ Spinner sp = mWarehouselocSelectVisual.findViewById(R.id.location_selection_1);
+ ArrayAdapter starAdapter = new ArrayAdapter(getContext(), R.layout.select_item, args);
+ sp.setAdapter(starAdapter);
+ sp.setSelection(0);
+ sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
+ if(R.id.location_selection_1==R.id.location_selection_1) {
+ Warehouseloc=Integer.parseInt(adapterView.getItemAtPosition(i).toString());
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> adapterView) {
+
+ }
+ });
+ }
+
+ FryingPanPar fry=new FryingPanPar();
+ boolean IsMaintenanceMode=false;
+ private void OpenGoodSelectDialog()
+ {
+ MessageManager.getInstance().registerMessageReceiver(getActivity(), MessageName.ClickMakeGoodNew, new MessageLooper.OnMessageListener() {
+ @Override
+ public void onMessage(Object msg) {
+ if (msg != null) {
+ BPA_GOODS goods = (BPA_GOODS) msg;
+ fry.GoodID= goods.id;
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if(!getActivity().isFinishing()){
+ OpenParSet();
+ }
+
+ }
+ });
+
+ }
+ }
+ });
+
+ btn1.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view){
+ ProductSelectionButtonBinder(R.id.main_btn1,1);
+ }
+ });
+
+ btn2.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view){
+ ProductSelectionButtonBinder(R.id.main_btn2,2);
+ }
+ });
+
+ //手动入库
+ btn_warehousing.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view){
+ if(!ModbusMaster.get().IsConnected){
+ AlertDialogUtils.showDialog(getContext(),"提示","机器人未连接");
+ return;
+ }
+ if(RobotData.RobotIdle){
+ WarehouselocInit();
+ mWarehouselocSelectVisual.setCanceledOnTouchOutside(false);
+ DialogManager.getInstance().show(mWarehouselocSelectVisual,R.id.close_dialog); //打开商品选择窗口
+ }
+ else{
+ AlertDialogUtils.showDialog(getContext(),"提示","机器人忙碌中,请稍后");
+ }
+ }
+ });
+
+ //机器人维护
+ btn_maintenance.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view){
+ if(!ModbusMaster.get().IsConnected){
+ AlertDialogUtils.showDialog(getContext(),"提示","机器人未连接");
+ return;
+ }
+ if(!IsMaintenanceMode)
+ {
+ if(RobotData.RobotIdle){
+ AlertDialogUtils.showDialog(getContext(), "提示", "是否进入机器人维护模式?", new QMUIDialogAction.ActionListener() {
+ @Override
+ public void onClick(QMUIDialog dialog, int index) {
+ btn_maintenance.setEnabled(false);//禁用按钮
+ btn_warehousing.setText("维护模式中...");
+ ModbusMaster.get().WriteShort("GI0",(short) (41),1,null);//写入机器人主任务,指定入库位置
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ while(!RobotData.RobotReachTending){
+ Thread.sleep(100);
+ }
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ btn_warehousing.setText("完成维护");
+ btn_warehousing.setEnabled(true);//取消禁用按钮
+ }
+ });
+
+ }catch(InterruptedException ex){
+ }
+ }
+ }).start();
+ }
+ });
+
+ }
+ else{
+ AlertDialogUtils.showDialog(getContext(),"提示","机器人忙碌中,请稍后");
+ }
+ }
+ else{
+ ModbusMaster.get().WriteBool(DoubleFryingpanControl.getInstance().RobotAddress("M520"), true,1,null);//写入机器人主任务,指定入库位置
+ btn_warehousing.setText("维护");
+ IsMaintenanceMode=false;
+ }
+
+ }
+ });
+ }
+
+ /**
+ * 同步商品
+ */
+ private void synchronous(){
+ Button btn=mDialogVisual.findViewById(R.id.synchronous);
+ btn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Init();
+ LoadingGood();
+ }
+ });
+ }
+
+ /**
+ * 加载商品
+ */
+ public void LoadingGood() {
+ ArrayList goods= QueryDB.GetGoodsALL();
+ ArrayList goodsm=new ArrayList<>();
+ if (goods.size()>0){
+ for (BPA_GOODS item:goods)goodsm.add(item);
+ }else{
+ for(CloudGood item: ConfigName.getInstance().cloudGoods){
+ BPA_GOODS bpa=new BPA_GOODS();
+ bpa.name=item.goods_Name;
+ bpa.url=item.goods_ImgUrl;
+ bpa.id=item.id;
+ goodsm.add(bpa);
+ }
+ }
+ List Fdata = new ArrayList<>();
+ Fdata.add(new LinkMode("main", Arrays.asList(goodsm.toArray()),true));
+ MakeGoodRightAdapter rightAdapter = new MakeGoodRightAdapter(R.layout.item_right_lc, Fdata, getResources());
+ material.setAdapter(rightAdapter);
+
+ }
+
+ private void ParSetInit(int id,String[] args)
+ {
+ Spinner sp = mParSetVisual.findViewById(id);
+ ArrayAdapter starAdapter = new ArrayAdapter(getContext(), R.layout.select_item, args);
+ sp.setAdapter(starAdapter);
+ sp.setSelection(0);
+ sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
+ if(R.id.location_selection_1==id) {
+ fry.IngredientsLocs[0]=Integer.parseInt(adapterView.getItemAtPosition(i).toString());
+ }
+ else if (R.id.location_selection_2==id) {
+ fry.IngredientsLocs[1]=Integer.parseInt(adapterView.getItemAtPosition(i).toString());;
+ }
+ else if (R.id.accessories_selection_1==id) {
+ fry.AccessoriesLocs[0]=Integer.parseInt(adapterView.getItemAtPosition(i).toString());;
+ }
+ else if (R.id.accessories_selection_2==id) {
+ fry.AccessoriesLocs[1]=Integer.parseInt(adapterView.getItemAtPosition(i).toString());;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> adapterView) {
+
+ }
+ });
+ }
+
+ /**
+ * 菜品选择事件执行
+ * @param id 按钮id
+ * @param FiryNum 炒锅编号
+ */
+ private void ProductSelectionButtonBinder(int id,int FiryNum){
+ Button btn =getActivity().findViewById(id);
+ if(btn.getText().equals("强制取消"))
+ {
+ AlertDialogUtils.showDialog(getContext(), "提示", "是否强制结束任务?", new QMUIDialogAction.ActionListener() {
+ @Override
+ public void onClick(QMUIDialog dialog, int index) {
+ DoubleFryingpanControl.getInstance().SetForceEnd(FiryNum);
+ btn.setVisibility(View.GONE);
+ dialog.dismiss();
+ }
+ });
+ }
+ else
+ {
+ fry.FryingPanNum=FiryNum;
+ mDialogVisual.setCanceledOnTouchOutside(false);
+ material=mDialogVisual.findViewById(R.id.rv_material);
+ synchronous();
+ LoadingGood();
+ if(!getActivity().isFinishing())
+ DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+ }
+
+ }
+
+ /**
+ * 弹框按钮事件绑定
+ * @param dv 弹框页面
+ * @param id 按钮id
+ * @param action 执行委托
+ */
+ private void ButtonClickBinder(DialogView dv,int id, IRun action){
+ if(dv!=null&& !dv.findViewById(id).hasOnClickListeners()){
+ dv.findViewById(id).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if(action!=null) action.Run();
+ }
+ });
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java
index b91f9e71..d3165b25 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java
@@ -187,7 +187,6 @@ public class MakeGoodFragment extends BaseFragment {
rv_left.setAdapter(leftAdapter);
rv_right.setAdapter(rightAdapter);
-
//添加分组悬浮效果
List typeListener = new ArrayList<>();
for (LinkMode item : Fdata) {
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/RobotMain.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/RobotMain.java
index 45f0ac7c..9e5ea305 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/RobotMain.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/RobotMain.java
@@ -1,7 +1,10 @@
package com.bonait.bnframework.modules.home.fragment;
+import android.annotation.SuppressLint;
+import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -10,27 +13,57 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
+import com.bonait.bnframework.business.DoubleFryingpanControl;
+import com.bonait.bnframework.business.ExecuteTheRecipe;
+import com.bonait.bnframework.business.FryingPanPar;
+import com.bonait.bnframework.business.ICompleteNotify;
+import com.bonait.bnframework.business.IStatusNotify;
+import com.bonait.bnframework.business.OrderData;
+import com.bonait.bnframework.business.RobotControl;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
+import com.bonait.bnframework.common.constant.DataBus;
+import com.bonait.bnframework.common.constant.MessageName;
+import com.bonait.bnframework.common.db.QueryDB;
+import com.bonait.bnframework.common.db.mode.BPA_GOODS;
+import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
+import com.bonait.bnframework.common.db.res.ResGoodsMake;
import com.bonait.bnframework.common.helper.I.IRun;
+import com.bonait.bnframework.common.helper.I.MyClickListener;
+import com.bonait.bnframework.common.linktab.LinkMode;
+import com.bonait.bnframework.common.linktab.makegood.MakeGoodLeftAdapter;
+import com.bonait.bnframework.common.linktab.makegood.MakeGoodRightAdapter;
+import com.bonait.bnframework.common.message.MessageLooper;
+import com.bonait.bnframework.common.message.MessageManager;
+import com.bonait.bnframework.common.modbus.ModbusMaster;
+import com.bonait.bnframework.common.model.mode.CloudGood;
+import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.dialog.DialogManager;
import com.bonait.bnframework.dialog.DialogView;
+import com.bonait.bnframework.modules.home.adapter.loadinggood_adapter;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
+import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
+import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class RobotMain extends BaseFragment {
-// @BindView(R.id.robot_topbar)
-// QMUITopBarLayout mTopBar;//顶部标题
-
@BindView(R.id.main_btn1)
Button btn1;
@@ -43,6 +76,23 @@ public class RobotMain extends BaseFragment {
@BindView(R.id.main_btn4)
Button btn4;
+ @BindView(R.id.tv_Status1)
+ TextView tv_Status1;
+
+ @BindView(R.id.tv_Status2)
+ TextView tv_Status2;
+
+ @BindView(R.id.tv_Status3)
+ TextView tv_Status3;
+
+ @BindView(R.id.tv_Status4)
+ TextView tv_Status4;
+
+ @BindView(R.id.robot_topbar)
+ QMUITopBarLayout mTopBar;//顶部标题
+
+ RecyclerView material;
+
private DialogView mDialogVisual;
private DialogView mParSetVisual;
@@ -51,69 +101,449 @@ public class RobotMain extends BaseFragment {
protected View onCreateView() {
View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_robot_main, null);
ButterKnife.bind(this, root);
- return root;
+ return root;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- Init();
OpenGoodSelectDialog();
+ Init();
+
+ String status = ModbusMaster.get().IsConnected?"已连接":"未连接";
+ mTopBar.setTitle("机器人连接状态:"+ status);
+
+ RobotControl.getInstance().completeNotify= new ICompleteNotify() {
+ @Override
+ public void onComplete(int num) {
+// getActivity().runOnUiThread(new Runnable() {
+// @Override
+// public void run() {
+// if (num==1)btn3.setVisibility(View.VISIBLE);
+// else if (num==2)btn1.setVisibility(View.VISIBLE);
+// else if (num==3)btn4.setVisibility(View.VISIBLE);
+// else if (num==4)btn2.setVisibility(View.VISIBLE);
+// }
+// });
+
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (num==1){
+ btn3.setText("选择菜品");
+ btn3.setVisibility(View.VISIBLE);
+ btn3.setBackgroundResource(R.drawable.button4);
+ btn3.setTextColor(Color.parseColor("#000000"));
+ }
+ else if (num==2){
+ btn1.setText("选择菜品");
+ btn1.setVisibility(View.VISIBLE);
+ btn1.setBackgroundResource(R.drawable.button4);
+ btn1.setTextColor(Color.parseColor("#000000"));
+ }
+ else if (num==3){
+ btn4.setText("选择菜品");
+ btn4.setVisibility(View.VISIBLE);
+ btn4.setBackgroundResource(R.drawable.button4);
+ btn4.setTextColor(Color.parseColor("#000000"));
+ }
+ else if (num==4){
+ btn2.setText("选择菜品");
+ btn2.setVisibility(View.VISIBLE);
+ btn2.setBackgroundResource(R.drawable.button4);
+ btn2.setTextColor(Color.parseColor("#000000"));
+ }
+ }
+ });
+ }
+ };
+
+ RobotControl.getInstance().statusNotify=new IStatusNotify() {
+ @Override
+ public void OnStatusChanged(String s1, String s2, String s3, String s4) {
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ tv_Status1.setText(s2);
+ tv_Status2.setText(s4);
+ tv_Status3.setText(s1);
+ tv_Status4.setText(s3);
+
+ String status = ModbusMaster.get().IsConnected?"已连接":"未连接";
+ mTopBar.setTitle("机器人连接状态:"+ status);
+
+ }
+ });
+ }
+ };
+
+
mDialogVisual= DialogManager.getInstance().initView(getContext(), R.layout.activity_material_view, Gravity.BOTTOM);
mParSetVisual = DialogManager.getInstance().initView(getContext(),R.layout.activity_par_set,Gravity.BOTTOM);
}
+ @SuppressLint("HandlerLeak")
+ private Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.obj.toString()== "MSG_REFRESH") {
+ if(ConfigName.getInstance().cloudGoods!=null && ConfigName.getInstance().cloudGoods.size()>0)
+ {
+ ArrayList goods= QueryDB.GetGoodsALL();
+ ArrayList rec= QueryDB.GetGoodsSrecipeALL();
+ for (BPA_GOODS good:goods)
+ {
+ QueryDB.DeleteGoods(good);
+ }
+ for (BPA_GOODSRECIPE pf:rec)
+ {
+ QueryDB.DeleteGoodsSrecipe(pf);
+ }
+ for (CloudGood item : ConfigName.getInstance().cloudGoods) {
+ ConfigData.getInstance().GetGoodProcess(getContext(),item.id,false);
+ }
+ }
+ Log.i("info", "handleMessage: 获取商品信息成功");
+ }
+ }
+ };
+
private void Init(){
+ Log.i("bpa", "Init: 开始获取云端数据");
ConfigData.getInstance().GetOrganize(getContext());
- ConfigData.getInstance().GetGevGood(getContext(),null);
+ ConfigData.getInstance().GetGevGood(getContext(),mHandler);
+ }
+
+ private void OpenParSet(){
+ //参数配置界面确认按钮
+ ButtonClickBinder(mParSetVisual, R.id.parset_ok_btn,()->{
+ Log.i("TAG", "onClick: 确认参数配置");
+
+ if(!ModbusMaster.get().IsConnected){
+ AlertDialogUtils.showDialog(getContext(),"提示","请先连接机器人");
+ return;
+ }
+ RobotControl.getInstance(). GoodDown(fry.GoodID,fry.FryingPanNum);
+
+ try {
+// Thread.sleep(4000);
+ long startTime=System.currentTimeMillis();
+ while(!RobotControl.getInstance().GetGoodVery(fry.FryingPanNum)&&(System.currentTimeMillis()-startTime)<=4000){
+ Thread.sleep(100);
+ }
+
+ if (RobotControl.getInstance().GetGoodVery(fry.FryingPanNum)){
+ if (fry.FryingPanNum==1) {
+ btn3.setText("强制取消");
+ btn3.setBackgroundResource(R.drawable.button5);
+ btn3.setTextColor(Color.parseColor("#ffffff"));
+ }
+ else if (fry.FryingPanNum==2){
+ btn1.setText("强制取消");
+ btn1.setBackgroundResource(R.drawable.button5);
+ btn1.setTextColor(Color.parseColor("#ffffff"));
+ }
+ else if (fry.FryingPanNum==3) {
+ btn4.setText("强制取消");
+ btn4.setBackgroundResource(R.drawable.button5);
+ btn4.setTextColor(Color.parseColor("#ffffff"));
+ }
+ else if (fry.FryingPanNum==4) {
+ btn2.setText("强制取消");
+ btn2.setBackgroundResource(R.drawable.button5);
+ btn2.setTextColor(Color.parseColor("#ffffff"));
+ }
+ RobotControl.getInstance().FryingPan.put(fry.FryingPanNum,fry);
+ fry=new FryingPanPar();
+ DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
+ }
+ else{
+ AlertDialogUtils.showDialog(getContext(),"提示","商品验证失败");
+ }
+ }
+ catch (InterruptedException e) {
+
+ }
+
+// if (RobotControl.getInstance().GetGoodVery(fry.FryingPanNum)){
+// if (fry.FryingPanNum==1)btn3.setVisibility(View.GONE);
+// else if (fry.FryingPanNum==2)btn1.setVisibility(View.GONE);
+// else if (fry.FryingPanNum==3)btn4.setVisibility(View.GONE);
+// else if (fry.FryingPanNum==4)btn2.setVisibility(View.GONE);
+// RobotControl.getInstance().FryingPan.put(fry.FryingPanNum,fry);
+// fry=new FryingPanPar();
+// DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
+// }
+// else{
+// AlertDialogUtils.showDialog(getContext(),"提示","商品验证失败");
+// }
+
+ });
+
+ //参数配置界面取消按钮
+ ButtonClickBinder(mParSetVisual, R.id.parset_cancel_btn, ()->{
+ Log.i("TAG", "onClick: 退出参数配置");
+ fry=new FryingPanPar();
+ DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
+ });
+
+ DialogManager.getInstance().hide(mDialogVisual);//关闭商品选择窗口
+ DialogManager.getInstance().show(mParSetVisual,R.id.parset_close_dialog); //打开参数设置窗口
+
+ if (fry.FryingPanNum==1){
+ ParSetInit(R.id.location_selection,new String[] { "1", "2", "3"});
+ }else if (fry.FryingPanNum==2){
+ ParSetInit(R.id.location_selection,new String[] { "4","5","6"});
+ }else if (fry.FryingPanNum==3){
+ ParSetInit(R.id.location_selection,new String[] { "4","5","6"});
+ }else if (fry.FryingPanNum==4){
+ ParSetInit(R.id.location_selection,new String[] { "1", "2", "3"});
+ }
+
+// ParSetInit(R.id.location_selection,new String[] {"0", "1", "2", "3", "4","5","6"});
+ ParSetInit(R.id.accessories_selection_1,new String[] {"0", "1", "2", "3", "4","5","6","7","8"});
+ ParSetInit(R.id.accessories_selection_2,new String[] {"0", "1", "2", "3", "4","5","6","7","8"});
}
+ FryingPanPar fry=new FryingPanPar();
+
private void OpenGoodSelectDialog()
{
+ MessageManager.getInstance().registerMessageReceiver(getActivity(), MessageName.ClickMakeGoodNew, new MessageLooper.OnMessageListener() {
+ @Override
+ public void onMessage(Object msg) {
+ if (msg != null) {
+ BPA_GOODS goods = (BPA_GOODS) msg;
+// OrderData.getInstance().goods=(BPA_GOODS) msg ;
+ fry.GoodID= goods.id;
+ OpenParSet();
+ }
+ }
+ });
+
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view){
- mDialogVisual.setCanceledOnTouchOutside(false);
- Button openSetView = mDialogVisual .findViewById(R.id.open);
- openSetView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- //参数配置界面确认按钮
- ButtonClickBinder(mParSetVisual, R.id.parset_ok_btn,()->{
- Log.i("TAG", "onClick: 确认参数配置");
- DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
- });
-
- //参数配置界面取消按钮
- ButtonClickBinder(mParSetVisual, R.id.parset_cancel_btn, ()->{
- Log.i("TAG", "onClick: 退出参数配置");
- DialogManager.getInstance().hide(mParSetVisual);//关闭参数设置窗口
- });
-
- DialogManager.getInstance().hide(mDialogVisual);//关闭商品选择窗口
- DialogManager.getInstance().show(mParSetVisual,R.id.parset_close_dialog); //打开参数设置窗口
-
- ParSetInit(R.id.location_selection,new String[] {"0", "1", "2", "3", "4","5","6"});
- ParSetInit(R.id.accessories_selection_1,new String[] {"0", "1", "2", "3", "4","5","6","7","8"});
- ParSetInit(R.id.accessories_selection_2,new String[] {"0", "1", "2", "3", "4","5","6","7","8"});
- }
- });
- DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+
+ ProductSelectionButtonBinder(R.id.main_btn1,2);
+// if(btn1.getText().equals("强制取消"))
+// {
+// AlertDialogUtils.showDialog(getContext(), "提示", "是否强制结束任务?", new QMUIDialogAction.ActionListener() {
+// @Override
+// public void onClick(QMUIDialog dialog, int index) {
+// RobotControl.getInstance().SetForceEnd(2);
+// btn1.setVisibility(View.GONE);
+// dialog.dismiss();
+// }
+// });
+// }
+// else{
+// fry.FryingPanNum=2;
+// mDialogVisual.setCanceledOnTouchOutside(false);
+// material=mDialogVisual.findViewById(R.id.rv_material);
+// synchronous();
+// LoadingGood();
+// if(!getActivity().isFinishing())
+// DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+// }
+
+
+// fry.FryingPanNum=2;
+// mDialogVisual.setCanceledOnTouchOutside(false);
+// material=mDialogVisual.findViewById(R.id.rv_material);
+// synchronous();
+// LoadingGood();
+// DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+ }
+ });
+
+ btn2.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view){
+ ProductSelectionButtonBinder(R.id.main_btn2,4);
+// if(btn2.getText().equals("强制取消"))
+// {
+// AlertDialogUtils.showDialog(getContext(), "提示", "是否强制结束任务?", new QMUIDialogAction.ActionListener() {
+// @Override
+// public void onClick(QMUIDialog dialog, int index) {
+// RobotControl.getInstance().SetForceEnd(4);
+// btn2.setVisibility(View.GONE);
+// dialog.dismiss();
+// }
+// });
+// }
+// else
+// {
+// fry.FryingPanNum=4;
+// mDialogVisual.setCanceledOnTouchOutside(false);
+// material=mDialogVisual.findViewById(R.id.rv_material);
+// synchronous();
+// LoadingGood();
+// if(!getActivity().isFinishing())
+// DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+// }
+
+
+
+// if(RobotControl.getInstance().GetFryingPan(4)) {
+// fry.FryingPanNum=4;
+// mDialogVisual.setCanceledOnTouchOutside(false);
+// material=mDialogVisual.findViewById(R.id.rv_material);
+// synchronous();
+// LoadingGood();
+// DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+// }
+// else{
+// AlertDialogUtils.showDialog(getContext(),"提示","炒锅状态异常");
+// }
+ }
+ });
+
+ btn3.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view){
+
+ ProductSelectionButtonBinder(R.id.main_btn3,1);
+
+// if(btn3.getText().equals("强制取消"))
+// {
+// AlertDialogUtils.showDialog(getContext(), "提示", "是否强制结束任务?", new QMUIDialogAction.ActionListener() {
+// @Override
+// public void onClick(QMUIDialog dialog, int index) {
+// RobotControl.getInstance().SetForceEnd(1);
+// btn3.setVisibility(View.GONE);
+// dialog.dismiss();
+// }
+// });
+// }
+// else
+// {
+// fry.FryingPanNum=1;
+// mDialogVisual.setCanceledOnTouchOutside(false);
+// material=mDialogVisual.findViewById(R.id.rv_material);
+// synchronous();
+// LoadingGood();
+// if(!getActivity().isFinishing())
+// DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+// }
+
+
+// if(RobotControl.getInstance().GetFryingPan(2)){
+// fry.FryingPanNum=1;
+// mDialogVisual.setCanceledOnTouchOutside(false);
+// material=mDialogVisual.findViewById(R.id.rv_material);
+// synchronous();
+// LoadingGood();
+// DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+// }
+// else{
+// AlertDialogUtils.showDialog(getContext(),"提示","炒锅状态异常");
+// }
+ }
+ });
+
+ btn4.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view){
+
+ ProductSelectionButtonBinder(R.id.main_btn4,3);
+
+// if(btn4.getText().equals("强制取消"))
+// {
+// AlertDialogUtils.showDialog(getContext(), "提示", "是否强制结束任务?", new QMUIDialogAction.ActionListener() {
+// @Override
+// public void onClick(QMUIDialog dialog, int index) {
+// DoubleFryingpanControl.getInstance().SetForceEnd(3);
+// btn4.setVisibility(View.GONE);
+// dialog.dismiss();
+// }
+// });
+// }
+// else
+// {
+// fry.FryingPanNum=3;
+// mDialogVisual.setCanceledOnTouchOutside(false);
+// material=mDialogVisual.findViewById(R.id.rv_material);
+// synchronous();
+// LoadingGood();
+// if(!getActivity().isFinishing())
+// DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+// }
+
+
+// if(RobotControl.getInstance().GetFryingPan(3)){
+// fry.FryingPanNum=3;
+// mDialogVisual.setCanceledOnTouchOutside(false);
+// material=mDialogVisual.findViewById(R.id.rv_material);
+// synchronous();
+// LoadingGood();
+// DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+// }
+// else{
+// AlertDialogUtils.showDialog(getContext(),"提示","炒锅状态异常");
+// }
+ }
+ });
+ }
+
+ /**
+ * 同步商品
+ */
+ private void synchronous(){
+ Button btn=mDialogVisual.findViewById(R.id.synchronous);
+ btn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Init();
+ LoadingGood();
}
});
}
+ /**
+ * 加载商品
+ */
+ public void LoadingGood() {
+ ArrayList goods= QueryDB.GetGoodsALL();
+ ArrayList goodsm=new ArrayList<>();
+ if (goods.size()>0){
+ for (BPA_GOODS item:goods)goodsm.add(item);
+ }else{
+ for(CloudGood item: ConfigName.getInstance().cloudGoods){
+ BPA_GOODS bpa=new BPA_GOODS();
+ bpa.name=item.goods_Name;
+ bpa.url=item.goods_ImgUrl;
+ bpa.id=item.id;
+ goodsm.add(bpa);
+ }
+ }
+ List Fdata = new ArrayList<>();
+ Fdata.add(new LinkMode("main", Arrays.asList(goodsm.toArray()),true));
+ MakeGoodRightAdapter rightAdapter = new MakeGoodRightAdapter(R.layout.item_right_lc, Fdata, getResources());
+ material.setAdapter(rightAdapter);
+ }
+
private void ParSetInit(int id,String[] args)
{
Spinner sp = mParSetVisual.findViewById(id);
ArrayAdapter starAdapter = new ArrayAdapter(getContext(), R.layout.select_item, args);
sp.setAdapter(starAdapter);
sp.setSelection(0);
+
+
+
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
-
+ if(R.id.location_selection==id) {
+ fry.IngredientsLocs[0]=Integer.parseInt(adapterView.getItemAtPosition(i).toString());
+ }
+ else if (R.id.accessories_selection_1==id) {
+ fry.AccessoriesLocs[0]=Integer.parseInt(adapterView.getItemAtPosition(i).toString());;
+ }
+ else if (R.id.accessories_selection_2==id) {
+ fry.AccessoriesLocs[1]=Integer.parseInt(adapterView.getItemAtPosition(i).toString());;
+ }
}
@Override
@@ -123,6 +553,32 @@ public class RobotMain extends BaseFragment {
});
}
+ private void ProductSelectionButtonBinder(int id,int FiryNum){
+ Button btn =getActivity().findViewById(id);
+ if(btn.getText().equals("强制取消"))
+ {
+ AlertDialogUtils.showDialog(getContext(), "提示", "是否强制结束任务?", new QMUIDialogAction.ActionListener() {
+ @Override
+ public void onClick(QMUIDialog dialog, int index) {
+ DoubleFryingpanControl.getInstance().SetForceEnd(FiryNum);
+ btn.setVisibility(View.GONE);
+ dialog.dismiss();
+ }
+ });
+ }
+ else
+ {
+ fry.FryingPanNum=FiryNum;
+ mDialogVisual.setCanceledOnTouchOutside(false);
+ material=mDialogVisual.findViewById(R.id.rv_material);
+ synchronous();
+ LoadingGood();
+ if(!getActivity().isFinishing())
+ DialogManager.getInstance().show(mDialogVisual,R.id.close_dialog); //打开商品选择窗口
+ }
+
+ }
+
/**
* 弹框按钮事件绑定
* @param dv 弹框页面
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/SheZhifragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/SheZhifragment.java
index 40072e60..e79f35cc 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/SheZhifragment.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/SheZhifragment.java
@@ -12,6 +12,7 @@ import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.modules.home.fragment.from.DeviceInformationActivity;
import com.bonait.bnframework.modules.home.fragment.from.ImageSourceActivity;
+import com.bonait.bnframework.modules.home.fragment.from.LogActivity;
import com.bonait.bnframework.modules.home.fragment.from.PlcControlActivity;
import com.bonait.bnframework.modules.home.fragment.from.SystemParameterActivity;
import com.bonait.bnframework.modules.home.fragment.from.DzcjyActivity;
@@ -54,29 +55,30 @@ public class SheZhifragment extends BaseFragment {
mTopBar.setTitle("订单管理");
}
- @OnClick({R.id.xtcs,R.id.imagegl,R.id.shebeixinxi
- ,R.id.plckz,R.id.dzcsz,R.id.wdsz})
+// @OnClick({R.id.xtcs,R.id.imagegl,R.id.shebeixinxi
+// ,R.id.plckz,R.id.dzcsz,R.id.wdsz})
+ @OnClick({R.id.xtcs,R.id.rl_log})
public void onViewClicked(View view) {
switch (view.getId()) {
- case R.id.plckz://
- skipToActivity(PlcControlActivity.class);
- break;
+// case R.id.plckz://
+// skipToActivity(PlcControlActivity.class);
+// break;
case R.id.xtcs://
skipToActivity(SystemParameterActivity.class);
break;
- case R.id.imagegl://
- skipToActivity(ImageSourceActivity.class);
- break;
- case R.id.shebeixinxi://
- skipToActivity(DeviceInformationActivity.class);
+ case R.id.rl_log://
+ skipToActivity(LogActivity.class);
break;
+// case R.id.shebeixinxi://
+// skipToActivity(DeviceInformationActivity.class);
+// break;
- case R.id.dzcsz://电子秤设置
- skipToActivity(DzcjyActivity.class);
- break;
- case R.id.wdsz://温度设置
- skipToActivity(WdszActivity.class);
- break;
+// case R.id.dzcsz://电子秤设置
+// skipToActivity(DzcjyActivity.class);
+// break;
+// case R.id.wdsz://温度设置
+// skipToActivity(WdszActivity.class);
+// break;
}
}
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java
index 6f629363..9e89feb1 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java
@@ -122,8 +122,12 @@ public class SystemParameterActivity extends BaseActivity {
for (BPA_SYSTEMSET item : bpa_systemsets) {
switch (item.type) {
case -100:
- ConfigName.getInstance().versionSelectionEnum = item.value;
- versionselection.setSelection(material_map_vis.get(item.value));
+ try {
+ ConfigName.getInstance().versionSelectionEnum = item.value;
+ versionselection.setSelection(material_map_vis.get(item.value));
+ }catch(Exception ex){
+
+ }
break;
case -99:
ConfigName.getInstance().Environment = item.value;
diff --git a/app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java b/app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java
index fd6878a9..91f0d37a 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java
@@ -22,7 +22,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
-import com.bonait.bnframework.MainActivity;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.common.base.BaseActivity;
diff --git a/app/src/main/res/drawable/button5.xml b/app/src/main/res/drawable/button5.xml
new file mode 100644
index 00000000..b18827e5
--- /dev/null
+++ b/app/src/main/res/drawable/button5.xml
@@ -0,0 +1,30 @@
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/datatab/layout/activity_main.xml b/app/src/main/res/layout/datatab/layout/activity_main.xml
deleted file mode 100644
index c3e27c48..00000000
--- a/app/src/main/res/layout/datatab/layout/activity_main.xml
+++ /dev/null
@@ -1,213 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/datatab/layout/activity_material_view.xml b/app/src/main/res/layout/datatab/layout/activity_material_view.xml
index 91cbd27d..95584543 100644
--- a/app/src/main/res/layout/datatab/layout/activity_material_view.xml
+++ b/app/src/main/res/layout/datatab/layout/activity_material_view.xml
@@ -8,10 +8,10 @@
tools:context=".material_view">
+ android:layout_height="600dp">
-
+
+
+
@@ -51,10 +68,13 @@
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
-
+
diff --git a/app/src/main/res/layout/datatab/layout/activity_par_set1.xml b/app/src/main/res/layout/datatab/layout/activity_par_set1.xml
new file mode 100644
index 00000000..5151bd4a
--- /dev/null
+++ b/app/src/main/res/layout/datatab/layout/activity_par_set1.xml
@@ -0,0 +1,165 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/datatab/layout/activity_warehouseloc_select.xml b/app/src/main/res/layout/datatab/layout/activity_warehouseloc_select.xml
new file mode 100644
index 00000000..095b6f6c
--- /dev/null
+++ b/app/src/main/res/layout/datatab/layout/activity_warehouseloc_select.xml
@@ -0,0 +1,82 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/datatab/values/strings.xml b/app/src/main/res/layout/datatab/values/strings.xml
index 73862c41..6048840e 100644
--- a/app/src/main/res/layout/datatab/values/strings.xml
+++ b/app/src/main/res/layout/datatab/values/strings.xml
@@ -1 +1,4 @@
-
\ No newline at end of file
+
+
+ Hello blank fragment
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_double_fryingpan.xml b/app/src/main/res/layout/fragment_double_fryingpan.xml
new file mode 100644
index 00000000..7a00aa40
--- /dev/null
+++ b/app/src/main/res/layout/fragment_double_fryingpan.xml
@@ -0,0 +1,198 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_robot_main.xml b/app/src/main/res/layout/fragment_robot_main.xml
index e40a4823..a2be3074 100644
--- a/app/src/main/res/layout/fragment_robot_main.xml
+++ b/app/src/main/res/layout/fragment_robot_main.xml
@@ -40,18 +40,19 @@
android:layout_columnWeight="1">
@@ -59,7 +60,8 @@
android:id="@+id/main_btn1"
android:layout_width="match_parent"
android:layout_height="50dp"
- android:layout_margin="20dp"
+ android:layout_marginTop="10dp"
+ android:layout_marginLeft="20dp"
android:textSize="20sp"
android:background="@drawable/button4"
android:text="选择菜品"/>
@@ -90,18 +92,19 @@
android:layout_columnWeight="1">
@@ -109,7 +112,8 @@
android:id="@+id/main_btn2"
android:layout_width="match_parent"
android:layout_height="50dp"
- android:layout_margin="20dp"
+ android:layout_marginTop="10dp"
+ android:layout_marginLeft="20dp"
android:textSize="20sp"
android:background="@drawable/button4"
android:text="选择菜品"/>
@@ -140,18 +144,19 @@
android:layout_columnWeight="1">
@@ -159,7 +164,8 @@
android:id="@+id/main_btn3"
android:layout_width="match_parent"
android:layout_height="50dp"
- android:layout_margin="20dp"
+ android:layout_marginTop="10dp"
+ android:layout_marginLeft="20dp"
android:textSize="20sp"
android:background="@drawable/button4"
android:text="选择菜品"/>
@@ -190,18 +196,19 @@
android:layout_columnWeight="1">
@@ -209,7 +216,8 @@
android:id="@+id/main_btn4"
android:layout_width="match_parent"
android:layout_height="50dp"
- android:layout_margin="20dp"
+ android:layout_marginTop="10dp"
+ android:layout_marginLeft="20dp"
android:textSize="20sp"
android:background="@drawable/button4"
android:text="选择菜品"/>
diff --git a/app/src/main/res/layout/fragment_she_zhi.xml b/app/src/main/res/layout/fragment_she_zhi.xml
index 16e80bc8..7966cf7f 100644
--- a/app/src/main/res/layout/fragment_she_zhi.xml
+++ b/app/src/main/res/layout/fragment_she_zhi.xml
@@ -29,24 +29,109 @@
android:layout_height="match_parent"
android:orientation="horizontal">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ android:background="@drawable/jcsjgl_bj">
+ android:src="@mipmap/sz3" />
+
+ android:src="@mipmap/new1" />
-
-
-
-
-
-
-
-
-
-
-
@@ -170,133 +214,133 @@
android:layout_height="match_parent"
android:orientation="horizontal">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/mipmap-hdpi/robot.png b/app/src/main/res/mipmap-hdpi/robot.png
new file mode 100644
index 00000000..e4a1487b
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/robot.png differ