using BPASmartClient.Business;
using BPASmartClient.Device;
using BPASmartClient.DRCoffee;
using BPASmartClient.EventBus;
using BPASmartClient.GSIceCream;
using BPASmartClient.Helper;
using BPASmartClient.LebaiRobot;
using BPASmartClient.Message;
using BPASmartClient.Model;
using BPASmartClient.Model.乐白机器人;
using BPASmartClient.Model.冰淇淋.Enum;
using BPASmartClient.Model.单片机;
using BPASmartClient.Model.单片机.Enum;
using BPASmartClient.Model.咖啡机.Enum;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
namespace BPASmartClient.MorkTHQ.ViewModel
{
public class DebugViewModel : ObservableObject
{
#region 乐白机器人
///
/// 乐白机器人连接状态
///
public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } }
private string _robotConnected { get; set; }
///
/// 乐白机器人的模式状态
///
public string RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } }
private string _robotMode { get; set; }
///
/// 机器人控制指令
///
public RelayCommand Button_RobotControlCommand { get; set; }
///
/// 机器人控制
///
///
public RelayCommand Button_SetValueCommand { get; set; }
private void Button_SetValue()
{
EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
}
private void Button_RobotControl(object o)
{
EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
}
#endregion
#region 冰淇淋机器
///
/// 制作冰淇淋
///
public RelayCommand Button_MakeIceCreamCommand { get; set; }
///
/// 选择冰淇淋模式
///
public RelayCommand Button_SetIceCreamModelCommand { get; set; }
///
/// 冰淇淋连接状态
///
public string IceCreamConnected { get { return _iceCreamConnected; } set { _iceCreamConnected = value; OnPropertyChanged(); } }
private string _iceCreamConnected { get; set; }
///
/// 预冷温度
///
public string YLWD { get { return _yLWD; } set { _yLWD = value; OnPropertyChanged(); } }
private string _yLWD { get; set; }
///
/// 回气温度
///
public string HQWD { get { return _hQWD; } set { _hQWD = value; OnPropertyChanged(); } }
private string _hQWD { get; set; }
///
/// 环境温度
///
public string HJWD { get { return _hJWD; } set { _hJWD = value; OnPropertyChanged(); } }
private string _hJWD { get; set; }
///
/// 电流
///
public string DL { get { return _DL; } set { _DL = value; OnPropertyChanged(); } }
private string _DL { get; set; }
///
/// 电压
///
public string DY { get { return _dy; } set { _dy = value; OnPropertyChanged(); } }
private string _dy { get; set; }
///
/// 当前模式
///
public string CurrentMode { get { return _CurrentMode; } set { _CurrentMode = value; OnPropertyChanged(); } }
private string _CurrentMode;
///
/// 故障
///
public string IceCreamFault { get { return _IceCreamFault; } set { _IceCreamFault = value; OnPropertyChanged(); } }
private string _IceCreamFault { get; set; }
///
/// 成型比
///
public string CXB { get { return _cXB; } set { _cXB = value; OnPropertyChanged(); } }
private string _cXB { get; set; }
///
/// 打料完成状态
///
public string DLCompleted { get { return _dLCompleted; } set { _dLCompleted = value; OnPropertyChanged(); } }
private string _dLCompleted { get; set; }
public List IceCreamModes { get; set; } = new List();
public string SelecteIceCreamdMode { get; set; }
private void Button_MakeIceCream()
{
EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId });
}
private void Button_SetIceCreamModel()
{
MORKI_MODE mORKI_MODE = (MORKI_MODE)Enum.Parse(typeof(MORKI_MODE), SelecteIceCreamdMode);
new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = mORKI_MODE }.Publish();
}
#endregion
#region 咖啡机
///
/// 咖啡机连接状态
///
public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } }
private string _coffeeConnected { get; set; }
///
/// 咖啡机状态
///
public string CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } }
private string _coffeeStatus { get; set; }
///
/// 应用状态
///
public string CoffeeAppStatus { get { return _coffeAappStatus; } set { _coffeAappStatus = value; OnPropertyChanged(); } }
private string _coffeAappStatus { get; set; }
///
/// 告警
///
public string CoffeeWarning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
private string _warning { get; set; }
///
/// 故障信息
///
public string CoffeeFault { get { return _coffeeFault; } set { _coffeeFault = value; OnPropertyChanged(); } }
private string _coffeeFault { get; set; }
public string Coffeeprogress { get { return _coffeeprogress; } set { _coffeeprogress = value; OnPropertyChanged(); } }
private string _coffeeprogress { get; set; }
public List Coffees { get; set; } = new List();
public string SelectedCoffee { get; set; }
public List CoffeeCmds { get; set; } = new List();
public string SelectedCoffeeCmd { get; set; }
///
/// 制作咖啡
///
public RelayCommand Button_MakeCoffeeCommand { get; set; }
///
/// 停止制作咖啡
///
public RelayCommand Button_StopMakeCoffeCommand { get; set; }
///
/// 咖啡模式设置
///
public RelayCommand Button_CoffeeModeSetCommand { get; set; }
private void Button_MakeCoffee()
{
EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)});
}
private void Button_StopMakeCoffe()
{
EventBus.EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
}
private void Button_CoffeeModeSet()
{
EventBus.EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)});
}
#endregion
#region 单片机
///
/// 单片机连接状态
///
public string SCChipIsConnect { get { return _sCChipIsConnect; } set { _sCChipIsConnect = value; OnPropertyChanged(); } }
private string _sCChipIsConnect { get; set; }
///
/// 咖啡杯或冰淇淋杯落杯
///
public RelayCommand Button_CupControlCommand { get; set; }
///
/// 单片机冰淇淋机器制冷
///
public RelayCommand Button_SCChipRefrigerationCommand { get; set; }
///
/// 单片机冰淇淋机器打料
///
public RelayCommand Button_SCChipDischargeCommand { get; set; }
///
/// 模拟测试
///
public RelayCommand Button_SCChipTestCommand { get; set; }
private void Button_CupControl(object CupType)
{
EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent() { DeviceId = DeviceId, Cup = (IC_CUP)Enum.Parse(typeof(IC_CUP), CupType.ToString()) });
}
private void Button_SCChipRefrigeration()
{
EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
Thread.Sleep(500);
EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
}
private void Button_SCChipDischarge()
{
EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });
}
#endregion
#region 果汁机
///
/// 果汁机连接状态
///
public string JuiceIsConnect { get { return _juiceIsConnect; } set { _juiceIsConnect = value; OnPropertyChanged(); } }
private string _juiceIsConnect { get; set; }
public List Juice { get; set; } = new List() { "果汁1", "果汁2", "果汁3", "果汁4" };
public string SelectedJuice { get; set; } = "果汁1";
public List Temperature { get; set; } = new List() { "冷", "热" };
public string SelectedTemperature { get; set; } = "冷";
public RelayCommand MakeJuiceCommand { get; set; }
private void MakeJuice()
{
switch (SelectedJuice)
{
case "果汁1":
if (SelectedTemperature == "冷")
{
MakeJuiceEvent(0x01);
}
else MakeJuiceEvent(0x00);
break;
case "果汁2":
if (SelectedTemperature == "冷")
{
MakeJuiceEvent(0x03);
}
else MakeJuiceEvent(0x02);
break;
case "果汁3":
if (SelectedTemperature == "冷")
{
MakeJuiceEvent(0x05);
}
else MakeJuiceEvent(0x04);
break;
case "果汁4":
if (SelectedTemperature == "冷")
{
MakeJuiceEvent(0x07);
}
else MakeJuiceEvent(0x06);
break;
default:
MakeJuiceEvent(0x00);
break;
}
}
private void MakeJuiceEvent(byte b)
{
EventBus.EventBus.GetInstance().Publish(new WriteJuicer { DeviceId = DeviceId, Value = b });
}
#endregion
///
/// 设备ID
///
public int DeviceId { get; set; }
///
/// 设备数据
///
public ObservableCollection variableMonitors { get; set; }
public DebugViewModel()
{
Button_RobotControlCommand = new RelayCommand(Button_RobotControl);
Button_SetValueCommand = new RelayCommand(Button_SetValue);
Button_MakeIceCreamCommand = new RelayCommand(Button_MakeIceCream);
Button_SetIceCreamModelCommand = new RelayCommand(Button_SetIceCreamModel);
Button_MakeCoffeeCommand = new RelayCommand(Button_MakeCoffee);
Button_StopMakeCoffeCommand = new RelayCommand(Button_StopMakeCoffe);
Button_CoffeeModeSetCommand = new RelayCommand(Button_CoffeeModeSet);
Button_CupControlCommand = new RelayCommand(Button_CupControl);
Button_SCChipRefrigerationCommand = new RelayCommand(Button_SCChipRefrigeration);
Button_SCChipDischargeCommand = new RelayCommand(Button_SCChipDischarge);
Button_SCChipTestCommand = new RelayCommand(() =>
{
Button_SCChipRefrigeration();
Thread.Sleep(50);
Button_SCChipDischarge();
});
MakeJuiceCommand = new RelayCommand(MakeJuice);
foreach (DrinkType code in Enum.GetValues(typeof(DrinkType)))
{
Coffees.Add(code.ToString());
}
SelectedCoffee = Coffees[0];
foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
{
CoffeeCmds.Add(code.ToString());
}
SelectedCoffeeCmd = CoffeeCmds[0];
foreach (MORKI_MODE code in Enum.GetValues(typeof(MORKI_MODE)))
{
IceCreamModes.Add(code.ToString());
}
SelecteIceCreamdMode = IceCreamModes[0];
Plugin.GetInstance()?.GetPlugin()?.GetDevices().ForEach(device =>
{
if (device.Name == "MorkTHQ") DeviceId = device.DeviceId
;
});
ThreadManage.GetInstance().StartLong(new Action(() =>
{
variableMonitors = Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.FirstOrDefault(p => p.DeviceId == DeviceId)?.variableMonitors;
if (variableMonitors != null && variableMonitors.Count > 0)
{
RobotConnected = variableMonitors.FirstOrDefault(p=>p.Notes == "机器人连接状态").CurrentValue == "True" ? "已连接" : "未连接";
IceCreamConnected = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋连接状态").CurrentValue == "True" ? "已连接" : "未连接";
CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
SCChipIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "单片机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
JuiceIsConnect = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
CoffeeAppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
CoffeeWarning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
CoffeeFault = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机故障").CurrentValue;
Coffeeprogress = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机制作进度").CurrentValue;
YLWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器预冷温度").CurrentValue;
HQWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器回气温度").CurrentValue;
HJWD = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器环境温度").CurrentValue;
DL = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电流").CurrentValue;
DY = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器电压").CurrentValue;
CurrentMode = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器模式").CurrentValue;
IceCreamFault = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器故障").CurrentValue;
CXB = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器成型比").CurrentValue;
DLCompleted = variableMonitors.FirstOrDefault(p => p.Notes == "冰淇淋机器打料完成")?.CurrentValue == "True" ? "打料完成" : "打料中";
}
Thread.Sleep(500);
}), "MorkT-状态刷新");
}
}
}