Hamlib/README.multicast

188 wiersze
5.6 KiB
Plaintext
Czysty Zwykły widok Historia

Planned for version 4.3 -- comments/suggestions about this are more than welcome
Multicast UDP broadcast on port 4531 (one below rigctld 4532)
Bidirectional rig control and status
Choice of token pairs or JSON
All packets will be tagged with ID=[unique name] -- so multiple rigs can broadcast/rx on the same port
Broadcast packet contents to be based on get_rig_info output
This will be the text format of name=value pairs
Can be multiple VFO lines
Parsers should allow for unknown tags that may be added in the future
Rig command: \get_rig_info
Rig command: \get_rig_info
VFO=Main Freq=145000000 Mode=None Width=0 RX=1 TX=1
VFO=VFOB Freq=145000000 Mode=FM Width=15000 RX=0 TX=0
Split=0 SatMode=0
PTT=1 (1=On, 0=Off)
Rig=Dummy (name of connected rig)
App=Hamlib (name of application providing the packet)
Version=20210429 1.0.0 (version YYYYMMDD)
Status=OK (possible values OK, Offline, Error)
ErrorMsg=msg text (pipe delimited multi-line error message)
CRC=0xf49f4708 (this is just an example CRC and not accurate for this example)
Example JSON
{
2021-05-18 13:58:21 +00:00
"__comment1__": "customizable rig identification -- will allow multiple rigs to be on the multicast",
"ID": "Rig#1",
"VFOs": [
2021-05-18 13:58:21 +00:00
{
"Name": "VFOA",
2021-05-18 13:58:21 +00:00
"Freq": 14074000,
"Mode": "USB",
2021-05-18 13:58:21 +00:00
"Width": 5000,
"RX": true,
"TX": false
},
2021-05-18 13:58:21 +00:00
{
"Name": "VFOB",
"Freq": 14076000,
"Mode": "USB",
"Width": 5000,
"RX": false,
"TX": false
2021-05-18 13:58:21 +00:00
}],
"__comment_spectra__": "Rigs that have spectrum output may include this array data",
"Spectra": [
{
"Name": "Main",
"Length": 475,
"__comment_spectrum_data__": "2-char hex bytes so data len=2*Length",
"Data": "00AAFF75BD2AAA...",
"Type": "FIXED|CENTER",
"MinLevel": 0,
"MaxLevel": 140,
"MinStrength": -100,
"MaxStrength": 0,
"__comment_spectrum_center__": "If Type=CENTER, the following fields will be present:",
"CenterFreq": 14267000,
"Span": 25000,
"__comment_spectrum_fixed__": "If SpectrumType=FIXED, the following fields will be present:",
"LowFreq": 14000000,
"HighFreq": 14250000
},
{
"Name": "Sub",
"Length": 475,
"__comment_spectrum_data__": "2-char hex bytes so data len=2*Length",
"Data": "00AAFF75BD2AAA...",
"Type": "FIXED|CENTER",
"MinLevel": 0,
"MaxLevel": 140,
"MinStrength": -100,
"MaxStrength": 0,
"__comment_spectrum_center__": "If Type=CENTER, the following fields will be present:",
"CenterFreq": 14267000,
"Span": 25000,
"__comment_spectrum_fixed__": "If SpectrumType=FIXED, the following fields will be present:",
"LowFreq": 14000000,
"HighFreq": 14250000
}],
LastCommand {
"ID": "MyApp 123",
"Command": "set_freq VFOA 14074000".
"Status": "OK"
},
"PTT" : false,
"Split": true,
"SatMode": false,
"Rig": "Dummy",
"App": "Hamlib",
"__comment_version__": "protocol version YYYYMMDD x.x.x, 1.0.0 will be used when this is implemented",
"Version": "20210521 0.0.0",
"Status": "OK";
2021-05-18 13:58:21 +00:00
"__comment_seq__": "Seq is 1-up sequence number 32-bit -- wraps around to 1 from 2^32-1",
"Seq": 1,
"__comment_crc__": "32-bit CRC of entire JSON record replacing the CRC value with 0x00000000",
"ErrorMsg": "OK",
"CRC": "0x00000000"
}
Will be able to set freq, mode, width, ptt, satmode, and split to start since those are common to many apps.
More functions will be added as time goes on.
C# Json Deserialize Example -- beginning of a HamlibMultiCast client
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
namespace HamlibMultiCast
{
public class HamlibMulticastClient
{
public class VFO
{
public string Name;
public ulong Freq;
public string Mode;
public int Width;
public bool RX;
public bool TX;
}
public class SpectrumClass
{
public int Length;
public string Data;
public string Type;
public int MinLevel;
public int MaxLevel;
public int MinStrength;
public int MaxStrength;
public double CenterFreq;
public int Span;
public double LowFreq;
public double HighFreq;
}
LastCommand {
public string ID; // an application name plus sequence number recommended
public string Command;
public string Status;
}
public string ID;
public List<VFO> VFOs { get; set; }
public bool PTT;
public bool Split;
public bool SatMode;
public string Rig;
public string App;
public string Version;
public string Status;
public UInt32 Seq;
public string CRC;
public SpectrumClass Spectrum { get; set; }
public string ErrorMsg;
}
class Program
{
static int Main(string[] args)
{
Console.WriteLine("HamlibMultiCast Test Json Deserialize");
ITraceWriter traceWriter = new MemoryTraceWriter();
try
{
string json = File.ReadAllText("test.json");
var client = JsonConvert.DeserializeObject<HamlibMulticastClient>(json, new JsonSerializerSettings { TraceWriter = traceWriter, Converters = { new JavaScriptDateTimeConverter() } });
Console.WriteLine(traceWriter);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return 1;
}
return 0;
}
}
}