Browse Source

增加咖啡机 冰淇淋Event,

样式分支
fyf 2 years ago
parent
commit
a2d6a4563f
17 changed files with 610 additions and 13 deletions
  1. +1
    -0
      BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj
  2. +41
    -3
      BPASmartClient.DRCoffee/CoffeeMachine.cs
  3. +42
    -0
      BPASmartClient.KLMCoffee/Protocal/BitValue.cs
  4. +96
    -0
      BPASmartClient.KLMCoffee/Protocal/FaultMessage.cs
  5. +1
    -10
      BPASmartClient.KLMCoffee/Protocal/K95Command.cs
  6. +25
    -0
      BPASmartClient.KLMCoffee/Protocal/K95SysTemStatus.cs
  7. +60
    -0
      BPASmartClient.KLMCoffee/Protocal/K95commandEnumExtensions.cs
  8. +19
    -0
      BPASmartClient.KLMCoffee/Protocal/MakeStatus.cs
  9. +84
    -0
      BPASmartClient.KLMCoffee/Protocal/SystemStatusModel.cs
  10. +22
    -0
      BPASmartClient.KLMCoffee/Protocal/TaskIndex.cs
  11. +36
    -0
      BPASmartClient.KLMCoffee/Protocal/UpkeepMessage.cs
  12. +4
    -0
      BPASmartClient.Model/BPASmartClient.Model.csproj
  13. +38
    -0
      BPASmartClient.Model/冰淇淋/GSIceCreamEvent.cs
  14. +46
    -0
      BPASmartClient.Model/单片机/SCChipEvent.cs
  15. +45
    -0
      BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs
  16. +46
    -0
      BPASmartClient.Model/咖啡机/KLMCoffeeEvent.cs
  17. +4
    -0
      BPASmartClient/DeviceInfo.xml

+ 1
- 0
BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj View File

@@ -10,6 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" />
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" />
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" />
<ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" />
</ItemGroup>


+ 41
- 3
BPASmartClient.DRCoffee/CoffeeMachine.cs View File

@@ -1,10 +1,13 @@
using BPASmartClient.DRCoffee;
using BPASmartClient.EventBus;
using BPASmartClient.Helper;
using BPASmartClient.Model;
using BPASmartClient.Peripheral;
using BPASmartClient.SerialPort;
using System;
using System.Collections.Generic;
using System.Threading;
using static BPASmartClient.EventBus.EventBus;

namespace BPASmartClient.DRCoffee
{
@@ -13,7 +16,7 @@ namespace BPASmartClient.DRCoffee
/// </summary>
public class CoffeeMachine: BasePeripheral
{
public Action<bool> PauseAsk { get; set; }
//通讯代理
SerialPortClient commProxy = null;
//数据仓库
@@ -70,9 +73,20 @@ namespace BPASmartClient.DRCoffee
/// </summary>
public Action<DrCoffeeAppStatus> CoffeeAppStatusChanged;

private DrCoffeePackage drinksOrder = new DrCoffeePackage();

/// <summary>
/// 串口COM口
/// </summary>
public string PortName { get; set; }
/// <summary>
/// 串口波特率
/// </summary>
public string BaudRate { get; set; }

public CoffeeMachine()
{
//commProxy = new SerialPortClient(portName, baud);
//
//commProxy.SetDataStorage(dataStorage);
//commandHandler.Init(commProxy);
//commandHandler.PauseAsk = delegate (bool pause)
@@ -86,6 +100,7 @@ namespace BPASmartClient.DRCoffee
/// </summary>
public override void Start()
{
commProxy = new SerialPortClient(PortName,(BaudRates)Enum.Parse(typeof(BaudRates),BaudRate));
commProxy.Start();
running = true;
MainLoop();
@@ -155,12 +170,35 @@ namespace BPASmartClient.DRCoffee

protected override void InitStatus()
{
throw new NotImplementedException();
}


public override void Init()
{
//咖博士咖啡机制作
EventBus.EventBus.GetInstance().Subscribe<DRCoffee_MakeCoffeeEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack)
{
PauseAsk?.Invoke(true);
Thread.Sleep(200);
drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
//drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).CommCmd;
commProxy.SendData(DrCoffee.Packe(drinksOrder));
Thread.Sleep(200);
PauseAsk?.Invoke(false);
});

//咖博士咖啡机取消制作咖啡
EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CancelMakeCoffeeEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack)
{

});

//咖博士咖啡机模式设置
EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeeCommCmdEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack)
{

});
}
}
}

