Commit 0b7f06c6 authored by Joachim Ehbrecht's avatar Joachim Ehbrecht
Browse files

improve CAN-parser

parent a81fb849
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -23,6 +23,12 @@ namespace VehicleBusDataInterpreter.UnitTest.Tests.Services;

public class VBDIServicesTests : TestsProjectBase
{
    #region Constants

    private const string VBMDI_NAME = "Easy";// "MEB_UNECE_150300"; //"IAV_Example";

    #endregion Constants

    #region Fields

    private static int _lastServerOption = -1;
@@ -95,9 +101,8 @@ public class VBDIServicesTests : TestsProjectBase
        
        CreateNotificationProcessor();

        string contextName = "MEB_UNECE_150300"; //"IAV_Example";
        return new VBDI( contextName,
                         GetSettings( contextName, types, serverOption ),
        return new VBDI( VBMDI_NAME,
                         GetSettings( VBMDI_NAME, types, serverOption ),
                         OnWorkStateChanged,
                         OnContentChanged );
    }
+1 −1
Original line number Diff line number Diff line
@@ -201,7 +201,7 @@ public class _02_VBDIServicesTests_LoadSave : VBDIServicesTests
    public void T0206_LoadSaveAllTypes_NoServer_1True2True3True() {
        #region Arrange scenario

        VBDI vbdiHandler = ArrangeScenario( serverOption: 0 );
        VBDI vbdiHandler = ArrangeScenario( VBDataSourceType.Can, 0 );
        if ( vbdiHandler?.Settings == null || vbdiHandler.Settings.Length == 0 )
            Assert.Inconclusive( this.TestContext.TestName + ": Arrange scenario failed." );

+6 −15
Original line number Diff line number Diff line
@@ -16,21 +16,6 @@
    <PackageReference Include="MSTest.TestFramework" Version="3.6.2" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Common">
      <HintPath>..\VehicleBusDataInterpreter\DLLs\Common.dll</HintPath>
    </Reference>
    <Reference Include="Common.UI">
      <HintPath>..\VehicleBusDataInterpreter\DLLs\Common.UI.dll</HintPath>
    </Reference>
    <Reference Include="Database">
      <HintPath>..\VehicleBusDataInterpreter\DLLs\Database.dll</HintPath>
    </Reference>
    <Reference Include="Database.Common">
      <HintPath>..\VehicleBusDataInterpreter\DLLs\Database.Common.dll</HintPath>
    </Reference>
    <Reference Include="DataProvider">
      <HintPath>..\VehicleBusDataInterpreter\DLLs\DataProvider.dll</HintPath>
    </Reference>
    <Reference Include="UnitTestBase">
      <HintPath>..\..\UnitTestBase\UnitTestBase\bin\Debug\net8.0-windows\UnitTestBase.dll</HintPath>
    </Reference>
@@ -38,6 +23,12 @@
      <HintPath>..\VehicleBusDataInterpreter\bin\Debug\net8.0-windows\VehicleBusDataInterpreter.dll</HintPath>
    </Reference>
  </ItemGroup>
	<ItemGroup>
		<ProjectReference Include="..\..\Common\Common\Common.csproj" />
		<ProjectReference Include="..\..\Database\Database\Database.csproj" />
		<ProjectReference Include="..\..\Database\Database.Common\Database.Common.csproj" />
		<ProjectReference Include="..\..\DataProvider\DataProvider\DataProvider.csproj" />
	</ItemGroup>
  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="&#xD;&#xA;:: ---------------------------------------------------------------------------&#xD;&#xA;:: --------------------++## Get DBServer libraries ##++--------------------&#xD;&#xA;&#xD;&#xA;set &quot;fileNameDBServer=Database.Server.&quot;&#xD;&#xA;set &quot;srcDirDBServer=$(SolutionDir)..\Database\Database.Server\$(OutDir)&quot;&#xD;&#xA;set &quot;dstDirDBServerUnitTest=$(TargetDir)&quot; &#xD;&#xA;copy /Y %25srcDirDBServer%25%25fileNameDBServer%25exe %25dstDirDBServerUnitTest%25%25fileNameDBServer%25exe&#xD;&#xA;if not $(TargetFramework) == net461 (&#xD;&#xA;    copy /Y %25srcDirDBServer%25%25fileNameDBServer%25dll %25dstDirDBServerUnitTest%25%25fileNameDBServer%25dll&#xD;&#xA;    copy /Y %25srcDirDBServer%25%25fileNameDBServer%25runtimeconfig.json %25dstDirDBServerUnitTest%25%25fileNameDBServer%25runtimeconfig.json&#xD;&#xA;)" />
  </Target>
+7 −5
Original line number Diff line number Diff line
@@ -17,15 +17,17 @@ public enum VBDITextMarker
    InterfaceIdPart3 = 3,

    /// <summary> The file content is parsed for the 'Resource'-text-marker. </summary>
    Resource = 11,
    ResourceStartIndex = 11,
    /// <summary> The file content is parsed for the 'Resource'-text-marker. </summary>
    Resource = 12,
    /// <summary> The file content is parsed for the 'Description'-text-marker for a Resource. </summary>
    ResourceDescription = 12,
    ResourceDescription = 13,
    /// <summary> The file content is parsed for the ResourceDescription related 'SendType'-text-marker. </summary>
    ResourceDescriptionSendType = 13,
    ResourceDescriptionSendType = 14,
    /// <summary> The file content is parsed for the ResourceDescription related 'CycleTime'-text-marker. </summary>
    ResourceDescriptionCycleTime = 14,
    ResourceDescriptionCycleTime = 15,
    /// <summary> The file content is parsed for the ResourceDescription related 'DelayTime'-text-marker. </summary>
    ResourceDescriptionDelayTime = 15,
    ResourceDescriptionDelayTime = 16,

    /// <summary> The file content is parsed for the 'Property'-text-marker. </summary>
    Property = 21,
+46 −18
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ public class CanParser : VBSourceFileParserBase
        { VBDITextMarker.InterfaceIdPart1, "BA_ " },
        { VBDITextMarker.InterfaceIdPart2, "\"DBName\"" },
        { VBDITextMarker.InterfaceIdPart3, "\nCM_ \"" },
        { VBDITextMarker.ResourceStartIndex, "\nBU_: " },
        { VBDITextMarker.Resource, "\nBO_ " },
        { VBDITextMarker.ResourceDescription, @"\nBA_ ""([a-zA-Z0-9]+)"" BO_ ([0-9]+) ([A-Za-z0-9]+);" },
        { VBDITextMarker.ResourceDescriptionSendType, "GenMsgSendType" },
@@ -106,40 +107,59 @@ public class CanParser : VBSourceFileParserBase
            return null;
        }

