From fd1de75a1d14e87847dc8227f17291102985b19e Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Wed, 24 Jun 2020 10:44:57 -0500 Subject: [PATCH 01/47] Updated CiscoSpark to work with ce9.13 Resolves #277 --- .../VideoCodec/CiscoCodec/CiscoSparkCodec.cs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs index cad7a18c..05bd7b01 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs @@ -601,9 +601,9 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco //JsonSerializerSettings settings = new JsonSerializerSettings(); //settings.NullValueHandling = NullValueHandling.Ignore; //settings.MissingMemberHandling = MissingMemberHandling.Ignore; - //settings.ObjectCreationHandling = ObjectCreationHandling.Auto; - - if (response.IndexOf("\"Status\":{") > -1) + //settings.ObjectCreationHandling = ObjectCreationHandling.Auto; + + if (response.IndexOf("\"Status\":{") > -1 || response.IndexOf("\"Status\": {") > -1) { // Status Message @@ -775,8 +775,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco if (!SyncState.InitialConfigurationMessageWasReceived) SendText("xConfiguration"); } - } - else if (response.IndexOf("\"Configuration\":{") > -1) + } + else if (response.IndexOf("\"Configuration\":{") > -1 || response.IndexOf("\"Configuration\": {") > -1) { // Configuration Message @@ -791,39 +791,39 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco } } - } - else if (response.IndexOf("\"Event\":{") > -1) - { - if (response.IndexOf("\"CallDisconnect\":{") > -1) + } + else if (response.IndexOf("\"Event\":{") > -1 || response.IndexOf("\"Event\": {") > -1) + { + if (response.IndexOf("\"CallDisconnect\":{") > -1 || response.IndexOf("\"CallDisconnect\": {") > -1) { CiscoCodecEvents.RootObject eventReceived = new CiscoCodecEvents.RootObject(); JsonConvert.PopulateObject(response, eventReceived); EvalutateDisconnectEvent(eventReceived); - } - else if (response.IndexOf("\"Bookings\":{") > -1) // The list has changed, reload it + } + else if (response.IndexOf("\"Bookings\":{") > -1 || response.IndexOf("\"Bookings\": {") > -1) // The list has changed, reload it { GetBookings(null); } - } - else if (response.IndexOf("\"CommandResponse\":{") > -1) + } + else if (response.IndexOf("\"CommandResponse\":{") > -1 || response.IndexOf("\"CommandResponse\": {") > -1) { - // CommandResponse Message - - if (response.IndexOf("\"CallHistoryRecentsResult\":{") > -1) + // CommandResponse Message + + if (response.IndexOf("\"CallHistoryRecentsResult\":{") > -1 || response.IndexOf("\"CallHistoryRecentsResult\": {") > -1) { var codecCallHistory = new CiscoCallHistory.RootObject(); JsonConvert.PopulateObject(response, codecCallHistory); CallHistory.ConvertCiscoCallHistoryToGeneric(codecCallHistory.CommandResponse.CallHistoryRecentsResult.Entry); - } - else if (response.IndexOf("\"CallHistoryDeleteEntryResult\":{") > -1) + } + else if (response.IndexOf("\"CallHistoryDeleteEntryResult\":{") > -1 || response.IndexOf("\"CallHistoryDeleteEntryResult\": {") > -1) { GetCallHistory(); - } - else if (response.IndexOf("\"PhonebookSearchResult\":{") > -1) + } + else if (response.IndexOf("\"PhonebookSearchResult\":{") > -1 || response.IndexOf("\"PhonebookSearchResult\": {") > -1) { var codecPhonebookResponse = new CiscoCodecPhonebook.RootObject(); From 001933bac39272e22c4b3fbfa540e4305ea80160 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Thu, 25 Jun 2020 10:12:30 -0500 Subject: [PATCH 02/47] Change base class on HdMdNxM4kEController to be CrestronGenericBaseDevice Add required Factory class to HdMdNxM4kEController Fixes #280 --- .../Chassis/HdMdNxM4kEController.cs | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdMdNxM4kEController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdMdNxM4kEController.cs index fff3b112..57c52627 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdMdNxM4kEController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdMdNxM4kEController.cs @@ -4,14 +4,16 @@ using System.Linq; using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro.DM; +using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.DM.Config; namespace PepperDash.Essentials.DM.Chassis { - public class HdMdNxM4kEController : Device, IRoutingInputsOutputs, IRouting + public class HdMdNxM4kEController : CrestronGenericBaseDevice, IRoutingInputsOutputs, IRouting { public HdMdNxM Chassis { get; private set; } @@ -27,7 +29,7 @@ namespace PepperDash.Essentials.DM.Chassis /// public HdMdNxM4kEController(string key, string name, HdMdNxM chassis, HdMdNxM4kEPropertiesConfig props) - : base(key, name) + : base(key, name, chassis) { Chassis = chassis; @@ -99,6 +101,8 @@ namespace PepperDash.Essentials.DM.Chassis /// /// /// + /// /* + /* public static HdMdNxM4kEController GetController(string key, string name, string type, HdMdNxM4kEPropertiesConfig properties) { @@ -123,6 +127,35 @@ namespace PepperDash.Essentials.DM.Chassis Debug.Console(0, "ERROR Creating device key {0}: \r{1}", key, e); return null; } + }*/ + + #region Factory + + public class HdMdNxM4kEFactory : EssentialsDeviceFactory + { + public HdMdNxM4kEFactory() + { + TypeNames = new List() {"hdmd4x14ke"}; + } + + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new HD-MD-NxM-4K-E Device"); + + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + var type = dc.Type.ToLower(); + var control = props.Control; + var ipid = control.IpIdInt; + var address = control.TcpSshProperties.Address; + + return new HdMdNxM4kEController(dc.Key, dc.Name, new HdMd4x14kE(ipid, address, Global.ControlSystem), props); + + } } + + #endregion + } } \ No newline at end of file From 8d8899f9aca591b1f356ec5915bb20bf3d4b5609 Mon Sep 17 00:00:00 2001 From: Jonathan Avila Date: Sat, 27 Jun 2020 15:44:51 -0400 Subject: [PATCH 03/47] Resolves #262 Register device when using internal RF gateway --- .../Remotes/Hrxx0WirelessRemoteController.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs index ff1ef06b..746f449f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs @@ -112,17 +112,29 @@ namespace PepperDash.Essentials.Core return null; } + Hr1x0WirelessRemoteBase remoteBase; switch (type) { case ("hr100"): - return new Hr100(rfId, gateway); + remoteBase = new Hr100(rfId, gateway); + break; case ("hr150"): - return new Hr150(rfId, gateway); + remoteBase = new Hr150(rfId, gateway); + break; case ("hr310"): - return new Hr310(rfId, gateway); + remoteBase = new Hr310(rfId, gateway); + break; default: return null; } + + // register the device when using an internal RF gateway + if (props.GatewayDeviceKey == "processor") + { + remoteBase.RegisterWithLogging(config.Key); + } + + return remoteBase; } static void gateway_BaseEvent(GenericBase device, BaseEventArgs args) @@ -249,4 +261,4 @@ namespace PepperDash.Essentials.Core trilist.BooleanInput[join].BoolValue = b; } } -} \ No newline at end of file +} From 80c98c60ca24d11bad1e85eb93328a527b7a8594 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:22:09 -0600 Subject: [PATCH 04/47] changed master -> main and added pull-request workflow --- .github/workflows/{master.yml => main.yml} | 0 .github/workflows/pull-request.yml | 266 +++++++++++++++++++++ 2 files changed, 266 insertions(+) rename .github/workflows/{master.yml => main.yml} (100%) create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/master.yml b/.github/workflows/main.yml similarity index 100% rename from .github/workflows/master.yml rename to .github/workflows/main.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 00000000..aad90bca --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,266 @@ +name: Pull Request Build Using Docker + +on: + pull_request: + branches: + - development + +env: + # solution path doesn't need slashes unless there it is multiple folders deep + # solution name does not include extension. .sln is assumed + SOLUTION_PATH: PepperDashEssentials + SOLUTION_FILE: PepperDashEssentials + # Do not edit this, we're just creating it here + VERSION: 0.0.0-buildtype-buildnumber + # Defaults to debug for build type + BUILD_TYPE: Debug + # Defaults to main as the release branch. Change as necessary + RELEASE_BRANCH: main +jobs: + Build_Project: + runs-on: windows-latest + steps: + # First we checkout the source repo + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 + # And any submodules + - name: Checkout submodules + shell: bash + run: | + git config --global url."https://github.com/".insteadOf "git@github.com:" + auth_header="$(git config --local --get http.https://github.com/.extraheader)" + git submodule sync --recursive + git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 + # Fetch all tags + - name: Fetch tags + run: git fetch --tags + # Generate the appropriate version number + - name: Set Version Number + shell: powershell + run: | + $version = ./.github/scripts/GenerateVersionNumber.ps1 + Write-Output "::set-env name=VERSION::$version" + # Use the version number to set the version of the assemblies + - name: Update AssemblyInfo.cs + shell: powershell + run: | + Write-Output ${{ env.VERSION }} + ./.github/scripts/UpdateAssemblyVersion.ps1 ${{ env.VERSION }} + # Login to Docker + - name: Login to Docker + uses: azure/docker-login@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + # Build the solutions in the docker image + - name: Build Solution + shell: powershell + run: | + Invoke-Expression "docker run --rm --mount type=bind,source=""$($Env:GITHUB_WORKSPACE)"",target=""c:/project"" pepperdash/sspbuilder c:\cihelpers\vsidebuild.exe -Solution ""c:\project\$($Env:SOLUTION_FILE).sln"" -BuildSolutionConfiguration $($ENV:BUILD_TYPE)" + # Zip up the output files as needed + - name: Zip Build Output + shell: powershell + run: ./.github/scripts/ZipBuildOutput.ps1 + # Write the version to a file to be consumed by the push jobs + - name: Write Version + run: Write-Output "$($Env:VERSION)" | Out-File -FilePath "$($Env:GITHUB_HOME)\output\version.txt" + # Upload the build output as an artifact + - name: Upload Build Output + uses: actions/upload-artifact@v1 + with: + name: Build + path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip + # Upload the Version file as an artifact + - name: Upload version.txt + uses: actions/upload-artifact@v1 + with: + name: Version + path: ${{env.GITHUB_HOME}}\output\version.txt + # Create the release on the source repo + - name: Create tag for non-rc builds + if: contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta') + run: | + git tag $($Env:VERSION) + git push --tags origin + - name: Create Release + id: create_release + # using contributor's version to allow for pointing at the right commit + if: contains(env.VERSION,'-rc-') || contains(env.VERSION,'-hotfix-') + uses: fleskesvor/create-release@feature/support-target-commitish + with: + tag_name: ${{ env.VERSION }} + release_name: ${{ env.VERSION }} + prerelease: ${{contains('debug', env.BUILD_TYPE)}} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Upload the build package to the release + - name: Upload Release Package + if: contains(env.VERSION,'-rc-') || contains(env.VERSION,'-hotfix-') + id: upload_release + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip + asset_name: ${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip + asset_content_type: application/zip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # This step always runs and pushes the build to the internal build rep + Internal_Push_Output: + needs: Build_Project + runs-on: windows-latest + steps: + - name: check Github ref + run: ${{toJson(github.ref)}} + # Checkout the repo + - name: Checkout Builds Repo + uses: actions/checkout@v2 + with: + token: ${{ secrets.BUILDS_TOKEN }} + repository: PepperDash-Engineering/essentials-builds + ref: ${{ Env.GITHUB_REF }} + # Download the version artifact from the build job + - name: Download Build Version Info + uses: actions/download-artifact@v1 + with: + name: Version + - name: Check Directory + run: Get-ChildItem "./" + # Set the version number environment variable from the file we just downloaded + - name: Set Version Number + shell: powershell + run: | + Get-ChildItem "./Version" + $version = Get-Content -Path ./Version/version.txt + Write-Host "Version: $version" + Write-Output "::set-env name=VERSION::$version" + Remove-Item -Path ./Version/version.txt + Remove-Item -Path ./Version + # Checkout/Create the branch + - name: Create new branch + run: git checkout -b $($Env:GITHUB_REF -replace "refs/heads/") + # Download the build output into the repo + - name: Download Build output + uses: actions/download-artifact@v1 + with: + name: Build + path: ./ + - name: Check directory + run: Get-ChildItem ./ + # Unzip the build package file + - name: Unzip Build file + run: | + Get-ChildItem .\*.zip | Expand-Archive -DestinationPath .\ + Remove-Item -Path .\*.zip + - name: Check directory again + run: Get-ChildItem ./ + # Copy Contents of output folder to root directory + - name: Copy Files to root & delete output directory + run: | + Remove-Item -Path .\* -Include @("*.cpz","*.md","*.cplz","*.json","*.dll","*.clz") + Get-ChildItem -Path .\output\* | Copy-Item -Destination .\ + Remove-Item -Path .\output -Recurse + # Commits the build output to the branch and tags it with the version + - name: Commit build output and tag the commit + shell: powershell + run: | + git config user.email "actions@pepperdash.com" + git config user.name "GitHub Actions" + git add . + $commit = "Build $($Env:GITHUB_RUN_NUMBER) from commit: https://github.com/$($Env:GITHUB_REPOSITORY)/commit/$($Env:GITHUB_SHA)" + Write-Host "Commit: $commit" + git commit -m $commit + git tag $($Env:VERSION) + # Push the commit + - name: Push to Builds Repo + shell: powershell + run: | + $branch = $($Env:GITHUB_REF) -replace "refs/heads/" + Write-Host "Branch: $branch" + git push -u origin $($branch) --force + # Push the tags + - name: Push tags + run: git push --tags origin + - name: Check Directory + run: Get-ChildItem ./ + # This step only runs if the branch is main or release/ runs and pushes the build to the public build repo + Public_Push_Output: + needs: Build_Project + runs-on: windows-latest + if: contains(github.ref, 'main') || contains(github.ref, '/release/') + steps: + # Checkout the repo + - name: check Github ref + run: ${{toJson(github.ref)}} + - name: Checkout Builds Repo + uses: actions/checkout@v2 + with: + token: ${{ secrets.BUILDS_TOKEN }} + repository: PepperDash/Essentials-Builds + ref: ${{ Env.GITHUB_REF }} + # Download the version artifact from the build job + - name: Download Build Version Info + uses: actions/download-artifact@v1 + with: + name: Version + - name: Check Directory + run: Get-ChildItem "./" + # Set the version number environment variable from the file we just downloaded + - name: Set Version Number + shell: powershell + run: | + Get-ChildItem "./Version" + $version = Get-Content -Path ./Version/version.txt + Write-Host "Version: $version" + Write-Output "::set-env name=VERSION::$version" + Remove-Item -Path ./Version/version.txt + Remove-Item -Path ./Version + # Checkout/Create the branch + - name: Create new branch + run: git checkout -b $($Env:GITHUB_REF -replace "refs/heads/") + # Download the build output into the repo + - name: Download Build output + uses: actions/download-artifact@v1 + with: + name: Build + path: ./ + - name: Check directory + run: Get-ChildItem ./ + # Unzip the build package file + - name: Unzip Build file + run: | + Get-ChildItem .\*.zip | Expand-Archive -DestinationPath .\ + Remove-Item -Path .\*.zip + - name: Check directory again + run: Get-ChildItem ./ + # Copy Contents of output folder to root directory + - name: Copy Files to root & delete output directory + run: | + Remove-Item -Path .\* -Include @("*.cpz","*.md","*.cplz","*.json","*.dll","*.clz") + Get-ChildItem -Path .\output\* | Copy-Item -Destination .\ + Remove-Item -Path .\output -Recurse + # Commits the build output to the branch and tags it with the version + - name: Commit build output and tag the commit + shell: powershell + run: | + git config user.email "actions@pepperdash.com" + git config user.name "GitHub Actions" + git add . + $commit = "Build $($Env:GITHUB_RUN_NUMBER) from commit: https://github.com/$($Env:GITHUB_REPOSITORY)/commit/$($Env:GITHUB_SHA)" + Write-Host "Commit: $commit" + git commit -m $commit + git tag $($Env:VERSION) + # Push the commit + - name: Push to Builds Repo + shell: powershell + run: | + $branch = $($Env:GITHUB_REF) -replace "refs/heads/" + Write-Host "Branch: $branch" + git push -u origin $($branch) --force + # Push the tags + - name: Push tags + run: git push --tags origin + - name: Check Directory + run: Get-ChildItem ./ From 91464d8ec15bcd505c83fe5fcd241c879c1e96f1 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:35:24 -0600 Subject: [PATCH 05/47] remove new workflow and add pull-request trigger to existing workflow --- .github/workflows/docker.yml | 3 + .github/workflows/pull-request.yml | 266 ----------------------------- 2 files changed, 3 insertions(+), 266 deletions(-) delete mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3eb3e42e..f823491b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -8,6 +8,9 @@ on: - bugfix/* - release/* - development + pull_request: + branches: + - development env: # solution path doesn't need slashes unless there it is multiple folders deep diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml deleted file mode 100644 index aad90bca..00000000 --- a/.github/workflows/pull-request.yml +++ /dev/null @@ -1,266 +0,0 @@ -name: Pull Request Build Using Docker - -on: - pull_request: - branches: - - development - -env: - # solution path doesn't need slashes unless there it is multiple folders deep - # solution name does not include extension. .sln is assumed - SOLUTION_PATH: PepperDashEssentials - SOLUTION_FILE: PepperDashEssentials - # Do not edit this, we're just creating it here - VERSION: 0.0.0-buildtype-buildnumber - # Defaults to debug for build type - BUILD_TYPE: Debug - # Defaults to main as the release branch. Change as necessary - RELEASE_BRANCH: main -jobs: - Build_Project: - runs-on: windows-latest - steps: - # First we checkout the source repo - - name: Checkout repo - uses: actions/checkout@v2 - with: - fetch-depth: 0 - # And any submodules - - name: Checkout submodules - shell: bash - run: | - git config --global url."https://github.com/".insteadOf "git@github.com:" - auth_header="$(git config --local --get http.https://github.com/.extraheader)" - git submodule sync --recursive - git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 - # Fetch all tags - - name: Fetch tags - run: git fetch --tags - # Generate the appropriate version number - - name: Set Version Number - shell: powershell - run: | - $version = ./.github/scripts/GenerateVersionNumber.ps1 - Write-Output "::set-env name=VERSION::$version" - # Use the version number to set the version of the assemblies - - name: Update AssemblyInfo.cs - shell: powershell - run: | - Write-Output ${{ env.VERSION }} - ./.github/scripts/UpdateAssemblyVersion.ps1 ${{ env.VERSION }} - # Login to Docker - - name: Login to Docker - uses: azure/docker-login@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - # Build the solutions in the docker image - - name: Build Solution - shell: powershell - run: | - Invoke-Expression "docker run --rm --mount type=bind,source=""$($Env:GITHUB_WORKSPACE)"",target=""c:/project"" pepperdash/sspbuilder c:\cihelpers\vsidebuild.exe -Solution ""c:\project\$($Env:SOLUTION_FILE).sln"" -BuildSolutionConfiguration $($ENV:BUILD_TYPE)" - # Zip up the output files as needed - - name: Zip Build Output - shell: powershell - run: ./.github/scripts/ZipBuildOutput.ps1 - # Write the version to a file to be consumed by the push jobs - - name: Write Version - run: Write-Output "$($Env:VERSION)" | Out-File -FilePath "$($Env:GITHUB_HOME)\output\version.txt" - # Upload the build output as an artifact - - name: Upload Build Output - uses: actions/upload-artifact@v1 - with: - name: Build - path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - # Upload the Version file as an artifact - - name: Upload version.txt - uses: actions/upload-artifact@v1 - with: - name: Version - path: ${{env.GITHUB_HOME}}\output\version.txt - # Create the release on the source repo - - name: Create tag for non-rc builds - if: contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta') - run: | - git tag $($Env:VERSION) - git push --tags origin - - name: Create Release - id: create_release - # using contributor's version to allow for pointing at the right commit - if: contains(env.VERSION,'-rc-') || contains(env.VERSION,'-hotfix-') - uses: fleskesvor/create-release@feature/support-target-commitish - with: - tag_name: ${{ env.VERSION }} - release_name: ${{ env.VERSION }} - prerelease: ${{contains('debug', env.BUILD_TYPE)}} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Upload the build package to the release - - name: Upload Release Package - if: contains(env.VERSION,'-rc-') || contains(env.VERSION,'-hotfix-') - id: upload_release - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - asset_name: ${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - asset_content_type: application/zip - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # This step always runs and pushes the build to the internal build rep - Internal_Push_Output: - needs: Build_Project - runs-on: windows-latest - steps: - - name: check Github ref - run: ${{toJson(github.ref)}} - # Checkout the repo - - name: Checkout Builds Repo - uses: actions/checkout@v2 - with: - token: ${{ secrets.BUILDS_TOKEN }} - repository: PepperDash-Engineering/essentials-builds - ref: ${{ Env.GITHUB_REF }} - # Download the version artifact from the build job - - name: Download Build Version Info - uses: actions/download-artifact@v1 - with: - name: Version - - name: Check Directory - run: Get-ChildItem "./" - # Set the version number environment variable from the file we just downloaded - - name: Set Version Number - shell: powershell - run: | - Get-ChildItem "./Version" - $version = Get-Content -Path ./Version/version.txt - Write-Host "Version: $version" - Write-Output "::set-env name=VERSION::$version" - Remove-Item -Path ./Version/version.txt - Remove-Item -Path ./Version - # Checkout/Create the branch - - name: Create new branch - run: git checkout -b $($Env:GITHUB_REF -replace "refs/heads/") - # Download the build output into the repo - - name: Download Build output - uses: actions/download-artifact@v1 - with: - name: Build - path: ./ - - name: Check directory - run: Get-ChildItem ./ - # Unzip the build package file - - name: Unzip Build file - run: | - Get-ChildItem .\*.zip | Expand-Archive -DestinationPath .\ - Remove-Item -Path .\*.zip - - name: Check directory again - run: Get-ChildItem ./ - # Copy Contents of output folder to root directory - - name: Copy Files to root & delete output directory - run: | - Remove-Item -Path .\* -Include @("*.cpz","*.md","*.cplz","*.json","*.dll","*.clz") - Get-ChildItem -Path .\output\* | Copy-Item -Destination .\ - Remove-Item -Path .\output -Recurse - # Commits the build output to the branch and tags it with the version - - name: Commit build output and tag the commit - shell: powershell - run: | - git config user.email "actions@pepperdash.com" - git config user.name "GitHub Actions" - git add . - $commit = "Build $($Env:GITHUB_RUN_NUMBER) from commit: https://github.com/$($Env:GITHUB_REPOSITORY)/commit/$($Env:GITHUB_SHA)" - Write-Host "Commit: $commit" - git commit -m $commit - git tag $($Env:VERSION) - # Push the commit - - name: Push to Builds Repo - shell: powershell - run: | - $branch = $($Env:GITHUB_REF) -replace "refs/heads/" - Write-Host "Branch: $branch" - git push -u origin $($branch) --force - # Push the tags - - name: Push tags - run: git push --tags origin - - name: Check Directory - run: Get-ChildItem ./ - # This step only runs if the branch is main or release/ runs and pushes the build to the public build repo - Public_Push_Output: - needs: Build_Project - runs-on: windows-latest - if: contains(github.ref, 'main') || contains(github.ref, '/release/') - steps: - # Checkout the repo - - name: check Github ref - run: ${{toJson(github.ref)}} - - name: Checkout Builds Repo - uses: actions/checkout@v2 - with: - token: ${{ secrets.BUILDS_TOKEN }} - repository: PepperDash/Essentials-Builds - ref: ${{ Env.GITHUB_REF }} - # Download the version artifact from the build job - - name: Download Build Version Info - uses: actions/download-artifact@v1 - with: - name: Version - - name: Check Directory - run: Get-ChildItem "./" - # Set the version number environment variable from the file we just downloaded - - name: Set Version Number - shell: powershell - run: | - Get-ChildItem "./Version" - $version = Get-Content -Path ./Version/version.txt - Write-Host "Version: $version" - Write-Output "::set-env name=VERSION::$version" - Remove-Item -Path ./Version/version.txt - Remove-Item -Path ./Version - # Checkout/Create the branch - - name: Create new branch - run: git checkout -b $($Env:GITHUB_REF -replace "refs/heads/") - # Download the build output into the repo - - name: Download Build output - uses: actions/download-artifact@v1 - with: - name: Build - path: ./ - - name: Check directory - run: Get-ChildItem ./ - # Unzip the build package file - - name: Unzip Build file - run: | - Get-ChildItem .\*.zip | Expand-Archive -DestinationPath .\ - Remove-Item -Path .\*.zip - - name: Check directory again - run: Get-ChildItem ./ - # Copy Contents of output folder to root directory - - name: Copy Files to root & delete output directory - run: | - Remove-Item -Path .\* -Include @("*.cpz","*.md","*.cplz","*.json","*.dll","*.clz") - Get-ChildItem -Path .\output\* | Copy-Item -Destination .\ - Remove-Item -Path .\output -Recurse - # Commits the build output to the branch and tags it with the version - - name: Commit build output and tag the commit - shell: powershell - run: | - git config user.email "actions@pepperdash.com" - git config user.name "GitHub Actions" - git add . - $commit = "Build $($Env:GITHUB_RUN_NUMBER) from commit: https://github.com/$($Env:GITHUB_REPOSITORY)/commit/$($Env:GITHUB_SHA)" - Write-Host "Commit: $commit" - git commit -m $commit - git tag $($Env:VERSION) - # Push the commit - - name: Push to Builds Repo - shell: powershell - run: | - $branch = $($Env:GITHUB_REF) -replace "refs/heads/" - Write-Host "Branch: $branch" - git push -u origin $($branch) --force - # Push the tags - - name: Push tags - run: git push --tags origin - - name: Check Directory - run: Get-ChildItem ./ From ea3cb6eb8054092881cd9b42e25d53776da6dda6 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:42:13 -0600 Subject: [PATCH 06/47] added check for GITHUB_REF --- .github/workflows/docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f823491b..1656a4c0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -47,6 +47,7 @@ jobs: - name: Set Version Number shell: powershell run: | + Write-Output ${{ env.GITHUB_REF }} $version = ./.github/scripts/GenerateVersionNumber.ps1 Write-Output "::set-env name=VERSION::$version" # Use the version number to set the version of the assemblies From 51f5d7e07bef77852824142a756fb70845443d1c Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:46:26 -0600 Subject: [PATCH 07/47] added print info step --- .github/workflows/docker.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1656a4c0..388c68d3 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -43,11 +43,12 @@ jobs: # Fetch all tags - name: Fetch tags run: git fetch --tags + - name: print Info + run: toJson(${{ github }}) # Generate the appropriate version number - name: Set Version Number shell: powershell run: | - Write-Output ${{ env.GITHUB_REF }} $version = ./.github/scripts/GenerateVersionNumber.ps1 Write-Output "::set-env name=VERSION::$version" # Use the version number to set the version of the assemblies From 48220b8fe97e0e9beea0b0bb8ea8157aa85633b6 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:47:57 -0600 Subject: [PATCH 08/47] fix expression syntax --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 388c68d3..3e6969b5 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -44,7 +44,7 @@ jobs: - name: Fetch tags run: git fetch --tags - name: print Info - run: toJson(${{ github }}) + run: toJson(github) # Generate the appropriate version number - name: Set Version Number shell: powershell From 44f6b465d4a51fd01b94171c5727c1f0d3afaaff Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:49:39 -0600 Subject: [PATCH 09/47] really fix expression syntax --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3e6969b5..3479055e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -44,7 +44,7 @@ jobs: - name: Fetch tags run: git fetch --tags - name: print Info - run: toJson(github) + run: ${{ toJson(github) }} # Generate the appropriate version number - name: Set Version Number shell: powershell From 67cdd8bfa6f14e6c4405b3ffffeae650d6c4cd1f Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:52:44 -0600 Subject: [PATCH 10/47] add print env step --- .github/workflows/docker.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3479055e..61034efc 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -43,8 +43,10 @@ jobs: # Fetch all tags - name: Fetch tags run: git fetch --tags - - name: print Info - run: ${{ toJson(github) }} + - name: print github info + run: ${{ github }} + - name: print env Info + run: ${{env}} # Generate the appropriate version number - name: Set Version Number shell: powershell From a03e6824c502ffa3c83a46e29dde0e00c175f5a1 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:55:05 -0600 Subject: [PATCH 11/47] trying to get environment variables --- .github/workflows/docker.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 61034efc..bcc4e5a0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -43,10 +43,8 @@ jobs: # Fetch all tags - name: Fetch tags run: git fetch --tags - - name: print github info - run: ${{ github }} - - name: print env Info - run: ${{env}} + - name: print env info + run: ${{ toJson(env) }} # Generate the appropriate version number - name: Set Version Number shell: powershell From 1f21b573e2c9ccff51d8c7a70e5961590c24420f Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 13:57:00 -0600 Subject: [PATCH 12/47] print GITHUB_REF --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index bcc4e5a0..706a6578 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -44,7 +44,7 @@ jobs: - name: Fetch tags run: git fetch --tags - name: print env info - run: ${{ toJson(env) }} + run: ${{ env.GITHUB_REF }} # Generate the appropriate version number - name: Set Version Number shell: powershell From 2e788d19177a2e7cbdd295e12869ece6ad621ccd Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:05:44 -0600 Subject: [PATCH 13/47] figuring out what ref to use --- .github/workflows/docker.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 706a6578..6bfe58d9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -44,7 +44,10 @@ jobs: - name: Fetch tags run: git fetch --tags - name: print env info - run: ${{ env.GITHUB_REF }} + run: | + ${{ env.GITHUB_REF }} + ${{ env.GITHUB_HEAD_REF }} + ${{ env.GITHUB_BASE_REF }} # Generate the appropriate version number - name: Set Version Number shell: powershell From 4d4230d9f40e719e2cb04a7ff9388e590a238ae9 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:13:43 -0600 Subject: [PATCH 14/47] getting all env variables --- .github/workflows/docker.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6bfe58d9..ba2f75f5 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -44,10 +44,7 @@ jobs: - name: Fetch tags run: git fetch --tags - name: print env info - run: | - ${{ env.GITHUB_REF }} - ${{ env.GITHUB_HEAD_REF }} - ${{ env.GITHUB_BASE_REF }} + run: ${{ env }} # Generate the appropriate version number - name: Set Version Number shell: powershell From 6b908e18de131ead66639ac1a52f46a613f4dc11 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:18:14 -0600 Subject: [PATCH 15/47] updating script for forked builds --- .github/scripts/GenerateVersionNumber.ps1 | 55 ++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/.github/scripts/GenerateVersionNumber.ps1 b/.github/scripts/GenerateVersionNumber.ps1 index 75a18d37..a0b35b69 100644 --- a/.github/scripts/GenerateVersionNumber.ps1 +++ b/.github/scripts/GenerateVersionNumber.ps1 @@ -17,31 +17,36 @@ Foreach ($version in $latestVersions) { $newVersion = [version]$latestVersion $phase = "" $newVersionString = "" -switch -regex ($Env:GITHUB_REF) { - '^refs\/heads\/main*.' { - $newVersionString = "{0}.{1}.{2}" -f $newVersion.Major, $newVersion.Minor, $newVersion.Build - } - '^refs\/heads\/feature\/*.' { - $phase = 'alpha' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER - } - '^refs\/heads\/release\/*.' { - $splitRef = $Env:GITHUB_REF -split "/" - $version = [version]($splitRef[-1] -replace "v", "") - $phase = 'rc' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $version.Major, $version.Minor, $version.Build, $phase, $Env:GITHUB_RUN_NUMBER - } - '^refs\/heads\/development*.' { - $phase = 'beta' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER - } - '^refs\/heads\/hotfix\/*.' { - $phase = 'hotfix' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER - } - '^refs\/heads\/bugfix\/*.' { - $phase = 'hotfix' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER +if(!$Env:GITHUB_REF) { + $phase = 'fork' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER +} else { + switch -regex ($Env:GITHUB_REF) { + '^refs\/heads\/main*.' { + $newVersionString = "{0}.{1}.{2}" -f $newVersion.Major, $newVersion.Minor, $newVersion.Build + } + '^refs\/heads\/feature\/*.' { + $phase = 'alpha' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/release\/*.' { + $splitRef = $Env:GITHUB_REF -split "/" + $version = [version]($splitRef[-1] -replace "v", "") + $phase = 'rc' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $version.Major, $version.Minor, $version.Build, $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/development*.' { + $phase = 'beta' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/hotfix\/*.' { + $phase = 'hotfix' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/bugfix\/*.' { + $phase = 'hotfix' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } } } From 5f04190e6aa237cf146955bfae21133790cce207 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:19:28 -0600 Subject: [PATCH 16/47] removed info print name --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ba2f75f5..738e6211 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -44,7 +44,7 @@ jobs: - name: Fetch tags run: git fetch --tags - name: print env info - run: ${{ env }} + run: ${{ toJson() }} # Generate the appropriate version number - name: Set Version Number shell: powershell From c7363c6434856a61e6c6014393965ccd1cad7308 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:20:36 -0600 Subject: [PATCH 17/47] removed print step --- .github/workflows/docker.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 738e6211..f823491b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -43,8 +43,6 @@ jobs: # Fetch all tags - name: Fetch tags run: git fetch --tags - - name: print env info - run: ${{ toJson() }} # Generate the appropriate version number - name: Set Version Number shell: powershell From 6160580f0817a03b8c75eb3fde1242e1f0c924ba Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:26:43 -0600 Subject: [PATCH 18/47] removed submodule checkout and moved it to checkout action --- .github/workflows/docker.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f823491b..315fbd67 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -32,14 +32,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - # And any submodules - - name: Checkout submodules - shell: bash - run: | - git config --global url."https://github.com/".insteadOf "git@github.com:" - auth_header="$(git config --local --get http.https://github.com/.extraheader)" - git submodule sync --recursive - git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 + submodules: true # Fetch all tags - name: Fetch tags run: git fetch --tags From 708d4c266e53f45688e590f639c6e6e20867b378 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:28:02 -0600 Subject: [PATCH 19/47] adding some print info back --- .github/workflows/docker.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 315fbd67..481045eb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,6 +36,10 @@ jobs: # Fetch all tags - name: Fetch tags run: git fetch --tags + - name: print info + run: | + ${{ toJson(github) }} + ${{ toJson(env) }} # Generate the appropriate version number - name: Set Version Number shell: powershell From acdff4ad670f6a329e7351eda30680e8bf1a8ff3 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:31:05 -0600 Subject: [PATCH 20/47] add string IsNullOrEmpty check --- .github/scripts/GenerateVersionNumber.ps1 | 2 +- .github/workflows/docker.yml | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/scripts/GenerateVersionNumber.ps1 b/.github/scripts/GenerateVersionNumber.ps1 index a0b35b69..78143388 100644 --- a/.github/scripts/GenerateVersionNumber.ps1 +++ b/.github/scripts/GenerateVersionNumber.ps1 @@ -17,7 +17,7 @@ Foreach ($version in $latestVersions) { $newVersion = [version]$latestVersion $phase = "" $newVersionString = "" -if(!$Env:GITHUB_REF) { +if([string]::IsNullOrEmpty($Env:GITHUB_REF)) { $phase = 'fork' $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER } else { diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 481045eb..315fbd67 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,10 +36,6 @@ jobs: # Fetch all tags - name: Fetch tags run: git fetch --tags - - name: print info - run: | - ${{ toJson(github) }} - ${{ toJson(env) }} # Generate the appropriate version number - name: Set Version Number shell: powershell From 83ca3ee3509fec28315da54e7c99b85f4cdf2c59 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:34:23 -0600 Subject: [PATCH 21/47] printing things in powershell --- .github/scripts/GenerateVersionNumber.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/scripts/GenerateVersionNumber.ps1 b/.github/scripts/GenerateVersionNumber.ps1 index 78143388..75897bf6 100644 --- a/.github/scripts/GenerateVersionNumber.ps1 +++ b/.github/scripts/GenerateVersionNumber.ps1 @@ -1,5 +1,8 @@ $latestVersions = $(git tag --merged origin/main) $latestVersion = [version]"0.0.0" +Write-Host "GITHUB_REF: $($Env:GITHUB_REF)" +Write-Host "GITHUB_HEAD_REF: $($Env:GITHUB_HEAD_REF)" +Write-Host "GITHUB_BASE_REF: $($Env:GITHUB_BASE_REF)" Foreach ($version in $latestVersions) { Write-Host $version try { From a26c951dbae8b69554284e8fd99ca28150eadd77 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 29 Jun 2020 14:47:54 -0600 Subject: [PATCH 22/47] add logic to add pr postfix for pr triggered builds --- .github/scripts/GenerateVersionNumber.ps1 | 62 ++++++++++++----------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/.github/scripts/GenerateVersionNumber.ps1 b/.github/scripts/GenerateVersionNumber.ps1 index 75897bf6..9cccbf43 100644 --- a/.github/scripts/GenerateVersionNumber.ps1 +++ b/.github/scripts/GenerateVersionNumber.ps1 @@ -20,37 +20,39 @@ Foreach ($version in $latestVersions) { $newVersion = [version]$latestVersion $phase = "" $newVersionString = "" -if([string]::IsNullOrEmpty($Env:GITHUB_REF)) { - $phase = 'fork' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER -} else { - switch -regex ($Env:GITHUB_REF) { - '^refs\/heads\/main*.' { - $newVersionString = "{0}.{1}.{2}" -f $newVersion.Major, $newVersion.Minor, $newVersion.Build - } - '^refs\/heads\/feature\/*.' { - $phase = 'alpha' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER - } - '^refs\/heads\/release\/*.' { - $splitRef = $Env:GITHUB_REF -split "/" - $version = [version]($splitRef[-1] -replace "v", "") - $phase = 'rc' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $version.Major, $version.Minor, $version.Build, $phase, $Env:GITHUB_RUN_NUMBER - } - '^refs\/heads\/development*.' { - $phase = 'beta' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER - } - '^refs\/heads\/hotfix\/*.' { - $phase = 'hotfix' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER - } - '^refs\/heads\/bugfix\/*.' { - $phase = 'hotfix' - $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER - } + +switch -regex ($Env:GITHUB_REF) { + '^refs\/pull\/*.' { + $splitRef = $Env:GITHUB_REF -split "/" + $phase = "pr$($splitRef[2])" + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER } + '^refs\/heads\/main*.' { + $newVersionString = "{0}.{1}.{2}" -f $newVersion.Major, $newVersion.Minor, $newVersion.Build + } + '^refs\/heads\/feature\/*.' { + $phase = 'alpha' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/release\/*.' { + $splitRef = $Env:GITHUB_REF -split "/" + $version = [version]($splitRef[-1] -replace "v", "") + $phase = 'rc' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $version.Major, $version.Minor, $version.Build, $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/development*.' { + $phase = 'beta' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/hotfix\/*.' { + $phase = 'hotfix' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/bugfix\/*.' { + $phase = 'hotfix' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + } From 5d1aa3b0247fd1ede554b0c6af4155884d7c7fbb Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Tue, 30 Jun 2020 11:01:46 -0500 Subject: [PATCH 23/47] Added a null check to determining SIP information Resolves #290 --- .../VideoCodec/CiscoCodec/CiscoSparkCodec.cs | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs index 05bd7b01..ffcffbac 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs @@ -1658,7 +1658,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco { get { - if (CodecStatus.Status.SIP.Registration.Count > 0) + if (CodecStatus.Status.SIP != null && CodecStatus.Status.SIP.Registration.Count > 0) { var match = Regex.Match(CodecStatus.Status.SIP.Registration[0].URI.Value, @"(\d+)"); // extract numbers only if (match.Success) @@ -1678,17 +1678,26 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco return string.Empty; } } - } - public override string SipUri - { - get - { - if (CodecStatus.Status.SIP.AlternateURI.Primary.URI.Value != null) - return CodecStatus.Status.SIP.AlternateURI.Primary.URI.Value; - else - return string.Empty; - } - } + } + + public override string SipUri + { + get + { + if (CodecStatus.Status.SIP != null && CodecStatus.Status.SIP.AlternateURI.Primary.URI.Value != null) + { + return CodecStatus.Status.SIP.AlternateURI.Primary.URI.Value; + } + else if (CodecStatus.Status.UserInterface != null && + CodecStatus.Status.UserInterface.ContactInfo.ContactMethod[0].Number.Value != null) + { + return CodecStatus.Status.UserInterface.ContactInfo.ContactMethod[0].Number.Value; + } + else + return string.Empty; + } + } + public override bool AutoAnswerEnabled { get From e1c93cc13a4e0142cca5bdc718d332bb60c04ea8 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Tue, 30 Jun 2020 12:03:48 -0500 Subject: [PATCH 24/47] Updates to correct 'hardware' references accidentally changed to 'sensor'. Updated SIMPLBridge example config to include GLS-PART-CN configuration Resolves #270 --- .../SIMPLBridgeExample_configurationFile.json | 17 + .../JoinMaps/GlsPartitionSensorJoinMap.cs | 130 +++ .../JoinMaps/JoinMapBase.cs | 958 +++++++++--------- .../PepperDash_Essentials_Core.csproj | 1 + .../Essentials Devices Common.csproj | 2 + .../GlsPartitionSensorController.cs | 257 +++++ .../GlsPartitionSensorControllerFactory.cs | 39 + 7 files changed, 925 insertions(+), 479 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/GlsPartitionSensorJoinMap.cs create mode 100644 essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs create mode 100644 essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs diff --git a/PepperDashEssentials/Example Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json b/PepperDashEssentials/Example Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json index 3fb02ce8..f66add0c 100644 --- a/PepperDashEssentials/Example Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json +++ b/PepperDashEssentials/Example Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json @@ -175,6 +175,10 @@ { "deviceKey": "gls-odt-1", "joinStart": 2751 + }, + { + "deviceKey": "gls-part-1", + "joinStart": 2781 } ] } @@ -427,6 +431,19 @@ "method": "cresnet" } } + }, + { + "key": "gls-part-1", + "uid": 19, + "name": "GLS-PART-CN 1", + "type": "glspartcn", + "group": "partition", + "properties": { + "control": { + "cresnetId": "90", + "method": "cresnet" + } + } } ], "rooms": [], diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/GlsPartitionSensorJoinMap.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/GlsPartitionSensorJoinMap.cs new file mode 100644 index 00000000..cc554790 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/GlsPartitionSensorJoinMap.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using PepperDash.Essentials.Core; + +namespace PepperDash_Essentials_Core.Bridges.JoinMaps +{ + public class GlsPartitionSensorJoinMap : JoinMapBaseAdvanced + { + [JoinName("IsOnline")] + public JoinDataComplete IsOnline = new JoinDataComplete( + new JoinData() + { + JoinNumber = 1, + JoinSpan = 1 + }, + new JoinMetadata() + { + Description = "Sensor Is Online", + JoinCapabilities = eJoinCapabilities.ToSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("Name")] + public JoinDataComplete Name = new JoinDataComplete( + new JoinData() + { + JoinNumber = 1, + JoinSpan = 1 + }, + new JoinMetadata() + { + Description = "Sensor Name", + JoinCapabilities = eJoinCapabilities.ToSIMPL, + JoinType = eJoinType.Serial + }); + + [JoinName("Enable")] + public JoinDataComplete Enable = new JoinDataComplete( + new JoinData() + { + JoinNumber = 2, + JoinSpan = 1 + }, + new JoinMetadata() + { + Description = "Sensor Enable", + JoinCapabilities = eJoinCapabilities.ToFromSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("PartitionSensed")] + public JoinDataComplete PartitionSensed = new JoinDataComplete( + new JoinData() + { + JoinNumber = 3, + JoinSpan = 1 + }, + new JoinMetadata() + { + Description = "Sensor Partition Sensed", + JoinCapabilities = eJoinCapabilities.ToSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("PartitionNotSensed")] + public JoinDataComplete PartitionNotSensed = new JoinDataComplete( + new JoinData() + { + JoinNumber = 4, + JoinSpan = 1 + }, + new JoinMetadata() + { + Description = "Sensor Partition Not Sensed", + JoinCapabilities = eJoinCapabilities.ToSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("IncreaseSensitivity")] + public JoinDataComplete IncreaseSensitivity = new JoinDataComplete( + new JoinData() + { + JoinNumber = 6, + JoinSpan = 1 + }, + new JoinMetadata() + { + Description = "Sensor Increase Sensitivity", + JoinCapabilities = eJoinCapabilities.FromSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("DecreaseSensitivity")] + public JoinDataComplete DecreaseSensitivity = new JoinDataComplete( + new JoinData() + { + JoinNumber = 7, + JoinSpan = 1 + }, + new JoinMetadata() + { + Description = "Sensor Decrease Sensitivity", + JoinCapabilities = eJoinCapabilities.FromSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("Sensitivity")] + public JoinDataComplete Sensitivity = new JoinDataComplete( + new JoinData() + { + JoinNumber = 2, + JoinSpan = 1 + }, + new JoinMetadata() + { + Description = "Sensor Sensitivity", + JoinCapabilities = eJoinCapabilities.ToFromSIMPL, + JoinType = eJoinType.Analog + }); + + public GlsPartitionSensorJoinMap(uint joinStart) + : base(joinStart, typeof (GlsPartitionSensorJoinMap)) + { + + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs index 676299e5..ba6b3482 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs @@ -1,488 +1,488 @@ -using System; -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using Crestron.SimplSharp.Reflection; - -using PepperDash.Core; -using PepperDash.Essentials.Core.Config; - -using Newtonsoft.Json; - -namespace PepperDash.Essentials.Core -{ - public static class JoinMapHelper - { - /// - /// Attempts to get the serialized join map from config - /// - /// - /// - public static string GetSerializedJoinMapForDevice(string joinMapKey) - { - if (string.IsNullOrEmpty(joinMapKey)) - return null; - - var joinMap = ConfigReader.ConfigObject.JoinMaps[joinMapKey]; - - return joinMap; - } - - /// - /// Attempts to get the serialized join map from config - /// - /// - /// - public static string GetJoinMapForDevice(string joinMapKey) - { - return GetSerializedJoinMapForDevice(joinMapKey); - } - - /// - /// Attempts to find a custom join map by key and returns it deserialized if found - /// - /// - /// - public static Dictionary TryGetJoinMapAdvancedForDevice(string joinMapKey) - { - if (string.IsNullOrEmpty(joinMapKey)) - return null; - - var joinMapSerialzed = ConfigReader.ConfigObject.JoinMaps[joinMapKey]; - - if (joinMapSerialzed == null) return null; - - var joinMapData = JsonConvert.DeserializeObject>(joinMapSerialzed); - - return joinMapData; - } - - } - - /// - /// Base class for join maps - /// - [Obsolete("This is being deprecated in favor of JoinMapBaseAdvanced")] - public abstract class JoinMapBase - { - /// - /// Modifies all the join numbers by adding the offset. This should never be called twice - /// - /// - public abstract void OffsetJoinNumbers(uint joinStart); - - /// - /// The collection of joins and associated metadata - /// - public Dictionary Joins = new Dictionary(); - - /// - /// Prints the join information to console - /// - public void PrintJoinMapInfo() - { - Debug.Console(0, "{0}:\n", GetType().Name); - - // Get the joins of each type and print them - Debug.Console(0, "Digitals:"); - var digitals = Joins.Where(j => (j.Value.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Digital Joins", digitals.Count); - PrintJoinList(GetSortedJoins(digitals)); - - Debug.Console(0, "Analogs:"); - var analogs = Joins.Where(j => (j.Value.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Analog Joins", analogs.Count); - PrintJoinList(GetSortedJoins(analogs)); - - Debug.Console(0, "Serials:"); - var serials = Joins.Where(j => (j.Value.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Serial Joins", serials.Count); - PrintJoinList(GetSortedJoins(serials)); - - } - - /// - /// Returns a sorted list by JoinNumber - /// - /// - /// - List> GetSortedJoins(Dictionary joins) - { - var sortedJoins = joins.ToList(); - - sortedJoins.Sort((pair1, pair2) => pair1.Value.JoinNumber.CompareTo(pair2.Value.JoinNumber)); - - return sortedJoins; - } - - void PrintJoinList(List> joins) - { - foreach (var join in joins) - { - Debug.Console(0, - @"Join Number: {0} | Label: '{1}' | JoinSpan: '{2}' | Type: '{3}' | Capabilities: '{4}'", - join.Value.JoinNumber, - join.Value.Label, - join.Value.JoinSpan, - join.Value.JoinType.ToString(), - join.Value.JoinCapabilities.ToString()); - } - } - - /// - /// Returns the join number for the join with the specified key - /// - /// - /// - public uint GetJoinForKey(string key) - { - return Joins.ContainsKey(key) ? Joins[key].JoinNumber : 0; - } - - /// - /// Returns the join span for the join with the specified key - /// - /// - /// - public uint GetJoinSpanForKey(string key) - { - return Joins.ContainsKey(key) ? Joins[key].JoinSpan : 0; - } - } - - /// - /// Base class for join maps - /// - public abstract class JoinMapBaseAdvanced - { - protected uint JoinOffset; - - /// - /// The collection of joins and associated metadata - /// - public Dictionary Joins { get; private set; } - - protected JoinMapBaseAdvanced(uint joinStart) - { - Joins = new Dictionary(); - - JoinOffset = joinStart - 1; - } - - protected JoinMapBaseAdvanced(uint joinStart, Type type):this(joinStart) - { - AddJoins(type); - } - - protected void AddJoins(Type type) - { - // Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset - //Joins = this.GetType() - // .GetCType() - // .GetFields(BindingFlags.Public | BindingFlags.Instance) - // .Where(field => field.IsDefined(typeof(JoinNameAttribute), true)) - // .Select(field => (JoinDataComplete)field.GetValue(this)) - // .ToDictionary(join => join.GetNameAttribute(), join => - // { - // join.SetJoinOffset(_joinOffset); - // return join; - // }); - - //type = this.GetType(); <- this wasn't working because 'this' was always the base class, never the derived class - var fields = - type.GetCType() - .GetFields(BindingFlags.Public | BindingFlags.Instance) - .Where(f => f.IsDefined(typeof (JoinNameAttribute), true)); - - foreach (var field in fields) - { - var childClass = Convert.ChangeType(this, type, null); - - var value = field.GetValue(childClass) as JoinDataComplete; //this here is JoinMapBaseAdvanced, not the child class. JoinMapBaseAdvanced has no fields. - - if (value == null) - { - Debug.Console(0, "Unable to caset base class to {0}", type.Name); - continue; - } - - value.SetJoinOffset(JoinOffset); - - var joinName = value.GetNameAttribute(field); - - if (String.IsNullOrEmpty(joinName)) continue; - - Joins.Add(joinName, value); - } - - - PrintJoinMapInfo(); - } - - /// - /// Prints the join information to console - /// - public void PrintJoinMapInfo() - { - Debug.Console(0, "{0}:\n", GetType().Name); - - // Get the joins of each type and print them - Debug.Console(0, "Digitals:"); - var digitals = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Digital Joins", digitals.Count); - PrintJoinList(GetSortedJoins(digitals)); - - Debug.Console(0, "Analogs:"); - var analogs = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Analog Joins", analogs.Count); - PrintJoinList(GetSortedJoins(analogs)); - - Debug.Console(0, "Serials:"); - var serials = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Serial Joins", serials.Count); - PrintJoinList(GetSortedJoins(serials)); - - } - - /// - /// Returns a sorted list by JoinNumber - /// - /// - /// - List> GetSortedJoins(Dictionary joins) - { - var sortedJoins = joins.ToList(); - - sortedJoins.Sort((pair1, pair2) => pair1.Value.JoinNumber.CompareTo(pair2.Value.JoinNumber)); - - return sortedJoins; - } - - void PrintJoinList(List> joins) - { - foreach (var join in joins) - { - Debug.Console(0, - @"Join Number: {0} | JoinSpan: '{1}' | Label: '{2}' | Type: '{3}' | Capabilities: '{4}'", - join.Value.JoinNumber, - join.Value.JoinSpan, - join.Value.Metadata.Label, - join.Value.Metadata.JoinType.ToString(), - join.Value.Metadata.JoinCapabilities.ToString()); - } - } - - /// - /// Attempts to find the matching key for the custom join and if found overwrites the default JoinData with the custom - /// - /// - public void SetCustomJoinData(Dictionary joinData) - { - foreach (var customJoinData in joinData) - { - var join = Joins[customJoinData.Key]; - - if (join != null) - { - join.SetCustomJoinData(customJoinData.Value); - } - else - { - Debug.Console(2, "No mathcing key found in join map for: '{0}'", customJoinData.Key); - } - } - - PrintJoinMapInfo(); - } - - ///// - ///// Returns the join number for the join with the specified key - ///// - ///// - ///// - //public uint GetJoinForKey(string key) - //{ - // return Joins.ContainsKey(key) ? Joins[key].JoinNumber : 0; - //} - - - ///// - ///// Returns the join span for the join with the specified key - ///// - ///// - ///// - //public uint GetJoinSpanForKey(string key) - //{ - // return Joins.ContainsKey(key) ? Joins[key].JoinSpan : 0; - //} - } - - /// - /// Read = Provides feedback to SIMPL - /// Write = Responds to sig values from SIMPL - /// - [Flags] - public enum eJoinCapabilities - { - None = 0, - ToSIMPL = 1, - FromSIMPL = 2, - ToFromSIMPL = ToSIMPL | FromSIMPL - } - - [Flags] - public enum eJoinType - { - None = 0, - Digital = 1, - Analog = 2, - Serial = 4, - DigitalAnalog = Digital | Analog, - DigitalSerial = Digital | Serial, - AnalogSerial = Analog | Serial, - DigitalAnalogSerial = Digital | Analog | Serial - } - - /// - /// Metadata describing the join - /// - public class JoinMetadata +using Crestron.SimplSharp.Reflection; + +using PepperDash.Core; +using PepperDash.Essentials.Core.Config; + +using Newtonsoft.Json; + +namespace PepperDash.Essentials.Core +{ + public static class JoinMapHelper { - private string _description; - - /// - /// Join number (based on join offset value) - /// - [JsonProperty("joinNumber")] - [Obsolete] - public uint JoinNumber { get; set; } - /// - /// Join range span. If join indicates the start of a range of joins, this indicated the maximum number of joins in the range - /// - [Obsolete] - [JsonProperty("joinSpan")] - public uint JoinSpan { get; set; } - - /// - /// A label for the join to better describe its usage - /// - [Obsolete("Use Description instead")] - [JsonProperty("label")] - public string Label { get { return _description; } set { _description = value; } } - /// - /// A description for the join to better describe its usage - /// - [JsonProperty("description")] - public string Description { get { return _description; } set { _description = value; } } - /// - /// Signal type(s) - /// - [JsonProperty("joinType")] - public eJoinType JoinType { get; set; } - /// - /// Indicates whether the join is read and/or write - /// - [JsonProperty("joinCapabilities")] - public eJoinCapabilities JoinCapabilities { get; set; } - /// - /// Indicates a set of valid values (particularly if this translates to an enum - /// - [JsonProperty("validValues")] - public string[] ValidValues { get; set; } - - } - - /// - /// Data describing the join. Can be - /// - public class JoinData - { - /// - /// Join number (based on join offset value) - /// - [JsonProperty("joinNumber")] - public uint JoinNumber { get; set; } - /// - /// Join range span. If join indicates the start of a range of joins, this indicated the maximum number of joins in the range - /// - [JsonProperty("joinSpan")] - public uint JoinSpan { get; set; } - } - - /// - /// A class to aggregate the JoinData and JoinMetadata for a join - /// - public class JoinDataComplete - { - private uint _joinOffset; - - private JoinData _data; - public JoinMetadata Metadata { get; set; } - - public JoinDataComplete(JoinData data, JoinMetadata metadata) - { - _data = data; - Metadata = metadata; - } - - /// - /// Sets the join offset value - /// - /// - public void SetJoinOffset(uint joinOffset) - { - _joinOffset = joinOffset; - } - - /// - /// The join number (including the offset) - /// - public uint JoinNumber - { - get { return _data.JoinNumber+ _joinOffset; } - set { _data.JoinNumber = value; } - } - - public uint JoinSpan - { - get { return _data.JoinSpan; } - } - - public void SetCustomJoinData(JoinData customJoinData) - { - _data = customJoinData; - } - - public string GetNameAttribute(MemberInfo memberInfo) - { - var name = string.Empty; - var attribute = (JoinNameAttribute)CAttribute.GetCustomAttribute(memberInfo, typeof(JoinNameAttribute)); - - if (attribute == null) return name; - - name = attribute.Name; - Debug.Console(2, "JoinName Attribute value: {0}", name); - return name; + /// Attempts to get the serialized join map from config + /// + /// + /// + public static string GetSerializedJoinMapForDevice(string joinMapKey) + { + if (string.IsNullOrEmpty(joinMapKey)) + return null; + + var joinMap = ConfigReader.ConfigObject.JoinMaps[joinMapKey]; + + return joinMap; + } + + /// + /// Attempts to get the serialized join map from config + /// + /// + /// + public static string GetJoinMapForDevice(string joinMapKey) + { + return GetSerializedJoinMapForDevice(joinMapKey); + } + + /// + /// Attempts to find a custom join map by key and returns it deserialized if found + /// + /// + /// + public static Dictionary TryGetJoinMapAdvancedForDevice(string joinMapKey) + { + if (string.IsNullOrEmpty(joinMapKey)) + return null; + + var joinMapSerialzed = ConfigReader.ConfigObject.JoinMaps[joinMapKey]; + + if (joinMapSerialzed == null) return null; + + var joinMapData = JsonConvert.DeserializeObject>(joinMapSerialzed); + + return joinMapData; + } + + } + + /// + /// Base class for join maps + /// + [Obsolete("This is being deprecated in favor of JoinMapBaseAdvanced")] + public abstract class JoinMapBase + { + /// + /// Modifies all the join numbers by adding the offset. This should never be called twice + /// + /// + public abstract void OffsetJoinNumbers(uint joinStart); + + /// + /// The collection of joins and associated metadata + /// + public Dictionary Joins = new Dictionary(); + + /// + /// Prints the join information to console + /// + public void PrintJoinMapInfo() + { + Debug.Console(0, "{0}:\n", GetType().Name); + + // Get the joins of each type and print them + Debug.Console(0, "Digitals:"); + var digitals = Joins.Where(j => (j.Value.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value); + Debug.Console(2, "Found {0} Digital Joins", digitals.Count); + PrintJoinList(GetSortedJoins(digitals)); + + Debug.Console(0, "Analogs:"); + var analogs = Joins.Where(j => (j.Value.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value); + Debug.Console(2, "Found {0} Analog Joins", analogs.Count); + PrintJoinList(GetSortedJoins(analogs)); + + Debug.Console(0, "Serials:"); + var serials = Joins.Where(j => (j.Value.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value); + Debug.Console(2, "Found {0} Serial Joins", serials.Count); + PrintJoinList(GetSortedJoins(serials)); + + } + + /// + /// Returns a sorted list by JoinNumber + /// + /// + /// + List> GetSortedJoins(Dictionary joins) + { + var sortedJoins = joins.ToList(); + + sortedJoins.Sort((pair1, pair2) => pair1.Value.JoinNumber.CompareTo(pair2.Value.JoinNumber)); + + return sortedJoins; + } + + void PrintJoinList(List> joins) + { + foreach (var join in joins) + { + Debug.Console(0, + @"Join Number: {0} | Label: '{1}' | JoinSpan: '{2}' | Type: '{3}' | Capabilities: '{4}'", + join.Value.JoinNumber, + join.Value.Label, + join.Value.JoinSpan, + join.Value.JoinType.ToString(), + join.Value.JoinCapabilities.ToString()); + } + } + + /// + /// Returns the join number for the join with the specified key + /// + /// + /// + public uint GetJoinForKey(string key) + { + return Joins.ContainsKey(key) ? Joins[key].JoinNumber : 0; + } + + /// + /// Returns the join span for the join with the specified key + /// + /// + /// + public uint GetJoinSpanForKey(string key) + { + return Joins.ContainsKey(key) ? Joins[key].JoinSpan : 0; } } - - - [AttributeUsage(AttributeTargets.All)] - public class JoinNameAttribute : CAttribute - { - private string _Name; - - public JoinNameAttribute(string name) - { - Debug.Console(2, "Setting Attribute Name: {0}", name); - _Name = name; - } - - public string Name - { - get { return _Name; } - } + /// + /// Base class for join maps + /// + public abstract class JoinMapBaseAdvanced + { + protected uint JoinOffset; + + /// + /// The collection of joins and associated metadata + /// + public Dictionary Joins { get; private set; } + + protected JoinMapBaseAdvanced(uint joinStart) + { + Joins = new Dictionary(); + + JoinOffset = joinStart - 1; + } + + protected JoinMapBaseAdvanced(uint joinStart, Type type):this(joinStart) + { + AddJoins(type); + } + + protected void AddJoins(Type type) + { + // Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset + //Joins = this.GetType() + // .GetCType() + // .GetFields(BindingFlags.Public | BindingFlags.Instance) + // .Where(field => field.IsDefined(typeof(JoinNameAttribute), true)) + // .Select(field => (JoinDataComplete)field.GetValue(this)) + // .ToDictionary(join => join.GetNameAttribute(), join => + // { + // join.SetJoinOffset(_joinOffset); + // return join; + // }); + + //type = this.GetType(); <- this wasn't working because 'this' was always the base class, never the derived class + var fields = + type.GetCType() + .GetFields(BindingFlags.Public | BindingFlags.Instance) + .Where(f => f.IsDefined(typeof (JoinNameAttribute), true)); + + foreach (var field in fields) + { + var childClass = Convert.ChangeType(this, type, null); + + var value = field.GetValue(childClass) as JoinDataComplete; //this here is JoinMapBaseAdvanced, not the child class. JoinMapBaseAdvanced has no fields. + + if (value == null) + { + Debug.Console(0, "Unable to caset base class to {0}", type.Name); + continue; + } + + value.SetJoinOffset(JoinOffset); + + var joinName = value.GetNameAttribute(field); + + if (String.IsNullOrEmpty(joinName)) continue; + + Joins.Add(joinName, value); + } + + + PrintJoinMapInfo(); + } + + /// + /// Prints the join information to console + /// + public void PrintJoinMapInfo() + { + Debug.Console(0, "{0}:\n", GetType().Name); + + // Get the joins of each type and print them + Debug.Console(0, "Digitals:"); + var digitals = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value); + Debug.Console(2, "Found {0} Digital Joins", digitals.Count); + PrintJoinList(GetSortedJoins(digitals)); + + Debug.Console(0, "Analogs:"); + var analogs = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value); + Debug.Console(2, "Found {0} Analog Joins", analogs.Count); + PrintJoinList(GetSortedJoins(analogs)); + + Debug.Console(0, "Serials:"); + var serials = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value); + Debug.Console(2, "Found {0} Serial Joins", serials.Count); + PrintJoinList(GetSortedJoins(serials)); + + } + + /// + /// Returns a sorted list by JoinNumber + /// + /// + /// + List> GetSortedJoins(Dictionary joins) + { + var sortedJoins = joins.ToList(); + + sortedJoins.Sort((pair1, pair2) => pair1.Value.JoinNumber.CompareTo(pair2.Value.JoinNumber)); + + return sortedJoins; + } + + void PrintJoinList(List> joins) + { + foreach (var join in joins) + { + Debug.Console(0, + @"Join Number: {0} | JoinSpan: '{1}' | Label: '{2}' | Type: '{3}' | Capabilities: '{4}'", + join.Value.JoinNumber, + join.Value.JoinSpan, + join.Value.Metadata.Label, + join.Value.Metadata.JoinType.ToString(), + join.Value.Metadata.JoinCapabilities.ToString()); + } + } + + /// + /// Attempts to find the matching key for the custom join and if found overwrites the default JoinData with the custom + /// + /// + public void SetCustomJoinData(Dictionary joinData) + { + foreach (var customJoinData in joinData) + { + var join = Joins[customJoinData.Key]; + + if (join != null) + { + join.SetCustomJoinData(customJoinData.Value); + } + else + { + Debug.Console(2, "No mathcing key found in join map for: '{0}'", customJoinData.Key); + } + } + + PrintJoinMapInfo(); + } + + ///// + ///// Returns the join number for the join with the specified key + ///// + ///// + ///// + //public uint GetJoinForKey(string key) + //{ + // return Joins.ContainsKey(key) ? Joins[key].JoinNumber : 0; + //} + + + ///// + ///// Returns the join span for the join with the specified key + ///// + ///// + ///// + //public uint GetJoinSpanForKey(string key) + //{ + // return Joins.ContainsKey(key) ? Joins[key].JoinSpan : 0; + //} + } + + /// + /// Read = Provides feedback to SIMPL + /// Write = Responds to sig values from SIMPL + /// + [Flags] + public enum eJoinCapabilities + { + None = 0, + ToSIMPL = 1, + FromSIMPL = 2, + ToFromSIMPL = ToSIMPL | FromSIMPL + } + + [Flags] + public enum eJoinType + { + None = 0, + Digital = 1, + Analog = 2, + Serial = 4, + DigitalAnalog = Digital | Analog, + DigitalSerial = Digital | Serial, + AnalogSerial = Analog | Serial, + DigitalAnalogSerial = Digital | Analog | Serial + } + + /// + /// Metadata describing the join + /// + public class JoinMetadata + { + private string _description; + + /// + /// Join number (based on join offset value) + /// + [JsonProperty("joinNumber")] + [Obsolete] + public uint JoinNumber { get; set; } + /// + /// Join range span. If join indicates the start of a range of joins, this indicated the maximum number of joins in the range + /// + [Obsolete] + [JsonProperty("joinSpan")] + public uint JoinSpan { get; set; } + + /// + /// A label for the join to better describe its usage + /// + [Obsolete("Use Description instead")] + [JsonProperty("label")] + public string Label { get { return _description; } set { _description = value; } } + + /// + /// A description for the join to better describe its usage + /// + [JsonProperty("description")] + public string Description { get { return _description; } set { _description = value; } } + /// + /// Signal type(s) + /// + [JsonProperty("joinType")] + public eJoinType JoinType { get; set; } + /// + /// Indicates whether the join is read and/or write + /// + [JsonProperty("joinCapabilities")] + public eJoinCapabilities JoinCapabilities { get; set; } + /// + /// Indicates a set of valid values (particularly if this translates to an enum + /// + [JsonProperty("validValues")] + public string[] ValidValues { get; set; } + + } + + /// + /// Data describing the join. Can be + /// + public class JoinData + { + /// + /// Join number (based on join offset value) + /// + [JsonProperty("joinNumber")] + public uint JoinNumber { get; set; } + /// + /// Join range span. If join indicates the start of a range of joins, this indicated the maximum number of joins in the range + /// + [JsonProperty("joinSpan")] + public uint JoinSpan { get; set; } + } + + /// + /// A class to aggregate the JoinData and JoinMetadata for a join + /// + public class JoinDataComplete + { + private uint _joinOffset; + + private JoinData _data; + public JoinMetadata Metadata { get; set; } + + public JoinDataComplete(JoinData data, JoinMetadata metadata) + { + _data = data; + Metadata = metadata; + } + + /// + /// Sets the join offset value + /// + /// + public void SetJoinOffset(uint joinOffset) + { + _joinOffset = joinOffset; + } + + /// + /// The join number (including the offset) + /// + public uint JoinNumber + { + get { return _data.JoinNumber+ _joinOffset; } + set { _data.JoinNumber = value; } + } + + public uint JoinSpan + { + get { return _data.JoinSpan; } + } + + public void SetCustomJoinData(JoinData customJoinData) + { + _data = customJoinData; + } + + public string GetNameAttribute(MemberInfo memberInfo) + { + var name = string.Empty; + var attribute = (JoinNameAttribute)CAttribute.GetCustomAttribute(memberInfo, typeof(JoinNameAttribute)); + + if (attribute == null) return name; + + name = attribute.Name; + Debug.Console(2, "JoinName Attribute value: {0}", name); + return name; + } + } + + + + [AttributeUsage(AttributeTargets.All)] + public class JoinNameAttribute : CAttribute + { + private string _Name; + + public JoinNameAttribute(string name) + { + Debug.Console(2, "Setting Attribute Name: {0}", name); + _Name = name; + } + + public string Name + { + get { return _Name; } + } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 55a157b4..f4eeabe5 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -137,6 +137,7 @@ + diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj index ba12a129..78a6e565 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj @@ -116,6 +116,8 @@ + + diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs new file mode 100644 index 00000000..256b2496 --- /dev/null +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro.DeviceSupport; +using Crestron.SimplSharpPro.GeneralIO; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.Core.Bridges; +using PepperDash_Essentials_Core.Bridges.JoinMaps; + +namespace PepperDash.Essentials.Devices.Common.PartitionSensor +{ + [Description("Wrapper class for GLS Cresnet Partition Sensor")] + public class GlsPartitionSensorController : CrestronGenericBridgeableBaseDevice + { + public GlsPartCn PartitionSensor { get; private set; } + + public StringFeedback NameFeedback { get; private set; } + + public BoolFeedback EnableFeedback { get; private set; } + + public BoolFeedback PartitionSensedFeedback { get; private set; } + public BoolFeedback PartitionNotSensedFeedback { get; private set; } + + public IntFeedback SensitivityFeedback { get; private set; } + + public bool InTestMode { get; private set; } + public bool TestEnableFeedback { get; private set; } + public bool TestPartitionSensedFeedback { get; private set; } + public int TestSensitivityFeedback { get; private set; } + + public Func NameFeedbackFunc + { + get { return () => Name; } + } + + public Func EnableFeedbackFunc + { + get { return () => InTestMode ? TestEnableFeedback : PartitionSensor.EnableFeedback.BoolValue; } + } + + public Func PartitionSensedFeedbackFunc + { + get { return () => InTestMode ? TestPartitionSensedFeedback : PartitionSensor.PartitionSensedFeedback.BoolValue; } + } + + public Func PartitionNotSensedFeedbackFunc + { + get { return () => InTestMode ? TestPartitionSensedFeedback : PartitionSensor.PartitionNotSensedFeedback.BoolValue; } + } + + public Func SensitivityFeedbackFunc + { + get { return () => InTestMode ? TestSensitivityFeedback : PartitionSensor.SensitivityFeedback.UShortValue; } + } + + /// + /// Constructor + /// + /// + /// + /// + public GlsPartitionSensorController(string key, string name, GlsPartCn hardware) + : base(key, name, hardware) + { + PartitionSensor = hardware; + + NameFeedback = new StringFeedback(NameFeedbackFunc); + EnableFeedback = new BoolFeedback(EnableFeedbackFunc); + PartitionSensedFeedback = new BoolFeedback(PartitionSensedFeedbackFunc); + PartitionNotSensedFeedback = new BoolFeedback(PartitionNotSensedFeedbackFunc); + SensitivityFeedback = new IntFeedback(SensitivityFeedbackFunc); + + if (PartitionSensor != null) PartitionSensor.BaseEvent += PartitionSensor_BaseEvent; + } + + + private void PartitionSensor_BaseEvent(GenericBase device, BaseEventArgs args) + { + Debug.Console(2, this, "EventId: {0}, Index: {1}", args.EventId, args.Index); + + switch (args.EventId) + { + case (GlsPartCn.EnableFeedbackEventId): + { + EnableFeedback.FireUpdate(); + break; + } + case (GlsPartCn.PartitionSensedFeedbackEventId): + { + PartitionSensedFeedback.FireUpdate(); + break; + } + case (GlsPartCn.PartitionNotSensedFeedbackEventId): + { + PartitionNotSensedFeedback.FireUpdate(); + break; + } + case (GlsPartCn.SensitivityFeedbackEventId): + { + SensitivityFeedback.FireUpdate(); + break; + } + default: + { + Debug.Console(2, this, "args.EventId: {0}", args.EventId); + break; + } + } + } + + public void SetTestMode(bool mode) + { + InTestMode = mode; + Debug.Console(1, this, "InTestMode: {0}", InTestMode.ToString()); + } + + public void SetTestEnableState(bool state) + { + if (InTestMode) + { + TestEnableFeedback = state; + Debug.Console(1, this, "TestEnableFeedback: {0}", TestEnableFeedback.ToString()); + return; + } + + Debug.Console(1, this, "InTestMode: {0}, unable to set enable state: {1}", InTestMode.ToString(), state.ToString()); + } + + public void SetTestPartitionSensedState(bool state) + { + if (InTestMode) + { + TestPartitionSensedFeedback = state; + Debug.Console(1, this, "TestPartitionSensedFeedback: {0}", TestPartitionSensedFeedback.ToString()); + return; + } + + Debug.Console(1, this, "InTestMode: {0}, unable to set partition state: {1}", InTestMode.ToString(), state.ToString()); + } + + public void SetTestSensitivityValue(int value) + { + if (InTestMode) + { + TestSensitivityFeedback = value; + Debug.Console(1, this, "TestSensitivityFeedback: {0}", TestSensitivityFeedback); + return; + } + + Debug.Console(1, this, "InTestMode: {0}, unable to set sensitivity value: {1}", InTestMode.ToString(), value); + } + + public void SetEnableState(bool state) + { + if (PartitionSensor == null) + return; + + PartitionSensor.Enable.BoolValue = state; + } + + public void IncreaseSensitivity() + { + if (PartitionSensor == null) + return; + + PartitionSensor.IncreaseSensitivity(); + } + + public void DecreaseSensitivity() + { + if (PartitionSensor == null) + return; + + PartitionSensor.DecreaseSensitivity(); + } + + public void SetSensitivity(ushort value) + { + if (PartitionSensor == null) + return; + + PartitionSensor.Sensitivity.UShortValue = (ushort)value; + } + + + public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) + { + var joinMap = new GlsPartitionSensorJoinMap(joinStart); + var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); + + if (!string.IsNullOrEmpty(joinMapSerialized)) + joinMap = JsonConvert.DeserializeObject(joinMapSerialized); + + if (bridge != null) + { + bridge.AddJoinMap(Key, joinMap); + } + else + { + Debug.Console(0, this, "Please update config to use 'type': 'EiscApiAdvanced' to get all join map features for this device"); + } + + Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); + Debug.Console(0, this, "Linking to Bridge Type {0}", GetType().Name); + + // link input from simpl + trilist.SetSigTrueAction(joinMap.Enable.JoinNumber, () => SetEnableState(true)); + trilist.SetSigFalseAction(joinMap.Enable.JoinNumber, () => SetEnableState(false)); + trilist.SetSigTrueAction(joinMap.IncreaseSensitivity.JoinNumber, IncreaseSensitivity); + trilist.SetSigTrueAction(joinMap.DecreaseSensitivity.JoinNumber, DecreaseSensitivity); + trilist.SetUShortSigAction(joinMap.Sensitivity.JoinNumber, SetSensitivity); + + // link output to simpl + IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]); + EnableFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Enable.JoinNumber]); + PartitionSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionSensed.JoinNumber]); + PartitionNotSensedFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]); + SensitivityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Sensitivity.JoinNumber]); + + FeedbacksFireUpdates(); + + // update when device is online + PartitionSensor.OnlineStatusChange += (o, a) => + { + if (a.DeviceOnLine) + { + FeedbacksFireUpdates(); + } + }; + + // update when trilist is online + trilist.OnlineStatusChange += (o, a) => + { + if (a.DeviceOnLine) + { + FeedbacksFireUpdates(); + } + }; + } + + private void FeedbacksFireUpdates() + { + IsOnline.FireUpdate(); + NameFeedback.FireUpdate(); + EnableFeedback.FireUpdate(); + PartitionSensedFeedback.FireUpdate(); + PartitionNotSensedFeedback.FireUpdate(); + SensitivityFeedback.FireUpdate(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs new file mode 100644 index 00000000..543fc799 --- /dev/null +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro.GeneralIO; +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.Devices.Common.Occupancy; + +namespace PepperDash.Essentials.Devices.Common.PartitionSensor +{ + public class GlsPartitionSensorControllerFactory : EssentialsDeviceFactory + { + public GlsPartitionSensorControllerFactory() + { + TypeNames = new List() { "glspartcn" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(2, "Factory Attempting to create new GLS-PART-CN Device"); + + var typeName = dc.Type.ToLower(); + var key = dc.Key; + var name = dc.Name; + var comm = CommFactory.GetControlPropertiesConfig(dc); + if (comm == null) + { + Debug.Console(0, "ERROR: Control Properties Config are null"); + return null; + } + + var sensor = new GlsPartCn(comm.CresnetIdInt, Global.ControlSystem); + return new GlsPartitionSensorController(dc.Key, dc.Name, sensor); + } + } +} \ No newline at end of file From 495bf70d3ac51ca25a5ba419e7322849003b1a02 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Tue, 30 Jun 2020 14:46:46 -0500 Subject: [PATCH 25/47] Changes to CrestronGenericBridgeableBaseDevice and CrestronGenericBaseDevice to allow it to take a func in an overloaded constructor Addresses #292 --- .../Crestron IO/C2nRts/C2nRthsController.cs | 3 ++- .../Crestron/CrestronGenericBaseDevice.cs | 27 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs index 73279368..2ec1dd49 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs @@ -18,7 +18,8 @@ namespace PepperDash.Essentials.Core.CrestronIO public IntFeedback TemperatureFeedback { get; private set; } public IntFeedback HumidityFeedback { get; private set; } - public C2nRthsController(string key, string name, GenericBase hardware) : base(key, name, hardware) + public C2nRthsController(string key, string name, GenericBase hardware) + : base(key, name, hardware) { _device = hardware as C2nRths; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron/CrestronGenericBaseDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron/CrestronGenericBaseDevice.cs index 7866075f..0ad6e135 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron/CrestronGenericBaseDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron/CrestronGenericBaseDevice.cs @@ -1,7 +1,9 @@ -using System.Linq; +using System; +using System.Linq; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; +using PepperDash.Core.JsonStandardObjects; using PepperDash.Essentials.Core.Bridges; namespace PepperDash.Essentials.Core @@ -42,6 +44,24 @@ namespace PepperDash.Essentials.Core CommunicationMonitor = new CrestronGenericBaseCommunicationMonitor(this, hardware, 120000, 300000); } + protected CrestronGenericBaseDevice(string key, string name) + : base(key, name) + { + Feedbacks = new FeedbackCollection(); + + } + + protected void RegisterCrestronGenericBase(GenericBase hardware) + { + Hardware = hardware; + IsOnline = new BoolFeedback("IsOnlineFeedback", () => Hardware.IsOnline); + IsRegistered = new BoolFeedback("IsRegistered", () => Hardware.Registered); + IpConnectionsText = new StringFeedback("IpConnectionsText", () => Hardware.ConnectedIpList != null ? string.Join(",", Hardware.ConnectedIpList.Select(cip => cip.DeviceIpAddress).ToArray()) : string.Empty); + AddToFeedbackList(IsOnline, IpConnectionsText); + + CommunicationMonitor = new CrestronGenericBaseCommunicationMonitor(this, hardware, 120000, 300000); + } + /// /// Make sure that overriding classes call this! /// Registers the Crestron device, connects up to the base events, starts communication monitor @@ -135,6 +155,11 @@ namespace PepperDash.Essentials.Core { } + protected CrestronGenericBridgeableBaseDevice(string key, string name) + : base(key, name) + { + } + public abstract void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge); } From f954043981dbad95928412849fa69c3c3430e01b Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Tue, 30 Jun 2020 14:48:31 -0500 Subject: [PATCH 26/47] Updated C2NRthsController Class to build new devices in PreActivate Method Addresses #292 --- .../Crestron IO/C2nRts/C2nRthsController.cs | 97 +++++++++++++++---- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs index 2ec1dd49..9d2b50ac 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.GeneralIO; @@ -11,22 +12,38 @@ using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core.CrestronIO { [Description("Wrapper class for the C2N-RTHS sensor")] - public class C2nRthsController : CrestronGenericBridgeableBaseDevice + public class C2nRthsController : CrestronGenericBridgeableBaseDevice, IOnline { - private readonly C2nRths _device; + private C2nRths _device; public IntFeedback TemperatureFeedback { get; private set; } public IntFeedback HumidityFeedback { get; private set; } + public BoolFeedback IsOnline { get; private set; } - public C2nRthsController(string key, string name, GenericBase hardware) - : base(key, name, hardware) + public C2nRthsController(string key, Func preActivationFunc, + DeviceConfig config) + : base(key, config.Name) { - _device = hardware as C2nRths; - TemperatureFeedback = new IntFeedback(() => _device.TemperatureFeedback.UShortValue); - HumidityFeedback = new IntFeedback(() => _device.HumidityFeedback.UShortValue); + AddPreActivationAction(() => + { + _device = preActivationFunc(config); - if (_device != null) _device.BaseEvent += DeviceOnBaseEvent; + RegisterCrestronGenericBase(_device); + + TemperatureFeedback = new IntFeedback(() => _device.TemperatureFeedback.UShortValue); + HumidityFeedback = new IntFeedback(() => _device.HumidityFeedback.UShortValue); + IsOnline = new BoolFeedback(() => _device.IsOnline); + + if (_device != null) _device.BaseEvent += DeviceOnBaseEvent; + if (_device != null) _device.OnlineStatusChange += _device_OnlineStatusChange; + + }); + } + + void _device_OnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args) + { + IsOnline.FireUpdate(); } private void DeviceOnBaseEvent(GenericBase device, BaseEventArgs args) @@ -77,24 +94,66 @@ namespace PepperDash.Essentials.Core.CrestronIO HumidityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Humidity.JoinNumber]); trilist.StringInput[joinMap.Name.JoinNumber].StringValue = Name; - } - } - public class C2nRthsControllerFactory : EssentialsDeviceFactory - { - public C2nRthsControllerFactory() - { - TypeNames = new List() { "c2nrths" }; + trilist.OnlineStatusChange += (d, args) => + { + if (!args.DeviceOnLine) return; + + UpdateFeedbacksWhenOnline(); + + trilist.StringInput[joinMap.Name.JoinNumber].StringValue = Name; + }; } - public override EssentialsDevice BuildDevice(DeviceConfig dc) + private void UpdateFeedbacksWhenOnline() { - Debug.Console(1, "Factory Attempting to create new C2N-RTHS Device"); + IsOnline.FireUpdate(); + TemperatureFeedback.FireUpdate(); + HumidityFeedback.FireUpdate(); + } + #region PreActivation + + private static C2nRths GetC2nRthsDevice(DeviceConfig dc) + { var control = CommFactory.GetControlPropertiesConfig(dc); var cresnetId = control.CresnetIdInt; + var branchId = control.ControlPortNumber; + var parentKey = string.IsNullOrEmpty(control.ControlPortDevKey) ? "processor" : control.ControlPortDevKey; - return new C2nRthsController(dc.Key, dc.Name, new C2nRths(cresnetId, Global.ControlSystem)); + if (parentKey.Equals("processor", StringComparison.CurrentCultureIgnoreCase)) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new C2nRths"); + return new C2nRths(cresnetId, Global.ControlSystem); + } + var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as ICresnetBridge; + + if (cresnetBridge != null) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new C2nRths"); + return new C2nRths(cresnetId, cresnetBridge.Branches[branchId]); + } + Debug.Console(0, "Device {0} is not a valid cresnet master", branchId); + return null; + } + #endregion + + public class C2nRthsControllerFactory : EssentialsDeviceFactory + { + public C2nRthsControllerFactory() + { + TypeNames = new List() { "c2nrths" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new C2N-RTHS Device"); + + var control = CommFactory.GetControlPropertiesConfig(dc); + var cresnetId = control.CresnetIdInt; + + return new C2nRthsController(dc.Key, GetC2nRthsDevice, dc); + } } } } \ No newline at end of file From b694f7640a7e280e7b7592ad3cb4265dd73c7736 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Tue, 30 Jun 2020 15:05:42 -0500 Subject: [PATCH 27/47] Minor Fixes to CrestronGenericBaseDevice Update StatusSignController constructor and factory to build device in PreActivation phase Addresses #292 --- .../Crestron IO/C2nRts/C2nRthsController.cs | 13 +-- .../StatusSign/StatusSignController.cs | 102 ++++++++++++------ 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs index 9d2b50ac..4a82fe09 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs @@ -12,13 +12,12 @@ using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core.CrestronIO { [Description("Wrapper class for the C2N-RTHS sensor")] - public class C2nRthsController : CrestronGenericBridgeableBaseDevice, IOnline + public class C2nRthsController : CrestronGenericBridgeableBaseDevice { private C2nRths _device; public IntFeedback TemperatureFeedback { get; private set; } public IntFeedback HumidityFeedback { get; private set; } - public BoolFeedback IsOnline { get; private set; } public C2nRthsController(string key, Func preActivationFunc, DeviceConfig config) @@ -33,18 +32,11 @@ namespace PepperDash.Essentials.Core.CrestronIO TemperatureFeedback = new IntFeedback(() => _device.TemperatureFeedback.UShortValue); HumidityFeedback = new IntFeedback(() => _device.HumidityFeedback.UShortValue); - IsOnline = new BoolFeedback(() => _device.IsOnline); if (_device != null) _device.BaseEvent += DeviceOnBaseEvent; - if (_device != null) _device.OnlineStatusChange += _device_OnlineStatusChange; - }); } - void _device_OnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args) - { - IsOnline.FireUpdate(); - } private void DeviceOnBaseEvent(GenericBase device, BaseEventArgs args) { @@ -149,9 +141,6 @@ namespace PepperDash.Essentials.Core.CrestronIO { Debug.Console(1, "Factory Attempting to create new C2N-RTHS Device"); - var control = CommFactory.GetControlPropertiesConfig(dc); - var cresnetId = control.CresnetIdInt; - return new C2nRthsController(dc.Key, GetC2nRthsDevice, dc); } } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs index 1bd22ebe..c316c9b4 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs @@ -13,7 +13,7 @@ namespace PepperDash.Essentials.Core.CrestronIO [Description("Wrapper class for the Crestron StatusSign device")] public class StatusSignController : CrestronGenericBridgeableBaseDevice { - private readonly StatusSign _device; + private StatusSign _device; public BoolFeedback RedLedEnabledFeedback { get; private set; } public BoolFeedback GreenLedEnabledFeedback { get; private set; } @@ -23,34 +23,40 @@ namespace PepperDash.Essentials.Core.CrestronIO public IntFeedback GreenLedBrightnessFeedback { get; private set; } public IntFeedback BlueLedBrightnessFeedback { get; private set; } - public StatusSignController(string key, string name, GenericBase hardware) : base(key, name, hardware) + public StatusSignController(string key, Func preActivationFunc, DeviceConfig config) : base(key, config.Name) { - _device = hardware as StatusSign; + AddPreActivationAction(() => + { + _device = preActivationFunc(config); - RedLedEnabledFeedback = + RegisterCrestronGenericBase(_device); + + RedLedEnabledFeedback = new BoolFeedback( () => - _device.Leds[(uint) StatusSign.Led.eLedColor.Red] - .ControlFeedback.BoolValue); - GreenLedEnabledFeedback = - new BoolFeedback( - () => - _device.Leds[(uint) StatusSign.Led.eLedColor.Green] - .ControlFeedback.BoolValue); - BlueLedEnabledFeedback = - new BoolFeedback( - () => - _device.Leds[(uint) StatusSign.Led.eLedColor.Blue] + _device.Leds[(uint)StatusSign.Led.eLedColor.Red] .ControlFeedback.BoolValue); + GreenLedEnabledFeedback = + new BoolFeedback( + () => + _device.Leds[(uint)StatusSign.Led.eLedColor.Green] + .ControlFeedback.BoolValue); + BlueLedEnabledFeedback = + new BoolFeedback( + () => + _device.Leds[(uint)StatusSign.Led.eLedColor.Blue] + .ControlFeedback.BoolValue); - RedLedBrightnessFeedback = - new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Red].BrightnessFeedback); - GreenLedBrightnessFeedback = - new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Green].BrightnessFeedback); - BlueLedBrightnessFeedback = - new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Blue].BrightnessFeedback); + RedLedBrightnessFeedback = + new IntFeedback(() => (int)_device.Leds[(uint)StatusSign.Led.eLedColor.Red].BrightnessFeedback); + GreenLedBrightnessFeedback = + new IntFeedback(() => (int)_device.Leds[(uint)StatusSign.Led.eLedColor.Green].BrightnessFeedback); + BlueLedBrightnessFeedback = + new IntFeedback(() => (int)_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].BrightnessFeedback); - if (_device != null) _device.BaseEvent += _device_BaseEvent; + if (_device != null) _device.BaseEvent += _device_BaseEvent; + + }); } void _device_BaseEvent(GenericBase device, BaseEventArgs args) @@ -167,23 +173,51 @@ namespace PepperDash.Essentials.Core.CrestronIO device.SetColor(redBrightness, greenBrightness, blueBrightness); } - } - public class StatusSignControllerFactory : EssentialsDeviceFactory - { - public StatusSignControllerFactory() + #region PreActivation + + private static StatusSign GetStatusSignDevice(DeviceConfig dc) { - TypeNames = new List() { "statussign" }; - } - - public override EssentialsDevice BuildDevice(DeviceConfig dc) - { - Debug.Console(1, "Factory Attempting to create new StatusSign Device"); - var control = CommFactory.GetControlPropertiesConfig(dc); var cresnetId = control.CresnetIdInt; + var branchId = control.ControlPortNumber; + var parentKey = string.IsNullOrEmpty(control.ControlPortDevKey) ? "processor" : control.ControlPortDevKey; - return new StatusSignController(dc.Key, dc.Name, new StatusSign(cresnetId, Global.ControlSystem)); + if (parentKey.Equals("processor", StringComparison.CurrentCultureIgnoreCase)) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new StatusSign"); + return new StatusSign(cresnetId, Global.ControlSystem); + } + var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as ICresnetBridge; + + if (cresnetBridge != null) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new StatusSign"); + return new StatusSign(cresnetId, cresnetBridge.Branches[branchId]); + } + Debug.Console(0, "Device {0} is not a valid cresnet master", branchId); + return null; + } + #endregion + + public class StatusSignControllerFactory : EssentialsDeviceFactory + { + public StatusSignControllerFactory() + { + TypeNames = new List() { "statussign" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new StatusSign Device"); + + var control = CommFactory.GetControlPropertiesConfig(dc); + var cresnetId = control.CresnetIdInt; + + return new StatusSignController(dc.Key, GetStatusSignDevice, dc); + } } } + + } \ No newline at end of file From ac379763ce61082f02668ca849a65a45e69cda3f Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Tue, 30 Jun 2020 15:25:20 -0500 Subject: [PATCH 28/47] Updates to Cresnet OccSensor Classes Addresses #292 --- .../GlsOccupancySensorBaseController.cs | 169 ++++++++++++------ .../GlsOdtOccupancySensorController.cs | 88 +++++---- 2 files changed, 169 insertions(+), 88 deletions(-) diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOccupancySensorBaseController.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOccupancySensorBaseController.cs index b6508920..9ee0de95 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOccupancySensorBaseController.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOccupancySensorBaseController.cs @@ -55,38 +55,57 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy } } - public GlsOccupancySensorBaseController(string key, string name, GlsOccupancySensorBase sensor) - : base(key, name, sensor) + public GlsOccupancySensorBaseController(string key, Func preActivationFunc, + DeviceConfig config) + : base(key, config.Name) + { + + + AddPreActivationAction(() => + { + OccSensor = preActivationFunc(config); + + RegisterCrestronGenericBase(OccSensor); + + RegisterGlsOdtSensorBaseController(); + + }); + } + + public GlsOccupancySensorBaseController(string key, string name) : base(key, name) {} + + protected void RegisterGlsOdtSensorBaseController() { - OccSensor = sensor; - RoomIsOccupiedFeedback = new BoolFeedback(RoomIsOccupiedFeedbackFunc); - PirSensorEnabledFeedback = new BoolFeedback(() => OccSensor.PirEnabledFeedback.BoolValue); + PirSensorEnabledFeedback = new BoolFeedback(() => OccSensor.PirEnabledFeedback.BoolValue); - LedFlashEnabledFeedback = new BoolFeedback(() => OccSensor.LedFlashEnabledFeedback.BoolValue); + LedFlashEnabledFeedback = new BoolFeedback(() => OccSensor.LedFlashEnabledFeedback.BoolValue); - ShortTimeoutEnabledFeedback = new BoolFeedback(() => OccSensor.ShortTimeoutEnabledFeedback.BoolValue); + ShortTimeoutEnabledFeedback = new BoolFeedback(() => OccSensor.ShortTimeoutEnabledFeedback.BoolValue); - PirSensitivityInVacantStateFeedback = new IntFeedback(() => OccSensor.PirSensitivityInVacantStateFeedback.UShortValue); + PirSensitivityInVacantStateFeedback = + new IntFeedback(() => OccSensor.PirSensitivityInVacantStateFeedback.UShortValue); - PirSensitivityInOccupiedStateFeedback = new IntFeedback(() => OccSensor.PirSensitivityInOccupiedStateFeedback.UShortValue); + PirSensitivityInOccupiedStateFeedback = + new IntFeedback(() => OccSensor.PirSensitivityInOccupiedStateFeedback.UShortValue); - CurrentTimeoutFeedback = new IntFeedback(() => OccSensor.CurrentTimeoutFeedback.UShortValue); + CurrentTimeoutFeedback = new IntFeedback(() => OccSensor.CurrentTimeoutFeedback.UShortValue); - LocalTimoutFeedback = new IntFeedback(() => OccSensor.LocalTimeoutFeedback.UShortValue); + LocalTimoutFeedback = new IntFeedback(() => OccSensor.LocalTimeoutFeedback.UShortValue); - GraceOccupancyDetectedFeedback = new BoolFeedback(() => OccSensor.GraceOccupancyDetectedFeedback.BoolValue); + GraceOccupancyDetectedFeedback = + new BoolFeedback(() => OccSensor.GraceOccupancyDetectedFeedback.BoolValue); - RawOccupancyFeedback = new BoolFeedback(() => OccSensor.RawOccupancyFeedback.BoolValue); + RawOccupancyFeedback = new BoolFeedback(() => OccSensor.RawOccupancyFeedback.BoolValue); - InternalPhotoSensorValue = new IntFeedback(() => OccSensor.InternalPhotoSensorValueFeedback.UShortValue); + InternalPhotoSensorValue = new IntFeedback(() => OccSensor.InternalPhotoSensorValueFeedback.UShortValue); - ExternalPhotoSensorValue = new IntFeedback(() => OccSensor.ExternalPhotoSensorValueFeedback.UShortValue); + ExternalPhotoSensorValue = new IntFeedback(() => OccSensor.ExternalPhotoSensorValueFeedback.UShortValue); - OccSensor.BaseEvent += new Crestron.SimplSharpPro.BaseEventHandler(OccSensor_BaseEvent); + OccSensor.BaseEvent += new Crestron.SimplSharpPro.BaseEventHandler(OccSensor_BaseEvent); - OccSensor.GlsOccupancySensorChange += new GlsOccupancySensorChangeEventHandler(OccSensor_GlsOccupancySensorChange); + OccSensor.GlsOccupancySensorChange += OccSensor_GlsOccupancySensorChange; } @@ -97,40 +116,56 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy /// protected virtual void OccSensor_GlsOccupancySensorChange(GlsOccupancySensorBase device, GlsOccupancySensorChangeEventArgs args) { - if (args.EventId == GlsOccupancySensorBase.PirEnabledFeedbackEventId) - PirSensorEnabledFeedback.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.LedFlashEnabledFeedbackEventId) - LedFlashEnabledFeedback.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.ShortTimeoutEnabledFeedbackEventId) - ShortTimeoutEnabledFeedback.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.PirSensitivityInOccupiedStateFeedbackEventId) - PirSensitivityInOccupiedStateFeedback.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.PirSensitivityInVacantStateFeedbackEventId) - PirSensitivityInVacantStateFeedback.FireUpdate(); + switch (args.EventId) + { + case GlsOccupancySensorBase.PirEnabledFeedbackEventId: + PirSensorEnabledFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.LedFlashEnabledFeedbackEventId: + LedFlashEnabledFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.ShortTimeoutEnabledFeedbackEventId: + ShortTimeoutEnabledFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.PirSensitivityInOccupiedStateFeedbackEventId: + PirSensitivityInOccupiedStateFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.PirSensitivityInVacantStateFeedbackEventId: + PirSensitivityInVacantStateFeedback.FireUpdate(); + break; + } } protected virtual void OccSensor_BaseEvent(Crestron.SimplSharpPro.GenericBase device, Crestron.SimplSharpPro.BaseEventArgs args) { Debug.Console(2, this, "GlsOccupancySensorChange EventId: {0}", args.EventId); - if (args.EventId == Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomOccupiedFeedbackEventId - || args.EventId == Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomVacantFeedbackEventId) + switch (args.EventId) { - Debug.Console(1, this, "Occupancy State: {0}", OccSensor.OccupancyDetectedFeedback.BoolValue); - RoomIsOccupiedFeedback.FireUpdate(); + case Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomVacantFeedbackEventId: + case Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomOccupiedFeedbackEventId: + Debug.Console(1, this, "Occupancy State: {0}", OccSensor.OccupancyDetectedFeedback.BoolValue); + RoomIsOccupiedFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.TimeoutFeedbackEventId: + CurrentTimeoutFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.TimeoutLocalFeedbackEventId: + LocalTimoutFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.GraceOccupancyDetectedFeedbackEventId: + GraceOccupancyDetectedFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.RawOccupancyFeedbackEventId: + RawOccupancyFeedback.FireUpdate(); + break; + case GlsOccupancySensorBase.InternalPhotoSensorValueFeedbackEventId: + InternalPhotoSensorValue.FireUpdate(); + break; + case GlsOccupancySensorBase.ExternalPhotoSensorValueFeedbackEventId: + ExternalPhotoSensorValue.FireUpdate(); + break; } - else if (args.EventId == GlsOccupancySensorBase.TimeoutFeedbackEventId) - CurrentTimeoutFeedback.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.TimeoutLocalFeedbackEventId) - LocalTimoutFeedback.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.GraceOccupancyDetectedFeedbackEventId) - GraceOccupancyDetectedFeedback.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.RawOccupancyFeedbackEventId) - RawOccupancyFeedback.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.InternalPhotoSensorValueFeedbackEventId) - InternalPhotoSensorValue.FireUpdate(); - else if (args.EventId == GlsOccupancySensorBase.ExternalPhotoSensorValueFeedbackEventId) - ExternalPhotoSensorValue.FireUpdate(); } public void SetTestMode(bool mode) @@ -373,27 +408,51 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy { LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge); } - } - public class GlsOccupancySensorBaseControllerFactory : EssentialsDeviceFactory - { - public GlsOccupancySensorBaseControllerFactory() + #region PreActivation + + private static GlsOirCCn GetGlsOirCCn(DeviceConfig dc) { - TypeNames = new List() { "glsoirccn" }; + var control = CommFactory.GetControlPropertiesConfig(dc); + var cresnetId = control.CresnetIdInt; + var branchId = control.ControlPortNumber; + var parentKey = string.IsNullOrEmpty(control.ControlPortDevKey) ? "processor" : control.ControlPortDevKey; + + if (parentKey.Equals("processor", StringComparison.CurrentCultureIgnoreCase)) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOirCCn"); + return new GlsOirCCn(cresnetId, Global.ControlSystem); + } + var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as ICresnetBridge; + + if (cresnetBridge != null) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOirCCn"); + return new GlsOirCCn(cresnetId, cresnetBridge.Branches[branchId]); + } + Debug.Console(0, "Device {0} is not a valid cresnet master", branchId); + return null; } + #endregion - public override EssentialsDevice BuildDevice(DeviceConfig dc) + public class GlsOccupancySensorBaseControllerFactory : EssentialsDeviceFactory { - Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device"); + public GlsOccupancySensorBaseControllerFactory() + { + TypeNames = new List() { "glsoirccn" }; + } - var key = dc.Key; - var name = dc.Name; - var comm = CommFactory.GetControlPropertiesConfig(dc); - GlsOccupancySensorBase occSensor = new GlsOirCCn(comm.CresnetIdInt, Global.ControlSystem); + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device"); + + return new GlsOccupancySensorBaseController(dc.Key, GetGlsOirCCn, dc); + } - return new GlsOccupancySensorBaseController(key, name, occSensor); } } + + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOdtOccupancySensorController.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOdtOccupancySensorController.cs index 26fec016..4eef3d2d 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOdtOccupancySensorController.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOdtOccupancySensorController.cs @@ -35,26 +35,35 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy public BoolFeedback RawOccupancyUsFeedback { get; private set; } - public GlsOdtOccupancySensorController(string key, string name, GlsOdtCCn sensor) - : base(key, name, sensor) + public GlsOdtOccupancySensorController(string key, Func preActivationFunc, + DeviceConfig config) + : base(key, config.Name) { - OccSensor = sensor; + AddPreActivationAction(() => + { + OccSensor = preActivationFunc(config); - AndWhenVacatedFeedback = new BoolFeedback(() => OccSensor.AndWhenVacatedFeedback.BoolValue); + RegisterCrestronGenericBase(OccSensor); - OrWhenVacatedFeedback = new BoolFeedback(() => OccSensor.OrWhenVacatedFeedback.BoolValue); + RegisterGlsOdtSensorBaseController(); - UltrasonicAEnabledFeedback = new BoolFeedback(() => OccSensor.UsAEnabledFeedback.BoolValue); + AndWhenVacatedFeedback = new BoolFeedback(() => OccSensor.AndWhenVacatedFeedback.BoolValue); - UltrasonicBEnabledFeedback = new BoolFeedback(() => OccSensor.UsBEnabledFeedback.BoolValue); + OrWhenVacatedFeedback = new BoolFeedback(() => OccSensor.OrWhenVacatedFeedback.BoolValue); - RawOccupancyPirFeedback = new BoolFeedback(() => OccSensor.RawOccupancyPirFeedback.BoolValue); + UltrasonicAEnabledFeedback = new BoolFeedback(() => OccSensor.UsAEnabledFeedback.BoolValue); - RawOccupancyUsFeedback = new BoolFeedback(() => OccSensor.RawOccupancyUsFeedback.BoolValue); + UltrasonicBEnabledFeedback = new BoolFeedback(() => OccSensor.UsBEnabledFeedback.BoolValue); - UltrasonicSensitivityInVacantStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInVacantStateFeedback.UShortValue); + RawOccupancyPirFeedback = new BoolFeedback(() => OccSensor.RawOccupancyPirFeedback.BoolValue); - UltrasonicSensitivityInOccupiedStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInOccupiedStateFeedback.UShortValue); + RawOccupancyUsFeedback = new BoolFeedback(() => OccSensor.RawOccupancyUsFeedback.BoolValue); + + UltrasonicSensitivityInVacantStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInVacantStateFeedback.UShortValue); + + UltrasonicSensitivityInOccupiedStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInOccupiedStateFeedback.UShortValue); + + }); } /// @@ -160,38 +169,51 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy { LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge); } - } - public class GlsOdtOccupancySensorControllerFactory : EssentialsDeviceFactory - { - public GlsOdtOccupancySensorControllerFactory() + #region PreActivation + + private static GlsOdtCCn GetGlsOdtCCn(DeviceConfig dc) { - TypeNames = new List() { "glsodtccn" }; - } + var control = CommFactory.GetControlPropertiesConfig(dc); + var cresnetId = control.CresnetIdInt; + var branchId = control.ControlPortNumber; + var parentKey = string.IsNullOrEmpty(control.ControlPortDevKey) ? "processor" : control.ControlPortDevKey; - public override EssentialsDevice BuildDevice(DeviceConfig dc) - { - Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device"); - - var typeName = dc.Type.ToLower(); - var key = dc.Key; - var name = dc.Name; - var comm = CommFactory.GetControlPropertiesConfig(dc); - - var occSensor = new GlsOdtCCn(comm.CresnetIdInt, Global.ControlSystem); - - if (occSensor != null) + if (parentKey.Equals("processor", StringComparison.CurrentCultureIgnoreCase)) { - return new GlsOdtOccupancySensorController(key, name, occSensor); + Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOdtCCn"); + return new GlsOdtCCn(cresnetId, Global.ControlSystem); } - else + var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as ICresnetBridge; + + if (cresnetBridge != null) { - Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key); - return null; + Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOdtCCn"); + return new GlsOdtCCn(cresnetId, cresnetBridge.Branches[branchId]); + } + Debug.Console(0, "Device {0} is not a valid cresnet master", branchId); + return null; + } + #endregion + + public class GlsOdtOccupancySensorControllerFactory : EssentialsDeviceFactory + { + public GlsOdtOccupancySensorControllerFactory() + { + TypeNames = new List() { "glsodtccn" }; } + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device"); + + return new GlsOdtOccupancySensorController(dc.Key, GetGlsOdtCCn, dc); + } + } } + + } \ No newline at end of file From ea86c8b63987c7d110a1fcbb6edb639940a706ff Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Tue, 30 Jun 2020 17:32:50 -0500 Subject: [PATCH 29/47] Removed funcs and updated feedbacks in constructor --- .../GlsPartitionSensorController.cs | 75 +++++-------------- .../GlsPartitionSensorControllerFactory.cs | 14 +--- 2 files changed, 23 insertions(+), 66 deletions(-) diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs index 256b2496..29847144 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; -using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.GeneralIO; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; -using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; using PepperDash_Essentials_Core.Bridges.JoinMaps; @@ -18,15 +12,12 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor [Description("Wrapper class for GLS Cresnet Partition Sensor")] public class GlsPartitionSensorController : CrestronGenericBridgeableBaseDevice { - public GlsPartCn PartitionSensor { get; private set; } + private readonly GlsPartCn _partitionSensor; public StringFeedback NameFeedback { get; private set; } - public BoolFeedback EnableFeedback { get; private set; } - public BoolFeedback PartitionSensedFeedback { get; private set; } public BoolFeedback PartitionNotSensedFeedback { get; private set; } - public IntFeedback SensitivityFeedback { get; private set; } public bool InTestMode { get; private set; } @@ -34,31 +25,6 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor public bool TestPartitionSensedFeedback { get; private set; } public int TestSensitivityFeedback { get; private set; } - public Func NameFeedbackFunc - { - get { return () => Name; } - } - - public Func EnableFeedbackFunc - { - get { return () => InTestMode ? TestEnableFeedback : PartitionSensor.EnableFeedback.BoolValue; } - } - - public Func PartitionSensedFeedbackFunc - { - get { return () => InTestMode ? TestPartitionSensedFeedback : PartitionSensor.PartitionSensedFeedback.BoolValue; } - } - - public Func PartitionNotSensedFeedbackFunc - { - get { return () => InTestMode ? TestPartitionSensedFeedback : PartitionSensor.PartitionNotSensedFeedback.BoolValue; } - } - - public Func SensitivityFeedbackFunc - { - get { return () => InTestMode ? TestSensitivityFeedback : PartitionSensor.SensitivityFeedback.UShortValue; } - } - /// /// Constructor /// @@ -68,15 +34,15 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor public GlsPartitionSensorController(string key, string name, GlsPartCn hardware) : base(key, name, hardware) { - PartitionSensor = hardware; + _partitionSensor = hardware; - NameFeedback = new StringFeedback(NameFeedbackFunc); - EnableFeedback = new BoolFeedback(EnableFeedbackFunc); - PartitionSensedFeedback = new BoolFeedback(PartitionSensedFeedbackFunc); - PartitionNotSensedFeedback = new BoolFeedback(PartitionNotSensedFeedbackFunc); - SensitivityFeedback = new IntFeedback(SensitivityFeedbackFunc); + NameFeedback = new StringFeedback(() => Name); + EnableFeedback = new BoolFeedback(() => _partitionSensor.EnableFeedback.BoolValue); + PartitionSensedFeedback = new BoolFeedback(() => _partitionSensor.PartitionSensedFeedback.BoolValue); + PartitionNotSensedFeedback = new BoolFeedback(() => _partitionSensor.PartitionNotSensedFeedback.BoolValue); + SensitivityFeedback = new IntFeedback(() => _partitionSensor.SensitivityFeedback.UShortValue); - if (PartitionSensor != null) PartitionSensor.BaseEvent += PartitionSensor_BaseEvent; + if (_partitionSensor != null) _partitionSensor.BaseEvent += PartitionSensor_BaseEvent; } @@ -108,7 +74,7 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor } default: { - Debug.Console(2, this, "args.EventId: {0}", args.EventId); + Debug.Console(2, this, "Unhandled args.EventId: {0}", args.EventId); break; } } @@ -158,37 +124,36 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor public void SetEnableState(bool state) { - if (PartitionSensor == null) + if (_partitionSensor == null) return; - PartitionSensor.Enable.BoolValue = state; + _partitionSensor.Enable.BoolValue = state; } public void IncreaseSensitivity() { - if (PartitionSensor == null) + if (_partitionSensor == null) return; - PartitionSensor.IncreaseSensitivity(); + _partitionSensor.IncreaseSensitivity(); } public void DecreaseSensitivity() { - if (PartitionSensor == null) + if (_partitionSensor == null) return; - PartitionSensor.DecreaseSensitivity(); + _partitionSensor.DecreaseSensitivity(); } public void SetSensitivity(ushort value) { - if (PartitionSensor == null) + if (_partitionSensor == null) return; - PartitionSensor.Sensitivity.UShortValue = (ushort)value; + _partitionSensor.Sensitivity.UShortValue = value; } - public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) { var joinMap = new GlsPartitionSensorJoinMap(joinStart); @@ -220,13 +185,13 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]); EnableFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Enable.JoinNumber]); PartitionSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionSensed.JoinNumber]); - PartitionNotSensedFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]); + PartitionNotSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]); SensitivityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Sensitivity.JoinNumber]); FeedbacksFireUpdates(); // update when device is online - PartitionSensor.OnlineStatusChange += (o, a) => + _partitionSensor.OnlineStatusChange += (o, a) => { if (a.DeviceOnLine) { diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs index 543fc799..a60637f7 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; +using System.Collections.Generic; using Crestron.SimplSharpPro.GeneralIO; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; -using PepperDash.Essentials.Devices.Common.Occupancy; namespace PepperDash.Essentials.Devices.Common.PartitionSensor { @@ -21,14 +16,11 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor public override EssentialsDevice BuildDevice(DeviceConfig dc) { Debug.Console(2, "Factory Attempting to create new GLS-PART-CN Device"); - - var typeName = dc.Type.ToLower(); - var key = dc.Key; - var name = dc.Name; + var comm = CommFactory.GetControlPropertiesConfig(dc); if (comm == null) { - Debug.Console(0, "ERROR: Control Properties Config are null"); + Debug.Console(0, "ERROR: Control Properties Config for {0} is null", dc.Key); return null; } From 0a3f2bb524d75b1800141ad02291a8f9f96cc930 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Wed, 1 Jul 2020 10:35:57 -0500 Subject: [PATCH 30/47] WIP Cresnet Gateway SUpport --- .../Factory/ReadyEventArgs.cs | 30 ++ .../Gateways/CenRfgwController.cs | 272 ++++++++++-------- .../PepperDash_Essentials_Core.csproj | 1 + .../Remotes/Hrxx0WirelessRemoteController.cs | 45 ++- .../Chassis/DmChassisController.cs | 1 + 5 files changed, 232 insertions(+), 117 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs new file mode 100644 index 00000000..6999bd74 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +namespace PepperDash_Essentials_Core +{ + public delegate void IsReadyEventHandler(object source, IsReadyEventArgs e); + + public class IsReadyEventArgs : EventArgs + { + private readonly bool _EventData; + + public IsReadyEventArgs(bool data) + { + _EventData = data; + } + + public bool GetData() + { + return _EventData; + } + } + + public interface IHasReady + { + event IsReadyEventHandler IsReady; + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs index 1fd7da6d..767714d1 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs @@ -6,134 +6,182 @@ using Crestron.SimplSharp; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.Gateways; using Newtonsoft.Json; +using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; +using PepperDash_Essentials_Core; -namespace PepperDash.Essentials.Core +namespace PepperDash.Essentials.Core { - [Description("Wrapper class for Crestron Infinet-EX Gateways")] - public class CenRfgwController : CrestronGenericBaseDevice - { - private GatewayBase _Gateway; - public GatewayBase GateWay { get { return _Gateway; } } - - /// - /// Constructor for the on-board gateway - /// - /// - /// - public CenRfgwController(string key, string name, GatewayBase gateway) : - base(key, name, gateway) - { - _Gateway = gateway; - } - - public static CenRfgwController GetNewExGatewayController(string key, string name, ushort ipId, ushort cresnetId, string gatewayType) - { - eExGatewayType type = (eExGatewayType)Enum.Parse(typeof(eExGatewayType), gatewayType, true); - try - { - var cs = Global.ControlSystem; - - GatewayBase gw = null; - switch (type) - { - case eExGatewayType.Ethernet: - gw = new CenRfgwEx(ipId, cs); - break; - case eExGatewayType.EthernetShared: - gw = new CenRfgwExEthernetSharable(ipId, cs); - break; - case eExGatewayType.Cresnet: - gw = new CenRfgwExCresnet(cresnetId, cs); - break; - } - return new CenRfgwController(key, name, gw); - } - catch (Exception) - { - Debug.Console(0, "ERROR: Cannot create EX Gateway, id {0}, type {1}", type == eExGatewayType.Cresnet ? cresnetId : ipId, gatewayType); - return null; - } - } - public static CenRfgwController GetNewErGatewayController(string key, string name, ushort ipId, ushort cresnetId, string gatewayType) - { - eExGatewayType type = (eExGatewayType)Enum.Parse(typeof(eExGatewayType), gatewayType, true); - try - { - var cs = Global.ControlSystem; - - GatewayBase gw = null; - switch (type) - { - case eExGatewayType.Ethernet: - gw = new CenErfgwPoe(ipId, cs); - break; - case eExGatewayType.EthernetShared: - gw = new CenErfgwPoeEthernetSharable(ipId, cs); - break; - case eExGatewayType.Cresnet: - gw = new CenErfgwPoeCresnet(cresnetId, cs); - break; - } - return new CenRfgwController(key, name, gw); - } - catch (Exception) - { - Debug.Console(0, "ERROR: Cannot create ER Gateway, id {0}, type {1}", type== eExGatewayType.Cresnet ? cresnetId : ipId, gatewayType); - return null; - } - } - - } - - - - public enum eExGatewayType - { - Ethernet, EthernetShared, Cresnet - } + [Description("Wrapper class for Crestron Infinet-EX Gateways")] + public class CenRfgwController : CrestronGenericBaseDevice, IHasReady + { + public event IsReadyEventHandler IsReady; + private GatewayBase _gateway; - #region Factory - public class CenRfgwControllerFactory : EssentialsDeviceFactory - { - public CenRfgwControllerFactory() - { - TypeNames = new List() { "cenrfgwex", "cenerfgwpoe" }; - } - - public override EssentialsDevice BuildDevice(DeviceConfig dc) + public GatewayBase GateWay { + get { return _gateway; } + } - Debug.Console(1, "Factory Attempting to create new CEN-GWEXER Device"); - - var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + /// + /// Constructor for the on-board gateway + /// + /// + /// + public CenRfgwController(string key, string name, GatewayBase gateway) : + base(key, name, gateway) + { + _gateway = gateway; + IsReady(this, new IsReadyEventArgs(true)); + } - var type = dc.Type.ToLower(); - var control = props.Control; - var ipid = control.IpIdInt; - var cresnetId = control.CresnetIdInt; - var gatewayType = props.GatewayType; - - switch (type) + public CenRfgwController(string key, Func preActivationFunc, DeviceConfig config) : + base(key, config.Name) + { + IsReady(this, new IsReadyEventArgs(false)); + AddPreActivationAction(() => { - case ("cenrfgwex"): - return CenRfgwController.GetNewExGatewayController(dc.Key, dc.Name, - (ushort)ipid, (ushort)cresnetId, gatewayType); - case ("cenerfgwpoe"): - return CenRfgwController.GetNewErGatewayController(dc.Key, dc.Name, - (ushort)ipid, (ushort)cresnetId, gatewayType); - default: - return null; - } + _gateway = preActivationFunc(config); + + RegisterCrestronGenericBase(_gateway); + IsReady(this, new IsReadyEventArgs(true)); + + }); + } + + public static GatewayBase GetNewIpRfGateway(DeviceConfig dc) + { + var control = CommFactory.GetControlPropertiesConfig(dc); + var name = dc.Name; + var type = dc.Type; + var key = dc.Key; + var ipId = control.IpIdInt; + + if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenRfgwEx(ipId, Global.ControlSystem); + } + if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenErfgwPoe(ipId, Global.ControlSystem); + } + return null; + } + + public static GatewayBase GetNewSharedIpRfGateway(DeviceConfig dc) + { + var control = CommFactory.GetControlPropertiesConfig(dc); + var ipId = control.IpIdInt; + + if (dc.Type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenRfgwExEthernetSharable(ipId, Global.ControlSystem); + } + if (dc.Type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenErfgwPoeEthernetSharable(ipId, Global.ControlSystem); + } + return null; + } + + public static GatewayBase GetCenRfgwCresnetController(DeviceConfig dc) + { + var control = CommFactory.GetControlPropertiesConfig(dc); + var type = dc.Type; + var cresnetId = control.CresnetIdInt; + var branchId = control.ControlPortNumber; + var parentKey = string.IsNullOrEmpty(control.ControlPortDevKey) ? "processor" : control.ControlPortDevKey; + + if (parentKey.Equals("processor", StringComparison.CurrentCultureIgnoreCase)) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOdtCCn"); + if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenErfgwPoeCresnet(cresnetId, Global.ControlSystem); + } + if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenRfgwExCresnet(cresnetId, Global.ControlSystem); + } + } + var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as ICresnetBridge; + + if (cresnetBridge != null) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOdtCCn"); + + if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenErfgwPoeCresnet(cresnetId, cresnetBridge.Branches[branchId]); + } + if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenRfgwExCresnet(cresnetId, cresnetBridge.Branches[branchId]); + } + } + Debug.Console(0, "Device {0} is not a valid cresnet master", branchId); + return null; + } + + + + + + + + public enum eExGatewayType + { + Ethernet, + EthernetShared, + Cresnet + } + + + #region Factory + + public class CenRfgwControllerFactory : EssentialsDeviceFactory + { + public CenRfgwControllerFactory() + { + TypeNames = new List() {"cenrfgwex", "cenerfgwpoe"}; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + + Debug.Console(1, "Factory Attempting to create new CEN-GWEXER Device"); + + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + var type = dc.Type.ToLower(); + var control = props.Control; + var ipid = control.IpIdInt; + var cresnetId = control.CresnetIdInt; + + eExGatewayType gatewayType = + (eExGatewayType) Enum.Parse(typeof (eExGatewayType), props.GatewayType, true); + + switch (gatewayType) + { + case (eExGatewayType.Ethernet): + return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewIpRfGateway(dc)); + case (eExGatewayType.EthernetShared): + return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewSharedIpRfGateway(dc)); + case (eExGatewayType.Cresnet): + return new CenRfgwController(dc.Key, CenRfgwController.GetCenRfgwCresnetController, dc); + } + return null; + } } } + #endregion +} -} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 55a157b4..4e1676fb 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -192,6 +192,7 @@ + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs index 746f449f..dd52257e 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs @@ -21,6 +21,8 @@ namespace PepperDash.Essentials.Core [Description("Wrapper class for all HR-Series remotes")] public class Hrxx0WirelessRemoteController : EssentialsBridgeableDevice, IHasFeedback { + private CenRfgwController _gateway; + private Hr1x0WirelessRemoteBase _remote; public FeedbackCollection Feedbacks { get; set; } @@ -33,6 +35,39 @@ namespace PepperDash.Essentials.Core { Feedbacks = new FeedbackCollection(); + var props = JsonConvert.DeserializeObject(config.Properties.ToString()); + + var type = config.Type; + var rfId = (uint)props.Control.InfinetIdInt; + + GatewayBase gateway; + + if (props.GatewayDeviceKey == "processor") + { + gateway = Global.ControlSystem.ControllerRFGatewayDevice; + } + + else + { + var gatewayDev = DeviceManager.GetDeviceForKey(props.GatewayDeviceKey) as CenRfgwController; + if (gatewayDev == null) + { + Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid device", props.GatewayDeviceKey); + } + if (gatewayDev != null) + { + Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is a valid device", props.GatewayDeviceKey); + gateway = gatewayDev.GateWay; + _gateway = gatewayDev; + } + } + + if (_gateway != null) + { + _gateway.IsReady += new PepperDash_Essentials_Core.IsReadyEventHandler(_gateway_IsReady); + } + + AddPreActivationAction(() => { _remote = preActivationFunc(config); @@ -47,6 +82,11 @@ namespace PepperDash.Essentials.Core }); } + void _gateway_IsReady(object source, PepperDash_Essentials_Core.IsReadyEventArgs e) + { + throw new NotImplementedException(); + } + void _remote_BaseEvent(GenericBase device, BaseEventArgs args) { if(args.EventId == Hr1x0EventIds.BatteryCriticalFeedbackEventId) @@ -137,11 +177,6 @@ namespace PepperDash.Essentials.Core return remoteBase; } - static void gateway_BaseEvent(GenericBase device, BaseEventArgs args) - { - throw new NotImplementedException(); - } - #endregion #region Factory diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs index 9a28f75f..9cd0c655 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs @@ -614,6 +614,7 @@ namespace PepperDash.Essentials.DM var cecPort2 = outputCard.Card2.HdmiOutput; AddDmcHdoPorts(number, cecPort1, cecPort2); } + else if (type == "dmchdo") { var outputCard = new DmcHdoSingle(number, Chassis); From 9596d0f3c349c636d17af1c9f7107b2d1a33f01c Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Wed, 1 Jul 2020 10:44:28 -0500 Subject: [PATCH 31/47] Adds Dmc4kzHdo Resolves #294 --- .../Essentials_DM/Chassis/DmChassisController.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs index 9a28f75f..8aeb6668 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs @@ -614,6 +614,13 @@ namespace PepperDash.Essentials.DM var cecPort2 = outputCard.Card2.HdmiOutput; AddDmcHdoPorts(number, cecPort1, cecPort2); } + else if (type == "dmc4kzhdo") + { + var outputCard = new Dmc4kzHdoSingle(number, Chassis); + var cecPort1 = outputCard.Card1.HdmiOutput; + var cecPort2 = outputCard.Card2.HdmiOutput; + AddDmcHdoPorts(number, cecPort1, cecPort2); + } else if (type == "dmchdo") { var outputCard = new DmcHdoSingle(number, Chassis); From 2fea151089d178728660c29f14bef0aca69764fe Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Wed, 1 Jul 2020 16:03:32 -0500 Subject: [PATCH 32/47] Changes to CrestronGenericBase Refactor RfGatewayController new IHasReady interface Updates to Hrxx0WirelessRemoteController merge in development Addresses #292 --- .../Crestron/CrestronGenericBaseDevice.cs | 2 +- .../Factory/ReadyEventArgs.cs | 14 ++---- .../Gateways/CenRfgwController.cs | 48 +++++++++++-------- .../Remotes/Hrxx0WirelessRemoteController.cs | 47 +++++++++++------- 4 files changed, 62 insertions(+), 49 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron/CrestronGenericBaseDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron/CrestronGenericBaseDevice.cs index 0ad6e135..9db81122 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron/CrestronGenericBaseDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron/CrestronGenericBaseDevice.cs @@ -13,7 +13,7 @@ namespace PepperDash.Essentials.Core /// public abstract class CrestronGenericBaseDevice : EssentialsDevice, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking { - public virtual GenericBase Hardware { get; protected set; } + protected GenericBase Hardware; /// /// Returns a list containing the Outputs that we want to expose. diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs index 6999bd74..89c0b7b3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs @@ -6,25 +6,19 @@ using Crestron.SimplSharp; namespace PepperDash_Essentials_Core { - public delegate void IsReadyEventHandler(object source, IsReadyEventArgs e); - public class IsReadyEventArgs : EventArgs { - private readonly bool _EventData; + public bool IsReady { get; set; } public IsReadyEventArgs(bool data) { - _EventData = data; - } - - public bool GetData() - { - return _EventData; + IsReady = data; } } public interface IHasReady { - event IsReadyEventHandler IsReady; + event EventHandler IsReadyEvent; + bool IsReady { get; } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs index 767714d1..ba185e4f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs @@ -20,7 +20,9 @@ namespace PepperDash.Essentials.Core [Description("Wrapper class for Crestron Infinet-EX Gateways")] public class CenRfgwController : CrestronGenericBaseDevice, IHasReady { - public event IsReadyEventHandler IsReady; + public event EventHandler IsReadyEvent; + + public bool IsReady { get; private set; } private GatewayBase _gateway; @@ -34,23 +36,27 @@ namespace PepperDash.Essentials.Core /// /// /// + /// public CenRfgwController(string key, string name, GatewayBase gateway) : base(key, name, gateway) { _gateway = gateway; - IsReady(this, new IsReadyEventArgs(true)); + IsReady = true; + FireIsReadyEvent(IsReady); } public CenRfgwController(string key, Func preActivationFunc, DeviceConfig config) : base(key, config.Name) { - IsReady(this, new IsReadyEventArgs(false)); + IsReady = false; + FireIsReadyEvent(IsReady); AddPreActivationAction(() => { _gateway = preActivationFunc(config); + IsReady = true; RegisterCrestronGenericBase(_gateway); - IsReady(this, new IsReadyEventArgs(true)); + FireIsReadyEvent(IsReady); }); } @@ -58,9 +64,7 @@ namespace PepperDash.Essentials.Core public static GatewayBase GetNewIpRfGateway(DeviceConfig dc) { var control = CommFactory.GetControlPropertiesConfig(dc); - var name = dc.Name; var type = dc.Type; - var key = dc.Key; var ipId = control.IpIdInt; if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) @@ -74,6 +78,15 @@ namespace PepperDash.Essentials.Core return null; } + private void FireIsReadyEvent(bool data) + { + var handler = IsReadyEvent; + if (handler == null) return; + + handler(this, new IsReadyEventArgs(data)); + + } + public static GatewayBase GetNewSharedIpRfGateway(DeviceConfig dc) { var control = CommFactory.GetControlPropertiesConfig(dc); @@ -135,7 +148,7 @@ namespace PepperDash.Essentials.Core - public enum eExGatewayType + public enum EExGatewayType { Ethernet, EthernetShared, @@ -159,22 +172,17 @@ namespace PepperDash.Essentials.Core var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); - var type = dc.Type.ToLower(); - var control = props.Control; - var ipid = control.IpIdInt; - var cresnetId = control.CresnetIdInt; - - eExGatewayType gatewayType = - (eExGatewayType) Enum.Parse(typeof (eExGatewayType), props.GatewayType, true); + EExGatewayType gatewayType = + (EExGatewayType) Enum.Parse(typeof (EExGatewayType), props.GatewayType, true); switch (gatewayType) { - case (eExGatewayType.Ethernet): - return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewIpRfGateway(dc)); - case (eExGatewayType.EthernetShared): - return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewSharedIpRfGateway(dc)); - case (eExGatewayType.Cresnet): - return new CenRfgwController(dc.Key, CenRfgwController.GetCenRfgwCresnetController, dc); + case (EExGatewayType.Ethernet): + return new CenRfgwController(dc.Key, dc.Name, GetNewIpRfGateway(dc)); + case (EExGatewayType.EthernetShared): + return new CenRfgwController(dc.Key, dc.Name, GetNewSharedIpRfGateway(dc)); + case (EExGatewayType.Cresnet): + return new CenRfgwController(dc.Key, GetCenRfgwCresnetController, dc); } return null; } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs index dd52257e..311df7f1 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs @@ -29,6 +29,8 @@ namespace PepperDash.Essentials.Core public CrestronCollection