public void ReceivedIAm(BacNetRawMessage msg, IPEndPoint endPoint)
{
BacNetRemoteDevice newDevice = new BacNetRemoteDevice();
newDevice.EndPoint = endPoint;
BacNetIpNpdu npdu;
IAm apdu;
try
{
npdu = new BacNetIpNpdu(msg.Npdu);
apdu = new IAm(msg.Apdu);
}
catch (Exception ex)
{
_logger.WarnException("Received malformed I-am", ex);
return;
}
if (npdu.Source != null)
newDevice.BacAddress = npdu.Source;
newDevice.MaxApduLength = apdu.MaxApduLength;
newDevice.InstanceNumber = apdu.deviceObject.ObjectId;
newDevice.Segmentation = apdu.SegmentationSupported;
newDevice.VendorId = apdu.VendorId;
if (newDevice.InstanceNumber == BacNetDevice.Instance.DeviceId)
return;
BacNetRemoteDevice rem =
BacNetDevice.Instance.Remote.FirstOrDefault(s => s.InstanceNumber == newDevice.InstanceNumber);
if (rem != null)
BacNetDevice.Instance.Remote.Remove(rem);
BacNetDevice.Instance.Remote.Add(newDevice);
}