53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
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 GroupMonitorExtRequest
|
|
{
|
|
private static PDUType PduType = PDUType.GROUP_MONITOR_EXT_REQ;
|
|
|
|
public static String GetInstance(Int64 gatewayISSI, List<Int64> groupIds)
|
|
{
|
|
StringBuilder sb = new StringBuilder("");
|
|
|
|
// PDU Type (8 bits)
|
|
sb.Append(GetBits((int)PduType, 8));
|
|
|
|
// gateway ISSI (32 bits)
|
|
sb.Append(GetBits(gatewayISSI, 32));
|
|
|
|
// number of monitored groups, up to 255 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, List<Int64> groupIds)
|
|
{
|
|
String res = GetInstance(gatewayISSI, 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;
|
|
}
|
|
|
|
}
|
|
}
|