HamBook – Rev 46
?pathlinks?
using HamBook.Radios.Generic;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static HamBook.Radios.Yaesu.FT_891.Constants;
using RJCP.IO.Ports;
namespace HamBook.Radios.Yaesu.FT_891.CAT
{
[Radio("Yaesu FT-891")]
public class IF : Generic.CAT.IF
{
public override CatLength CatLength => new CatLength { Answer = 28, Read = 3 };
public IF(SerialPortStream serialPort) : base(serialPort)
{
}
public override Information Read()
{
SerialPort.Write($"{Name}{Constants.EOT}");
var buffer = new byte[CatLength.Answer];
if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer)
{
throw new UnexpectedRadioResponseException(Name, buffer);
}
var answer = Constants.Encoding.GetString(buffer);
var match = InformationRegex.Match(answer);
if (!match.Success)
{
throw new UnmatchedRadioResponseException(Name, answer);
}
var radioBank = int.Parse(match.Result("${radioBank}"));
var Frequency = int.Parse(match.Result("${frequency}"));
var clarifierDirection = char.Parse(match.Result("${clarifierDirection}"));
var clarifierOffset = int.Parse(match.Result("${clarifierOffset}"));
var clar = int.Parse(match.Result("${clar}")) == 0 ? false : true;
var radioMode = char.Parse(match.Result("${mode}"));
var storage = match.Result("${storage}");
var ctcss = match.Result("${ctcssMode}");
var phase = match.Result("${phase}");
var information = new Information
{
RadioBank = radioBank,
Frequency = Frequency,
ClarifierDirection = clarifierDirection,
ClarifierOffset = clarifierOffset,
Clar = clar,
RadioMode = new RadioMode(radioMode),
Storage = storage,
Ctcss = new Ctcss(ctcss),
Phase = new Phase(phase)
};
return information;
}
}
}