private void InputLoopOnRawDataReceived(object sender, RawDataReceivedEventArgs rawDataReceivedEventArgs) { List <CorsairLedId> activeInput = new List <CorsairLedId>(); // ReSharper disable once LoopCanBeConvertedToQuery - no ... foreach (InputBitMask bitMask in _bitMasks) { if (bitMask.IsSet(rawDataReceivedEventArgs.Buffer, 1)) // DarthAffe 03.01.2017: The first byte seems to be some sort of id (it's always 0x03) so we need to ignore it here. { activeInput.Add(bitMask.LedId); } } foreach (CorsairLedId lastActiveLedId in _lastActiveInput) { if (!activeInput.Contains(lastActiveLedId)) { OnInput(new OnInputEventArgs(_cueDevice, lastActiveLedId, InputAction.Released)); } } foreach (CorsairLedId activeLedId in activeInput) { if (!_lastActiveInput.Contains(activeLedId)) { OnInput(new OnInputEventArgs(_cueDevice, activeLedId, InputAction.Pressed)); } } _lastActiveInput = activeInput; }
private void port_RawDataReceived(object sender, RawDataReceivedEventArgs e) { if (!IsCommandMode) { RawDataReceived.Rise(this, e); } }
/// <summary> /// Subscriber callback that listen for Publisher uadp notifications /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RawDataReceived(object sender, RawDataReceivedEventArgs e) { lock (m_lock) { // Assert var localhost = GetFirstNic(); Assert.IsNotNull(localhost, "localhost is null"); Assert.IsNotNull(localhost.Address, "localhost.Address is null"); Assert.IsNotNull(e.Source, "Udp address received should not be null"); if (localhost.Address.ToString() != e.Source.ToString()) { // the message comes from the network but was not initiated by test return; } byte[] bytes = e.Message; Assert.AreEqual(m_sentBytes.Length, bytes.Length, "Sent bytes size: {0} does not match received bytes size: {1}", m_sentBytes.Length, bytes.Length); string sentBytesStr = BitConverter.ToString(m_sentBytes); string bytesStr = BitConverter.ToString(bytes); Assert.AreEqual(sentBytesStr, bytesStr, "Sent bytes: {0} and received bytes: {1} content are not equal", sentBytesStr, bytesStr); m_shutdownEvent.Set(); } }
private void port_RawDataReceived(object sender, RawDataReceivedEventArgs e) { var sToLog = string.Format("[RAW] >> {0}", Encoding.ASCII.GetString(e.Data)); InvokeAppendLine(rawHistoryTxb, string.Format(" >> {0}", Encoding.ASCII.GetString(e.Data))); logger.Write(sToLog); }
/// <summary> /// Handler for <see cref="UaPubSubApplication.RawDataReceived" /> event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void UaPubSubApplication_RawDataReceived(object sender, RawDataReceivedEventArgs e) { lock (m_lock) { Console.WriteLine("RawDataReceived bytes:{0}, Source:{1}, TransportProtocol:{2}, MessageMapping:{3}", e.Message.Length, e.Source, e.TransportProtocol, e.MessageMapping); Console.WriteLine(kDisplaySeparator); } }
private void port_RawData(object sender, RawDataReceivedEventArgs e) { if (!isServiceTab) { bytesReceived += e.Data.Length; InvokeAppendText(commLogTxb, logger.Write(string.Format(">> {0}", Utils.ToSafeString(e.Data)))); if (isEchoer) { Send(e.Data); } } }
/// <summary> /// Handle Receive event for an UADP channel on Subscriber Side /// </summary> /// <param name="result"></param> private void OnUadpReceive(IAsyncResult result) { lock (m_lock) { if (m_subscriberUdpClients == null || m_subscriberUdpClients.Count == 0) { return; } } // this is what had been passed into BeginReceive as the second parameter: UdpClient socket = result.AsyncState as UdpClient; if (socket == null) { return; } // points towards whoever had sent the message: IPEndPoint source = new IPEndPoint(0, 0); // get the actual message and fill out the source: try { byte[] message = socket.EndReceive(result, ref source); if (message != null) { Utils.Trace("OnUadpReceive received message with length {0} from {1}", message.Length, source.Address); if (message.Length > 1) { // raise RawData received event RawDataReceivedEventArgs rawDataReceivedEventArgs = new RawDataReceivedEventArgs() { Message = message, Source = source.Address.ToString(), TransportProtocol = this.TransportProtocol, MessageMapping = MessageMapping.Uadp, PubSubConnectionConfiguration = PubSubConnectionConfiguration }; // trigger notification for received raw data Application.RaiseRawDataReceivedEvent(rawDataReceivedEventArgs); // check if the RawData message is marked as handled if (rawDataReceivedEventArgs.Handled) { Utils.Trace("UdpConnection message from source={0} is marked as handled and will not be decoded.", rawDataReceivedEventArgs.Source); return; } // call on a new thread Task.Run(() => { ProcessReceivedMessage(message, source); }); } } } catch (Exception ex) { Utils.Trace(ex, "OnUadpReceive from {0}", source.Address); } try { // schedule the next receive operation once reading is done: socket.BeginReceive(new AsyncCallback(OnUadpReceive), socket); } catch (Exception ex) { Utils.Trace(Utils.TraceMasks.Information, "OnUadpReceive BeginReceive threw Exception {0}", ex.Message); lock (m_lock) { Renew(socket); } } }
private void nmeaPort_RawData(object sender, RawDataReceivedEventArgs e) { if (nmeaPort.IsRawModeOnly) { timer.Stop(); int result = e.Data[0]; if (result == 49) { repeats = 0; List <byte> tpacket = new List <byte>(); for (int n = 0; (n < packetSize) && (fw_bytes_rPos < fw_bytes.Length); n++) { tpacket.Add(fw_bytes[fw_bytes_rPos++]); } packetCrc = crc.CRC32(0, tpacket.ToArray()); tpacket.AddRange(BitConverter.GetBytes(packetCrc)); action = UCNL_FW_ACTION.FW_BLOCK; InvokeWriteLogString("DEVICE: Next packet\r\n"); if (fw_bytes_rPos >= fw_bytes.Length) { tpacket.AddRange(fw_tableOffsets); } packet = tpacket.ToArray(); RequestTransferBlock(); if (packetIdx == 0) { InvokeSwitchProgressBarMode(ProgressBarStyle.Continuous); } InvokeSetProgressBarValue(packetIdx); if (packetIdx < totalPackets) { packetIdx++; } } else if (result == 50) { action = UCNL_FW_ACTION.FW_BLOCK; RequestTransferBlock(); InvokeWriteLogString("DEVICE: Bad packet\r\n"); } else if (result == 51) { UpdateFinished("SUCCESS"); } else if (result == 52) { // 4 UpdateFinished("FAIL: device timeout (4)"); } else if (result == 53) { // 5 UpdateFinished("FAIL: Firmware integrity error. Try again with \"Device is empty option\""); } else { UpdateFinished(string.Format("FAIL: ({0})", result)); } } }