HamBook – Rev 21

Subversion Repositories:
Rev:
using Org.BouncyCastle.Crypto.Tls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HamBook.Radios.Generic
{
    public class MemoryRadioMode
    {
        public char Mode { get; set; }

        public MemoryRadioMode(string mode) : this()
        {
            Mode = Parse(mode);
        }

        public MemoryRadioMode(char mode) : this()
        {
            Mode = Parse(mode);
        }

        public MemoryRadioMode()
        {

        }

        public static bool TryParse(string mode, out MemoryRadioMode memoryRadioMode)
        {
            switch (mode)
            {

                case "LSB":
                case "USB":
                case "CW":
                case "FM":
                case "AM":
                case "RTTY-LSB":
                case "CW-R":
                case "DATA-LSB":
                case "RTTY-USB":
                case "FM-N":
                case "DATA-USB":
                case "AM-N":
                    memoryRadioMode = new MemoryRadioMode(mode);
                    return true;
                default:
                    memoryRadioMode = null;
                    return false;
            }
        }

        public static bool TryParse(char mode, out MemoryRadioMode memoryRadioMode)
        {
            switch (mode)
            {
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                case 'B':
                case 'C':
                case 'D':
                    memoryRadioMode = new MemoryRadioMode(mode);
                    return true;
                default:
                    memoryRadioMode = null;
                    return false;
            }
        }

        private char Parse(string mode)
        {
            switch (mode)
            {
                case "LSB":
                    return '1';
                case "USB":
                    return '2';
                case "CW":
                    return '3';
                case "FM":
                    return '4';
                case "AM":
                    return '5';
                case "RTTY-LSB":
                    return '6';
                case "CW-R":
                    return '7';
                case "DATA-LSB":
                    return '8';
                case "RTTY-USB":
                    return '9';
                case "FM-N":
                    return 'B';
                case "DATA-USB":
                    return 'C';
                case "AM-N":
                    return 'D';
                default:
                    throw new ArgumentException();
            }
        }

        private char Parse(char mode)
        {
            switch (mode)
            {
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                case 'B':
                case 'C':
                case 'D':
                    return mode;
                default:
                    throw new ArgumentException();
            }
        }

        public static implicit operator MemoryRadioMode(string mode)
        {
            return new MemoryRadioMode(mode);
        }

        public static implicit operator string(MemoryRadioMode memoryRadioMode)
        {
            switch (memoryRadioMode.Mode)
            {
                case '1':
                    return "LSB";
                case '2':
                    return "USB";
                case '3':
                    return "CW";
                case '4':
                    return "FM";
                case '5':
                    return "AM";
                case '6':
                    return "RTTY-USB";
                case '7':
                    return "CW-R";
                case '8':
                    return "DATA-LSB";
                case '9':
                    return "RTTY-USB";
                case 'B':
                    return "FM-N";
                case 'C':
                    return "DATA-USB";
                case 'D':
                    return "AM-N";
                default:
                    throw new ArgumentException();
            }
        }

        public static implicit operator MemoryRadioMode(char mode)
        {
            return new MemoryRadioMode(mode);
        }

        public static implicit operator char(MemoryRadioMode memoryRadioMode)
        {
            return memoryRadioMode.Mode;
        }
    }
}