+ 42
- 0
BPASmartClient.KLMCoffee/Protocal/BitValue.cs View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.KLMCoffee.Protocal
{
public class BitValue
{
#region Byte位数据获取
/// <summary>
/// 7 6 5 4 3 2 1 0
/// </summary>
/// <param name="value"></param>
/// <param name="bit"></param>
/// <returns></returns>
public bool GetBitValue(byte value,byte bit)
{
return (value & (byte)Math.Pow(2,bit)) > 0 ? true : false;
}

/// <summary>
/// 设置某一位的值
/// </summary>
/// <param name="data"></param>
/// <param name="index">要设置的位, 值从低到高为 1-8</param>
/// <param name="flag">要设置的值 true / false</param>
/// <returns></returns>
public byte SetBitValue(byte data,int index,bool flag)
{
if (!((index > 8 || index < 1)))
{
int v = index < 2 ? index : (2 << (index - 2));
return flag ? (byte)(data | v) : (byte)(data & ~v);
}
else
return data;
}
#endregion
}
}

+ 96
- 0
BPASmartClient.KLMCoffee/Protocal/FaultMessage.cs View File

@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.KLMCoffee.Protocal
{
public class FaultMessage :BitValue
{
/// <summary>
/// 蓄水盘没有安装
/// /// </summary>
public bool 安装蓄水盘 { get; set; }
/// <summary>
/// 水箱缺水
/// </summary>
public bool 水箱缺水 { get; set; }
/// <summary>
/// 磨豆异常,无豆检测有豆子,可能是磨豆少、磨豆机不转等问题。
/// </summary>
public bool 磨豆异常 { get; set; }
/// <summary>
/// 蓄水盘废水满
/// </summary>
public bool 蓄水盘满 { get; set; }
/// <summary>
/// 咖啡机满渣
/// </summary>
public bool 咖啡渣满 { get; set; }
/// <summary>
/// 系统缺水
/// </summary>
public bool 系统缺水 { get; set; }
/// <summary>
/// 冲泡器下压位置异常
/// </summary>
public bool 冲泡器故障L { get; set; }
/// <summary>
/// 冲泡器复位位置异常
/// </summary>
public bool 冲泡器故障H { get; set; }
/// <summary>
/// 咖啡机电热盘温度过高,高于设定上限温度
/// </summary>
public bool 高温报警 { get; set; }
/// <summary>
/// 咖啡机开机温度检测环境温度低于 0°。需要温度升到 1° C 以上才可以使用
/// </summary>
public bool 低温报警 { get; set; }
/// <summary>
/// NTC 损坏,阻值无穷大
/// </summary>
public bool ERROR2 { get; set; }
/// <summary>
/// 豆盒中没有豆了
/// </summary>
public bool 咖啡豆用尽 { get; set; }
/// <summary>
/// 电热盘保险丝烧断,加热 NTC 阻值无变化
/// /// </summary>
public bool ERROR1 { get; set; }
/// <summary>
/// 制作咖啡时管路压力过大
/// </summary>
public bool 压力过大 { get; set; }
/// <summary>
/// 连续 3 次系统补水,仍补不上水
/// </summary>
public bool ERROR6 { get; set; }
/// <summary>
/// A & B 中没有牛奶
/// </summary>
public bool 牛奶已用尽 { get; set; }

public FaultMessage(byte valueL,byte valueH)
{
安装蓄水盘 = GetBitValue(valueL,0);
水箱缺水 = GetBitValue(valueL,1);
磨豆异常 = GetBitValue(valueL,2);
蓄水盘满 = GetBitValue(valueL,3);
咖啡渣满 = GetBitValue(valueL,4);
系统缺水 = GetBitValue(valueL,5);
冲泡器故障L = GetBitValue(valueL,6);
冲泡器故障H = GetBitValue(valueL,7);
高温报警 = GetBitValue(valueL,0);
低温报警 = GetBitValue(valueH,1);
ERROR2 = GetBitValue(valueH,2);
咖啡豆用尽 = GetBitValue(valueH,3);
ERROR1 = GetBitValue(valueH,4);
压力过大 = GetBitValue(valueH,5);
ERROR6 = GetBitValue(valueH,6);
牛奶已用尽 = GetBitValue(valueH,7);
}
}
}

