refactor TSBK classes to be more streamlined

4.32j_maint
firealarmss 11 months ago
parent 2188db063a
commit 3679b1b8cd

@ -27,6 +27,8 @@ namespace fnecore.P25.LC
protected byte Lco;
protected byte MfId;
protected internal byte[] Payload = new byte[P25Defines.P25_TSBK_LENGTH_BYTES - 4];
/// <summary>
/// Creates an instance of <see cref="TSBKBase"/>
/// </summary>
@ -42,7 +44,7 @@ namespace fnecore.P25.LC
/// <param name="payload"></param>
/// <param name="rawTSBK"></param>
/// <returns></returns>
public virtual bool Decode(byte[] data, ref byte[] payload, bool rawTSBK)
public virtual bool Decode(byte[] data, bool rawTSBK)
{
byte[] tsbk = new byte[P25Defines.P25_TSBK_LENGTH_BYTES];
FneUtils.Memset(tsbk, 0x00, tsbk.Length);
@ -83,7 +85,7 @@ namespace fnecore.P25.LC
LastBlock = (tsbk[0] & 0x80) == 0x80; // Last Block Marker
MfId = tsbk[1]; // Manufacturer ID
Array.Copy(tsbk, 1, payload, 0, P25Defines.P25_TSBK_LENGTH_BYTES - 4);
Array.Copy(tsbk, 1, Payload, 0, Payload.Length);
return true;
}
@ -95,13 +97,13 @@ namespace fnecore.P25.LC
/// <param name="payload"></param>
/// <param name="rawTSBK"></param>
/// <param name="noTrellis"></param>
public virtual void Encode(ref byte[] data, ref byte[] payload, bool rawTSBK, bool noTrellis)
public virtual void Encode(ref byte[] data, bool rawTSBK, bool noTrellis)
{
byte[] tsbk = new byte[P25Defines.P25_TSBK_LENGTH_BYTES];
FneUtils.Memset(tsbk, 0x00, tsbk.Length);
Array.Copy(payload, 0, tsbk, 2, P25Defines.P25_TSBK_LENGTH_BYTES - 4);
Array.Copy(Payload, 0, tsbk, 2, Payload.Length);
tsbk[0] = Lco; // LCO
tsbk[0] |= LastBlock ? (byte)0x80 : (byte)0x00; // Last Block Marker

@ -48,22 +48,18 @@ namespace fnecore.P25.LC.TSBK
/// <param name="data"></param>
/// <param name="rawTSBK"></param>
/// <returns></returns>
public bool Decode(byte[] data, bool rawTSBK)
public override bool Decode(byte[] data, bool rawTSBK = true)
{
byte[] tsbk = new byte[P25Defines.P25_TSBK_LENGTH_BYTES];
FneUtils.Memset(tsbk, 0x00, tsbk.Length);
bool ret = base.Decode(data, ref tsbk, rawTSBK);
if (!ret)
if (!base.Decode(data, rawTSBK))
return false;
ulong tsbkValue = FneUtils.ToUInt64(tsbk, 0);
ulong tsbkValue = FneUtils.ToUInt64(Payload, 0);
Aiv = ((tsbkValue >> 56) & 0x80U) == 0x80U; // Additional Info Flag
Service = (byte)((tsbkValue >> 56) & 0x3FU); // Service Type
DstId = FneUtils.Bytes3ToUInt32(tsbk, 3); // Target Radio Address
SrcId = FneUtils.Bytes3ToUInt32(tsbk, 0); // Source Radio Address
DstId = FneUtils.Bytes3ToUInt32(Payload, 3); // Target Radio Address
SrcId = FneUtils.Bytes3ToUInt32(Payload, 0); // Source Radio Address
return true;
}
@ -75,7 +71,7 @@ namespace fnecore.P25.LC.TSBK
/// <param name="payload"></param>
/// <param name="rawTSBK"></param>
/// <param name="noTrellis"></param>
public override void Encode(ref byte[] data, ref byte[] payload, bool rawTSBK, bool noTrellis)
public override void Encode(ref byte[] data, bool rawTSBK = true, bool noTrellis = true)
{
ulong tsbkValue = 0;
@ -95,10 +91,10 @@ namespace fnecore.P25.LC.TSBK
tsbkValue = (tsbkValue << 24) + SrcId; // Source Radio Address
FneUtils.Memset(payload, 0x00, payload.Length);
FneUtils.WriteBytes(tsbkValue, ref payload, 0);
FneUtils.Memset(Payload, 0x00, Payload.Length);
FneUtils.WriteBytes(tsbkValue, ref Payload, 0);
base.Encode(ref data, ref payload, rawTSBK, noTrellis);
base.Encode(ref data, rawTSBK, noTrellis);
}
} // public class IOSP_ACK_RSP
} // namespace fnecore.P25.LC.TSBK

