From b0a4c47dd74bc41c5df3bab6ddd8de7bcc6a52b0 Mon Sep 17 00:00:00 2001
From: patrick <patrick.xu@broconcentric.com>
Date: 星期五, 06 十二月 2019 18:35:42 +0800
Subject: [PATCH] 1. 重新整理项目,按照A034模式,将设备异步操作修改为类同步操作。使用任务队列来存储和分配任务。

---
 src/Bro.Device.AuboRobot/AuboRobotConfig.cs |  205 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 161 insertions(+), 44 deletions(-)

diff --git a/src/Bro.Device.AuboRobot/AuboRobotConfig.cs b/src/Bro.Device.AuboRobot/AuboRobotConfig.cs
index 8c70b49..043faec 100644
--- a/src/Bro.Device.AuboRobot/AuboRobotConfig.cs
+++ b/src/Bro.Device.AuboRobot/AuboRobotConfig.cs
@@ -1,7 +1,6 @@
 锘縰sing Bro.Common.Base;
 using Bro.Common.Helper;
 using Bro.Common.Model;
-using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Drawing.Design;
@@ -25,12 +24,20 @@
         public int ReplyTimeout { get; set; } = 1000;
 
         [Category("閫氫俊璁剧疆")]
+        [Description("鍙嶉瓒呮椂閲嶈瘯娆℃暟")]
+        public int TimeoutRetryTimes { get; set; } = 5;
+
+        [Category("閫氫俊璁剧疆")]
         [Description("鍗忚鏂囨湰缁撴潫瀛楃")]
         public string EndChar { get; set; } = "#";
 
         [Category("閫氫俊璁剧疆")]
         [Description("鍗忚鍐呭鍒嗛殧瀛楃")]
         public string Seperator { get; set; } = ",";
+
+        [Category("鍔ㄤ綔璁剧疆")]
+        [Description("鍔ㄤ綔瓒呮椂璁剧疆锛屽崟浣峬in")]
+        public float OperationTimeout { get; set; } = 1;
 
         [Category("IO鐩戝惉璁剧疆")]
         [Description("IO鐩戝惉鎿嶄綔閰嶇疆闆嗗悎")]
@@ -40,12 +47,54 @@
 
         [Category("IO鐩戝惉璁剧疆")]
         [Description("IO鐩戝惉闂撮殧锛屼互ms涓哄崟浣�")]
-        public int ScanInterval { get; set; } = 100;
+        public int ScanInterval { get; set; } = 9999;
+
+        [Category("IO鐩戝惉璁剧疆")]
+        [Description("鏄惁鍚敤IO鐩戝惉,true锛氱洃鍚� false锛氫笉鐩戝惉")]
+        public bool IsEnableMonitor { get; set; } = false;
+
+        [Category("鎶ヨ閰嶇疆")]
+        [Description("鎶ヨ浠g爜閰嶇疆")]
+        [TypeConverter(typeof(CollectionCountConvert))]
+        [Editor(typeof(ComplexCollectionEditor<RobotWarningCode>), typeof(UITypeEditor))]
+        public List<RobotWarningCode> RobotWarnings { get; set; } = new List<RobotWarningCode>();
+    }
+
+    public class RobotWarningCode
+    {
+        [Category("鎶ヨ閰嶇疆")]
+        [Description("鎶ヨ浠g爜")]
+        public int WarningCode { get; set; }
+
+        [Category("鎶ヨ閰嶇疆")]
+        [Description("鎶ヨ浠g爜鎻忚堪")]
+        public string WarningDescription { get; set; }
     }
 
     [Device("AuboRobot", "濂ュ崥鏈哄櫒浜�", EnumHelper.DeviceAttributeType.OperationConfig)]
     public class AuboRobotOperationConfig : OperationConfigBase
     {
+        [Category("鍔ㄤ綔鎸囦护")]
+        [Description("鍔ㄤ綔鎸囦护")]
+        public RobotMsgAction Action { get; set; } = RobotMsgAction.Move;
+
+        [Category("鍙傛暟")]
+        [Description("鍙傛暟1")]
+        public int Para1 { get; set; } = 0;
+
+        [Category("鍙傛暟")]
+        [Description("鍙傛暟2")]
+        public int Para2 { get; set; } = 0;
+
+        [Category("杩愬姩閰嶇疆")]
+        [Description("鏈哄櫒浜鸿繍鍔ㄧ偣浣�")]
+        [TypeConverter(typeof(ComplexObjectConvert))]
+        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
+        public RobotPoint Point { get; set; } = new RobotPoint();
+
+        [Category("鎿嶄綔閰嶇疆")]
+        [Description("鏄惁绛夊緟瀹屾垚淇″彿")]
+        public bool IsWaitFinished { get; set; } = true;
     }
 
     public class RobotMsg : IComplexDisplay