+ 1
- 10
BPASmartClient.KLMCoffee/Protocal/K95Command.cs View File

@@ -168,16 +168,7 @@ namespace BPASmartClient.KLMCoffee.Protocal
{
try
{
if (string.IsNullOrEmpty(message) || message.Length < 21)
return;
//:010510000000000000000000F3A 10000000000000000000F
string str = message.Trim().Substring(5,message.Trim().Length - 7); // 去掉字符串首尾处的空格
string systemStatus = str.Substring(0,4);
string makeStatus = str.Substring(4,4);
string makeProgress = str.Substring(8,4);
string makeProgress1 = str.Substring(12,4);
string Error = str.Substring(16,4);
string InFormation = str.Substring(20,1);
SystemStatusModel systemStatus = new SystemStatusModel(message);
}
catch (Exception)
{


+ 25
- 0
BPASmartClient.KLMCoffee/Protocal/K95SysTemStatus.cs View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.KLMCoffee.Protocal
{
/// <summary>
/// 系统状态
/// </summary>
public enum K95SysTemStatus
{
初始化状态,
空闲状态,
运行状态,
关机状态,
正在制作咖啡,
冲泡器清洗和奶沫器清洗,
冲泡器药片清洗,
奶沫器药片清洗,
除垢清洗,
清空管路
}
}

+ 60
- 0
BPASmartClient.KLMCoffee/Protocal/K95commandEnumExtensions.cs View File

@@ -146,5 +146,65 @@ namespace BPASmartClient.KLMCoffee.Protocal
default: return "00";
}
}

/// <summary>
/// 获取系统状态枚举值
/// </summary>
/// <param name="me"></param>
/// <returns></returns>
public static string GetString(this K95SysTemStatus me)
{
switch (me)
{
case K95SysTemStatus.初始化状态: return "0";
case K95SysTemStatus.空闲状态: return "1";
case K95SysTemStatus.运行状态: return "2";
case K95SysTemStatus.关机状态: return "3";
case K95SysTemStatus.正在制作咖啡: return "8";
case K95SysTemStatus.冲泡器清洗和奶沫器清洗: return "9";
case K95SysTemStatus.冲泡器药片清洗: return "A";
case K95SysTemStatus.奶沫器药片清洗: return "B";
case K95SysTemStatus.除垢清洗: return "C";
case K95SysTemStatus.清空管路: return "D";
default: return "0";
}
}

/// <summary>
/// 获取饮品制作状态值
/// </summary>
/// <param name="me"></param>
/// <returns></returns>
public static string GetString(this MakeStatus me)
{
switch (me)
{
case MakeStatus.正在制作: return "0";
case MakeStatus.暂停: return "1";
case MakeStatus.取消: return "2";
case MakeStatus.完成: return "3";
default: return "0";
}
}

/// <summary>
/// 获取饮品制作状态值
/// </summary>
/// <param name="me"></param>
/// <returns></returns>
public static string GetString(this TaskIndex me)
{
switch (me)
{
case TaskIndex.无任务: return "0";
case TaskIndex.出咖啡: return "1";
case TaskIndex.出热水: return "2";
case TaskIndex.出牛奶: return "3";
case TaskIndex.出奶沫: return "4";
case TaskIndex.同时出: return "5";
case TaskIndex.磨豆: return "6";
default: return "0";
}
}
}
}

+ 19
- 0
BPASmartClient.KLMCoffee/Protocal/MakeStatus.cs View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.KLMCoffee.Protocal
{
/// <summary>
/// 饮品制作状态
/// </summary>
public enum MakeStatus
{
正在制作,
暂停,
取消,
完成
}
}

+ 84
- 0
BPASmartClient.KLMCoffee/Protocal/SystemStatusModel.cs View File

