SafeDispatch/LibrarySDR/Responses/GroupMonitorExtResponse.cs

67 lines
2.5 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using LibrarySDR.Enums;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static LibrarySDR.Helpers.BinaryHexHelper;
namespace LibrarySDR.Responses
{
public class GroupMonitorExtResponse
{
public PDUType PduType => PDUType.GROUP_MONITOR_EXT_RESP;
private Int64 hostISSI;
public Int64 HostISSI { get { return hostISSI; } }
private Dictionary<Int64, GroupMonitorExtResult> groupsResult = new Dictionary<long, GroupMonitorExtResult>();
public Dictionary<Int64, GroupMonitorExtResult> GroupsResult { get { return groupsResult; } }
public GroupMonitorExtResponse(String hexResponsePayload)
{
String resp = hexResponsePayload;
int i = 0;
int prevIdx = 0;
// get host SSI (32 bits = 4 byte = 8 hex characters)
String hex = LittleToBigEndianHexString(resp.Substring(i = i + prevIdx, prevIdx = 4 * 2));
Int64.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hostISSI);
Int32 length = 0;
// get length (16 bits = 2 byte = 16 hex characters)
hex = LittleToBigEndianHexString(resp.Substring(i = i + prevIdx, prevIdx = 2 * 2));
Int32.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out length);
for (int j = 0; j < length; j++)
{
Int64 groupSSI = 0;
hex = LittleToBigEndianHexString(resp.Substring(i = i + prevIdx, prevIdx = 4 * 2));
Int64.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out groupSSI);
Int16 result = 0;
hex = LittleToBigEndianHexString(resp.Substring(i = i + prevIdx, prevIdx = 1 * 2));
Int16.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result);
if (groupsResult.ContainsKey(groupSSI))
groupsResult.Remove(groupSSI);
groupsResult.Add(groupSSI, (GroupMonitorExtResult)result);
}
}
public override String ToString()
{
String groupsState = "";
foreach (KeyValuePair<Int64, GroupMonitorExtResult> kvp in groupsResult)
groupsState += $"[{kvp.Key},{kvp.Value}],";
return $"Host ISSI : {HostISSI} | Groups Size : {groupsResult.Count} | GroupState : {groupsState}";
}
}
}