45 lines
1.2 KiB
C#
45 lines
1.2 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 RegisterRequest
|
|
{
|
|
private static PDUType PduType = PDUType.REGISTER_REQ;
|
|
|
|
public static String GetInstance(Int64 GatewayISSI)
|
|
{
|
|
StringBuilder sb = new StringBuilder("");
|
|
|
|
// PDU Type (8 bits)
|
|
sb.Append(GetBits((int)PduType, 8));
|
|
|
|
// Gateway ISSI (32 bits)
|
|
sb.Append(GetBits(GatewayISSI, 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)
|
|
{
|
|
String res = GetInstance(GatewayISSI);
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|