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.冰淇淋.Enum;
using BPASmartClient.Model.单片机;
using BPASmartClient.Model.单片机.Enum;
using BPASmartClient.Model.咖啡机.Enum;
using BPASmartClient.MorkT.Model;
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.MorkT.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 int TimeInterval { get { return Global.TimeInterval; } set { Global.TimeInterval = value; OnPropertyChanged(); } }
//private int _timeInterval { get; set; } = Global.TimeInterval;
///
/// 机器人控制指令
///
public RelayCommand Button_RobotControlCommand { get; set; }
///
/// 机器人控制
///
///
public RelayCommand Button_SetValueCommand { get; set; }
public RelayCommand Button_GoToHomeCommand { 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() });
}
private void Button_GoToHome()
{
//EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
//MessageLog.GetInstance.Show("开始执行乐白机器人回原点");
//EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_机器人回原点 });
//MessageLog.GetInstance.Show("开始执行乐白机器人回原点-----");
}
#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);
EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = mORKI_MODE });
}
#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 AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } }
private string _appStatus { get; set; }
///
/// 告警
///
public string Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } }
public string _warning { get; set; }
///
/// 故障信息
///
public string CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } }
public string _caffeeFault { 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 });
EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Value = true, Pin = 1 });
Thread.Sleep(500);
EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Value = false, Pin = 1 });
}
private void Button_SCChipDischarge()
{
EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });
}
#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_GoToHomeCommand = new RelayCommand(Button_GoToHome);
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();
});
foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode)))
{
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 == "MorkT") 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" ? "已连接" : "未连接";
RobotMode = variableMonitors.FirstOrDefault(p => p.Notes == "机器人状态").CurrentValue;
CoffeeStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机状态").CurrentValue;
AppStatus = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机应用状态").CurrentValue;
Warning = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机告警").CurrentValue;
CaffeeFault = 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-状态刷新");
}
}
}