/// <summary> /// Checks whether it's possible to connect the given sockets without incurring shared pin conflicts. This method will consider /// all other sockets currently connected to the mainboard when checking for conflicts /// </summary> internal static bool CanPinsConnect(Socket socket, SocketUse socketUse) { var providedSocket = socket.Definition as ProvidedSocket; if (providedSocket == null) { return(false); } if (providedSocket.SharedPinMaps == null || providedSocket.SharedPinMaps.Count == 0) { return(true); } foreach (var sharedPinMap in providedSocket.SharedPinMaps) { //is it used by the connecting socketuse? SharedPinMap map = sharedPinMap; Pin connectingPin = (from pin in ((SocketUseDefinition)socketUse.Definition).Pins where pin.Value == map.SocketPin select pin).FirstOrDefault(); if (connectingPin == null) { continue; } // if the pin can only be used shared and this use is not compatible with sharing, fail if (!connectingPin.Shared && sharedPinMap.SharedOnly) { return(false); } foreach (var s in socket.GadgeteerHardware.Sockets) { //We are interested in sockets other than "us" if (s == socket) { continue; } if (!s.IsConnected) { continue; } var ps = s.Definition as ProvidedSocket; //If there are no shared pin maps there's nothing else to check if (ps.SharedPinMaps == null || ps.SharedPinMaps.Count == 0) { continue; } foreach (var spm in ps.SharedPinMaps) { //are the shared pind maps for the same mainboard resource? if (spm.NetId != sharedPinMap.NetId) { continue; } //is it in use or are they both shared? foreach (var pin in ((SocketUseDefinition)s.SocketUse.Definition).Pins) { if (pin.Value == spm.SocketPin && (!pin.Shared || !connectingPin.Shared)) { return(false); } } } } } return(true); }
/// <summary> /// Checks whether it's possible to connect the given sockets without incurring shared pin conflicts. This method will consider /// all other sockets currently connected to the mainboard when checking for conflicts /// </summary> internal static bool CanPinsConnect(Socket socket, SocketUse socketUse) { var providedSocket = socket.Definition as ProvidedSocket; if (providedSocket == null) { return(false); } if (providedSocket.SharedPinMaps == null || providedSocket.SharedPinMaps.Count == 0) { return(true); } foreach (var sharedPinMap in providedSocket.SharedPinMaps) { //is it used by the connecting socketuse? SharedPinMap map = sharedPinMap; Pin connectingPin = (from pin in ((SocketUseDefinition)socketUse.Definition).Pins where pin.Value == map.SocketPin select pin).FirstOrDefault(); if (connectingPin == null) { continue; } // if the pin can only be used shared and this use is not compatible with sharing, fail //#warning this check may be insufficient - have to follow the chain up to see if any provider says "sharedonly" if (!connectingPin.Shared && sharedPinMap.SharedOnly) { return(false); } // iterate over foreach (var s in socket.GadgeteerHardware.Sockets) { //We are interested in sockets other than "us" if (s == socket) { continue; } if (!s.IsConnected) { continue; } //socket.GadgeteerHardware. //#warning need to check USED sockets too, and follow the net downstream var otherProvidedSocket = s.Definition as ProvidedSocket; //If there are no shared pin maps there's nothing else to check if (otherProvidedSocket.SharedPinMaps == null || otherProvidedSocket.SharedPinMaps.Count == 0) { continue; } foreach (var spm in otherProvidedSocket.SharedPinMaps) { //are the shared pind maps for the same mainboard resource? if (spm.NetId != sharedPinMap.NetId) { continue; } //is it in use or are they both shared? foreach (var pin in ((SocketUseDefinition)s.SocketUse.Definition).Pins) { if (pin.Value == spm.SocketPin && (!pin.Shared || !connectingPin.Shared)) { return(false); } } } } } return(true); }