using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace arDev
{
    public  partial class MasterK
    {
        [Description("")]
        public enum eMsgType
        {
            [Description("")]
            Rx = 0,
            [Description("")]
            Tx,
            RxRaw,
        }
        [Description("Operation Code , 이 코드값으로 컨트롤 보드에 명령합니다.")]
        public enum eOpCode : byte
        {
            GET_IO_DATA = 0,
            RELAY_OUTPUT,
        }
        /// 
        /// digital input/output direction
        /// 
        public enum eIOPINDIR : byte
        {
            [Description("Digital Input")]
            INPUT = 0,
            [Description("Digital Output")]
            OUTPUT = 1,
        }
        /// 
        /// error code list 
        /// 
        public enum eErrorCode : byte
        {
            [Description("포트가사용중입니다.")]
            PortBusy = 0,
            [Description("열려있지않습니다.")]
            NotOpen,
            [Description("쓰기오류")]
            WriteError,
            [Description("읽기오류")]
            ReadError,
            [Description("프레임오류")]
            FrameError,
            [Description("체크섬오류")]
            ChecksumError
        }
        /// 
        /// message frame
        /// 
        public struct sRecvMessage
        {
            /// 
            /// 국번
            /// 
            public string Device;
            /// 
            /// 명령어
            /// 
            public char Command;
            /// 
            /// 명령어타입
            /// 
            public string CmdType;
            /// 
            /// 블록수
            /// 
            public int BlockCount;
            /// 
            /// 데이터갯수
            /// 
            public int DataLen;
            /// 
            /// 데이터
            /// 
            public string Data;
            public string FullString;
            /// 
            /// full message frame
            /// 
            [Description("전체 메세지 영역")]
            public byte[] Buffer;
            /// 
            /// check byte (crc16)
            /// 
            [Description("체크섬 2byte(CRC 16)")]
            public byte[] checksum;
            /// 
            /// checksum error
            /// 
            [Description("체크섬에 오류가 있는지 확인합니다.(true일경우 오류)")]
            public Boolean isCSError;
            [Description("기타메세지")]
            public string Message;
            [Description("정보를 삭제합니다.")]
            public void Clear()
            {
                Message = "NOTSET";
                Data = null;
                Buffer = null;
                checksum = null;
                isCSError = false;
                BlockCount = 0;
                DataLen = 0;
                FullString = string.Empty;
            }
            [Description("응답코드가 NAK인지확인합니다. NAK응답은 컨트롤러로부터 오류가 수신되었음을 의미합니다.")]
            public Boolean isNAK
            {
                get
                {
                    if (Buffer[0] == 0x15) return true;
                    else return false;
                }
            }
            [Description("오류가 있는지 체크합니다. 버퍼가 없거나 체크섬 오류 ,  DLC오류등을 체크 합니다.")]
            public Boolean isError
            {
                get
                {
                    if (Buffer == null || isCSError || BlockCount == 0 || isNAK) return true;
                    else return false;
                }
            }
        }
        public struct sSendMessage
        {
            /// 
            /// 국번
            /// 
            public string Device;
            /// 
            /// 명령어
            /// 
            public char Command;
            /// 
            /// 명령어타입
            /// 
            public string CmdType;
            /// 
            /// 변수길이
            /// 
            public int DeviceLength;
            public int NumberofBlock;
            /// 
            /// 변수명
            /// 
            public string VarName;
            /// 
            /// 데이터갯수
            /// 
            public int DataLen;
            public string Data;
            /// 
            /// full message frame
            /// 
            [Description("전체 메세지 영역")]
            public byte[] Buffer;
            public string Strbuffer;
            /// 
            /// check byte (crc16)
            /// 
            [Description("체크섬 2byte(CRC 16)")]
            public byte[] checksum;
            /// 
            /// checksum error
            /// 
            [Description("체크섬에 오류가 있는지 확인합니다.(true일경우 오류)")]
            public Boolean isCSError;
            [Description("기타메세지")]
            public string Message;
            [Description("정보를 삭제합니다.")]
            public void Clear()
            {
                Data = string.Empty;
                Message = "NOTSET";
                Buffer = null;
                checksum = null;
                isCSError = false;
                DeviceLength = 0;
                NumberofBlock = 0;
                DataLen = 0;
                Strbuffer = string.Empty;
            }
            [Description("오류가 있는지 체크합니다. 버퍼가 없거나 체크섬 오류 ,  DLC오류등을 체크 합니다.")]
            public Boolean isError
            {
                get
                {
                    if (Buffer == null || isCSError || DeviceLength == 0) return true;
                    else return false;
                }
            }
        }
    }
}