using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ButcherFactory.Controls
{
  internal class IND560DataFormat : DataFormatBase
  {
    public override int DataLength
    {
      get { return 10; }
    }

    public override char Beginchar
    {
      get { return (char)0x80; }//这种数据没有固定的开始标志
    }

    public override char Endchar
    {
      get { return (char)0x67; }
    }

    public override short Bufsize
    {
      get { return 36; }
    }
    public override string ParseData(string buf, out bool isStatic)
    {
      isStatic = false;
      return string.Empty;
    }

    public override bool ParseAscii(string buf, out string weight, out bool isStatic)
    {
      isStatic = true;
      weight = buf.Replace("kg", "").Replace((char)0x0D, (char)0x20).Replace((char)0x0A, (char)0x20).Replace((char)0x3F, (char)0x20);
      weight = weight.Trim();
      if (weight.Any(x => x == ' '))
      {
        var arr = weight.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (arr.Length > 1)
          weight = arr[1];
      }
      return true;
    }

    public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr)
    {
      weight = "";
      isStatic = false;
      subStr = "";
      return false;
    }
  }
}