@@ -56,16 +105,13 @@
 
         public RobotMsgAction Action { get; set; } = RobotMsgAction.Move;
 
-        public RobotMsgParas Para1 { get; set; } = RobotMsgParas.None;
+        public int Para1 { get; set; }
 
         public int Para2 { get; set; } = 0;
 
-        /// <summary>
-        /// Paras涓嶅寘鍚玃ara1,Para2鍐呭
-        /// </summary>
-        public List<string> Datas { get; set; } = new List<string>();
+        public RobotPoint Point { get; set; } = new RobotPoint();
 
-        public byte[] GetMsgBytes(string seperator, string endChar)
+        public byte[] GetMsgBytes(string seperator, string endChar, out string msg)
         {
             List<string> list = new List<string>() { ((int)Type).ToString("D2"), ID.ToString("D2") };
 
@@ -73,34 +119,51 @@
             {
                 list.Add(((int)Action).ToString("D2"));
 
-                list.Add(((int)Para1).ToString("D2"));
+                list.Add(Para1.ToString("D2"));
                 list.Add(Para2.ToString("D2"));
 
-                if (Datas == null)
-                {
-                    Datas = new List<string>();
-                }
-
-                while (Datas.Count < 5)
-                {
-                    Datas.Add("0");
-                }
-
-                list.AddRange(Datas.ConvertAll(s =>
-                {
-                    string res = float.Parse(s).ToString("F7");
-
-                    while (res.Length < 11)
-                    {
-                        res = "0" + res;
-                    }
-                    return res;
-                }));
+                list.Add(GetFormatString(Point.X));
+                list.Add(GetFormatString(Point.Y));
+                list.Add(GetFormatString(Point.Z));
+                list.Add(GetFormatString_Angle(Point.A));
+                list.Add(GetFormatString_Angle(Point.B));
+                list.Add(GetFormatString_Angle(Point.C));
             }
 
-            string msg = string.Join(seperator, list);
+            msg = string.Join(seperator, list) + seperator + endChar;
 
-            return System.Text.Encoding.ASCII.GetBytes(msg + endChar);
+            return System.Text.Encoding.ASCII.GetBytes(msg);
+        }
+
+        private string GetFormatString(float x)
+        {
+            string s = x.ToString("f10");
+
+            s = s.TrimEnd(new char[] { '0' });
+
+            bool isNegative = x < 0;
+
+            while (s.Length < 11)
+            {
+                s = s.Insert(isNegative ? 1 : 0, "0");
+            }
+
+            return s;
+        }
+
+        /// <summary>
+        /// 灏嗚搴︽暟鍊艰浆鎹负11浣嶅瓧绗︿覆锛岃緭鍏ヨ搴﹀尯闂�0~360锛岃緭鍑鸿搴﹀尯闂�-180~+180
+        /// </summary>
+        /// <param name="x"></param>
+        /// <returns></returns>
+        private string GetFormatString_Angle(float x)
+        {
+            if (x > 180)
+            {
+                x = x - 360;
+            }
+
+            return GetFormatString(x);
         }
 
         public static RobotMsg GetRobotMsg(string data, string seperator)
