public static void AddSendHandler(object state, SendDataDelegate SendData) { if (SendHandlers.ContainsKey(state)) SendHandlers[state] = SendData; else SendHandlers.Add(state, SendData); }
public EdCustomAdapterCommon(SendDataDelegate sendDataFunc, ReceiveDataDelegate receiveDataFunc, DiscardInBufferDelegate discardInBufferFunc, ReadInBufferDelegate readInBufferFunc, int readTimeoutOffsetLong, int readTimeoutOffsetShort, int echoTimeout, bool echoFailureReconnect) { _readTimeoutOffsetLong = readTimeoutOffsetLong; _readTimeoutOffsetShort = readTimeoutOffsetShort; _echoTimeout = echoTimeout; _echoFailureReconnect = echoFailureReconnect; _sendDataFunc = sendDataFunc; _receiveDataFunc = receiveDataFunc; _discardInBufferFunc = discardInBufferFunc; _readInBufferFunc = readInBufferFunc; RawMode = false; CurrentProtocol = EdInterfaceObd.Protocol.Uart; ActiveProtocol = EdInterfaceObd.Protocol.Uart; CurrentBaudRate = 0; ActiveBaudRate = -1; CurrentWordLength = 0; ActiveWordLength = -1; CurrentParity = EdInterfaceObd.SerialParity.None; ActiveParity = EdInterfaceObd.SerialParity.None; InterByteTime = 0; CanTxId = -1; CanRxId = -1; CanFlags = EdInterfaceObd.CanFlags.Empty; AdapterType = -1; AdapterVersion = -1; AdapterSerial = null; }
public void TestConsumeBuildStartedEvent() { bool wentInHandler = false; BuildStartedEventArgs buildStarted = new BuildStartedEventArgs("Start", "Help"); SendDataDelegate transportDelegate = delegate(INodePacket packet) { wentInHandler = true; }; BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(transportDelegate); transportSink.Consume(buildStarted, 0); Assert.IsTrue(transportSink.HaveLoggedBuildStartedEvent); Assert.IsFalse(transportSink.HaveLoggedBuildFinishedEvent); Assert.IsFalse(wentInHandler, "Expected not to go into transport delegate"); }
public void TestShutDown() { SendDataDelegate transportDelegate = PacketProcessor; var weakTransportDelegateReference = new WeakReference(transportDelegate); var transportSink = new BuildEventArgTransportSink(transportDelegate); transportSink.ShutDown(); Assert.NotNull(weakTransportDelegateReference.Target); transportDelegate = null; GC.Collect(); GC.WaitForPendingFinalizers(); // Expected shutdown to null out the sendData delegate, the two garbage collections // should have collected the sendDataDelegate causing the weak reference to die. Assert.Null(weakTransportDelegateReference.Target); // " Expected delegate to be dead" }
public void TestConsumeMessageBuildEvent() { bool wentInHandler = false; BuildMessageEventArgs messageEvent = new BuildMessageEventArgs("My message", "Help me keyword", "Sender", MessageImportance.High); SendDataDelegate transportDelegate = delegate(INodePacket packet) { wentInHandler = true; LogMessagePacket loggingPacket = packet as LogMessagePacket; Assert.IsNotNull(loggingPacket); BuildMessageEventArgs messageEventFromPacket = loggingPacket.NodeBuildEvent.Value.Value as BuildMessageEventArgs; Assert.IsTrue(messageEventFromPacket == messageEvent); }; BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(transportDelegate); transportSink.Consume(messageEvent, 0); Assert.IsTrue(wentInHandler, "Expected to go into transport delegate"); }
public PacketBufferer(SendDataDelegate SendData, object state, int interval) { _SendData = SendData; _state = state; ticker = new Timer(ticker_Elapsed, null, interval, interval); }
public PacketBufferer(SendDataDelegate SendData, object state) : this(SendData, state, 100) { }
/// <summary> /// Create the sink which will consume a buildEventArg /// Create a INodePacket and send it to the transport component /// </summary> /// <param name="sendData">A delegate which takes an INodePacket and sends the packet to where it needs to go</param> /// <exception cref="InternalErrorException">Send data delegate is null</exception> internal BuildEventArgTransportSink(SendDataDelegate sendData) { ErrorUtilities.VerifyThrow(sendData != null, "sendData delegate is null"); _sendDataDelegate = sendData; }
/// <summary> /// Dispose of any resources the sink is holding onto. /// </summary> public void ShutDown() { _sendDataDelegate = null; }
public void SendData(string textData) { m_SendDataDelegate = new SendDataDelegate(_SendData); m_SendDataDelegate.BeginInvoke(textData, new AsyncCallback(_SendDataCompleted), DateTime.Now.ToString()); }