diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 767c61ab..6b52cebc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,14 +34,31 @@ tools:node="merge" tools:replace="android:icon"> + + + + + android:exported="false" + tools:ignore="Instantiatable" /> diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTest.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTest.java new file mode 100644 index 00000000..48d35527 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTest.java @@ -0,0 +1,682 @@ +package com.bonait.bnframework.business; + +import android.app.Activity; +import android.content.Context; +import android.content.ContextWrapper; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; + +import androidx.annotation.NonNull; + +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; +import com.bonait.bnframework.common.db.mode.BPA_SILOS; +import com.bonait.bnframework.common.helper.I.IWriteCallBack; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.qmuiteam.qmui.widget.dialog.QMUIDialog; +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ExecuteTest { + public static int whileTime = 40; + + /** + * 商品是否强制结束 + */ + public static boolean IsForcedEnd = false; + + /** + * 是否启动 + */ + public static boolean IsStart = false; + + //region 强制结束 + + /** + * 设置强制结束 + */ + public static void SetForcedEnd() { + ToastUtils.info("客官,小菠萝正在强制结束,请耐心等候!!!"); + IsForcedEnd = true; + } + + /** + * 停止强制结束 + */ + public static void StopForcedEnd() { + IsForcedEnd = false; + } + //endregion + + //region 执行配方 + /** + * 执行工序步骤 + * + * @param text + */ + public static void ExecuteOperationSteps(String processname, String text) { + try { + if (!text.isEmpty() && !processname.isEmpty() && !IsForcedEnd) { + //工序名称和值 + HashMap formulation = new HashMap<>(); + //region 获取仓号和值 + List data = new ArrayList<>(); + if (text.contains("|")) { + String[] res = text.split("[|]"); + for (int i = 0; i < res.length; i++) { + data.add(res[i]); + } + } else { + data.add(text); + } + for (String item : data) { + if (!item.isEmpty() && item.contains(",")) { + String[] wl = item.split("[,]"); + if (wl != null && wl.length == 2) { + String name = wl[0]; + String val = wl[1]; + formulation.put(name, val); + } + } + } + //endregion + //写入PLC + if (formulation.size() > 0) { + switch (processname) { + case "搅拌": + Write_PLC_Stir(formulation); + break; + case "位置": + Write_PLC_Location(formulation); + break; + case "加热": + Write_PLC_Heating(formulation); + break; + case "主料": + Write_PLC_Ingredients(formulation); + break; + case "延迟": + Write_PLC_Delay(formulation); + break; + case "清洗": + Write_PLC_CleanPan(formulation); + break; + } + } + } + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + //endregion + + //region 物料PLC控制 + + /** + * 写入仓号需求值 + * + * @param silos + * @param val + */ + public static void Write_PLC_Material(int silos, int val) { + try { + if(IsForcedEnd){ return;} + ToastUtils.info("准备写入PLC仓号需求:" + silos + "," + val / 10.0); + + String name = "料仓" + silos + "下料完成"; + ExecuteTheRecipe.WritePLC(name, false, null); + + final boolean[] IsComplete = {false}; + + ExecuteTheRecipe.WritePLC("料仓" + silos + "需求值", val, new IWriteCallBack() { + @Override + public void onSuccess() { + BottomClick("料仓" + silos + "下料"); + IsComplete[0] = true; + } + + @Override + public void onFailure(String ErrorMsg) { + } + }); + long a = System.currentTimeMillis(); + while (!IsComplete[0]) { + if ((System.currentTimeMillis() - a) > 1000 * whileTime) { + break; + } + Thread.sleep(100);//10 *6 + } + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + //endregion + + //region 写PLC工序 + + /** + * 写PLC搅拌 + * + * @param data + */ + private static void Write_PLC_Stir(HashMap data) { + try { + int val = 0; + + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key.contains("(秒)")) { + val = Integer.parseInt(value); + } else { + ToastUtils.info("工序:" + key + "," + value); + int writeValue = GetMXValue(key, value); + ExecuteTheRecipe.WritePLC(key, writeValue, new IWriteCallBack() { + @Override + public void onSuccess() { + if (writeValue == 0) { + ExecuteTheRecipe.WritePLC("搅拌", false, null); + } else { + ExecuteTheRecipe.WritePLC("搅拌", true, null); + } + } + + @Override + public void onFailure(String ErrorMsg) { + } + }); + } + } + + if (val > 0) { + ThreadDelay(val); + //Thread.sleep(val * 1000); + } + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + + /** + * 写PLC位置 + * + * @param data + */ + private static void Write_PLC_Location(HashMap data) { + try { + int val = 0; + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key.contains("(秒)")) { + val = Integer.parseInt(value); + } else if (key.contains("速度")) { + int writeValue = GetMXValue(key, value); + //修改最高速度40 + ExecuteTheRecipe.WritePLC(key, writeValue >= 30 ? 30 : writeValue, null); + } + } + + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (!key.contains("(秒)") && !key.contains("速度")) { + ToastUtils.info("工序:" + key + "," + value); + + //原点位,等待机器移动倒响应位置 + BottomClick1(value); + //一直等待机器移动到该位置,否则就一直等待 6s超时 + String name = value + "反馈"; + final boolean[] IsComplete = {false}; + long a = System.currentTimeMillis(); + Log.e("等待反馈", name + ",等待中"); + while (!IsComplete[0] && !IsForcedEnd) { + if ((System.currentTimeMillis() - a) > 1000 * whileTime) { + break; + } else { + Object sb = ExecuteTheRecipe.ReadPLC(name);//ListeningValue.get(name); + if (sb != null) { + IsComplete[0] = (boolean) (sb); + } + } + Thread.sleep(100);//10 *6 + } + Log.e("等待反馈", name + ",等待结束"); + + ToastUtils.info("炒锅到达" + value + ",继续制作!!!"); + } + } + + if (val > 0 && !IsForcedEnd) { + ThreadDelay(val); + //Thread.sleep(val * 1000); + } + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + + /** + * 写PLC主料 + * + * @param data + */ + private static void Write_PLC_Ingredients(HashMap data) { + try { + //是否手动 + boolean ishand = true; + ToastUtils.info("准备倒入主料!"); + + //region 判断是否手动 + if (ConfigName.getInstance().versionSelectionEnum.equals("大炒版本")) { + ishand = true; + } else { + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key.contains("投料动作")) { + if (value.contains("手动投料")) { + ishand = true; + } else { + ishand = false; + } + } + } + } + //endregion + + + if (ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本") || ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) { + String writeValue = "1号位"; + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key.contains("主料位置")) { + writeValue = value; + } + } + + + //1.去某一个位置 + BottomClick1("平移-去" + writeValue); + + + Log.d("平移", "平移-去" + writeValue); + //一直等待机器移动到该位置,否则就一直等待 6s超时 + String name = "平移轴在" + writeValue; + final boolean[] IsComplete = {false}; + long a = System.currentTimeMillis(); + while (!IsComplete[0] && !IsForcedEnd) { + if ((System.currentTimeMillis() - a) > 1000 * whileTime) { + break; + } else { + Object sb = ExecuteTheRecipe.ReadPLC(name);// ListeningValue.get(name); + if (sb != null) { + IsComplete[0] = (boolean) (sb); + } + } + Thread.sleep(100);//10 *6 + } + Log.d("平移", name + "已经就位"); + + //2.给倒菜启动 + BottomClick1("主料"); + name = "倒菜完成"; + IsComplete[0] = false; + a = System.currentTimeMillis(); + while (!IsComplete[0] && !IsForcedEnd) { + if ((System.currentTimeMillis() - a) > 1000 * whileTime) { + break; + } else { + Object sb = ExecuteTheRecipe.ReadPLC(name);// ListeningValue.get(name); + if (sb != null) { + IsComplete[0] = (boolean) (sb); + } + } + Thread.sleep(100);//10 *6 + } + ToastUtils.info("主料倒入完成,继续制作!"); + + } + + Log.d("倒菜", "倒菜完成了"); + //判断是否有烹饪时间 + int val = 0; + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key.contains("(秒)")) { + val = Integer.parseInt(value); + } + } + if (val > 0 && !IsForcedEnd) { + ThreadDelay(val); + //Thread.sleep(val * 1000); + } + + Log.d("烹饪时间", "烹饪时间完成了"); + + + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + + /** + * 按下 + * + * @param name + */ + public static void BottomClick(String name) { + try { + Log.e("按钮按下", name); + ExecuteTheRecipe.WritePLC(name, true, null); + new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { + @Override + public void run() { + Log.e("按钮复位", name); + ExecuteTheRecipe.WritePLC(name, false, null); + } + }, 500); + } catch (Exception ex) { + Log.e("按钮异常", name + ex.getMessage()); + } + } + + /** + * 组断执行 + * + * @param name + */ + public static void BottomClick1(String name) { + try { + Log.e("按钮按下", name); + ExecuteTheRecipe.WritePLC(name, true, null); + Thread.sleep(200); + ExecuteTheRecipe.WritePLC(name, false, null); + Log.e("按钮复位", name); + } catch (Exception ex) { + Log.e("按钮异常", name + ex.getMessage()); + ExecuteTheRecipe.WritePLC(name, false, null); + } + } + + /** + * 写PLC 加热 + * + * @param data + */ + private static void Write_PLC_Heating(HashMap data) { + try { + int val = 0; + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key.contains("(秒)")) { + val = Integer.parseInt(value); + } else { + ToastUtils.info("工序:" + key + "," + value); + int writeValue = GetMXValue(key, value); + //写加热挡位 + ExecuteTheRecipe.WritePLC(key, writeValue, null); + if (writeValue == 0) { + ConfigName.getInstance().IsOpenHuoLi = false; + ExecuteTheRecipe.WritePLC("加热", false, null); + } else { + ConfigName.getInstance().IsOpenHuoLi = true; + ExecuteTheRecipe.WritePLC("加热", true, null); + } + } + } + + if (val > 0 && !IsForcedEnd) { + ThreadDelay(val); + //Thread.sleep(val * 1000); + } + + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + + /** + * 火力点击 + * + * @param data + */ + public static void Write_PLC_HuoLI(int data) { + try { + ExecuteTheRecipe.WritePLC("加热功率", data, new IWriteCallBack() { + @Override + public void onSuccess() { + if (data == 0) { + ConfigName.getInstance().IsOpenHuoLi = false; + ExecuteTheRecipe.WritePLC("加热", false, null); + } else { + ConfigName.getInstance().IsOpenHuoLi = true; + ExecuteTheRecipe.WritePLC("加热", true, null); + } + } + + @Override + public void onFailure(String ErrorMsg) { + } + }); + ToastUtils.info("火力按钮点击,当前级别:" + data); + + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + + /** + * 写PLC 延迟 + * + * @param data + */ + private static void Write_PLC_Delay(HashMap data) { + try { + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + ToastUtils.info("工序:" + key + "," + value); + if (key.contains("(秒)") && !IsForcedEnd) { + int val = Integer.parseInt(value); + ThreadDelay(val); + //Thread.sleep(val * 1000); + } + } + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + + /** + * 写PLC 清洗 + * + * @param data + */ + private static void Write_PLC_CleanPan(HashMap data) { + try { + ToastUtils.info("准备清洗!"); + //先延迟 + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + ToastUtils.info("工序:" + key + "," + value); + if (key.contains("(秒)") && !IsForcedEnd) { + int val = Integer.parseInt(value); + ThreadDelay(val); + //Thread.sleep(val * 1000); + } + } + + BottomClick1("炒锅清洗"); + + //一直等待机器移动到该位置,否则就一直等待 6s超时 + String name = "炒锅清洗反馈"; + final boolean[] IsComplete = {false}; + long a = System.currentTimeMillis(); + while (!IsComplete[0] && !IsForcedEnd) { + if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 5)) { + break; + } else { + Object sb = ExecuteTheRecipe.ReadPLC(name);//ListeningValue.get(name); + if (sb != null) { + IsComplete[0] = (boolean) (sb); + } + } + Thread.sleep(100);//10 *6 + } + + ToastUtils.info("炒锅清洗完成!"); + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } + } + //endregion + + //region 获取基础挡位变量 + /** + * 获取挡位变量 + * + * @param name + * @param value + * @return + */ + public static int GetMXValue(String name, String value) { + final int[] ReturnsVariable = {0}; + try { + if (name.contains("速度")) { + ReturnsVariable[0] = ConfigName.getInstance().StirringSpeed.get(value); + } else if (name.contains("功率")) { + ReturnsVariable[0] = ConfigName.getInstance().HeatingGear.get(value); + int max = ConfigName.getInstance().HeatingGear.get(ConfigName.getInstance().HuoLi); + if (ReturnsVariable[0] > max) { + ReturnsVariable[0] = max; + } + } + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } finally { + return ReturnsVariable[0]; + } + } + //endregion + + //region 延迟函数 + + /** + * 线程延迟函数(避免线程阻塞等待) + * + * @param delay + */ + public static void ThreadDelay(int delay) { + long startTime = System.currentTimeMillis(); + while ((System.currentTimeMillis() - startTime) <= (delay * 1000) && !IsForcedEnd) // + { + try { + Thread.sleep(100); + } catch (InterruptedException ex) { + } + } + } + //endregion + + //region 获取工艺 + /** + * 获取延迟 + * + * @param time + * @return + */ + public static BPA_GOODSRECIPE Get延迟(int time) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "延迟"; + pf.processms = "延迟(" + time + ")"; + pf.processvalue = "延迟(秒)," + time; + return pf; + } + + /** + * 获取主料 + * + * @param wz + * @return + */ + public static BPA_GOODSRECIPE Get主料(int wz) { + String ms = "未知"; + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "主料"; + pf.processms = "主料(" + ms + "," + wz + "号位,0,直接投出,0)"; + pf.processvalue = "主料名称," + ms + "|主料位置," + wz + "号位|主料重量,0|投料动作,直接投出|烹饪(秒),0"; + return pf; + } + /** + * 获取位置 + * + * @param + * @return + */ + public static BPA_GOODSRECIPE Get位置(String name) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "位置"; + pf.processms = "位置(高速," + name + ",0)"; + pf.processvalue = "转动速度,高速|位置动作," + name + "|延迟(秒),0"; + return pf; + } + + /** + * 获取搅拌 + * + * @param sd + * @return + */ + public static BPA_GOODSRECIPE Get搅拌(String sd) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "搅拌"; + pf.processms = "搅拌(" + sd + ",0)"; + pf.processvalue = "搅拌速度," + sd + "|延迟(秒),0"; + return pf; + } + + /** + * 获取加热 + * + * @param sd + * @return + */ + public static BPA_GOODSRECIPE Get加热(String sd) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "加热"; + pf.processms = "加热(" + sd + ",0)"; + pf.processvalue = "加热功率," + sd + "|延迟(秒),0"; + return pf; + } + + /** + * 获取清洗 + * + * @return + */ + public static BPA_GOODSRECIPE Get清洗(int k) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "清洗"; + pf.processms = "清洗(" + k + ")"; + pf.processvalue = "等待(秒)," + k; + return pf; + } + //endregion +} diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java index 8c015d8c..b0adfbc1 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -83,7 +83,10 @@ public class ExecuteTheRecipe { * 当前工序的index */ static int Index_select = 0; - + /** + * 商品是否开始制作 + */ + public static boolean MakeStatus = false; /** * 是否启动 */ diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java b/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java index be3b5706..9338e865 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java @@ -229,6 +229,11 @@ public class DataBus { * 选择菜品事件 */ public MyClickListener mListener=null; + + /** + * 选择菜品事件 + */ + public MyClickListener mListener1=null; /** * 获取商品数据 */ diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gnleft_adapter.java b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gnleft_adapter.java new file mode 100644 index 00000000..291ba356 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gnleft_adapter.java @@ -0,0 +1,70 @@ +package com.bonait.bnframework.modules.home.adapter; + +import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; +import com.bonait.bnframework.common.helper.I.MyClickListener; + +import java.util.List; + +public class gnleft_adapter extends ArrayAdapter { + /** + * 内部点击事件 + */ + private MyClickListener mListener; + private List datas; + + private int selectedPosition = -1;// 选中的位置 + int resource1; + + public gnleft_adapter(@NonNull Context context, int resource, @NonNull List objects, MyClickListener listener) { + super(context, resource, objects); + mListener = listener; + datas = objects; + this.resource1 = resource; + } + + public int getSelectedPosition() { + return selectedPosition; + } + + public void setSelectedPosition(int position) { + selectedPosition = position; + } + + //每个子项被滚动到屏幕内的时候会被调用 + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + String lc = (String) getItem(position);//得到当前项选中item实例 + //为每一个子项加载设定的布局 + View view = LayoutInflater.from(getContext()).inflate(resource1, parent, false); + //分别获取 image view 和 textview 的实例 + RelativeLayout layout=view.findViewById(R.id.tv_type_layout); + RelativeLayout image=view.findViewById(R.id.tv_image); + TextView text = view.findViewById(R.id.tv_type); + text.setText(lc+""); + + if (selectedPosition == position) { + layout.setBackground(getContext().getResources().getDrawable(R.color.main_background)); + image.setVisibility(View.VISIBLE); + text.setTextColor(getContext().getResources().getColor(R.color.app_color_blue)); + } else { + layout.setBackground(getContext().getResources().getDrawable(R.color.white)); + image.setVisibility(View.GONE); + text.setTextColor(getContext().getResources().getColor(R.color.tab_text_normal) ); + } + return view; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java index c4414cab..15777814 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java @@ -132,10 +132,6 @@ public class Home1Fragment extends BaseFragment { @BindView(R.id.wk_zhuangtai) QMUILinkTextView wk_zhuangtai;// - /** - * 商品是否开始制作 - */ - public boolean Status = false; /** * 当前制作商品信息 */ @@ -189,7 +185,7 @@ public class Home1Fragment extends BaseFragment { caipumingcheng.setText(""); shengyushijian.setText("预计剩余时间:0s"); startbutton.setImageResource(R.mipmap.qdzz); - Status = false; + ExecuteTheRecipe.MakeStatus = false; mTopBar.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.app_color_theme_4)); mTopBar.setTitle("菜谱烹饪"); @@ -240,9 +236,9 @@ public class Home1Fragment extends BaseFragment { getActivity().runOnUiThread(new Runnable() { @Override public void run() { - if (!IsMake(true)) { - return; - } +// if (!IsMake(true)) { +// return; +// } good = (BPA_GOODS) data; SetBottonStatus(false); caipumingcheng.setText(good.name); @@ -507,10 +503,10 @@ public class Home1Fragment extends BaseFragment { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { Log.e("鼠标", "按下: "); -// if (!IsMake(false)) -// { -// return false; -// } + if (!IsMake(false)) + { + return false; + } int jd = (int) nifty_slider3.getValue(); ExecuteTheRecipe.WritePLC("转动速度", jd, new IWriteCallBack() { @Override @@ -574,7 +570,7 @@ public class Home1Fragment extends BaseFragment { while (IsRunThread) { try { - if (Status && good != null) { + if ( ExecuteTheRecipe.MakeStatus && good != null) { long startTime = System.currentTimeMillis(); //起始时间 try { //获取工艺 @@ -649,7 +645,7 @@ public class Home1Fragment extends BaseFragment { while (IsRunThread) { try { - if (Status && good != null && gongxuIndex != 10000 && goodsrecipesL != null && MakeCipe != null) { + if ( ExecuteTheRecipe.MakeStatus && good != null && gongxuIndex != 10000 && goodsrecipesL != null && MakeCipe != null) { try { if (ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本") || ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) { //获取工艺 @@ -866,7 +862,7 @@ public class Home1Fragment extends BaseFragment { */ public void SetBottonStatus(boolean status) { try { - Status = status; + ExecuteTheRecipe.MakeStatus = status; if (status) { startbutton.setImageResource(R.mipmap.tzzz); TimerCount(good.maketime, true);//开始计时器,记录进度条 @@ -932,7 +928,7 @@ public class Home1Fragment extends BaseFragment { ToastUtils.info("打开菜谱选择界面"); break; case R.id.startbutton: - if (Status) { + if ( ExecuteTheRecipe.MakeStatus ) { // ToastUtils.info("客官菜谱正在制作过程中,请耐心等待一下,马上就好啦!"); // return; //按钮点击 @@ -1059,7 +1055,7 @@ public class Home1Fragment extends BaseFragment { // return false; // } - if (Status && k) { + if (ExecuteTheRecipe.MakeStatus && k) { ToastUtils.warning("客官,商品制作未结束请勿进行其他操作.请耐心等待商品制作结束!!!"); return false; } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/AutoTestActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/AutoTestActivity.java new file mode 100644 index 00000000..0fd00861 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/AutoTestActivity.java @@ -0,0 +1,164 @@ +package com.bonait.bnframework.modules.home.fragment.from; + +import androidx.annotation.NonNull; +import androidx.viewpager.widget.ViewPager; + +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RelativeLayout; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ExecuteTest; +import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.base.BaseActivity; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; +import com.bonait.bnframework.modules.home.fragment.from.fragment.AutoTestMoreFragment; +import com.bonait.bnframework.modules.home.fragment.from.fragment.AutoTestOneFragment; +import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.qmuiteam.qmui.widget.QMUITopBarLayout; +import com.qmuiteam.qmui.widget.QMUIViewPager; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class AutoTestActivity extends BaseActivity { + + + @BindView(R.id.topbar) + QMUITopBarLayout mTopBar; + @BindView(R.id.navigation) + BottomNavigationView bottomNavigationView; + @BindView(R.id.viewpager) + QMUIViewPager viewPager; + + @BindView(R.id.quanxian) + RelativeLayout quanxian;//权限显示 + @BindView(R.id.edittext_quanxian) + EditText edittext_quanxian;//权限密码 + @BindView(R.id.quanxianmima) + Button quanxianmima;//权限密码 + + private MenuItem menuItem; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_auto_test); + + ButterKnife.bind(this); + initTopBar(); + initFragment(); + viewPager.addOnPageChangeListener(pageChangeListener); + // 设置viewPager缓存多少个fragment + viewPager.setOffscreenPageLimit(2); + bottomNavigationView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + } + + + @Override + public void onWindowFocusChanged(boolean hasFocus) { + super.onWindowFocusChanged(hasFocus); + } + + private void initTopBar() { + mTopBar.setTitle("模块自动测试"); + mTopBar.addLeftImageButton(R.mipmap.fanhui, R.id.topbar).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(ExecuteTest.IsStart || ExecuteTheRecipe.MakeStatus) + { + ToastUtils.warning("请先结束任务!!!"); + return; + }else + { + finish(); + } + } + }); + + quanxianmima.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String s = edittext_quanxian.getText().toString(); + if (s == null || s.isEmpty()) { + ToastUtils.warning("权限密码不能为空!"); + } else { + if (s.equals("bpa123456")) { + quanxian.setVisibility(View.GONE); + viewPager.setVisibility(View.VISIBLE); + } else { + ToastUtils.warning("权限密码不正确!"); + } + } + } + }); + } + + FragmentAdapter fragmentAdapter = null; + + /** + * viewPager里添加fragment + */ + private void initFragment() { + fragmentAdapter = new FragmentAdapter(getSupportFragmentManager()); + fragmentAdapter.addFragment(new AutoTestOneFragment()); + fragmentAdapter.addFragment(new AutoTestMoreFragment()); + viewPager.setAdapter(fragmentAdapter); + } + //-------------------------配置viewPager与fragment关联----------------------------// + /** + * 配置bottom底部菜单栏监听器,手指点击底部菜单监听 + */ + private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener + = new BottomNavigationView.OnNavigationItemSelectedListener() { + + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case R.id.bottom_device_1: + viewPager.setCurrentItem(0); + return true; + case R.id.bottom_device_2: + viewPager.setCurrentItem(1); + return true; + } + return false; + } + }; + + + /** + * 配置ViewPager监听器,手指滑动监听 + */ + private ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + MenuItem menuItem = bottomNavigationView.getMenu().getItem(position); + } + + @Override + public void onPageSelected(int position) { + menuItem = bottomNavigationView.getMenu().getItem(position); + menuItem.setChecked(true); + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + }; + + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Override + protected boolean canDragBack() { + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/Cpxz1Activity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/Cpxz1Activity.java new file mode 100644 index 00000000..c66e707f --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/Cpxz1Activity.java @@ -0,0 +1,114 @@ +package com.bonait.bnframework.modules.home.fragment.from; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.SearchView; +import androidx.recyclerview.widget.RecyclerView; + +import android.os.Bundle; +import android.view.View; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.base.BaseActivity; +import com.bonait.bnframework.common.constant.DataBus; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.helper.I.MyClickListener; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.common.view.MyLayoutManager; +import com.bonait.bnframework.modules.home.adapter.sp_adapter; +import com.qmuiteam.qmui.widget.QMUITopBarLayout; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class Cpxz1Activity extends BaseActivity { + + + @BindView(R.id.topbar) + QMUITopBarLayout mTopBar;//顶部标题 + @BindView(R.id.recycler_view) + RecyclerView recyclerView;//菜谱列表 + @BindView(R.id.search_view) + SearchView search_view;//查询框 + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_cpxz1);//属性绑定 + ButterKnife.bind(this); + initTopBar(); + Init(); + initData(); + } + + private void initTopBar() { + mTopBar.setTitle("菜谱列表"); + mTopBar.addLeftImageButton(R.mipmap.fanhui,R.id.topbar).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + finish(); + } + }); + } + + private void Init() + { + search_view.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String s) { + ToastUtils.info("点击搜索按钮时触发"+s); + return false; + } + + @Override + public boolean onQueryTextChange(String s) { + DataBus.getInstance().GetGoods(s); + ToastUtils.info("搜索内容改变时触发,"+s); + return false; + } + }); + } + + private void initData() { + try{ + MyLayoutManager layout = new MyLayoutManager(); + layout.setAutoMeasureEnabled(true); + recyclerView.setLayoutManager(layout); + DataBus.getInstance().spadapter = new sp_adapter(this); + recyclerView.setAdapter(DataBus.getInstance().spadapter); + DataBus.getInstance().GetGoods(""); + DataBus.getInstance().spadapter.mListener=new MyClickListener() { + @Override + public void clickListener(View v, Object data) { + BPA_GOODS good=(BPA_GOODS)data; + DataBus.getInstance().SelectGood=good; + if( DataBus.getInstance().mListener1!=null) + { + DataBus.getInstance().mListener1.clickListener(v,good); + } + finish(); + } + + @Override + public void clickListenerNew(View v, int k, Object data) { + + } + }; + }catch(Exception e){ + ToastUtils.info("异常信息:"+e.getMessage()); + } + } + + public void initEvent() + { + + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Override + protected boolean canDragBack() { + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DishTestActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DishTestActivity.java index 39f60a00..b7fd21fd 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DishTestActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DishTestActivity.java @@ -271,8 +271,7 @@ public class DishTestActivity extends BaseActivity { touliao_k.setVisibility(View.GONE); touliao_m.setVisibility(View.GONE); device_image.setImageResource(R.mipmap.device00); - }else - { + } else { touliao_k.setVisibility(View.VISIBLE); touliao_m.setVisibility(View.VISIBLE); device_image.setImageResource(R.mipmap.device1); @@ -761,7 +760,7 @@ public class DishTestActivity extends BaseActivity { guoneichoushui.setVisibility(View.VISIBLE); runtime_cs.setBase(SystemClock.elapsedRealtime()); runtime_cs.start(); - IsChouShui=true; + IsChouShui = true; } }); } @@ -780,12 +779,11 @@ public class DishTestActivity extends BaseActivity { DataBus.getInstance().PumpWaterTimeOut = (int) (elapsedMillis / 1000); ClikTime = (int) ((SystemClock.elapsedRealtime() - runtime.getBase()) / 1000); - if(IsChouShui) - { + if (IsChouShui) { BPA_GOODSRECIPE data = Get加水(DataBus.getInstance().PumpWaterTimeOut); DataBus.getInstance().bpa_goodsrecipes.add(data); } - IsChouShui=false; + IsChouShui = false; } }); } @@ -937,7 +935,7 @@ public class DishTestActivity extends BaseActivity { } DataBus.getInstance().bpa_goodsrecipes.add(Get手动主料()); ExecuteTheRecipe.WritePLC("暂停开关", true, null); - //刷新工序 + //刷新工序 RefreshProcedure(); String title = "手动投料-温馨提示!"; String message = "客官请投入主料,投入后点击[确定]继续流程!"; @@ -998,7 +996,8 @@ public class DishTestActivity extends BaseActivity { }).start(); } - boolean IsChouShui=false; + boolean IsChouShui = false; + /** * 抽水 */ diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/AutoTestMoreFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/AutoTestMoreFragment.java new file mode 100644 index 00000000..20fecb29 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/AutoTestMoreFragment.java @@ -0,0 +1,271 @@ +package com.bonait.bnframework.modules.home.fragment.from.fragment; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.base.BaseFragment; +import com.bonait.bnframework.common.constant.DataBus; +import com.bonait.bnframework.common.constant.MessageName; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.db.res.MakeStatus; +import com.bonait.bnframework.common.helper.I.MyClickListener; +import com.bonait.bnframework.common.image.MyBitmapUtils; +import com.bonait.bnframework.common.message.MessageManager; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.common.view.CircleImageView; +import com.bonait.bnframework.modules.home.adapter.gnleft_adapter; +import com.bonait.bnframework.modules.home.fragment.from.Cpxz1Activity; +import com.bonait.bnframework.modules.home.fragment.from.CpxzActivity; +import com.orhanobut.logger.Logger; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class AutoTestMoreFragment extends BaseFragment { + + //region 变量 + @BindView(R.id.cpfm) + CircleImageView cpfm;//菜谱封面 + + @BindView(R.id.cpmc) + TextView cpmc;//菜谱名称 + + @BindView(R.id.caipu11) + EditText caipu11;//菜谱循环次数 + + @BindView(R.id.kaishixunhuan) + Button kaishixunhuan;//开始循环 + + @BindView(R.id.showbuttomtop) + RelativeLayout showbuttomtop;//显示弹窗 + + @BindView(R.id.xunhuancishu) + TextView xunhuancishu;//循环次数 + + @BindView(R.id.jieshutuichu) + ImageView jieshutuichu;//结束退出 + + + //endregion + + //region 界面 + private Context context; + + @Override + protected View onCreateView() { + View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_auto_test_more, null); + ButterKnife.bind(this, root); + return root; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Logger.d("我的fragment创建"); + context = getContext(); + Init(); + RefreshThread(); + } + //endregion + + //region 公共 + + /** + * 初始化 + */ + public void Init() { + kaishixunhuan.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (GetTextInput(caipu11) == 0) { + ToastUtils.warning("循环次数不能为0或空!!!"); + return; + } + + if (good==null) { + ToastUtils.warning("商品不能为空!!!"); + return; + } + showbuttomtop.setVisibility(View.VISIBLE); + IsRun = true; + RunCount = 0; + RunAllCount = GetTextInput(caipu11); + ExecuteTheRecipe.StopForcedEnd(); + } + }); + jieshutuichu.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showbuttomtop.setVisibility(View.GONE); + IsRun = false; + ExecuteTheRecipe.SetForcedEnd(); + } + }); + + /** + * 选择菜谱 + */ + cpfm.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + skipToActivity(Cpxz1Activity.class); + } + }); + + DataBus.getInstance().mListener1 = new MyClickListener() { + @Override + public void clickListener(View v, Object data) { + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + good = (BPA_GOODS) data; + cpmc.setText(good.name+""); + new MyBitmapUtils().disPlay(cpfm, good.url); + } + }); + + } + @Override + public void clickListenerNew(View v, int k, Object data) { + + } + }; + } + + public boolean IsRun = false; + public int RunCount = 0; + public int RunAllCount = 0; + + public BPA_GOODS good=null; + /** + * 刷新UI线程 + */ + public void RefreshThread() { + new Thread(new Runnable() { + @Override + public void run() { + while (true) { + try { + if(IsRun) + { + MakeGood(); + } + Thread.sleep(1000); + } catch (Exception ex) { + + } + } + } + }).start(); + + + } + + + /** + * 制作商品 + */ + public void MakeGood() + { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + xunhuancishu.setText(RunCount+""); + } + }); + if(RunCount data = new ArrayList<>(); + data.add("锅口"); + data.add("清洗"); + data.add("投料"); + data.add("出料"); + data.add("延迟"); + data.add("加热"); + data.add("热稳定"); + + adapter = new gnleft_adapter(getContext(), R.layout.item_left_cd, data, null); + datatab_left.setAdapter(adapter); + datatab_left.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long l) { + // TODO Auto-generated method stub + adapter.setSelectedPosition(position); + adapter.notifyDataSetInvalidated(); + SetSelect(position);//单击工序行,显示变量 + } + }); + adapter.setSelectedPosition(0);//默认选中第一行 + SetSelect(0);//单击工序行,显示变量 + + ArrayAdapter adapter2 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(ConfigName.getInstance().HeatingGearL.keySet())); + adapter2.setDropDownViewResource(R.layout.spinner_dropdown_item); + HuoLi.setAdapter(adapter2); + HuoLi.setSelection(0); + + + ArrayAdapter adapter3 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(ConfigName.getInstance().HeatingGearL.keySet())); + adapter3.setDropDownViewResource(R.layout.spinner_dropdown_item); + HuoLi1.setAdapter(adapter3); + HuoLi1.setSelection(0); + } + + /** + * 刷新UI线程 + */ + public void RefreshThread() { + //这是主线控制流程 + new Thread(new Runnable() { + @Override + public void run() { + while (true) { + try { + if (ExecuteTest.IsStart) { + switch (RunIndex) { + case 0: + MakeGKCX_ZFZ(); + break; + case 1: + MakeQX(); + break; + case 2: + MakeTL(); + break; + case 3: + MakeYTL(); + break; + case 4: + MakeYCJR(); + break; + case 5: + MakeJR(); + break; + case 6: + MakeJRWDX(); + break; + } + } + Thread.sleep(1000); + } catch (Exception ex) { + + } + } + } + }).start(); + + //这是搅拌控制逻辑 + new Thread(new Runnable() { + @Override + public void run() { + while (true) { + try { + if (ExecuteTest.IsStart) { + switch (RunIndex) { + case 0: + MakeGKCX_JB(); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + break; + case 5: + break; + } + + + //故障信息 + for (StatusMode item:ConfigName.getInstance().statusModes) + { + if(ExecuteTheRecipe.getConcurrentHash(item.sort)) + { + SetMiaosShu1(item.Name); + } + } + + String x1= ConfigName.getInstance().statusModes_电机.get(ExecuteTheRecipe.getConcurrentHash_dj("搅拌电机")); + String x2= ConfigName.getInstance().statusModes_电机.get(ExecuteTheRecipe.getConcurrentHash_dj("翻转电机")); + if(!x1.equals("无故障")) + { + SetMiaosShu1("搅拌电机故障代码:"+x1); + } + + if(!x2.equals("无故障")) + { + SetMiaosShu1("翻转电机故障代码:"+x2); + } + } + Thread.sleep(1000); + } catch (Exception ex) { + + } + } + } + }).start(); + } + //endregion + + //region 界面操作 + + /** + * 点击事件 + * + * @param view + */ + @OnClick({R.id.start_goodmake, R.id.qingkong,}) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.start_goodmake: + if (!ExecuteTest.IsStart) { + if (DataIsHF()) { + onRecordStart(); + } + } else { + onRecordStop(); + } + break; + case R.id.qingkong: + ClearMiaosShu(); + break; + } + } + + /** + * 设置选中 + * + * @param index + */ + public void SetSelect(int index) { + if (index == 0) { + re_gkcx.setVisibility(View.VISIBLE); + re_qingxi.setVisibility(View.GONE); + re_touliao.setVisibility(View.GONE); + re_yetiliao.setVisibility(View.GONE); + re_yanchi.setVisibility(View.GONE); + re_jiare.setVisibility(View.GONE); + re_jiarewending.setVisibility(View.GONE); + } else if (index == 1) { + re_gkcx.setVisibility(View.GONE); + re_qingxi.setVisibility(View.VISIBLE); + re_touliao.setVisibility(View.GONE); + re_yetiliao.setVisibility(View.GONE); + re_yanchi.setVisibility(View.GONE); + re_jiare.setVisibility(View.GONE); + re_jiarewending.setVisibility(View.GONE); + + } else if (index == 2) { + re_gkcx.setVisibility(View.GONE); + re_qingxi.setVisibility(View.GONE); + re_touliao.setVisibility(View.VISIBLE); + re_yetiliao.setVisibility(View.GONE); + re_yanchi.setVisibility(View.GONE); + re_jiare.setVisibility(View.GONE); + re_jiarewending.setVisibility(View.GONE); + + + } else if (index == 3) { + re_gkcx.setVisibility(View.GONE); + re_qingxi.setVisibility(View.GONE); + re_touliao.setVisibility(View.GONE); + re_yetiliao.setVisibility(View.VISIBLE); + re_yanchi.setVisibility(View.GONE); + re_jiare.setVisibility(View.GONE); + re_jiarewending.setVisibility(View.GONE); + + } else if (index == 4) { + re_gkcx.setVisibility(View.GONE); + re_qingxi.setVisibility(View.GONE); + re_touliao.setVisibility(View.GONE); + re_yetiliao.setVisibility(View.GONE); + re_yanchi.setVisibility(View.VISIBLE); + re_jiare.setVisibility(View.GONE); + re_jiarewending.setVisibility(View.GONE); + + } else if (index == 5) { + re_gkcx.setVisibility(View.GONE); + re_qingxi.setVisibility(View.GONE); + re_touliao.setVisibility(View.GONE); + re_yetiliao.setVisibility(View.GONE); + re_yanchi.setVisibility(View.GONE); + re_jiare.setVisibility(View.VISIBLE); + re_jiarewending.setVisibility(View.GONE); + + }else if (index == 6) { + re_gkcx.setVisibility(View.GONE); + re_qingxi.setVisibility(View.GONE); + re_touliao.setVisibility(View.GONE); + re_yetiliao.setVisibility(View.GONE); + re_yanchi.setVisibility(View.GONE); + re_jiare.setVisibility(View.GONE); + re_jiarewending.setVisibility(View.VISIBLE); + } + } + + /** + * 判断数据是否合法 + * + * @return + */ + public boolean DataIsHF() { + boolean sucess = false; + int index = adapter.getSelectedPosition(); + switch (index) { + case 0: + if (GetTextInput(gkcx1) == 0) { + SetMiaosShu("锅体正反转循环一次的圈数不能为0或空!!!"); + } else if (GetTextInput(gkcx2) == 0) { + SetMiaosShu("锅体正反转共运行次数不能为0或空!!!"); + } else if (GetTextInput(gkcx3) == 0) { + SetMiaosShu("搅拌组件运行分钟数不能为0或空!!!"); + } else { + sucess = true; + gkcx11.setText("0"); + gkcx22.setText("0"); + gkcxCount = 0; + jiaobanCount = 0; + + gkcxYiQuan = GetTextInput(gkcx1); + gkcxAllCount = GetTextInput(gkcx2); + jiaobanAllCount = GetTextInput(gkcx3); + } + break; + case 1: + if (GetTextInput(qingxi1) == 0) { + SetMiaosShu("运行次数不能为0或空!!!"); + } else { + sucess = true; + qingxi11.setText("0"); + qingxiCount = 0; + qingxiAllCount = GetTextInput(qingxi1); + } + break; + case 2: + if (GetTextInput(touliao1) == 0) { + SetMiaosShu("运行次数不能为0或空!!!"); + } else { + sucess = true; + touliao11.setText("0"); + touliaoCount = 0; + touliaoAllCount = GetTextInput(touliao1); + } + break; + case 3: + if (GetTextInput(yetiliao1) == 0) { + SetMiaosShu("运行次数不能为0或空!!!"); + } else { + sucess = true; + yetiliao11.setText("0"); + yetiliaoCount = 0; + yetiliaoAllCount = GetTextInput(yetiliao1); + } + break; + case 4: + if (GetTextInput(yanchi1) == 0) { + SetMiaosShu("加热持续时间不能为0或空!!!"); + } else if (GetTextInput(yanchi2) == 0) { + SetMiaosShu("冷却时间不能为0或空!!!"); + } else if (GetTextInput(yanchi3) == 0) { + SetMiaosShu("运行次数不能为0或空!!!"); + } else { + sucess = true; + yanchi11.setText("0"); + yanchiCount = 0; + yanchiAllCount = GetTextInput(yanchi3); + + yanchiJR = GetTextInput(yanchi1); + yanchiLQ = GetTextInput(yanchi2); + + dw = HuoLi.getSelectedItem().toString(); + } + break; + case 5: + if (GetTextInput(jiare1) == 0) { + SetMiaosShu("加热持续时间不能为0或空!!!"); + } else if (GetTextInput(jiare2) == 0) { + SetMiaosShu("停止时间不能为0或空!!!"); + } else if (GetTextInput(jiare3) == 0) { + SetMiaosShu("运行次数不能为0或空!!!"); + } else { + sucess = true; + jiare11.setText("0"); + jiareCount = 0; + jiareAllCount = GetTextInput(jiare3); + + jiareJR = GetTextInput(jiare1); + jiareLQ = GetTextInput(jiare2); + } + break; + case 6: + if (GetTextInput(jiarewending1) == 0) { + SetMiaosShu("加热时间不能为0或空!!!"); + } else if (GetTextInput(jiarewending2) == 0) { + SetMiaosShu("再次加热时间不能为0或空!!!"); + } else if (GetTextInput(jiarewending3) == 0) { + SetMiaosShu("运行次数不能为0或空!!!"); + } else { + sucess = true; + jiarewending11.setText("0"); + jiarewendingCount = 0; + jiarewendingAllCount = GetTextInput(jiarewending3); + + jiarewendingJR = GetTextInput(jiarewending1); + jiarewendingLQ = GetTextInput(jiarewending2); + } + break; + } + return sucess; + } + //endregion + + //region 锅口朝向测试 + public int gkcxCount = 0; + public int gkcxYiQuan = 0; + public int gkcxAllCount = 0; + + /** + * 炒锅正反转 + */ + public void MakeGKCX_ZFZ() { + if (gkcxCount < gkcxAllCount)//运行次数少于设置总数 + { + for (int i = 0; i < gkcxYiQuan; i++) { + if (ExecuteTest.IsStart) { + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get位置("原点位").processname, ExecuteTest.Get位置("原点位").processvalue); + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get位置("倒菜位").processname, ExecuteTest.Get位置("倒菜位").processvalue); + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get位置("清洗位").processname, ExecuteTest.Get位置("清洗位").processvalue); + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get位置("原点位").processname, ExecuteTest.Get位置("原点位").processvalue); + gkcxCount++; + } + } + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + gkcx11.setText(gkcxCount + ""); + if (gkcxCount >= gkcxAllCount && jiaobanCount >= jiaobanAllCount) { + onRecordStop(); + } + } + }); + } + + public int jiaobanCount = 0;//搅拌分钟数 + public int jiaobanAllCount = 0; + + /** + * 搅拌功能 + */ + public void MakeGKCX_JB() { + if (jiaobanCount < jiaobanAllCount)//搅拌分钟数 + { + Object obj1 = ExecuteTheRecipe.ReadPLC("搅拌"); + if (obj1 != null && (boolean) obj1 == false) { + ExecuteTheRecipe.WritePLC("搅拌速度", 40, new IWriteCallBack() { + @Override + public void onSuccess() { + ExecuteTheRecipe.WritePLC("搅拌", true, null); + } + + @Override + public void onFailure(String ErrorMsg) { + } + }); + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + long elapsedMillis = SystemClock.elapsedRealtime() - runtime.getBase(); + int mm = (int) (elapsedMillis / 1000); + jiaobanCount = mm / 60; + } + }); + } else //达到分钟数 关闭搅拌 + { + Object obj1 = ExecuteTheRecipe.ReadPLC("搅拌"); + if (obj1 != null && (boolean) obj1) { + ExecuteTheRecipe.WritePLC("搅拌", false, null); + } + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + gkcx22.setText(jiaobanCount + ""); + if (gkcxCount >= gkcxAllCount && jiaobanCount >= jiaobanAllCount) { + onRecordStop(); + } + } + }); + + } + //endregion + + //region 清洗 + public int qingxiCount = 0; + public int qingxiAllCount = 0; + + /** + * 清洗 + */ + public void MakeQX() { + if (qingxiCount < qingxiAllCount)//搅拌分钟数 + { + if (ExecuteTest.IsStart) { + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get清洗(0).processname, ExecuteTest.Get清洗(0).processvalue); + qingxiCount++; + } + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + qingxi11.setText(qingxiCount + ""); + if (qingxiCount >= qingxiAllCount) { + onRecordStop(); + } + } + }); + + } + //endregion + + //region 投料 + public int touliaoCount = 0; + public int touliaoAllCount = 0; + + /** + * 投料 + */ + public void MakeTL() { + if (touliaoCount < touliaoAllCount) { + if (ExecuteTest.IsStart) { + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get位置("炒菜位1").processname, ExecuteTest.Get位置("炒菜位1").processvalue); + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get主料(1).processname, ExecuteTest.Get主料(1).processvalue); + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get主料(2).processname, ExecuteTest.Get主料(2).processvalue); + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get主料(3).processname, ExecuteTest.Get主料(3).processvalue); + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get主料(4).processname, ExecuteTest.Get主料(4).processvalue); + touliaoCount++; + } + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + touliao11.setText(touliaoCount + ""); + if (touliaoCount >= touliaoAllCount) { + onRecordStop(); + } + } + }); + + } + //endregion + + //region 液体料 + public int yetiliaoCount = 0; + public int yetiliaoAllCount = 0; + + /** + * 投料 + */ + public void MakeYTL() { + if (yetiliaoCount < yetiliaoAllCount) { + if (ExecuteTest.IsStart) { + ExecuteTest.Write_PLC_Material(1, 100); + ExecuteTest.Write_PLC_Material(2, 100); + ExecuteTest.Write_PLC_Material(3, 100); + ExecuteTest.Write_PLC_Material(4, 100); + yetiliaoCount++; + } + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + yetiliao11.setText(yetiliaoCount + ""); + if (yetiliaoCount >= yetiliaoAllCount) { + onRecordStop(); + } + } + }); + + } + //endregion + + //region 延迟 + public int yanchiCount = 0; + public int yanchiAllCount = 0; + + public int yanchiJR = 0; + public int yanchiLQ = 0; + + public String dw = "三档"; + + /** + * 延迟加热 + */ + public void MakeYCJR() { + if (yanchiCount < yanchiAllCount) { + if (ExecuteTest.IsStart) { + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get加热(dw).processname, ExecuteTest.Get加热(dw).processvalue); + ExecuteTest.ThreadDelay(yanchiJR);//加热持续多少秒 + ExecuteTheRecipe.WritePLC("加热", false, null); + ExecuteTest.ThreadDelay(yanchiLQ * 60);//冷却多少分钟 + yanchiCount++; + } + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + yanchi11.setText(yanchiCount + ""); + if (yanchiCount >= yanchiAllCount) { + onRecordStop(); + } + } + }); + + } + //endregion + + //region 加热 + public int jiareCount = 0; + public int jiareAllCount = 0; + + public int jiareJR = 0; + public int jiareLQ = 0; + + + /** + * 延迟加热 + */ + public void MakeJR() { + List Dwei = new ArrayList() {{ + add("一档"); + add("二档"); + add("三档"); + add("四档"); + add("五档"); + add("六档"); + add("七档"); + add("八档"); + }}; + for (String item : Dwei) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + jiaredangwei.setText(item + ""); + } + }); + if (ExecuteTest.IsStart) { + for (jiaobanCount = 0; jiareCount < jiareAllCount; jiareAllCount++) { + if (ExecuteTest.IsStart) { + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get加热(item).processname, ExecuteTest.Get加热(item).processvalue); + ExecuteTest.ThreadDelay(jiareJR);//加热持续多少秒 + ExecuteTheRecipe.WritePLC("加热", false, null); + ExecuteTest.ThreadDelay(jiareLQ * 60);//冷却多少分钟 + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + jiare11.setText(jiareCount + ""); + jiaredangwei.setText(item + ""); + } + }); + } + } + } + } + onRecordStop(); + } + //endregion + + //region 加热稳定性 + public int jiarewendingCount = 0; + public int jiarewendingAllCount = 0; + + public int jiarewendingJR = 0; + public int jiarewendingLQ = 0; + + public String dw1 = "三档"; + + /** + * 加热稳定性 + */ + public void MakeJRWDX() { + if (jiarewendingCount < jiarewendingAllCount) { + if (ExecuteTest.IsStart) { + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get加热(dw1).processname, ExecuteTest.Get加热(dw1).processvalue); + ExecuteTest.ThreadDelay(jiarewendingJR);//加热持续多少秒 + ExecuteTheRecipe.WritePLC("加热", false, null); + ExecuteTest.ExecuteOperationSteps(ExecuteTest.Get加热(dw1).processname, ExecuteTest.Get加热(dw1).processvalue); + ExecuteTest.ThreadDelay(jiarewendingLQ);//冷却多少分钟 + ExecuteTheRecipe.WritePLC("加热", false, null); + jiarewendingCount++; + } + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + jiarewending11.setText(jiarewendingCount + ""); + if (jiarewendingCount >= jiarewendingAllCount) { + onRecordStop(); + } + } + }); + + } + //endregion + + //region 私有函数 + + + /** + * 获取输入文字 + * + * @param editText + * @return + */ + public int GetTextInput(EditText editText) { + int res = 0; + try { + if (!editText.getText().toString().isEmpty()) { + res = Integer.parseInt(editText.getText().toString()); + } + } catch (Exception ex) { + res = 0; + } + return res; + } + + /** + * 设置显示 + * + * @param text + */ + public void SetMiaosShu(String text) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = new Date(); + String tempMsg = miaoshu.getText() + formatter.format(date) + ":" + text + "\n"; + miaoshu.setText(tempMsg); + ToastUtils.warning(formatter.format(date) + ":" + text); + } + }); + } + + /** + * 不重复 + * @param text + */ + public void SetMiaosShu1(String text) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + String YL= miaoshu.getText().toString(); + if(!YL.isEmpty() && YL.contains(text)) + { + + }else + { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = new Date(); + String tempMsg = YL+ formatter.format(date) + ":" + text + "\n"; + miaoshu.setText(tempMsg); + ToastUtils.warning(formatter.format(date) + ":" + text); + } + } + }); + } + + /** + * 清空显示 + * + * @param + */ + public void ClearMiaosShu() { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + miaoshu.setText(""); + } + }); + } + //endregion + + //region 计时器 + + /** + * 记录下来的总时间 + */ + private long recordingTime = 0; + /** + * 当前运行总时长 + */ + public int TimeOut = 0; + /** + * 当前运行的index + */ + public int RunIndex = 0; + + /** + * 启动定时器 + */ + public void onRecordStart() { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + ExecuteTest.StopForcedEnd(); + runtime.setBase(SystemClock.elapsedRealtime() - recordingTime);// 跳过已经记录了的时间,起到继续计时的作用 + runtime.start(); + ExecuteTest.IsStart = true; + TimeOut = 0; + RunIndex = adapter.getSelectedPosition(); + showbuttomtop.setVisibility(View.VISIBLE); + start_goodmake.setImageResource(R.mipmap.zhizuo_js2); + } + }); + } + + /** + * 停止计时器 + */ + public void onRecordStop() { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + ExecuteTest.SetForcedEnd(); + runtime.stop(); + ExecuteTest.IsStart = false; + + recordingTime = 0; + long elapsedMillis = SystemClock.elapsedRealtime() - runtime.getBase(); + TimeOut = (int) (elapsedMillis / 1000); + + showbuttomtop.setVisibility(View.GONE); + start_goodmake.setImageResource(R.mipmap.zhizuo_ks2); + } + }); + } + //endregion +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java index 5a70b500..d26a1b26 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java @@ -154,7 +154,7 @@ public class SystemSystemsetFragment extends BaseFragment { break; case -100: ConfigName.getInstance().versionSelectionEnum = item.value; - versionselection.setSelection(material_map_vis.get(item.value)); + versionselection.setSelection(material_map_vis.get(item.value)==null?0:material_map_vis.get(item.value)); break; case -99: ConfigName.getInstance().Environment = item.value; diff --git a/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java b/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java index a326e912..3dcfc6e4 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java @@ -30,6 +30,7 @@ import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.utils.UpdateAppUtils; import com.bonait.bnframework.manager.ActivityLifecycleManager; +import com.bonait.bnframework.modules.home.fragment.from.AutoTestActivity; import com.bonait.bnframework.modules.home.fragment.from.WokSetActivity; import com.bonait.bnframework.modules.mine.fragment.from.NoticeActivity; import com.bonait.bnframework.modules.welcome.activity.LoginActivity; @@ -69,7 +70,11 @@ public class MyFragment extends BaseFragment { SuperTextView stv_user; @BindView(R.id.stv_devicesz) - SuperTextView stv_devicesz; + SuperTextView stv_devicesz;//专员调试 + + @BindView(R.id.stv_zdtest) + SuperTextView stv_zdtest;//自动测试项目 + @BindView(R.id.stv_announcement) SuperTextView stvAnnouncement; @@ -183,6 +188,18 @@ public class MyFragment extends BaseFragment { } }); + /** + * 自动化测试项目 + */ + stv_zdtest.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener(SuperTextView superTextView) { + Intent intent = new Intent(context, AutoTestActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + } + }); + /** * 用户名点击 */ diff --git a/app/src/main/res/drawable-hdpi/icon_test.png b/app/src/main/res/drawable-hdpi/icon_test.png new file mode 100644 index 00000000..2d94af7d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/icon_test.png differ diff --git a/app/src/main/res/layout/activity_auto_test.xml b/app/src/main/res/layout/activity_auto_test.xml new file mode 100644 index 00000000..c85a88ae --- /dev/null +++ b/app/src/main/res/layout/activity_auto_test.xml @@ -0,0 +1,88 @@ + + + + + + + + + +