@ -39,17 +39,13 @@ namespace fnecore.P25.LC.TSBK
/// <param name="data"></param>
/// <param name="rawTSBK"></param>
/// <returns></returns>
public bool Decode(byte[] data, bool rawTSBK)
public override bool Decode(byte[] data, bool rawTSBK = true)
{
byte[] tsbk = new byte[P25Defines.P25_TSBK_LENGTH_BYTES];
FneUtils.Memset(tsbk, 0x00, tsbk.Length);
bool ret = base.Decode(data, ref tsbk, rawTSBK);
if (!ret)
if (!base.Decode(data, rawTSBK))
return false;
DstId = FneUtils.Bytes3ToUInt32(tsbk, 3); // Target Radio Address
SrcId = FneUtils.Bytes3ToUInt32(tsbk, 0); // Source Radio Address
DstId = FneUtils.Bytes3ToUInt32(Payload, 3); // Target Radio Address
SrcId = FneUtils.Bytes3ToUInt32(Payload, 0); // Source Radio Address
return true;
}
@ -61,16 +57,16 @@ namespace fnecore.P25.LC.TSBK
/// <param name="payload"></param>
/// <param name="rawTSBK"></param>
/// <param name="noTrellis"></param>
public override void Encode(ref byte[] data, ref byte[] payload, bool rawTSBK, bool noTrellis)
public override void Encode(ref byte[] data, bool rawTSBK = true, bool noTrellis = true)
{
ulong tsbkValue = 0;
tsbkValue = (tsbkValue << 40) + DstId; // Target Radio Address
tsbkValue = (tsbkValue << 24) + SrcId; // Source Radio Address
tsbkValue = (tsbkValue << 40) + DstId; // Target Radio Address
tsbkValue = (tsbkValue << 24) + SrcId; // Source Radio Address
FneUtils.Memset(payload, 0x00, payload.Length);
FneUtils.WriteBytes(tsbkValue, ref payload, 0);
FneUtils.Memset(Payload, 0x00, Payload.Length);
FneUtils.WriteBytes(tsbkValue, ref Payload, 0);
base.Encode(ref data, ref payload, rawTSBK, noTrellis);
base.Encode(ref data, rawTSBK, noTrellis);
}
} // public class IOSP_CALL_ALRT
} // namespace fnecore.P25.LC.TSBK

@ -42,16 +42,12 @@ namespace fnecore.P25.LC.TSBK
/// <param name="data"></param>
/// <param name="rawTSBK"></param>
/// <returns></returns>
public bool Decode(byte[] data, bool rawTSBK)
public override bool Decode(byte[] data, bool rawTSBK = true)
{
byte[] tsbk = new byte[P25Defines.P25_TSBK_LENGTH_BYTES];
FneUtils.Memset(tsbk, 0x00, tsbk.Length);
bool ret = base.Decode(data, ref tsbk, rawTSBK);
if (!ret)
if (!base.Decode(data, rawTSBK))
return false;
ulong tsbkValue = FneUtils.ToUInt64(tsbk, 0);
ulong tsbkValue = FneUtils.ToUInt64(Payload, 0);
ExtendedFunction = (ushort)((tsbkValue >> 48) & 0xFFFF); // Extended Function
SrcId = (uint)((tsbkValue >> 24) & 0xFFFFFF); // Argument
@ -67,18 +63,18 @@ namespace fnecore.P25.LC.TSBK
/// <param name="payload"></param>
/// <param name="rawTSBK"></param>
/// <param name="noTrellis"></param>
public override void Encode(ref byte[] data, ref byte[] payload, bool rawTSBK, bool noTrellis)
public override void Encode(ref byte[] data, bool rawTSBK = true, bool noTrellis = true)
{
ulong tsbkValue = 0;
tsbkValue = (tsbkValue << 16) + ExtendedFunction; // Extended Function
tsbkValue = (tsbkValue << 24) + SrcId; // Argument
tsbkValue = (tsbkValue << 24) + DstId; // Target Radio Address
tsbkValue = (tsbkValue << 16) | ExtendedFunction; // Extended Function
tsbkValue = (tsbkValue << 24) | SrcId; // Argument
tsbkValue = (tsbkValue << 24) | DstId; // Target Radio Address
FneUtils.Memset(payload, 0x00, payload.Length);
FneUtils.WriteBytes(tsbkValue, ref payload, 0);
FneUtils.Memset(Payload, 0x00, Payload.Length);
FneUtils.WriteBytes(tsbkValue, ref Payload, 0);
base.Encode(ref data, ref payload, rawTSBK, noTrellis);
base.Encode(ref data, rawTSBK, noTrellis);
}
} // public class IOSP_EXT_FNCT
} // namespace fnecore.P25.LC.TSBK

Loading…
Cancel
Save

Powered by TurnKey Linux.