        string name = String.Empty;
        int startIndexName = indexFirstBA + tempFileContent[indexFirstBA..].IndexOf( this._canTextMarker[VBDITextMarker.InterfaceIdPart2] );
        if ( startIndexName < 0 )
        if ( startIndexName > 0 )
        {
            this._vbdi?.Msg?.RaiseMessageAvailable( this._vbdi._logContent.GetMsgEventArgs( new LogEntryId( LogLevel.Warning, 2001 ), new List<string>() { this._vbdi.ContextName, fileName } ) );
            return null;
        }

            startIndexName += this._canTextMarker[VBDITextMarker.InterfaceIdPart2].Length + 2;
        string name = tempFileContent.Slice( startIndexName, tempFileContent[startIndexName..].IndexOf( "\";" ) ).ToString();
            int stopIndexName = tempFileContent[startIndexName..].IndexOf( "\";" );

        int startIndexInterfaceId = tempFileContent.IndexOf( this._canTextMarker[VBDITextMarker.InterfaceIdPart3] );
        if ( startIndexInterfaceId < 0 )
            if ( stopIndexName > 0 )
            {
            this._vbdi?.Msg?.RaiseMessageAvailable( this._vbdi._logContent.GetMsgEventArgs( new LogEntryId( LogLevel.Warning, 2001 ), new List<string>() { this._vbdi.ContextName, fileName } ) );
            return null;
                name = tempFileContent.Slice( startIndexName, stopIndexName ).ToString();
            }
        }
        if ( String.IsNullOrEmpty( name ) )
        {
            name = this._vbdi.ContextName;
        }

        string interfaceIdContent = String.Empty;
        int startIndexInterfaceId = tempFileContent.IndexOf( this._canTextMarker[VBDITextMarker.InterfaceIdPart3] );
        if ( startIndexInterfaceId > 1 )
        {
            startIndexInterfaceId += 6;
        string interfaceIdContent = tempFileContent.Slice( startIndexInterfaceId, tempFileContent[( startIndexInterfaceId + 1 )..].IndexOf( "\";" ) ).ToString();
            int stopIndexInterfaceId = tempFileContent[( startIndexInterfaceId + 1 )..].IndexOf( "\";" );
            if ( stopIndexInterfaceId > 0 )
            {
                interfaceIdContent = tempFileContent.Slice( startIndexInterfaceId, stopIndexInterfaceId ).ToString();
                if ( String.IsNullOrEmpty( interfaceIdContent ) )
                {
                    this._vbdi?.Msg?.RaiseMessageAvailable( this._vbdi._logContent.GetMsgEventArgs( new LogEntryId( LogLevel.Warning, 2001 ), new List<string>() { this._vbdi.ContextName, fileName } ) );
                    return null;
                }

                interfaceIdContent = interfaceIdContent.Split( new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries ).Last();
        string platform = interfaceIdContent.Split( new char[] { ' ', '_' } ).First();
        string[] versionParts = interfaceIdContent[( platform.Length + 1 )..].Split( ' ' ).First().Replace( platform, String.Empty ).Trim( new char[] { ' ', '_', 'v', 'V', 'f', 'F' } ).Split( '.' );
            }
        }

        string platform = String.Empty;
        string[] versionParts = Array.Empty<string>();
        if ( String.IsNullOrEmpty( interfaceIdContent ) )
        {
            platform = this._vbdi.ContextName + "CAN";
        }
        else
        {
            platform = interfaceIdContent.Split( new char[] { ' ', '_' } ).First();
            versionParts = interfaceIdContent[( platform.Length + 1 )..].Split( ' ' ).First().Replace( platform, String.Empty ).Trim( new char[] { ' ', '_', 'v', 'V', 'f', 'F' } ).Split( '.' );
        }

        if ( versionParts.Length >= 2 )
            return new VBDataEntityId( VBDataSourceType.Can, name, platform, versionParts[0] + "." + versionParts[1] );
        else if ( versionParts.Length == 1 )
            return new VBDataEntityId( VBDataSourceType.Can, name, platform, versionParts[0] );
        else
            return new VBDataEntityId( VBDataSourceType.Can, name, platform, "0.1" );
            return new VBDataEntityId( VBDataSourceType.Can, name, platform, "1.0.0" );
    }

    #region Resources
