public void DisconnectBus(Bus bus) { if (BusConnections.Contains(bus)) { BusConnections.Remove(bus); } bus.DisconnectModule(this); //Log new connection EventLog.AddLog(new SimEvent( "Module " + Name + " has disconnected from bus " + bus.Name, EventSeverity.INFO)); }
public void ConnectBus(Bus newBus) { if (!BusConnections.Contains(newBus)) { BusConnections.Add(newBus); newBus.ConnectModule(this); //Log new connection EventLog.AddLog(new SimEvent( "Module " + Name + " has connected to bus " + newBus.Name, EventSeverity.INFO)); } }
public void SendCSPPacket(CSPBus bus, byte destination_addr, byte destination_port, byte source_port, byte priority, short dataSize, ModuleCommand command) { var rnd = new Random(); BitVector32 packetHeader = new BitVector32(0x00000000); packetHeader[CSPPacket.SourceAddress] = randomSource ? ((byte)(rnd.Next(0, 32))) : Address; packetHeader[CSPPacket.DestinationAddress] = randomDestination ? ((byte)(rnd.Next(0, 32))) : destination_addr; packetHeader[CSPPacket.SourcePort] = randomSourcePort ? ((byte)(rnd.Next(0, 64))) : source_port; packetHeader[CSPPacket.DestinationPort] = randomDestinationPort ? ((byte)(rnd.Next(0, 64))) : destination_port; packetHeader[CSPPacket.Priority] = randomPriority ? ((byte)(rnd.Next(0, 4))) : priority; CSPPacket packet = new CSPPacket(packetHeader, dataSize, command); if (bus == null) { //Log failed send EventLog.AddLog(new SimEvent( "Module " + Name + " failed to send a packet because the target bus does not exist (check that the bus in your script exists in the simulation)", EventSeverity.ERROR)); } else if (CommunicationDisabled) { //Log failed send EventLog.AddLog(new SimEvent( "Module " + Name + " failed to send packet " + packet.ToString() + " because it has lost connection", EventSeverity.ERROR)); } else if (BusConnections.Contains(bus)) { //We are assuming that all packets with wrong bits/data are considered in error because the //probablity that the error is not detected is negligible if (randomPriority) { packet.ErrorDetected = true; //Log sending packet with random priority EventLog.AddLog(new SimEvent( "Module " + Name + " sends a packet containing a random priority: " + packet.ToString() + " to bus " + bus.Name, EventSeverity.WARNING)); } if (randomDestination) { packet.ErrorDetected = true; //Log sending packet with random destination EventLog.AddLog(new SimEvent( "Module " + Name + " sends a packet containing a random destination address: " + packet.ToString() + " to bus " + bus.Name, EventSeverity.WARNING)); } if (randomSource) { packet.ErrorDetected = true; //Log sending packet with random psource EventLog.AddLog(new SimEvent( "Module " + Name + " sends a packet containing a random source address: " + packet.ToString() + " to bus " + bus.Name, EventSeverity.WARNING)); } if (randomDestinationPort) { packet.ErrorDetected = true; //Log sending packet with random psource EventLog.AddLog(new SimEvent( "Module " + Name + " sends a packet containing a random destination port: " + packet.ToString() + " to bus " + bus.Name, EventSeverity.WARNING)); } if (randomSourcePort) { packet.ErrorDetected = true; //Log sending packet with random psource EventLog.AddLog(new SimEvent( "Module " + Name + " sends a packet containing a random source port: " + packet.ToString() + " to bus " + bus.Name, EventSeverity.WARNING)); } if (GarbageOutput) { packet.ErrorDetected = true; } bus.EnqueuePacket(packet); if (!(randomPriority || randomDestination || randomSource || randomDestinationPort || randomSourcePort)) { //Log sending normal packet EventLog.AddLog(new SimEvent( "Module " + Name + " sends packet " + packet.ToString() + " to bus " + bus.Name, EventSeverity.INFO)); } } else { //Log failed send EventLog.AddLog(new SimEvent( "Module " + Name + " failed to send packet " + packet.ToString() + " because it is not connected to bus " + bus.Name, EventSeverity.ERROR)); } }