using LibrarySDR.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static LibrarySDR.Helpers.BinaryHexHelper; namespace LibrarySDR.Requests { public class GroupMonitorRequest { private static PDUType PduType = PDUType.GROUP_MONITOR_REQ; public static String GetInstance(Int64 gatewayISSI, bool shouldMonitor, List groupIds) { StringBuilder sb = new StringBuilder(""); // PDU Type (8 bits) sb.Append(GetBits((int)PduType, 8)); // gateway ISSI (32 bits) sb.Append(GetBits(gatewayISSI, 32)); // Monitor (8 bits) sb.Append(GetBits(shouldMonitor ? 1 : 0, 8)); // number of monitored groups, up to 5 groups (16 bits) sb.Append(GetBits(groupIds.Count, 16)); // add each group id to the list foreach(Int64 groupId in groupIds) sb.Append(GetBits(groupId, 32)); // get the header with the length String header = Header.GetHeaderBinary(sb.ToString().Length / 8); // add header in front of the request return BinaryStringToHexString($"{header}{sb.ToString()}", Padding.RIGHT); } public static byte[] GetBytes(Int64 gatewayISSI, bool shouldMonitor, List groupIds) { String res = GetInstance(gatewayISSI, shouldMonitor, groupIds); byte[] response = new byte[res.Length / 2]; for (int i = 0; i < res.Length / 2; i++) response[i] = (byte)Convert.ToInt16(res.Substring(i * 2, 2), 16); return response; } } }