@@ -151,8 +171,16 @@ public class CanParser : VBSourceFileParserBase
    /// <returns> The from file content parsed Resources, or 'null', if the related Task is canceled or any error has been occurred. </returns>
    private VBDataEntity GetCanResources( VBDataEntity vbDataEntity,
                                          string fileContent ) {
        int startIndexResource = 0;
        int startIndexResource = fileContent.IndexOf( this._canTextMarker[VBDITextMarker.ResourceStartIndex] );
        if ( startIndexResource < 0 )
        {
            this._vbdi?.Msg?.RaiseMessageAvailable( this._vbdi._logContent.GetMsgEventArgs( new LogEntryId( LogLevel.Warning, 2001 ), new List<string>() { this._vbdi.ContextName } ) );
            return null;
        }
        startIndexResource = fileContent.IndexOf( '\n', startIndexResource + 1 );
        int stopIndexAllResources = fileContent.IndexOf( this._canTextMarker[VBDITextMarker.InterfaceIdPart2] );
        if ( stopIndexAllResources < 0 )
            stopIndexAllResources = fileContent.Length;
        Dictionary<long, VBDataEntityResource> resources = new();
        while ( startIndexResource >= 0 && startIndexResource < stopIndexAllResources && this._vbdi != null && !this._vbdi.IsCanceled() )
        {