public void _0002_Mode_Mask() { MessageFilterCollection filters = new MessageFilterCollection(); filters.GuiAdd(new MessageFilterItem("Test", true, MaskOrArbId.Mask, 0x03, ArbitrationIdType.Standard, false, MessageDirection.Transmitted, MessageFilterMode.InsertToLog)); Assert.IsTrue(filters.DoAddToLog(2, ArbitrationIdType.Standard, false, MessageDirection.Transmitted)); Assert.AreEqual(1, filters[0].AcceptanceCount); Assert.IsFalse(filters.DoAddToLog(4, ArbitrationIdType.Standard, false, MessageDirection.Transmitted)); Assert.AreEqual(1, filters[0].AcceptanceCount); }
/// <summary> /// Ütemesen nézzük mi a helyzet az adapterrel /// </summary> private void DoWork() { _isRunning = true; Exception loopException = null; { /*SynContext*/ Action doMehtod = () => OnStarted(); if (App.SyncContext != null) { App.SyncContext.Post((e1) => { doMehtod(); }, null); } else { doMehtod(); } } do { if (_adapter != null && _adapter.IsConnected) { if (_adapter.LasException != null) { Debug.WriteLine(GetType().Namespace + "." + GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "(): DoWork is now shutdown by Adapter LastException is not null."); loopException = _adapter.LasException; break; } /* * TODO: Ezt megcsinálni a ToolTable-re is * if (_messageSenders.LastException != null) * { * Debug.WriteLine(GetType().Namespace + "." + GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "(): DoWork is now shutdown by MessageSender LastException is not null."); * loopException = _messageSenders.LastException; * break; * } */ try { #region CAN Adapter Funcitons if (_txQueue.Count > 0) { var tx = _txQueue.Dequeue(); var txTimestamp = DateTime.Now; var txTrace = new MessageTraceItem( name: tx.Name, timestamp: txTimestamp, direction: MessageDirection.Transmitted, type: tx.Type, remote: tx.Remote, arbitrationId: tx.ArbitrationId, data: tx.Data, documentation: tx.Documentation, description: tx.Description); _adapter.Write(new[] { new CanMessage( isRemote: tx.Remote ? (byte)0x01 : (byte)0x00b, arbitrationId: (tx.Type == ArbitrationIdType.Standard) ? tx.ArbitrationId : tx.ArbitrationId | 0x20000000, data: tx.Data) }); if (!_paramters.FiltersEnabled || _filters.DoAddToTrace( arbitrationId: tx.ArbitrationId, type: tx.Type, remote: tx.Remote, direction: MessageDirection.Transmitted)) { if (_project.Parameters.TraceEnabled) { _messageTrace.Add(txTrace); } } if (!_paramters.FiltersEnabled || _filters.DoAddToLog( arbitrationId: tx.ArbitrationId, type: tx.Type, remote: tx.Remote, direction: MessageDirection.Transmitted)) { if (_project.Parameters.LogEnabled) { _log.Messages.AddToStorage( name: tx.Name, timestamp: txTimestamp, direction: MessageDirection.Transmitted, type: tx.Type, arbitrationId: tx.ArbitrationId, isRemote: tx.Remote, data: tx.Data, documentation: tx.Documentation, description: tx.Description); } } if (_project.Parameters.MessageStatisticsEnabled) { Action doMehtod = () =>/*SynContext*/ { _messageStat.InsertMessage( name: tx.Name, direction: MessageDirection.Transmitted, type: tx.Type, arbitrationId: tx.ArbitrationId, data: tx.Data, remote: tx.Remote, timestamp: txTimestamp); }; if (App.SyncContext != null) { App.SyncContext.Post((e1) => { doMehtod(); }, null); } else { doMehtod(); } } } if (_adapter.Attributes.PendingRxMessages > 0) { var rxItems = new CanMessage[1]; _adapter.Read(rxItems, 0, 1); var rxType = ((rxItems[0].ArbitrationId & 0x20000000) == 0) ? ArbitrationIdType.Standard : ArbitrationIdType.Extended; var rxArbId = unchecked (rxItems[0].ArbitrationId & (uint)(~0x20000000)); var rxIsRmote = rxItems[0].IsRemote != 0 ? true : false; var rxTimestamp = new DateTime(rxItems[0].TimestampTick); var rxData = rxItems[0].Data; var rxName = string.Empty; var rxDocumentation = string.Empty; var rxDescription = string.Empty; /* * TODO: Ezt megcsinálni * if (_paramters.RxMsgResolvingBySenderEnabled) * { * var resolvedRxMsg = _messageSenders.GetMsg(rxArbId, rxType, rxIsRmote); * if (resolvedRxMsg != null) * { * rxName = resolvedRxMsg.Name; * rxDocumentation = resolvedRxMsg.Documentation; * rxDescription = resolvedRxMsg.Description; * } * } */ var rxTrace = new MessageTraceItem( name: rxName, timestamp: rxTimestamp, direction: MessageDirection.Received, type: rxType, remote: rxIsRmote, arbitrationId: rxArbId, data: rxData, documentation: rxDocumentation, description: rxDescription); if (!_paramters.FiltersEnabled || _filters.DoAddToTrace( arbitrationId: rxArbId, type: rxType, remote: rxIsRmote, direction: MessageDirection.Received)) { if (_paramters.TraceEnabled) { _messageTrace.Add(rxTrace); } } if (!_paramters.FiltersEnabled || _filters.DoAddToLog( arbitrationId: rxArbId, type: rxType, remote: rxIsRmote, direction: MessageDirection.Received)) { if (_paramters.LogEnabled) { _log.Messages.AddToStorage( name: rxName, timestamp: rxTimestamp, direction: MessageDirection.Received, type: rxType, arbitrationId: rxArbId, isRemote: rxIsRmote, data: rxData, documentation: rxDocumentation, description: rxDescription); } } if (_paramters.MessageStatisticsEnabled) { Action doMehtod = () =>/*SynContext*/ { _messageStat.InsertMessage( name: rxName, direction: MessageDirection.Received, type: rxType, arbitrationId: rxArbId, data: rxData, remote: rxIsRmote, timestamp: rxTimestamp); }; if (App.SyncContext != null) { App.SyncContext.Post((e1) => { doMehtod(); }, null); } else { doMehtod(); } } } if (_paramters.AdapterStatisticsEnabled) { /*Statiszitikai az adapter követi. Az értkékeket időnként le kell kérdezni tőle.*/ /*Az adapter leállítását követően még egyszer LE KELL KÉRDEZNI, hogy az UI-n az UTOLSÓ érték látszódjon.*/ long nowDateTimeTicks = DateTime.Now.Ticks; if ((nowDateTimeTicks - _statusUpdateTimestamp) > 10000 * 1000) { AppDiagService.WriteLine(GetType().Namespace + "." + GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "(): Adapter Staistics Poll Now... DiffTime: " + ((DateTime.Now.Ticks - _statusUpdateTimestamp) / 10000).ToString("N4") + "ms"); _statusUpdateTimestamp = nowDateTimeTicks; _adapterStat.UpdateReceived( total: _adapter.Attributes.RxTotal, drop: _adapter.Attributes.RxDrop, error: _adapter.Attributes.RxErrorCounter, pending: _adapter.Attributes.PendingRxMessages); _adapterStat.UpdateTransmitted( total: _adapter.Attributes.TxTotal, drop: _adapter.Attributes.TxDrop, error: _adapter.Attributes.TxErrorCounter, pending: _txQueue.Count); } } #endregion } catch (Exception ex) { Debug.WriteLine(GetType().Namespace + "." + GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "(): DoWork is now shutdown by Loop Fuction Exception."); loopException = ex; break; } } else { try { #region Virtual CAN Adapter Funcitions /*Virtuaális adapter*/ if (_txQueue.Count > 0) { _virtualAdapterFrameCounter++; var tx = _txQueue.Dequeue(); var txTrace = new MessageTraceItem( name: tx.Name, timestamp: DateTime.Now, direction: MessageDirection.Transmitted, type: tx.Type, remote: tx.Remote, arbitrationId: tx.ArbitrationId, data: tx.Data, documentation: tx.Documentation, description: tx.Description); if (!_paramters.FiltersEnabled || _filters.DoAddToTrace( arbitrationId: tx.ArbitrationId, type: tx.Type, remote: tx.Remote, direction: MessageDirection.Transmitted)) { if (_paramters.TraceEnabled) { _messageTrace.Add(txTrace); } } if (!_paramters.FiltersEnabled || _filters.DoAddToLog( arbitrationId: tx.ArbitrationId, type: tx.Type, remote: tx.Remote, direction: MessageDirection.Transmitted)) { if (_project.Parameters.LogEnabled) { _log.Messages.AddToStorage( name: tx.Name, timestamp: DateTime.Now, direction: MessageDirection.Transmitted, type: tx.Type, arbitrationId: tx.ArbitrationId, isRemote: tx.Remote, data: tx.Data, documentation: tx.Documentation, description: tx.Description); } } if (_paramters.MessageStatisticsEnabled) { Action doMehtod = () => { _messageStat.InsertMessage( name: tx.Name, direction: MessageDirection.Transmitted, type: tx.Type, arbitrationId: tx.ArbitrationId, data: tx.Data, remote: tx.Remote, timestamp: DateTime.Now); }; if (App.SyncContext != null) { App.SyncContext.Post((e1) => { doMehtod(); }, null); } else { doMehtod(); } } } if (_paramters.AdapterStatisticsEnabled) { /*Statiszitikai az adapter követi. Az értkékeket időnként le kell kérdezni tőle.*/ /*Az adapter leállítását követően még egyszer LE KELL KÉRDEZNI, hogy az UI-n az UTOLSÓ érték látszódjon.*/ long nowDateTimeTicks = DateTime.Now.Ticks; if ((nowDateTimeTicks - _statusUpdateTimestamp) > 10000 * 1000) { AppDiagService.WriteLine(GetType().Namespace + "." + GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "(): Virtual Adapter Staistics Poll Now... DiffTime: " + ((DateTime.Now.Ticks - _statusUpdateTimestamp) / 10000).ToString("N4") + "ms"); _statusUpdateTimestamp = nowDateTimeTicks; _adapterStat.UpdateTransmitted( total: _virtualAdapterFrameCounter, drop: 0, error: 0, pending: _txQueue.Count); } } #endregion } catch (Exception ex) { Debug.WriteLine(GetType().Namespace + "." + GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "(): DoWork is now shutdown by Loop Fuction Exception."); loopException = ex; break; } } if (_shutdownEvent.WaitOne(0)) { Debug.WriteLine(GetType().Namespace + "." + GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "(): DoWork is now shutdown!"); break; } } while (_isRunning); /*Probléma megjelnítése*/ if (loopException != null) { new ErrorHandlerService().Show(loopException); } #region Update Last State if (loopException == null) { /*Csak ha nem volt gebasz az adapterrel...*/ if (_paramters.DeviceName != VirtualDeviceName && _adapter.IsConnected) { /*Statisztika lefrissítése az UI-nak*/ _adapterStat.UpdateReceived( total: _adapter.Attributes.RxTotal, drop: _adapter.Attributes.RxDrop, error: _adapter.Attributes.RxErrorCounter, pending: _adapter.Attributes.PendingRxMessages); _adapterStat.UpdateTransmitted( total: _adapter.Attributes.TxTotal, drop: _adapter.Attributes.TxDrop, error: _adapter.Attributes.TxErrorCounter, pending: _txQueue.Count); _adapter.Disconnect(); } else { _adapterStat.UpdateTransmitted( total: _virtualAdapterFrameCounter, drop: 0, error: 0, pending: _txQueue.Count); } } #endregion #region Resource Freeing if (_adapter != null) { _adapter.Dispose(); _adapter = null; } // _messageSenders.Stop(); _readyToDisposeEvent.Set(); _isRunning = false; _toolTables.Stop(); #endregion #region Loop Terminate { /*SynContext*/ Action doMehtod = () => { try { if (_project.Parameters.LogEnabled) { _log.Messages.AddToStorageEnd(); _logFiles.Add(_log); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { /*Minden áron jelezni kell! hogy megállt.*/ OnStopped(); Debug.WriteLine(GetType().Namespace + "." + GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "(): Loop is colsed..."); } }; if (App.SyncContext != null) { App.SyncContext.Post((e1) => { doMehtod(); }, null); } else { doMehtod(); } } #endregion }