@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.KLMCoffee.Protocal
{
public class SystemStatusModel :BitValue
{
/// <summary>
/// 系统状态
/// </summary>
public K95SysTemStatus temStatus { get; set; }
/// <summary>
/// 饮品类型
/// </summary>
public DrinkType drinkType { get; set; }
/// <summary>
/// 制作状态
/// </summary>
public MakeStatus makeStatus { get; set; }
/// <summary>
/// 当前任务
/// </summary>
public TaskIndex taskIndex { get; set; }
/// <summary>
/// 当前进度 10%
/// </summary>
public int progress { get; set; }
/// <summary>
/// 故障信息
/// </summary>
public FaultMessage faultMessage { get; set; }
/// <summary>
/// 保养信息
/// </summary>
public UpkeepMessage upkeepMessage { get; set; }

public SystemStatusModel(string cmd)
{
// 去掉字符串首尾处的空格
if (string.IsNullOrEmpty(cmd) || cmd.Length < 21)
return;
string str = cmd.Trim().Substring(5,cmd.Trim().Length - 7).Replace(@"\R","").Replace("\r","").Replace(@"\n","").Replace(@"\N","");
string systemStatus = str.Substring(0,4);//系统状态
string makeSta = str.Substring(4,4);//制作状态
string makeProgress = str.Substring(8,4);//制作进度
string makeProgress1 = str.Substring(12,4);//制作进度
byte ErrorH = byte.Parse(str.Substring(16,2));//故障信息
byte ErrorL = byte.Parse(str.Substring(18,2));//故障信息
byte InFormation = byte.Parse(str.Substring(20,1));//保养信息

foreach (var item in Enum.GetNames(typeof(K95SysTemStatus)))
{
if (systemStatus.Substring(0,1) == ((K95SysTemStatus)Enum.Parse(typeof(K95SysTemStatus),item)).GetString())
temStatus = ((K95SysTemStatus)Enum.Parse(typeof(K95SysTemStatus),item));
}

foreach (var item in Enum.GetNames(typeof(DrinkType)))
{
if ("0" + makeSta.Substring(0,1) == ((DrinkType)Enum.Parse(typeof(DrinkType),item)).GetString())
drinkType = ((DrinkType)Enum.Parse(typeof(DrinkType),item));
}

foreach (var item in Enum.GetNames(typeof(MakeStatus)))
{
if (makeSta.Substring(1,1) == ((MakeStatus)Enum.Parse(typeof(MakeStatus),item)).GetString())
makeStatus = ((MakeStatus)Enum.Parse(typeof(MakeStatus),item));
}

foreach (var item in Enum.GetNames(typeof(TaskIndex)))
{
if (makeSta.Substring(2,1) == ((TaskIndex)Enum.Parse(typeof(TaskIndex),item)).GetString())
taskIndex = ((TaskIndex)Enum.Parse(typeof(TaskIndex),item));
}

if (makeProgress1 != "0000")
progress = Convert.ToInt32(makeProgress,16) / Convert.ToInt32(makeProgress1,16);
faultMessage = new FaultMessage(ErrorL,ErrorH);
upkeepMessage = new UpkeepMessage(InFormation);
}
}
}

+ 22
- 0
BPASmartClient.KLMCoffee/Protocal/TaskIndex.cs View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.KLMCoffee.Protocal
{
/// <summary>
/// 任务进度索引
/// </summary>
public enum TaskIndex
{
无任务,
出咖啡,
出热水,
出牛奶,
出奶沫,
同时出,
磨豆
}
}

+ 36
- 0
BPASmartClient.KLMCoffee/Protocal/UpkeepMessage.cs View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.KLMCoffee.Protocal
{
public class UpkeepMessage :BitValue
{
/// <summary>
/// 1 冲泡器需要清洗,
/// /// </summary>
public bool 冲泡器需要清洗 { get; set; }
/// <summary>
/// 1 奶沫器需要清洗,
/// /// </summary>
public bool 奶沫器需要清洗 { get; set; }
/// <summary>
/// 1 咖啡机需要除垢,
/// /// </summary>
public bool 咖啡机需要除垢 { get; set; }
/// <summary>
/// 1 需要更换滤芯,
/// /// </summary>
public bool 需要更换滤芯 { get; set; }

public UpkeepMessage(byte value)
{
冲泡器需要清洗 = GetBitValue(value,3);
奶沫器需要清洗 = GetBitValue(value,2);
咖啡机需要除垢 = GetBitValue(value,1);
需要更换滤芯 = GetBitValue(value,0);
}
}
}

+ 4
- 0
BPASmartClient.Model/BPASmartClient.Model.csproj View File

