123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Log;
- using MECF.Framework.Common.Communications;
- using MECF.Framework.Common.Utilities;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFs.TruPlasmaRF
- {
- //TruPlasma RF 1001 to 1003
- public abstract class TruPlasmaRF1001Handler : HandlerBase
- {
- public TruPlasmaRF1001 Device { get; }
- public string _command;
- protected string _parameter;
- protected TruPlasmaRF1001Handler(TruPlasmaRF1001 device, string cmd):base("")
- {
- Device = device;
- Name = _command = cmd;
- }
- protected TruPlasmaRF1001Handler(TruPlasmaRF1001 device, string command, string parameter = null)
- : base(BuildMessage(ToByteArray(command), ToByteArray(parameter)))
- {
- Device = device;
- _command = command;
- _parameter = parameter;
- Name = command;
- }
- protected TruPlasmaRF1001Handler(TruPlasmaRF1001 device, string command, byte[] parameter)
- : base(BuildMessage(ToByteArray(command), parameter))
- {
- Device = device;
- _command = command;
- //_parameter = parameter;
- Name = command;
- }
- private static byte _start = 0xAA;
- private static byte _address = 0x02;
- private static byte _GS = 0x00;
- private static byte _stop = 0x55;
- protected static byte[] BuildMessage(byte[] commandArray, byte[] argumentArray)
- {
- List<byte> buffer = new List<byte>();
- buffer.Add(_start);
- buffer.Add(_address);
- int length = 1 + (commandArray != null ? commandArray.Length : 0) + (argumentArray != null ? argumentArray.Length : 0);
- buffer.Add((byte)length);
- buffer.Add(_GS);
- if (commandArray != null && commandArray.Length > 0)
- {
- //skip ManualExecuteCommand
- if (!(commandArray.Length == 1 && commandArray[0] == 0))
- {
- buffer.AddRange(commandArray);
- }
- }
- if (argumentArray != null && argumentArray.Length > 0)
- {
- buffer.AddRange(argumentArray);
- }
- //var checkSum = Crc16.CRC16_CCITT(contentBuffer);
- var checkSum = Crc16.Crc16Ccitt(buffer.ToArray());
- buffer.AddRange(BitConverter.GetBytes(checkSum));
- buffer.Add(_stop);
- return buffer.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
- {
- transactionComplete = false;
- TruPlasmaRF1001Message response = msg as TruPlasmaRF1001Message;
- ResponseMessage = msg;
- if (response.IsError)
- {
- Device.NoteError(response.ErrorCode);
- }
- else
- {
- Device.NoteError(null);
- }
- if (response.IsAck)
- {
- SetState(EnumHandlerState.Acked);
- }
- if (this.IsAcked && response.IsComplete)
- {
- if (response == null || response.RawMessage == null) return false;
- ushort checkSum_calc = Crc16.Crc16Ccitt(response.RawMessage.Take(response.RawMessage.Length - 3).ToArray());
- ushort checkSum = BitConverter.ToUInt16(response.RawMessage, response.RawMessage.Length - 3);
- if (checkSum_calc != checkSum)
- {
- LOG.Warning($"{this.Device.Address} received wrong checksum");
- return false;
- }
- if (response.Command == _command)
- {
- SetState(EnumHandlerState.Completed);
- transactionComplete = true;
- return true;
- }
- else
- Device.NoteError($"command mismatch set command={_command} response command={response.Command}");
- }
- return false;
- }
- protected static byte[] ToByteArray(string parameter)
- {
- if (parameter == null)
- return new byte[] { };
- return parameter.Split(',').Select(para => Convert.ToByte(para, 16)).ToArray();
- }
- }
- public class TruPlasmaRF1001RawCommandHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001RawCommandHandler(TruPlasmaRF1001 device, string command, string parameter = null)
- : base(device, command, parameter)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001GetControlHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001GetControlHandler(TruPlasmaRF1001 device)
- : base(device, "05,01,00,00", "FF")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteInterfaceActived(true);
- }
- return true;
- }
- }
- public class TruPlasmaRF1001ReleaseControlHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReleaseControlHandler(TruPlasmaRF1001 device)
- : base(device, "05,02,00,00", "FF")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteInterfaceActived(false);
- }
- return true;
- }
- }
- //active RS232
- public class TruPlasmaRF1001SetActiveInterfaceHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//SINT32
- public TruPlasmaRF1001SetActiveInterfaceHandler(TruPlasmaRF1001 device)
- : base(device, "02,52,01,01", IntToByteArray(1))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- }
- return true;
- }
- }
- //Pi=forward power
- public class TruPlasmaRF1001PreSetPiValueHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//SINT32
- public TruPlasmaRF1001PreSetPiValueHandler(TruPlasmaRF1001 device, int piValue)
- : base(device, "02,06,00,01", IntToByteArray(piValue))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- //Pi=forward power
- public class TruPlasmaRF1001ReadPiValueHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReadPiValueHandler(TruPlasmaRF1001 device)
- : base(device, "01,12,00,01", "FF")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- if (result.Data != null && result.Data.Length == 4)
- {
- Device.ForwardPower = BitConverter.ToInt32(result.Data, 0);
- }
- }
- return true;
- }
- }
- //Pr=Reflected power
- public class TruPlasmaRF1001ReadPrValueHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReadPrValueHandler(TruPlasmaRF1001 device)
- : base(device, "01,14,00,01", "FF")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- if (result.Data != null && result.Data.Length == 4)
- {
- Device.ReflectPower = BitConverter.ToInt32(result.Data, 0);
- }
- }
- return true;
- }
- }
- public class TruPlasmaRF1001ReadProcessStatusHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReadProcessStatusHandler(TruPlasmaRF1001 device)
- : base(device, "01,75,00,01", "FF")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- if (result.Data != null && result.Data.Length == 4)
- {
- //0x00000010 = Power output on
- //0x00000080 = Alarm pending
- //0x00008000 = Temperature alarm pending
- var status = BitConverter.ToUInt32(result.Data, 0);
- Device.IsPowerOn = (status & 0x00000010) > 0;
- Device.IsError = (status & 0x00000080) > 0 || (status & 0x00008000) > 0;
- }
- }
- return true;
- }
- }
- public class TruPlasmaRF1001SetPowerOnOffHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x07;//UINT32
- public TruPlasmaRF1001SetPowerOnOffHandler(TruPlasmaRF1001 device, bool isOn)
- : base(device, "02,6F,00,01", IntToByteArray(isOn ? 1 : 0))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes((uint)num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001ReadPowerOnOffHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReadPowerOnOffHandler(TruPlasmaRF1001 device)
- : base(device, "01,6F,00,01", "FF")
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- byte[] bytes = BitConverter.GetBytes(num);
- return bytes;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- if (result.Data != null && result.Data.Length == 4)
- {
- Device.IsPowerOn = BitConverter.ToUInt32(result.Data, 0) > 0;
- }
- }
- return true;
- }
- }
- public class TruPlasmaRF1001SetPulseModeHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001SetPulseModeHandler(TruPlasmaRF1001 device, EnumRfPowerWorkMode pulseMode)
- : base(device, "02,6A,01,01", IntToByteArray(pulseMode == EnumRfPowerWorkMode.PulsingMode ? 1 : 0))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001ReadPulseModeHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReadPulseModeHandler(TruPlasmaRF1001 device)
- : base(device, "01,6A,01,01", "FF")
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- byte[] bytes = BitConverter.GetBytes(num);
- return bytes;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- if (result.Data != null && result.Data.Length == 4)
- {
- Device.WorkMode = BitConverter.ToInt32(result.Data, 0) == 1 ? EnumRfPowerWorkMode.PulsingMode : EnumRfPowerWorkMode.ContinuousWaveMode;
- }
- }
- return true;
- }
- }
- public class TruPlasmaRF1001SetClockOffsetModeHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001SetClockOffsetModeHandler(TruPlasmaRF1001 device, bool isFrequencyOffset)
- : base(device, "02,04,02,01", IntToByteArray(isFrequencyOffset ? 1 : 0))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- // Tuning start offset
- public class TruPlasmaRF1001TuningOffsetHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001TuningOffsetHandler(TruPlasmaRF1001 device, int tuningOffset)
- : base(device, "02,46,02,01")
- {
- List<byte> offset = new List<byte>() { _STAT, _TYP };
- offset.AddRange(BitConverter.GetBytes(tuningOffset));
- SendBinary = BuildMessage(ToByteArray(_command), offset.ToArray());
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- // Tuning delay
- public class TruPlasmaRF1001TuningDelayHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001TuningDelayHandler(TruPlasmaRF1001 device, int delay)
- : base(device, "02,49,02,01")
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(delay));
- SendBinary = BuildMessage(ToByteArray(_command), tmp.ToArray());
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001SetFreqHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- //unit is Hz
- //the colck offset ode must be set to FrequencyOffset
- public TruPlasmaRF1001SetFreqHandler(TruPlasmaRF1001 device, int freq)
- : base(device, "02,C9,01,01", IntToByteArray(freq))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- //457
- public class TruPlasmaRF1001ReadFreqOffsetHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReadFreqOffsetHandler(TruPlasmaRF1001 device)
- : base(device, "01,C9,01,01", "FF")
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- byte[] bytes = BitConverter.GetBytes(num);
- return bytes;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- if (result.Data != null && result.Data.Length == 4)
- {
- Device.Frequency = BitConverter.ToInt32(result.Data, 0) / 1000;//unit kHz
- }
- }
- return true;
- }
- }
- //519
- public class TruPlasmaRF1001ReadActualFreqHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReadActualFreqHandler(TruPlasmaRF1001 device)
- : base(device, "01,07,02,01", "FF")
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- byte[] bytes = BitConverter.GetBytes(num);
- return bytes;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- if (result.Data != null && result.Data.Length == 4)
- {
- Device.Frequency = BitConverter.ToInt32(result.Data, 0);//unit kHz
- }
- }
- return true;
- }
- }
- public class TruPlasmaRF1001SetClockModeHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- //0=Phase offset;1=Frequency offset;2=Frequency agility
- public TruPlasmaRF1001SetClockModeHandler(TruPlasmaRF1001 device, EnumRfPowerClockMode clockMode)
- : base(device, "02,04,02,01", IntToByteArray(GetValue(clockMode)))
- {
- }
- private static int GetValue(EnumRfPowerClockMode clockMode)
- {
- if (clockMode == EnumRfPowerClockMode.FreqAuto)
- return 2;
- if (clockMode == EnumRfPowerClockMode.FreqManual)
- return 1;
- return 0;
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001ReadClockModeHandler : TruPlasmaRF1001Handler
- {
- public TruPlasmaRF1001ReadClockModeHandler(TruPlasmaRF1001 device)
- : base(device, "01,04,02,01", "FF")
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- byte[] bytes = BitConverter.GetBytes(num);
- return bytes;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- if (result.Data != null && result.Data.Length == 4)
- {
- Device.ClockMode = GetMode(BitConverter.ToInt32(result.Data, 0));
- }
- }
- return true;
- }
- private EnumRfPowerClockMode GetMode(int mode)
- {
- if (mode == 2)
- return EnumRfPowerClockMode.FreqAuto;
- if (mode == 1)
- return EnumRfPowerClockMode.FreqManual;
- return EnumRfPowerClockMode.Phase;
- }
- }
- public class TruPlasmaRF1001SetGainHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001SetGainHandler(TruPlasmaRF1001 device, int gain)
- : base(device, "02,4C,02,01", IntToByteArray(gain))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001SetRelativeGainHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001SetRelativeGainHandler(TruPlasmaRF1001 device, int gain)
- : base(device, "02,4D,02,01", IntToByteArray(gain))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001SetModulationDeviationHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001SetModulationDeviationHandler(TruPlasmaRF1001 device, int deviation)
- : base(device, "02,4E,02,01", IntToByteArray(deviation))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001SetRelativeModulationDeviationHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001SetRelativeModulationDeviationHandler(TruPlasmaRF1001 device, int deviation)
- : base(device, "02,4F,02,01", IntToByteArray(deviation))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as TruPlasmaRF1001Message;
- Device.NoteRawCommandInfo(_command, string.Join(",", result.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
- }
- return true;
- }
- }
- public class TruPlasmaRF1001ResetHandler : TruPlasmaRF1001Handler
- {
- private static byte _STAT = 0x00;//No error, data follows.
- private static byte _TYP = 0x04;//INT32
- public TruPlasmaRF1001ResetHandler(TruPlasmaRF1001 device)
- : base(device, "02,4D,00,01", IntToByteArray(0xAA))
- {
- }
- private static byte[] IntToByteArray(int num)
- {
- List<byte> tmp = new List<byte>() { _STAT, _TYP };
- tmp.AddRange(BitConverter.GetBytes(num));
- return tmp.ToArray();
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- }
- return true;
- }
- }
- }
|