using System;

namespace arDev
{
    public partial class Narumi
    {

        public class Signal
        {
            private COMM.Flag _value { get; set; } = new COMM.Flag(16);
            public void SetValue(Int16 value) { this._value.writeValue(value); }
            public UInt16 Value
            {
                get
                {
                    return (UInt16)_value.Value;
                }
            }
            public enum eflag
            {
                front_gate_out = 0,
                rear_sensor_out,
                mark_sensor_1,
                mark_sensor_2,
                front_left_sensor,
                front_right_sensor,
                front_center_sensor,
                charger_align_sensor,
                
                lift_down,
                lift_up,
                magnet_on,
                ChargetSensor,
                cart_detect1,
                cart_detect2,
                Spare1,
                Spare2
            }

            public bool GetValue(eflag idx)
            {
                return _value.Get((int)idx);
            }
            public bool GetChanged(eflag idx)
            {
                return _value.GetChanged((int)idx);
            }

            public Boolean front_gate_out { get { return GetValue(eflag.front_gate_out); } }
            public Boolean rear_sensor_out { get { return GetValue(eflag.rear_sensor_out); } }
            public Boolean mark_sensor_1 { get { return GetValue(eflag.mark_sensor_1); } }
            public Boolean mark_sensor_2 { get { return GetValue(eflag.mark_sensor_2); } }
            public Boolean mark_sensor { get { return mark_sensor_1 || mark_sensor_2; } }
            public Boolean front_left_sensor { get { return GetValue(eflag.front_left_sensor); } }
            public Boolean front_right_sensor { get { return GetValue(eflag.front_right_sensor); } }
            public Boolean front_center_sensor { get { return GetValue(eflag.front_center_sensor); } }
            public Boolean charger_align_sensor { get { return GetValue(eflag.charger_align_sensor); } }
            public Boolean lift_up { get { return GetValue(eflag.lift_up); } }
            public Boolean lift_down { get { return GetValue(eflag.lift_down); } }
            public Boolean magnet_on { get { return GetValue(eflag.magnet_on); } }
            public Boolean cart_detect1 { get { return GetValue(eflag.cart_detect1); } }
            public Boolean cart_detect2 { get { return GetValue(eflag.cart_detect2); } }
            public override string ToString()
            {
                //모든사태값을 탭으로 구분하여 문자를 생성한다
                var sb = new System.Text.StringBuilder();
                for (int i = 0; i < 16; i++)
                {
                    var def = Enum.IsDefined(typeof(eflag), i);
                    if(def)
                    {
                        var flag = (eflag)i;
                        var value = _value.Get(i);
                        sb.AppendLine($"[{i:00}][{flag}] : {value}");
                    }
          
                }
                return sb.ToString();
            }

        }

    }


}
