From e276d85c5a4a652261d42a08fe0534968c6b048b Mon Sep 17 00:00:00 2001 From: Jakob Date: Sun, 14 Sep 2025 22:00:45 +0200 Subject: [PATCH 01/92] add git ignore --- .gitignore | 399 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 399 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fbe19f --- /dev/null +++ b/.gitignore @@ -0,0 +1,399 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd +/z21Client/.idea/.idea.z21Client.dir/.idea/workspace.xml + + +# Common IntelliJ Platform excludes + +# User specific +**/.idea/**/workspace.xml +**/.idea/**/tasks.xml +**/.idea/shelf/* +**/.idea/dictionaries +**/.idea/httpRequests/ + +# Sensitive or high-churn files +**/.idea/**/dataSources/ +**/.idea/**/dataSources.ids +**/.idea/**/dataSources.xml +**/.idea/**/dataSources.local.xml +**/.idea/**/sqlDataSources.xml +**/.idea/**/dynamic.xml + +# Rider +# Rider auto-generates .iml files, and contentModel.xml +**/.idea/**/*.iml +**/.idea/**/contentModel.xml +**/.idea/**/modules.xml + +*.suo +*.user +.vs/ +[Bb]in/ +[Oo]bj/ +_UpgradeReport_Files/ +[Pp]ackages/ + +Thumbs.db +Desktop.ini +.DS_Store \ No newline at end of file From 660c206f1e73e9d8f6842c39008fda83f738df8c Mon Sep 17 00:00:00 2001 From: Jakob Date: Sun, 14 Sep 2025 22:02:22 +0200 Subject: [PATCH 02/92] add git ignore --- .idea/.idea.Z21Client/.idea/.gitignore | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .idea/.idea.Z21Client/.idea/.gitignore diff --git a/.idea/.idea.Z21Client/.idea/.gitignore b/.idea/.idea.Z21Client/.idea/.gitignore new file mode 100644 index 0000000..58e934f --- /dev/null +++ b/.idea/.idea.Z21Client/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/projectSettingsUpdater.xml +/.idea.Z21Client.iml +/contentModel.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml From 0629152108520d2a5fbb37f3293494f382556d41 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sun, 14 Sep 2025 22:06:17 +0200 Subject: [PATCH 03/92] add git ignore --- {.idea/.idea.Z21Client => src/.idea/.idea.Z21}/.idea/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {.idea/.idea.Z21Client => src/.idea/.idea.Z21}/.idea/.gitignore (100%) diff --git a/.idea/.idea.Z21Client/.idea/.gitignore b/src/.idea/.idea.Z21/.idea/.gitignore similarity index 100% rename from .idea/.idea.Z21Client/.idea/.gitignore rename to src/.idea/.idea.Z21/.idea/.gitignore From 5d45b2aacea419c130d23735e906b1df6a37d6d3 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sun, 14 Sep 2025 22:06:26 +0200 Subject: [PATCH 04/92] add code --- LICENSE | 674 ++++++++++++++++++ README.md | 61 +- src/.idea/.idea.Z21/.idea/.name | 1 + src/.idea/.idea.Z21/.idea/indexLayout.xml | 8 + src/.idea/.idea.Z21/.idea/vcs.xml | 6 + .../Command/Driving/GetLocoInfoCommandTest.cs | 24 + .../Command/Driving/PurgeLocoCommandTest.cs | 18 + .../Driving/SetLocoDriveCommandTest.cs | 29 + .../Driving/SetLocoEStopCommandTest.cs | 18 + .../Driving/SetLocoFunctionCommandTest.cs | 18 + .../Settings/GetAccessoryModeCommandTest.cs | 23 + .../Settings/GetLocoModeCommandTest.cs | 24 + .../Settings/SetAccessoryModeCommandTest.cs | 33 + .../Settings/SetLocoModeCommandTest.cs | 33 + .../GetExtAccessoryInfoCommandTest.cs | 24 + .../Switching/GetTurnoutInfoCommandTest.cs | 24 + .../Switching/SetExtAccessoryCommandTest.cs | 49 ++ .../Switching/SetTurnoutCommandTest.cs | 25 + .../GetBroadcastFlagsCommandTest.cs | 22 + .../Command/SystemState/GetCodeCommandTest.cs | 22 + .../GetFirmwareVersionCommandTest.cs | 25 + .../SystemState/GetHardwareInfoCommandTest.cs | 22 + .../SystemState/GetSerialNumberCommandTest.cs | 22 + .../SystemState/GetStatusCommandTest.cs | 23 + .../GetSystemStateDataCommandTest.cs | 14 + .../SystemState/GetVersionCommandTest.cs | 23 + .../Command/SystemState/LogOffCommandTest.cs | 22 + .../SetBroadcastFlagsCommandTest.cs | 29 + .../TrackPower/SetStopCommandTest.cs | 22 + .../TrackPower/SetTrackPowerOffCommandTest.cs | 23 + .../TrackPower/SetTrackPowerOnCommandTest.cs | 23 + .../LocoSpeedOutOfRangeExceptionTest.cs | 26 + .../MtuPayloadLengthExceededExceptionTest.cs | 30 + .../Core/Helper/AddressHelperTest.cs | 57 ++ .../Core/Helper/LocoSpeedHelperTest.cs | 122 ++++ .../SwitchDecoderPayloadTest.cs | 21 + .../Driving/LocoInfoResponseHandlerTest.cs | 81 +++ .../AccessoryModeResponseHandlerTest.cs | 62 ++ .../Settings/LocoModeResponseHandlerTest.cs | 63 ++ .../ExtAccessoryInfoResponseHandlerTest.cs | 61 ++ .../TurnoutInfoResponseHandlerTest.cs | 62 ++ .../BroadcastFlagsResponseHandlerTest.cs | 57 ++ .../FirmwareVersionResponseHandlerTest.cs | 60 ++ .../HardwareInfoResponseHandlerTest.cs | 60 ++ .../SerialNumberResponseHandlerTest.cs | 55 ++ .../SoftwareLockResponseHandlerTest.cs | 59 ++ .../StatusChangedResponseHandlerTest.cs | 75 ++ ...stemStateDataChangedResponseHandlerTest.cs | 68 ++ .../ProgrammingModeResponseHandlerTest.cs | 58 ++ .../TrackPower/StoppedResponseHandlerTest.cs | 58 ++ .../TrackPowerOffResponseHandlerTest.cs | 58 ++ .../TrackPowerOnResponseHandlerTest.cs | 58 ++ .../UnknownCommandResponseHandlerTest.cs | 57 ++ .../SystemState/VersionResponseHandlerTest.cs | 66 ++ .../CapabilitiesResponseParserTest.cs | 50 ++ .../CentralStateExResponseParserTest.cs | 38 + .../CentralStateResponseParserTest.cs | 39 + .../SystemStateResponseParserTest.cs | 59 ++ src/Z21.Client.UnitTest/Core/Z21ClientTest.cs | 7 + .../Z21.Client.UnitTest.csproj | 30 + .../Command/CliGetFirmwareVersionCommand.cs | 21 + .../Command/CliSetTrackPowerCommand.cs | 49 ++ src/Z21.Console/Program.cs | 64 ++ src/Z21.Console/Z21.Console.csproj | 27 + .../Z21.DependencyInjection.UnitTest.csproj | 30 + .../Z21DependencyInjectionExtensionTest.cs | 35 + src/Z21.DependencyInjection/LICENSE | 674 ++++++++++++++++++ .../Z21.DependencyInjection.csproj | 27 + .../Z21DependencyInjectionExtension.cs | 86 +++ src/Z21.sln | 71 ++ .../.idea.z21Client.dir/.idea/encodings.xml | 4 + .../.idea.z21Client.dir/.idea/indexLayout.xml | 8 + .../.idea/projectSettingsUpdater.xml | 7 + .../.idea/.idea.z21Client.dir/.idea/vcs.xml | 6 + .../.idea/.idea.z21Client/.idea/.gitignore | 13 + .../.idea.z21Client/.idea/indexLayout.xml | 8 + .../.idea/.idea.z21Client/.idea/vcs.xml | 6 + .../Command/Driving/GetLocoInfoCommand.cs | 35 + .../Core/Command/Driving/PurgeLocoCommand.cs | 31 + .../Command/Driving/SetLocoDriveCommand.cs | 47 ++ .../Command/Driving/SetLocoEStopCommand.cs | 32 + .../Command/Driving/SetLocoFunctionCommand.cs | 34 + src/Z21Client/Core/Command/IZ21Command.cs | 12 + .../Settings/GetAccessoryModeCommand.cs | 34 + .../Command/Settings/GetLocoModeCommand.cs | 34 + .../Settings/SetAccessoryModeCommand.cs | 36 + .../Command/Settings/SetLocoModeCommand.cs | 36 + .../Switching/GetExtAccessoryInfoCommand.cs | 29 + .../Switching/GetTurnoutInfoCommand.cs | 30 + .../Switching/SetExtAccessoryCommand.cs | 46 ++ .../Command/Switching/SetTurnoutCommand.cs | 40 ++ .../SystemState/GetBroadcastFlagsCommand.cs | 18 + .../SystemState/GetFirmwareVersionCommand.cs | 21 + .../SystemState/GetHardwareInfoCommand.cs | 18 + .../SystemState/GetSerialNumberCommand.cs | 18 + .../SystemState/GetSoftwareLockCommand.cs | 19 + .../Command/SystemState/GetStatusCommand.cs | 19 + .../SystemState/GetSystemStateDataCommand.cs | 18 + .../Command/SystemState/GetVersionCommand.cs | 19 + .../Core/Command/SystemState/LogOffCommand.cs | 18 + .../SystemState/SetBroadcastFlagsCommand.cs | 32 + .../SystemState/TrackPower/SetStopCommand.cs | 18 + .../TrackPower/SetTrackPowerOffCommand.cs | 19 + .../TrackPower/SetTrackPowerOnCommand.cs | 19 + .../Exception/ClientNotConnectedException.cs | 9 + .../Exception/LocoSpeedOutOfRangeException.cs | 24 + .../MtuPayloadLengthExceededException.cs | 13 + src/Z21Client/Core/Helper/AddressHelper.cs | 35 + src/Z21Client/Core/Helper/LocoSpeedHelper.cs | 73 ++ src/Z21Client/Core/IZ21Client.cs | 24 + src/Z21Client/Core/Model/AccessoryOutput.cs | 11 + src/Z21Client/Core/Model/AccessoryState.cs | 12 + src/Z21Client/Core/Model/Capabilities.cs | 44 ++ src/Z21Client/Core/Model/CentralState.cs | 34 + src/Z21Client/Core/Model/CentralStateEx.cs | 40 ++ src/Z21Client/Core/Model/DccSpeedMode.cs | 22 + src/Z21Client/Core/Model/DecoderMode.cs | 20 + src/Z21Client/Core/Model/DrivingDirection.cs | 11 + .../BroadcastFlagsReceivedEventArgs.cs | 7 + .../EventArgs/ConnectionChangedEventArgs.cs | 7 + .../EventArgs/DecoderModeReceivedEventArgs.cs | 9 + .../ExtAccessoryInfoReceivedEventArgs.cs | 11 + .../FirmwareVersionReceivedEventArgs.cs | 9 + .../Model/EventArgs/HardwareInfoEventArgs.cs | 7 + .../EventArgs/LocoInfoReceivedEventArgs.cs | 9 + .../EventArgs/ResponseReceivedEventArgs.cs | 7 + .../SerialNumberReceivedEventArgs.cs | 7 + .../SoftwareLockReceivedEventArgs.cs | 7 + .../StatusChangedReceivedEventArgs.cs | 7 + .../SystemStatusChangedReceivedEventArgs.cs | 7 + .../EventArgs/TurnoutInfoReceivedEventArgs.cs | 13 + .../UnknownCommandReceivedEventArgs.cs | 7 + .../EventArgs/VersionReceivedEventArgs.cs | 9 + .../IExcAccessoryPayload.cs | 8 + .../SwitchDecoderPayload.cs | 26 + src/Z21Client/Core/Model/FirmwareVersion.cs | 13 + .../Core/Model/FunctionToggleType.cs | 12 + src/Z21Client/Core/Model/LocoFunctionData.cs | 17 + src/Z21Client/Core/Model/LocoInfoData.cs | 25 + src/Z21Client/Core/Model/SystemState.cs | 62 ++ src/Z21Client/Core/Model/Z21BroadcastFlags.cs | 31 + src/Z21Client/Core/Model/Z21Configuration.cs | 53 ++ src/Z21Client/Core/Model/Z21HardwareType.cs | 62 ++ src/Z21Client/Core/Model/Z21SoftwareLock.cs | 20 + .../Driving/LocoInfoResponseHandler.cs | 103 +++ .../ResponseHandler/IZ21ResponseHandler.cs | 21 + .../Settings/AccessoryModeResponseHandler.cs | 50 ++ .../Settings/LocoModeResponseHandler.cs | 49 ++ .../ExtAccessoryInfoResponseHandler.cs | 48 ++ .../Switching/TurnoutInfoResponseHandler.cs | 55 ++ .../BroadcastFlagsResponseHandler.cs | 39 + .../FirmwareVersionResponseHandler.cs | 49 ++ .../HardwareInfoResponseHandler.cs | 41 ++ .../SerialNumberResponseHandler.cs | 40 ++ .../SoftwareLockResponseHandler.cs | 38 + .../StatusChangedResponseHandler.cs | 47 ++ .../SystemStateDataChangedResponseHandler.cs | 42 ++ .../ProgrammingModeResponseHandler.cs | 40 ++ .../TrackPower/StoppedResponseHandler.cs | 43 ++ .../TrackPowerOffResponseHandler.cs | 43 ++ .../TrackPower/TrackPowerOnResponseHandler.cs | 43 ++ .../TrackPower/TrackShortResponseHandler.cs | 42 ++ .../UnknownCommandResponseHandler.cs | 41 ++ .../SystemState/VersionResponseHandler.cs | 43 ++ .../CapabilitiesResponseParser.cs | 28 + .../CentralStateExResponseParser.cs | 24 + .../CentralStateResponseParser.cs | 23 + .../Core/ResponseParser/IZ21ResponseParser.cs | 7 + .../SystemStateResponseParser.cs | 30 + src/Z21Client/Core/Z21Client.cs | 183 +++++ src/Z21Client/Extension/StructExtension.cs | 9 + src/Z21Client/LICENSE | 674 ++++++++++++++++++ src/Z21Client/Transport/IZ21Transport.cs | 19 + src/Z21Client/Transport/Z21Transport.cs | 55 ++ src/Z21Client/Z21.Client.csproj | 30 + src/Z21Client/Z21.Client.csproj.DotSettings | 2 + 176 files changed, 7673 insertions(+), 1 deletion(-) create mode 100644 LICENSE create mode 100644 src/.idea/.idea.Z21/.idea/.name create mode 100644 src/.idea/.idea.Z21/.idea/indexLayout.xml create mode 100644 src/.idea/.idea.Z21/.idea/vcs.xml create mode 100644 src/Z21.Client.UnitTest/Core/Command/Driving/GetLocoInfoCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Driving/PurgeLocoCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoDriveCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoEStopCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoFunctionCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Settings/GetAccessoryModeCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Settings/GetLocoModeCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Settings/SetAccessoryModeCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Settings/SetLocoModeCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Switching/GetExtAccessoryInfoCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Switching/GetTurnoutInfoCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Switching/SetExtAccessoryCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/Switching/SetTurnoutCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/GetBroadcastFlagsCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/GetCodeCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/GetFirmwareVersionCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/GetHardwareInfoCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/GetSerialNumberCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/GetStatusCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/GetSystemStateDataCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/GetVersionCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/LogOffCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/SetBroadcastFlagsCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetStopCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommandTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Exception/LocoSpeedOutOfRangeExceptionTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Exception/MtuPayloadLengthExceededExceptionTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Helper/AddressHelperTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Helper/LocoSpeedHelperTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Model/ExcAccessoryPayload/SwitchDecoderPayloadTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/Driving/LocoInfoResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/Settings/AccessoryModeResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/Settings/LocoModeResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/Switching/TurnoutInfoResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/HardwareInfoResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SerialNumberResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SoftwareLockResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/StatusChangedResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/UnknownCommandResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/VersionResponseHandlerTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseParser/CapabilitiesResponseParserTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseParser/CentralStateExResponseParserTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseParser/CentralStateResponseParserTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/ResponseParser/SystemStateResponseParserTest.cs create mode 100644 src/Z21.Client.UnitTest/Core/Z21ClientTest.cs create mode 100644 src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj create mode 100644 src/Z21.Console/Command/CliGetFirmwareVersionCommand.cs create mode 100644 src/Z21.Console/Command/CliSetTrackPowerCommand.cs create mode 100644 src/Z21.Console/Program.cs create mode 100644 src/Z21.Console/Z21.Console.csproj create mode 100644 src/Z21.DependencyInjection.UnitTest/Z21.DependencyInjection.UnitTest.csproj create mode 100644 src/Z21.DependencyInjection.UnitTest/Z21DependencyInjectionExtensionTest.cs create mode 100644 src/Z21.DependencyInjection/LICENSE create mode 100644 src/Z21.DependencyInjection/Z21.DependencyInjection.csproj create mode 100644 src/Z21.DependencyInjection/Z21DependencyInjectionExtension.cs create mode 100644 src/Z21.sln create mode 100644 src/Z21Client/.idea/.idea.z21Client.dir/.idea/encodings.xml create mode 100644 src/Z21Client/.idea/.idea.z21Client.dir/.idea/indexLayout.xml create mode 100644 src/Z21Client/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml create mode 100644 src/Z21Client/.idea/.idea.z21Client.dir/.idea/vcs.xml create mode 100644 src/Z21Client/.idea/.idea.z21Client/.idea/.gitignore create mode 100644 src/Z21Client/.idea/.idea.z21Client/.idea/indexLayout.xml create mode 100644 src/Z21Client/.idea/.idea.z21Client/.idea/vcs.xml create mode 100644 src/Z21Client/Core/Command/Driving/GetLocoInfoCommand.cs create mode 100644 src/Z21Client/Core/Command/Driving/PurgeLocoCommand.cs create mode 100644 src/Z21Client/Core/Command/Driving/SetLocoDriveCommand.cs create mode 100644 src/Z21Client/Core/Command/Driving/SetLocoEStopCommand.cs create mode 100644 src/Z21Client/Core/Command/Driving/SetLocoFunctionCommand.cs create mode 100644 src/Z21Client/Core/Command/IZ21Command.cs create mode 100644 src/Z21Client/Core/Command/Settings/GetAccessoryModeCommand.cs create mode 100644 src/Z21Client/Core/Command/Settings/GetLocoModeCommand.cs create mode 100644 src/Z21Client/Core/Command/Settings/SetAccessoryModeCommand.cs create mode 100644 src/Z21Client/Core/Command/Settings/SetLocoModeCommand.cs create mode 100644 src/Z21Client/Core/Command/Switching/GetExtAccessoryInfoCommand.cs create mode 100644 src/Z21Client/Core/Command/Switching/GetTurnoutInfoCommand.cs create mode 100644 src/Z21Client/Core/Command/Switching/SetExtAccessoryCommand.cs create mode 100644 src/Z21Client/Core/Command/Switching/SetTurnoutCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/GetBroadcastFlagsCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/GetFirmwareVersionCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/GetHardwareInfoCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/GetSerialNumberCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/GetSoftwareLockCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/GetStatusCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/GetSystemStateDataCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/GetVersionCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/LogOffCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/SetBroadcastFlagsCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/TrackPower/SetStopCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs create mode 100644 src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs create mode 100644 src/Z21Client/Core/Exception/ClientNotConnectedException.cs create mode 100644 src/Z21Client/Core/Exception/LocoSpeedOutOfRangeException.cs create mode 100644 src/Z21Client/Core/Exception/MtuPayloadLengthExceededException.cs create mode 100644 src/Z21Client/Core/Helper/AddressHelper.cs create mode 100644 src/Z21Client/Core/Helper/LocoSpeedHelper.cs create mode 100644 src/Z21Client/Core/IZ21Client.cs create mode 100644 src/Z21Client/Core/Model/AccessoryOutput.cs create mode 100644 src/Z21Client/Core/Model/AccessoryState.cs create mode 100644 src/Z21Client/Core/Model/Capabilities.cs create mode 100644 src/Z21Client/Core/Model/CentralState.cs create mode 100644 src/Z21Client/Core/Model/CentralStateEx.cs create mode 100644 src/Z21Client/Core/Model/DccSpeedMode.cs create mode 100644 src/Z21Client/Core/Model/DecoderMode.cs create mode 100644 src/Z21Client/Core/Model/DrivingDirection.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/ConnectionChangedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/HardwareInfoEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/ResponseReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs create mode 100644 src/Z21Client/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs create mode 100644 src/Z21Client/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs create mode 100644 src/Z21Client/Core/Model/FirmwareVersion.cs create mode 100644 src/Z21Client/Core/Model/FunctionToggleType.cs create mode 100644 src/Z21Client/Core/Model/LocoFunctionData.cs create mode 100644 src/Z21Client/Core/Model/LocoInfoData.cs create mode 100644 src/Z21Client/Core/Model/SystemState.cs create mode 100644 src/Z21Client/Core/Model/Z21BroadcastFlags.cs create mode 100644 src/Z21Client/Core/Model/Z21Configuration.cs create mode 100644 src/Z21Client/Core/Model/Z21HardwareType.cs create mode 100644 src/Z21Client/Core/Model/Z21SoftwareLock.cs create mode 100644 src/Z21Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/IZ21ResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs create mode 100644 src/Z21Client/Core/ResponseParser/CapabilitiesResponseParser.cs create mode 100644 src/Z21Client/Core/ResponseParser/CentralStateExResponseParser.cs create mode 100644 src/Z21Client/Core/ResponseParser/CentralStateResponseParser.cs create mode 100644 src/Z21Client/Core/ResponseParser/IZ21ResponseParser.cs create mode 100644 src/Z21Client/Core/ResponseParser/SystemStateResponseParser.cs create mode 100644 src/Z21Client/Core/Z21Client.cs create mode 100644 src/Z21Client/Extension/StructExtension.cs create mode 100644 src/Z21Client/LICENSE create mode 100644 src/Z21Client/Transport/IZ21Transport.cs create mode 100644 src/Z21Client/Transport/Z21Transport.cs create mode 100644 src/Z21Client/Z21.Client.csproj create mode 100644 src/Z21Client/Z21.Client.csproj.DotSettings diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e72bfdd --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/README.md b/README.md index b8fabbf..95b9bcb 100644 --- a/README.md +++ b/README.md @@ -1 +1,60 @@ -# Z21 +# Z21 [![](https://github.com/Jakob-Eichberger/z21Client/actions/workflows/dotnet.yml/badge.svg?branch=master)](https://github.com/Jakob-Eichberger/z21Client/actions/workflows/dotnet.yml) + +The **Z21 client** library is a C# library for interfacing with the Roco and Fleischmann [Z21 Digital Command Center (DCC)](https://www.z21.eu/). It allows you to control trains, functions, and eventually signals/switches using the Z21 protocol. The library is available as a [NuGet package](https://www.nuget.org/packages/Z21/) for easy integration into your project. + +## Features + +- **Train Control**: Send commands to control locomotives, set speed, direction, and read locomotive status. +- **Function Control**: Activate and deactivate functions (lights, sound, etc.) on locomotives. +- **Signal/Switch Control (Planned)**: Future enhancements will include support for controlling signals and switches on your layout. + +## Getting Started + +1. **Installation**: Install the `Z21` NuGet package in your project. + + ```bash + Install-Package Z21 + ``` + +2. **Initialization**: + + ```csharp + using Z21; + + // Initialize the Z21 client + var client = new Client(); + client.Connect(IPAddress.Parse("192.168.1.111")); // Replace with your Z21 IP address + ``` + +3. **Train Control**: + + ```csharp + // Set locomotive speed + client.SetLocoDrive(new LokInfoData() { Adresse = new(1), Speed = 10, DrivingDirection = true }); // Locomotive address 1, speed 50, direction forward + + // Get locomotive speed + client.OnGetLocoInfo += Client_OnGetLocoInfo; // Subscribe to the specific event + void Client_OnGetLocoInfo(object? sender, Z21.Events.GetLocoInfoEventArgs e) // GetLocoInfoEventArgs contains address, speed, direction, and function states + client.GetLocoInfo(new LokAdresse(2)); // Call GetLocoInfo() to pull the data from the z21 and distribute it on the event bus + ``` + +4. **Function Control**: + + ```csharp + // Activate function F1 (e.g., lights) + client.SetLocoFunction(new FunctionData(1, 0, Z21.Enums.ToggleType.Off));; // Locomotive address 1, function F1 + + // Deactivate function F1 + client.SetLocoFunction(new FunctionData(1, 0, Z21.Enums.ToggleType.On));; // Locomotive address 1, function F1 + + // Toggle function F1 + client.SetLocoFunction(new FunctionData(1, 0, Z21.Enums.ToggleType.Toggle));; // Locomotive address 1, function F1 + ``` + +## Contributing + +Contributions are welcome! If you encounter any issues or have suggestions, please open an issue or submit a pull request. + +## License + +This project is licensed under the MIT License - see the LICENSE file for details. diff --git a/src/.idea/.idea.Z21/.idea/.name b/src/.idea/.idea.Z21/.idea/.name new file mode 100644 index 0000000..0d736d4 --- /dev/null +++ b/src/.idea/.idea.Z21/.idea/.name @@ -0,0 +1 @@ +Z21 \ No newline at end of file diff --git a/src/.idea/.idea.Z21/.idea/indexLayout.xml b/src/.idea/.idea.Z21/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/src/.idea/.idea.Z21/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/.idea/.idea.Z21/.idea/vcs.xml b/src/.idea/.idea.Z21/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/src/.idea/.idea.Z21/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Driving/GetLocoInfoCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Driving/GetLocoInfoCommandTest.cs new file mode 100644 index 0000000..7dfad7c --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Driving/GetLocoInfoCommandTest.cs @@ -0,0 +1,24 @@ +using Z21.Core.Command.Driving; + +namespace Z21.UnitTest.Core.Command.Driving +{ + public class GetLocoInfoCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetLocoInfoCommand command = new(3); + Assert.That(command.Data, + Is.EqualTo(new byte[] + { + 0x09, 0x00, + 0x40, 0x00, + 0xE3, + 0xF0, + 0x00, + 0x03, + 0x10 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Driving/PurgeLocoCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Driving/PurgeLocoCommandTest.cs new file mode 100644 index 0000000..7d46fb0 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Driving/PurgeLocoCommandTest.cs @@ -0,0 +1,18 @@ +using Z21.Core.Command.Driving; + +namespace Z21.UnitTest.Core.Command.Driving +{ + public class PurgeLocoCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + PurgeLocoCommand getSerialNumberCommand = new(3); + Assert.That(getSerialNumberCommand.Data, + Is.EqualTo(new byte[] + { + 0x09, 0x00, 0x40, 0x00, 0xE3, 0x44, 0x00, 0x03, 0xA4, + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoDriveCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoDriveCommandTest.cs new file mode 100644 index 0000000..1e281ed --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoDriveCommandTest.cs @@ -0,0 +1,29 @@ +using Z21.Core.Command.Driving; +using Z21.Core.Exception; +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Command.Driving +{ + public class SetLocoDriveCommandTest + { + [Test] + [TestCase(DccSpeedMode.Steps14, (ushort)15)] + [TestCase(DccSpeedMode.Steps28, (ushort)29)] + [TestCase(DccSpeedMode.Steps128, (ushort)127)] + public void Ctor_SpeedOutOfRange_ThrowsLocoSpeedOutOfRangeException(DccSpeedMode dccSpeedMode, ushort locoSpeed) + { + Assert.Throws(() => _ = new SetLocoDriveCommand(dccSpeedMode, 0, DrivingDirection.Forward, locoSpeed)); + } + + [Test] + [TestCase(DccSpeedMode.Steps128, (ushort)20, DrivingDirection.Forward, (ushort)1, new byte[] { 0x0A, 0x00, 0x40, 0x00, 0xE4, 0x13, 0x00, 0x14, 0x82, 0x61 })] + [TestCase(DccSpeedMode.Steps28, (ushort)101, DrivingDirection.Backward, (ushort)2, new byte[] { 0x0A, 0x00, 0x40, 0x00, 0xE4, 0x12, 0x00, 0x65, 0x12, 0x81 })] + [TestCase(DccSpeedMode.Steps28, (ushort)101, DrivingDirection.Backward, (ushort)3, new byte[] { 0x0A, 0x00, 0x40, 0x00, 0xE4, 0x12, 0x00, 0x65, 0x03, 0x90 })] + [TestCase(DccSpeedMode.Steps14, (ushort)130, DrivingDirection.Backward, (ushort)1, new byte[] { 0x0A, 0x00, 0x40, 0x00, 0xE4, 0x10, 0xC0, 0x82, 0x2, 0xB4 })] + public void Ctor_SetsCorrectDataBits(DccSpeedMode dccSpeedMode, ushort locoAddress, DrivingDirection drivingDirection, ushort locoSpeed, byte[] data) + { + SetLocoDriveCommand command = new(dccSpeedMode, locoAddress, drivingDirection, locoSpeed); + Assert.That(command.Data, Is.EqualTo(data)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoEStopCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoEStopCommandTest.cs new file mode 100644 index 0000000..42ce1dc --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoEStopCommandTest.cs @@ -0,0 +1,18 @@ +using Z21.Core.Command.Driving; + +namespace Z21.UnitTest.Core.Command.Driving +{ + public class SetLocoEStopCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + SetLocoEStopCommand getSerialNumberCommand = new(3); + Assert.That(getSerialNumberCommand.Data, + Is.EqualTo(new byte[] + { + 0x08, 0x00, 0x40, 0x00, 0x92, 0x00, 0x03, 0x91 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoFunctionCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoFunctionCommandTest.cs new file mode 100644 index 0000000..60d475b --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Driving/SetLocoFunctionCommandTest.cs @@ -0,0 +1,18 @@ +using Z21.Core.Command.Driving; +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Command.Driving +{ + public class SetLocoFunctionCommandTest + { + [Test] + [TestCase((ushort)20, (ushort)0, FunctionToggleType.Off, new byte[] { 0x0A, 0x00, 0x40, 0x00, 0xE4, 0xF8, 0x00, 0x14, 0x00, 0x08 })] + [TestCase((ushort)125, (ushort)31, FunctionToggleType.On, new byte[] { 0x0A, 0x00, 0x40, 0x00, 0xE4, 0xF8, 0x00, 0x7D, 0x5F, 0x3E })] + [TestCase((ushort)16, (ushort)5, FunctionToggleType.Toggle, new byte[] { 0x0A, 0x00, 0x40, 0x00, 0xE4, 0xF8, 0x00, 0x10, 0x85, 0x89 })] + public void Ctor_SetsCorrectDataBits(ushort locoAddress, ushort functionIndex, FunctionToggleType toggleType, byte[] data) + { + SetLocoFunctionCommand command = new(locoAddress, functionIndex, toggleType); + Assert.That(command.Data, Is.EqualTo(data)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Settings/GetAccessoryModeCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Settings/GetAccessoryModeCommandTest.cs new file mode 100644 index 0000000..86bddfd --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Settings/GetAccessoryModeCommandTest.cs @@ -0,0 +1,23 @@ +using Z21.Core.Command.Settings; + +namespace Z21.UnitTest.Core.Command.Settings +{ + public class GetAccessoryModeCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetAccessoryModeCommand command = new(24); + Assert.That(command.Data, + Is.EqualTo(new byte[] + { + 0x06, + 0x00, + 0x70, + 0x00, + 0x00, + 0x18 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Settings/GetLocoModeCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Settings/GetLocoModeCommandTest.cs new file mode 100644 index 0000000..bb78b7a --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Settings/GetLocoModeCommandTest.cs @@ -0,0 +1,24 @@ +using Z21.Core.Command.Settings; + +namespace Z21.UnitTest.Core.Command.Settings +{ + public class GetLocoModeCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetLocoModeCommand command = new(24); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x06, + 0x00, + 0x60, + 0x00, + 0x00, + 0x18 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Settings/SetAccessoryModeCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Settings/SetAccessoryModeCommandTest.cs new file mode 100644 index 0000000..9ec317a --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Settings/SetAccessoryModeCommandTest.cs @@ -0,0 +1,33 @@ +using Z21.Core.Command.Settings; +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Command.Settings +{ + public class SetAccessoryModeCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits([Values(DecoderMode.DCC, DecoderMode.MM)] DecoderMode decoderMode) + { + SetAccessoryModeCommand command = new(12, decoderMode); + Assert.That(command.Data, + Is.EqualTo(new byte[] + { + 0x07, + 0x00, + 0x71, + 0x00, + 0x00, + 0x0C, + (byte)decoderMode + })); + } + + [Test] + public void Ctor_LocoModeUnknown_ThrowsArgumentException() + { + ArgumentException? exception = Assert.Throws(() => _ = new SetAccessoryModeCommand(12, DecoderMode.Unknown)); + Assert.That(exception, Is.Not.Null); + Assert.That(exception.Message, Is.EqualTo($"{DecoderMode.Unknown} is not a valid DecoderMode. (Parameter 'decoderMode')")); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Settings/SetLocoModeCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Settings/SetLocoModeCommandTest.cs new file mode 100644 index 0000000..9a1a967 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Settings/SetLocoModeCommandTest.cs @@ -0,0 +1,33 @@ +using Z21.Core.Command.Settings; +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Command.Settings +{ + public class SetLocoModeCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits([Values(DecoderMode.DCC, DecoderMode.MM)] DecoderMode decoderMode) + { + SetLocoModeCommand command = new(12, decoderMode); + Assert.That(command.Data, + Is.EqualTo(new byte[] + { + 0x07, + 0x00, + 0x61, + 0x00, + 0x00, + 0x0C, + (byte)decoderMode + })); + } + + [Test] + public void Ctor_LocoModeUnknown_ThrowsArgumentException() + { + ArgumentException? exception = Assert.Throws(() => _ = new SetLocoModeCommand(12, DecoderMode.Unknown)); + Assert.That(exception, Is.Not.Null); + Assert.That(exception.Message, Is.EqualTo($"{DecoderMode.Unknown} is not a valid DecoderMode. (Parameter 'decoderMode')")); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Switching/GetExtAccessoryInfoCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Switching/GetExtAccessoryInfoCommandTest.cs new file mode 100644 index 0000000..87f80cc --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Switching/GetExtAccessoryInfoCommandTest.cs @@ -0,0 +1,24 @@ +using Z21.Core.Command.Switching; + +namespace Z21.UnitTest.Core.Command.Switching +{ + public class GetExtAccessoryInfoCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetExtAccessoryInfoCommand command = new(15); + Assert.That(command.Data, + Is.EqualTo(new byte[] + { + 0x9, 0x0, + 0x40, 0x0, + 0x44, + 0x0, + 0xE, + 0x0, + 0x4A + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Switching/GetTurnoutInfoCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Switching/GetTurnoutInfoCommandTest.cs new file mode 100644 index 0000000..7e72dc7 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Switching/GetTurnoutInfoCommandTest.cs @@ -0,0 +1,24 @@ +using Z21.Core.Command.Switching; + +namespace Z21.UnitTest.Core.Command.Switching +{ + public class GetTurnoutInfoCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetTurnoutInfoCommand command = new(15); + Assert.That(command.Data, + Is.EqualTo(new byte[] + { + 0x08, 0x00, 0x40, 0x00, 0x43, 0x00, 0x0E, 0x4D + })); + } + + [Test] + public void Ctor_AccessoryAddressIs0_ThrowsArgumentOutOfRangeException() + { + Assert.Throws(() => _ = new GetTurnoutInfoCommand(0)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Switching/SetExtAccessoryCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Switching/SetExtAccessoryCommandTest.cs new file mode 100644 index 0000000..6c478f2 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Switching/SetExtAccessoryCommandTest.cs @@ -0,0 +1,49 @@ +using Z21.Core.Command.Switching; +using Z21.Core.Model.ExcAccessoryPayload; + +namespace Z21.UnitTest.Core.Command.Switching +{ + public class SetExtAccessoryCommandTest + { + public class ExcAccessoryPayloadDummy(byte payload) : IExcAccessoryPayload + { + public byte Payload { get; } = payload; + } + + [Test] + public void Ctor_WithPayload_SetsCorrectDataBits() + { + SetExtAccessoryCommand command = new(15, new ExcAccessoryPayloadDummy(0x52)); + Assert.That(command.Data, + Is.EqualTo(new byte[] + { + 0xA, 0x0, + 0x40, 0x0, + 0x54, + 0x0, + 0xE, + 0x52, + 0x0, + 0x8 + })); + } + + [Test] + public void Ctor_SetsCorrectDataBits() + { + SetExtAccessoryCommand command = new(15, 0x62); + Assert.That(command.Data, + Is.EqualTo(new byte[] + { + 0xA, 0x0, + 0x40, 0x0, + 0x54, + 0x0, + 0xE, + 0x62, + 0x0, + 0x38 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/Switching/SetTurnoutCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/Switching/SetTurnoutCommandTest.cs new file mode 100644 index 0000000..2d6c3af --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/Switching/SetTurnoutCommandTest.cs @@ -0,0 +1,25 @@ +using Z21.Core.Command.Switching; +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Command.Switching +{ + public class SetTurnoutCommandTest + { + [Test] + [TestCase((ushort)16, AccessoryOutput.Output1, AccessoryState.Activate, true, new byte[] { 0x09, 0x00, 0x40, 0x00, 0x53, 0x00, 0x0F, 0xA8, 0xF4 })] + [TestCase((ushort)8, AccessoryOutput.Output2, AccessoryState.Activate, true, new byte[] { 0x09, 0x00, 0x40, 0x00, 0x53, 0x00, 0x07, 0xA9, 0xFD })] + [TestCase((ushort)8, AccessoryOutput.Output2, AccessoryState.Deactivate, true, new byte[] { 0x09, 0x00, 0x40, 0x00, 0x53, 0x00, 0x07, 0xA1, 0xF5 })] + [TestCase((ushort)8, AccessoryOutput.Output2, AccessoryState.Deactivate, false, new byte[] { 0x09, 0x00, 0x40, 0x00, 0x53, 0x00, 0x07, 0x81, 0xD5 })] + public void Ctor_SetsCorrectDataBits(ushort accessoryAddress, AccessoryOutput accessoryOutput, AccessoryState accessoryState, bool executeImmediately, byte[] data) + { + SetTurnoutCommand command = new(accessoryAddress, accessoryOutput, accessoryState, executeImmediately); + Assert.That(command.Data, Is.EqualTo(data)); + } + + [Test] + public void Ctor_AccessoryAddressIs0_ThrowsArgumentOutOfRangeException() + { + Assert.Throws(() => _ = new SetTurnoutCommand(0, AccessoryOutput.Output1, AccessoryState.Activate, false)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/GetBroadcastFlagsCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetBroadcastFlagsCommandTest.cs new file mode 100644 index 0000000..844f84b --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetBroadcastFlagsCommandTest.cs @@ -0,0 +1,22 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class GetBroadcastFlagsCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetBroadcastFlagsCommand getSerialNumberCommand = new(); + Assert.That( + getSerialNumberCommand.Data, Is.EqualTo( + new byte[] + { + 0x04, + 0x00, + 0x51, + 0x00 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/GetCodeCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetCodeCommandTest.cs new file mode 100644 index 0000000..bf96598 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetCodeCommandTest.cs @@ -0,0 +1,22 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class GetSoftwareLockCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetSoftwareLockCommand command = new(); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x04, + 0x00, + 0x18, + 0x00 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/GetFirmwareVersionCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetFirmwareVersionCommandTest.cs new file mode 100644 index 0000000..0021cc3 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetFirmwareVersionCommandTest.cs @@ -0,0 +1,25 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class GetFirmwareVersionCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetFirmwareVersionCommand getSerialNumberCommand = new(); + Assert.That( + getSerialNumberCommand.Data, Is.EqualTo( + new byte[] + { + 0x07, + 0x00, + 0x40, + 0x00, + 0xF1, + 0x0A, + 0xFB + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/GetHardwareInfoCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetHardwareInfoCommandTest.cs new file mode 100644 index 0000000..639e781 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetHardwareInfoCommandTest.cs @@ -0,0 +1,22 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class GetHardwareInfoCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetHardwareInfoCommand command = new(); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x04, + 0x00, + 0x1A, + 0x00 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/GetSerialNumberCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetSerialNumberCommandTest.cs new file mode 100644 index 0000000..e72f9f1 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetSerialNumberCommandTest.cs @@ -0,0 +1,22 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class GetSerialNumberCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetSerialNumberCommand getSerialNumberCommand = new(); + Assert.That( + getSerialNumberCommand.Data, Is.EqualTo( + new byte[] + { + 0x04, + 0x00, + 0x10, + 0x00 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/GetStatusCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetStatusCommandTest.cs new file mode 100644 index 0000000..68dfdb6 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetStatusCommandTest.cs @@ -0,0 +1,23 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class GetStatusCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + GetStatusCommand command = new(); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x07, 0x00, + 0x40, 0x00, + 0x21, + 0x24, + 0x05 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/GetSystemStateDataCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetSystemStateDataCommandTest.cs new file mode 100644 index 0000000..a9e4679 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetSystemStateDataCommandTest.cs @@ -0,0 +1,14 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class GetSystemStateDataCommandTest + { + [Test] + public void Ctor_SetsDataCorrectly() + { + GetSystemStateDataCommand command = new(); + Assert.That(command.Data, Is.EqualTo(new byte[] { 0x04, 0x00, 0x85, 0x00 })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/GetVersionCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetVersionCommandTest.cs new file mode 100644 index 0000000..c229eb0 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/GetVersionCommandTest.cs @@ -0,0 +1,23 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class GetVersionCommandTest + { + [Test] + public void Ctor_SetsDataCorrectly() + { + GetVersionCommand command = new(); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x07, 0x00, + 0x40, 0x00, + 0x21, + 0x21, + 0x00 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/LogOffCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/LogOffCommandTest.cs new file mode 100644 index 0000000..089af1c --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/LogOffCommandTest.cs @@ -0,0 +1,22 @@ +using Z21.Core.Command.SystemState; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class LogOffCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + LogOffCommand command = new(); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x04, + 0x00, + 0x30, + 0x00 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/SetBroadcastFlagsCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/SetBroadcastFlagsCommandTest.cs new file mode 100644 index 0000000..5eecfa8 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/SetBroadcastFlagsCommandTest.cs @@ -0,0 +1,29 @@ +using Z21.Core.Command.SystemState; +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Command.SystemState +{ + public class SetBroadcastFlagsCommandTest + { + [Test] + public void Ctor_SetsCorrectDataBits() + { + SetBroadcastFlagsCommand command = new( + Z21BroadcastFlags.DriveAndSwitchingMessages, + Z21BroadcastFlags.RailComDataChangedMessages); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x08, + 0x0, + 0x50, + 0x0, + 0x5, + 0x0, + 0x0, + 0x0 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetStopCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetStopCommandTest.cs new file mode 100644 index 0000000..88cbd22 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetStopCommandTest.cs @@ -0,0 +1,22 @@ +using Z21.Core.Command.SystemState.TrackPower; + +namespace Z21.UnitTest.Core.Command.SystemState.TrackPower +{ + public class SetStopCommandTest + { + [Test] + public void Ctor_SetsDataCorrectly() + { + SetStopCommand command = new(); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x06, 0x00, + 0x40, 0x00, + 0x80, + (0 ^ 0x80) + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommandTest.cs new file mode 100644 index 0000000..270d62a --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommandTest.cs @@ -0,0 +1,23 @@ +using Z21.Core.Command.SystemState.TrackPower; + +namespace Z21.UnitTest.Core.Command.SystemState.TrackPower +{ + public class SetTrackPowerOffCommandTest + { + [Test] + public void Ctor_SetsDataCorrectly() + { + SetTrackPowerOffCommand command = new(); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x07, 0x00, + 0x40, 0x00, + 0x21, + 0x80, + 0xa1 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommandTest.cs b/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommandTest.cs new file mode 100644 index 0000000..8e0bf50 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommandTest.cs @@ -0,0 +1,23 @@ +using Z21.Core.Command.SystemState.TrackPower; + +namespace Z21.UnitTest.Core.Command.SystemState.TrackPower +{ + public class SetTrackPowerOnCommandTest + { + [Test] + public void Ctor_SetDataCorrectly() + { + SetTrackPowerOnCommand command = new(); + Assert.That( + command.Data, Is.EqualTo( + new byte[] + { + 0x07, 0x00, + 0x40, 0x00, + 0x21, + 0x81, + 0xa0 + })); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Exception/LocoSpeedOutOfRangeExceptionTest.cs b/src/Z21.Client.UnitTest/Core/Exception/LocoSpeedOutOfRangeExceptionTest.cs new file mode 100644 index 0000000..d9ecc84 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Exception/LocoSpeedOutOfRangeExceptionTest.cs @@ -0,0 +1,26 @@ +using Z21.Core.Exception; +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Exception +{ + public class LocoSpeedOutOfRangeExceptionTest + { + [Test] + [TestCase(DccSpeedMode.Steps14, (ushort)14)] + [TestCase(DccSpeedMode.Steps28, (ushort)28)] + [TestCase(DccSpeedMode.Steps128, (ushort)126)] + public void ThrowIfOutOfRange_ValuesInRange_DoesNothing(DccSpeedMode dccSpeedMode, ushort locoSpeed) + { + Assert.DoesNotThrow(() => LocoSpeedOutOfRangeException.ThrowIfOutOfRange(dccSpeedMode, locoSpeed)); + } + + [Test] + [TestCase(DccSpeedMode.Steps14, (ushort)15)] + [TestCase(DccSpeedMode.Steps28, (ushort)29)] + [TestCase(DccSpeedMode.Steps128, (ushort)127)] + public void ThrowIfOutOfRange_ValuesOutOfRange_ThrowsLocoSpeedOutOfRangeException(DccSpeedMode dccSpeedMode, ushort locoSpeed) + { + Assert.Throws(() => LocoSpeedOutOfRangeException.ThrowIfOutOfRange(dccSpeedMode, locoSpeed)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Exception/MtuPayloadLengthExceededExceptionTest.cs b/src/Z21.Client.UnitTest/Core/Exception/MtuPayloadLengthExceededExceptionTest.cs new file mode 100644 index 0000000..4d6a0c9 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Exception/MtuPayloadLengthExceededExceptionTest.cs @@ -0,0 +1,30 @@ +using Z21.Core; +using Z21.Core.Exception; + +namespace Z21.UnitTest.Core.Exception +{ + public class MtuPayloadLengthExceededExceptionTest + { + [Test] + public void ThrowIfExceeded_DatagramSmallerThenMaxUdpPayload_DoNothing() + { + byte[] datagram = new byte [Z21Client.MaxUdpPayload - 1]; + Assert.DoesNotThrow(() => MtuPayloadLengthExceededException.ThrowIfExceeded(datagram)); + } + + [Test] + public void ThrowIfExceeded_DatagramEqualMaxUdpPayload_DoNothing() + { + byte[] datagram = new byte [Z21Client.MaxUdpPayload]; + Assert.DoesNotThrow(() => MtuPayloadLengthExceededException.ThrowIfExceeded(datagram)); + } + + [Test] + public void ThrowIfExceeded_DatagramBiggerThenMaxUdpPayload_ThrowMtuPayloadLengthExceededException() + { + byte[] datagram = new byte [Z21Client.MaxUdpPayload + 1]; + MtuPayloadLengthExceededException exception = Assert.Throws(() => MtuPayloadLengthExceededException.ThrowIfExceeded(datagram)); + Assert.That(exception.Message, Is.EqualTo($"Combined UDP payload length '{datagram.Length}' exceeds MTU size '{Z21Client.MaxUdpPayload}'.")); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Helper/AddressHelperTest.cs b/src/Z21.Client.UnitTest/Core/Helper/AddressHelperTest.cs new file mode 100644 index 0000000..0fa495e --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Helper/AddressHelperTest.cs @@ -0,0 +1,57 @@ +using Z21.Core.Helper; + +namespace Z21.UnitTest.Core.Helper +{ + public class AddressHelperTest + { + [Test] + [TestCase((ushort)0, 0x00, 0x00)] + [TestCase((ushort)1, 0x01, 0x00)] + [TestCase((ushort)255, 0xFF, 0x00)] + [TestCase((ushort)256, 0x00, 0x01)] + [TestCase((ushort)512, 0x00, 0x02)] + [TestCase((ushort)1023, 0xFF, 0x03)] + [TestCase((ushort)1234, 0xD2, 0x04)] + [TestCase((ushort)16383, 0xFF, 0x3F)] + public void SplitLocoAddress_ReturnsCorrectLSBAndMSB(ushort input, byte expectedLsb, byte expectedMsb) + { + (byte lsb, byte msb) = AddressHelper.SplitLocoAddress(input); + + if (input >= 128) + expectedMsb |= 0xC0; + + Assert.Multiple(() => + { + Assert.That(lsb, Is.EqualTo(expectedLsb), "LSB is incorrect"); + Assert.That(msb, Is.EqualTo(expectedMsb), "MSB is incorrect"); + }); + } + + [Test] + public void SplitAccessoryAddress_ReturnsCorrectLSBAndMSB() + { + (byte lsb, byte msb) = AddressHelper.SplitAccessoryAddress(48); + Assert.Multiple(() => + { + Assert.That((msb << 8) + lsb, Is.EqualTo(47)); + Assert.That(msb, Is.EqualTo(0x00)); + Assert.That(lsb, Is.EqualTo(0x2F)); + }); + } + + [Test] + public void SplitAccessoryAddress_AddressIs0_ThrowsArgumentOutOfRangeException() + { + Assert.Throws(() => AddressHelper.SplitAccessoryAddress(0)); + } + + [Test] + public void CombineAccessoryAddress_ReturnsCorrectAddress() + { + const byte msb = 0x00; + const byte lsb = 0x2f; + ushort address = AddressHelper.CombineAccessoryAddress(lsb, msb); + Assert.That(address, Is.EqualTo(48)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Helper/LocoSpeedHelperTest.cs b/src/Z21.Client.UnitTest/Core/Helper/LocoSpeedHelperTest.cs new file mode 100644 index 0000000..24d5f0d --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Helper/LocoSpeedHelperTest.cs @@ -0,0 +1,122 @@ +using Z21.Core.Helper; +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Helper +{ + public class LocoSpeedHelperTest + { + + [Test] + [TestCase((ushort)0, (ushort)0)] + [TestCase((ushort)1, (ushort)2)] + [TestCase((ushort)2, (ushort)3)] + [TestCase((ushort)13, (ushort)14)] + public void CalculateDccSpeed_Dcc14(ushort speedStep, ushort dccSpeed) + { + Assert.That(LocoSpeedHelper.CalculateDccSpeed(DccSpeedMode.Steps14, speedStep), Is.EqualTo(dccSpeed)); + } + + [Test] + [TestCase((ushort)0, (ushort)0)] + [TestCase((ushort)1, (ushort)2)] + [TestCase((ushort)2, (ushort)3)] + [TestCase((ushort)127, (ushort)128)] + public void CalculateDccSpeed_Dcc128(ushort speedStep, ushort dccSpeed) + { + Assert.That(LocoSpeedHelper.CalculateDccSpeed(DccSpeedMode.Steps128, speedStep), Is.EqualTo(dccSpeed)); + } + + [Test] + [TestCase((ushort)0, (ushort)0)] + [TestCase((ushort)1, (ushort)2)] + [TestCase((ushort)2, (ushort)18)] + [TestCase((ushort)3, (ushort)3)] + [TestCase((ushort)4, (ushort)19)] + [TestCase((ushort)5, (ushort)4)] + [TestCase((ushort)6, (ushort)20)] + [TestCase((ushort)7, (ushort)5)] + [TestCase((ushort)8, (ushort)21)] + [TestCase((ushort)9, (ushort)6)] + [TestCase((ushort)10, (ushort)22)] + [TestCase((ushort)11, (ushort)7)] + [TestCase((ushort)12, (ushort)23)] + [TestCase((ushort)13, (ushort)8)] + [TestCase((ushort)14, (ushort)24)] + [TestCase((ushort)15, (ushort)9)] + [TestCase((ushort)16, (ushort)25)] + [TestCase((ushort)17, (ushort)10)] + [TestCase((ushort)18, (ushort)26)] + [TestCase((ushort)19, (ushort)11)] + [TestCase((ushort)20, (ushort)27)] + [TestCase((ushort)21, (ushort)12)] + [TestCase((ushort)22, (ushort)28)] + [TestCase((ushort)23, (ushort)13)] + [TestCase((ushort)24, (ushort)29)] + [TestCase((ushort)25, (ushort)14)] + [TestCase((ushort)26, (ushort)30)] + [TestCase((ushort)27, (ushort)15)] + [TestCase((ushort)28, (ushort)31)] + public void CalculateDccSpeed_Dcc28(ushort speedStep, ushort dccSpeed) + { + Assert.That(LocoSpeedHelper.CalculateDccSpeed(DccSpeedMode.Steps28, speedStep), Is.EqualTo(dccSpeed)); + } + + + [TestCase((ushort)0, (ushort)0)] + [TestCase((ushort)1, (ushort)0)] + [TestCase((ushort)2, (ushort)1)] + [TestCase((ushort)13, (ushort)12)] + public void CalculateSpeedStep_Dcc14(ushort dccSpeed, ushort speedStep) + { + Assert.That(LocoSpeedHelper.CalculateSpeedStep(DccSpeedMode.Steps14, dccSpeed), Is.EqualTo(speedStep)); + } + + [TestCase((ushort)0, (ushort)0)] + [TestCase((ushort)1, (ushort)0)] + [TestCase((ushort)2, (ushort)1)] + [TestCase((ushort)129, (ushort)128)] + public void CalculateSpeedStep_Dcc128(ushort dccSpeed, ushort speedStep) + { + Assert.That(LocoSpeedHelper.CalculateSpeedStep(DccSpeedMode.Steps128, dccSpeed), Is.EqualTo(speedStep)); + } + + + [Test] + [TestCase(0, 0)] + [TestCase(16, 0)] + [TestCase(1, 0)] + [TestCase(17, 0)] + [TestCase(2, 1)] + [TestCase(18, 2)] + [TestCase(3, 3)] + [TestCase(19, 4)] + [TestCase(4, 5)] + [TestCase(20, 6)] + [TestCase(5, 7)] + [TestCase(21, 8)] + [TestCase(6, 9)] + [TestCase(22, 10)] + [TestCase(7, 11)] + [TestCase(23, 12)] + [TestCase(8, 13)] + [TestCase(24, 14)] + [TestCase(9, 15)] + [TestCase(25, 16)] + [TestCase(10, 17)] + [TestCase(26, 18)] + [TestCase(11, 19)] + [TestCase(27, 20)] + [TestCase(12, 21)] + [TestCase(28, 22)] + [TestCase(13, 23)] + [TestCase(29, 24)] + [TestCase(14, 25)] + [TestCase(30, 26)] + [TestCase(15, 27)] + [TestCase(31, 28)] + public void CalculateSpeedStep_Dcc28(short dccSpeed, short speedStep) + { + Assert.That(LocoSpeedHelper.CalculateSpeedStep(DccSpeedMode.Steps28, (ushort)dccSpeed), Is.EqualTo((ushort)speedStep), $"Dcc Speed: {dccSpeed}. Expected speed step: {speedStep}"); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Model/ExcAccessoryPayload/SwitchDecoderPayloadTest.cs b/src/Z21.Client.UnitTest/Core/Model/ExcAccessoryPayload/SwitchDecoderPayloadTest.cs new file mode 100644 index 0000000..c688c55 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Model/ExcAccessoryPayload/SwitchDecoderPayloadTest.cs @@ -0,0 +1,21 @@ +using Z21.Core.Model; +using Z21.Core.Model.ExcAccessoryPayload; + +namespace Z21.UnitTest.Core.Model.ExcAccessoryPayload +{ + public class SwitchDecoderPayloadTest + { + [Test] + public void Ctor_CalculatesPayloadCorrectly() + { + SwitchDecoderPayload payload = new(AccessoryOutput.Output1, 10); + Assert.That(payload.Payload, Is.EqualTo(0xA)); + } + + [Test] + public void Ctor_SwitchTimeBiggerThen127_ThrowsArgumentOutOfRangeException() + { + Assert.Throws(() => _ = new SwitchDecoderPayload(AccessoryOutput.Output1, 128)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/Driving/LocoInfoResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/Driving/LocoInfoResponseHandlerTest.cs new file mode 100644 index 0000000..1b99441 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/Driving/LocoInfoResponseHandlerTest.cs @@ -0,0 +1,81 @@ +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler.Driving; + +namespace Z21.UnitTest.Core.ResponseHandler.Driving +{ + public class LocoInfoResponseHandlerTest + { + private LocoInfoResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x0F, 0x00, 0x40, 0x00, 0xEF, 0x00, 0x03, 0x02, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x0F, 0x00, 0x41, 0x00, 0xEF, 0x00, 0x03, 0x02, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + //TODO add even more tests. + [Test] + [TestCase(3, + DccSpeedMode.Steps28, + DecoderMode.DCC, + DrivingDirection.Forward, + (ushort)11, + false, + false, + false, + new byte[] { 0x0F, 0x00, 0x40, 0x00, 0xEF, 0x00, 0x03, 0x02, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69 })] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs(short locoAddress, DccSpeedMode dccSpeedMode, DecoderMode decoderMode, DrivingDirection drivingDirection, ushort locoSpeed, bool locoIsBusy, + bool locoContainedInDoubleTraction, bool smartSearch, byte[] response) + { + LocoInfoReceivedEventArgs? receivedArgs = null; + LocoInfoResponseHandler? handler = null; + _handler.OnLocoInfoReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as LocoInfoResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + + Assert.That(receivedArgs.Data.LocoAddress, Is.EqualTo(locoAddress)); + Assert.That(receivedArgs.Data.DccSpeedMode, Is.EqualTo(dccSpeedMode)); + Assert.That(receivedArgs.Data.DecoderMode, Is.EqualTo(decoderMode)); + Assert.That(receivedArgs.Data.DrivingDirection, Is.EqualTo(drivingDirection)); + Assert.That(receivedArgs.Data.LocoSpeed, Is.EqualTo(locoSpeed)); + Assert.That(receivedArgs.Data.LocoIsBusy, Is.EqualTo(locoIsBusy)); + Assert.That(receivedArgs.Data.LocoContainedInDoubleTraction, Is.EqualTo(locoContainedInDoubleTraction)); + Assert.That(receivedArgs.Data.SmartSearch, Is.EqualTo(smartSearch)); + + Assert.That(receivedArgs.Data.LocoFunctionsData.All(data => data.FunctionToggleType == FunctionToggleType.Off), Is.True); + + List index = receivedArgs.Data.LocoFunctionsData.Select(data => data.FunctionIndex).Distinct().ToList(); + Assert.That(index, Has.Count.EqualTo(29)); + Assert.That(index.Min(), Is.EqualTo(0)); + Assert.That(index.Max(), Is.EqualTo(28)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/Settings/AccessoryModeResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/Settings/AccessoryModeResponseHandlerTest.cs new file mode 100644 index 0000000..3cd9a30 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/Settings/AccessoryModeResponseHandlerTest.cs @@ -0,0 +1,62 @@ +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler.Settings; + +namespace Z21.UnitTest.Core.ResponseHandler.Settings +{ + public class AccessoryModeResponseHandlerTest + { + private AccessoryModeResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x07, 0x00, 0x70, 0x00, 0x00, 0x0C, 0x00]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x07, 0x00, 0x71, 0x00, 0x00, 0x0C, 0x00 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + [TestCase(0x00, DecoderMode.DCC)] + [TestCase(0x01, DecoderMode.MM)] + [TestCase(0x05, DecoderMode.Unknown)] + [TestCase(0x24, DecoderMode.Unknown)] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs(byte modeByte, DecoderMode modeEnum) + { + byte[] response = [0x07, 0x00, 0x70, 0x00, 0x00, 0x0C, modeByte]; + + DecoderModeReceivedEventArgs? receivedArgs = null; + AccessoryModeResponseHandler? handler = null; + _handler.OnAccessoryModeReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as AccessoryModeResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.LocoAddress, Is.EqualTo(12)); + Assert.That(receivedArgs.Mode, Is.EqualTo(modeEnum)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/Settings/LocoModeResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/Settings/LocoModeResponseHandlerTest.cs new file mode 100644 index 0000000..a15c072 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/Settings/LocoModeResponseHandlerTest.cs @@ -0,0 +1,63 @@ +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler.Settings; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.UnitTest.Core.ResponseHandler.Settings +{ + public class LocoModeResponseHandlerTest + { + private LocoModeResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x07, 0x00, 0x60, 0x00, 0x00, 0x0C, 0x00]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x07, 0x00, 0x61, 0x00, 0x00, 0x0C, 0x00 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + [TestCase(0x00, DecoderMode.DCC)] + [TestCase(0x01, DecoderMode.MM)] + [TestCase(0x05, DecoderMode.Unknown)] + [TestCase(0x24, DecoderMode.Unknown)] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs(byte modeByte, DecoderMode modeEnum) + { + byte[] response = [0x07, 0x00, 0x60, 0x00, 0x00, 0x0C, modeByte]; + + DecoderModeReceivedEventArgs? receivedArgs = null; + LocoModeResponseHandler? handler = null; + _handler.OnLocoModeReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as LocoModeResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.LocoAddress, Is.EqualTo(12)); + Assert.That(receivedArgs.Mode, Is.EqualTo(modeEnum)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandlerTest.cs new file mode 100644 index 0000000..b22fdb6 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandlerTest.cs @@ -0,0 +1,61 @@ +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler.Switching; + +namespace Z21.UnitTest.Core.ResponseHandler.Switching +{ + public class ExtAccessoryInfoResponseHandlerTest + { + private ExtAccessoryInfoResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x0A, 0x00, 0x40, 0x00, 0x44, 0x00, 0x2F, 0x00, 0x00, 0x6B]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x0A, 0x00, 0x40, 0x01, 0x44, 0x00, 0x2F, 0x00, 0x00, 0x6B }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + [TestCase(0x00, 0x00, true)] + [TestCase(0x06, 0x99, false)] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs(byte db2, byte db3, bool validData) + { + byte[] response = [0x0A, 0x00, 0x40, 0x00, 0x44, 0x00, 0x2F, db2, db3, 0x6B]; + + ExtAccessoryInfoReceivedEventArgs? receivedArgs = null; + ExtAccessoryInfoResponseHandler? handler = null; + _handler.OnExtAccessoryInfoReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as ExtAccessoryInfoResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.AccessoryAddress, Is.EqualTo(48)); + Assert.That(receivedArgs.EncodedState, Is.EqualTo(db2)); + Assert.That(receivedArgs.DataValid, Is.EqualTo(validData)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/Switching/TurnoutInfoResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/Switching/TurnoutInfoResponseHandlerTest.cs new file mode 100644 index 0000000..547d5c4 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/Switching/TurnoutInfoResponseHandlerTest.cs @@ -0,0 +1,62 @@ +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler.Switching; + +namespace Z21.UnitTest.Core.ResponseHandler.Switching +{ + public class TurnoutInfoResponseHandlerTest + { + private TurnoutInfoResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x09, 0x00, 0x40, 0x00, 0x43, 0x00, 0x0E, 0x01, 0x4C]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x09, 0x00, 0x41, 0x00, 0x43, 0x00, 0x0E, 0x01, 0x4C }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + [TestCase(0x00, null)] + [TestCase(0x03, null)] + [TestCase(0x01, AccessoryOutput.Output1)] + [TestCase(0x02, AccessoryOutput.Output2)] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs(byte db2, AccessoryOutput? accessoryOutput) + { + byte[] response = [0x09, 0x00, 0x40, 0x00, 0x43, 0x00, 0x40, db2, 0x01]; + + TurnoutInfoReceivedEventArgs? receivedArgs = null; + TurnoutInfoResponseHandler? handler = null; + _handler.OnTurnoutInfoReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as TurnoutInfoResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.AccessoryAddress, Is.EqualTo(65)); + Assert.That(receivedArgs.AccessoryOutput, Is.EqualTo(accessoryOutput)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandlerTest.cs new file mode 100644 index 0000000..d7111a6 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandlerTest.cs @@ -0,0 +1,57 @@ +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + public class BroadcastFlagsResponseHandlerTest + { + private BroadcastFlagsResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x51, 0x00]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x52, 0x00 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x08, 0x00, 0x51, 0x00, 0x01, 0x00, 0x01, 0x00]; + + BroadcastFlagsReceivedEventArgs? receivedArgs = null; + BroadcastFlagsResponseHandler? handler = null; + _handler.OnBroadcastFlagsReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as BroadcastFlagsResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.BroadCastFlag, Is.EqualTo(65537)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandlerTest.cs new file mode 100644 index 0000000..370ba82 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandlerTest.cs @@ -0,0 +1,60 @@ +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + public class FirmwareVersionResponseHandlerTest + { + private FirmwareVersionResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x40, 0x00, 0xf3, 0x0a, 0x01, 0x23, 0xdb]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x23, 0x0a, 0x01, 0x23, 0xdb }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x00, 0x00, 0x40, 0x00, 0xf3, 0x0a, 0x01, 0x23, 0xdb]; + + FirmwareVersionReceivedEventArgs? receivedArgs = null; + FirmwareVersionResponseHandler? handler = null; + _handler.OnFirmwareVersionReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as FirmwareVersionResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.FirmwareVersion, Is.Not.Null); + Assert.That(receivedArgs.FirmwareVersion.Major, Is.EqualTo(1)); + Assert.That(receivedArgs.FirmwareVersion.Minor, Is.EqualTo(23)); + Assert.That(receivedArgs.FirmwareVersion.Firmware, Is.EqualTo("1.23")); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/HardwareInfoResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/HardwareInfoResponseHandlerTest.cs new file mode 100644 index 0000000..0593acf --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/HardwareInfoResponseHandlerTest.cs @@ -0,0 +1,60 @@ +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + //Test response from z21: 0C-00-1A-00-04-02-00-00-43-01-00-00 + + public class HardwareInfoResponseHandlerTest + { + private HardwareInfoResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x0C, 0x00, 0x1A, 0x00, 0x04, 0x02, 0x00, 0x00, 0x43, 0x01, 0x00, 0x00]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x0C, 0x00, 0x1A, 0x01, 0x04, 0x02, 0x00, 0x00, 0x43, 0x01, 0x00, 0x00 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x0C, 0x00, 0x1A, 0x00, 0x04, 0x02, 0x00, 0x00, 0x43, 0x01, 0x00, 0x00]; + + HardwareInfoEventArgs? receivedArgs = null; + HardwareInfoResponseHandler? handler = null; + _handler.OnHardwareInfoReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as HardwareInfoResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.Z21HardwareType, Is.EqualTo(Z21HardwareType.z21Start)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SerialNumberResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SerialNumberResponseHandlerTest.cs new file mode 100644 index 0000000..5453f39 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SerialNumberResponseHandlerTest.cs @@ -0,0 +1,55 @@ +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + public class SerialNumberResponseHandlerTest + { + private SerialNumberResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] response = new byte[8]; + response[2] = 0x10; + response[3] = 0x00; + + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x11, 0x00 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectSerialNumber() + { + byte[] response = new byte[8]; + const uint expectedSerial = 123456789; + BitConverter.GetBytes(expectedSerial).CopyTo(response, 4); + + SerialNumberReceivedEventArgs? receivedArgs = null; + + _handler.OnSerialNumberReceived += (sender, args) => { receivedArgs = args; }; + + _handler.Handle(response); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.SerialNumber, Is.EqualTo(expectedSerial)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SoftwareLockResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SoftwareLockResponseHandlerTest.cs new file mode 100644 index 0000000..de789a3 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SoftwareLockResponseHandlerTest.cs @@ -0,0 +1,59 @@ +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + //response from z21: 05-00-18-00-02 + public class SoftwareLockResponseHandlerTest + { + private SoftwareLockResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x05, 0x00, 0x18, 0x00, 0x02]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x05, 0x00, 0x17, 0x00, 0x02 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x05, 0x00, 0x18, 0x00, 0x02]; + + SoftwareLockReceivedEventArgs? receivedArgs = null; + SoftwareLockResponseHandler? handler = null; + _handler.OnSoftwareLockReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as SoftwareLockResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs!.Code, Is.EqualTo(Z21SoftwareLock.Z21StartUnlocked)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/StatusChangedResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/StatusChangedResponseHandlerTest.cs new file mode 100644 index 0000000..9e08e64 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/StatusChangedResponseHandlerTest.cs @@ -0,0 +1,75 @@ +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; +using Z21.Core.ResponseParser; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + public class StatusChangedResponseHandlerTest + { + private StatusChangedResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(new CentralStateResponseParser()); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x40, 0x00, 0x62, 0x22, 0x01, 0x41]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x62, 0x22, 0x02, 0x41 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x62, 0x22, 0x00, 0x41 }, false, false, false, false)] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x62, 0x22, 0x01, 0x41 }, true, false, false, false)] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x62, 0x22, 0x02, 0x41 }, false, true, false, false)] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x62, 0x22, 0x04, 0x41 }, false, false, true, false)] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x62, 0x22, 0x20, 0x41 }, false, false, false, true)] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs(byte[] response, bool emergencyStop, + bool trackVoltageOff, + bool shortCircuit, bool programmingModeActive) + { + StatusChangedReceivedEventArgs? receivedArgs = null; + StatusChangedResponseHandler? handler = null; + _handler.OnStatusChangedReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as StatusChangedResponseHandler; + }; + + _handler.Handle(response); + + Assert.Multiple( + () => + { + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs?.CentralState, Is.Not.Null); + }); + Assert.Multiple( + () => + { + Assert.That(receivedArgs.CentralState!.EmergencyStop, Is.EqualTo(emergencyStop)); + Assert.That(receivedArgs.CentralState!.TrackVoltageOff, Is.EqualTo(trackVoltageOff)); + Assert.That(receivedArgs.CentralState!.ShortCircuit, Is.EqualTo(shortCircuit)); + Assert.That(receivedArgs.CentralState!.ProgrammingModeActive, Is.EqualTo(programmingModeActive)); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandlerTest.cs new file mode 100644 index 0000000..7a11c21 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandlerTest.cs @@ -0,0 +1,68 @@ +using Moq; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; +using Z21.Core.ResponseParser; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + public class SystemStateDataChangedResponseHandlerTest + { + private SystemStateDataChangedResponseHandler _handler; + private Mock _systemStateResponseParserMock; + + [SetUp] + public void Setup() + { + _systemStateResponseParserMock = new(MockBehavior.Strict); + _handler = new(_systemStateResponseParserMock.Object); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x14, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x83, 0x45, 0x83, 0x45, 0x00, 0x00, 0x00, 0x7B]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x14, 0x00, 0x84, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x83, 0x45, 0x83, 0x45, 0x00, 0x00, 0x00, 0x7B }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x14, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x83, 0x45, 0x83, 0x45, 0x00, 0x00, 0x00, 0x7B]; + + SystemStatusChangedReceivedEventArgs? receivedArgs = null; + SystemStateDataChangedResponseHandler? handler = null; + _handler.OnSystemStateDataChangedReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as SystemStateDataChangedResponseHandler; + }; + + Z21.Core.Model.SystemState systemState = new() { CentralState = null!, CentralStateEx = null! }; + + _systemStateResponseParserMock.Setup(parser => parser.Parse(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x83, 0x45, 0x83, 0x45, 0x00, 0x00, 0x00, 0x7B })) + .Returns(systemState) + .Verifiable(); + + _handler.Handle(response); + + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.SystemState, Is.EqualTo(systemState)); + Assert.That(handler, Is.EqualTo(_handler)); + _systemStateResponseParserMock.Verify(); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandlerTest.cs new file mode 100644 index 0000000..b7623bf --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandlerTest.cs @@ -0,0 +1,58 @@ +using Z21.Core.ResponseHandler.SystemState.TrackPower; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState.TrackPower +{ + public class ProgrammingModeResponseHandlerTest + { + private ProgrammingModeResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x40, 0x00, 0x61, 0x02, 0x63]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x61, 0x03, 0x63 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x00, 0x00, 0x40, 0x00, 0x61, 0x02, 0x63]; + + EventArgs? receivedArgs = null; + ProgrammingModeResponseHandler? handler = null; + _handler.OnProgrammingModeReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as ProgrammingModeResponseHandler; + }; + + _handler.Handle(response); + + Assert.Multiple( + () => + { + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandlerTest.cs new file mode 100644 index 0000000..4ab71a6 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandlerTest.cs @@ -0,0 +1,58 @@ +using Z21.Core.ResponseHandler.SystemState.TrackPower; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState.TrackPower +{ + public class StoppedResponseHandlerTest + { + private StoppedResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x40, 0x00, 0x81, 0x00, 0x81]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x81, 0x01, 0x81 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x00, 0x00, 0x40, 0x00, 0x81, 0x00, 0x81]; + + EventArgs? receivedArgs = null; + StoppedResponseHandler? handler = null; + _handler.OnStoppedReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as StoppedResponseHandler; + }; + + _handler.Handle(response); + + Assert.Multiple( + () => + { + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandlerTest.cs new file mode 100644 index 0000000..edec559 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandlerTest.cs @@ -0,0 +1,58 @@ +using Z21.Core.ResponseHandler.SystemState.TrackPower; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState.TrackPower +{ + public class TrackPowerOffResponseHandlerTest + { + private TrackPowerOffResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x40, 0x00, 0x61, 0x00, 0x61]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x61, 0x01, 0x61 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x00, 0x00, 0x40, 0x00, 0x61, 0x00, 0x61]; + + EventArgs? receivedArgs = null; + TrackPowerOffResponseHandler? handler = null; + _handler.OnTrackPowerOffReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as TrackPowerOffResponseHandler; + }; + + _handler.Handle(response); + + Assert.Multiple( + () => + { + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandlerTest.cs new file mode 100644 index 0000000..4ebf1c8 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandlerTest.cs @@ -0,0 +1,58 @@ +using Z21.Core.ResponseHandler.SystemState.TrackPower; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState.TrackPower +{ + public class TrackPowerOnResponseHandlerTest + { + private TrackPowerOnResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x40, 0x00, 0x61, 0x01, 0x60]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x62, 0x01, 0x60 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x00, 0x00, 0x40, 0x00, 0x61, 0x01, 0x60]; + + EventArgs? receivedArgs = null; + TrackPowerOnResponseHandler? handler = null; + _handler.OnTrackPowerOnReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as TrackPowerOnResponseHandler; + }; + + _handler.Handle(response); + + Assert.Multiple( + () => + { + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/UnknownCommandResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/UnknownCommandResponseHandlerTest.cs new file mode 100644 index 0000000..bac2a10 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/UnknownCommandResponseHandlerTest.cs @@ -0,0 +1,57 @@ +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + public class UnknownCommandResponseHandlerTest + { + private UnknownCommandResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x40, 0x00, 0x61, 0x82, 0xE3]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x40, 0x00, 0x62, 0x82, 0xE3 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x00, 0x00, 0x40, 0x00, 0x62, 0x82, 0xE3]; + + UnknownCommandReceivedEventArgs? receivedArgs = null; + UnknownCommandResponseHandler? handler = null; + _handler.OnUnknownCommandReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as UnknownCommandResponseHandler; + }; + + _handler.Handle(response); + + Assert.That(receivedArgs, Is.Not.Null); + Assert.That(receivedArgs.UnknownDatagram, Is.EqualTo(response)); + Assert.That(handler, Is.EqualTo(_handler)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/VersionResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/VersionResponseHandlerTest.cs new file mode 100644 index 0000000..8975685 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/VersionResponseHandlerTest.cs @@ -0,0 +1,66 @@ +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.UnitTest.Core.ResponseHandler.SystemState +{ + public class VersionResponseHandlerTest + { + private VersionResponseHandler _handler; + + [SetUp] + public void Setup() + { + _handler = new(); + } + + [Test] + public void CanHandle_ValidResponse_ReturnsTrue() + { + byte[] validResponse = [0x00, 0x00, 0x40, 0x00, 0x63, 0x21, 0x01, 0x02]; + + bool result = _handler.CanHandle(validResponse); + + Assert.That(result, Is.True); + } + + [Test] + [TestCase(new byte[] { 0x00, 0x00, 0x41, 0x00, 0x62, 0x20, 0x01, 0x02 }, TestName = "Not Responsible")] + [TestCase(new byte[] { 0x00 }, TestName = "Response to small")] + public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) + { + bool result = _handler.CanHandle(response); + + Assert.That(result, Is.False); + } + + [Test] + public void Handle_ValidResponse_RaisesEventWithCorrectArgs() + { + byte[] response = [0x00, 0x00, 0x40, 0x00, 0x63, 0x21, 0xAA, 0xBB]; + + VersionReceivedEventArgs? receivedArgs = null; + VersionResponseHandler? handler = null; + _handler.OnVersionReceived += (sender, args) => + { + receivedArgs = args; + handler = sender as VersionResponseHandler; + }; + + _handler.Handle(response); + + Assert.Multiple( + () => + { + Assert.That(handler, Is.EqualTo(_handler)); + Assert.That(receivedArgs, Is.Not.Null); + }); + Assert.Multiple( + () => + { + Assert.That(receivedArgs!.XbusVer, Is.EqualTo(0xAA)); + Assert.That(receivedArgs.CmdstId, Is.EqualTo(0xBB)); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseParser/CapabilitiesResponseParserTest.cs b/src/Z21.Client.UnitTest/Core/ResponseParser/CapabilitiesResponseParserTest.cs new file mode 100644 index 0000000..b027e13 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseParser/CapabilitiesResponseParserTest.cs @@ -0,0 +1,50 @@ +using Z21.Core.Model; +using Z21.Core.ResponseParser; + +namespace Z21.UnitTest.Core.ResponseParser +{ + public class CapabilitiesResponseParserTests + { + private CapabilitiesResponseParser _parser; + + [SetUp] + public void Setup() + { + _parser = new(); + } + + [Test] + public void Parse_StatusByteIsZero_ReturnsNull() + { + Capabilities? result = _parser.Parse(0x00); + Assert.That(result, Is.Null); + } + + [TestCase(0x01, true, false, false, false, false, false, false)] + [TestCase(0x02, false, true, false, false, false, false, false)] + [TestCase(0x08, false, false, true, false, false, false, false)] + [TestCase(0x10, false, false, false, true, false, false, false)] + [TestCase(0x20, false, false, false, false, true, false, false)] + [TestCase(0x40, false, false, false, false, false, true, false)] + [TestCase(0x80, false, false, false, false, false, false, true)] + [TestCase(0x01 | 0x02 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80, true, true, true, true, true, true, true)] + public void Parse_IndividualBits_ReturnsCorrectCapabilities(byte statusByte, bool expectedDcc, bool expectedMm, bool expectedRailCom, bool expectedLocoCmds, bool expectedAccessoryCmds, + bool expectedDetectorCmds, bool expectedNeedsUnlockCode) + { + Capabilities? result = _parser.Parse(statusByte); + + Assert.That(result, Is.Not.Null); + Assert.Multiple( + () => + { + Assert.That(result.Dcc, Is.EqualTo(expectedDcc)); + Assert.That(result.Mm, Is.EqualTo(expectedMm)); + Assert.That(result.RailCom, Is.EqualTo(expectedRailCom)); + Assert.That(result.LocoCmds, Is.EqualTo(expectedLocoCmds)); + Assert.That(result.AccessoryCmds, Is.EqualTo(expectedAccessoryCmds)); + Assert.That(result.DetectorCmds, Is.EqualTo(expectedDetectorCmds)); + Assert.That(result.NeedsUnlockCode, Is.EqualTo(expectedNeedsUnlockCode)); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseParser/CentralStateExResponseParserTest.cs b/src/Z21.Client.UnitTest/Core/ResponseParser/CentralStateExResponseParserTest.cs new file mode 100644 index 0000000..a20ccd2 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseParser/CentralStateExResponseParserTest.cs @@ -0,0 +1,38 @@ +using Z21.Core.Model; +using Z21.Core.ResponseParser; + +namespace Z21.UnitTest.Core.ResponseParser +{ + public class CentralStateExResponseParserTests + { + private CentralStateExResponseParser _parser; + + [SetUp] + public void Setup() + { + _parser = new(); + } + + [TestCase(0x01, true, false, false, false, false)] + [TestCase(0x02, false, true, false, false, false)] + [TestCase(0x04, false, false, true, false, false)] + [TestCase(0x08, false, false, false, true, false)] + [TestCase(0x20, false, false, false, false, true)] + [TestCase(0x01 | 0x02 | 0x04 | 0x08 | 0x20, true, true, true, true, true)] + [TestCase(0x00, false, false, false, false, false)] + public void Parse_ShouldSetCorrectFlags(byte statusByte, bool expectedHighTemp, bool expectedPowerLost, bool expectedShortExternal, bool expectedShortInternal, bool expectedRcn213) + { + CentralStateEx result = _parser.Parse(statusByte); + + Assert.Multiple( + () => + { + Assert.That(result.HighTemperature, Is.EqualTo(expectedHighTemp)); + Assert.That(result.PowerLost, Is.EqualTo(expectedPowerLost)); + Assert.That(result.ShortCircuitExternal, Is.EqualTo(expectedShortExternal)); + Assert.That(result.ShortCircuitInternal, Is.EqualTo(expectedShortInternal)); + Assert.That(result.Rcn213, Is.EqualTo(expectedRcn213)); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseParser/CentralStateResponseParserTest.cs b/src/Z21.Client.UnitTest/Core/ResponseParser/CentralStateResponseParserTest.cs new file mode 100644 index 0000000..606a58c --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseParser/CentralStateResponseParserTest.cs @@ -0,0 +1,39 @@ +using Z21.Core.Model; +using Z21.Core.ResponseParser; + +namespace Z21.UnitTest.Core.ResponseParser +{ + [TestFixture] + public class CentralStateResponseParserTests + { + private CentralStateResponseParser _parser; + + [SetUp] + public void Setup() + { + _parser = new(); + } + + [TestCase(0x00, false, false, false, false)] + [TestCase(0x01, true, false, false, false)] + [TestCase(0x02, false, true, false, false)] + [TestCase(0x04, false, false, true, false)] + [TestCase(0x20, false, false, false, true)] + [TestCase(0x01 | 0x02 | 0x4, true, true, true, false)] + [TestCase(0x01 | 0x20, true, false, false, true)] + [TestCase(0x01 | 0x02 | 0x04 | 0x20, true, true, true, true)] + public void Parse_ShouldSetCorrectFlags(byte statusByte, bool emergencyStop, bool trackVoltageOff, bool shortCircuit, bool programmingModeActive) + { + CentralState result = _parser.Parse(statusByte); + + Assert.Multiple( + () => + { + Assert.That(result.EmergencyStop, Is.EqualTo(emergencyStop)); + Assert.That(result.TrackVoltageOff, Is.EqualTo(trackVoltageOff)); + Assert.That(result.ShortCircuit, Is.EqualTo(shortCircuit)); + Assert.That(result.ProgrammingModeActive, Is.EqualTo(programmingModeActive)); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseParser/SystemStateResponseParserTest.cs b/src/Z21.Client.UnitTest/Core/ResponseParser/SystemStateResponseParserTest.cs new file mode 100644 index 0000000..71edda8 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/ResponseParser/SystemStateResponseParserTest.cs @@ -0,0 +1,59 @@ +using Moq; +using NUnit.Framework.Constraints; +using Z21.Core.Model; +using Z21.Core.ResponseParser; + +namespace Z21.UnitTest.Core.ResponseParser +{ + public class SystemStateResponseParserTest + { + private SystemStateResponseParser _handler; + private Mock _centralStateResponseParserMock; + private Mock _centralStateExResponseParserMock; + private Mock _capabilitiesResponseParserMock; + + [SetUp] + public void Setup() + { + _centralStateResponseParserMock = new(MockBehavior.Strict); + _centralStateExResponseParserMock = new(MockBehavior.Strict); + _capabilitiesResponseParserMock = new(MockBehavior.Strict); + _handler = new(_centralStateResponseParserMock.Object, _centralStateExResponseParserMock.Object, _capabilitiesResponseParserMock.Object); + } + + [Test] + public void Parse() + { + byte[] data = [0xFF, 0x7F, 0xFE, 0x7E, 0xFD, 0x7D, 0xFC, 0x7C, 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0]; + + CentralState centralState = new(); + CentralStateEx centralStateEx = new(); + Capabilities capabilities = new(); + _centralStateResponseParserMock.Setup(parser => parser.Parse(0xF3)) + .Returns(centralState) + .Verifiable(Times.Once); + _centralStateExResponseParserMock.Setup(parser => parser.Parse(0xF2)) + .Returns(centralStateEx) + .Verifiable(Times.Once); + _capabilitiesResponseParserMock.Setup(parser => parser.Parse(0xF0)) + .Returns(capabilities) + .Verifiable(Times.Once); + + SystemState value = _handler.Parse(data); + Assert.Multiple( + () => + { + Assert.That(value.VccVoltage, Is.EqualTo(62709)); + Assert.That(value.Temperature, Is.EqualTo(31996)); + Assert.That(value.SupplyVoltage, Is.EqualTo(63223)); + Assert.That(value.ProgCurrent, Is.EqualTo(32510)); + Assert.That(value.MainCurrent, Is.EqualTo(32767)); + Assert.That(value.FilteredMainCurrent, Is.EqualTo(32253)); + Assert.That(value.CentralState, Is.SameAs(centralState)); + Assert.That(value.CentralStateEx, Is.SameAs(centralStateEx)); + Assert.That(value.Capabilities, Is.SameAs(capabilities)); + }); + Mock.VerifyAll(); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/Z21ClientTest.cs b/src/Z21.Client.UnitTest/Core/Z21ClientTest.cs new file mode 100644 index 0000000..bcdafcc --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Z21ClientTest.cs @@ -0,0 +1,7 @@ +namespace Z21.UnitTest.Core +{ + public class Z21ClientTest + { + + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj b/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj new file mode 100644 index 0000000..7776ab0 --- /dev/null +++ b/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj @@ -0,0 +1,30 @@ + + + + net8.0 + enable + enable + + false + true + Z21.UnitTest + + + + + + + + + + + + + + + + + + + + diff --git a/src/Z21.Console/Command/CliGetFirmwareVersionCommand.cs b/src/Z21.Console/Command/CliGetFirmwareVersionCommand.cs new file mode 100644 index 0000000..e183c7d --- /dev/null +++ b/src/Z21.Console/Command/CliGetFirmwareVersionCommand.cs @@ -0,0 +1,21 @@ +using System.Diagnostics.CodeAnalysis; +using Spectre.Console.Cli; +using Z21.Core; +using Z21.Core.Command; +using Z21.Core.Command.SystemState; + +namespace Z21.Console.Command +{ + public class GetFirmwareVersionSettings : CommandSettings + { + } + + public class CliGetFirmwareVersionCommand : Command + { + override public int Execute([NotNull] CommandContext context, [NotNull] GetFirmwareVersionSettings settings) + { + Program.Z21Client.SendCommandsAsync(new GetFirmwareVersionCommand()); + return 0; + } + } +} \ No newline at end of file diff --git a/src/Z21.Console/Command/CliSetTrackPowerCommand.cs b/src/Z21.Console/Command/CliSetTrackPowerCommand.cs new file mode 100644 index 0000000..398a575 --- /dev/null +++ b/src/Z21.Console/Command/CliSetTrackPowerCommand.cs @@ -0,0 +1,49 @@ +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using Spectre.Console; +using Spectre.Console.Cli; +using Z21.Core; +using Z21.Core.Command.SystemState.TrackPower; + +namespace Z21.Console.Command +{ + public class SetTrackPowerSettings : CommandSettings + { + [CommandOption("-o|--on")] + [Description("Turn track power on.")] + public bool On { get; set; } + + [CommandOption("-f|--off")] + [Description("Turn track power off.")] + public bool Off { get; set; } + + override public ValidationResult Validate() + { + if (On && Off) + return ValidationResult.Error("Cannot specify both --on and --off."); + if (!On && !Off) + return ValidationResult.Error("Must specify either --on or --off."); + return ValidationResult.Success(); + } + } + + public class CliSetTrackPowerCommand : Command + { + override public int Execute([NotNull] CommandContext context, [NotNull] SetTrackPowerSettings settings) + { + if (settings.On) + { + Program.Z21Client.SendCommandsAsync(new SetTrackPowerOnCommand()); + return 0; + } + + if (settings.Off) + { + Program.Z21Client.SendCommandsAsync(new SetTrackPowerOffCommand()); + return 0; + } + + return 1; + } + } +} \ No newline at end of file diff --git a/src/Z21.Console/Program.cs b/src/Z21.Console/Program.cs new file mode 100644 index 0000000..fa3deb0 --- /dev/null +++ b/src/Z21.Console/Program.cs @@ -0,0 +1,64 @@ +using Microsoft.Extensions.DependencyInjection; +using Serilog; +using Serilog.Events; +using Serilog.Sinks.SystemConsole.Themes; +using Spectre.Console.Cli; +using Spectre.Console.Cli.Extensions.DependencyInjection; +using Z21.Console.Command; +using Z21.Core; +using Z21.Core.Model; +using Z21.DependencyInjection; + +namespace Z21.Console +{ + abstract internal class Program + { + internal static IZ21Client Z21Client = null!; + + public static void Main(string[] args) + { + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .Enrich.FromLogContext() + .WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Debug, theme: AnsiConsoleTheme.Sixteen) + .CreateLogger(); + + ServiceCollection services = new(); + services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true)); + services.ConfigureZ21Client(Z21Configuration.Defaults.IpEndPoint); + services.AddZ21Client(); + services.AddZ21Transport(); + services.AddZ21ResponseParser(); + services.AddZ21ResponseHandler(); + ServiceProvider serviceProvider = services.BuildServiceProvider(); + + Z21Client = serviceProvider.GetRequiredService(); + + Z21Client.ConnectAsync(); + + using DependencyInjectionRegistrar registrar = new(services); + CommandApp app = new(registrar); + + app.Configure( + config => + { + config.AddCommand("SetTrackPower") + .WithDescription("Turn track power on or off."); + + config.AddCommand("GetFirmwareVersion") + .WithDescription("Retrieve the firmware version."); + }); + + + app.Run(new List()); + while (true) + { + string? value = System.Console.ReadLine(); + if (string.IsNullOrWhiteSpace(value)) + break; + IEnumerable userArgs = System.CommandLine.Parsing.CommandLineParser.SplitCommandLine(value); + app.Run(userArgs); + } + } + } +} \ No newline at end of file diff --git a/src/Z21.Console/Z21.Console.csproj b/src/Z21.Console/Z21.Console.csproj new file mode 100644 index 0000000..c7d5343 --- /dev/null +++ b/src/Z21.Console/Z21.Console.csproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + 12 + enable + enable + + + + + + + + + + + + + + + + + + + diff --git a/src/Z21.DependencyInjection.UnitTest/Z21.DependencyInjection.UnitTest.csproj b/src/Z21.DependencyInjection.UnitTest/Z21.DependencyInjection.UnitTest.csproj new file mode 100644 index 0000000..26629e3 --- /dev/null +++ b/src/Z21.DependencyInjection.UnitTest/Z21.DependencyInjection.UnitTest.csproj @@ -0,0 +1,30 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Z21.DependencyInjection.UnitTest/Z21DependencyInjectionExtensionTest.cs b/src/Z21.DependencyInjection.UnitTest/Z21DependencyInjectionExtensionTest.cs new file mode 100644 index 0000000..8e9334d --- /dev/null +++ b/src/Z21.DependencyInjection.UnitTest/Z21DependencyInjectionExtensionTest.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.DependencyInjection; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseHandler.SystemState; + +namespace Z21.DependencyInjection.UnitTest +{ + public class Z21DependencyInjectionExtensionTest + { + [Test] + public void AddZ21ResponseHandler_SameInstanceIsRegisteredForAllInterfaces() + { + ServiceCollection services = new(); + services.AddZ21ResponseParser(); + services.AddZ21ResponseHandler(); + ServiceProvider serviceProvider = services.BuildServiceProvider(); + + + ISerialNumberResponseHandler implementation = + serviceProvider.GetRequiredService(); + ISerialNumberResponseHandler implementationSpecificInterface = + serviceProvider.GetRequiredService(); + ISerialNumberResponseHandler baseInterface = serviceProvider + .GetRequiredService>() + .OfType() + .Single(); + + Assert.Multiple(() => + { + Assert.That(implementation, Is.SameAs(implementationSpecificInterface)); + Assert.That(implementation, Is.SameAs(baseInterface)); + Assert.That(implementationSpecificInterface, Is.SameAs(baseInterface)); + }); + } + } +} \ No newline at end of file diff --git a/src/Z21.DependencyInjection/LICENSE b/src/Z21.DependencyInjection/LICENSE new file mode 100644 index 0000000..e72bfdd --- /dev/null +++ b/src/Z21.DependencyInjection/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj b/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj new file mode 100644 index 0000000..089b3d7 --- /dev/null +++ b/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj @@ -0,0 +1,27 @@ + + + + net8.0;net8.0-windows;net9.0 + enable + enable + true + Jakob Eichberger + https://github.com/Jakob-Eichberger/z21Client + 5.0.0-alpha + LICENSE + true + + + + + + + + + + + + + + + diff --git a/src/Z21.DependencyInjection/Z21DependencyInjectionExtension.cs b/src/Z21.DependencyInjection/Z21DependencyInjectionExtension.cs new file mode 100644 index 0000000..50803ea --- /dev/null +++ b/src/Z21.DependencyInjection/Z21DependencyInjectionExtension.cs @@ -0,0 +1,86 @@ +using System.Net; +using Microsoft.Extensions.DependencyInjection; +using Z21.Core; +using Z21.Core.Model; +using Z21.Core.ResponseHandler; +using Z21.Core.ResponseParser; +using Z21.Transport; + +namespace Z21.DependencyInjection +{ + public static class Z21DependencyInjectionExtension + { + /// + /// Discovers all Z21 response handlers and registers them in the collection. + /// + public static ServiceCollection AddZ21ResponseHandler(this ServiceCollection services) + { + ArgumentNullException.ThrowIfNull(services, nameof(services)); + + Type baseInterface = typeof(IZ21ResponseHandler); + + IEnumerable handlerTypes = baseInterface.Assembly.GetTypes().Where(type => type is { IsClass: true, IsAbstract: false } && baseInterface.IsAssignableFrom(type)); + + foreach (Type handlerType in handlerTypes) + { + // Get all interfaces this class implements that are in the chain to IZ21ResponseHandler + List interfacesToRegister = handlerType.GetInterfaces().Where(type => baseInterface.IsAssignableFrom(type)).ToList(); + services.AddSingleton(handlerType); + foreach (Type serviceType in interfacesToRegister) + { + services.AddSingleton(serviceType, provider => provider.GetRequiredService(handlerType)); + } + } + + return services; + } + + public static ServiceCollection AddZ21ResponseParser(this ServiceCollection services) + { + ArgumentNullException.ThrowIfNull(services, nameof(services)); + + Type baseInterface = typeof(IZ21ResponseParser); + + IEnumerable handlerTypes = baseInterface.Assembly.GetTypes().Where(type => type is { IsClass: true, IsAbstract: false } && baseInterface.IsAssignableFrom(type)); + + foreach (Type handlerType in handlerTypes) + { + // Get all interfaces this class implements that are in the chain up to IZ21ResponseParser + List interfacesToRegister = handlerType.GetInterfaces().Where(type => baseInterface.IsAssignableFrom(type) && type != baseInterface).ToList(); + services.AddSingleton(handlerType); + foreach (Type serviceType in interfacesToRegister) + { + services.AddSingleton(serviceType, provider => provider.GetRequiredService(handlerType)); + } + } + + return services; + } + + public static ServiceCollection AddZ21Transport(this ServiceCollection services) // TODO: Test + { + ArgumentNullException.ThrowIfNull(services, nameof(services)); + services.AddSingleton(); + return services; + } + + public static ServiceCollection AddZ21Client(this ServiceCollection services) // TODO: Test + { + ArgumentNullException.ThrowIfNull(services, nameof(services)); + services.AddSingleton(); + return services; + } + + public static ServiceCollection ConfigureZ21Client(this ServiceCollection services, IPEndPoint z21EndPoint, Action? configurationAction = null) // TODO: Test + { + ArgumentNullException.ThrowIfNull(services, nameof(services)); + ArgumentNullException.ThrowIfNull(z21EndPoint, nameof(z21EndPoint)); + + Z21Configuration configuration = new(z21EndPoint); + configurationAction?.Invoke(configuration); + services.AddSingleton(configuration); + + return services; + } + } +} \ No newline at end of file diff --git a/src/Z21.sln b/src/Z21.sln new file mode 100644 index 0000000..18c8597 --- /dev/null +++ b/src/Z21.sln @@ -0,0 +1,71 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32630.192 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Z21.Client", "Z21Client\Z21.Client.csproj", "{A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z21.Client.UnitTest", "Z21.Client.UnitTest\Z21.Client.UnitTest.csproj", "{A3246DA8-ACBE-435D-B050-CA7595512C1A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z21.DependencyInjection", "Z21.DependencyInjection\Z21.DependencyInjection.csproj", "{6B823598-684E-4EAC-BFD5-93BFD43531D8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z21.Console", "Z21.Console\Z21.Console.csproj", "{4355685F-8F0B-451A-93AA-68C5752AD2B8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z21.DependencyInjection.UnitTest", "Z21.DependencyInjection.UnitTest\Z21.DependencyInjection.UnitTest.csproj", "{B1276BFA-A2F1-4A4A-8081-BA1191833D39}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}.Debug|Any CPU.ActiveCfg = Debug|x64 + {A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}.Debug|x64.ActiveCfg = Debug|x64 + {A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}.Debug|x64.Build.0 = Debug|x64 + {A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}.Release|Any CPU.ActiveCfg = Debug|x64 + {A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}.Release|Any CPU.Build.0 = Debug|x64 + {A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}.Release|x64.ActiveCfg = Debug|x64 + {A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}.Release|x64.Build.0 = Debug|x64 + {A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}.Debug|Any CPU.Build.0 = Debug|x64 + {A3246DA8-ACBE-435D-B050-CA7595512C1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3246DA8-ACBE-435D-B050-CA7595512C1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3246DA8-ACBE-435D-B050-CA7595512C1A}.Debug|x64.ActiveCfg = Debug|Any CPU + {A3246DA8-ACBE-435D-B050-CA7595512C1A}.Debug|x64.Build.0 = Debug|Any CPU + {A3246DA8-ACBE-435D-B050-CA7595512C1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3246DA8-ACBE-435D-B050-CA7595512C1A}.Release|Any CPU.Build.0 = Release|Any CPU + {A3246DA8-ACBE-435D-B050-CA7595512C1A}.Release|x64.ActiveCfg = Release|Any CPU + {A3246DA8-ACBE-435D-B050-CA7595512C1A}.Release|x64.Build.0 = Release|Any CPU + {6B823598-684E-4EAC-BFD5-93BFD43531D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B823598-684E-4EAC-BFD5-93BFD43531D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B823598-684E-4EAC-BFD5-93BFD43531D8}.Debug|x64.ActiveCfg = Debug|Any CPU + {6B823598-684E-4EAC-BFD5-93BFD43531D8}.Debug|x64.Build.0 = Debug|Any CPU + {6B823598-684E-4EAC-BFD5-93BFD43531D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B823598-684E-4EAC-BFD5-93BFD43531D8}.Release|Any CPU.Build.0 = Release|Any CPU + {6B823598-684E-4EAC-BFD5-93BFD43531D8}.Release|x64.ActiveCfg = Release|Any CPU + {6B823598-684E-4EAC-BFD5-93BFD43531D8}.Release|x64.Build.0 = Release|Any CPU + {4355685F-8F0B-451A-93AA-68C5752AD2B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4355685F-8F0B-451A-93AA-68C5752AD2B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4355685F-8F0B-451A-93AA-68C5752AD2B8}.Debug|x64.ActiveCfg = Debug|Any CPU + {4355685F-8F0B-451A-93AA-68C5752AD2B8}.Debug|x64.Build.0 = Debug|Any CPU + {4355685F-8F0B-451A-93AA-68C5752AD2B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4355685F-8F0B-451A-93AA-68C5752AD2B8}.Release|Any CPU.Build.0 = Release|Any CPU + {4355685F-8F0B-451A-93AA-68C5752AD2B8}.Release|x64.ActiveCfg = Release|Any CPU + {4355685F-8F0B-451A-93AA-68C5752AD2B8}.Release|x64.Build.0 = Release|Any CPU + {B1276BFA-A2F1-4A4A-8081-BA1191833D39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B1276BFA-A2F1-4A4A-8081-BA1191833D39}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B1276BFA-A2F1-4A4A-8081-BA1191833D39}.Debug|x64.ActiveCfg = Debug|Any CPU + {B1276BFA-A2F1-4A4A-8081-BA1191833D39}.Debug|x64.Build.0 = Debug|Any CPU + {B1276BFA-A2F1-4A4A-8081-BA1191833D39}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B1276BFA-A2F1-4A4A-8081-BA1191833D39}.Release|Any CPU.Build.0 = Release|Any CPU + {B1276BFA-A2F1-4A4A-8081-BA1191833D39}.Release|x64.ActiveCfg = Release|Any CPU + {B1276BFA-A2F1-4A4A-8081-BA1191833D39}.Release|x64.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4C252142-EFFB-438D-AFB6-5767423AED4B} + EndGlobalSection +EndGlobal diff --git a/src/Z21Client/.idea/.idea.z21Client.dir/.idea/encodings.xml b/src/Z21Client/.idea/.idea.z21Client.dir/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/src/Z21Client/.idea/.idea.z21Client.dir/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/Z21Client/.idea/.idea.z21Client.dir/.idea/indexLayout.xml b/src/Z21Client/.idea/.idea.z21Client.dir/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/src/Z21Client/.idea/.idea.z21Client.dir/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Z21Client/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml b/src/Z21Client/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml new file mode 100644 index 0000000..64af657 --- /dev/null +++ b/src/Z21Client/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/src/Z21Client/.idea/.idea.z21Client.dir/.idea/vcs.xml b/src/Z21Client/.idea/.idea.z21Client.dir/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/src/Z21Client/.idea/.idea.z21Client.dir/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Z21Client/.idea/.idea.z21Client/.idea/.gitignore b/src/Z21Client/.idea/.idea.z21Client/.idea/.gitignore new file mode 100644 index 0000000..3dee4d0 --- /dev/null +++ b/src/Z21Client/.idea/.idea.z21Client/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/.idea.z21Client.iml +/projectSettingsUpdater.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/src/Z21Client/.idea/.idea.z21Client/.idea/indexLayout.xml b/src/Z21Client/.idea/.idea.z21Client/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/src/Z21Client/.idea/.idea.z21Client/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Z21Client/.idea/.idea.z21Client/.idea/vcs.xml b/src/Z21Client/.idea/.idea.z21Client/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/src/Z21Client/.idea/.idea.z21Client/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Driving/GetLocoInfoCommand.cs b/src/Z21Client/Core/Command/Driving/GetLocoInfoCommand.cs new file mode 100644 index 0000000..e5ad71c --- /dev/null +++ b/src/Z21Client/Core/Command/Driving/GetLocoInfoCommand.cs @@ -0,0 +1,35 @@ +using Z21.Core.Command.SystemState; +using Z21.Core.Helper; +using Z21.Core.Model; + +namespace Z21.Core.Command.Driving +{ + /// + /// The following command can be used to poll the status of a locomotive. At the same time, the client also "subscribes" to the locomotive information for this locomotive address (only in combination with , Flag ). + /// + public class GetLocoInfoCommand : IZ21Command + { + public GetLocoInfoCommand(ushort locoAddress) + { + const byte xHeader = 0xE3; + const byte db0 = 0xF0; + + (byte lsb, byte msb) = AddressHelper.SplitLocoAddress(locoAddress); + byte xor = (byte)(xHeader ^ db0 ^ lsb ^ msb); + Data = + [ + 0x09, 0x00, + 0x40, 0x00, + xHeader, + db0, + msb, + lsb, + xor + ]; + } + + public string Name => "LAN_X_GET_LOCO_INFO"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Driving/PurgeLocoCommand.cs b/src/Z21Client/Core/Command/Driving/PurgeLocoCommand.cs new file mode 100644 index 0000000..4e3a28f --- /dev/null +++ b/src/Z21Client/Core/Command/Driving/PurgeLocoCommand.cs @@ -0,0 +1,31 @@ +using Z21.Core.Helper; + +namespace Z21.Core.Command.Driving +{ + /// + /// From Z21 FW version 1.43, a locomotive can be removed from the Z21 with the following command. + /// This also cancels the sending of the loco commands for this locomotive on the track. + /// Sending will start again as soon as a new drive or function command is sent to the same locomotive address. + /// + public class PurgeLocoCommand : IZ21Command + { + public PurgeLocoCommand(ushort locoAddress) + { + (byte lsb, byte msb) = AddressHelper.SplitLocoAddress(locoAddress); + Data = + [ + 0x09, 0x00, + 0x40, 0x00, + 0xE3, + 0x44, + msb, + lsb, + (byte)(0xE3 ^ 0x44 ^ msb ^ lsb) + ]; + } + + public string Name => "LAN_X_PURGE_LOCO"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Driving/SetLocoDriveCommand.cs b/src/Z21Client/Core/Command/Driving/SetLocoDriveCommand.cs new file mode 100644 index 0000000..fbb9dc8 --- /dev/null +++ b/src/Z21Client/Core/Command/Driving/SetLocoDriveCommand.cs @@ -0,0 +1,47 @@ +using System; +using Z21.Core.Exception; +using Z21.Core.Helper; +using Z21.Core.Model; + +namespace Z21.Core.Command.Driving +{ + /// + /// Change the speed and direction of a locomotive. + /// + public class SetLocoDriveCommand : IZ21Command + { + public SetLocoDriveCommand(DccSpeedMode dccSpeedMode, ushort locoAddress, DrivingDirection drivingDirection, ushort locoSpeed) + { + LocoSpeedOutOfRangeException.ThrowIfOutOfRange(dccSpeedMode, locoSpeed); + ushort dccSpeed = LocoSpeedHelper.CalculateDccSpeed(dccSpeedMode, locoSpeed); + + const byte xHeader = 0xE4; + byte db0 = (byte)(0x10 | GetByte(dccSpeedMode)); + (byte lsb, byte msb) = AddressHelper.SplitLocoAddress(locoAddress); + byte db3 = (byte)((byte)drivingDirection | dccSpeed); + Data = + [ + 0x0A, 0x00, + 0x40, 0x00, + xHeader, + db0, + msb, + lsb, + db3, + (byte)(xHeader ^ db0 ^ msb ^ lsb ^ db3) + ]; + } + + public string Name => "LAN_X_SET_LOCO_DRIVE"; + + public byte[] Data { get; } + + private byte GetByte(DccSpeedMode dccSpeedMode) => dccSpeedMode switch + { + DccSpeedMode.Steps14 => 0x0, + DccSpeedMode.Steps28 => 0x02, + DccSpeedMode.Steps128 => 0x03, + _ => throw new ArgumentOutOfRangeException(nameof(dccSpeedMode), dccSpeedMode, null) + }; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Driving/SetLocoEStopCommand.cs b/src/Z21Client/Core/Command/Driving/SetLocoEStopCommand.cs new file mode 100644 index 0000000..933ddb2 --- /dev/null +++ b/src/Z21Client/Core/Command/Driving/SetLocoEStopCommand.cs @@ -0,0 +1,32 @@ +using Z21.Core.Helper; + +namespace Z21.Core.Command.Driving +{ + /// + /// From Z21 FW version 1.43, a locomotive can be stopped with the following command. + /// In the case of a DCC locomotive, the speed step "E-STOP" ("emergency stop" according to RCN-212) is then sent in the DCC speed command onto the track, i.e., the decoder should stop the engine as quickly as possible. + /// In the case of an MM locomotive, the speed step 0 ("Stop") is sent onto the track. + /// + public class SetLocoEStopCommand : IZ21Command + { + public SetLocoEStopCommand(ushort locoAddress) + { + (byte lsb, byte msb) = AddressHelper.SplitLocoAddress(locoAddress); + Data = + [ + 0x08, + 0x00, + 0x40, + 0x00, + 0x92, + msb, + lsb, + (byte)(0x92 ^ msb ^ lsb) + ]; + } + + public string Name => "LAN_X_SET_LOCO_E_STOP"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Driving/SetLocoFunctionCommand.cs b/src/Z21Client/Core/Command/Driving/SetLocoFunctionCommand.cs new file mode 100644 index 0000000..c9fc1cc --- /dev/null +++ b/src/Z21Client/Core/Command/Driving/SetLocoFunctionCommand.cs @@ -0,0 +1,34 @@ +using Z21.Core.Helper; +using Z21.Core.Model; + +namespace Z21.Core.Command.Driving +{ + /// + /// Change a function of a locomotive. + /// + public class SetLocoFunctionCommand : IZ21Command + { + public SetLocoFunctionCommand(ushort locoAddress, ushort functionIndex, FunctionToggleType toggleType) + { + const byte xHeader = 0xE4; + const byte db0 = 0xF8; + byte db3 = (byte)((byte)toggleType | functionIndex); + (byte lsb, byte msb) = AddressHelper.SplitLocoAddress(locoAddress); + Data = + [ + 0x0A, 0x00, + 0x40, 0x00, + xHeader, + db0, + msb, + lsb, + db3, + (byte)(xHeader ^ db0 ^ msb ^ lsb ^ db3) + ]; + } + + public string Name => "LAN_X_SET_LOCO_FUNCTION"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/IZ21Command.cs b/src/Z21Client/Core/Command/IZ21Command.cs new file mode 100644 index 0000000..fe8d22a --- /dev/null +++ b/src/Z21Client/Core/Command/IZ21Command.cs @@ -0,0 +1,12 @@ +namespace Z21.Core.Command +{ + public interface IZ21Command + { + /// + /// Human-readable command according to the specification. + /// + public string Name { get; } + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Settings/GetAccessoryModeCommand.cs b/src/Z21Client/Core/Command/Settings/GetAccessoryModeCommand.cs new file mode 100644 index 0000000..c0a47eb --- /dev/null +++ b/src/Z21Client/Core/Command/Settings/GetAccessoryModeCommand.cs @@ -0,0 +1,34 @@ +using System; + +namespace Z21.Core.Command.Settings +{ + /// + /// Read the settings for a given accessory decoder address ("Accessory Decoder" RP-9.2.1). + /// + /// + /// In the Z21, the output format (DCC, MM) is persistently stored for each accessory decoder address. + /// A maximum of 256 different accessory decoder addresses can be stored. Each address >= 256 is automatically DCC. + /// + public class GetAccessoryModeCommand : IZ21Command + { + public GetAccessoryModeCommand(short locoAddress) + { + byte[] addressBytes = BitConverter.GetBytes(locoAddress); + Array.Reverse(addressBytes); + + Data = + [ + 0x06, + 0x00, + 0x70, + 0x00, + addressBytes[0], + addressBytes[1] + ]; + } + + public string Name => "LAN_GET_TURNOUTMODE"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Settings/GetLocoModeCommand.cs b/src/Z21Client/Core/Command/Settings/GetLocoModeCommand.cs new file mode 100644 index 0000000..790b5b1 --- /dev/null +++ b/src/Z21Client/Core/Command/Settings/GetLocoModeCommand.cs @@ -0,0 +1,34 @@ +using System; + +namespace Z21.Core.Command.Settings +{ + /// + /// Read the output format for a given locomotive address. + /// + /// + /// In the Z21, the output format (DCC, MM) is persistently stored for each locomotive address. A maximum of 256 different locomotive addresses can be stored. Each address >= 256 is DCC automatically. + /// + public class GetLocoModeCommand : IZ21Command + { + + public GetLocoModeCommand(short locoAddress) + { + byte[] addressBytes = BitConverter.GetBytes(locoAddress); + Array.Reverse(addressBytes); + + Data = + [ + 0x06, + 0x00, + 0x60, + 0x00, + addressBytes[0], + addressBytes[1] + ]; + } + + public string Name => "LAN_GET_LOCOMODE"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Settings/SetAccessoryModeCommand.cs b/src/Z21Client/Core/Command/Settings/SetAccessoryModeCommand.cs new file mode 100644 index 0000000..5288edd --- /dev/null +++ b/src/Z21Client/Core/Command/Settings/SetAccessoryModeCommand.cs @@ -0,0 +1,36 @@ +using System; +using Z21.Core.Model; + +namespace Z21.Core.Command.Settings +{ + /// + /// Set the output format for a given accessory decoder address. The format is stored in the Z21 persistently. + /// + public class SetAccessoryModeCommand : IZ21Command + { + /// Is thrown when is + public SetAccessoryModeCommand(short accessoryAddress, DecoderMode decoderMode) + { + if (decoderMode is DecoderMode.Unknown) + throw new ArgumentException($"{DecoderMode.Unknown} is not a valid DecoderMode.", nameof(decoderMode)); + + byte[] addressBytes = BitConverter.GetBytes(accessoryAddress); + Array.Reverse(addressBytes); + + Data = + [ + 0x07, + 0x00, + 0x71, + 0x00, + addressBytes[0], + addressBytes[1], + (byte)decoderMode + ]; + } + + public string Name => "LAN_SET_TURNOUTMODE"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Settings/SetLocoModeCommand.cs b/src/Z21Client/Core/Command/Settings/SetLocoModeCommand.cs new file mode 100644 index 0000000..3a8de9c --- /dev/null +++ b/src/Z21Client/Core/Command/Settings/SetLocoModeCommand.cs @@ -0,0 +1,36 @@ +using System; +using Z21.Core.Model; + +namespace Z21.Core.Command.Settings +{ + /// + /// Set the output format for a given locomotive address. The format is stored in the Z21persistently. + /// + public class SetLocoModeCommand : IZ21Command + { + /// Is thrown when is + public SetLocoModeCommand(short locoAddress, DecoderMode decoderMode) + { + if (decoderMode is DecoderMode.Unknown) + throw new ArgumentException($"{DecoderMode.Unknown} is not a valid DecoderMode.", nameof(decoderMode)); + + byte[] addressBytes = BitConverter.GetBytes(locoAddress); + Array.Reverse(addressBytes); + + Data = + [ + 0x07, + 0x00, + 0x61, + 0x00, + addressBytes[0], + addressBytes[1], + (byte)decoderMode + ]; + } + + public string Name => "LAN_SET_LOCOMODE"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Switching/GetExtAccessoryInfoCommand.cs b/src/Z21Client/Core/Command/Switching/GetExtAccessoryInfoCommand.cs new file mode 100644 index 0000000..19ff68f --- /dev/null +++ b/src/Z21Client/Core/Command/Switching/GetExtAccessoryInfoCommand.cs @@ -0,0 +1,29 @@ +using Z21.Core.Helper; + +namespace Z21.Core.Command.Switching +{ + /// + /// From Z21 FW V1. 40, the following request can be used to poll the last command transferred to an extended accessory decoder. + /// + public class GetExtAccessoryInfoCommand : IZ21Command + { + public GetExtAccessoryInfoCommand(ushort accessoryAddress) + { + (byte lsb, byte msb) = AddressHelper.SplitAccessoryAddress(accessoryAddress); + Data = + [ + 0x09, 0x00, + 0x40, 0x00, + 0x44, + msb, + lsb, + 0x00, + (byte)(0x44 ^ msb ^ lsb ^ 0x00) + ]; + } + + public string Name => "LAN_X_GET_EXT_ACCESSORY_INFO"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Switching/GetTurnoutInfoCommand.cs b/src/Z21Client/Core/Command/Switching/GetTurnoutInfoCommand.cs new file mode 100644 index 0000000..ef7b061 --- /dev/null +++ b/src/Z21Client/Core/Command/Switching/GetTurnoutInfoCommand.cs @@ -0,0 +1,30 @@ +using System; +using Z21.Core.Helper; + +namespace Z21.Core.Command.Switching +{ + /// + /// The following command can be used to poll the status of a turnout (or any accessory function). + /// + public class GetTurnoutInfoCommand : IZ21Command + { + /// Thrown when is smaller than 1. + public GetTurnoutInfoCommand(ushort accessoryAddress) + { + (byte lsb, byte msb) = AddressHelper.SplitAccessoryAddress(accessoryAddress); + Data = + [ + 0x08, 0x00, + 0x40, 0x00, + 0x43, + msb, + lsb, + (byte)(0x43 ^ msb ^ lsb) + ]; + } + + public string Name => "LAN_X_GET_TURNOUT_INFO"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Switching/SetExtAccessoryCommand.cs b/src/Z21Client/Core/Command/Switching/SetExtAccessoryCommand.cs new file mode 100644 index 0000000..32121d4 --- /dev/null +++ b/src/Z21Client/Core/Command/Switching/SetExtAccessoryCommand.cs @@ -0,0 +1,46 @@ +using Z21.Core.Helper; +using Z21.Core.Model.ExcAccessoryPayload; + +namespace Z21.Core.Command.Switching +{ + /// + /// From Z21 FW V1. 40, a DCC command in the "extended accessory decoder package format "(DCCext) can be sent to an extended accessory decoder with the following request. It allows to send even switching times for turnouts or complex signal aspects with just one single command + /// + public class SetExtAccessoryCommand : IZ21Command + { + /// + /// From Z21 FW V1. 40, a DCC command in the "extended accessory decoder package format "(DCCext) can be sent to an extended accessory decoder with the following request. It allows to send even switching times for turnouts or complex signal aspects with just one single command + /// + /// The 10837 Z21 signaldecoder interprets as one of 256 theoretically possible signal aspects. The actual value range depends to a large extent on the signal type set in the signal decoder. See for all possible values. + /// The 10836 Z21 switch DECODER interprets the payload as "switch decoder with reception of switching time". Use to generate payload. + public SetExtAccessoryCommand(ushort accessoryAddress, IExcAccessoryPayload payload) : this(accessoryAddress, (byte)payload.Payload) + { + } + + /// + /// From Z21 FW V1. 40, a DCC command in the "extended accessory decoder package format" can be sent to an extended accessory decoder with the following request. It allows to send even switching times for turnouts or complex signal aspects with just one single command + /// + /// The 10837 Z21 signaldecoder interprets as one of 256 theoretically possible signal aspects. The actual value range depends to a large extent on the signal type set in the signal decoder. See for all possible values. + /// The 10836 Z21 switch DECODER interprets the payload as "switch decoder with reception of switching time". Use to generate payload. + public SetExtAccessoryCommand(ushort accessoryAddress, byte payload) + { + (byte lsb, byte msb) = AddressHelper.SplitAccessoryAddress(accessoryAddress); + + Data = + [ + 0x0A, 0x00, + 0x40, 0x00, + 0x54, + msb, + lsb, + payload, + 0x00, + (byte)(0x54 ^ msb ^ lsb ^ payload ^ 0x00) + ]; + } + + public string Name => "LAN_X_SET_EXT_ACCESSORY"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/Switching/SetTurnoutCommand.cs b/src/Z21Client/Core/Command/Switching/SetTurnoutCommand.cs new file mode 100644 index 0000000..c9c8de2 --- /dev/null +++ b/src/Z21Client/Core/Command/Switching/SetTurnoutCommand.cs @@ -0,0 +1,40 @@ +using System; +using Z21.Core.Helper; +using Z21.Core.Model; + +namespace Z21.Core.Command.Switching +{ + /// + /// A turnout (or any accessory function) can be switched with the following command. + /// + /// + /// The signal is output on the track until the LAN client sends the corresponding > signale.Only one switching command may be active at the same time. + /// + /// + /// Wrong: Activate 1 -> Active 2 -> Deactivate 1 -> Deactivate 2 Correct: Activate 1 -> Deactivate 1 -> Activate 2 -> Deactivate 2 + /// + public class SetTurnoutCommand : IZ21Command + { + /// Thrown when is smaller than 1. + public SetTurnoutCommand(ushort accessoryAddress, AccessoryOutput accessoryOutput, AccessoryState accessoryState, bool executeImmediately) + { + (byte lsb, byte msb) = AddressHelper.SplitAccessoryAddress(accessoryAddress); + byte db2 = (byte)(0x80 | (int)accessoryOutput | (int)accessoryState | (executeImmediately ? 0x20 : 0x00)); + + Data = + [ + 0x09, 0x00, + 0x40, 0x00, + 0x53, + msb, + lsb, + db2, + (byte)(0x53 ^ msb ^ lsb ^ db2) + ]; + } + + public string Name => "LAN_X_SET_TURNOUT"; + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/GetBroadcastFlagsCommand.cs b/src/Z21Client/Core/Command/SystemState/GetBroadcastFlagsCommand.cs new file mode 100644 index 0000000..a1ee498 --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/GetBroadcastFlagsCommand.cs @@ -0,0 +1,18 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// Reading the broadcast flags in the Z21. + /// + public class GetBroadcastFlagsCommand : IZ21Command + { + public string Name => "LAN_GET_BROADCASTFLAGS"; + + public byte[] Data { get; } = + [ + 0x04, + 0x00, + 0x51, + 0x00 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/GetFirmwareVersionCommand.cs b/src/Z21Client/Core/Command/SystemState/GetFirmwareVersionCommand.cs new file mode 100644 index 0000000..09ceeb4 --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/GetFirmwareVersionCommand.cs @@ -0,0 +1,21 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// The firmware version of the Z21 can be read with this command. + /// + public class GetFirmwareVersionCommand : IZ21Command + { + public string Name => "LAN_X_GET_FIRMWARE_VERSION"; + + public byte[] Data { get; } = + [ + 0x07, + 0x00, + 0x40, + 0x00, + 0xF1, + 0x0A, + 0xF1 ^ 0x0A + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/GetHardwareInfoCommand.cs b/src/Z21Client/Core/Command/SystemState/GetHardwareInfoCommand.cs new file mode 100644 index 0000000..d6c92cf --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/GetHardwareInfoCommand.cs @@ -0,0 +1,18 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// Read the hardware type and the firmware version of the Z21. + /// + public class GetHardwareInfoCommand : IZ21Command + { + public string Name => "LAN_GET_HWINFO"; + + public byte[] Data { get; } = + [ + 0x04, + 0x00, + 0x1A, + 0x00 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/GetSerialNumberCommand.cs b/src/Z21Client/Core/Command/SystemState/GetSerialNumberCommand.cs new file mode 100644 index 0000000..81dc090 --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/GetSerialNumberCommand.cs @@ -0,0 +1,18 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// Reading the serial number of the Z21. + /// + public class GetSerialNumberCommand : IZ21Command + { + public string Name => "LAN_GET_SERIAL_NUMBER"; + + public byte[] Data { get; } = + [ + 0x04, + 0x00, + 0x10, + 0x00 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/GetSoftwareLockCommand.cs b/src/Z21Client/Core/Command/SystemState/GetSoftwareLockCommand.cs new file mode 100644 index 0000000..8fb141c --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/GetSoftwareLockCommand.cs @@ -0,0 +1,19 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// Read the software feature scope of the Z21 (and z21 or z21start of course). + /// + /// This command is of particular interest for the hardware variant "z21 start", in order to be able to check whether driving and switching via LAN is blocked or permitted. + public class GetSoftwareLockCommand : IZ21Command + { + public string Name => "LAN_GET_CODE"; + + public byte[] Data { get; } = + [ + 0x04, + 0x00, + 0x18, + 0x00 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/GetStatusCommand.cs b/src/Z21Client/Core/Command/SystemState/GetStatusCommand.cs new file mode 100644 index 0000000..629960d --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/GetStatusCommand.cs @@ -0,0 +1,19 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// This command can be used to request the Z21 status. + /// + public class GetStatusCommand : IZ21Command + { + public string Name => "LAN_X_GET_STATUS"; + + public byte[] Data { get; } = + [ + 0x07, 0x00, //DataLen + 0x40, 0x00, //Header + 0x21, // X-Header + 0x24, // DB0 + 0x21 ^ 0x24 // XOR-Byte + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/GetSystemStateDataCommand.cs b/src/Z21Client/Core/Command/SystemState/GetSystemStateDataCommand.cs new file mode 100644 index 0000000..76ec424 --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/GetSystemStateDataCommand.cs @@ -0,0 +1,18 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// Request the current system status. + /// + public class GetSystemStateDataCommand : IZ21Command + { + public string Name => "LAN_SYSTEMSTATE_GETDATA"; + + public byte[] Data { get; } = + [ + 0x04, + 0x00, + 0x85, + 0x00 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/GetVersionCommand.cs b/src/Z21Client/Core/Command/SystemState/GetVersionCommand.cs new file mode 100644 index 0000000..336a770 --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/GetVersionCommand.cs @@ -0,0 +1,19 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// The X-Bus version of the Z21 can be read out with the following command. + /// + public class GetVersionCommand : IZ21Command + { + public string Name => "LAN_X_GET_VERSION"; + + public byte[] Data { get; } = + [ + 0x07, 0x00, + 0x40, 0x00, + 0x21, + 0x21, + 0x21 ^ 0x21 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/LogOffCommand.cs b/src/Z21Client/Core/Command/SystemState/LogOffCommand.cs new file mode 100644 index 0000000..6046c8d --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/LogOffCommand.cs @@ -0,0 +1,18 @@ +namespace Z21.Core.Command.SystemState +{ + /// + /// Logging off the client from the Z21. + /// + public class LogOffCommand : IZ21Command + { + public string Name => "LAN_LOGOFF"; + + public byte[] Data { get; } = + [ + 0x04, + 0x00, + 0x30, + 0x00 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/SetBroadcastFlagsCommand.cs b/src/Z21Client/Core/Command/SystemState/SetBroadcastFlagsCommand.cs new file mode 100644 index 0000000..3e17ecd --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/SetBroadcastFlagsCommand.cs @@ -0,0 +1,32 @@ +using System; +using System.Linq; +using Z21.Core.Model; + +namespace Z21.Core.Command.SystemState +{ + /// + /// Implements the LAN_SET_BROADCASTFLAGS command. See for some flags. See LAN_SET_BROADCASTFLAGS section of the Z21 lan protocol document for all possible flags. + /// + public class SetBroadcastFlagsCommand : IZ21Command + { + public string Name => "LAN_SET_BROADCASTFLAGS"; + + public SetBroadcastFlagsCommand(params uint[] flags) + { + uint flag = flags.Length > 0 ? flags.Aggregate((u, u1) => u | u1) : 0; + + byte[] broadcastFlags = BitConverter.GetBytes(flag); + Data = + [ + 0x08, 0x00, + 0x50, 0x00, + broadcastFlags[0], + broadcastFlags[1], + broadcastFlags[2], + broadcastFlags[3], + ]; + } + + public byte[] Data { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/TrackPower/SetStopCommand.cs b/src/Z21Client/Core/Command/SystemState/TrackPower/SetStopCommand.cs new file mode 100644 index 0000000..e0e8b2c --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/TrackPower/SetStopCommand.cs @@ -0,0 +1,18 @@ +namespace Z21.Core.Command.SystemState.TrackPower +{ + /// + /// With this command the emergency stop is activated, i.e. the locomotives are stopped but the track voltage remains switched on. + /// + public class SetStopCommand : IZ21Command + { + public string Name => "LAN_X_SET_STOP"; + + public byte[] Data { get; } = + [ + 0x06, 0x00, + 0x40, 0x00, + 0x80, + 0x0 ^ 0x80 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs b/src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs new file mode 100644 index 0000000..a6616a2 --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs @@ -0,0 +1,19 @@ +namespace Z21.Core.Command.SystemState.TrackPower +{ + /// + /// This command switches off the track voltage. + /// + public class SetTrackPowerOffCommand : IZ21Command + { + public string Name => "LAN_X_SET_TRACK_POWER_OFF"; + + public byte[] Data { get; } = + [ + 0x07, 0x00, + 0x40, 0x00, + 0x21, + 0x80, + 0x21 ^ 0x80 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs b/src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs new file mode 100644 index 0000000..5334cd8 --- /dev/null +++ b/src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs @@ -0,0 +1,19 @@ +namespace Z21.Core.Command.SystemState.TrackPower +{ + /// + /// This command switches on the track voltage, or terminates either the emergency stop or the programming mode. + /// + public class SetTrackPowerOnCommand : IZ21Command + { + public string Name => "LAN_X_SET_TRACK_POWER_ON"; + + public byte[] Data { get; } = + [ + 0x07, 0x00, + 0x40, 0x00, + 0x21, + 0x81, + 0x21 ^ 0x81 + ]; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Exception/ClientNotConnectedException.cs b/src/Z21Client/Core/Exception/ClientNotConnectedException.cs new file mode 100644 index 0000000..e4fa737 --- /dev/null +++ b/src/Z21Client/Core/Exception/ClientNotConnectedException.cs @@ -0,0 +1,9 @@ +using System; + +namespace Z21.Core.Exception +{ + public class ClientNotConnectedException : InvalidOperationException + { + + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Exception/LocoSpeedOutOfRangeException.cs b/src/Z21Client/Core/Exception/LocoSpeedOutOfRangeException.cs new file mode 100644 index 0000000..1ed550b --- /dev/null +++ b/src/Z21Client/Core/Exception/LocoSpeedOutOfRangeException.cs @@ -0,0 +1,24 @@ +using System; +using Z21.Core.Model; + +namespace Z21.Core.Exception +{ + public class LocoSpeedOutOfRangeException(string message, string parameter) : ArgumentOutOfRangeException(message, parameter) + { + public static void ThrowIfOutOfRange(DccSpeedMode dccSpeedMode, ushort locoSpeed) + { + switch (dccSpeedMode) + { + case DccSpeedMode.Steps14 when locoSpeed > 14: + throw new LocoSpeedOutOfRangeException($"{nameof(DccSpeedMode.Steps14)} allows for a maximum speed of 13 steps.", nameof(locoSpeed)); + case DccSpeedMode.Steps28 when locoSpeed > 28: + throw new LocoSpeedOutOfRangeException($"{nameof(DccSpeedMode.Steps28)} allows for a maximum speed of 25 steps.", nameof(locoSpeed)); + case DccSpeedMode.Steps128 when locoSpeed > 126: + throw new LocoSpeedOutOfRangeException($"{nameof(DccSpeedMode.Steps128)} allows for a maximum speed of 125 steps.", nameof(locoSpeed)); + default: + return; + } + } + + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Exception/MtuPayloadLengthExceededException.cs b/src/Z21Client/Core/Exception/MtuPayloadLengthExceededException.cs new file mode 100644 index 0000000..d3c7e03 --- /dev/null +++ b/src/Z21Client/Core/Exception/MtuPayloadLengthExceededException.cs @@ -0,0 +1,13 @@ +using System; + +namespace Z21.Core.Exception +{ + public class MtuPayloadLengthExceededException(string message) : InvalidOperationException(message) + { + public static void ThrowIfExceeded(byte[] datagram) + { + if (datagram.Length > Z21Client.MaxUdpPayload) + throw new MtuPayloadLengthExceededException($"Combined UDP payload length '{datagram.Length}' exceeds MTU size '{Z21Client.MaxUdpPayload}'."); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Helper/AddressHelper.cs b/src/Z21Client/Core/Helper/AddressHelper.cs new file mode 100644 index 0000000..9875864 --- /dev/null +++ b/src/Z21Client/Core/Helper/AddressHelper.cs @@ -0,0 +1,35 @@ +using System; + +namespace Z21.Core.Helper +{ + public static class AddressHelper + { + public static (byte lsb, byte msb) SplitLocoAddress(ushort address) + { + byte lsb = (byte)(address & 0xFF); + byte msb = (byte)((address >> 8) & 0xFF); + + if (address >= 128) + msb |= 0xC0; + + return (lsb, msb); + } + + /// Thrown when > is smaller than 1. + public static (byte lsb, byte msb) SplitAccessoryAddress(ushort address) + { + if (address < 1) + throw new ArgumentOutOfRangeException(nameof(address), address, "Smallest address is 1"); + + ushort dccAddress = (ushort)(address - 1); + byte msb = (byte)((dccAddress >> 8) & 0xFF); + byte lsb = (byte)(dccAddress & 0xFF); + return (lsb, msb); + } + + public static ushort CombineAccessoryAddress(byte lsb, byte msb) + { + return (ushort)((msb << 8) + lsb + 1); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Helper/LocoSpeedHelper.cs b/src/Z21Client/Core/Helper/LocoSpeedHelper.cs new file mode 100644 index 0000000..0ed5559 --- /dev/null +++ b/src/Z21Client/Core/Helper/LocoSpeedHelper.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using Z21.Core.Model; + +namespace Z21.Core.Helper +{ + public class LocoSpeedHelper + { + /// + /// Calculates the dcc step that should send to the Z21. + /// + /// + /// + /// + public static ushort CalculateDccSpeed(DccSpeedMode dccSpeedMode, ushort speedStep) => dccSpeedMode switch + { + DccSpeedMode.Steps14 when speedStep > 0 => (ushort)(speedStep + 1), + DccSpeedMode.Steps28 when speedStep > 0 => CalculateDcc28DccSpeed(speedStep + 3), + DccSpeedMode.Steps128 when speedStep > 0 => (ushort)(speedStep + 1), + _ => speedStep + }; + + private static ushort CalculateDcc28DccSpeed(int speedStep) + { + double dcc14Speed = speedStep / 2.0; + int dccSpeed = (int)Math.Floor(dcc14Speed); + + if (dcc14Speed % 1 != 0) + dccSpeed |= 0x10; + return (ushort)dccSpeed; + } + + /// + /// Calculates the dcc speed step that will be sent to event subscribers. + /// + /// + /// + /// + public static ushort CalculateSpeedStep(DccSpeedMode dccSpeedMode, ushort dccSpeed) => dccSpeedMode switch + { + DccSpeedMode.Steps14 when dccSpeed > 1 => (ushort)(dccSpeed - 1), + DccSpeedMode.Steps28 when dccSpeed > 0 => CalculateDcc28SpeedStep(dccSpeed), + DccSpeedMode.Steps128 when dccSpeed > 1 => (ushort)(dccSpeed - 1), + _ => 0 + }; + + private readonly static Dictionary CalculateDcc28SpeedStepLookup = new() + { + { 0, 0 }, { 16, 0 }, + { 1, 0 }, { 17, 0 }, + { 2, 1 }, { 18, 2 }, + { 3, 3 }, { 19, 4 }, + { 4, 5 }, { 20, 6 }, + { 5, 7 }, { 21, 8 }, + { 6, 9 }, { 22, 10 }, + { 7, 11 }, { 23, 12 }, + { 8, 13 }, { 24, 14 }, + { 9, 15 }, { 25, 16 }, + { 10, 17 }, { 26, 18 }, + { 11, 19 }, { 27, 20 }, + { 12, 21 }, { 28, 22 }, + { 13, 23 }, { 29, 24 }, + { 14, 25 }, { 30, 26 }, + { 15, 27 }, { 31, 28 } + }; + + + private static ushort CalculateDcc28SpeedStep(ushort dccSpeed) + { + return CalculateDcc28SpeedStepLookup[dccSpeed]; + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/IZ21Client.cs b/src/Z21Client/Core/IZ21Client.cs new file mode 100644 index 0000000..ae7e66a --- /dev/null +++ b/src/Z21Client/Core/IZ21Client.cs @@ -0,0 +1,24 @@ +using System; +using System.Threading.Tasks; +using Z21.Core.Command; +using Z21.Core.Exception; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core +{ + public interface IZ21Client + { + event EventHandler? OnConnectionChanged; + + /// + /// Sends to the Z21. + /// + /// Thrown if command length exceeds max udp payload length. + /// Thrown when has not yet been called. + Task SendCommandsAsync(params IZ21Command[] z21Commands); + + Task ConnectAsync(); + + bool IsConnected { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/AccessoryOutput.cs b/src/Z21Client/Core/Model/AccessoryOutput.cs new file mode 100644 index 0000000..efd7ced --- /dev/null +++ b/src/Z21Client/Core/Model/AccessoryOutput.cs @@ -0,0 +1,11 @@ +using System; + +namespace Z21.Core.Model +{ + [Flags] + public enum AccessoryOutput + { + Output1 = 0x0, + Output2 = 0x1 + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/AccessoryState.cs b/src/Z21Client/Core/Model/AccessoryState.cs new file mode 100644 index 0000000..e62a38e --- /dev/null +++ b/src/Z21Client/Core/Model/AccessoryState.cs @@ -0,0 +1,12 @@ +using System; + +namespace Z21.Core.Model +{ + + [Flags] + public enum AccessoryState + { + Deactivate = 0x0, + Activate = 0x8 + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/Capabilities.cs b/src/Z21Client/Core/Model/Capabilities.cs new file mode 100644 index 0000000..e3798ed --- /dev/null +++ b/src/Z21Client/Core/Model/Capabilities.cs @@ -0,0 +1,44 @@ +namespace Z21.Core.Model +{ + /// + /// Represents the supported capabilities of a Z21 device. + /// Each property corresponds to a specific protocol feature. + /// + public class Capabilities + { + /// + /// Indicates whether the device supports DCC (Digital Command Control) protocol. + /// + public bool Dcc { get; init; } + + /// + /// Indicates whether the device supports Märklin Motorola (MM) protocol. + /// + public bool Mm { get; init; } + + /// + /// Indicates whether the device supports RailCom feedback functionality. + /// + public bool RailCom { get; init; } + + /// + /// Indicates whether the device can send locomotive commands. + /// + public bool LocoCmds { get; init; } + + /// + /// Indicates whether the device can send accessory commands (e.g., turnouts, signals). + /// + public bool AccessoryCmds { get; init; } + + /// + /// Indicates whether the device can send detector commands (e.g., feedback modules). + /// + public bool DetectorCmds { get; init; } + + /// + /// Indicates whether the device requires an unlock code to access certain features. + /// + public bool NeedsUnlockCode { get; init; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/CentralState.cs b/src/Z21Client/Core/Model/CentralState.cs new file mode 100644 index 0000000..a434fc2 --- /dev/null +++ b/src/Z21Client/Core/Model/CentralState.cs @@ -0,0 +1,34 @@ +namespace Z21.Core.Model +{ + /// + /// Represents the current operational state of the Z21 central unit. + /// Each property reflects a specific system condition or mode. + /// + public class CentralState + { + /// + /// Indicates whether an emergency stop has been triggered. + /// This halts all train movement immediately. + /// + public bool EmergencyStop { get; init; } + + /// + /// Indicates whether the track voltage is currently turned off. + /// No power is supplied to the rails when this is true. + /// + public bool TrackVoltageOff { get; init; } + + /// + /// Indicates whether a short circuit has been detected on the track. + /// This typically disables power until the fault is resolved. + /// + public bool ShortCircuit { get; init; } + + /// + /// Indicates whether the central unit is currently in programming mode. + /// Used for configuring decoders on the programming track. + /// + public bool ProgrammingModeActive { get; init; } + } + +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/CentralStateEx.cs b/src/Z21Client/Core/Model/CentralStateEx.cs new file mode 100644 index 0000000..2d6adfc --- /dev/null +++ b/src/Z21Client/Core/Model/CentralStateEx.cs @@ -0,0 +1,40 @@ +namespace Z21.Core.Model +{ + /// + /// Represents extended diagnostic states reported by the Z21 central unit. + /// These flags provide additional system-level status information beyond the basic central state. + /// + public class CentralStateEx + { + /// + /// Indicates that the central unit has reached a high internal temperature. + /// This may trigger automatic shutdown or reduced performance to prevent damage. + /// + public bool HighTemperature { get; init; } + + /// + /// Indicates that the central unit has lost its power supply. + /// This typically means the device is running on backup or has shut down. + /// + public bool PowerLost { get; init; } + + /// + /// Indicates that an external short circuit has been detected. + /// This usually refers to a fault in connected boosters or track wiring. + /// + public bool ShortCircuitExternal { get; init; } + + /// + /// Indicates that an internal short circuit has been detected within the central unit. + /// This may require hardware inspection or service. + /// + public bool ShortCircuitInternal { get; init; } + + /// + /// Indicates that RCN-213 protocol-specific conditions are active. + /// This flag is used for RailCom diagnostics and may relate to feedback or communication issues. + /// + public bool Rcn213 { get; init; } + } + +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/DccSpeedMode.cs b/src/Z21Client/Core/Model/DccSpeedMode.cs new file mode 100644 index 0000000..f65309f --- /dev/null +++ b/src/Z21Client/Core/Model/DccSpeedMode.cs @@ -0,0 +1,22 @@ +using System; + +namespace Z21.Core.Model +{ + public enum DccSpeedMode + { + /// + /// Allows for a maximum for 14 steps of speed. + /// + Steps14 = 14, + + /// + /// Allows for a maximum for 28 steps of speed. + /// + Steps28 = 28, + + /// + /// Allows for a maximum for 128 steps of speed. + /// + Steps128 = 128 + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/DecoderMode.cs b/src/Z21Client/Core/Model/DecoderMode.cs new file mode 100644 index 0000000..b0a7302 --- /dev/null +++ b/src/Z21Client/Core/Model/DecoderMode.cs @@ -0,0 +1,20 @@ +namespace Z21.Core.Model +{ + public enum DecoderMode + { + /// + /// DCC format + /// + DCC = 0, + + /// + /// MM format + /// + MM = 1, + + /// + /// Unknown format + /// + Unknown = int.MaxValue + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/DrivingDirection.cs b/src/Z21Client/Core/Model/DrivingDirection.cs new file mode 100644 index 0000000..7a0828b --- /dev/null +++ b/src/Z21Client/Core/Model/DrivingDirection.cs @@ -0,0 +1,11 @@ +using System; + +namespace Z21.Core.Model +{ + [Flags] + public enum DrivingDirection + { + Backward = 0x0, + Forward = 0x80, + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs new file mode 100644 index 0000000..253d360 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class BroadcastFlagsReceivedEventArgs(uint broadCastFlag) : System.EventArgs + { + public uint BroadCastFlag { get; } = broadCastFlag; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/ConnectionChangedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/ConnectionChangedEventArgs.cs new file mode 100644 index 0000000..2052747 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/ConnectionChangedEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class ConnectionChangedEventArgs(bool isConnected) : System.EventArgs + { + public bool IsConnected { get; } = isConnected; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs new file mode 100644 index 0000000..b8794b3 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs @@ -0,0 +1,9 @@ +namespace Z21.Core.Model.EventArgs +{ + public class DecoderModeReceivedEventArgs(short locoAddress, DecoderMode mode) : System.EventArgs + { + public short LocoAddress { get; } = locoAddress; + + public DecoderMode Mode { get; } = mode; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs new file mode 100644 index 0000000..e7e2824 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs @@ -0,0 +1,11 @@ +namespace Z21.Core.Model.EventArgs +{ + public class ExtAccessoryInfoReceivedEventArgs(ushort accessoryAddress, byte encodedState, bool dataValid) : System.EventArgs + { + public ushort AccessoryAddress { get; } = accessoryAddress; + + public byte EncodedState { get; } = encodedState; + + public bool DataValid { get; } = dataValid; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs new file mode 100644 index 0000000..819f30f --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs @@ -0,0 +1,9 @@ +using Z21.Core.ResponseHandler; + +namespace Z21.Core.Model.EventArgs +{ + public class FirmwareVersionReceivedEventArgs(FirmwareVersion firmwareVersion) + { + public FirmwareVersion FirmwareVersion { get; } = firmwareVersion; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/HardwareInfoEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/HardwareInfoEventArgs.cs new file mode 100644 index 0000000..6bd93e6 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/HardwareInfoEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class HardwareInfoEventArgs(int z21HardwareType) : System.EventArgs + { + public int Z21HardwareType { get; init; } = z21HardwareType; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs new file mode 100644 index 0000000..41860f6 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Z21.Core.Model.EventArgs +{ + public class LocoInfoReceivedEventArgs(LocoInfoData data) : System.EventArgs + { + public LocoInfoData Data { get; } = data; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/ResponseReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/ResponseReceivedEventArgs.cs new file mode 100644 index 0000000..00ac865 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/ResponseReceivedEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class ResponseReceivedEventArgs(byte[] response) : System.EventArgs + { + public byte[] Response { get; } = response; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs new file mode 100644 index 0000000..48d5938 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class SerialNumberReceivedEventArgs (uint serialNumber) : System.EventArgs + { + public uint SerialNumber { get; } = serialNumber; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs new file mode 100644 index 0000000..3dd7e6c --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class SoftwareLockReceivedEventArgs(int code) : System.EventArgs + { + public int Code { get; } = code; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs new file mode 100644 index 0000000..7988957 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class StatusChangedReceivedEventArgs(CentralState centralState) + { + public CentralState CentralState { get; } = centralState; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs new file mode 100644 index 0000000..2f986cb --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class SystemStatusChangedReceivedEventArgs (SystemState systemState) + { + public SystemState SystemState { get; } = systemState; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs new file mode 100644 index 0000000..38aa502 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs @@ -0,0 +1,13 @@ +namespace Z21.Core.Model.EventArgs +{ + public class TurnoutInfoReceivedEventArgs(ushort accessoryAddress, AccessoryOutput? accessoryOutput) : System.EventArgs + { + + public ushort AccessoryAddress { get; set; } = accessoryAddress; + + /// + /// State of the turnout. Null if not yet switched or switched with an invalid combination. + /// + public AccessoryOutput? AccessoryOutput { get; set; } = accessoryOutput; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs new file mode 100644 index 0000000..59dbce3 --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.Model.EventArgs +{ + public class UnknownCommandReceivedEventArgs(byte[] unknownDatagram) : System.EventArgs + { + public byte[] UnknownDatagram { get; } = unknownDatagram; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs b/src/Z21Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs new file mode 100644 index 0000000..60695ea --- /dev/null +++ b/src/Z21Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs @@ -0,0 +1,9 @@ +namespace Z21.Core.Model.EventArgs +{ + public class VersionReceivedEventArgs(int xbusVer, int cmdstId) : System.EventArgs + { + public int XbusVer { get; } = xbusVer; + + public int CmdstId { get; } = cmdstId; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs b/src/Z21Client/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs new file mode 100644 index 0000000..d5bfa88 --- /dev/null +++ b/src/Z21Client/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs @@ -0,0 +1,8 @@ +namespace Z21.Core.Model.ExcAccessoryPayload +{ + public interface IExcAccessoryPayload + { + public byte Payload { get; } + } + +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs b/src/Z21Client/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs new file mode 100644 index 0000000..11a9636 --- /dev/null +++ b/src/Z21Client/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs @@ -0,0 +1,26 @@ +using System; + +namespace Z21.Core.Model.ExcAccessoryPayload +{ + /// + /// The 10836 Z21 switch DECODER interprets the payload as "switch decoder with reception of switching time" + /// + public class SwitchDecoderPayload : IExcAccessoryPayload + { + /// + /// The 10836 Z21 switch DECODER interprets the payload as "switch decoder with reception of switching time" + /// + /// Select the decoder output + /// A value of 0 means that the output is switched off. A value of 127 means that the output is switched on permanently, i.e. until the next command to this address + /// Thrown when is bigger then 127 + public SwitchDecoderPayload(AccessoryOutput accessoryOutput, ushort switchTime) + { + if (switchTime > 127) + throw new ArgumentOutOfRangeException(nameof(switchTime), switchTime, "Maximum switch time is 127"); + + Payload = (byte)((int)accessoryOutput | switchTime); + } + + public byte Payload { get; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/FirmwareVersion.cs b/src/Z21Client/Core/Model/FirmwareVersion.cs new file mode 100644 index 0000000..05294a3 --- /dev/null +++ b/src/Z21Client/Core/Model/FirmwareVersion.cs @@ -0,0 +1,13 @@ +namespace Z21.Core.Model +{ + public class FirmwareVersion(int major, int minor) + { + public int Major { get; } = major; + + public int Minor { get; } = minor; + + public string Firmware { get; } = major + "." + minor; + + override public string ToString() => Firmware; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/FunctionToggleType.cs b/src/Z21Client/Core/Model/FunctionToggleType.cs new file mode 100644 index 0000000..32dc7da --- /dev/null +++ b/src/Z21Client/Core/Model/FunctionToggleType.cs @@ -0,0 +1,12 @@ +using System; + +namespace Z21.Core.Model +{ + [Flags] + public enum FunctionToggleType + { + Off = 0x0, + On = 0x40, + Toggle = 0x80 + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/LocoFunctionData.cs b/src/Z21Client/Core/Model/LocoFunctionData.cs new file mode 100644 index 0000000..10ba5eb --- /dev/null +++ b/src/Z21Client/Core/Model/LocoFunctionData.cs @@ -0,0 +1,17 @@ +using System; + +namespace Z21.Core.Model +{ + public class LocoFunctionData(short functionIndex, FunctionToggleType functionToggleType) : IEquatable + { + public short FunctionIndex { get; } = functionIndex; + + public FunctionToggleType FunctionToggleType { get; } = functionToggleType; + + public bool Equals(LocoFunctionData? other) => other != null && other.FunctionIndex == FunctionIndex; + + override public bool Equals(object? obj) => obj is LocoFunctionData functionData && Equals(functionData); + + override public int GetHashCode() => HashCode.Combine(FunctionIndex); + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/LocoInfoData.cs b/src/Z21Client/Core/Model/LocoInfoData.cs new file mode 100644 index 0000000..f90cbd9 --- /dev/null +++ b/src/Z21Client/Core/Model/LocoInfoData.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace Z21.Core.Model +{ + public class LocoInfoData + { + public required short LocoAddress { get; init; } + + public required IReadOnlyCollection LocoFunctionsData { get; init; } + + public required DccSpeedMode DccSpeedMode { get; init; } + + public required DecoderMode DecoderMode { get; init; } + + public required DrivingDirection DrivingDirection { get; init; } + + public required ushort LocoSpeed { get; init; } + + public required bool LocoIsBusy { get; init; } + + public required bool LocoContainedInDoubleTraction { get; init; } + + public required bool SmartSearch { get; init; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/SystemState.cs b/src/Z21Client/Core/Model/SystemState.cs new file mode 100644 index 0000000..f2efc09 --- /dev/null +++ b/src/Z21Client/Core/Model/SystemState.cs @@ -0,0 +1,62 @@ +namespace Z21.Core.Model +{ + /// + /// Represents the complete system status of the Z21 central unit, + /// including electrical measurements, temperature, and operational flags. + /// + public class SystemState + { + /// + /// The current (in milliamps) drawn by the main track output. + /// + public int MainCurrent { get; init; } + + /// + /// The current (in milliamps) drawn by the programming track output. + /// + public int ProgCurrent { get; init; } + + /// + /// The filtered current (in milliamps) of the main track output. + /// This value may be smoothed or averaged for diagnostics. + /// + public int FilteredMainCurrent { get; init; } + + /// + /// The internal temperature of the Z21 unit (in degrees Celsius). + /// + public int Temperature { get; init; } + + /// + /// The supply voltage (in millivolts) provided to the Z21 unit. + /// + public int SupplyVoltage { get; init; } + + /// + /// The internal Vcc voltage (in millivolts) used by the Z21 logic circuits. + /// + public int VccVoltage { get; init; } + + /// + /// The basic operational state of the Z21 central unit, + /// including emergency stop, voltage status, and programming mode. + /// + public required CentralState CentralState { get; init; } + + /// + /// Extended diagnostic flags from the Z21 central unit, + /// such as temperature warnings, power loss, and short circuit conditions. + /// + public required CentralStateEx CentralStateEx { get; init; } + + // Reserved field for future use or protocol alignment. + // public int? Reserved { get; init; } + + /// + /// The set of capabilities supported by the Z21 device, + /// such as RailCom, LocoNet, and accessory command support. + /// Will be null on older firmware versions. + /// + public Capabilities? Capabilities { get; init; } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/Z21BroadcastFlags.cs b/src/Z21Client/Core/Model/Z21BroadcastFlags.cs new file mode 100644 index 0000000..25958a4 --- /dev/null +++ b/src/Z21Client/Core/Model/Z21BroadcastFlags.cs @@ -0,0 +1,31 @@ +namespace Z21.Core.Model +{ + public static class Z21BroadcastFlags + { + /// + /// Automatically generated broadcasts and messages related to driving and switching are delivered to the registered client. + /// The client needs to be subscribed to a locomotive address to receive messages. + /// + public const uint DriveAndSwitchingMessages = 0x00000001; + + /// + /// Changes to feedback sensors on the R-Bus are sent automatically. + /// + public const uint RmBusDataChangedMessages = 0x00000002; + + /// + /// Changes in RailCom data of subscribed locomotives are sent automatically. + /// + public const uint RailComDataChangedMessages = 0x00000004; + + /// + /// Changes in the Z21 system status are sent automatically. + /// + public const uint SystemStateDataChangedMessages = 0x00000100; + + /// + /// The client now receives loco info changed messages without having to subscribe to the corresponding locomotive addresses beforehand. Creates a lot of traffic, should only be used on pcs. + /// + public const uint LocoInfoChangedMessages = 0x00010000; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/Z21Configuration.cs b/src/Z21Client/Core/Model/Z21Configuration.cs new file mode 100644 index 0000000..f292120 --- /dev/null +++ b/src/Z21Client/Core/Model/Z21Configuration.cs @@ -0,0 +1,53 @@ +using System; +using System.Net; + +// ReSharper disable InconsistentNaming + +namespace Z21.Core.Model +{ + public class Z21Configuration + { + + public Z21Configuration(IPEndPoint clientIpEndPoint) + { + ArgumentNullException.ThrowIfNull(clientIpEndPoint, nameof(clientIpEndPoint)); + + ClientIPEndPoint = clientIpEndPoint; + } + + /// + /// IPEndPoint of the Z21. + /// + public IPEndPoint ClientIPEndPoint { get; } + + /// + /// Enables or disables Network Address Translation (NAT) traversal on a UdpClient instance. + /// + public bool AllowNatTraversal { get; set; } = true; + + /// + /// Configures the interval in witch the client will send a keep alive command to the z21. This Setting should not need changing! + /// + /// The specification states that the client must communicate at least once per minute with the z21 or else the z21 assumes that the client has disconnected. + public TimeSpan ConnectionKeepAliveCommandInterval { get; set; } = TimeSpan.FromSeconds(20); + + /// + /// Time it takes between a command being sent and a response being received. This Setting should not need changing! + /// + public TimeSpan ResponseTime { get; set; } = TimeSpan.FromSeconds(2); + + /// + /// Configures the default broadcast flags that should be sent to the Z21 + /// + public uint[] BroadcastFlags { get; set; } = + [ + Z21BroadcastFlags.DriveAndSwitchingMessages, + Z21BroadcastFlags.LocoInfoChangedMessages + ]; + + public static class Defaults + { + public readonly static IPEndPoint IpEndPoint = new(IPAddress.Parse("192.168.0.111"), 21105); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/Z21HardwareType.cs b/src/Z21Client/Core/Model/Z21HardwareType.cs new file mode 100644 index 0000000..024054a --- /dev/null +++ b/src/Z21Client/Core/Model/Z21HardwareType.cs @@ -0,0 +1,62 @@ +// ReSharper disable InconsistentNaming + +namespace Z21.Core.Model +{ + public static class Z21HardwareType + { + /// + /// Black Z21. Hardware version till 2012. + /// + public const int Z21Old = 0x00000200; + + /// + /// Black Z21. Hardware version beginning 2013. + /// + public const int Z21New = 0x00000201; + + /// + /// Smartrail. Starting 2012. + /// + public const int Smartrail = 0x00000202; + + /// + /// white z21. Starterset variant starting 2013. + /// + public const int z21Small = 0x00000203; + + /// + /// z21 start. Starterset variant starting 2016. + /// + public const int z21Start = 0x00000204; + + /// + /// 10806 „Z21 Single Booster” (zLink) + /// + public const int SingleBooster = 0x00000205; + + /// + /// 10807 „Z21 Dual Booster” (zLink) + /// + public const int DualBooster = 0x00000206; + + /// + /// 10870 „Z21 XL Series” (starting 2020) + /// + public const int Z21Xl = 0x00000211; + + /// + /// 10869 „Z21 XL Booster” (starting 2021, zLink) + /// + public const int XlBooster = 0x00000212; + + /// + /// 10836 „Z21 SwitchDecoder” (zLink) + /// + public const int Z21SwitchDecoder = 0x00000301; + + /// + /// 10836 „Z21 SignalDecoder” (zLink) + /// + public const int Z21SignalDecoder = 0x00000302; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Model/Z21SoftwareLock.cs b/src/Z21Client/Core/Model/Z21SoftwareLock.cs new file mode 100644 index 0000000..8c53afe --- /dev/null +++ b/src/Z21Client/Core/Model/Z21SoftwareLock.cs @@ -0,0 +1,20 @@ +namespace Z21.Core.Model +{ + public static class Z21SoftwareLock + { + /// + /// No feature locked. + /// + public const int NoLock = 0x00; + + /// + /// z21 start: Driving and switching per lan locked. + /// + public const int Z21StartLocked = 0x01; + + /// + /// z21 start: no feature locked. + /// + public const int Z21StartUnlocked = 0x02; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs new file mode 100644 index 0000000..344cb5d --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Z21.Core.Command.Driving; +using Z21.Core.Command.SystemState; +using Z21.Core.Helper; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.Driving +{ + public interface ILocoInfoResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnLocoInfoReceived; + } + + /// + /// This message is sent from the Z21 to the clients in response to the command . + /// It is also unsolicitedly sent to an associated client if the locomotive status has been changed by one of the (other) clients or handset controls and the associated client has activated the corresponding broadcast or via . + /// + public class LocoInfoResponseHandler : ILocoInfoResponseHandler + { + public string Name => "LAN_X_LOCO_INFO"; + + public event EventHandler? OnLocoInfoReceived; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 && response[3] == 0x00 && response[4] == 0xEF; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + short address = (short)(((response[5] & 0x3F) << 8) + response[6]); + + byte db2 = response[7]; + DecoderMode decoderMode = (db2 & 0x10) == 0x10 ? DecoderMode.MM : DecoderMode.DCC; + bool locoIsBusy = (db2 & 0x8) == 0x8; + + DccSpeedMode speedMode = (DccSpeedMode)999; + if ((db2 & 0x1) == 0x1) + speedMode = DccSpeedMode.Steps14; + if ((db2 & 0x2) == 0x2) + speedMode = DccSpeedMode.Steps28; + if ((db2 & 0x4) == 0x4) + speedMode = DccSpeedMode.Steps128; + + byte db3 = response[8]; + DrivingDirection drivingDirection = (db3 & 0x80) == 0x80 ? DrivingDirection.Forward : DrivingDirection.Backward; + ushort stepSpeed = LocoSpeedHelper.CalculateSpeedStep(speedMode, (ushort)(db3 & 0x7F)); + + byte db4 = response[9]; + bool locoContainedInDoubleTraction = (db4 & 0x40) == 0x40; + bool smartSearch = (db4 & 0x20) == 0x20; + + List infodata = + [ + new(0, GetFunctionToggleType((db4 & 0x10) == 0x10)), + new(4, GetFunctionToggleType((db4 & 0x8) == 0x8)), + new(3, GetFunctionToggleType((db4 & 0x4) == 0x4)), + new(2, GetFunctionToggleType((db4 & 0x2) == 0x2)), + new(1, GetFunctionToggleType((db4 & 0x1) == 0x1)) + ]; + + int functionAddressCount = 5; + for (int index = 10; index < response.Length - 2; index++) + { + BitArray functionBits = new(new[] { response[index] }); + for (int temp = 0; temp < 8; temp++) + { + infodata.Add(new((short)functionAddressCount++, GetFunctionToggleType(functionBits.Get(temp)))); + } + } + + string function = string.Join(", ", infodata.Select(functionData => $"F{functionData.FunctionIndex}: {functionData.FunctionToggleType}")); + Console.WriteLine($"Address: {address}, DecoderMode: {decoderMode}, Busy: {locoIsBusy}, DccSpeedMode: {speedMode}, Direction: {drivingDirection}, Speed: {stepSpeed}, Double Traction: {locoContainedInDoubleTraction}, smartSearch: {smartSearch}\n{function}"); + + OnLocoInfoReceived?.Invoke(this, + new(new() + { + LocoAddress = address, + LocoFunctionsData = infodata.AsReadOnly(), + DccSpeedMode = speedMode, + DecoderMode = decoderMode, + DrivingDirection = drivingDirection, + LocoSpeed = stepSpeed, + LocoIsBusy = locoIsBusy, + LocoContainedInDoubleTraction = locoContainedInDoubleTraction, + SmartSearch = smartSearch + })); + } + + private static FunctionToggleType GetFunctionToggleType(bool value) => value ? FunctionToggleType.On : FunctionToggleType.Off; + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/IZ21ResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/IZ21ResponseHandler.cs new file mode 100644 index 0000000..62662f5 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/IZ21ResponseHandler.cs @@ -0,0 +1,21 @@ +using System; + +namespace Z21.Core.ResponseHandler +{ + public interface IZ21ResponseHandler + { + /// + /// Human-readable command according to the specification. + /// + public string Name { get; } + + /// + /// Returns true if this response handler can handle the response. False otherwise. + /// + /// + /// + public bool CanHandle(byte[] response); + + public void Handle(byte[] response); + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs new file mode 100644 index 0000000..1bd4d6a --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs @@ -0,0 +1,50 @@ +using System; +using System.Buffers.Binary; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.Settings +{ + public interface IAccessoryModeResponseHandler + { + event EventHandler? OnAccessoryModeReceived; + } + + /// + /// Read the settings for a given accessory decoder address ("Accessory Decoder" RP-9.2.1). + /// + /// + /// In the Z21, the output format (DCC, MM) is persistently stored for each accessory decoder address. A maximum of 256 different accessory decoder addresses can be stored. Each address >= 256 automatically is DCC. + /// + public class AccessoryModeResponseHandler : IAccessoryModeResponseHandler + { + + public event EventHandler? OnAccessoryModeReceived; + + public string Name => "LAN_GET_TURNOUTMODE"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x70 && response[3] == 0x00; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + byte[] cutDatagram = new byte[2]; + Buffer.BlockCopy(response, 4, cutDatagram, 0, 2); + short locoAddress = BinaryPrimitives.ReadInt16BigEndian(cutDatagram); + + byte rawMode = response[6]; + DecoderMode mode = Enum.IsDefined(typeof(DecoderMode), (int)rawMode) ? (DecoderMode)rawMode : DecoderMode.Unknown; + + OnAccessoryModeReceived?.Invoke(this, new(locoAddress, mode)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs new file mode 100644 index 0000000..79bb9c8 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs @@ -0,0 +1,49 @@ +using System; +using System.Buffers.Binary; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.Settings +{ + public interface ILocoModeResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnLocoModeReceived; + } + + /// + /// Read the output format for a given locomotive address. + /// + /// + /// In the Z21, the output format (DCC, MM) is persistently stored for each locomotive address. A maximum of 256 different locomotive addresses can be stored. Each address >= 256 is DCC automatically. + /// + public class LocoModeResponseHandler : ILocoModeResponseHandler + { + public event EventHandler? OnLocoModeReceived; + + public string Name => "LAN_GET_LOCOMODE"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x60 && response[3] == 0x00; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + byte[] cutDatagram = new byte[2]; + Buffer.BlockCopy(response, 4, cutDatagram, 0, 2); + short locoAddress = BinaryPrimitives.ReadInt16BigEndian(cutDatagram); + + byte rawMode = response[6]; + DecoderMode mode = Enum.IsDefined(typeof(DecoderMode), (int)rawMode) ? (DecoderMode)rawMode : DecoderMode.Unknown; + + OnLocoModeReceived?.Invoke(this, new(locoAddress, mode)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs new file mode 100644 index 0000000..a2e1ced --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs @@ -0,0 +1,48 @@ +using System; +using Z21.Core.Command.Switching; +using Z21.Core.Command.SystemState; +using Z21.Core.Helper; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.Switching +{ + public interface IExtAccessoryInfoResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnExtAccessoryInfoReceived; + } + + /// + /// Reads the encoded extended accessory decoder state either because it was requested via or the accessory status has been changed by other clients or a handset controller and the client has activated the corresponding broadcast via . + /// + public class ExtAccessoryInfoResponseHandler : IExtAccessoryInfoResponseHandler + { + public event EventHandler? OnExtAccessoryInfoReceived; + + public string Name => "LAN_X_EXT_ACCESSORY_INFO"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 && response[3] == 0x00 && response[4] == 0x44; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + byte msb = response[5]; + byte lsb = response[6]; + ushort address = AddressHelper.CombineAccessoryAddress(lsb, msb); + + byte db2 = response[7]; + byte status = response[8]; + + OnExtAccessoryInfoReceived?.Invoke(this, new(address, db2, status == 0)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs new file mode 100644 index 0000000..bde875a --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs @@ -0,0 +1,55 @@ +using System; +using Z21.Core.Command.Switching; +using Z21.Core.Command.SystemState; +using Z21.Core.Helper; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.Switching +{ + public interface ITurnoutInfoResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnTurnoutInfoReceived; + } + + /// + /// This message is sent from the Z21 to the clients in response to the command . + /// It is also sent to an associated client unsolicitedly if the function status has been changed by one of the (other) clients or a handset controller and the associated client has activated the corresponding broadcast via + /// + public class TurnoutInfoResponseHandler : ITurnoutInfoResponseHandler + { + + public event EventHandler? OnTurnoutInfoReceived; + + public string Name => "LAN_X_TURNOUT_INFO"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 && response[3] == 0x00 && response[4] == 0x43; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + byte msb = response[5]; + byte lsb = response[6]; + ushort address = AddressHelper.CombineAccessoryAddress(lsb, msb); + + byte db2 = response[7]; + AccessoryOutput? accessoryOutput = null; + if (db2 == 0x1) + accessoryOutput = AccessoryOutput.Output1; + if (db2 == 0x02) + accessoryOutput = AccessoryOutput.Output2; + + Console.WriteLine($"Turnout: {address}, State: {accessoryOutput}"); + OnTurnoutInfoReceived?.Invoke(this, new(address, accessoryOutput)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs new file mode 100644 index 0000000..16e69c8 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs @@ -0,0 +1,39 @@ +using System; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface IBroadcastFlagsResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnBroadcastFlagsReceived; + } + + /// + /// Reading the broadcast flags in the Z21. + /// + public class BroadcastFlagsResponseHandler : IBroadcastFlagsResponseHandler + { + public event EventHandler? OnBroadcastFlagsReceived; + + public string Name => "LAN_GET_BROADCASTFLAGS"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x51 + && response[3] == 0x00; + } catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + uint flag = BitConverter.ToUInt32(response, 4); + + OnBroadcastFlagsReceived?.Invoke(this, new(flag)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs new file mode 100644 index 0000000..df1158e --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs @@ -0,0 +1,49 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface IFirmwareVersionResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnFirmwareVersionReceived; + } + + /// + /// Reads the firmware version of the Z21 when requested with . + /// + public class FirmwareVersionResponseHandler : IFirmwareVersionResponseHandler + { + public event EventHandler? OnFirmwareVersionReceived; + + public string Name => "LAN_X_GET_FIRMWARE_VERSION"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 + && response[3] == 0x00 + && response[4] == 0xF3 + && response[5] == 0x0A + && (response[4] ^ response[5] ^ response[6] ^ response[7]) == response[8]; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + OnFirmwareVersionReceived?.Invoke(this, new(new(BcdToInt(response[6]), BcdToInt(response[7])))); + } + + protected virtual int BcdToInt(byte bcd) + { + int highNibble = (bcd >> 4) & 0xF; + int lowNibble = bcd & 0xF; + return highNibble * 10 + lowNibble; + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs new file mode 100644 index 0000000..a12287c --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs @@ -0,0 +1,41 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface IHardwareInfoResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnHardwareInfoReceived; + } + + /// + /// Reads the hardware type and the firmware version of the Z21 when requested via . + /// + public class HardwareInfoResponseHandler : IHardwareInfoResponseHandler + { + public string Name => "LAN_GET_HWINFO"; + + public event EventHandler? OnHardwareInfoReceived; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x1A && response[3] == 0x00; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + // TODO: calculate FW version and add to HardwareInfoEventArgs + int hwType = BitConverter.ToInt32(response, 4); + OnHardwareInfoReceived?.Invoke(this, new(hwType)); + } + + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs new file mode 100644 index 0000000..6172121 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs @@ -0,0 +1,40 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface ISerialNumberResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnSerialNumberReceived; + } + + /// + /// Reads the serial number of the Z21 when requested via . + /// + public class SerialNumberResponseHandler : ISerialNumberResponseHandler + { + public event EventHandler? OnSerialNumberReceived; + + public string Name => "LAN_GET_SERIAL_NUMBER"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x10 + && response[3] == 0x00; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + uint serialNumber = BitConverter.ToUInt32(response, 4); + OnSerialNumberReceived?.Invoke(this, new(serialNumber)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs new file mode 100644 index 0000000..459a378 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs @@ -0,0 +1,38 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface ISoftwareLockResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnSoftwareLockReceived; + } + + /// + /// Reads the software feature scope of the Z21 when request via . + /// + public class SoftwareLockResponseHandler : ISoftwareLockResponseHandler + { + public string Name => "LAN_GET_CODE"; + + public event EventHandler? OnSoftwareLockReceived; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x18 && response[3] == 0x00; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + OnSoftwareLockReceived?.Invoke(this, new(response[4])); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs new file mode 100644 index 0000000..95e6773 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs @@ -0,0 +1,47 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseParser; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface IStatusChangedResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnStatusChangedReceived; + } + + /// + /// Reads the Z21 status when requested via . + /// + public class StatusChangedResponseHandler(ICentralStateResponseParser centralStateResponseParser) + : IStatusChangedResponseHandler + { + public event EventHandler? OnStatusChangedReceived; + + public string Name => "LAN_X_STATUS_CHANGED"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 + && response[3] == 0x00 + && response[4] == 0x62 + && response[5] == 0x22 + && (response[4] ^ response[5] ^ response[6]) == response[7]; + } catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + byte statusByte = response[6]; + + CentralState centralState = centralStateResponseParser.Parse(statusByte); + OnStatusChangedReceived?.Invoke(this, new(centralState)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs new file mode 100644 index 0000000..bc64320 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs @@ -0,0 +1,42 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseParser; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface ISystemStateDataChangedResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnSystemStateDataChangedReceived; + } + + /// + /// Reports a change in the system status from the Z21 to the client either automatically when is set via or when requested via . + /// + public class SystemStateDataChangedResponseHandler(ISystemStateResponseParser systemStateResponseParser) : ISystemStateDataChangedResponseHandler + { + public string Name => "LAN_SYSTEMSTATE_DATACHANGED"; + + public event EventHandler? OnSystemStateDataChangedReceived; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x84 && response[3] == 0x00; + } catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + byte[] data = new byte[16]; + Buffer.BlockCopy(response, 4, data, 0, 16); + + OnSystemStateDataChangedReceived?.Invoke(this, new (systemStateResponseParser.Parse(data))); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs new file mode 100644 index 0000000..00dd29e --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs @@ -0,0 +1,40 @@ +using System; + +namespace Z21.Core.ResponseHandler.SystemState.TrackPower +{ + public interface IProgrammingModeResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnProgrammingModeReceived; + } + + /// + /// The following packet is sent from the Z21 to the registered clients if the Z21 has been put into CV programming mode via LAN_X_CV_READ or LAN_X_CV_WRITE + /// + public class ProgrammingModeResponseHandler : IProgrammingModeResponseHandler + { + public event EventHandler? OnProgrammingModeReceived; + + public string Name => "LAN_X_BC_PROGRAMMING_MODE"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 + && response[3] == 0x00 + && response[4] == 0x61 + && response[5] == 0x02 + && (response[4] ^ response[5]) == 0x63; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + OnProgrammingModeReceived?.Invoke(this, EventArgs.Empty); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs new file mode 100644 index 0000000..3d4e233 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs @@ -0,0 +1,43 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Command.SystemState.TrackPower; +using Z21.Core.Model; + +namespace Z21.Core.ResponseHandler.SystemState.TrackPower +{ + public interface IStoppedResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnStoppedReceived; + } + + /// + /// The following packet is sent from the Z21 to the registered clients when a client has sent or the emergency stop was triggered by some input device (multiMaus) and the relevant client has activated the corresponding broadcast the corresponding broadcast via + /// + public class StoppedResponseHandler : IStoppedResponseHandler + { + public event EventHandler? OnStoppedReceived; + + public string Name => "LAN_X_BC_STOPPED"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 + && response[3] == 0x00 + && response[4] == 0x81 + && response[5] == 0x00 + && (response[4] ^ response[5]) == 0x81; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + OnStoppedReceived?.Invoke(this, EventArgs.Empty); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs new file mode 100644 index 0000000..4055a94 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs @@ -0,0 +1,43 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Command.SystemState.TrackPower; +using Z21.Core.Model; + +namespace Z21.Core.ResponseHandler.SystemState.TrackPower +{ + public interface ITrackPowerOffResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnTrackPowerOffReceived; + } + + /// + /// The following packet is sent from the Z21 to the registered clients when a client has sent command > or the track voltage has been switched off by some input device (multiMaus) and the relevant client has activated the corresponding broadcast via + /// + public class TrackPowerOffResponseHandler : ITrackPowerOffResponseHandler + { + public event EventHandler? OnTrackPowerOffReceived; + + public string Name => "LAN_X_BC_TRACK_POWER_OFF"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 + && response[3] == 0x00 + && response[4] == 0x61 + && response[5] == 0x00 + && (response[4] ^ response[5]) == 0x61; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + OnTrackPowerOffReceived?.Invoke(this, EventArgs.Empty); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs new file mode 100644 index 0000000..3f62470 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs @@ -0,0 +1,43 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Command.SystemState.TrackPower; +using Z21.Core.Model; + +namespace Z21.Core.ResponseHandler.SystemState.TrackPower +{ + public interface ITrackPowerOnResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnTrackPowerOnReceived; + } + + /// + /// The following packet is sent from the Z21 to the registered clients when a client has sent command > or the track voltage has been switched on by some input device (multiMaus) and the relevant client has activated the corresponding broadcast via + /// + public class TrackPowerOnResponseHandler : ITrackPowerOnResponseHandler + { + public event EventHandler? OnTrackPowerOnReceived; + + public string Name => "LAN_X_BC_TRACK_POWER_ON"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 + && response[3] == 0x00 + && response[4] == 0x61 + && response[5] == 0x01 + && (response[4] ^ response[5]) == 0x60; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + OnTrackPowerOnReceived?.Invoke(this, EventArgs.Empty); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs new file mode 100644 index 0000000..db54b4f --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs @@ -0,0 +1,42 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Model; + +namespace Z21.Core.ResponseHandler.SystemState.TrackPower +{ + public interface ITrackShortResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnTrackShortReceived; + } + + /// + /// The following packet is sent from the Z21 to the registered clients if a short circuit has occurred and the relevant client has activated the corresponding broadcast via + /// + public class TrackShortResponseHandler : ITrackShortResponseHandler + { + public event EventHandler? OnTrackShortReceived; + + public string Name => "LAN_X_BC_TRACK_SHORT_CIRCUIT"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 + && response[3] == 0x00 + && response[4] == 0x61 + && response[5] == 0x08 + && (response[4] ^ response[5]) == 0x69; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + OnTrackShortReceived?.Invoke(this, EventArgs.Empty); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs new file mode 100644 index 0000000..a5a5c33 --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs @@ -0,0 +1,41 @@ +using System; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface IUnknownCommandResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnUnknownCommandReceived; + } + + /// + /// The following packet is sent from the Z21 to the client in response to an invalid request. + /// + public class UnknownCommandResponseHandler : IUnknownCommandResponseHandler + { + public event EventHandler? OnUnknownCommandReceived; + + public string Name => "LAN_X_UNKNOWN_COMMAND"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 + && response[3] == 0x00 + && response[4] == 0x61 + && response[5] == 0x82 + && (response[4] ^ response[5]) == 0xE3; + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + OnUnknownCommandReceived?.Invoke(this, new(response)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs b/src/Z21Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs new file mode 100644 index 0000000..975d54e --- /dev/null +++ b/src/Z21Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs @@ -0,0 +1,43 @@ +using System; +using Z21.Core.Command.SystemState; +using Z21.Core.Model.EventArgs; + +namespace Z21.Core.ResponseHandler.SystemState +{ + public interface IVersionResponseHandler : IZ21ResponseHandler + { + event EventHandler? OnVersionReceived; + } + + /// + /// Reads the X-Bus version of the Z21 when requested via . + /// + public class VersionResponseHandler : IVersionResponseHandler + { + public event EventHandler? OnVersionReceived; + + public string Name => "LAN_X_GET_VERSION"; + + public bool CanHandle(byte[] response) + { + try + { + return response[2] == 0x40 && + response[4] == 0x63 && + response[5] == 0x21; + // TODO handle XOR-Byte + } + catch (IndexOutOfRangeException) + { + return false; + } + } + + public void Handle(byte[] response) + { + byte xbusVer = response[6]; + byte cmdStationId = response[7]; + OnVersionReceived?.Invoke(this, new(xbusVer, cmdStationId)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseParser/CapabilitiesResponseParser.cs b/src/Z21Client/Core/ResponseParser/CapabilitiesResponseParser.cs new file mode 100644 index 0000000..50dcb54 --- /dev/null +++ b/src/Z21Client/Core/ResponseParser/CapabilitiesResponseParser.cs @@ -0,0 +1,28 @@ +using Z21.Core.Model; + +namespace Z21.Core.ResponseParser +{ + public interface ICapabilitiesResponseParser : IZ21ResponseParser + { + Capabilities? Parse(byte statusByte); + } + + public class CapabilitiesResponseParser : ICapabilitiesResponseParser + { + public Capabilities? Parse(byte statusByte) + { + if (statusByte == 0) + return null; + return new() + { + Dcc = (statusByte & 0x01) == 0x01, + Mm = (statusByte & 0x02) == 0x02, + RailCom = (statusByte & 0x08) == 0x08, + LocoCmds = (statusByte & 0x10) == 0x10, + AccessoryCmds = (statusByte & 0x20) == 0x20, + DetectorCmds = (statusByte & 0x40) == 0x40, + NeedsUnlockCode = (statusByte & 0x80) == 0x80, + }; + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseParser/CentralStateExResponseParser.cs b/src/Z21Client/Core/ResponseParser/CentralStateExResponseParser.cs new file mode 100644 index 0000000..5052d03 --- /dev/null +++ b/src/Z21Client/Core/ResponseParser/CentralStateExResponseParser.cs @@ -0,0 +1,24 @@ +using Z21.Core.Model; + +namespace Z21.Core.ResponseParser +{ + public interface ICentralStateExResponseParser : IZ21ResponseParser + { + CentralStateEx Parse(byte statusByte); + } + + public class CentralStateExResponseParser : ICentralStateExResponseParser + { + public CentralStateEx Parse(byte statusByte) + { + return new() + { + HighTemperature = (statusByte & 0x01) == 0x01, + PowerLost = (statusByte & 0x02) == 0x02, + ShortCircuitExternal = (statusByte & 0x04) == 0x04, + ShortCircuitInternal = (statusByte & 0x08) == 0x08, + Rcn213 = (statusByte & 0x20) == 0x20, + }; + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseParser/CentralStateResponseParser.cs b/src/Z21Client/Core/ResponseParser/CentralStateResponseParser.cs new file mode 100644 index 0000000..aa2ee6b --- /dev/null +++ b/src/Z21Client/Core/ResponseParser/CentralStateResponseParser.cs @@ -0,0 +1,23 @@ +using Z21.Core.Model; + +namespace Z21.Core.ResponseParser +{ + public interface ICentralStateResponseParser : IZ21ResponseParser + { + public CentralState Parse(byte statusByte); + } + + public class CentralStateResponseParser : ICentralStateResponseParser + { + public CentralState Parse(byte statusByte) + { + return new() + { + EmergencyStop = (statusByte & 0x01) == 0x01, + TrackVoltageOff = (statusByte & 0x02) == 0x02, + ShortCircuit = (statusByte & 0x04) == 0x04, + ProgrammingModeActive = (statusByte & 0x20) == 0x20 + }; + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseParser/IZ21ResponseParser.cs b/src/Z21Client/Core/ResponseParser/IZ21ResponseParser.cs new file mode 100644 index 0000000..f94ac44 --- /dev/null +++ b/src/Z21Client/Core/ResponseParser/IZ21ResponseParser.cs @@ -0,0 +1,7 @@ +namespace Z21.Core.ResponseParser +{ + public interface IZ21ResponseParser + { + + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/ResponseParser/SystemStateResponseParser.cs b/src/Z21Client/Core/ResponseParser/SystemStateResponseParser.cs new file mode 100644 index 0000000..3ae3ab3 --- /dev/null +++ b/src/Z21Client/Core/ResponseParser/SystemStateResponseParser.cs @@ -0,0 +1,30 @@ +using System; +using Z21.Core.Model; + +namespace Z21.Core.ResponseParser +{ + public interface ISystemStateResponseParser : IZ21ResponseParser + { + public SystemState Parse(byte[] data); + } + + public class SystemStateResponseParser(ICentralStateResponseParser centralStateResponseParser, ICentralStateExResponseParser centralStateExResponseParser, ICapabilitiesResponseParser capabilitiesResponseParser) + : ISystemStateResponseParser + { + public SystemState Parse(byte[] data) + { + return new() + { + MainCurrent = BitConverter.ToInt16(data, 0), + ProgCurrent = BitConverter.ToInt16(data, 2), + FilteredMainCurrent = BitConverter.ToInt16(data, 4), + Temperature = BitConverter.ToInt16(data, 6), + SupplyVoltage = BitConverter.ToUInt16(data, 8), + VccVoltage = BitConverter.ToUInt16(data, 10), + CentralState = centralStateResponseParser.Parse(data[12]), + CentralStateEx = centralStateExResponseParser.Parse(data[13]), + Capabilities = capabilitiesResponseParser.Parse(data[15]) + }; + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Core/Z21Client.cs b/src/Z21Client/Core/Z21Client.cs new file mode 100644 index 0000000..77765f6 --- /dev/null +++ b/src/Z21Client/Core/Z21Client.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Timers; +using Microsoft.Extensions.Logging; +using Z21.Core.Command; +using Z21.Core.Command.SystemState; +using Z21.Core.Exception; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; +using Z21.Core.ResponseHandler; +using Z21.Transport; +// ReSharper disable ClassWithVirtualMembersNeverInherited.Global + +namespace Z21.Core +{ + public class Z21Client : IZ21Client + { + private bool _previousIsConnected; + private DateTime _lastCommunication = DateTime.MinValue; + private readonly Timer _connectionKeepAlive; + private readonly ILogger _logger; + private readonly Z21Configuration _z21Configuration; + private readonly IZ21Transport _transport; + private readonly List _handlers; + + /// + /// IPv4 safe MTU for payload according to specification. + /// + public const int MaxUdpPayload = 1472; + + /// Thrown when system architecture is not little-endian. + public Z21Client(Z21Configuration z21Configuration, IZ21Transport z21Transport, IEnumerable z21ResponseHandlers, ILogger logger) + { + ArgumentNullException.ThrowIfNull(z21Configuration, nameof(z21Configuration)); + ArgumentNullException.ThrowIfNull(z21Transport, nameof(z21Transport)); + ArgumentNullException.ThrowIfNull(z21ResponseHandlers, nameof(z21ResponseHandlers)); + ArgumentNullException.ThrowIfNull(logger, nameof(logger)); + + if (!BitConverter.IsLittleEndian) + throw new PlatformNotSupportedException("Z21Client requires little-endian architecture."); + + _z21Configuration = z21Configuration; + _transport = z21Transport; + _handlers = z21ResponseHandlers.ToList(); + _logger = logger; + _transport.OnResponseReceived += Transport_OnResponseReceived; + + _connectionKeepAlive = new(z21Configuration.ConnectionKeepAliveCommandInterval) + { + AutoReset = true, + Enabled = false + }; + _connectionKeepAlive.Elapsed += ConnectionKeepAlive_OnElapsed; + } + + public event EventHandler? OnConnectionChanged; + + public bool IsConnected => DateTime.UtcNow - _lastCommunication < _z21Configuration.ConnectionKeepAliveCommandInterval + _z21Configuration.ResponseTime; + + public async Task ConnectAsync() + { + _logger.LogInformation("Z21Client trying to connect with {ClientIPEndPoint}.", _transport.Z21Configuration.ClientIPEndPoint); + _transport.Connect(); + _connectionKeepAlive.Enabled = true; + await SendCommandsAsync(new GetFirmwareVersionCommand()); + } + + public async Task SendCommandsAsync(params IZ21Command[] z21Commands) + { + ArgumentNullException.ThrowIfNull(z21Commands, nameof(z21Commands)); + + if (!_transport.IsConnected) + throw new ClientNotConnectedException(); + + foreach (IZ21Command z21Command in z21Commands) + _logger.LogDebug("{commandName} sending {datagram} to Z21.", z21Command.Name, BitConverter.ToString(z21Command.Data)); + + byte[] combinedPayload = z21Commands.SelectMany(z21Command => z21Command.Data).ToArray(); + + MtuPayloadLengthExceededException.ThrowIfExceeded(combinedPayload); + + _connectionKeepAlive.Stop(); + _connectionKeepAlive.Start(); + await VerifyConnectionOnDemandAsync(); + + await _transport.SendAsync(combinedPayload); + } + + public List CutDatagram(byte[] datagram) + { + List cutDatagrams = []; + int offset = 0; + while (offset < datagram.Length) + { + try + { + if (offset + 2 > datagram.Length) + { + _logger.LogError("Incomplete DataLen field — discarding remainder. Data: {datagram}", BitConverter.ToString(datagram)); + return cutDatagrams; + } + + ushort dataLen = (ushort)(datagram[offset] | (datagram[offset + 1] << 8)); + + if (offset + dataLen > datagram.Length) + { + _logger.LogError("Incomplete packet — discarding remainder. Data: {datagram}", BitConverter.ToString(datagram)); + return cutDatagrams; + } + + byte[] cutDatagram = new byte[dataLen]; + Buffer.BlockCopy(datagram, offset, cutDatagram, 0, dataLen); + _logger.LogDebug("Received cut datagram: {cutDatagram}", BitConverter.ToString(cutDatagram)); + offset += dataLen; + cutDatagrams.Add(cutDatagram); + } + catch (System.Exception exception) + { + _logger.LogError(exception, "Failed to cut datagram — discarding remainder. Data: {datagram}", BitConverter.ToString(datagram)); + return cutDatagrams; + } + } + + return cutDatagrams; + } + + public void HandleDatagram(byte[] data) + { + foreach (IZ21ResponseHandler handler in _handlers.Where(handler => handler.CanHandle(data))) + { + try + { + _logger.LogDebug("{handlerName} handling datagram {cutDatagram}.", handler.Name, BitConverter.ToString(data)); + handler.Handle(data); + } + catch (System.Exception exception) + { + _logger.LogError(exception, "{handlerName} failed to handle datagram {cutDatagram}.", handler.Name, BitConverter.ToString(data)); + } + } + } + + private async Task VerifyConnectionOnDemandAsync() + { + bool previousIsConnected = _previousIsConnected; + _previousIsConnected = IsConnected; + + if (previousIsConnected != IsConnected) + { + if (IsConnected) + { + _logger.LogInformation("Z21Client connecting with {ClientIPEndPoint}.", _transport.Z21Configuration.ClientIPEndPoint); + await LogOnAsync(); + } + else + { + _logger.LogInformation("Z21Client lost connection with {ClientIPEndPoint}.", _transport.Z21Configuration.ClientIPEndPoint); + } + OnConnectionChanged?.Invoke(this, new(IsConnected)); + } + } + + protected async virtual Task LogOnAsync() + { + await SendCommandsAsync(new SetBroadcastFlagsCommand(_z21Configuration.BroadcastFlags), new GetFirmwareVersionCommand()); + } + + private async void Transport_OnResponseReceived(object? sender, ResponseReceivedEventArgs bytes) + { + _lastCommunication = DateTime.UtcNow; + await VerifyConnectionOnDemandAsync(); + + CutDatagram(bytes.Response).ForEach(HandleDatagram); + } + + private async void ConnectionKeepAlive_OnElapsed(object? sender, ElapsedEventArgs e) + { + await SendCommandsAsync(new GetFirmwareVersionCommand()); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Extension/StructExtension.cs b/src/Z21Client/Extension/StructExtension.cs new file mode 100644 index 0000000..302ba7e --- /dev/null +++ b/src/Z21Client/Extension/StructExtension.cs @@ -0,0 +1,9 @@ +using System; + +namespace Z21.Extension +{ + public static class StructExtension + { + public static bool IsSet(this uint mask, uint flag) => (flag & mask) != 0; + } +} \ No newline at end of file diff --git a/src/Z21Client/LICENSE b/src/Z21Client/LICENSE new file mode 100644 index 0000000..e72bfdd --- /dev/null +++ b/src/Z21Client/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/src/Z21Client/Transport/IZ21Transport.cs b/src/Z21Client/Transport/IZ21Transport.cs new file mode 100644 index 0000000..e12ffb7 --- /dev/null +++ b/src/Z21Client/Transport/IZ21Transport.cs @@ -0,0 +1,19 @@ +using System; +using System.Threading.Tasks; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; + +namespace Z21.Transport +{ + public interface IZ21Transport + { + bool IsConnected { get; } + event EventHandler? OnResponseReceived; + + public Z21Configuration Z21Configuration { get; } + + void Connect(); + + Task SendAsync(byte[] datagram); + } +} \ No newline at end of file diff --git a/src/Z21Client/Transport/Z21Transport.cs b/src/Z21Client/Transport/Z21Transport.cs new file mode 100644 index 0000000..b4b29b3 --- /dev/null +++ b/src/Z21Client/Transport/Z21Transport.cs @@ -0,0 +1,55 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; + +namespace Z21.Transport +{ + public class Z21Transport : IZ21Transport + { + public Z21Transport(Z21Configuration z21Configuration) + { + ArgumentNullException.ThrowIfNull(z21Configuration, nameof(z21Configuration)); + Z21Configuration = z21Configuration; + + UdpClient = new(Z21Configuration.ClientIPEndPoint.Port); + + if (OperatingSystem.IsWindows()) + UdpClient.AllowNatTraversal(Z21Configuration.AllowNatTraversal); + } + + public bool IsConnected { get; private set; } = false; + + public event EventHandler? OnResponseReceived; + + public UdpClient UdpClient { get; } + + public Z21Configuration Z21Configuration { get; } + + public void Connect() + { + UdpClient.Connect(Z21Configuration.ClientIPEndPoint); + UdpClient.BeginReceive(Receiving, null); + IsConnected = true; + } + + private void Receiving(IAsyncResult res) + { + IPEndPoint? remoteIpEndPoint = null!; + byte[] received = UdpClient.EndReceive(res, ref remoteIpEndPoint); + UdpClient.BeginReceive(Receiving, null); + + if (remoteIpEndPoint is not null + && remoteIpEndPoint.Equals(Z21Configuration.ClientIPEndPoint)) + OnResponseReceived?.Invoke(this, new(received)); + } + + public async Task SendAsync(byte[] datagram) + { + ArgumentNullException.ThrowIfNull(datagram, nameof(datagram)); + await UdpClient.SendAsync(datagram, datagram.GetLength(0)); + } + } +} \ No newline at end of file diff --git a/src/Z21Client/Z21.Client.csproj b/src/Z21Client/Z21.Client.csproj new file mode 100644 index 0000000..de2b6db --- /dev/null +++ b/src/Z21Client/Z21.Client.csproj @@ -0,0 +1,30 @@ + + + + enable + 12 + True + Z21 + Jakob Eichberger + Z21Client partially implements the z21 lan protocoll for the digital command center z21/Z21 from Roco/Fleischmann. + https://github.com/Jakob-Eichberger/z21Client + Z21;Roco;Fleischman + Debug + 4.0.0 + x64 + enable + net8.0;net8.0-windows;net9.0 + 5.0.3-alpha + true + LICENSE + Z21 + + + + + + + + + + diff --git a/src/Z21Client/Z21.Client.csproj.DotSettings b/src/Z21Client/Z21.Client.csproj.DotSettings new file mode 100644 index 0000000..28a18ce --- /dev/null +++ b/src/Z21Client/Z21.Client.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file From e536bd9846814b75cc57c5e1fdedc8d13ef86331 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Sun, 14 Sep 2025 23:11:05 +0200 Subject: [PATCH 05/92] Update README.md --- README.md | 208 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 162 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 95b9bcb..7f8a138 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,176 @@ # Z21 [![](https://github.com/Jakob-Eichberger/z21Client/actions/workflows/dotnet.yml/badge.svg?branch=master)](https://github.com/Jakob-Eichberger/z21Client/actions/workflows/dotnet.yml) -The **Z21 client** library is a C# library for interfacing with the Roco and Fleischmann [Z21 Digital Command Center (DCC)](https://www.z21.eu/). It allows you to control trains, functions, and eventually signals/switches using the Z21 protocol. The library is available as a [NuGet package](https://www.nuget.org/packages/Z21/) for easy integration into your project. + -## Features - -- **Train Control**: Send commands to control locomotives, set speed, direction, and read locomotive status. -- **Function Control**: Activate and deactivate functions (lights, sound, etc.) on locomotives. -- **Signal/Switch Control (Planned)**: Future enhancements will include support for controlling signals and switches on your layout. - -## Getting Started - -1. **Installation**: Install the `Z21` NuGet package in your project. - - ```bash - Install-Package Z21 - ``` - -2. **Initialization**: +The ROCO Z21 is a command station with support for LocoNet, R-Bus and XpressNet devices. It has an open LAN interface with a well-documented protocol that has been continuously developed since then. This C# library of the same name contains platform-independent code for the client-side (i.e. the part that runs on a computer/smart phone) implementation of the protocol. - ```csharp - using Z21; +## Protocol +The official documentation of the protocol can be downloaded from the ROCO homepage in English and German. - // Initialize the Z21 client - var client = new Client(); - client.Connect(IPAddress.Parse("192.168.1.111")); // Replace with your Z21 IP address - ``` +| English | German | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| [Z21 LAN protocol V1.13](https://www.z21.eu/media/Kwc_Basic_DownloadTag_Component/root-en-main_47-1652-959-downloadTag-download/default/d559b9cf/1628743384/z21-lan-protokoll-en.pdf) | [Z21 LAN Protokoll V1.13](https://www.z21.eu/media/Kwc_Basic_DownloadTag_Component/47-1652-959-downloadTag/default/69bad87e/1699290251/z21-lan-protokoll.pdf)| -3. **Train Control**: - ```csharp - // Set locomotive speed - client.SetLocoDrive(new LokInfoData() { Adresse = new(1), Speed = 10, DrivingDirection = true }); // Locomotive address 1, speed 50, direction forward - - // Get locomotive speed - client.OnGetLocoInfo += Client_OnGetLocoInfo; // Subscribe to the specific event - void Client_OnGetLocoInfo(object? sender, Z21.Events.GetLocoInfoEventArgs e) // GetLocoInfoEventArgs contains address, speed, direction, and function states - client.GetLocoInfo(new LokAdresse(2)); // Call GetLocoInfo() to pull the data from the z21 and distribute it on the event bus - ``` - -4. **Function Control**: - - ```csharp - // Activate function F1 (e.g., lights) - client.SetLocoFunction(new FunctionData(1, 0, Z21.Enums.ToggleType.Off));; // Locomotive address 1, function F1 - - // Deactivate function F1 - client.SetLocoFunction(new FunctionData(1, 0, Z21.Enums.ToggleType.On));; // Locomotive address 1, function F1 - - // Toggle function F1 - client.SetLocoFunction(new FunctionData(1, 0, Z21.Enums.ToggleType.Toggle));; // Locomotive address 1, function F1 - ``` +## Features +- Platform-independent +- Lightweight +- SOLID and event-driven architecture - Allowing you to expand the library to your liking. +- Fully unit tested +- Supports dependency injection out of the box via Z21.DependencyInjection. +- Fine grained command/response handler interfaces allowing for simple use. See below for a full list of all supported commands/responses. + - System ✅ + - Driving ✅ + - Switching ✅ + +## Getting Started +Get started by downloading the provided nuget Z21 package. To register the Z21 client use the Z21.DependencyInjection nuget package. + +### Dependency Injection + +Z21.DependencyInjection provides extension methods to register all required classes directly in the container. + +```csharp + services.ConfigureZ21Client(Z21Configuration.Defaults.IpEndPoint); + services.AddZ21Client(); + services.AddZ21Transport(); + services.AddZ21ResponseParser(); + services.AddZ21ResponseHandler(); +``` + +### Dependency Injection +> [!IMPORTANT] +> While this library works without dependency injection, DI is still recommend as it makes usage of this library much easier. +Z21.DependencyInjection provides extension methods to register all required classes directly in the container. + +```csharp + services.ConfigureZ21Client(Z21Configuration.Defaults.IpEndPoint); + services.AddZ21Client(); + services.AddZ21Transport(); + services.AddZ21ResponseParser(); + services.AddZ21ResponseHandler(); +``` + +## Z21 Commands + +> [!NOTE] +> ✅ - Implemented and ready to use. ❌ - Not yet implemented. + +| Command| Status | | +| ------------- | ------------- | ------------- | +| LAN_GET_SERIAL_NUMBER | ✅ | | +| LAN_GET_CODE | ✅ | | +| LAN_GET_HWINFO | ✅ | | +| LAN_LOGOFF | ✅ | | +| LAN_X_GET_VERSION | ✅ | | +| LAN_X_GET_STATUS | ✅ | | +| LAN_X_SET_TRACK_POWER_OFF | ✅ | | +| LAN_X_SET_TRACK_POWER_ON | ✅ | | +| LAN_X_DCC_READ_REGISTER | ❌ | | +| LAN_X_CV_READ | ✅ | | +| LAN_X_DCC_WRITE_REGISTER | ❌ | | +| LAN_X_CV_WRITE | ❌ | | +| LAN_X_MM_WRITE_BYTE | ❌ | | +| LAN_X_GET_TURNOUT_INFO | ✅ | | +| LAN_X_GET_EXT_ACCESSORY_INFO | ✅ | | +| LAN_X_SET_TURNOUT | ✅ | | +| LAN_X_SET_EXT_ACCESSORY | ✅ | | +| LAN_X_SET_STOP | ✅ | | +| LAN_X_SET_LOCO_E_STOP | ✅ | | +| LAN_X_PURGE_LOCO | ✅ | | +| LAN_X_GET_LOCO_INFO | ✅ | | +| LAN_X_SET_LOCO_DRIVE | ✅ | | +| LAN_X_SET_LOCO_FUNCTION | ✅ | | +| LAN_X_SET_LOCO_FUNCTION_GROUP | ❌ | | +| LAN_X_SET_LOCO_BINARY_STATE | ❌ | | +| LAN_X_CV_POM_WRITE_BYTE | ❌ | | +| LAN_X_CV_POM_WRITE_BIT | ❌ | | +| LAN_X_CV_POM_READ_BYTE | ❌ | | +| LAN_X_CV_POM_ACCESSORY_WRITE_BYTE | ❌ | | +| LAN_X_CV_POM_ACCESSORY_WRITE_BIT | ❌ | | +| LAN_X_CV_POM_ACCESSORY_READ_BYTE | ❌ | | +| LAN_X_GET_FIRMWARE_VERSION | ✅ | | +| LAN_SET_BROADCASTFLAGS | ✅ | | +| LAN_GET_BROADCASTFLAGS | ✅ | | +| LAN_GET_LOCOMODE | ✅ | | +| LAN_SET_LOCOMODE | ✅ | | +| LAN_GET_TURNOUTMODE | ✅ | | +| LAN_SET_TURNOUTMODE | ✅ | | +| LAN_RMBUS_GETDATA | ❌ | | +| LAN_RMBUS_PROGRAMMODULE | ❌ | | +| LAN_SYSTEMSTATE_GETDATA | ✅ | | +| LAN_RAILCOM_GETDATA | ❌ | | +| LAN_LOCONET_FROM_LAN | ❌ | | +| LAN_LOCONET_DISPATCH_ADDR | ❌ | | +| LAN_LOCONET_DETECTOR | ❌ | | +| LAN_CAN_DETECTOR | ❌ | | +| LAN_CAN_DEVICE_GET_DESCRIPTION | ❌ | | +| LAN_CAN_DEVICE_SET_DESCRIPTION | ❌ | | +| LAN_CAN_BOOSTER_SET_TRACKPOWER | ❌ | | +| LAN_FAST_CLOCK_CONTROL | ❌ | | +| LAN_FAST_CLOCK_SETTINGS_GET | ❌ | | +| LAN_FAST_CLOCK_SETTINGS_SET | ❌ | | +| LAN_BOOSTER_SET_POWER |❌ | | +| LAN_BOOSTER_GET_DESCRIPTION | ❌ | | +| LAN_BOOSTER_SET_DESCRIPTION | ❌ | | +| LAN_BOOSTER_SYSTEMSTATE_GETDATA | ❌ | | +| LAN_DECODER_GET_DESCRIPTION | ❌ | | +| LAN_DECODER_SET_DESCRIPTION | ❌ | | +| LAN_DECODER_SYSTEMSTATE_GETDATA | ❌ | | +| LAN_ZLINK_GET_HWINFO| ❌ | | + +## Z21 Responses + +> [!NOTE] +> ✅ - Implemented and ready to use. ❌ - Not yet implemented. + +| Response | Status | | +| ------------- | ------------- | ------------- | + | LAN_GET_SERIAL_NUMBER | ✅ | | + | LAN_GET_CODE | ✅ | | + | LAN_GET_HWINFO | ✅ | | + | LAN_X_TURNOUT_INFO | ✅ | | + | LAN_X_EXT_ACCESSORY_INFO | ✅ | | + | LAN_X_BC_TRACK_POWER_OFF | ✅ | | + | LAN_X_BC_TRACK_POWER_ON | ✅ | | + | LAN_X_BC_PROGRAMMING_MODE | ✅ | | + | LAN_X_BC_TRACK_SHORT_CIRCUIT | ✅ | | + | LAN_X_CV_NACK_SC | ❌ | | + | LAN_X_CV_NACK | ❌ | | + | LAN_X_UNKNOWN_COMMAND | ✅ | | + | LAN_X_STATUS_CHANGED | ✅ | | + | LAN_X_GET_VERSION | ✅ | | + | LAN_X_CV_RESULT | ❌ | | + | LAN_X_BC_STOPPED | ✅ | | + | LAN_X_LOCO_INFO | ✅ | | + | LAN_X_GET_FIRMWARE_VERSION | ✅ | | + | LAN_GET_BROADCASTFLAGS | ✅ | | + | LAN_GET_LOCOMODE | ✅ | | + | LAN_GET_TURNOUTMODE | ✅ | | + | LAN_RMBUS_DATACHANGED | ❌ | | + | LAN_SYSTEMSTATE_DATACHANGED | ✅ | | + | LAN_RAILCOM_DATACHANGED | ❌ | | + | LAN_LOCONET_Z21_RX | ❌ | | + | LAN_LOCONET_Z21_TX | ❌ | | + | LAN_LOCONET_FROM_LAN | ❌ | | + | LAN_LOCONET_DISPATCH_ADDR | ❌ | | + | LAN_LOCONET_DETECTOR | ❌ | | + | LAN_CAN_DETECTOR | ❌ | | + | LAN_CAN_DEVICE_GET_DESCRIPTION | ❌ | | + | LAN_CAN_BOOSTER_SYSTEMSTATE_CHGD | ❌ | | + | LAN_FAST_CLOCK_DATA | ❌ | | + | LAN_FAST_CLOCK_SETTINGS_GET | ❌ | | + | LAN_BOOSTER_GET_DESCRIPTION | ❌ | | + | LAN_BOOSTER_SYSTEMSTATE_DATACHANGED | ❌ | | + | LAN_DECODER_GET_DESCRIPTION | ❌ | | + | LAN_DECODER_SYSTEMSTATE_DATACHANGED | ❌ | | + | LAN_ZLINK_GET_HWINFO | ❌ | | + ## Contributing Contributions are welcome! If you encounter any issues or have suggestions, please open an issue or submit a pull request. ## License -This project is licensed under the MIT License - see the LICENSE file for details. +This project is licensed under the GPL-3.0 license - see the LICENSE file for details. From 2039dfdb814283e4820817cd7bb255b92dc14be7 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Sun, 14 Sep 2025 23:32:53 +0200 Subject: [PATCH 06/92] Update README.md --- README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7f8a138..77bc0f1 100644 --- a/README.md +++ b/README.md @@ -27,29 +27,34 @@ The official documentation of the protocol can be downloaded from the ROCO homep ## Getting Started Get started by downloading the provided nuget Z21 package. To register the Z21 client use the Z21.DependencyInjection nuget package. -### Dependency Injection +### Commands +All Commands can be found in the Z21.Core.Command namespace. +#### Sending Commands +> [!WARNING] +> When sending multiple commands at once take note of the maximum payload length. If the commands exceeds that length an exception will be thrown. -Z21.DependencyInjection provides extension methods to register all required classes directly in the container. +Create a command instance and hand it to the Z21Client.SendCommandsAsync method. +Multiple commands can be send at the same time in the same UDP packet. +This is important if certain actions should happen at the same time (i.e. controlling locos in a double traction where it is critical that both locomotives change speed at the same time) ```csharp - services.ConfigureZ21Client(Z21Configuration.Defaults.IpEndPoint); - services.AddZ21Client(); - services.AddZ21Transport(); - services.AddZ21ResponseParser(); - services.AddZ21ResponseHandler(); + await Z21Client.SendCommandsAsync(new GetFirmwareVersionCommand()); // Sends a single command + await Z21Client.SendCommandsAsync(new GetFirmwareVersionCommand(), new GetLocoInfoCommand(locoAddress: 13); // Send multiple commands in a single UDP packet ``` +### + ### Dependency Injection > [!IMPORTANT] > While this library works without dependency injection, DI is still recommend as it makes usage of this library much easier. Z21.DependencyInjection provides extension methods to register all required classes directly in the container. ```csharp - services.ConfigureZ21Client(Z21Configuration.Defaults.IpEndPoint); - services.AddZ21Client(); - services.AddZ21Transport(); - services.AddZ21ResponseParser(); - services.AddZ21ResponseHandler(); + services.ConfigureZ21Client(Z21Configuration.Defaults.IpEndPoint); + services.AddZ21Client(); + services.AddZ21Transport(); + services.AddZ21ResponseParser(); + services.AddZ21ResponseHandler(); ``` ## Z21 Commands From e89087f539884e9cee100ae97f37cff381072f5a Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Sun, 14 Sep 2025 23:55:30 +0200 Subject: [PATCH 07/92] Create dotnet.yml --- .github/workflows/dotnet.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..d340392 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,28 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "Release/**" ] + pull_request: + branches: [ "Release/**" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal From b0759d366a10e786bfa4ed4fee88b25b7cee8c1d Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:00:06 +0200 Subject: [PATCH 08/92] Update dotnet.yml --- .github/workflows/dotnet.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index d340392..06011aa 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -21,8 +21,8 @@ jobs: with: dotnet-version: 8.0.x - name: Restore dependencies - run: dotnet restore + run: dotnet restore src/Z21.sln - name: Build - run: dotnet build --no-restore + run: dotnet build src/Z21.sln --no-restore - name: Test - run: dotnet test --no-build --verbosity normal + run: dotnet test src/Z21.sln --no-build --verbosity normal From 81459b6b8ea7b7786baa7b27b47fcafde7a39ba6 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 15 Sep 2025 00:02:49 +0200 Subject: [PATCH 09/92] update TargetFramework --- src/.idea/.idea.Z21/.idea/vcs.xml | 1 + src/Z21.DependencyInjection/Z21.DependencyInjection.csproj | 2 +- src/Z21Client/Z21.Client.csproj | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/.idea/.idea.Z21/.idea/vcs.xml b/src/.idea/.idea.Z21/.idea/vcs.xml index 35eb1dd..62bd7a0 100644 --- a/src/.idea/.idea.Z21/.idea/vcs.xml +++ b/src/.idea/.idea.Z21/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj b/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj index 089b3d7..d090228 100644 --- a/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj +++ b/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj @@ -1,7 +1,7 @@  - net8.0;net8.0-windows;net9.0 + net8.0;net8.0-windows enable enable true diff --git a/src/Z21Client/Z21.Client.csproj b/src/Z21Client/Z21.Client.csproj index de2b6db..ee6617a 100644 --- a/src/Z21Client/Z21.Client.csproj +++ b/src/Z21Client/Z21.Client.csproj @@ -13,7 +13,7 @@ 4.0.0 x64 enable - net8.0;net8.0-windows;net9.0 + net8.0;net8.0-windows 5.0.3-alpha true LICENSE From 830360ecced8dce042197b30495c3bb009fbb052 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:04:12 +0200 Subject: [PATCH 10/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 77bc0f1..1137dcb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Z21 [![](https://github.com/Jakob-Eichberger/z21Client/actions/workflows/dotnet.yml/badge.svg?branch=master)](https://github.com/Jakob-Eichberger/z21Client/actions/workflows/dotnet.yml) - +[![.NET](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml) The ROCO Z21 is a command station with support for LocoNet, R-Bus and XpressNet devices. It has an open LAN interface with a well-documented protocol that has been continuously developed since then. This C# library of the same name contains platform-independent code for the client-side (i.e. the part that runs on a computer/smart phone) implementation of the protocol. From df75b366c5c621045153fb91cdb94c1dc64c7d6a Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:06:26 +0200 Subject: [PATCH 11/92] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1137dcb..9594ef2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -# Z21 [![](https://github.com/Jakob-Eichberger/z21Client/actions/workflows/dotnet.yml/badge.svg?branch=master)](https://github.com/Jakob-Eichberger/z21Client/actions/workflows/dotnet.yml) +# Z21 [![.NET](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml) + + -[![.NET](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml) The ROCO Z21 is a command station with support for LocoNet, R-Bus and XpressNet devices. It has an open LAN interface with a well-documented protocol that has been continuously developed since then. This C# library of the same name contains platform-independent code for the client-side (i.e. the part that runs on a computer/smart phone) implementation of the protocol. From b76282fa94e409ca01cf63cbe40c3d756693df7a Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 15 Sep 2025 00:13:55 +0200 Subject: [PATCH 12/92] Update Nuget PackageID and version --- src/Z21Client/Z21.Client.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Z21Client/Z21.Client.csproj b/src/Z21Client/Z21.Client.csproj index ee6617a..f5f6773 100644 --- a/src/Z21Client/Z21.Client.csproj +++ b/src/Z21Client/Z21.Client.csproj @@ -14,10 +14,11 @@ x64 enable net8.0;net8.0-windows - 5.0.3-alpha + 5.0.0-alpha true LICENSE Z21 + Z21 From 46bebe257e6c7226b53cb4216df3ae72b452119e Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 15 Sep 2025 00:33:21 +0200 Subject: [PATCH 13/92] init docfx --- src/docfx.json | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/docfx.json diff --git a/src/docfx.json b/src/docfx.json new file mode 100644 index 0000000..67e13a8 --- /dev/null +++ b/src/docfx.json @@ -0,0 +1,46 @@ +{ + "$schema": "https://raw.githubusercontent.com/dotnet/docfx/main/schemas/docfx.schema.json", + "metadata": [ + { + "src": [ + { + "src": "../src", + "files": [ + "**/*.csproj" + ] + } + ], + "dest": "api" + } + ], + "build": { + "content": [ + { + "files": [ + "**/*.{md,yml}" + ], + "exclude": [ + "_site/**" + ] + } + ], + "resource": [ + { + "files": [ + "images/**" + ] + } + ], + "output": "_site", + "template": [ + "default", + "modern" + ], + "globalMetadata": { + "_appName": "", + "_appTitle": "", + "_enableSearch": true, + "pdf": true + } + } +} \ No newline at end of file From 06fdc343485283dbec5a7322177de71be53a5293 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 15 Sep 2025 00:33:45 +0200 Subject: [PATCH 14/92] update docfx --- src/docfx.json | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/docfx.json b/src/docfx.json index 67e13a8..301d1b3 100644 --- a/src/docfx.json +++ b/src/docfx.json @@ -16,31 +16,12 @@ "build": { "content": [ { - "files": [ - "**/*.{md,yml}" - ], - "exclude": [ - "_site/**" - ] - } - ], - "resource": [ + "files": ["api/**.yml", "toc.yml"] + }, { - "files": [ - "images/**" - ] + "files": ["articles/**.md"] } ], - "output": "_site", - "template": [ - "default", - "modern" - ], - "globalMetadata": { - "_appName": "", - "_appTitle": "", - "_enableSearch": true, - "pdf": true - } + "dest": "_site" } } \ No newline at end of file From 39ef8f28b81eb4311c1d81a91c3eeb0f01f998cf Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:36:08 +0200 Subject: [PATCH 15/92] Create BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/BuildAndDeployDoc.yml diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml new file mode 100644 index 0000000..6923c99 --- /dev/null +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -0,0 +1,36 @@ +name: Build and Deploy Versioned Docs + +on: + push: + branches: + - 'release/**' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Extract Version + id: vars + run: | + echo "##[set-output name=version;]$(echo ${GITHUB_REF#refs/heads/release/})" + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.x' + + - name: Install DocFX + run: dotnet tool install -g docfx + + - name: Build Docs + run: docfx docfx.json + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./_site + destination_dir: ${{ steps.vars.outputs.version }} From 7342ed1b7a36ee177c3ed99af31b827e6e7a065b Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:37:11 +0200 Subject: [PATCH 16/92] Update BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml index 6923c99..1c29505 100644 --- a/.github/workflows/BuildAndDeployDoc.yml +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -4,6 +4,7 @@ on: push: branches: - 'release/**' + workflow_dispatch: jobs: build: From a3830ac7fb16e10b289b1829d8c29717fb0db8af Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:40:11 +0200 Subject: [PATCH 17/92] Update BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml index 1c29505..63bdcbf 100644 --- a/.github/workflows/BuildAndDeployDoc.yml +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -27,7 +27,7 @@ jobs: run: dotnet tool install -g docfx - name: Build Docs - run: docfx docfx.json + run: docfx src/docfx.json - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 From c3b9c104ecc1db9c00766713bc59301b7a356d27 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:42:48 +0200 Subject: [PATCH 18/92] Update BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml index 63bdcbf..a1133e4 100644 --- a/.github/workflows/BuildAndDeployDoc.yml +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -33,5 +33,5 @@ jobs: uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./_site + publish_dir: ./src/_site destination_dir: ${{ steps.vars.outputs.version }} From 4e33a4441dfbc2e3ceca6526b014571622c71894 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:49:25 +0200 Subject: [PATCH 19/92] Update BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml index a1133e4..0a7c4d8 100644 --- a/.github/workflows/BuildAndDeployDoc.yml +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -16,7 +16,9 @@ jobs: - name: Extract Version id: vars run: | - echo "##[set-output name=version;]$(echo ${GITHUB_REF#refs/heads/release/})" + VERSION=${GITHUB_REF#refs/heads/release/} + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Setup .NET uses: actions/setup-dotnet@v3 From 0f78dcd802d6556718a8dd5ab71d29e6a2d274a4 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:51:27 +0200 Subject: [PATCH 20/92] Update BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml index 0a7c4d8..a663b76 100644 --- a/.github/workflows/BuildAndDeployDoc.yml +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -16,8 +16,8 @@ jobs: - name: Extract Version id: vars run: | - VERSION=${GITHUB_REF#refs/heads/release/} - echo "VERSION=$VERSION" >> $GITHUB_ENV + RAW_REF="${GITHUB_REF#refs/heads/}" + VERSION="${RAW_REF#Release/}" echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Setup .NET From 7ddfc91785dca825673863de165c3aa0a844a9de Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 15 Sep 2025 01:01:51 +0200 Subject: [PATCH 21/92] rename root folder --- .../.idea/.idea.z21Client.dir/.idea/encodings.xml | 0 .../.idea/.idea.z21Client.dir/.idea/indexLayout.xml | 0 .../.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml | 0 .../.idea/.idea.z21Client.dir/.idea/vcs.xml | 0 .../.idea/.idea.z21Client/.idea/.gitignore | 0 .../.idea/.idea.z21Client/.idea/indexLayout.xml | 0 src/{Z21Client => Z21.Client}/.idea/.idea.z21Client/.idea/vcs.xml | 0 .../Core/Command/Driving/GetLocoInfoCommand.cs | 0 .../Core/Command/Driving/PurgeLocoCommand.cs | 0 .../Core/Command/Driving/SetLocoDriveCommand.cs | 0 .../Core/Command/Driving/SetLocoEStopCommand.cs | 0 .../Core/Command/Driving/SetLocoFunctionCommand.cs | 0 src/{Z21Client => Z21.Client}/Core/Command/IZ21Command.cs | 0 .../Core/Command/Settings/GetAccessoryModeCommand.cs | 0 .../Core/Command/Settings/GetLocoModeCommand.cs | 0 .../Core/Command/Settings/SetAccessoryModeCommand.cs | 0 .../Core/Command/Settings/SetLocoModeCommand.cs | 0 .../Core/Command/Switching/GetExtAccessoryInfoCommand.cs | 0 .../Core/Command/Switching/GetTurnoutInfoCommand.cs | 0 .../Core/Command/Switching/SetExtAccessoryCommand.cs | 0 .../Core/Command/Switching/SetTurnoutCommand.cs | 0 .../Core/Command/SystemState/GetBroadcastFlagsCommand.cs | 0 .../Core/Command/SystemState/GetFirmwareVersionCommand.cs | 0 .../Core/Command/SystemState/GetHardwareInfoCommand.cs | 0 .../Core/Command/SystemState/GetSerialNumberCommand.cs | 0 .../Core/Command/SystemState/GetSoftwareLockCommand.cs | 0 .../Core/Command/SystemState/GetStatusCommand.cs | 0 .../Core/Command/SystemState/GetSystemStateDataCommand.cs | 0 .../Core/Command/SystemState/GetVersionCommand.cs | 0 .../Core/Command/SystemState/LogOffCommand.cs | 0 .../Core/Command/SystemState/SetBroadcastFlagsCommand.cs | 0 .../Core/Command/SystemState/TrackPower/SetStopCommand.cs | 0 .../Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs | 0 .../Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs | 0 .../Core/Exception/ClientNotConnectedException.cs | 0 .../Core/Exception/LocoSpeedOutOfRangeException.cs | 0 .../Core/Exception/MtuPayloadLengthExceededException.cs | 0 src/{Z21Client => Z21.Client}/Core/Helper/AddressHelper.cs | 0 src/{Z21Client => Z21.Client}/Core/Helper/LocoSpeedHelper.cs | 0 src/{Z21Client => Z21.Client}/Core/IZ21Client.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/AccessoryOutput.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/AccessoryState.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/Capabilities.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/CentralState.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/CentralStateEx.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/DccSpeedMode.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/DecoderMode.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/DrivingDirection.cs | 0 .../Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/ConnectionChangedEventArgs.cs | 0 .../Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/HardwareInfoEventArgs.cs | 0 .../Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/ResponseReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs | 0 .../Core/Model/EventArgs/VersionReceivedEventArgs.cs | 0 .../Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs | 0 .../Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/FirmwareVersion.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/FunctionToggleType.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/LocoFunctionData.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/LocoInfoData.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/SystemState.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/Z21BroadcastFlags.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/Z21Configuration.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/Z21HardwareType.cs | 0 src/{Z21Client => Z21.Client}/Core/Model/Z21SoftwareLock.cs | 0 .../Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs | 0 .../Core/ResponseHandler/IZ21ResponseHandler.cs | 0 .../Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs | 0 .../Core/ResponseHandler/Settings/LocoModeResponseHandler.cs | 0 .../ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs | 0 .../Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs | 0 .../ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs | 0 .../ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs | 0 .../ResponseHandler/SystemState/HardwareInfoResponseHandler.cs | 0 .../ResponseHandler/SystemState/SerialNumberResponseHandler.cs | 0 .../ResponseHandler/SystemState/SoftwareLockResponseHandler.cs | 0 .../ResponseHandler/SystemState/StatusChangedResponseHandler.cs | 0 .../SystemState/SystemStateDataChangedResponseHandler.cs | 0 .../SystemState/TrackPower/ProgrammingModeResponseHandler.cs | 0 .../SystemState/TrackPower/StoppedResponseHandler.cs | 0 .../SystemState/TrackPower/TrackPowerOffResponseHandler.cs | 0 .../SystemState/TrackPower/TrackPowerOnResponseHandler.cs | 0 .../SystemState/TrackPower/TrackShortResponseHandler.cs | 0 .../ResponseHandler/SystemState/UnknownCommandResponseHandler.cs | 0 .../Core/ResponseHandler/SystemState/VersionResponseHandler.cs | 0 .../Core/ResponseParser/CapabilitiesResponseParser.cs | 0 .../Core/ResponseParser/CentralStateExResponseParser.cs | 0 .../Core/ResponseParser/CentralStateResponseParser.cs | 0 .../Core/ResponseParser/IZ21ResponseParser.cs | 0 .../Core/ResponseParser/SystemStateResponseParser.cs | 0 src/{Z21Client => Z21.Client}/Core/Z21Client.cs | 0 src/{Z21Client => Z21.Client}/Extension/StructExtension.cs | 0 src/{Z21Client => Z21.Client}/LICENSE | 0 src/{Z21Client => Z21.Client}/Transport/IZ21Transport.cs | 0 src/{Z21Client => Z21.Client}/Transport/Z21Transport.cs | 0 src/{Z21Client => Z21.Client}/Z21.Client.csproj | 0 src/{Z21Client => Z21.Client}/Z21.Client.csproj.DotSettings | 0 106 files changed, 0 insertions(+), 0 deletions(-) rename src/{Z21Client => Z21.Client}/.idea/.idea.z21Client.dir/.idea/encodings.xml (100%) rename src/{Z21Client => Z21.Client}/.idea/.idea.z21Client.dir/.idea/indexLayout.xml (100%) rename src/{Z21Client => Z21.Client}/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml (100%) rename src/{Z21Client => Z21.Client}/.idea/.idea.z21Client.dir/.idea/vcs.xml (100%) rename src/{Z21Client => Z21.Client}/.idea/.idea.z21Client/.idea/.gitignore (100%) rename src/{Z21Client => Z21.Client}/.idea/.idea.z21Client/.idea/indexLayout.xml (100%) rename src/{Z21Client => Z21.Client}/.idea/.idea.z21Client/.idea/vcs.xml (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Driving/GetLocoInfoCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Driving/PurgeLocoCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Driving/SetLocoDriveCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Driving/SetLocoEStopCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Driving/SetLocoFunctionCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/IZ21Command.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Settings/GetAccessoryModeCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Settings/GetLocoModeCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Settings/SetAccessoryModeCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Settings/SetLocoModeCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Switching/GetExtAccessoryInfoCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Switching/GetTurnoutInfoCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Switching/SetExtAccessoryCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/Switching/SetTurnoutCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/GetBroadcastFlagsCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/GetFirmwareVersionCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/GetHardwareInfoCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/GetSerialNumberCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/GetSoftwareLockCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/GetStatusCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/GetSystemStateDataCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/GetVersionCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/LogOffCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/SetBroadcastFlagsCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/TrackPower/SetStopCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Exception/ClientNotConnectedException.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Exception/LocoSpeedOutOfRangeException.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Exception/MtuPayloadLengthExceededException.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Helper/AddressHelper.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Helper/LocoSpeedHelper.cs (100%) rename src/{Z21Client => Z21.Client}/Core/IZ21Client.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/AccessoryOutput.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/AccessoryState.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/Capabilities.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/CentralState.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/CentralStateEx.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/DccSpeedMode.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/DecoderMode.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/DrivingDirection.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/ConnectionChangedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/HardwareInfoEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/ResponseReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/EventArgs/VersionReceivedEventArgs.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/FirmwareVersion.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/FunctionToggleType.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/LocoFunctionData.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/LocoInfoData.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/SystemState.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/Z21BroadcastFlags.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/Z21Configuration.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/Z21HardwareType.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Model/Z21SoftwareLock.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/IZ21ResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseHandler/SystemState/VersionResponseHandler.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseParser/CapabilitiesResponseParser.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseParser/CentralStateExResponseParser.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseParser/CentralStateResponseParser.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseParser/IZ21ResponseParser.cs (100%) rename src/{Z21Client => Z21.Client}/Core/ResponseParser/SystemStateResponseParser.cs (100%) rename src/{Z21Client => Z21.Client}/Core/Z21Client.cs (100%) rename src/{Z21Client => Z21.Client}/Extension/StructExtension.cs (100%) rename src/{Z21Client => Z21.Client}/LICENSE (100%) rename src/{Z21Client => Z21.Client}/Transport/IZ21Transport.cs (100%) rename src/{Z21Client => Z21.Client}/Transport/Z21Transport.cs (100%) rename src/{Z21Client => Z21.Client}/Z21.Client.csproj (100%) rename src/{Z21Client => Z21.Client}/Z21.Client.csproj.DotSettings (100%) diff --git a/src/Z21Client/.idea/.idea.z21Client.dir/.idea/encodings.xml b/src/Z21.Client/.idea/.idea.z21Client.dir/.idea/encodings.xml similarity index 100% rename from src/Z21Client/.idea/.idea.z21Client.dir/.idea/encodings.xml rename to src/Z21.Client/.idea/.idea.z21Client.dir/.idea/encodings.xml diff --git a/src/Z21Client/.idea/.idea.z21Client.dir/.idea/indexLayout.xml b/src/Z21.Client/.idea/.idea.z21Client.dir/.idea/indexLayout.xml similarity index 100% rename from src/Z21Client/.idea/.idea.z21Client.dir/.idea/indexLayout.xml rename to src/Z21.Client/.idea/.idea.z21Client.dir/.idea/indexLayout.xml diff --git a/src/Z21Client/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml b/src/Z21.Client/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml similarity index 100% rename from src/Z21Client/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml rename to src/Z21.Client/.idea/.idea.z21Client.dir/.idea/projectSettingsUpdater.xml diff --git a/src/Z21Client/.idea/.idea.z21Client.dir/.idea/vcs.xml b/src/Z21.Client/.idea/.idea.z21Client.dir/.idea/vcs.xml similarity index 100% rename from src/Z21Client/.idea/.idea.z21Client.dir/.idea/vcs.xml rename to src/Z21.Client/.idea/.idea.z21Client.dir/.idea/vcs.xml diff --git a/src/Z21Client/.idea/.idea.z21Client/.idea/.gitignore b/src/Z21.Client/.idea/.idea.z21Client/.idea/.gitignore similarity index 100% rename from src/Z21Client/.idea/.idea.z21Client/.idea/.gitignore rename to src/Z21.Client/.idea/.idea.z21Client/.idea/.gitignore diff --git a/src/Z21Client/.idea/.idea.z21Client/.idea/indexLayout.xml b/src/Z21.Client/.idea/.idea.z21Client/.idea/indexLayout.xml similarity index 100% rename from src/Z21Client/.idea/.idea.z21Client/.idea/indexLayout.xml rename to src/Z21.Client/.idea/.idea.z21Client/.idea/indexLayout.xml diff --git a/src/Z21Client/.idea/.idea.z21Client/.idea/vcs.xml b/src/Z21.Client/.idea/.idea.z21Client/.idea/vcs.xml similarity index 100% rename from src/Z21Client/.idea/.idea.z21Client/.idea/vcs.xml rename to src/Z21.Client/.idea/.idea.z21Client/.idea/vcs.xml diff --git a/src/Z21Client/Core/Command/Driving/GetLocoInfoCommand.cs b/src/Z21.Client/Core/Command/Driving/GetLocoInfoCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Driving/GetLocoInfoCommand.cs rename to src/Z21.Client/Core/Command/Driving/GetLocoInfoCommand.cs diff --git a/src/Z21Client/Core/Command/Driving/PurgeLocoCommand.cs b/src/Z21.Client/Core/Command/Driving/PurgeLocoCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Driving/PurgeLocoCommand.cs rename to src/Z21.Client/Core/Command/Driving/PurgeLocoCommand.cs diff --git a/src/Z21Client/Core/Command/Driving/SetLocoDriveCommand.cs b/src/Z21.Client/Core/Command/Driving/SetLocoDriveCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Driving/SetLocoDriveCommand.cs rename to src/Z21.Client/Core/Command/Driving/SetLocoDriveCommand.cs diff --git a/src/Z21Client/Core/Command/Driving/SetLocoEStopCommand.cs b/src/Z21.Client/Core/Command/Driving/SetLocoEStopCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Driving/SetLocoEStopCommand.cs rename to src/Z21.Client/Core/Command/Driving/SetLocoEStopCommand.cs diff --git a/src/Z21Client/Core/Command/Driving/SetLocoFunctionCommand.cs b/src/Z21.Client/Core/Command/Driving/SetLocoFunctionCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Driving/SetLocoFunctionCommand.cs rename to src/Z21.Client/Core/Command/Driving/SetLocoFunctionCommand.cs diff --git a/src/Z21Client/Core/Command/IZ21Command.cs b/src/Z21.Client/Core/Command/IZ21Command.cs similarity index 100% rename from src/Z21Client/Core/Command/IZ21Command.cs rename to src/Z21.Client/Core/Command/IZ21Command.cs diff --git a/src/Z21Client/Core/Command/Settings/GetAccessoryModeCommand.cs b/src/Z21.Client/Core/Command/Settings/GetAccessoryModeCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Settings/GetAccessoryModeCommand.cs rename to src/Z21.Client/Core/Command/Settings/GetAccessoryModeCommand.cs diff --git a/src/Z21Client/Core/Command/Settings/GetLocoModeCommand.cs b/src/Z21.Client/Core/Command/Settings/GetLocoModeCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Settings/GetLocoModeCommand.cs rename to src/Z21.Client/Core/Command/Settings/GetLocoModeCommand.cs diff --git a/src/Z21Client/Core/Command/Settings/SetAccessoryModeCommand.cs b/src/Z21.Client/Core/Command/Settings/SetAccessoryModeCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Settings/SetAccessoryModeCommand.cs rename to src/Z21.Client/Core/Command/Settings/SetAccessoryModeCommand.cs diff --git a/src/Z21Client/Core/Command/Settings/SetLocoModeCommand.cs b/src/Z21.Client/Core/Command/Settings/SetLocoModeCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Settings/SetLocoModeCommand.cs rename to src/Z21.Client/Core/Command/Settings/SetLocoModeCommand.cs diff --git a/src/Z21Client/Core/Command/Switching/GetExtAccessoryInfoCommand.cs b/src/Z21.Client/Core/Command/Switching/GetExtAccessoryInfoCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Switching/GetExtAccessoryInfoCommand.cs rename to src/Z21.Client/Core/Command/Switching/GetExtAccessoryInfoCommand.cs diff --git a/src/Z21Client/Core/Command/Switching/GetTurnoutInfoCommand.cs b/src/Z21.Client/Core/Command/Switching/GetTurnoutInfoCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Switching/GetTurnoutInfoCommand.cs rename to src/Z21.Client/Core/Command/Switching/GetTurnoutInfoCommand.cs diff --git a/src/Z21Client/Core/Command/Switching/SetExtAccessoryCommand.cs b/src/Z21.Client/Core/Command/Switching/SetExtAccessoryCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Switching/SetExtAccessoryCommand.cs rename to src/Z21.Client/Core/Command/Switching/SetExtAccessoryCommand.cs diff --git a/src/Z21Client/Core/Command/Switching/SetTurnoutCommand.cs b/src/Z21.Client/Core/Command/Switching/SetTurnoutCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/Switching/SetTurnoutCommand.cs rename to src/Z21.Client/Core/Command/Switching/SetTurnoutCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/GetBroadcastFlagsCommand.cs b/src/Z21.Client/Core/Command/SystemState/GetBroadcastFlagsCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/GetBroadcastFlagsCommand.cs rename to src/Z21.Client/Core/Command/SystemState/GetBroadcastFlagsCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/GetFirmwareVersionCommand.cs b/src/Z21.Client/Core/Command/SystemState/GetFirmwareVersionCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/GetFirmwareVersionCommand.cs rename to src/Z21.Client/Core/Command/SystemState/GetFirmwareVersionCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/GetHardwareInfoCommand.cs b/src/Z21.Client/Core/Command/SystemState/GetHardwareInfoCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/GetHardwareInfoCommand.cs rename to src/Z21.Client/Core/Command/SystemState/GetHardwareInfoCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/GetSerialNumberCommand.cs b/src/Z21.Client/Core/Command/SystemState/GetSerialNumberCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/GetSerialNumberCommand.cs rename to src/Z21.Client/Core/Command/SystemState/GetSerialNumberCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/GetSoftwareLockCommand.cs b/src/Z21.Client/Core/Command/SystemState/GetSoftwareLockCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/GetSoftwareLockCommand.cs rename to src/Z21.Client/Core/Command/SystemState/GetSoftwareLockCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/GetStatusCommand.cs b/src/Z21.Client/Core/Command/SystemState/GetStatusCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/GetStatusCommand.cs rename to src/Z21.Client/Core/Command/SystemState/GetStatusCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/GetSystemStateDataCommand.cs b/src/Z21.Client/Core/Command/SystemState/GetSystemStateDataCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/GetSystemStateDataCommand.cs rename to src/Z21.Client/Core/Command/SystemState/GetSystemStateDataCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/GetVersionCommand.cs b/src/Z21.Client/Core/Command/SystemState/GetVersionCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/GetVersionCommand.cs rename to src/Z21.Client/Core/Command/SystemState/GetVersionCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/LogOffCommand.cs b/src/Z21.Client/Core/Command/SystemState/LogOffCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/LogOffCommand.cs rename to src/Z21.Client/Core/Command/SystemState/LogOffCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/SetBroadcastFlagsCommand.cs b/src/Z21.Client/Core/Command/SystemState/SetBroadcastFlagsCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/SetBroadcastFlagsCommand.cs rename to src/Z21.Client/Core/Command/SystemState/SetBroadcastFlagsCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/TrackPower/SetStopCommand.cs b/src/Z21.Client/Core/Command/SystemState/TrackPower/SetStopCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/TrackPower/SetStopCommand.cs rename to src/Z21.Client/Core/Command/SystemState/TrackPower/SetStopCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs b/src/Z21.Client/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs rename to src/Z21.Client/Core/Command/SystemState/TrackPower/SetTrackPowerOffCommand.cs diff --git a/src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs b/src/Z21.Client/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs similarity index 100% rename from src/Z21Client/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs rename to src/Z21.Client/Core/Command/SystemState/TrackPower/SetTrackPowerOnCommand.cs diff --git a/src/Z21Client/Core/Exception/ClientNotConnectedException.cs b/src/Z21.Client/Core/Exception/ClientNotConnectedException.cs similarity index 100% rename from src/Z21Client/Core/Exception/ClientNotConnectedException.cs rename to src/Z21.Client/Core/Exception/ClientNotConnectedException.cs diff --git a/src/Z21Client/Core/Exception/LocoSpeedOutOfRangeException.cs b/src/Z21.Client/Core/Exception/LocoSpeedOutOfRangeException.cs similarity index 100% rename from src/Z21Client/Core/Exception/LocoSpeedOutOfRangeException.cs rename to src/Z21.Client/Core/Exception/LocoSpeedOutOfRangeException.cs diff --git a/src/Z21Client/Core/Exception/MtuPayloadLengthExceededException.cs b/src/Z21.Client/Core/Exception/MtuPayloadLengthExceededException.cs similarity index 100% rename from src/Z21Client/Core/Exception/MtuPayloadLengthExceededException.cs rename to src/Z21.Client/Core/Exception/MtuPayloadLengthExceededException.cs diff --git a/src/Z21Client/Core/Helper/AddressHelper.cs b/src/Z21.Client/Core/Helper/AddressHelper.cs similarity index 100% rename from src/Z21Client/Core/Helper/AddressHelper.cs rename to src/Z21.Client/Core/Helper/AddressHelper.cs diff --git a/src/Z21Client/Core/Helper/LocoSpeedHelper.cs b/src/Z21.Client/Core/Helper/LocoSpeedHelper.cs similarity index 100% rename from src/Z21Client/Core/Helper/LocoSpeedHelper.cs rename to src/Z21.Client/Core/Helper/LocoSpeedHelper.cs diff --git a/src/Z21Client/Core/IZ21Client.cs b/src/Z21.Client/Core/IZ21Client.cs similarity index 100% rename from src/Z21Client/Core/IZ21Client.cs rename to src/Z21.Client/Core/IZ21Client.cs diff --git a/src/Z21Client/Core/Model/AccessoryOutput.cs b/src/Z21.Client/Core/Model/AccessoryOutput.cs similarity index 100% rename from src/Z21Client/Core/Model/AccessoryOutput.cs rename to src/Z21.Client/Core/Model/AccessoryOutput.cs diff --git a/src/Z21Client/Core/Model/AccessoryState.cs b/src/Z21.Client/Core/Model/AccessoryState.cs similarity index 100% rename from src/Z21Client/Core/Model/AccessoryState.cs rename to src/Z21.Client/Core/Model/AccessoryState.cs diff --git a/src/Z21Client/Core/Model/Capabilities.cs b/src/Z21.Client/Core/Model/Capabilities.cs similarity index 100% rename from src/Z21Client/Core/Model/Capabilities.cs rename to src/Z21.Client/Core/Model/Capabilities.cs diff --git a/src/Z21Client/Core/Model/CentralState.cs b/src/Z21.Client/Core/Model/CentralState.cs similarity index 100% rename from src/Z21Client/Core/Model/CentralState.cs rename to src/Z21.Client/Core/Model/CentralState.cs diff --git a/src/Z21Client/Core/Model/CentralStateEx.cs b/src/Z21.Client/Core/Model/CentralStateEx.cs similarity index 100% rename from src/Z21Client/Core/Model/CentralStateEx.cs rename to src/Z21.Client/Core/Model/CentralStateEx.cs diff --git a/src/Z21Client/Core/Model/DccSpeedMode.cs b/src/Z21.Client/Core/Model/DccSpeedMode.cs similarity index 100% rename from src/Z21Client/Core/Model/DccSpeedMode.cs rename to src/Z21.Client/Core/Model/DccSpeedMode.cs diff --git a/src/Z21Client/Core/Model/DecoderMode.cs b/src/Z21.Client/Core/Model/DecoderMode.cs similarity index 100% rename from src/Z21Client/Core/Model/DecoderMode.cs rename to src/Z21.Client/Core/Model/DecoderMode.cs diff --git a/src/Z21Client/Core/Model/DrivingDirection.cs b/src/Z21.Client/Core/Model/DrivingDirection.cs similarity index 100% rename from src/Z21Client/Core/Model/DrivingDirection.cs rename to src/Z21.Client/Core/Model/DrivingDirection.cs diff --git a/src/Z21Client/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/BroadcastFlagsReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/ConnectionChangedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/ConnectionChangedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/ConnectionChangedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/ConnectionChangedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/DecoderModeReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/ExtAccessoryInfoReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/HardwareInfoEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/HardwareInfoEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/HardwareInfoEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/HardwareInfoEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/LocoInfoReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/ResponseReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/ResponseReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/ResponseReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/ResponseReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/SerialNumberReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/SoftwareLockReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/StatusChangedReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/SystemStatusChangedReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/TurnoutInfoReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/UnknownCommandReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs similarity index 100% rename from src/Z21Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs rename to src/Z21.Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs diff --git a/src/Z21Client/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs b/src/Z21.Client/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs similarity index 100% rename from src/Z21Client/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs rename to src/Z21.Client/Core/Model/ExcAccessoryPayload/IExcAccessoryPayload.cs diff --git a/src/Z21Client/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs b/src/Z21.Client/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs similarity index 100% rename from src/Z21Client/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs rename to src/Z21.Client/Core/Model/ExcAccessoryPayload/SwitchDecoderPayload.cs diff --git a/src/Z21Client/Core/Model/FirmwareVersion.cs b/src/Z21.Client/Core/Model/FirmwareVersion.cs similarity index 100% rename from src/Z21Client/Core/Model/FirmwareVersion.cs rename to src/Z21.Client/Core/Model/FirmwareVersion.cs diff --git a/src/Z21Client/Core/Model/FunctionToggleType.cs b/src/Z21.Client/Core/Model/FunctionToggleType.cs similarity index 100% rename from src/Z21Client/Core/Model/FunctionToggleType.cs rename to src/Z21.Client/Core/Model/FunctionToggleType.cs diff --git a/src/Z21Client/Core/Model/LocoFunctionData.cs b/src/Z21.Client/Core/Model/LocoFunctionData.cs similarity index 100% rename from src/Z21Client/Core/Model/LocoFunctionData.cs rename to src/Z21.Client/Core/Model/LocoFunctionData.cs diff --git a/src/Z21Client/Core/Model/LocoInfoData.cs b/src/Z21.Client/Core/Model/LocoInfoData.cs similarity index 100% rename from src/Z21Client/Core/Model/LocoInfoData.cs rename to src/Z21.Client/Core/Model/LocoInfoData.cs diff --git a/src/Z21Client/Core/Model/SystemState.cs b/src/Z21.Client/Core/Model/SystemState.cs similarity index 100% rename from src/Z21Client/Core/Model/SystemState.cs rename to src/Z21.Client/Core/Model/SystemState.cs diff --git a/src/Z21Client/Core/Model/Z21BroadcastFlags.cs b/src/Z21.Client/Core/Model/Z21BroadcastFlags.cs similarity index 100% rename from src/Z21Client/Core/Model/Z21BroadcastFlags.cs rename to src/Z21.Client/Core/Model/Z21BroadcastFlags.cs diff --git a/src/Z21Client/Core/Model/Z21Configuration.cs b/src/Z21.Client/Core/Model/Z21Configuration.cs similarity index 100% rename from src/Z21Client/Core/Model/Z21Configuration.cs rename to src/Z21.Client/Core/Model/Z21Configuration.cs diff --git a/src/Z21Client/Core/Model/Z21HardwareType.cs b/src/Z21.Client/Core/Model/Z21HardwareType.cs similarity index 100% rename from src/Z21Client/Core/Model/Z21HardwareType.cs rename to src/Z21.Client/Core/Model/Z21HardwareType.cs diff --git a/src/Z21Client/Core/Model/Z21SoftwareLock.cs b/src/Z21.Client/Core/Model/Z21SoftwareLock.cs similarity index 100% rename from src/Z21Client/Core/Model/Z21SoftwareLock.cs rename to src/Z21.Client/Core/Model/Z21SoftwareLock.cs diff --git a/src/Z21Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/IZ21ResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/IZ21ResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/IZ21ResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/IZ21ResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/Settings/AccessoryModeResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/Settings/LocoModeResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/Switching/ExtAccessoryInfoResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/Switching/TurnoutInfoResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/BroadcastFlagsResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/HardwareInfoResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/SerialNumberResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/SoftwareLockResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/StatusChangedResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/SystemStateDataChangedResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/ProgrammingModeResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/StoppedResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOffResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/TrackPowerOnResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/TrackPower/TrackShortResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/UnknownCommandResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs similarity index 100% rename from src/Z21Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs rename to src/Z21.Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs diff --git a/src/Z21Client/Core/ResponseParser/CapabilitiesResponseParser.cs b/src/Z21.Client/Core/ResponseParser/CapabilitiesResponseParser.cs similarity index 100% rename from src/Z21Client/Core/ResponseParser/CapabilitiesResponseParser.cs rename to src/Z21.Client/Core/ResponseParser/CapabilitiesResponseParser.cs diff --git a/src/Z21Client/Core/ResponseParser/CentralStateExResponseParser.cs b/src/Z21.Client/Core/ResponseParser/CentralStateExResponseParser.cs similarity index 100% rename from src/Z21Client/Core/ResponseParser/CentralStateExResponseParser.cs rename to src/Z21.Client/Core/ResponseParser/CentralStateExResponseParser.cs diff --git a/src/Z21Client/Core/ResponseParser/CentralStateResponseParser.cs b/src/Z21.Client/Core/ResponseParser/CentralStateResponseParser.cs similarity index 100% rename from src/Z21Client/Core/ResponseParser/CentralStateResponseParser.cs rename to src/Z21.Client/Core/ResponseParser/CentralStateResponseParser.cs diff --git a/src/Z21Client/Core/ResponseParser/IZ21ResponseParser.cs b/src/Z21.Client/Core/ResponseParser/IZ21ResponseParser.cs similarity index 100% rename from src/Z21Client/Core/ResponseParser/IZ21ResponseParser.cs rename to src/Z21.Client/Core/ResponseParser/IZ21ResponseParser.cs diff --git a/src/Z21Client/Core/ResponseParser/SystemStateResponseParser.cs b/src/Z21.Client/Core/ResponseParser/SystemStateResponseParser.cs similarity index 100% rename from src/Z21Client/Core/ResponseParser/SystemStateResponseParser.cs rename to src/Z21.Client/Core/ResponseParser/SystemStateResponseParser.cs diff --git a/src/Z21Client/Core/Z21Client.cs b/src/Z21.Client/Core/Z21Client.cs similarity index 100% rename from src/Z21Client/Core/Z21Client.cs rename to src/Z21.Client/Core/Z21Client.cs diff --git a/src/Z21Client/Extension/StructExtension.cs b/src/Z21.Client/Extension/StructExtension.cs similarity index 100% rename from src/Z21Client/Extension/StructExtension.cs rename to src/Z21.Client/Extension/StructExtension.cs diff --git a/src/Z21Client/LICENSE b/src/Z21.Client/LICENSE similarity index 100% rename from src/Z21Client/LICENSE rename to src/Z21.Client/LICENSE diff --git a/src/Z21Client/Transport/IZ21Transport.cs b/src/Z21.Client/Transport/IZ21Transport.cs similarity index 100% rename from src/Z21Client/Transport/IZ21Transport.cs rename to src/Z21.Client/Transport/IZ21Transport.cs diff --git a/src/Z21Client/Transport/Z21Transport.cs b/src/Z21.Client/Transport/Z21Transport.cs similarity index 100% rename from src/Z21Client/Transport/Z21Transport.cs rename to src/Z21.Client/Transport/Z21Transport.cs diff --git a/src/Z21Client/Z21.Client.csproj b/src/Z21.Client/Z21.Client.csproj similarity index 100% rename from src/Z21Client/Z21.Client.csproj rename to src/Z21.Client/Z21.Client.csproj diff --git a/src/Z21Client/Z21.Client.csproj.DotSettings b/src/Z21.Client/Z21.Client.csproj.DotSettings similarity index 100% rename from src/Z21Client/Z21.Client.csproj.DotSettings rename to src/Z21.Client/Z21.Client.csproj.DotSettings From 8a83cee5a9e71079e949e359d57b6acff2b52918 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 15 Sep 2025 01:03:29 +0200 Subject: [PATCH 22/92] update docfx.json --- src/docfx.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/docfx.json b/src/docfx.json index 301d1b3..b22e02c 100644 --- a/src/docfx.json +++ b/src/docfx.json @@ -5,8 +5,9 @@ "src": [ { "src": "../src", - "files": [ - "**/*.csproj" + "files": [ + "Z21.Client/Z21.Client.csproj", + "Z21.DependencyInjection/Z21.DependencyInjection.csproj" ] } ], From d8c2970fdd1f322c697da01165e4ae55fbc4b0e4 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 15 Sep 2025 01:06:10 +0200 Subject: [PATCH 23/92] fix build --- src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj | 2 +- src/Z21.Console/Z21.Console.csproj | 2 +- src/Z21.DependencyInjection/Z21.DependencyInjection.csproj | 2 +- src/Z21.sln | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj b/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj index 7776ab0..bdc61a9 100644 --- a/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj +++ b/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj @@ -24,7 +24,7 @@ - + diff --git a/src/Z21.Console/Z21.Console.csproj b/src/Z21.Console/Z21.Console.csproj index c7d5343..1ef64ca 100644 --- a/src/Z21.Console/Z21.Console.csproj +++ b/src/Z21.Console/Z21.Console.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj b/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj index d090228..d9e6351 100644 --- a/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj +++ b/src/Z21.DependencyInjection/Z21.DependencyInjection.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/Z21.sln b/src/Z21.sln index 18c8597..8f05d2f 100644 --- a/src/Z21.sln +++ b/src/Z21.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.2.32630.192 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Z21.Client", "Z21Client\Z21.Client.csproj", "{A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Z21.Client", "Z21.Client\Z21.Client.csproj", "{A6BAE63F-5DBE-4AE7-B2C5-5CB89C25BA15}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z21.Client.UnitTest", "Z21.Client.UnitTest\Z21.Client.UnitTest.csproj", "{A3246DA8-ACBE-435D-B050-CA7595512C1A}" EndProject From 69236ba7b7c1f5e82b6fdf2a3f5af48f579d0363 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 01:06:30 +0200 Subject: [PATCH 24/92] Update BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml index a663b76..25b6411 100644 --- a/.github/workflows/BuildAndDeployDoc.yml +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -2,8 +2,9 @@ name: Build and Deploy Versioned Docs on: push: - branches: - - 'release/**' + branches: [ "Release/**" ] + pull_request: + branches: [ "Release/**" ] workflow_dispatch: jobs: From f07bcd272ed563f3c9a7173d2020a93ec7aad545 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 01:07:56 +0200 Subject: [PATCH 25/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9594ef2..a4839d7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Z21 [![.NET](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml) +# Z21 [![.NET](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml) [![Github Pages](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml) From a64368bda974a375402708576079502639f3f0ad Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 01:08:43 +0200 Subject: [PATCH 26/92] Update BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml index 25b6411..011acd1 100644 --- a/.github/workflows/BuildAndDeployDoc.yml +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -1,4 +1,4 @@ -name: Build and Deploy Versioned Docs +name: Github Pages on: push: From d2ddc16dcab480a4935e2e8478eecfb83cd8907a Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:30:18 +0200 Subject: [PATCH 27/92] Create MutationTesting.yml --- .github/workflows/MutationTesting.yml | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/MutationTesting.yml diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml new file mode 100644 index 0000000..5ec54dd --- /dev/null +++ b/.github/workflows/MutationTesting.yml @@ -0,0 +1,35 @@ +name: Mutation Testing + +on: + push: + branches: [ "Release/**" ] + pull_request: + branches: [ "Release/**" ] + workflow_dispatch: + +jobs: + mutation-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Install Stryker.NET + run: dotnet tool install -g dotnet-stryker + + - name: Run mutation tests + run: | + cd src/Z21.Tests + dotnet stryker --reporters "html" --output-path ../../stryker-report + + - name: Upload HTML report + uses: actions/upload-artifact@v3 + with: + name: stryker-html-report + path: stryker-report/mutation-report.html From 48ef8b61e1bef29fa3b2c3a3e5d99ba92a48b944 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:31:44 +0200 Subject: [PATCH 28/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 5ec54dd..cd09bc0 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -29,7 +29,7 @@ jobs: dotnet stryker --reporters "html" --output-path ../../stryker-report - name: Upload HTML report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: stryker-html-report path: stryker-report/mutation-report.html From 5fe7dcea80501fc990b17bfd36070b25d5fa87b2 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:32:46 +0200 Subject: [PATCH 29/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index cd09bc0..bb9931b 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -25,7 +25,7 @@ jobs: - name: Run mutation tests run: | - cd src/Z21.Tests + cd src/Z21.Client.UnitTest dotnet stryker --reporters "html" --output-path ../../stryker-report - name: Upload HTML report From a2020b475623d6e73043e9410dc3e836eb8197d7 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:34:09 +0200 Subject: [PATCH 30/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index bb9931b..fc50d44 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -26,7 +26,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporters "html" --output-path ../../stryker-report + dotnet stryker --reporter html --output-path ../../stryker-report - name: Upload HTML report uses: actions/upload-artifact@v4 From 633f704620146afc1e5f8b8d1ed4088b784c9384 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:35:46 +0200 Subject: [PATCH 31/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index fc50d44..3ee6baf 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -26,7 +26,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html --output-path ../../stryker-report + dotnet stryker --reporter html --output ../../stryker-report - name: Upload HTML report uses: actions/upload-artifact@v4 From c922c3f2188402bb1fdea67e46dc3e9f46e7fda1 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:38:28 +0200 Subject: [PATCH 32/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 3ee6baf..049f7f3 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -32,4 +32,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: stryker-html-report - path: stryker-report/mutation-report.html + path: stryker-report/reports/mutation-report.html From f242b480d8f3dcaa5bbd3948e0bd8b17d7bd04dc Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:41:13 +0200 Subject: [PATCH 33/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 049f7f3..f6b072c 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -26,7 +26,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html --output ../../stryker-report + dotnet stryker --reporter html, progress --output ../../stryker-report --mutation-level Advanced - name: Upload HTML report uses: actions/upload-artifact@v4 From 4b4e6c98ca91692ea398885710424c57f657a5e9 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:42:24 +0200 Subject: [PATCH 34/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index f6b072c..54d43ce 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -26,7 +26,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html, progress --output ../../stryker-report --mutation-level Advanced + dotnet stryker --reporter html progress --mutation-level Advanced --output ../../stryker-report - name: Upload HTML report uses: actions/upload-artifact@v4 From c2429c0445fe628558a1277ca2ec280cc97029b5 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:44:33 +0200 Subject: [PATCH 35/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 54d43ce..c48db0e 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -26,8 +26,8 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html progress --mutation-level Advanced --output ../../stryker-report - + dotnet stryker --reporter html cleartext --output ../../stryker-report --mutation-level Advanced + - name: Upload HTML report uses: actions/upload-artifact@v4 with: From eb250fe609ae71a15024cce06fce34e8e0dd1cf5 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:45:17 +0200 Subject: [PATCH 36/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index c48db0e..0547aa1 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -26,7 +26,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html cleartext --output ../../stryker-report --mutation-level Advanced + dotnet stryker --reporter html, cleartext --output ../../stryker-report --mutation-level Advanced - name: Upload HTML report uses: actions/upload-artifact@v4 From b811609bf34910a7ad00601c67ba38a5a8c233cd Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:46:02 +0200 Subject: [PATCH 37/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 0547aa1..acd2274 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -26,7 +26,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html, cleartext --output ../../stryker-report --mutation-level Advanced + dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced - name: Upload HTML report uses: actions/upload-artifact@v4 From 479a89abd09a6f115ca1ebaf24da3852a840f6ee Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:51:11 +0200 Subject: [PATCH 38/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index acd2274..9cfb44b 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -11,6 +11,10 @@ jobs: mutation-test: runs-on: ubuntu-latest + env: + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: - name: Checkout code uses: actions/checkout@v3 @@ -26,7 +30,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced + dotnet stryker --reporter html dashboard --output ../../stryker-report --mutation-level Advanced - name: Upload HTML report uses: actions/upload-artifact@v4 From 11dda2efd643fee39791c4476a6ce943e0295c7d Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:52:46 +0200 Subject: [PATCH 39/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 9cfb44b..543ff3e 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -30,7 +30,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html dashboard --output ../../stryker-report --mutation-level Advanced + dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced - name: Upload HTML report uses: actions/upload-artifact@v4 From 7bf62e06c34b8055d60622a091303fa4de267cf6 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:06:40 +0200 Subject: [PATCH 40/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 543ff3e..50bcdd9 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -30,7 +30,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced + dotnet stryker --reporter html, dashboard --output ../../stryker-report --mutation-level Advanced - name: Upload HTML report uses: actions/upload-artifact@v4 From 824fbc234e064d85d6862c6caa559275c1371a7d Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:07:30 +0200 Subject: [PATCH 41/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 50bcdd9..480394a 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -30,10 +30,4 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html, dashboard --output ../../stryker-report --mutation-level Advanced - - - name: Upload HTML report - uses: actions/upload-artifact@v4 - with: - name: stryker-html-report - path: stryker-report/reports/mutation-report.html + dotnet stryker --reporter dashboard --mutation-level Advanced From 030ac8dfc11ba35582d04476a618aebda09f72da Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:09:20 +0200 Subject: [PATCH 42/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 480394a..0f7271c 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -9,7 +9,7 @@ on: jobs: mutation-test: - runs-on: ubuntu-latest + runs-on: windows-latest env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} From 983c09871ddec3609a92d65f6825a1b22bde0779 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:12:28 +0200 Subject: [PATCH 43/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 0f7271c..c22c62f 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -24,6 +24,9 @@ jobs: with: dotnet-version: '8.0.x' + - name: Build target project + run: dotnet build src/Z21.Client/Z21.Client.csproj -c Debug + - name: Install Stryker.NET run: dotnet tool install -g dotnet-stryker From 30eb94cb420b02c5bbbaa2f94c28c0f52b01c955 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:17:36 +0200 Subject: [PATCH 44/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index c22c62f..365a3d6 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -9,21 +9,22 @@ on: jobs: mutation-test: - runs-on: windows-latest + runs-on: ubuntu-latest env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - name: Checkout code - uses: actions/checkout@v3 - + - uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: - dotnet-version: '8.0.x' - + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore src/Z21.sln + - name: Build + run: dotnet build src/Z21.sln --no-restore - name: Build target project run: dotnet build src/Z21.Client/Z21.Client.csproj -c Debug @@ -31,6 +32,4 @@ jobs: run: dotnet tool install -g dotnet-stryker - name: Run mutation tests - run: | - cd src/Z21.Client.UnitTest - dotnet stryker --reporter dashboard --mutation-level Advanced + run: dotnet stryker --reporter dashboard --mutation-level Advanced From 701e42a6ee8d8d0ca81c400f7e7958912d4430e3 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:18:50 +0200 Subject: [PATCH 45/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 365a3d6..8c8d9d9 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -32,4 +32,6 @@ jobs: run: dotnet tool install -g dotnet-stryker - name: Run mutation tests - run: dotnet stryker --reporter dashboard --mutation-level Advanced + run: + cd src/Z21.Client.UnitTest + dotnet stryker --reporter dashboard --mutation-level Advanced From 44c4cd94a616dc58808f53d094aac54b70a7dc0f Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:20:25 +0200 Subject: [PATCH 46/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 8c8d9d9..543ff3e 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -16,22 +16,24 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore src/Z21.sln - - name: Build - run: dotnet build src/Z21.sln --no-restore - - name: Build target project - run: dotnet build src/Z21.Client/Z21.Client.csproj -c Debug - + dotnet-version: '8.0.x' + - name: Install Stryker.NET run: dotnet tool install -g dotnet-stryker - name: Run mutation tests - run: - cd src/Z21.Client.UnitTest - dotnet stryker --reporter dashboard --mutation-level Advanced + run: | + cd src/Z21.Client.UnitTest + dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced + + - name: Upload HTML report + uses: actions/upload-artifact@v4 + with: + name: stryker-html-report + path: stryker-report/reports/mutation-report.html From 8d5e772169af01f7c3529ea002e465e09c5cc8c8 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:26:31 +0200 Subject: [PATCH 47/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 543ff3e..17ab43b 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -24,16 +24,13 @@ jobs: with: dotnet-version: '8.0.x' + - name: Build target project + run: dotnet build src/Z21/Z21.csproj --configuration Debug + - name: Install Stryker.NET run: dotnet tool install -g dotnet-stryker - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced - - - name: Upload HTML report - uses: actions/upload-artifact@v4 - with: - name: stryker-html-report - path: stryker-report/reports/mutation-report.html + dotnet stryker --reporter dashboard --output ../../stryker-report --mutation-level Advanced From 41b535ded70702d43c88494aa202135d69ff2679 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:27:30 +0200 Subject: [PATCH 48/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 17ab43b..8a71589 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -24,8 +24,8 @@ jobs: with: dotnet-version: '8.0.x' - - name: Build target project - run: dotnet build src/Z21/Z21.csproj --configuration Debug + - name: Warm up build with dotnet test + run: dotnet test src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj --no-run - name: Install Stryker.NET run: dotnet tool install -g dotnet-stryker From 6d928a285ff65a5cd72b3a9729c6a6ed6e6b5516 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:28:14 +0200 Subject: [PATCH 49/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 8a71589..304ceb2 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -23,9 +23,9 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: '8.0.x' - - - name: Warm up build with dotnet test - run: dotnet test src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj --no-run + + - name: Build solution + run: dotnet build Z21.sln --configuration Debug - name: Install Stryker.NET run: dotnet tool install -g dotnet-stryker From 20b7ffa1260af3be4f9d5c184d856e75b7be32c3 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:33:59 +0200 Subject: [PATCH 50/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 304ceb2..543ff3e 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -23,14 +23,17 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: '8.0.x' - - - name: Build solution - run: dotnet build Z21.sln --configuration Debug - + - name: Install Stryker.NET run: dotnet tool install -g dotnet-stryker - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter dashboard --output ../../stryker-report --mutation-level Advanced + dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced + + - name: Upload HTML report + uses: actions/upload-artifact@v4 + with: + name: stryker-html-report + path: stryker-report/reports/mutation-report.html From 4cdbcd2d82b0e8de4781f5b2a5f3697789d5e463 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:34:19 +0200 Subject: [PATCH 51/92] Update dotnet.yml --- .github/workflows/dotnet.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 06011aa..d5be10c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -13,7 +13,11 @@ jobs: build: runs-on: ubuntu-latest - + + env: + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: - uses: actions/checkout@v4 - name: Setup .NET @@ -26,3 +30,11 @@ jobs: run: dotnet build src/Z21.sln --no-restore - name: Test run: dotnet test src/Z21.sln --no-build --verbosity normal + + - name: Install Stryker.NET + run: dotnet tool install -g dotnet-stryker + + - name: Run mutation tests + run: | + cd src/Z21.Client.UnitTest + dotnet stryker --reporter dashboard --output ../../stryker-report --mutation-level Advanced From a449c2da952ee181d0e6c9784c62ef1f3d81fa74 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:35:27 +0200 Subject: [PATCH 52/92] Update dotnet.yml --- .github/workflows/dotnet.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index d5be10c..06011aa 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -13,11 +13,7 @@ jobs: build: runs-on: ubuntu-latest - - env: - STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - + steps: - uses: actions/checkout@v4 - name: Setup .NET @@ -30,11 +26,3 @@ jobs: run: dotnet build src/Z21.sln --no-restore - name: Test run: dotnet test src/Z21.sln --no-build --verbosity normal - - - name: Install Stryker.NET - run: dotnet tool install -g dotnet-stryker - - - name: Run mutation tests - run: | - cd src/Z21.Client.UnitTest - dotnet stryker --reporter dashboard --output ../../stryker-report --mutation-level Advanced From a02a3fa91dbc92c781d3dede90a9292335958be4 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:42:48 +0200 Subject: [PATCH 53/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 543ff3e..f4d36b2 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -30,7 +30,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced + dotnet stryker --project "Z21.Client.csproj" --reporter html --output ../../stryker-report --mutation-level Advanced - name: Upload HTML report uses: actions/upload-artifact@v4 From e2aa716e333e436ec56e32ce5a35f690fde26184 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:43:08 +0200 Subject: [PATCH 54/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index f4d36b2..a4b3f0c 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -30,10 +30,4 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --project "Z21.Client.csproj" --reporter html --output ../../stryker-report --mutation-level Advanced - - - name: Upload HTML report - uses: actions/upload-artifact@v4 - with: - name: stryker-html-report - path: stryker-report/reports/mutation-report.html + dotnet stryker --project "Z21.Client.csproj" --reporter dashboard --mutation-level Advanced From 6ddc5ed2a4efc7b6e0d74c465d3fdd731e2cb699 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:55:00 +0200 Subject: [PATCH 55/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index a4b3f0c..543ff3e 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -30,4 +30,10 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --project "Z21.Client.csproj" --reporter dashboard --mutation-level Advanced + dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced + + - name: Upload HTML report + uses: actions/upload-artifact@v4 + with: + name: stryker-html-report + path: stryker-report/reports/mutation-report.html From 4f78b2d546e3ad98d5597586b185423376035103 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:56:07 +0200 Subject: [PATCH 56/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4839d7..4ec52cf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Z21 [![.NET](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml) [![Github Pages](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml) +# Z21 [![.NET](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml) [![Github Pages](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml) [![Mutation Testing](https://github.com/Jakob-Eichberger/Z21/actions/workflows/MutationTesting.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/MutationTesting.yml) From f37d81ce1051415305a860585014a4e46055ae1d Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:57:49 +0200 Subject: [PATCH 57/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 543ff3e..e643f49 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -30,7 +30,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced + dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced --threshold-high 90 --threshold-low 80 --threshold-break 75 - name: Upload HTML report uses: actions/upload-artifact@v4 From 3e56ef1fc91d25759c748db0103def040c4aafa7 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:59:03 +0200 Subject: [PATCH 58/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index e643f49..7596b06 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -30,7 +30,7 @@ jobs: - name: Run mutation tests run: | cd src/Z21.Client.UnitTest - dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced --threshold-high 90 --threshold-low 80 --threshold-break 75 + dotnet stryker --reporter html --output ../../stryker-report --mutation-level Advanced --threshold-high 90 --threshold-low 80 --break-at 75 - name: Upload HTML report uses: actions/upload-artifact@v4 From 9387b08d2d4002fe4affd17d5bb49a8b7ca68be0 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 11:10:39 +0200 Subject: [PATCH 59/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ec52cf..ac8281a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The official documentation of the protocol can be downloaded from the ROCO homep - Platform-independent - Lightweight - SOLID and event-driven architecture - Allowing you to expand the library to your liking. -- Fully unit tested +- Fully unit and mutation tested - Supports dependency injection out of the box via Z21.DependencyInjection. - Fine grained command/response handler interfaces allowing for simple use. See below for a full list of all supported commands/responses. - System ✅ From 9b2ca818a912b5e319d23c93bcbdc95e5c8fb1c7 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 11:12:23 +0200 Subject: [PATCH 60/92] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac8281a..a467dbd 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ The official documentation of the protocol can be downloaded from the ROCO homep - SOLID and event-driven architecture - Allowing you to expand the library to your liking. - Fully unit and mutation tested - Supports dependency injection out of the box via Z21.DependencyInjection. -- Fine grained command/response handler interfaces allowing for simple use. See below for a full list of all supported commands/responses. +- Fine grained command/response handler interfaces with great documentation. +- Right now the following features of the Z21 LAN protocoll are implemented. See below for a fully detailed list of all supported commands/responses. - System ✅ - Driving ✅ - Switching ✅ From b874f1c4817320212c29e855ecf7b53498bc3a01 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 11:25:23 +0200 Subject: [PATCH 61/92] Update and rename dotnet.yml to Build.yml --- .github/workflows/{dotnet.yml => Build.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{dotnet.yml => Build.yml} (98%) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/Build.yml similarity index 98% rename from .github/workflows/dotnet.yml rename to .github/workflows/Build.yml index 06011aa..1f5318a 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/Build.yml @@ -1,7 +1,7 @@ # This workflow will build a .NET project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net -name: .NET +name: Build on: push: From f329d0cb578499d9a1fc1f77fac9531ba5b9a3cc Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 15 Sep 2025 13:03:43 +0200 Subject: [PATCH 62/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a467dbd..b485728 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Z21 [![.NET](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/dotnet.yml) [![Github Pages](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml) [![Mutation Testing](https://github.com/Jakob-Eichberger/Z21/actions/workflows/MutationTesting.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/MutationTesting.yml) +# Z21 [![Build](https://github.com/Jakob-Eichberger/Z21/actions/workflows/Build.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/Build.yml) [![Github Pages](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/BuildAndDeployDoc.yml) [![Mutation Testing](https://github.com/Jakob-Eichberger/Z21/actions/workflows/MutationTesting.yml/badge.svg)](https://github.com/Jakob-Eichberger/Z21/actions/workflows/MutationTesting.yml) From 0747636bd4a36b605b34742049509746eb6771bd Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 6 Oct 2025 22:35:32 +0200 Subject: [PATCH 63/92] upgrade Newtonsoft.Json --- src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj | 1 + .../Z21.DependencyInjection.UnitTest.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj b/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj index bdc61a9..a45acc7 100644 --- a/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj +++ b/src/Z21.Client.UnitTest/Z21.Client.UnitTest.csproj @@ -14,6 +14,7 @@ + diff --git a/src/Z21.DependencyInjection.UnitTest/Z21.DependencyInjection.UnitTest.csproj b/src/Z21.DependencyInjection.UnitTest/Z21.DependencyInjection.UnitTest.csproj index 26629e3..4e084c0 100644 --- a/src/Z21.DependencyInjection.UnitTest/Z21.DependencyInjection.UnitTest.csproj +++ b/src/Z21.DependencyInjection.UnitTest/Z21.DependencyInjection.UnitTest.csproj @@ -14,6 +14,7 @@ + From 72134fa7a61f2aa962ed317f072fb5d8b832b76d Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 6 Oct 2025 22:35:43 +0200 Subject: [PATCH 64/92] Use ushort for LocoAddress --- src/Z21.Client/Core/Model/LocoInfoData.cs | 2 +- .../Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Z21.Client/Core/Model/LocoInfoData.cs b/src/Z21.Client/Core/Model/LocoInfoData.cs index f90cbd9..023b317 100644 --- a/src/Z21.Client/Core/Model/LocoInfoData.cs +++ b/src/Z21.Client/Core/Model/LocoInfoData.cs @@ -4,7 +4,7 @@ namespace Z21.Core.Model { public class LocoInfoData { - public required short LocoAddress { get; init; } + public required ushort LocoAddress { get; init; } public required IReadOnlyCollection LocoFunctionsData { get; init; } diff --git a/src/Z21.Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs index 344cb5d..90004c1 100644 --- a/src/Z21.Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs +++ b/src/Z21.Client/Core/ResponseHandler/Driving/LocoInfoResponseHandler.cs @@ -39,7 +39,7 @@ public bool CanHandle(byte[] response) public void Handle(byte[] response) { - short address = (short)(((response[5] & 0x3F) << 8) + response[6]); + ushort address = (ushort)(((response[5] & 0x3F) << 8) + response[6]); byte db2 = response[7]; DecoderMode decoderMode = (db2 & 0x10) == 0x10 ? DecoderMode.MM : DecoderMode.DCC; From 53f31710b8c896da089ea428c9d9f9e5a2924447 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 6 Oct 2025 23:29:19 +0200 Subject: [PATCH 65/92] Update Build.yml --- .github/workflows/Build.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 1f5318a..dcb391a 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -20,9 +20,27 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x + + - name: Setup GitVersion + uses: GitTools/actions/gitversion/setup@v0.9.10 + with: + versionSpec: '5.x' + + - name: Run GitVersion + id: gitversion + uses: GitTools/actions/gitversion/execute@v0.9.10 + - name: Restore dependencies run: dotnet restore src/Z21.sln - name: Build - run: dotnet build src/Z21.sln --no-restore + run: dotnet build src/Z21.sln --no-restore /p:Version=${{ steps.gitversion.outputs.semVer }} - name: Test run: dotnet test src/Z21.sln --no-build --verbosity normal + + - name: Tag commit with GitVersion + if: github.event_name == 'push' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag v${{ steps.gitversion.outputs.semVer }} + git push origin v${{ steps.gitversion.outputs.semVer }} From 60f9d48ab3ec517b19e30f8f2b977635c7249a7c Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 6 Oct 2025 23:30:08 +0200 Subject: [PATCH 66/92] Update Build.yml --- .github/workflows/Build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index dcb391a..79a3caf 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -5,9 +5,7 @@ name: Build on: push: - branches: [ "Release/**" ] pull_request: - branches: [ "Release/**" ] jobs: build: From 9b55431749c802e980ccd7e341b966735567c3b3 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Mon, 6 Oct 2025 23:33:29 +0200 Subject: [PATCH 67/92] Update Build.yml --- .github/workflows/Build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 79a3caf..a3141bd 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -13,7 +13,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required for GitVersion to access full commit history + - name: Setup .NET uses: actions/setup-dotnet@v4 with: From 408f19a3453b870dd7ff921eea05c9a07584c0ce Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 6 Oct 2025 23:36:28 +0200 Subject: [PATCH 68/92] Add GitVersion config file --- GitVersion.yaml | 167 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 GitVersion.yaml diff --git a/GitVersion.yaml b/GitVersion.yaml new file mode 100644 index 0000000..7e8ec32 --- /dev/null +++ b/GitVersion.yaml @@ -0,0 +1,167 @@ +assembly-versioning-scheme: MajorMinorPatch +assembly-file-versioning-scheme: MajorMinorPatch +tag-prefix: '[vV]?' +version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* +major-version-bump-message: \+semver:\s?(breaking|major) +minor-version-bump-message: \+semver:\s?(feature|minor) +patch-version-bump-message: \+semver:\s?(fix|patch) +no-bump-message: \+semver:\s?(none|skip) +tag-pre-release-weight: 60000 +commit-date-format: yyyy-MM-dd +merge-message-formats: {} +update-build-number: true +semantic-version-format: Strict +strategies: +- Fallback +- ConfiguredNextVersion +- MergeMessage +- TaggedCommit +- TrackReleaseBranches +- VersionInBranchName +branches: + develop: + mode: ContinuousDeployment + label: alpha + increment: Minor + prevent-increment: + when-current-commit-tagged: false + track-merge-target: true + track-merge-message: true + regex: ^dev(elop)?(ment)?$ + source-branches: + - main + is-source-branch-for: [] + tracks-release-branches: true + is-release-branch: false + is-main-branch: false + pre-release-weight: 0 + main: + label: '' + increment: Patch + prevent-increment: + of-merged-branch: true + track-merge-target: false + track-merge-message: true + regex: ^master$|^main$ + source-branches: [] + is-source-branch-for: [] + tracks-release-branches: false + is-release-branch: false + is-main-branch: true + pre-release-weight: 55000 + release: + mode: ManualDeployment + label: beta + increment: Minor + prevent-increment: + of-merged-branch: true + when-current-commit-tagged: false + track-merge-target: false + regex: ^releases?[\/-](?.+) + source-branches: + - main + - support + is-source-branch-for: [] + tracks-release-branches: false + is-release-branch: true + is-main-branch: false + pre-release-weight: 30000 + feature: + mode: ManualDeployment + label: '{BranchName}' + increment: Inherit + prevent-increment: + when-current-commit-tagged: false + track-merge-message: true + regex: ^features?[\/-](?.+) + source-branches: + - develop + - main + - release + - support + - hotfix + is-source-branch-for: [] + is-main-branch: false + pre-release-weight: 30000 + pull-request: + mode: ContinuousDeployment + label: PullRequest{Number} + increment: Inherit + prevent-increment: + of-merged-branch: true + when-current-commit-tagged: false + track-merge-message: true + regex: ^(pull-requests|pull|pr)[\/-](?\d*) + source-branches: + - develop + - main + - release + - feature + - support + - hotfix + is-source-branch-for: [] + pre-release-weight: 30000 + hotfix: + mode: ManualDeployment + label: beta + increment: Inherit + prevent-increment: + when-current-commit-tagged: false + regex: ^hotfix(es)?[\/-](?.+) + source-branches: + - main + - support + is-source-branch-for: [] + is-release-branch: true + is-main-branch: false + pre-release-weight: 30000 + support: + label: '' + increment: Patch + prevent-increment: + of-merged-branch: true + track-merge-target: false + regex: ^support[\/-](?.+) + source-branches: + - main + is-source-branch-for: [] + tracks-release-branches: false + is-release-branch: false + is-main-branch: true + pre-release-weight: 55000 + unknown: + mode: ManualDeployment + label: '{BranchName}' + increment: Inherit + prevent-increment: + when-current-commit-tagged: true + regex: (?.+) + source-branches: + - main + - develop + - release + - feature + - pull-request + - hotfix + - support + is-source-branch-for: [] + is-main-branch: false +ignore: + sha: [] + paths: [] +mode: ContinuousDeployment +label: '{BranchName}' +increment: Inherit +prevent-increment: + of-merged-branch: false + when-branch-merged: false + when-current-commit-tagged: true +track-merge-target: false +track-merge-message: true +commit-message-incrementing: Enabled +regex: '' +source-branches: [] +is-source-branch-for: [] +tracks-release-branches: false +is-release-branch: false +is-main-branch: false \ No newline at end of file From 51438ce9d8cc6d96f0b4da204538744db45f5e66 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 6 Oct 2025 23:54:47 +0200 Subject: [PATCH 69/92] change gitversion config --- GitVersion.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitVersion.yaml b/GitVersion.yaml index 7e8ec32..2c30342 100644 --- a/GitVersion.yaml +++ b/GitVersion.yaml @@ -54,7 +54,7 @@ branches: label: beta increment: Minor prevent-increment: - of-merged-branch: true + of-merged-branch: false when-current-commit-tagged: false track-merge-target: false regex: ^releases?[\/-](?.+) From 5a2dff3e07013dbb6db8ebdcb950b16afbda42d2 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 6 Oct 2025 23:56:02 +0200 Subject: [PATCH 70/92] change gitversion config --- GitVersion.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GitVersion.yaml b/GitVersion.yaml index 2c30342..f35971e 100644 --- a/GitVersion.yaml +++ b/GitVersion.yaml @@ -50,11 +50,11 @@ branches: is-main-branch: true pre-release-weight: 55000 release: - mode: ManualDeployment + mode: ContinuousDeployment label: beta increment: Minor prevent-increment: - of-merged-branch: false + of-merged-branch: true when-current-commit-tagged: false track-merge-target: false regex: ^releases?[\/-](?.+) @@ -67,7 +67,7 @@ branches: is-main-branch: false pre-release-weight: 30000 feature: - mode: ManualDeployment + mode: ContinuousDeployment label: '{BranchName}' increment: Inherit prevent-increment: From 3030d6fefdd0cacabd96652345c4299261d07bdc Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 7 Oct 2025 00:00:41 +0200 Subject: [PATCH 71/92] change gitversion config --- GitVersion.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/GitVersion.yaml b/GitVersion.yaml index f35971e..2b2dfb8 100644 --- a/GitVersion.yaml +++ b/GitVersion.yaml @@ -18,6 +18,7 @@ strategies: - TaggedCommit - TrackReleaseBranches - VersionInBranchName + branches: develop: mode: ContinuousDeployment From 23e21d38595699d317215957f1ad749157d3fac1 Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 7 Oct 2025 00:21:13 +0200 Subject: [PATCH 72/92] change gitversion config --- GitVersion.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/GitVersion.yaml b/GitVersion.yaml index 2b2dfb8..26bfe8c 100644 --- a/GitVersion.yaml +++ b/GitVersion.yaml @@ -18,7 +18,6 @@ strategies: - TaggedCommit - TrackReleaseBranches - VersionInBranchName - branches: develop: mode: ContinuousDeployment @@ -55,7 +54,7 @@ branches: label: beta increment: Minor prevent-increment: - of-merged-branch: true + of-merged-branch: false when-current-commit-tagged: false track-merge-target: false regex: ^releases?[\/-](?.+) From 695f5a0d1e2269f957045199198acbd7e1443468 Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 7 Oct 2025 00:30:37 +0200 Subject: [PATCH 73/92] change gitversion config --- GitVersion.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitVersion.yaml b/GitVersion.yaml index 26bfe8c..f35971e 100644 --- a/GitVersion.yaml +++ b/GitVersion.yaml @@ -54,7 +54,7 @@ branches: label: beta increment: Minor prevent-increment: - of-merged-branch: false + of-merged-branch: true when-current-commit-tagged: false track-merge-target: false regex: ^releases?[\/-](?.+) From 5aeec88f67521d8a4b0e8e9675dd979a7838655b Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 00:36:54 +0200 Subject: [PATCH 74/92] Update Build.yml --- .github/workflows/Build.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index a3141bd..4722272 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -34,11 +34,26 @@ jobs: - name: Restore dependencies run: dotnet restore src/Z21.sln + - name: Build run: dotnet build src/Z21.sln --no-restore /p:Version=${{ steps.gitversion.outputs.semVer }} + - name: Test run: dotnet test src/Z21.sln --no-build --verbosity normal + - name: Pack NuGet package + run: | + dotnet pack src/Z21.sln --no-build --configuration Release \ + /p:PackageVersion=${{ steps.gitversion.outputs.semVer }} \ + /p:Version=${{ steps.gitversion.outputs.semVer }} \ + --output ./nupkgs + + - name: Upload NuGet package as artifact + uses: actions/upload-artifact@v4 + with: + name: nuget-package-${{ steps.gitversion.outputs.semVer }} + path: ./nupkgs/*.nupkg + - name: Tag commit with GitVersion if: github.event_name == 'push' run: | From f45dcc765d990395e3a8c33fbb58068f31f5cc94 Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 7 Oct 2025 00:44:11 +0200 Subject: [PATCH 75/92] change configurations --- src/Z21.Client/Z21.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Z21.Client/Z21.Client.csproj b/src/Z21.Client/Z21.Client.csproj index f5f6773..3c843bb 100644 --- a/src/Z21.Client/Z21.Client.csproj +++ b/src/Z21.Client/Z21.Client.csproj @@ -9,7 +9,7 @@ Z21Client partially implements the z21 lan protocoll for the digital command center z21/Z21 from Roco/Fleischmann. https://github.com/Jakob-Eichberger/z21Client Z21;Roco;Fleischman - Debug + Debug 4.0.0 x64 enable From 245f72a0c4584319672dbd346702cbe3197d659b Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 00:44:34 +0200 Subject: [PATCH 76/92] Update Build.yml --- .github/workflows/Build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 4722272..a038688 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -36,7 +36,7 @@ jobs: run: dotnet restore src/Z21.sln - name: Build - run: dotnet build src/Z21.sln --no-restore /p:Version=${{ steps.gitversion.outputs.semVer }} + run: dotnet build src/Z21.sln --no-restore --configuration Release /p:Version=${{ steps.gitversion.outputs.semVer }} - name: Test run: dotnet test src/Z21.sln --no-build --verbosity normal From fd4ac0434fda1335a38aaa498b80e00437708524 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 00:47:17 +0200 Subject: [PATCH 77/92] Update Build.yml --- .github/workflows/Build.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index a038688..3f2dd78 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -35,12 +35,15 @@ jobs: - name: Restore dependencies run: dotnet restore src/Z21.sln - - name: Build - run: dotnet build src/Z21.sln --no-restore --configuration Release /p:Version=${{ steps.gitversion.outputs.semVer }} + - name: Build for testing (Debug) + run: dotnet build src/Z21.sln --no-restore /p:Version=${{ steps.gitversion.outputs.semVer }} - name: Test run: dotnet test src/Z21.sln --no-build --verbosity normal + - name: Build for packaging (Release) + run: dotnet build src/Z21.sln --no-restore --configuration Release /p:Version=${{ steps.gitversion.outputs.semVer }} + - name: Pack NuGet package run: | dotnet pack src/Z21.sln --no-build --configuration Release \ From fb4f669597c002f368f1314225a39ca7218db495 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 00:51:08 +0200 Subject: [PATCH 78/92] Update Build.yml --- .github/workflows/Build.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 3f2dd78..6ca7c89 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -44,13 +44,20 @@ jobs: - name: Build for packaging (Release) run: dotnet build src/Z21.sln --no-restore --configuration Release /p:Version=${{ steps.gitversion.outputs.semVer }} - - name: Pack NuGet package + - name: Pack Z21.sln NuGet package run: | dotnet pack src/Z21.sln --no-build --configuration Release \ /p:PackageVersion=${{ steps.gitversion.outputs.semVer }} \ /p:Version=${{ steps.gitversion.outputs.semVer }} \ --output ./nupkgs + - name: Pack Z21.DependencyInjection NuGet package + run: | + dotnet pack src/Z21.DependencyInjection/Z21.DependencyInjection.csproj --no-build --configuration Release \ + /p:PackageVersion=${{ steps.gitversion.outputs.semVer }} \ + /p:Version=${{ steps.gitversion.outputs.semVer }} \ + --output ./nupkgs + - name: Upload NuGet package as artifact uses: actions/upload-artifact@v4 with: From 28ea6514d4947c4f727b965319128888b7166195 Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 7 Oct 2025 00:52:49 +0200 Subject: [PATCH 79/92] dont create nuget for console --- src/Z21.Console/Z21.Console.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Z21.Console/Z21.Console.csproj b/src/Z21.Console/Z21.Console.csproj index 1ef64ca..0531a19 100644 --- a/src/Z21.Console/Z21.Console.csproj +++ b/src/Z21.Console/Z21.Console.csproj @@ -6,6 +6,7 @@ 12 enable enable + false From 58b6a9e76a0fd790a6db9f870fc297dfe60142b4 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 00:53:27 +0200 Subject: [PATCH 80/92] Update MutationTesting.yml --- .github/workflows/MutationTesting.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/MutationTesting.yml b/.github/workflows/MutationTesting.yml index 7596b06..2f47a0f 100644 --- a/.github/workflows/MutationTesting.yml +++ b/.github/workflows/MutationTesting.yml @@ -2,9 +2,7 @@ name: Mutation Testing on: push: - branches: [ "Release/**" ] pull_request: - branches: [ "Release/**" ] workflow_dispatch: jobs: From 8043b220c2a5f329d12ada13747d4eda419a596f Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 00:56:56 +0200 Subject: [PATCH 81/92] Update BuildAndDeployDoc.yml --- .github/workflows/BuildAndDeployDoc.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/BuildAndDeployDoc.yml b/.github/workflows/BuildAndDeployDoc.yml index 011acd1..a1e1823 100644 --- a/.github/workflows/BuildAndDeployDoc.yml +++ b/.github/workflows/BuildAndDeployDoc.yml @@ -2,9 +2,9 @@ name: Github Pages on: push: - branches: [ "Release/**" ] + branches: [ "release/**", "main" ] pull_request: - branches: [ "Release/**" ] + branches: [ "release/**", "main" ] workflow_dispatch: jobs: @@ -19,7 +19,8 @@ jobs: run: | RAW_REF="${GITHUB_REF#refs/heads/}" VERSION="${RAW_REF#Release/}" - echo "version=$VERSION" >> $GITHUB_OUTPUT + CLEAN_VERSION=$(echo "$VERSION" | cut -d'-' -f1) + echo "version=$CLEAN_VERSION" >> $GITHUB_OUTPUT - name: Setup .NET uses: actions/setup-dotnet@v3 From b59299d75fdbe0e68a4559ad93ffe2b089447272 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 01:07:22 +0200 Subject: [PATCH 82/92] Create main.yml --- .github/workflows/main.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..f3e00a2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,33 @@ +name: Publish NuGet Packages + +on: + workflow_run: + workflows: ["Build"] + types: + - completed + +jobs: + publish: + if: | + github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') + runs-on: ubuntu-latest + + steps: + - name: Download NuGet packages from Build workflow + uses: actions/download-artifact@v4 + with: + name: nuget-package-${{ github.event.workflow_run.head_commit.message }} + path: ./nupkgs + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Push packages to NuGet + run: | + for pkg in ./nupkgs/*.nupkg; do + dotnet nuget push "$pkg" \ + --api-key ${{ secrets.NUGET_API_KEY }} \ + --source https://api.nuget.org/v3/index.json + done From a01110bf73030b1a963479f67d3c50e54655db66 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 01:09:40 +0200 Subject: [PATCH 83/92] Update Build.yml --- .github/workflows/Build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 6ca7c89..3820504 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -61,7 +61,7 @@ jobs: - name: Upload NuGet package as artifact uses: actions/upload-artifact@v4 with: - name: nuget-package-${{ steps.gitversion.outputs.semVer }} + name: nuget-packages path: ./nupkgs/*.nupkg - name: Tag commit with GitVersion From b8c020ecf79f1cacbd10ecb65ccf38d955fc2ab9 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 01:10:20 +0200 Subject: [PATCH 84/92] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3e00a2..406fd1a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - name: Download NuGet packages from Build workflow uses: actions/download-artifact@v4 with: - name: nuget-package-${{ github.event.workflow_run.head_commit.message }} + name: nuget-packages path: ./nupkgs - name: Setup .NET From c9e165f976b59d8ae741f1eaef878a797feb6fc8 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 01:14:58 +0200 Subject: [PATCH 85/92] Update Build.yml --- .github/workflows/Build.yml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 3820504..bb7db9f 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -31,7 +31,7 @@ jobs: - name: Run GitVersion id: gitversion uses: GitTools/actions/gitversion/execute@v0.9.10 - + - name: Restore dependencies run: dotnet restore src/Z21.sln @@ -43,7 +43,15 @@ jobs: - name: Build for packaging (Release) run: dotnet build src/Z21.sln --no-restore --configuration Release /p:Version=${{ steps.gitversion.outputs.semVer }} - + + - name: Tag commit with GitVersion + if: github.event_name == 'push' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag v${{ steps.gitversion.outputs.semVer }} + git push origin v${{ steps.gitversion.outputs.semVer }} + - name: Pack Z21.sln NuGet package run: | dotnet pack src/Z21.sln --no-build --configuration Release \ @@ -63,11 +71,12 @@ jobs: with: name: nuget-packages path: ./nupkgs/*.nupkg - - - name: Tag commit with GitVersion - if: github.event_name == 'push' + + - name: Push packages to NuGet + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git tag v${{ steps.gitversion.outputs.semVer }} - git push origin v${{ steps.gitversion.outputs.semVer }} + for pkg in ./nupkgs/*.nupkg; do + dotnet nuget push "$pkg" \ + --api-key ${{ secrets.NUGET_API_KEY }} \ + --source https://api.nuget.org/v3/index.json + done From d163815f9d8a50b57a328e30c763694624b4480f Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 7 Oct 2025 01:15:41 +0200 Subject: [PATCH 86/92] remove none needed workflow --- .github/workflows/main.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 406fd1a..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Publish NuGet Packages - -on: - workflow_run: - workflows: ["Build"] - types: - - completed - -jobs: - publish: - if: | - github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') - runs-on: ubuntu-latest - - steps: - - name: Download NuGet packages from Build workflow - uses: actions/download-artifact@v4 - with: - name: nuget-packages - path: ./nupkgs - - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - - name: Push packages to NuGet - run: | - for pkg in ./nupkgs/*.nupkg; do - dotnet nuget push "$pkg" \ - --api-key ${{ secrets.NUGET_API_KEY }} \ - --source https://api.nuget.org/v3/index.json - done From 857eddbd5cb57a2f9449d700f6e20997fa2c01f7 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Tue, 7 Oct 2025 01:20:29 +0200 Subject: [PATCH 87/92] Update Build.yml --- .github/workflows/Build.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index bb7db9f..672870d 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -66,12 +66,6 @@ jobs: /p:Version=${{ steps.gitversion.outputs.semVer }} \ --output ./nupkgs - - name: Upload NuGet package as artifact - uses: actions/upload-artifact@v4 - with: - name: nuget-packages - path: ./nupkgs/*.nupkg - - name: Push packages to NuGet if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') run: | From e5360f8f34c2ac1d1b4f178f57b6ae450b9bc888 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Wed, 8 Oct 2025 23:10:23 +0200 Subject: [PATCH 88/92] Update Build.yml --- .github/workflows/Build.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 672870d..0128d4d 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -66,8 +66,16 @@ jobs: /p:Version=${{ steps.gitversion.outputs.semVer }} \ --output ./nupkgs + - name: Check commit message + id: commitcheck + run: | + echo "commit_message=$(git log -1 --pretty=%B)" >> $GITHUB_OUTPUT + - name: Push packages to NuGet - if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') + if: | + github.ref == 'refs/heads/main' || + (startsWith(github.ref, 'refs/heads/release/') && + contains(steps.commitcheck.outputs.commit_message, '[publishnuget]')) run: | for pkg in ./nupkgs/*.nupkg; do dotnet nuget push "$pkg" \ From 1a34998f38aaf4257e2b6384e29d06f047bd2677 Mon Sep 17 00:00:00 2001 From: Jakob Date: Wed, 8 Oct 2025 23:53:36 +0200 Subject: [PATCH 89/92] VersionResponseHandler correctly parses version. FirmwareVersion supports IComparable and IEquatable. --- .../Core/Model/FirmwareVersionTest.cs | 82 +++++++++++++++++++ .../SystemState/VersionResponseHandlerTest.cs | 24 +++--- .../EventArgs/VersionReceivedEventArgs.cs | 6 +- src/Z21.Client/Core/Model/FirmwareVersion.cs | 32 +++++++- .../SystemState/VersionResponseHandler.cs | 2 +- src/Z21.Client/Extension/StructExtension.cs | 9 -- 6 files changed, 128 insertions(+), 27 deletions(-) create mode 100644 src/Z21.Client.UnitTest/Core/Model/FirmwareVersionTest.cs delete mode 100644 src/Z21.Client/Extension/StructExtension.cs diff --git a/src/Z21.Client.UnitTest/Core/Model/FirmwareVersionTest.cs b/src/Z21.Client.UnitTest/Core/Model/FirmwareVersionTest.cs new file mode 100644 index 0000000..f9307f2 --- /dev/null +++ b/src/Z21.Client.UnitTest/Core/Model/FirmwareVersionTest.cs @@ -0,0 +1,82 @@ +using Z21.Core.Model; + +namespace Z21.UnitTest.Core.Model +{ + [TestFixture] + public class FirmwareVersionTests + { + [Test] + public void ToString_ReturnsExpectedFormat() + { + FirmwareVersion version = new(3, 6); + Assert.That(version.ToString(), Is.EqualTo("3.6")); + } + + [Test] + public void Equals_SameValues_ReturnsTrue() + { + FirmwareVersion v1 = new(4, 0); + FirmwareVersion v2 = new(4, 0); + Assert.That(v1, Is.EqualTo(v2)); + Assert.That(v1, Is.EqualTo(v2)); + Assert.That(v1, Is.EqualTo(v2)); + } + + [Test] + public void Equals_DifferentValues_ReturnsFalse() + { + FirmwareVersion v1 = new(3, 0); + FirmwareVersion v2 = new(3, 1); + Assert.That(v1, Is.Not.EqualTo(v2)); + Assert.That(v1, Is.Not.EqualTo(v2)); + Assert.That(v1, Is.Not.EqualTo(v2)); + } + + [Test] + public void CompareTo_MajorVersionWins() + { + FirmwareVersion lower = new(3, 9); + FirmwareVersion higher = new(4, 0); + Assert.That(lower.CompareTo(higher), Is.LessThan(0)); + Assert.That(higher.CompareTo(lower), Is.GreaterThan(0)); + } + + [Test] + public void CompareTo_MinorVersionWins() + { + FirmwareVersion lower = new(3, 5); + FirmwareVersion higher = new(3, 6); + Assert.That(lower.CompareTo(higher), Is.LessThan(0)); + Assert.That(higher.CompareTo(lower), Is.GreaterThan(0)); + } + + [Test] + public void ComparisonOperators_WorkAsExpected() + { + FirmwareVersion v1 = new(3, 0); + FirmwareVersion v2 = new(3, 6); + FirmwareVersion v3 = new(4, 0); + FirmwareVersion v4 = new(4, 1); + + Assert.That(v1, Is.LessThan(v2), "v1 < v2"); + Assert.That(v2, Is.LessThanOrEqualTo(v3), "v2 <= v3"); + Assert.That(v3, Is.GreaterThan(v2), "v3 > v2"); + Assert.That(v4, Is.GreaterThanOrEqualTo(v3), "v4 >= v3"); + } + + [Test] + public void GetHashCode_EqualObjects_HaveSameHash() + { + FirmwareVersion v1 = new(3, 6); + FirmwareVersion v2 = new(3, 6); + Assert.That(v2.GetHashCode(), Is.EqualTo(v1.GetHashCode())); + } + + [Test] + public void Equals_Null_ReturnsFalse() + { + FirmwareVersion version = new(3, 6); + Assert.That(version, Is.Not.EqualTo(null)); + } + } +} \ No newline at end of file diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/VersionResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/VersionResponseHandlerTest.cs index 8975685..f41ff64 100644 --- a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/VersionResponseHandlerTest.cs +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/VersionResponseHandlerTest.cs @@ -1,4 +1,5 @@ -using Z21.Core.Model.EventArgs; +using Z21.Core.Model; +using Z21.Core.Model.EventArgs; using Z21.Core.ResponseHandler; using Z21.Core.ResponseHandler.SystemState; @@ -37,29 +38,28 @@ public void CanHandle_InvalidResponse_ReturnsFalse(byte[] response) [Test] public void Handle_ValidResponse_RaisesEventWithCorrectArgs() { - byte[] response = [0x00, 0x00, 0x40, 0x00, 0x63, 0x21, 0xAA, 0xBB]; + byte[] response = [0x00, 0x00, 0x40, 0x00, 0x63, 0x21, 0x43, 0xBB]; VersionReceivedEventArgs? receivedArgs = null; VersionResponseHandler? handler = null; _handler.OnVersionReceived += (sender, args) => - { - receivedArgs = args; - handler = sender as VersionResponseHandler; - }; + { + receivedArgs = args; + handler = sender as VersionResponseHandler; + }; _handler.Handle(response); - Assert.Multiple( - () => + Assert.Multiple(() => { Assert.That(handler, Is.EqualTo(_handler)); Assert.That(receivedArgs, Is.Not.Null); }); - Assert.Multiple( - () => + Assert.Multiple(() => { - Assert.That(receivedArgs!.XbusVer, Is.EqualTo(0xAA)); - Assert.That(receivedArgs.CmdstId, Is.EqualTo(0xBB)); + Assert.That(receivedArgs.FirmwareVersion, Is.Not.Null); + Assert.That(receivedArgs.FirmwareVersion, Is.EqualTo(new FirmwareVersion(4, 3))); + Assert.That(receivedArgs.CommandStationId, Is.EqualTo(0xBB)); }); } } diff --git a/src/Z21.Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs index 60695ea..9cd356b 100644 --- a/src/Z21.Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs +++ b/src/Z21.Client/Core/Model/EventArgs/VersionReceivedEventArgs.cs @@ -1,9 +1,9 @@ namespace Z21.Core.Model.EventArgs { - public class VersionReceivedEventArgs(int xbusVer, int cmdstId) : System.EventArgs + public class VersionReceivedEventArgs(FirmwareVersion firmwareVersion, int commandStationId) : System.EventArgs { - public int XbusVer { get; } = xbusVer; + public FirmwareVersion FirmwareVersion { get; } = firmwareVersion; - public int CmdstId { get; } = cmdstId; + public int CommandStationId { get; } = commandStationId; } } \ No newline at end of file diff --git a/src/Z21.Client/Core/Model/FirmwareVersion.cs b/src/Z21.Client/Core/Model/FirmwareVersion.cs index 05294a3..a63da6a 100644 --- a/src/Z21.Client/Core/Model/FirmwareVersion.cs +++ b/src/Z21.Client/Core/Model/FirmwareVersion.cs @@ -1,6 +1,8 @@ -namespace Z21.Core.Model +using System; + +namespace Z21.Core.Model { - public class FirmwareVersion(int major, int minor) + public sealed class FirmwareVersion(int major, int minor) : IComparable, IEquatable { public int Major { get; } = major; @@ -9,5 +11,31 @@ public class FirmwareVersion(int major, int minor) public string Firmware { get; } = major + "." + minor; override public string ToString() => Firmware; + + public bool Equals(FirmwareVersion? other) => Major == other?.Major && Minor == other.Minor; + + override public bool Equals(object? obj) => obj is FirmwareVersion other && Equals(other); + + override public int GetHashCode() => HashCode.Combine(Major, Minor); + + public int CompareTo(FirmwareVersion? other) + { + int majorCmp = Major.CompareTo(other?.Major); + return majorCmp != 0 ? majorCmp : Minor.CompareTo(other?.Minor); + } + + public static bool operator <(FirmwareVersion left, FirmwareVersion right) => left.CompareTo(right) < 0; + + public static bool operator >(FirmwareVersion left, FirmwareVersion right) => left.CompareTo(right) > 0; + + public static bool operator <=(FirmwareVersion left, FirmwareVersion right) => left.CompareTo(right) <= 0; + + public static bool operator >=(FirmwareVersion left, FirmwareVersion right) => left.CompareTo(right) >= 0; + + public static bool operator ==(FirmwareVersion left, FirmwareVersion right) => left.Equals(right); + + public static bool operator !=(FirmwareVersion left, FirmwareVersion right) => !left.Equals(right); + + } } \ No newline at end of file diff --git a/src/Z21.Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs b/src/Z21.Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs index 975d54e..e90ce9a 100644 --- a/src/Z21.Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs +++ b/src/Z21.Client/Core/ResponseHandler/SystemState/VersionResponseHandler.cs @@ -37,7 +37,7 @@ public void Handle(byte[] response) { byte xbusVer = response[6]; byte cmdStationId = response[7]; - OnVersionReceived?.Invoke(this, new(xbusVer, cmdStationId)); + OnVersionReceived?.Invoke(this, new(new(xbusVer >> 4, xbusVer & 0x0F), cmdStationId)); } } } \ No newline at end of file diff --git a/src/Z21.Client/Extension/StructExtension.cs b/src/Z21.Client/Extension/StructExtension.cs deleted file mode 100644 index 302ba7e..0000000 --- a/src/Z21.Client/Extension/StructExtension.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Z21.Extension -{ - public static class StructExtension - { - public static bool IsSet(this uint mask, uint flag) => (flag & mask) != 0; - } -} \ No newline at end of file From 512ef0db172b6bb704894608d634e0ed3990b03c Mon Sep 17 00:00:00 2001 From: Jakob Date: Thu, 9 Oct 2025 00:00:02 +0200 Subject: [PATCH 90/92] Cleanup --- .../SystemState/FirmwareVersionResponseHandlerTest.cs | 1 - .../Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs | 4 +--- src/Z21.Client/Core/Model/FirmwareVersion.cs | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandlerTest.cs b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandlerTest.cs index 370ba82..2d4d280 100644 --- a/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandlerTest.cs +++ b/src/Z21.Client.UnitTest/Core/ResponseHandler/SystemState/FirmwareVersionResponseHandlerTest.cs @@ -1,5 +1,4 @@ using Z21.Core.Model.EventArgs; -using Z21.Core.ResponseHandler; using Z21.Core.ResponseHandler.SystemState; namespace Z21.UnitTest.Core.ResponseHandler.SystemState diff --git a/src/Z21.Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs b/src/Z21.Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs index 819f30f..8986432 100644 --- a/src/Z21.Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs +++ b/src/Z21.Client/Core/Model/EventArgs/FirmwareVersionReceivedEventArgs.cs @@ -1,6 +1,4 @@ -using Z21.Core.ResponseHandler; - -namespace Z21.Core.Model.EventArgs +namespace Z21.Core.Model.EventArgs { public class FirmwareVersionReceivedEventArgs(FirmwareVersion firmwareVersion) { diff --git a/src/Z21.Client/Core/Model/FirmwareVersion.cs b/src/Z21.Client/Core/Model/FirmwareVersion.cs index a63da6a..a6c4fba 100644 --- a/src/Z21.Client/Core/Model/FirmwareVersion.cs +++ b/src/Z21.Client/Core/Model/FirmwareVersion.cs @@ -35,7 +35,5 @@ public int CompareTo(FirmwareVersion? other) public static bool operator ==(FirmwareVersion left, FirmwareVersion right) => left.Equals(right); public static bool operator !=(FirmwareVersion left, FirmwareVersion right) => !left.Equals(right); - - } } \ No newline at end of file From e4aedc20b5646b4ed20d94e3faf9f1cc6f4d5335 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Sat, 11 Oct 2025 01:21:08 +0200 Subject: [PATCH 91/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b485728..dd00ccf 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The official documentation of the protocol can be downloaded from the ROCO homep - Switching ✅ ## Getting Started -Get started by downloading the provided nuget Z21 package. To register the Z21 client use the Z21.DependencyInjection nuget package. +Get started by downloading the provided nuget [Z21](https://www.nuget.org/packages/Z21/) package. To register the Z21 client use the [Z21.DependencyInjection](https://www.nuget.org/packages/Z21.DependencyInjection/) nuget package. ### Commands All Commands can be found in the Z21.Core.Command namespace. From beddeb07b42d9b946d640f536c21b96c19ee2db4 Mon Sep 17 00:00:00 2001 From: Jakob <53713395+Jakob-Eichberger@users.noreply.github.com> Date: Sat, 11 Oct 2025 01:23:01 +0200 Subject: [PATCH 92/92] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd00ccf..86c8e4e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The official documentation of the protocol can be downloaded from the ROCO homep - Switching ✅ ## Getting Started -Get started by downloading the provided nuget [Z21](https://www.nuget.org/packages/Z21/) package. To register the Z21 client use the [Z21.DependencyInjection](https://www.nuget.org/packages/Z21.DependencyInjection/) nuget package. +Get started by downloading the provided [Z21](https://www.nuget.org/packages/Z21/) nuget package. Dependency injection is nativly supported with the provided [Z21.DependencyInjection](https://www.nuget.org/packages/Z21.DependencyInjection/) nuget package. ### Commands All Commands can be found in the Z21.Core.Command namespace.