@@ -116,10 +179,22 @@
             {
                 msg.Action = (RobotMsgAction)int.Parse(datas[2]);
 
-                msg.Para1 = (RobotMsgParas)int.Parse(datas[3]);
+                msg.Para1 = int.Parse(datas[3]);
                 msg.Para2 = int.Parse(datas[4]);
 
-                msg.Datas = datas.Skip(5).ToList();
+                msg.Point = new RobotPoint()
+                {
+                    X = float.Parse(datas[5]),
+                    Y = float.Parse(datas[6]),
+                    Z = float.Parse(datas[7]),
+                    A = float.Parse(datas[8]) < 0 ? float.Parse(datas[8]) + 360 : float.Parse(datas[8]),
+                    B = float.Parse(datas[9]) < 0 ? float.Parse(datas[9]) + 360 : float.Parse(datas[9]),
+                    C = float.Parse(datas[10]) < 0 ? float.Parse(datas[10]) + 360 : float.Parse(datas[10]),
+                };
+            }
+            else
+            {
+                msg.Para1 = int.Parse(datas[2]);
             }
 
             return msg;
@@ -127,7 +202,7 @@
 
         public string GetDisplayText()
         {
-            string msg = $"搴忓彿锛歿ID},{Action.ToString()}_{Para1.ToString()}_{Para2.ToString()}_{(Datas.Count > 0 ? ("_" + string.Join(",", Datas)) : "")}";
+            string msg = $"搴忓彿锛歿ID},{Action.ToString()}_{Para1.ToString()}_{Para2.ToString()}_{Point.GetDisplayText()}";
             return msg;
         }
     }
@@ -143,20 +218,62 @@
         Move = 1,
         Unload = 2,
         Load = 3,
-        IO = 6,
+        GetPosition = 4,
+        /// <summary>
+        /// 鎸囧畾褰撳墠鐐逛綅涓哄熀鍑嗙偣
+        /// </summary>
+        BasePoint = 5,
+        IOSet = 6,
+        IOQuery = 7,
         Calibration = 9,
         StandardPoint = 10,
     }
 
-    public enum RobotMsgParas
+    public enum MoveType
     {
-        None = 0,
-        Home = 1,
-        LineSnap = 2,
-        EmptyTray = 3,
-        FullTray = 4,
-        UnloadEmptyTraySnap = 5,
-        LoadFullTraySnap = 6,
-        Query = 7,
+        [Description("缁濆杩愬姩")]
+        AbsoluteMove = 1,
+        [Description("鏈哄櫒浜哄潗鏍囩郴鐩稿杩愬姩")]
+        RobotRelativeMove = 2,
+        [Description("鐩稿鏌愪釜鍩哄噯鐐逛綅鐨勭浉瀵硅繍鍔�")]
+        BasedPointRelativeMove = 3,
+        [Description("鍥炲師鐐�")]
+        Origin = 4,
+        [Description("宸︿晶濮垮娍")]
+        LeftPose = 6,
+        [Description("鍙充晶濮垮娍")]
+        RightPose = 5,
+        [Description("鍓嶄晶濮垮娍")]
+        FrontPose = 7,
+        [Description("鐩告満鍧愭爣绯荤浉瀵硅繍鍔�")]
+        CameraRelativeMove = 12,
     }
+
+    public enum TrayType
+    {
+        FullTray = 1,
+        EmptyTray = 2,
+    }
+
+    //public enum RobotMsgAction
+    //{
+    //    Move = 1,
+    //    Unload = 2,
+    //    Load = 3,
+    //    IO = 6,
+    //    Calibration = 9,
+    //    StandardPoint = 10,
+    //}
+
+    //public enum RobotMsgParas
+    //{
+    //    None = 0,
+    //    Home = 1,
+    //    LineSnap = 2,
+    //    EmptyTray = 3,
+    //    FullTray = 4,
+    //    UnloadEmptyTraySnap = 5,
+    //    LoadFullTraySnap = 6,
+    //    Query = 7,
+    //}
 }

--
Gitblit v1.8.0