SafeDispatch/LibrarySDR/Requests/LifeSignRequest.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2024-02-22 16:43:59 +00:00
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 LifeSignRequest
{
private static PDUType PduType = PDUType.LIFE_SIGN_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;
}
}
}