private void Forward_NPDU(byte[] buffer, int msg_length, bool ToGlobalBroadcast, Net.IPEndPoint EPsender)
{
// Forms the forwarded NPDU from the original one, and send it to all
// orignal - 4 bytes BVLC - NPDU - APDU
// change to - 10 bytes BVLC - NPDU - APDU
// copy, 6 bytes shifted
byte[] b = new byte[msg_length + 6]; // normaly only 'small' frames are present here, so no need to check if it's to big for Udp
Array.Copy(buffer, 0, b, 6, msg_length);
// 10 bytes for the BVLC Header, with the embedded 6 bytes IP:Port of the original sender
First4BytesHeaderEncode(b, BacnetBvlcFunctions.BVLC_FORWARDED_NPDU, msg_length + 6);
BacnetAddress BacSender;
BacnetIpUdpProtocolTransport.Convert(EPsender, out BacSender); // to embbed in the forward BVLC header
for (int i = 0; i < BacSender.adr.Length; i++)
{
b[4 + i] = BacSender.adr[i];
}
// To BBMD
SendToBBMDs(b, msg_length + 6);
// To FD, except the sender
SendToFDs(b, msg_length + 6, EPsender);
// Broadcast if required
if (ToGlobalBroadcast == true)
{
MyBBMDTransport.Send(b, msg_length + 6, new Net.IPEndPoint(Net.IPAddress.Parse(BroadcastAdd), MyBBMDTransport.SharedPort));
}
}