public Thread readSensorDataNewThread(Demultiplexer <SensorData> distributor) { Thread producer = new Thread(readSensorDataThreadStart); producer.Start(distributor); return(producer); }
public Server(Configuration configuration) { config = configuration; input = new Demultiplexer(config.maxPacketsInQueue); joins = new Dictionary <string, Packet>(); ghost = new GameObject("Server Ghost"); lagSimulator = new LagSimulator(config); local = new Link.Builder() .Bind(true) .IP("0.0.0.0") .Port(config.serverListeningPort) .ReceiveTimeout(config.serverReceiveTimeout) .SendTimeout(config.serverSendTimeout) .Build(); links = new List <Link>(); outputs = new List <Stream>(); snapshot = config.GetServerSnapshot(); acks = new SortedDictionary <int, Packet> [config.maxPlayers]; for (int i = 0; i < config.maxPlayers; ++i) { acks[i] = new SortedDictionary <int, Packet>(); } threading = new Threading(); ghostTransform = ghost.transform; world = GameObject.Find("World") .GetComponent <World>() .LoadSnapshot(snapshot); lastSnapshot = 0.0f; timestamp = 0.0f; }
public void readSensorDataSync(Demultiplexer <SensorData> distributor) { var read = -1; byte[] buffer = new byte[BUFFER_SIZE]; Array.Clear(buffer, 0, BUFFER_SIZE); using (FileStream fs = new FileStream(SENSOR_DATA_FILE, FileMode.Open, FileAccess.Read, FileShare.Read, BUFFER_SIZE)) { while (read != 0) { read = fs.Read(buffer, 0, BUFFER_SIZE); for (var i = 0; i < read; i++) { var c = (char)buffer[i]; sb.Append(c); if (c == '\n') { SensorData data = produceSensorData(); if (data != null) { distributor(data); } } } } Console.WriteLine("finished reading file.Sending end signal"); distributor(null); } }
public override void Replicate() { Debug.Log("Enemy deployed: " + config.peerIPs[id] + ":" + config.peerPorts[id]); Thread.Sleep(100); Demultiplexer localInput = config.GetPlayer(0).GetInputDemultiplexer(); Link localLink = config.GetLink(0); while (!config.OnEscape()) { byte [] payload = localLink.Receive(link); if (payload != null) { Packet packet = new Packet(payload); PacketType type = packet.GetPacketType(); packet.Reset(); switch (type) { case PacketType.ACK: { localInput.Write(type, packet); break; } default: { // Se debe registrar y se debe generar un ACK de respuesta // en caso de que sea EVENT o FLOODING. input.Write(packet); break; } } } } }
static void Main() { //Sygnały System.Console.Write("x1 = "); Signal x1 = new Signal(System.Convert.ToInt32(System.Console.ReadLine())); System.Console.Write("x2 = "); Signal x2 = new Signal(System.Convert.ToInt32(System.Console.ReadLine())); System.Console.Write("x3 = "); Signal x3 = new Signal(System.Convert.ToInt32(System.Console.ReadLine())); System.Console.Write("x4 = "); Signal x4 = new Signal(System.Convert.ToInt32(System.Console.ReadLine())); //Bramki //Nand nand1 = new Nand(x3.result(0), x4.result(1)); //Nand nand2 = new Nand(x3.result(1), x4.result(0)); //Nand nand3 = new Nand(nand1.result(0), nand2.result(0)); //Not not1 = new Not(nand2.result(0)); //Multiplexer mux1 = new Multiplexer(4, 0, 0, x1.result(0), x2.result(0), not1.result(0), nand3.result(0), 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1); Demultiplexer dmux1 = new Demultiplexer(0, x1.result(0), x2.result(0), x3.result(0), x4.result(0)); //Wynik System.Console.WriteLine("F = {0}", dmux1.result(6)); System.Console.ReadLine(); }
public static Reactor CreateReactor() { Dispatcher dispatcher = new Dispatcher(); Demultiplexer demultiplexer = new Demultiplexer(dispatcher); return(new Reactor(demultiplexer, dispatcher)); }
public ListenerSubscriber2(DDS.DomainParticipant participant, DDS.Topic topic, Demultiplexer <T> demux) { this.topic = topic; this.participant = participant; demultiplexer = demux; initialize(); }
protected void Start() { link = config.GetLink(id); input = new Demultiplexer(config.maxPacketsInQueue); output = new Stream(config.maxPacketsInQueue); lastSnapshot = 0.0f; Δs = 1.0f / config.snapshotsPerSecond; }
public void When_event_source_is_not_blocked_event_is_passed_through_system() { Guid eventSourceId = Guid.NewGuid(); int enqueuedToProcessingCount = 0; var sut = new Demultiplexer(); sut.EventDemultiplexed += (s, e) => { enqueuedToProcessingCount++; }; sut.Demultiplex(CreateEvent(eventSourceId)); enqueuedToProcessingCount.Should().Be(1); }
public void readSensorDataDDSWaitset(Demultiplexer <SensorData> distributor) { DDS.Duration_t timeout; timeout.nanosec = 0; timeout.sec = 10; DDS.DomainParticipant participant = DefaultParticipant.Instance; DefaultParticipant.RegisterType <SensorData, SensorDataTypeSupport>(); WaitsetSubscriber <SensorData> subscriber = new WaitsetSubscriber <SensorData>(participant, "Raw SensorData", null, timeout, distributor); subscriber.subscribe(); }
public void Different_event_sources_does_not_block_each_other() { Guid firstEventSourceId = Guid.NewGuid(); Guid secondEventSourceId = Guid.NewGuid(); int enqueuedToProcessingCount = 0; var sut = new Demultiplexer(); sut.EventDemultiplexed += (s, e) => { enqueuedToProcessingCount++; }; sut.Demultiplex(CreateElement(firstEventSourceId)); sut.Demultiplex(CreateElement(secondEventSourceId)); enqueuedToProcessingCount.Should().Be(2); }
public WaitsetSubscriber(DDS.DomainParticipant participant, string topicName, string typeName, DDS.Duration_t timeout, Demultiplexer <T> demux) { this.participant = participant; this.topicName = topicName; if (typeName == null) { this.typeName = typeof(T).ToString(); } else { this.typeName = typeName; } this.timeout = timeout; this.demultiplexer = demux; }
public void Different_event_sources_does_not_block_each_other() { Guid firstEventSourceId = Guid.NewGuid(); Guid secondEventSourceId = Guid.NewGuid(); int enqueuedToProcessingCount = 0; var sut = new Demultiplexer(); sut.EventDemultiplexed += (s, e) => { enqueuedToProcessingCount++; }; sut.Demultiplex(CreateEvent(firstEventSourceId)); sut.Demultiplex(CreateEvent(secondEventSourceId)); enqueuedToProcessingCount.Should().Be(2); }
public ListenerSubscriber(DDS.DomainParticipant participant, string topicName, string typeName, Demultiplexer <T> demux) { if (typeName == null) { this.typeName = typeof(T).ToString(); } else { this.typeName = typeName; } this.participant = participant; this.topicName = topicName; demultiplexer = demux; }
public void readSensorDataDDSListener(Demultiplexer <SensorData> distributor) { DDS.DomainParticipant participant = DefaultParticipant.Instance; DefaultParticipant.RegisterType <SensorData, SensorDataTypeSupport>(); ListenerSubscriber <SensorData> subscriber = new ListenerSubscriber <SensorData>(participant, "Raw SensorData", null, distributor); subscriber.subscribe(); /*DDS.DomainParticipant participant = DefaultParticipant.Instance; * DefaultParticipant.RegisterType<SensorData, SensorDataTypeSupport>(); * DDS.Topic topic = participant.create_topic("Raw SensorData", typeof(SensorData).ToString(), * DDS.DomainParticipant.TOPIC_QOS_DEFAULT, null, DDS.StatusMask.STATUS_MASK_NONE); * if (topic == null) * { * throw new ApplicationException("create_topic error"); * } * ListenerSubscriber2<SensorData> subscriber_A = * new ListenerSubscriber2<SensorData>(participant, topic, distributor, QueryHelpers.getDefaultSensorData); * subscriber_A.setContentFilter("filtered_topic_A", * "(sensor_id >= %0 and sensor_id <= %1) OR (sensor_id >= %2 and sensor_id <= %3) OR (sensor_id >= %4 and sensor_id <= %5)", * new DDS.StringWrapper[] { "10", "28", "47", "59", "88", "98" }); * var readerQoS_A = subscriber_A.getDataReaderQos(); * * DDS.TransportUnicastSettings_t[] arr_A = new DDS.TransportUnicastSettings_t[1]; * arr_A[0] = new DDS.TransportUnicastSettings_t(); * readerQoS_A.unicast.value.loan(arr_A, 1); * readerQoS_A.unicast.value.ensure_length(1, 1); * readerQoS_A.unicast.value.get_at(0).receive_port = 9000; * * var subscriber_B = new ListenerSubscriber2<SensorData>(participant, topic, distributor, QueryHelpers.getDefaultSensorData); * subscriber_B.setContentFilter("filtered_topic_B", * "(sensor_id = %0) OR (sensor_id = %1) OR (sensor_id >= %2 and sensor_id <= %3) OR (sensor_id >= %4 and sensor_id <= %5) OR (sensor_id >= %6 and sensor_id <= %7)", * new DDS.StringWrapper[] { "4", "8", "38", "44", "61", "75", "99", "106" }); * var readerQoS_B = subscriber_B.getDataReaderQos(); * * DDS.TransportUnicastSettings_t[] arr_B = new DDS.TransportUnicastSettings_t[1]; * arr_B[0] = new DDS.TransportUnicastSettings_t(); * readerQoS_B.unicast.value.loan(arr_B, 1); * readerQoS_B.unicast.value.ensure_length(1, 1); * readerQoS_B.unicast.value.get_at(0).receive_port = 8000; * * subscriber_A.subscribe(); * subscriber_B.subscribe();*/ }
public Client(Configuration configuration) { config = configuration; input = new Demultiplexer(config.maxPacketsInQueue); local = new Link.Builder() .Bind(true) .IP("0.0.0.0") .Port(config.clientListeningPort) .ReceiveTimeout(config.clientReceiveTimeout) .SendTimeout(config.clientSendTimeout) .Build(); server = new Link.Builder() .Bind(false) .IP(config.serverAddress) .Port(config.serverListeningPort) .ReceiveTimeout(config.serverReceiveTimeout) .SendTimeout(config.serverSendTimeout) .Build(); snapshot = new Snapshot(config.maxPlayers); interpolator = new SnapshotInterpolator.Builder() .Snapshot(snapshot) .Window(config.slidingWindowSize) .SPS(config.snapshotsPerSecond) .Build(); output = new Stream(config.maxPacketsInQueue); threading = new Threading(); id = -1; sequence = 0; packets = new SortedDictionary <int, Packet>(); timedPackets = new SortedDictionary <int, Packet>(); lastTime = 0; timeout = config.timeout; player = null; predictor = null; world = GameObject.Find("World") .GetComponent <World>() .LoadSnapshot(snapshot); }
public List <StandardComponent> parcourir_copier() { UIElement[] tableau = new UIElement[1000]; List <StandardComponent> liste = new List <StandardComponent>(); int length = canvas.Children.Count; canvas.Children.CopyTo(tableau, 0); for (int i = 0; i < length; i++) { StandardComponent newChild = null; if (!(typeof(Line) == tableau[i].GetType()) && ((tableau[i] as StandardComponent).IsSelect)) { if (typeof(AND) == tableau[i].GetType()) { newChild = new AND((tableau[i] as AND).nbrInputs()); for (int j = 0; j < (tableau[i] as AND).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as AND).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as AND).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(OR) == tableau[i].GetType()) { newChild = new OR((tableau[i] as OR).nbrInputs()); for (int j = 0; j < (tableau[i] as OR).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as OR).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as OR).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(NAND) == tableau[i].GetType()) { newChild = new NAND((tableau[i] as NAND).nbrInputs()); for (int j = 0; j < (tableau[i] as NAND).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as NAND).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as NAND).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(NOR) == tableau[i].GetType()) { newChild = new NOR((tableau[i] as NOR).nbrInputs()); for (int j = 0; j < (tableau[i] as NOR).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as NOR).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as NOR).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(Not) == tableau[i].GetType()) { newChild = new Not(); Terminal terminal_1 = (Terminal)((tableau[i] as Not).inputStack.Children[0]); Terminal terminal_2 = (Terminal)((newChild as Not).inputStack.Children[0]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } else if (typeof(Output) == tableau[i].GetType()) { newChild = new Output(); } else if (typeof(Input) == tableau[i].GetType()) { newChild = new Input(); (newChild as Input).state = (tableau[i] as Input).state; } else if (typeof(XNOR) == tableau[i].GetType()) { newChild = new XNOR((tableau[i] as XNOR).nbrInputs()); for (int j = 0; j < (tableau[i] as XNOR).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as XNOR).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as XNOR).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(XOR) == tableau[i].GetType()) { newChild = new XOR((tableau[i] as XOR).nbrInputs()); for (int j = 0; j < (tableau[i] as XOR).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as XOR).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as XOR).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(Comparateur) == tableau[i].GetType()) { newChild = new Comparateur((tableau[i] as Comparateur).nbrInputs(), (tableau[i] as Comparateur).nbrOutputs()); } else if (typeof(Decodeur) == tableau[i].GetType()) { newChild = new Decodeur((tableau[i] as Decodeur).nbrInputs(), (tableau[i] as Decodeur).nbrOutputs()); } else if (typeof(Demultiplexer) == tableau[i].GetType()) { newChild = new Demultiplexer((tableau[i] as Demultiplexer).nbrInputs(), (tableau[i] as Demultiplexer).nbrOutputs(), (tableau[i] as Demultiplexer).nbrSelections()); } else if (typeof(Encodeur) == tableau[i].GetType()) { newChild = new Encodeur((tableau[i] as Encodeur).nbrInputs(), (tableau[i] as Encodeur).nbrOutputs()); } else if (typeof(FullAdder) == tableau[i].GetType()) { newChild = new FullAdder((tableau[i] as FullAdder).nbrInputs(), (tableau[i] as FullAdder).nbrOutputs()); } else if (typeof(FullSub) == tableau[i].GetType()) { newChild = new FullSub((tableau[i] as FullSub).nbrInputs(), (tableau[i] as FullSub).nbrOutputs()); } else if (typeof(HalfAdder) == tableau[i].GetType()) { newChild = new HalfAdder((tableau[i] as HalfAdder).nbrInputs(), (tableau[i] as HalfAdder).nbrOutputs()); } else if (typeof(HalfSub) == tableau[i].GetType()) { newChild = new HalfSub((tableau[i] as HalfSub).nbrInputs(), (tableau[i] as HalfSub).nbrOutputs()); } else if (typeof(Multiplexer) == tableau[i].GetType()) { newChild = new Multiplexer((tableau[i] as Multiplexer).nbrInputs(), (tableau[i] as Multiplexer).nbrOutputs(), (tableau[i] as Multiplexer).nbrSelections()); } else if (typeof(SequentialComponent.Clock) == tableau[i].GetType()) { newChild = new SequentialComponent.Clock((tableau[i] as SequentialComponent.Clock).LowLevelms, (tableau[i] as SequentialComponent.Clock).HighLevelms, MainWindow.Delay); } liste.Add(newChild); newChild.AllowDrop = true; newChild.PreviewMouseLeftButtonDown += fenetre.MouseLeftButtonDown; newChild.PreviewMouseMove += fenetre.MouseMove; newChild.PreviewMouseLeftButtonUp += fenetre.PreviewMouseLeftButtonUp; newChild.SetValue(Canvas.LeftProperty, tableau[i].GetValue(Canvas.LeftProperty)); newChild.SetValue(Canvas.TopProperty, tableau[i].GetValue(Canvas.TopProperty)); (newChild as StandardComponent).PosX = (tableau[i] as StandardComponent).PosX; (newChild as StandardComponent).PosY = (tableau[i] as StandardComponent).PosY; try { StandardComponent component = newChild as StandardComponent; component.recalculer_pos(); } catch { }; } } return(liste); }
public DataReaderListener(Demultiplexer <T> demux) { demultiplexer = demux; dataSeq = new DDS.UserRefSequence <T>(); infoSeq = new DDS.SampleInfoSeq(); }
private void readSensorDataThreadStart(object obj) { Demultiplexer <SensorData> distributor = (Demultiplexer <SensorData>)obj; readSensorDataSync(distributor); }
public void TestDemultiplexUIMFSingleFrame() { // Old: const int numSegments = 24; const int numberOfBits = 4; const int lcFramesToSum = 1; const string matrixString = "100110101111000"; var multiplierMatrix = MatrixCreator.CreateMatrixForDemultiplexing(matrixString); var scaledMatrix = (DenseMatrix)multiplierMatrix.Multiply(2.0 / 16.0); var inversedScaledMatrix = (DenseMatrix)scaledMatrix.Inverse(); Assert.AreEqual(15, inversedScaledMatrix.ColumnCount); Assert.AreEqual(15, inversedScaledMatrix.RowCount); var expectMatrixVals = new List <int> { 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, -1 }; for (var i = 0; i < expectMatrixVals.Count; i++) { Assert.AreEqual(expectMatrixVals[i], inversedScaledMatrix.Values[i], 0.01, "inversedScaledMatrix has unexpected values"); } var uimfFile = VerifyLocalUimfFile(@"Test_Data\9pep_mix_1uM_4bit_50_12Dec11_encoded.uimf"); if (uimfFile == null) { var currentDirectory = new DirectoryInfo("."); Assert.Fail("UIMF file not found; Current working directory is " + currentDirectory.FullName); } Console.WriteLine("Opening " + uimfFile.FullName); var uimfReader = new DataReader(uimfFile.FullName); var globalParams = uimfReader.GetGlobalParams(); var binWidth = globalParams.BinWidth; var frameNumbers = new List <int>(uimfReader.GetFrameNumbers(UIMFData.FrameType.MS1)); frameNumbers.AddRange(uimfReader.GetFrameNumbers(UIMFData.FrameType.Calibration)); frameNumbers.AddRange(uimfReader.GetFrameNumbers(UIMFData.FrameType.MS2)); frameNumbers.Sort(); var numFrames = frameNumbers.Count; Console.WriteLine("Total Data Frames = " + numFrames); var baseFileName = Path.GetFileNameWithoutExtension(uimfFile.Name); string newFileName; if (baseFileName.Contains("encoded")) { newFileName = baseFileName.Replace("encoded", "decoded") + ".uimf"; } else { newFileName = baseFileName + "_decoded.uimf"; } if (uimfFile.DirectoryName == null) { Assert.Fail("Unable to determine the parent directory of " + uimfFile.FullName); } var newFile = new FileInfo(Path.Combine(uimfFile.DirectoryName, newFileName)); var bitSequence = DemultiplexerOptions.GetBitSequence(numberOfBits); Assert.AreEqual(matrixString, bitSequence, "Unexpected bit sequence: " + bitSequence + "; expecting " + matrixString); if (newFile.Exists) { Console.WriteLine("Deleting existing decoded UIMF file: " + newFile.FullName); try { newFile.Delete(); } catch (Exception ex) { Assert.Fail("Error deleting file: " + ex.Message); } } Console.WriteLine("Demultiplexing to create " + newFile.FullName); var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); using (var uimfWriter = new DataWriter(newFile.FullName, executingAssembly)) { uimfWriter.CreateTables(globalParams.GetValue(GlobalParamKeyType.DatasetType)); uimfWriter.InsertGlobal(globalParams); // Old method of instantiating the Demultiplexer: // var firstFrameParams = uimfReader.GetFrameParams(1); // var averageTOFLength = firstFrameParams.GetValueDouble(FrameParamKeyType.AverageTOFLength); // Demultiplexer demultiplexer = new Demultiplexer(inversedScaledMatrix, numSegments, binWidth, averageTOFLength); var demultiplexerOptions = new DemultiplexerOptions(); var demultiplexer = new Demultiplexer(demultiplexerOptions); var scanToIndexMap = demultiplexerOptions.ScanToIndexMap; var segmentLength = demultiplexer.NumberOfSegments; foreach (var currentFrameNumber in frameNumbers) { Console.WriteLine("Processing Frame " + currentFrameNumber); // Setup the frame in the UIMFWriter var frameParams = uimfReader.GetFrameParams(currentFrameNumber); uimfWriter.InsertFrame(currentFrameNumber, frameParams); // If we are dealing with a calibration frame, we just want to write the data to the new UIMF file as is if (frameParams.FrameType == UIMFData.FrameType.Calibration) { for (var i = 0; i < frameParams.Scans; i++) { var intensities = uimfReader.GetSpectrumAsBins( currentFrameNumber, currentFrameNumber, frameParams.FrameType, startScanNumber: i, endScanNumber: i); var nonZeroCount = intensities.Count(x => x > 0); uimfWriter.InsertScan(currentFrameNumber, frameParams, i, intensities, binWidth); } continue; } // Data pulled from the UIMF file will not be re-ordered const bool isReordered = false; // Get the data of the frame from the UIMF File var arrayOfIntensityArrays = UIMFDemultiplexer.UIMFDemultiplexer.GetIntensityBlockForDemultiplexing( uimfReader, currentFrameNumber, frameParams.FrameType, segmentLength, scanToIndexMap, isReordered, lcFramesToSum); // Demultiplex the frame, which updates the array var scanDataEnumerable = demultiplexer.DemultiplexFrame(arrayOfIntensityArrays, isReordered); var sortByScanNumberQuery = (from scanData in scanDataEnumerable orderby scanData.ScanNumber select scanData).ToList(); Assert.AreEqual(93, sortByScanNumberQuery.Count); foreach (var scanData in sortByScanNumberQuery) { var dataPoints = new List <Tuple <int, int> >(scanData.BinsToIntensitiesMap.Count); dataPoints.AddRange(from dataPoint in scanData.BinsToIntensitiesMap where dataPoint.Value != 0 orderby dataPoint.Key select new Tuple <int, int>(dataPoint.Key, dataPoint.Value)); uimfWriter.InsertScan( currentFrameNumber, frameParams, scanData.ScanNumber, dataPoints, binWidth, 0); } uimfWriter.FlushUimf(); } } }