diff --git a/app/src/main/java/com/example/bpa/MainActivity.java b/app/src/main/java/com/example/bpa/MainActivity.java index 51e4df2..9c6b0a7 100644 --- a/app/src/main/java/com/example/bpa/MainActivity.java +++ b/app/src/main/java/com/example/bpa/MainActivity.java @@ -17,6 +17,7 @@ import androidx.fragment.app.FragmentTransaction; import com.example.bpa.config.ConfigName; import com.example.bpa.config.DataBus; +import com.example.bpa.helper.ModbusTcpServer; import com.example.bpa.view.fragment.CloudFragment; import com.example.bpa.view.fragment.HeplerFragment; import com.example.bpa.view.fragment.HomeFragment; @@ -57,6 +58,7 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen setContentView(R.layout.activity_main); Init(); initEvents(); + initBusiness(); } //endregion @@ -77,6 +79,7 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen ShowFragment(homeFragment,"系统主页"); //ShowFragment(systemCapabilitiesFragment,"功能菜单"); DataBus.getInstance().UpdateMainGoods(); + } /** * 初始化按钮事件 @@ -90,6 +93,13 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen HomeMain.setOnClickListener(this); ColseMain.setOnClickListener(this); } + /** + * 初始化业务 + */ + private void initBusiness() { + //PLC数据监控 + ModbusTcpServer.get().Connect(ConfigName.getInstance().Address, ConfigName.getInstance().Post); + } //endregion //region 点击事件 diff --git a/app/src/main/java/com/example/bpa/app/ICSApp.java b/app/src/main/java/com/example/bpa/app/ICSApp.java index 87a1211..44ae479 100644 --- a/app/src/main/java/com/example/bpa/app/ICSApp.java +++ b/app/src/main/java/com/example/bpa/app/ICSApp.java @@ -9,20 +9,18 @@ import com.example.bpa.config.ConfigName; import com.example.bpa.db.QueryDB; import com.example.bpa.db.mode.BPA_ALERTLOG; import com.example.bpa.db.mode.BPA_LOG; -import com.example.bpa.db.mode.BPA_MATERIAL; import com.example.bpa.db.mode.BPA_SILOS; import com.example.bpa.db.mode.BPA_SILOSANDMATERIAL; import com.example.bpa.db.mode.BPA_SUGAR; import com.example.bpa.db.mode.BPA_USER; -import com.example.bpa.helper.Json; import com.example.bpa.helper.MessageLog; +import com.example.bpa.helper.ModbusTcpServer; import com.example.bpa.helper.SdCart; import com.example.bpa.helper.ToastUtil; +import com.example.bpa.service.BusinessServer; import com.example.bpa.view.mode.AlertLogEnum; import com.example.bpa.view.mode.UserLogEnum; -import java.util.ArrayList; - /** * 程序启动执行 * 创建:fengyoufu 20230413 @@ -40,13 +38,11 @@ public class ICSApp extends Application { InitDBdata(); //4.初始化Main Main.getInstance(); - //5.PLC数据监控 - ModbusTcpServer.get().Connect(ConfigName.getInstance().Address, ConfigName.getInstance().Post); //BusinessServer.Get().test(); -// MessageLog.ShowAlertMessage(AlertLogEnum.传感器异常日志,"传感器异常"); -// MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志,"异常订单未制作日志"); -// MessageLog.ShowAlertMessage(AlertLogEnum.料仓缺料日志,"料仓缺料日志"); + //MessageLog.ShowAlertMessage(AlertLogEnum.传感器异常日志,"传感器异常"); + //MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志,"异常订单未制作日志"); + //MessageLog.ShowAlertMessage(AlertLogEnum.料仓缺料日志,"料仓缺料日志"); } /** diff --git a/app/src/main/java/com/example/bpa/config/DataBus.java b/app/src/main/java/com/example/bpa/config/DataBus.java index ec5d2a5..32e971f 100644 --- a/app/src/main/java/com/example/bpa/config/DataBus.java +++ b/app/src/main/java/com/example/bpa/config/DataBus.java @@ -2,15 +2,13 @@ package com.example.bpa.config; import com.example.bpa.Model.ResultA; import com.example.bpa.R; -import com.example.bpa.app.DeviceData; +import com.example.bpa.service.DeviceData; import com.example.bpa.db.QueryDB; import com.example.bpa.db.mode.BPA_ALERTLOG; import com.example.bpa.db.mode.BPA_GOODS; import com.example.bpa.db.mode.BPA_LOG; import com.example.bpa.db.mode.BPA_SILOS; -import com.example.bpa.view.adapter.maingoods_adapter; import com.example.bpa.view.adapter.makegood_adapter; -import com.example.bpa.view.control.MyLayoutManager; import com.example.bpa.view.mode.MakeStatus; import com.example.bpa.view.mode.ResGoodsMake; import com.example.bpa.view.mode.ResGoodsRecipe; diff --git a/app/src/main/java/com/example/bpa/app/DataFormat.java b/app/src/main/java/com/example/bpa/helper/DataFormat.java similarity index 67% rename from app/src/main/java/com/example/bpa/app/DataFormat.java rename to app/src/main/java/com/example/bpa/helper/DataFormat.java index 9b10a49..de82158 100644 --- a/app/src/main/java/com/example/bpa/app/DataFormat.java +++ b/app/src/main/java/com/example/bpa/helper/DataFormat.java @@ -1,4 +1,4 @@ -package com.example.bpa.app; +package com.example.bpa.helper; public enum DataFormat { ABCD, diff --git a/app/src/main/java/com/example/bpa/app/ModbusTcpHelper.java b/app/src/main/java/com/example/bpa/helper/ModbusTcpHelper.java similarity index 96% rename from app/src/main/java/com/example/bpa/app/ModbusTcpHelper.java rename to app/src/main/java/com/example/bpa/helper/ModbusTcpHelper.java index 9a9b42c..4cdf290 100644 --- a/app/src/main/java/com/example/bpa/app/ModbusTcpHelper.java +++ b/app/src/main/java/com/example/bpa/helper/ModbusTcpHelper.java @@ -1,4 +1,4 @@ -package com.example.bpa.app; +package com.example.bpa.helper; import com.licheedev.modbus4android.ModbusWorker; diff --git a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java b/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java similarity index 98% rename from app/src/main/java/com/example/bpa/app/ModbusTcpServer.java rename to app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java index 10d44b3..3d45b21 100644 --- a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java +++ b/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java @@ -1,10 +1,14 @@ -package com.example.bpa.app; +package com.example.bpa.helper; import com.example.bpa.Model.IReadCallBack; import com.example.bpa.Model.IWriteCallBack; +import com.example.bpa.service.BusinessServer; +import com.example.bpa.service.DeviceData; import com.example.bpa.config.DataBus; -import com.example.bpa.helper.MessageLog; +import com.example.bpa.service.DeviceServer; +import com.example.bpa.service.LogServer; +import com.example.bpa.service.OrderServer; import com.licheedev.modbus4android.ModbusCallback; import com.licheedev.modbus4android.ModbusParam; import com.licheedev.modbus4android.ModbusRespException; @@ -14,8 +18,6 @@ import com.serotonin.modbus4j.exception.ModbusInitException; import com.serotonin.modbus4j.exception.ModbusTransportException; import com.serotonin.modbus4j.msg.ReadCoilsResponse; import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse; -import com.serotonin.modbus4j.msg.WriteCoilResponse; -import com.serotonin.modbus4j.msg.WriteRegistersResponse; import java.nio.ByteBuffer; import java.util.Arrays; @@ -129,7 +131,12 @@ public class ModbusTcpServer { //3.设置自动模式 DeviceData.Get().setHandOrAutoSwitch(true, null); DeviceData.Get().setCleaningMode(false,null);//关闭自动清洗模式 - + //4.启动设备服务 + DeviceServer.Get().Init(); + //5.启动日志服务 + LogServer.Get().Init(); + //6.云订单服务 + OrderServer.Get().Init(); } @Override diff --git a/app/src/main/java/com/example/bpa/app/BusinessServer.java b/app/src/main/java/com/example/bpa/service/BusinessServer.java similarity index 98% rename from app/src/main/java/com/example/bpa/app/BusinessServer.java rename to app/src/main/java/com/example/bpa/service/BusinessServer.java index 56c0a25..b23b1bf 100644 --- a/app/src/main/java/com/example/bpa/app/BusinessServer.java +++ b/app/src/main/java/com/example/bpa/service/BusinessServer.java @@ -1,7 +1,6 @@ -package com.example.bpa.app; +package com.example.bpa.service; import com.example.bpa.Model.IRun; -import com.example.bpa.Model.IRunT; import com.example.bpa.Model.IThread; import com.example.bpa.Model.IWriteCallBack; import com.example.bpa.Model.ResultA; @@ -11,21 +10,20 @@ import com.example.bpa.db.mode.BPA_GOODS; import com.example.bpa.db.mode.BPA_SILOS; import com.example.bpa.db.mode.BPA_SUGAR; import com.example.bpa.helper.MessageLog; +import com.example.bpa.helper.ModbusTcpServer; import com.example.bpa.helper.ThreadManager; import com.example.bpa.view.mode.AlertLogEnum; -import com.example.bpa.view.mode.MakeStatus; import com.example.bpa.view.mode.ResGoodsRecipe; import com.example.bpa.view.mode.UserLogEnum; -import java.sql.Ref; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; +/** + * 业务服务 + */ public class BusinessServer { private static volatile BusinessServer _instance; diff --git a/app/src/main/java/com/example/bpa/app/DeviceData.java b/app/src/main/java/com/example/bpa/service/DeviceData.java similarity index 96% rename from app/src/main/java/com/example/bpa/app/DeviceData.java rename to app/src/main/java/com/example/bpa/service/DeviceData.java index d7a10a2..f6d4b54 100644 --- a/app/src/main/java/com/example/bpa/app/DeviceData.java +++ b/app/src/main/java/com/example/bpa/service/DeviceData.java @@ -1,24 +1,15 @@ -package com.example.bpa.app; +package com.example.bpa.service; -import com.example.bpa.Model.IReadCallBack; import com.example.bpa.Model.IRun; import com.example.bpa.Model.IRunT; import com.example.bpa.Model.IThread; import com.example.bpa.Model.IWriteCallBack; -import com.example.bpa.helper.MessageLog; +import com.example.bpa.helper.ModbusTcpServer; import com.example.bpa.helper.RTrig; import com.example.bpa.helper.ThreadManager; -import com.licheedev.modbus4android.ModbusCallback; -import com.licheedev.modbus4android.ModbusRespException; -import com.serotonin.modbus4j.exception.ModbusInitException; -import com.serotonin.modbus4j.exception.ModbusTransportException; -import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse; - -import java.util.ArrayList; -import java.util.List; + import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ExecutionException; public class DeviceData { private static volatile DeviceData _instance; diff --git a/app/src/main/java/com/example/bpa/service/DeviceServer.java b/app/src/main/java/com/example/bpa/service/DeviceServer.java new file mode 100644 index 0000000..f5316a6 --- /dev/null +++ b/app/src/main/java/com/example/bpa/service/DeviceServer.java @@ -0,0 +1,61 @@ +package com.example.bpa.service; + +import com.example.bpa.Model.IRun; +import com.example.bpa.Model.IThread; +import com.example.bpa.Model.IWriteCallBack; +import com.example.bpa.Model.ResultA; +import com.example.bpa.config.DataBus; +import com.example.bpa.db.QueryDB; +import com.example.bpa.db.mode.BPA_GOODS; +import com.example.bpa.db.mode.BPA_SILOS; +import com.example.bpa.db.mode.BPA_SUGAR; +import com.example.bpa.helper.MessageLog; +import com.example.bpa.helper.ModbusTcpServer; +import com.example.bpa.helper.ThreadManager; +import com.example.bpa.view.mode.AlertLogEnum; +import com.example.bpa.view.mode.ResGoodsRecipe; +import com.example.bpa.view.mode.UserLogEnum; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +/** + * 设备服务 + * 设备预警、上报设备告警、上报设备状态 + */ +public class DeviceServer { + + //region 私有单例 + private static volatile DeviceServer _instance; + + public static DeviceServer Get() { + if (_instance == null) + _instance = new DeviceServer(); + return _instance; + } + + private DeviceServer() { + } + //endregion + + //region + + /** + * 初始化 + */ + public void Init() + { +// ThreadManager.Get().StartLong("设备服务", true, new IThread() { +// @Override +// public void Run() throws InterruptedException { +// MessageLog.ShowInfo("我是设备服务!"); +// Thread.sleep(2000); +// } +// @Override +// public void RunComplete() throws InterruptedException { +// } +// }); + } + //endregion +} diff --git a/app/src/main/java/com/example/bpa/service/LogServer.java b/app/src/main/java/com/example/bpa/service/LogServer.java new file mode 100644 index 0000000..342a45c --- /dev/null +++ b/app/src/main/java/com/example/bpa/service/LogServer.java @@ -0,0 +1,45 @@ +package com.example.bpa.service; + +import com.example.bpa.Model.IThread; +import com.example.bpa.helper.MessageLog; +import com.example.bpa.helper.ThreadManager; + +/** + * 日志服务 + * 周期性上报日志 + */ +public class LogServer { + + //region 私有单例 + private static volatile LogServer _instance; + + public static LogServer Get() { + if (_instance == null) + _instance = new LogServer(); + return _instance; + } + + private LogServer() { + } + //endregion + + //region + + /** + * 初始化 + */ + public void Init() + { +// ThreadManager.Get().StartLong("日志服务", true, new IThread() { +// @Override +// public void Run() throws InterruptedException { +// MessageLog.ShowInfo("我是日志服务!"); +// Thread.sleep(2000); +// } +// @Override +// public void RunComplete() throws InterruptedException { +// } +// }); + } + //endregion +} diff --git a/app/src/main/java/com/example/bpa/service/OrderServer.java b/app/src/main/java/com/example/bpa/service/OrderServer.java new file mode 100644 index 0000000..988e5b6 --- /dev/null +++ b/app/src/main/java/com/example/bpa/service/OrderServer.java @@ -0,0 +1,45 @@ +package com.example.bpa.service; + +import com.example.bpa.Model.IThread; +import com.example.bpa.helper.MessageLog; +import com.example.bpa.helper.ThreadManager; + +/** + * 订单服务 + * 收发订单、订单预警、接收云端订单信息 + */ +public class OrderServer { + + //region 私有单例 + private static volatile OrderServer _instance; + + public static OrderServer Get() { + if (_instance == null) + _instance = new OrderServer(); + return _instance; + } + + private OrderServer() { + } + //endregion + + //region + + /** + * 初始化 + */ + public void Init() + { +// ThreadManager.Get().StartLong("订单服务", true, new IThread() { +// @Override +// public void Run() throws InterruptedException { +// MessageLog.ShowInfo("我是订单服务!"); +// Thread.sleep(2000); +// } +// @Override +// public void RunComplete() throws InterruptedException { +// } +// }); + } + //endregion +} diff --git a/app/src/main/java/com/example/bpa/view/adapter/maingoods_adapter.java b/app/src/main/java/com/example/bpa/view/adapter/maingoods_adapter.java index 12f0f70..8f8b425 100644 --- a/app/src/main/java/com/example/bpa/view/adapter/maingoods_adapter.java +++ b/app/src/main/java/com/example/bpa/view/adapter/maingoods_adapter.java @@ -12,9 +12,8 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.example.bpa.R; -import com.example.bpa.app.BusinessServer; +import com.example.bpa.service.BusinessServer; import com.example.bpa.config.DataBus; -import com.example.bpa.db.mode.BPA_GOODS; import com.example.bpa.helper.T; import com.example.bpa.view.mode.mainGoods; @@ -81,6 +80,12 @@ public class maingoods_adapter extends RecyclerView.Adapter @@ -114,7 +114,7 @@ android:layout_alignParentRight="true" android:layout_gravity="center" android:layout_marginTop="20dp" - android:layout_width="120dp" + android:layout_width="150dp" android:layout_height="wrap_content" />