@@ -10,4 +10,8 @@
<ProjectReference Include="..\BPASmartClient.EventBus\BPASmartClient.EventBus.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="机器人\" />
</ItemGroup>

</Project>

+ 38
- 0
BPASmartClient.Model/冰淇淋/GSIceCreamEvent.cs View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Model
{
/// <summary>
/// 驱动设备: 广深冰淇淋机器
/// 设备序列号:0x02225132
/// 创建时间: 20220419
/// </summary>

/// <summary>
/// 广深冰淇淋机模式设置
/// </summary>
public class GSIceCream_ModeSetEvent :BaseEvent
{

}

/// <summary>
/// 广深冰淇淋机打料
/// </summary>
public class GSIceCream_DischargeEvent :BaseEvent
{

}

/// <summary>
/// 广深冰淇淋机结束制作
/// </summary>
public class GSIceCream_EndCookEvent :BaseEvent
{

}
}

+ 46
- 0
BPASmartClient.Model/单片机/SCChipEvent.cs View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Model.单片机
{
/// <summary>
/// 驱动设备: 单片机外设
/// 设备序列号:0x02225132
/// 创建时间: 20220419
/// </summary>

/// <summary>
/// STM32F103RCT6单片机下杯
/// </summary>
public class SCChip_TakeCupEvent :BaseEvent
{

}

/// <summary>
/// STM32F103RCT6单片机舵机打料
/// </summary>
public class SCChip_MakeIceCreamEvent :BaseEvent
{

}

/// <summary>
/// STM32F103RCT6单片机舵机打开或者关闭
/// </summary>
public class SCChip_SESwitchCreamEvent :BaseEvent
{

}

/// <summary>
/// STM32F103RCT6单片机控制冰淇淋机器转
/// </summary>
public class SCChip_RotorSwitchEvent :BaseEvent
{

}
}

+ 45
- 0
BPASmartClient.Model/咖啡机/DRCoffeeEvent.cs View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Model
{
/// <summary>
/// 驱动设备: 咖博士咖啡机器
/// 设备序列号:0x02225132
/// 创建时间: 20220419
/// </summary>

/// <summary>
/// 咖博士咖啡机制作
/// </summary>
public class DRCoffee_MakeCoffeeEvent :BaseEvent
{
}

/// <summary>
/// 咖博士咖啡机取消制作咖啡
/// </summary>
public class DRCoffee_CancelMakeCoffeeEvent :BaseEvent
{

}

/// <summary>
/// 咖博士咖啡机模式设置
/// </summary>
public class DRCoffee_CoffeeCommCmdEvent :BaseEvent
{

}

/// <summary>
/// 咖博士咖啡机结束制作
/// </summary>
public class DRCoffee_CoffeEndCookEvent :BaseEvent
{

}
}

+ 46
- 0
BPASmartClient.Model/咖啡机/KLMCoffeeEvent.cs View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Model
{
/// <summary>
/// 驱动设备: 伽乐美咖啡机
/// 设备序列号:0x02225132
/// 创建时间: 20220419
/// </summary>

/// <summary>
/// 伽乐美咖啡机制作
/// </summary>
public class KLMCoffee_MakeCoffeeEvent :BaseEvent
{

}

/// <summary>
/// 伽乐美咖啡机取消制作咖啡
/// </summary>
public class KLMCoffee_CancelMakeCoffeeEvent :BaseEvent
{

}

/// <summary>
/// 伽乐美咖啡机模式设置
/// </summary>
public class KLMCoffee_CoffeeCommEvent :BaseEvent
{

}

/// <summary>
/// 伽乐美咖啡机结束制作
/// </summary>
public class KLMCoffee_CoffeEndCookEvent :BaseEvent
{

}
}

+ 4
- 0
BPASmartClient/DeviceInfo.xml View File

@@ -11,10 +11,14 @@
</Peripheral>
<Peripheral Module="BPASmartClient.DRCoffee.CoffeeMachine">
<Parameters>
<PortName>COM5</PortName>
<BaudRate>9600</BaudRate>
</Parameters>
</Peripheral>
<Peripheral Module="BPASmartClient.SCChip.ICChipMachine">
<Parameters>
<PortName>COM5</PortName>
<BaudRate>9600</BaudRate>
</Parameters>
</Peripheral>
</Peripherals>


Loading…
Cancel
Save