using BPASmartClient.Business;
using BPASmartClient.Device;
using BPASmartClient.DRCoffee;
using BPASmartClient.GSIceCream;
using BPA.Helper;
using BPASmartClient.LebaiRobot;
using BPASmartClient.Model;
using BPASmartClient.Model.乐白机器人;
using BPASmartClient.Model.冰淇淋.Enum;
using BPASmartClient.Model.单片机;
using BPASmartClient.Model.单片机.Enum;
using BPASmartClient.Model.咖啡机.Enum;
using BPA.Helper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
namespace BPASmartClient.MorkTLebaiJC.ViewModel;
public class DebugViewModel : NotifyBase
{
#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 BPARelayCommand Button_RobotControlCommand { get; set; }
///
/// 机器人控制
///
///
private void Button_RobotControl(object o)
{
EventBus.GetInstance().Publish(new LebaiRobot_LebaiControlEvent { DeviceId = DeviceId, LebaiControl = o.ToString() });
}
#endregion
#region 果汁机
///
/// 果汁机的连接状态
///
public string JuicerConnected { get { return _JuicerConnected; } set { _JuicerConnected = value; OnPropertyChanged(); } }
private string _JuicerConnected { get; set; }
///
/// 果汁机的状态
///
public string JuicerState { get { return _JuicerState; } set { _JuicerState = value; OnPropertyChanged(); } }
private string _JuicerState { get; set; }
#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 BPARelayCommand Button_MakeCoffeeCommand { get; set; }
///
/// 停止制作咖啡
///
public BPARelayCommand Button_StopMakeCoffeCommand { get; set; }
///
/// 咖啡模式设置
///
public BPARelayCommand Button_CoffeeModeSetCommand { get; set; }
private void Button_MakeCoffee()
{
EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() { DeviceId = DeviceId, DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee)});
}
private void Button_StopMakeCoffe()
{
EventBus.GetInstance().Publish(new DRCoffee_CancelMakeCoffeeEvent() { DeviceId = DeviceId });
}
private void Button_CoffeeModeSet()
{
EventBus.GetInstance().Publish(new DRCoffee_CoffeeCommCmdEvent() { DeviceId = DeviceId, CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd)});
}
#endregion
#region 单片机
public string MCUConnected { get { return _mcuConnected; } set { _mcuConnected = value; OnPropertyChanged(); } }
private string _mcuConnected { get; set; }
public BPARelayCommand Button_MCUOuputCommand { get; set; }
public BPARelayCommand Button_MCUDOuputCommand { get; set; }
public BPARelayCommand Button_LebaiDOuputCommand { get; set; }
public int PWMInputNumber { get { return _pwmInputNumber; } set { _pwmInputNumber = value; OnPropertyChanged(); } }
private int _pwmInputNumber = 1;
public int MCU_PWM_CH { get { return _choosePWM; } set { _choosePWM = value; OnPropertyChanged(); } }
private int _choosePWM = 1;
public int MCU_DO_CH { get { return _mcuDO_CH; } set { _mcuDO_CH = value; OnPropertyChanged(); } }
private int _mcuDO_CH = 1;
public int Lebai_DO_CH { get { return _lebaiDO_CH; } set { _lebaiDO_CH = value; OnPropertyChanged(); } }
private int _lebaiDO_CH = 1;
public int Lebai_DO_Value { get { return _lebaiDO_Value; } set { _lebaiDO_Value = value; OnPropertyChanged(); } }
private int _lebaiDO_Value = 1;
private int[] DICH { get { return _diCH; } set { _diCH = value; OnPropertyChanged(); } }
private int[] _diCH = new int[8];
public bool MCU_DO_Value { get { return _mcu_DO_Valuer; } set { _mcu_DO_Valuer = value; OnPropertyChanged(); } }
private bool _mcu_DO_Valuer = true;
public bool MCU_DI0 { get { return _mcu_DI0; }set { _mcu_DI0 = value;OnPropertyChanged(); } }
private bool _mcu_DI0 = true;
public bool MCU_DI1 { get { return _mcu_DI1; } set { _mcu_DI1 = value; OnPropertyChanged(); } }
private bool _mcu_DI1 = true;
public bool MCU_DI2 { get { return _mcu_DI2; } set { _mcu_DI2 = value; OnPropertyChanged(); } }
private bool _mcu_DI2 = true;
public bool MCU_DI3 { get { return _mcu_DI3; } set { _mcu_DI3 = value; OnPropertyChanged(); } }
private bool _mcu_DI3 = true;
public bool MCU_DI4 { get { return _mcu_DI4; } set { _mcu_DI4 = value; OnPropertyChanged(); } }
private bool _mcu_DI4 = true;
public bool MCU_DI5 { get { return _mcu_DI5; } set { _mcu_DI5 = value; OnPropertyChanged(); } }
private bool _mcu_DI5 = true;
public bool MCU_DI6 { get { return _mcu_DI6; } set { _mcu_DI6 = value; OnPropertyChanged(); } }
private bool _mcu_DI6 = true;
public bool MCU_DI7 { get { return _mcu_DI7; } set { _mcu_DI7 = value; OnPropertyChanged(); } }
private bool _mcu_DI7 = true;
///
/// 单片机舵机输出
///
private void Button_McuOutput()
{
string sChoosePWM =Convert.ToString(MCU_PWM_CH+1);
new WriteMcu() { TagName = "ServoControl", Address = sChoosePWM, Value = PWMInputNumber }.Publish();
}
///
/// 单片机DO输出
///
private void Button_McuDOutput()
{
string sChooseDO = Convert.ToString(MCU_DO_CH + 1);
new WriteMcu() { TagName = "OutputControl", Address = sChooseDO, Value = MCU_DO_Value }.Publish();
}
///
/// 乐白的DO输出
///
private void Button_LebaiDOutput()
{
int sChooseDO = Convert.ToInt16(Lebai_DO_CH);
bool lebai_DO_Value = Convert.ToInt16(Lebai_DO_Value) == 0;
new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = sChooseDO, Value = lebai_DO_Value }.Publish();
}
#endregion
///
/// 设备ID
///
public int DeviceId { get; set; }
///
/// 设备数据
///
public ObservableCollection variableMonitors { get; set; }
public DebugViewModel()
{
Button_RobotControlCommand = new BPARelayCommand(Button_RobotControl);
Button_MakeCoffeeCommand = new BPARelayCommand(Button_MakeCoffee);
Button_StopMakeCoffeCommand = new BPARelayCommand(Button_StopMakeCoffe);
Button_CoffeeModeSetCommand = new BPARelayCommand(Button_CoffeeModeSet);
Button_MCUOuputCommand = new BPARelayCommand(Button_McuOutput);
Button_MCUDOuputCommand = new BPARelayCommand(Button_McuDOutput);
Button_LebaiDOuputCommand = new BPARelayCommand(Button_LebaiDOutput);
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];
Plugin.GetInstance()?.GetPlugin()?.GetDevices().ForEach(device =>
{
if (device.Name == "MorkT") DeviceId = device.DeviceId
;
});
TaskManage.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" ? "已连接" : "未连接";
CoffeeConnected = variableMonitors.FirstOrDefault(p => p.Notes == "咖啡机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
JuicerConnected = variableMonitors.FirstOrDefault(p => p.Notes == "果汁机连接状态").CurrentValue == "True" ? "已连接" : "未连接";
MCUConnected = 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;
}
Thread.Sleep(500);
}), "MorkT-状态刷新");
}
}