From 9ac7f058a6e9dbbbe059328fb8370c77c7093d74 Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Tue, 19 Apr 2022 09:38:34 +0800 Subject: [PATCH] 1 --- .../BPASmartClient.KLMCoffee.csproj | 7 +- BPASmartClient.KLMCoffee/CommandEvent.cs | 44 +++++++ BPASmartClient.KLMCoffee/CommandHandler.cs | 111 ++++++++++++++++++ .../Protocal/RecipeModel.cs | 52 ++++++-- .../Class_MessageName.cs | 19 +++ 5 files changed, 223 insertions(+), 10 deletions(-) create mode 100644 BPASmartClient.KLMCoffee/CommandEvent.cs create mode 100644 BPASmartClient.KLMCoffee/CommandHandler.cs diff --git a/BPASmartClient.KLMCoffee/BPASmartClient.KLMCoffee.csproj b/BPASmartClient.KLMCoffee/BPASmartClient.KLMCoffee.csproj index dbc15171..9fe941ae 100644 --- a/BPASmartClient.KLMCoffee/BPASmartClient.KLMCoffee.csproj +++ b/BPASmartClient.KLMCoffee/BPASmartClient.KLMCoffee.csproj @@ -1,7 +1,12 @@ - + net6.0 + + + + + diff --git a/BPASmartClient.KLMCoffee/CommandEvent.cs b/BPASmartClient.KLMCoffee/CommandEvent.cs new file mode 100644 index 00000000..e96c5a29 --- /dev/null +++ b/BPASmartClient.KLMCoffee/CommandEvent.cs @@ -0,0 +1,44 @@ +using BPASmartClient.KLMCoffee.Protocal; + +namespace BPASmartClient.KLMCoffee +{ + /// + /// 制作咖啡 + /// + public class MakeCoffeeEvent + { + public DrinkType DrinkCode { get; set; } + } + + /// + /// 取消制作 + /// + public class CancelMakeCoffeeEvent + { + + } + + /// + /// 模式设置 + /// + public class CoffeeCommCmdEvent + { + //public DrCoffeeCommCmd CommCmd { get; set; } + } + + /// + /// 开始制作 + /// + public class CoffeBeginCook + { + + } + + /// + /// 结束制作 + /// + public class CoffeEndCook + { + + } +} diff --git a/BPASmartClient.KLMCoffee/CommandHandler.cs b/BPASmartClient.KLMCoffee/CommandHandler.cs new file mode 100644 index 00000000..23b23675 --- /dev/null +++ b/BPASmartClient.KLMCoffee/CommandHandler.cs @@ -0,0 +1,111 @@ +using BPASmartClient.KLMCoffee.Protocal; +using BPASmartClient.MessageCommunication; +using BPASmartClient.MessageCommunication.MsgControl; +using BPASmartClient.SerialPort; +using System; +using System.Threading; + +namespace BPASmartClient.KLMCoffee +{ + /// + /// 指令封装 + /// + internal class CommandHandler + { + byte[] cmdAsk; + private SerialPortClient commProxy; + private K95Command drinksOrder = new K95Command(); + public Action PauseAsk { get; set; } + + /// + /// 初始化 + /// + internal void Init(SerialPortClient commProxy) + { + this.commProxy = commProxy; + Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.KLMCoffee_MakeCoffee,"MakeCoffeeHandler"); + Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.KLMCoffee_CancelMakeCoffee,"CancelMakeCoffeeHandler"); + Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.KLMCoffee_CoffeeCommCmd,"CoffeeCommCmdHandler"); + } + + ///// + ///// 制作咖啡 + ///// + //public void MakeCoffeeHandler(object sender,InnerMessageEventArgs e) + //{ + // try + // { + // if (e.obj_MessageObj is MakeCoffeeEvent) + // { + // PauseAsk?.Invoke(true); + // Thread.Sleep(200); + // drinksOrder.ReturnsCommandData(K95CommandEnum.配方咖啡制作.GetString(),new new RecipeModel().Packe + // ); + // drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令; + // drinksOrder.DrinksCode = (DrCoffeeDrinksCode)int.Parse(e.obj_MessageObj.ToString()); + // commProxy.SendData(DrCoffee.Packe(drinksOrder)); + // Thread.Sleep(200); + // PauseAsk?.Invoke(false); + // } + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CancelMakeCoffeeHandler 类,描述:[{ex.Message}]"); + // } + //} + + ///// + ///// 取消制作 + ///// + //public void CancelMakeCoffeeHandler(object sender,InnerMessageEventArgs e) + //{ + // try + // { + // PauseAsk?.Invoke(true); + // Thread.Sleep(200); + // drinksOrder.CommCmd = DrCoffeeCommCmd.取消应用指令; + // drinksOrder.DrinksCode = 0; + // commProxy.SendData(DrCoffee.Packe(drinksOrder)); + // Thread.Sleep(200); + // PauseAsk?.Invoke(false); + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CancelMakeCoffeeHandler 类,描述:[{ex.Message}]"); + // } + //} + + ///// + ///// 模式设置 + ///// + ///// + ///// + //public void CoffeeCommCmdHandler(object sender,InnerMessageEventArgs e) + //{ + // try + // { + // if (e.obj_MessageObj is string) + // { + // PauseAsk?.Invoke(true); + // Thread.Sleep(200); + // drinksOrder.CommCmd = (DrCoffeeCommCmd)int.Parse(e.obj_MessageObj.ToString()); + // commProxy.SendData(DrCoffee.Packe(drinksOrder)); + // Thread.Sleep(200); + // PauseAsk?.Invoke(false); + // } + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeCommCmdHandler 类,描述:[{ex.Message}]"); + // } + //} + + /// + /// 发送状态询问 + /// + internal byte[] GetStatusAsk() + { + return cmdAsk; + } + } +} diff --git a/BPASmartClient.KLMCoffee/Protocal/RecipeModel.cs b/BPASmartClient.KLMCoffee/Protocal/RecipeModel.cs index 2fad4447..a947d627 100644 --- a/BPASmartClient.KLMCoffee/Protocal/RecipeModel.cs +++ b/BPASmartClient.KLMCoffee/Protocal/RecipeModel.cs @@ -113,15 +113,49 @@ namespace BPASmartClient.KLMCoffee.Protocal #endregion #region 8种配方测试示例 - //RecipeModel recipeModel = new RecipeModel(); - //string sd = recipeModel.GetItalian(60); - //sd = recipeModel.GetAmerican(60,450); - //sd = recipeModel.GetHotWater(194); - //sd = recipeModel.GetCabo(60,17); - //sd = recipeModel.GetMacChiato(60,8,17); - //sd = recipeModel.GetLatte(60,8,17); - //sd = recipeModel.GetHotMilk(8); - //sd = recipeModel.GetHotMilkFoam(17); + /// + /// 获取8中配方 + /// + /// + /// + public string Packe(DrinkType drink) + { + try + { + switch (drink) + { + case DrinkType.意式: + return GetItalian(60); + break; + case DrinkType.美式: + return GetAmerican(60,450); + break; + case DrinkType.热水: + return GetHotWater(194); + break; + case DrinkType.卡布: + return GetCabo(60,17); + break; + case DrinkType.玛奇朵: + return GetMacChiato(60,8,17); + break; + case DrinkType.拿铁: + return GetLatte(60,8,17); + break; + case DrinkType.热牛奶: + return GetHotMilk(8); + break; + case DrinkType.热奶沫: + return GetHotMilkFoam(17); + break; + } + } + catch (Exception ex) + { + return GetItalian(60); + } + return GetItalian(60); + } #endregion #region 8种默认配方 diff --git a/BPASmartClient.MessageCommunication/Class_MessageName.cs b/BPASmartClient.MessageCommunication/Class_MessageName.cs index e4d38c78..824ddf1a 100644 --- a/BPASmartClient.MessageCommunication/Class_MessageName.cs +++ b/BPASmartClient.MessageCommunication/Class_MessageName.cs @@ -63,5 +63,24 @@ namespace BPASmartClient.MessageCommunication /// public static string SCChip_RotorSwitch = "SCChip_RotorSwitch"; #endregion + + #region 伽乐美咖啡机消息名称 + /// + /// 伽乐美咖啡机制作 + /// + public static string KLMCoffee_MakeCoffee = "KLMCoffee_MakeCoffee"; + /// + /// 伽乐美咖啡机取消制作咖啡 + /// + public static string KLMCoffee_CancelMakeCoffee = "KLMCoffee_CancelMakeCoffee"; + /// + /// 伽乐美咖啡机模式设置 + /// + public static string KLMCoffee_CoffeeCommCmd = "KLMCoffee_CoffeeCommCmd"; + /// + /// 伽乐美咖啡机结束制作 + /// + public static string KLMCoffee_CoffeEndCook = "KLMCoffee_CoffeEndCook"; + #endregion } }