diff --git a/README.md b/README.md index 2921a447f..5d449c91a 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,12 @@ Additionally, the specifications given in the "Areas of Use and Application" for Any use of the source code and related documents of this repository in applications other than those specified above or under operating conditions other than those described in the documentation and the technical specifications is considered as "unintended". Furthermore, this software must not be used in any application areas not expressly approved by Bosch Rexroth. -## About +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT -Copyright © 2020-2022 Bosch Rexroth AG. All rights reserved. +## About Please note that any trademarks, logos and pictures contained or linked to in this Software are owned by or copyright © Bosch Rexroth AG 2021 and not licensed under the Software's license terms. diff --git a/doc/appdevguide.md b/doc/appdevguide.md index e483d1f2b..be293e6c8 100644 --- a/doc/appdevguide.md +++ b/doc/appdevguide.md @@ -23,7 +23,6 @@ [11 Real Time Extension (optional)](#realtime) -[12 Licensing (optional)](#licensing) ## 1 Introduction @@ -103,7 +102,7 @@ To simplify the delivery of artifacts, we provide a base folder structure with d **Handover of artifacts** -Once all the required information is available in your local folder, zip the folder using Windows-zip and upload it as "**artifacts.zip**" to the ctrlX World Portal space in the "**.../{company-name}/{app-name}/{version}/**" path. +Once all the required information is available in your local folder, zip the folder using Windows-zip and upload it as "**artifacts.zip**" to the ctrlX World Partner Portal space in the "**.../{company-name}/{app-name}/{version}/**" path. !!! important To avoid problems when uploading the artifacts.zip file, please use the Windows-zip feature @@ -113,7 +112,7 @@ Once all the required information is available in your local folder, zip the fol ### 2.4 Validation and Signing Validation is typically carried out in several iterations, depending on the result of a particular validation activity. -If all the required information is provided in the ctrlX World Portal, an email to `ctrlx.world@boschrexroth.com` will trigger a validation loop. +If all the required information is provided in the ctrlX World Portal, an email to `ctrlx.world@boschrexroth.de` will trigger a validation loop. Basically, the workflow will be as follows: 1. Partner/app developer: Uploads required artifacts and informs Bosch Rexroth @@ -139,7 +138,7 @@ The app itself and corresponding user documentation need to be provided. Legal a Working set information is needed to support the test and validation process. During runtime, the app must use the ctrlX CORE onboard licensing mechanism. #### **3.1.2 Customer User Experience** -Customers can find the app in the ctrlX App Store. They know how the app is licensed and can use the overall Bosch Rexroth licensing system for ctrlX. +Customers can find the app in the ctrlX App Store. They know how the app is licensed and can use the overall Bosch Rexroth licensing system for ctrlX CORE. They can also be sure that the app contributes to the basic ctrlX CORE security mechanisms. #### **3.1.3 Technical Prerequisites** @@ -219,7 +218,7 @@ Finally, an app can integrate in the Automation framework and extend the ctrlX r Real time integration requires additional training and support from Bosch Rexroth to avoid unexpected system behavior and impacts on the ctrlX real-time kernel. #### **3.3.1 Description** -The app exposes information in the ctrlX Data Layer for all other apps. It also can extend the real time functions of ctrlX if connected to the real-time task scheduler +The app exposes information in the ctrlX Data Layer for all other apps. It also can extend the real time functions of ctrlX CORE if connected to the real-time task scheduler #### **3.3.2 Customer User Experience** The app extends the ctrlX AUTOMATION system functions, e.g. for Motion and/or PLC @@ -244,13 +243,13 @@ The basic app information is checked as a prerequisite by Bosch Rexroth, before #### 4.1.1 Artifacts Folder Template -The ctrlX World Portal provides a file (artifacts.zip), which can be downloaded and extracted locally. +The ctrlX World Partner Portal provides a file (artifacts.zip), which can be downloaded and extracted locally. This will create the required folder structure for the mandatory artifacts out-of-the-box, with default descriptions and schema files. !!!! important Please use the given structure, folder names and file names unchanged. This will support an efficient validation process. -![image](images/artefacts.png) +![image](images/artifacts.png) The artifacts are organized in five sub folders: @@ -282,12 +281,15 @@ Note: For the `{xxx}-description` files, a default file (with explanation) and t - **"slotplug-description.json" (**MANDATORY**)** - All used slot and plugs are described in the slot and plug description + +**The [Base checklist](appdevguide_basechecks.md) contains the criteria which are checked in these files.** + #### 4.1.4 "Documentation" folder (**MANDATORY**) All documentation relevant to the app is provided here - **"manual.pdf" (**MANDATORY**)** - The app description (user manual) documents the app’s overall functionality - - **"test-setup-description.pdf" (**MANDATORY**)** - The app setup describes how to configure the app on a ctrlX device for a typical usage and test scenario + - **"test-setup-description.pdf" (**MANDATORY**)** - The app setup describes how to configure the app on a ctrlX CORE for a typical usage and test scenario - **"release-notes.pdf" (**MANDATORY**)** - The latest changes, workarounds and defects are mentioned in the release notes #### 4.1.5 "App States" folder (**MANDATORY**) @@ -302,9 +304,9 @@ The app validation framework tries to establish relevant states that have to be ctrlX currently supports the amd64 and the arm64 processor architecture. The corresponding target snaps for the app are provided here -- **"{TechnicalAppName}_{version}_arm64.snap" (**MANDATORY**)** - Snap that runs in armd64 environments. Currently, the arm64 architecture is used in ctrlX CORE hardware. +- **"ctrlx-{company name}-{app name}-{version}_arm64.snap" (**MANDATORY**)** - Snap that runs in armd64 environments. Currently, the arm64 architecture is used in ctrlX CORE hardware. -- **"{TechnicalAppName}_{version}_amd64.snap" (**OPTIONAL**)** - Snap that runs in amd64 environments. The amd64 is used in ctrlX COREvirtual. However, future ctrlX CORE hardware will also use amd64 architecture. So, it is recommended that a snap is also provided for this platform to avoid future inconvenience. +- **"ctrlx-{company name}-{app name}-{version}_amd64.snap" (**OPTIONAL**)** - Snap that runs in amd64 environments. The amd64 is used in ctrlX COREvirtual. However, future ctrlX CORE hardware will also use amd64 architecture. So, it is recommended that a snap is also provided for this platform to avoid future inconvenience. @@ -336,7 +338,7 @@ The following properties must be defined within the **"snapcraft.yaml"** file (s - **Title** - The general name of the app that will be shown on all sales channels and customer touch points, e.g. app overview or ctrlX App Store. This is defined together with the partner manager, as part of the business model definitions. Example: "My App" -- **Name** - The technical name of the snap. The name has to be unique in the snap universe and across all snap developer and device vendors. The snap name has to **start with "ctrlx-"** and must be **lowercase** and a **maximum length of 32 characters**. ctrlX World partners add their company name to the snap name. Example: "ctrlx-partnername-myapp" +- **Name** - The technical name of the snap. The name has to be unique in the snap universe and across all snap developer and device vendors. The snap name has to **start with "ctrlx-"** and must be **lowercase** and a **maximum length of 32 characters**. ctrlX World Partners add their company name to the snap name. Example: "ctrlx-partnername-myapp" - **Confinement** - Must be set to **"strict"** for releases. See also https://snapcraft.io/docs/snap-confinement @@ -386,24 +388,10 @@ Used interfaces (Slots & Plugs) must be documented in the **snapcraft.yaml** fil - **Debug interfaces only on demand**. By default, the app should not provide any open network debug interfaces. If debugging is required, the user should be able to enable the debug interface on demand and only after successful authentication (and authorization). In general, debug interfaces shall not be accessible without authentication and/or insufficient or even hard-coded credentials. +The following operating system interfaces which are listed here are denied or restricted for usage: + +[Reserved interfaces](appdevguide_reserved-interfaces.md), (1. Reserved slots and plugs) -The following operating system interfaces are denied or restricted for usage. See also https://snapcraft.io/docs/supported-interfaces. - -| Interface | Direction | Parameters | Exceptions | Reason | -| ----------- | ----------- | ---------| --------| ------| -| udisk2 | Plug & Slot | | | | -| system-files | Plug | * | "read=^(\\/dev\\/shm\| \\/dev\\/shm\\/.+)$", "write=^(\\/dev\\/shm\| \\/dev\\/shm\\/.+)$" | | -| snapd-control | Plug | * | | Prevent uncontrolled access to system configuration. | -|raw-volumes | Plug | | | Prevent mounting of partitions.| -|process-control | Plug | | | Prevent tampering with running processes.| -|content |Plug| content=package-certificates | |Prevent apps to act as device admin.| -|content | Plug | content=package-run | | Prevent apps to act as device admin.| -|content| Plug| content=package-assets | |Prevent apps to act as device admin.| -|content| Slot| content=auth-service | |Prevent unauthorized access, service to service authentication.| -|content| Slot| content=active-solution | |Prevent apps to act as solution snap.| -|block-devices | Plug | | | Prevent mounting of partitions.| -account-control | Plug |* | | Prevent uncontrolled access to user and group databases.| -|removable-media| Plug | | |Prevent uncontrolled access to removal media (micro sd, USB).| This list is subject to change and might be extended. If unsure, please provide the slot/plug you want to use inside your application together with justification to check whether or not this specific slot/plug is allowed and find potential alternatives. @@ -423,41 +411,12 @@ Security protocols are to be used by default. This means: - The app must provide a list of ports to be used in order to avoid conflicts. The app must therefore be robust to already open / used ports. At least a warning is to be issued to the user. -The following ports are blocked and cannot be used by an app: - -- 22 - -- 80 - -- 81 - -- 443 - -- 1338 (UDP) - -- 1880 - -- 1900 (UDP) - -- 2069 +The ports listed here are blocked and cannot be used by an app: -- 2070 -- 4840 +[Reserved interfaces](appdevguide_reserved-interfaces.md), (2. Blocked ports) -- 5355 (UDP) -- 5353 - -- 6000 - -- 7878 - -- 8069 - -- 11740 - -- 11741 This list is subject to change and might be extended. @@ -468,7 +427,7 @@ It is very likely that an app stores settings & configuration data in the applic ### 6.2 Resource Consumption and Read/Write Operations (**MANDATORY**) -Typically, more than one app runs on a ctrlX device. It is therefore very important than an app does not consume too many system resources (e.g. RAM or disk space). In addition, the available virtual memory on the device is limited to the amount of physical available memory, because the possibility of swapping unused RAM to disk is disabled on ctrlX devices. The reasons for this is the otherwise negative impact on real-time capability and flash disk lifetime. +Typically, more than one app runs on a ctrlX CORE. It is therefore very important than an app does not consume too many system resources (e.g. RAM or disk space). In addition, the available virtual memory on the device is limited to the amount of physical available memory, because the possibility of swapping unused RAM to disk is disabled on ctrlX CORE. The reasons for this is the otherwise negative impact on real-time capability and flash disk lifetime. #### 6.2.1 Resource Consumption @@ -499,7 +458,9 @@ Videos and further media can be attached. ### 7.1 ctrlX License Handling (**MANDATORY**) -A license model must be defined for each app which is part of ctrlX World. To ensure maximum usability for a ctrlX CORE user, the app must call up the ctrlX license manager API when it starts or is running to check if a license is activated. If a license is missing, the missing license will be shown to the user on a user interface (Note: This will be available after July 2021). A warning or error must be shown in case the license is missing. +ctrlX World Partner apps must use the licensing service that is operated by Bosch Rexroth. + +A license model must be defined for each app. To ensure maximum usability for a ctrlX CORE user, the app must call up the ctrlX license manager API when it starts or is running to check if a license is activated. If a license is missing, the missing license will be shown to the user on a user interface. A warning or error must be shown in case the license is missing. Each software license (SWL) bought by a customer generates one or more capabilities: @@ -509,7 +470,7 @@ Each software license (SWL) bought by a customer generates one or more capabilit - The usage of other licensing mechanisms is not allowed -- The licensing interface will be available by March 2021 +For information how to adapt an app to the licensing service please have look on the [Licensing guideline](licensing.md) !!! note @@ -612,13 +573,20 @@ For further information see https://docs.automation.boschrexroth.com Please contact your partner manager if a real-time extension might be required for your app. -## 12 Licensing (**OPTIONAL**) -If you are ctrlX World partner you must use the licensing service that is operated by Bosch Rexroth. For information how to adapt an app to the licensing service please have look on the [Licensing Page](licensing.md) +# Appendices -### Appendix -[Guide appendix](appdevguide_other-technologies.md) +[Base checklist](appdevguide_basechecks.md) +[Licensing guideline](licensing.md) + +[Reserved interfaces and ports](appdevguide_reserved-interfaces.md) + +[Guidelines for other platforms (not ctrlX OS)](appdevguide_other-technologies.md) + + +*** **Copyright** -© Bosch Rexroth AG 2021 +© Bosch Rexroth AG 2021-2023 + This guideline, as well as the data, specifications and other information set forth in it, are the exclusive property of Bosch Rexroth AG. It may not be reproduced or given to third parties without our consent. diff --git a/doc/appdevguide_basechecks.md b/doc/appdevguide_basechecks.md new file mode 100644 index 000000000..2c836fa48 --- /dev/null +++ b/doc/appdevguide_basechecks.md @@ -0,0 +1,139 @@ +# 1. Document Overview + +This document is part of the Bosch Rexroth ctrlX CORE App Development Guideline, and describes which basic aspects are checked in the Validation Process. + +Please refer to the App Development Guide for further information. + +The content of this document may be subject of change in further versions of the Validation Process. + +**** +# 2. snapcraft.yaml + + +## 2.1 Checked content + +| **Item** | **Criteria** | +| --- | --- | +| **title** | is unique and length is between 3 and 40 characters | +| **name** | matches with the snap name (technical app name) | +| **version** | follows semantic versioning (`MAJOR.MINOR.PATCH`) and does not exceed 32 characters | +| **description** | provides a short description of the App and is at least 16 characters long | +| **degree of isolation** | is set to `confinement = "strict"` | +| **grade** | is set to `grade = "stable"` | +| **restart delay** | ist set to `5` or higher | +| **plugs** | list of interfaces consumed by the snap | +| **slots** | list of interfaces provided by the snap (optional)| +| **package assets** | to exchange information | +| **package-certificates** | certificates and keys of the snap (optional) | + + +## 2.2 Additional notes + +- **Schema for snapcraft.yaml:** https://github.com/snapcore/snapcraft/blob/master/schema/snapcraft.json +- **Schema for technical app name:** "ctrlx-{company name}-{app name}-{app version}_arm64/amd64.snap" + + + +**** +# 3. package-manifest.json + + +## 3.1 Checked content + +| **Item** | **Criteria** | +| --- | --- | +| **licenses** | list of all used licenses (`licenses.name, .title, .description .required`) | +| **certificatestores** | snap service to handle keys and certificates (ptional) | + +For each given Proxy Mapping `services.proxyMapping[i]`: +| **Item** | **Criteria** | +| --- | --- | +| **name** | is only lowercase, contains `.web` and is unique in the list | +| **url** | is only lowercase and starts with `/` | +| **binding** | is valid / not empty | + +## 3.3 Additional notes + +- the *package-manifest.json* file must provide service entries for all services which are used in in the *portlist-description.json* file (proxy.service-name, see 3.) +- the *package-manifest.json* file must provide service entries for all services which are used in in the *unixsocket-description.json* file (socket name and accessibility, see 4.) + +**** +# 4. portlist-description.json + +## 4.3 Checked content + +| **Item** | **Criteria** | +| --- | --- | +| **id** | is available and matches to the technical app name (see also **name** entry in *snapcraft.yaml*) | + +For each given port in the description (`ports[i]`): +| **Item** | **Criteria** | +| --- | --- | +| **number**| has 3 to 5 digits and exists only once in the list| +| **purpose**| has at least 16 characters| +| **application-protocol**| has at least 3 characters| +| **binding**| (Network Binding Interface) is either localhost or IP| +| **routing** |is either internal or external| +| **service-name** |starts with `ctrlx-` or `bosch-`, is lowercase and exists only once in the list| +| **default-state**| is either `open` or `closed`| + + +## 4.4 Additional Notes + +- **Number of open ports**: For security reasons, the number of open ports should be limited to 3 +- **Unwanted direct external access**: The following configuration should be avoided: + - `"protocol = HTTP or HTTPS"`, `"binding = IP"` and `"routing = external"` + +- **Wrong configuration**: these configurations are considered as mismatch: + - `"protocol not HTTP or HTTPS"`, `"binding = IP"` and `"routing = internal"` + - `"protocol not HTTP or HTTPS"`, `"binding = localhost"` and `"routing = external"` + +- **Port conflicts with reserved ports**: + - Ports that are listed in the [Reserved interfaces and ports](appdevguide_reserved-interfaces.md) will generate a vakidation error + +**** +# 5. unix-socket-description.json + +## 5.1 Checked content + +For each given socket `(sockets[i])` +| **Item** | **Criteria** | +| --- | --- | +| **name** |is only lowercase, end with `.sock` or `.socket` and exists only once in the list| +| **purpose**| is at least 16 characters long| +| **accessibility** |is either `internal` or `external`| + +## 5.2 Additional notes + +- only web sockets (name contains `.web`) can be used for external accessibility + +**** +# 6. slotplug-description.json + +## 6.1 Checked content + +For each given slot `(slots[i])` and plug `(plugs[i])` +| **Item** | **Criteria** | +| --- | --- | +| **name** |is only lowercase| +| **purpose** |is at least 16 characters long| + +## 6.2 Additional notes +- both for slots an plugs, the max number of entries should be 8 +- All slots and plugs in the *slotplug-description.json* must be available in the *snapcraft.yaml* file also, and vice versa + +# 7. Scopes (${snapname}.scopes.json) + +## 7.1 Checked content + +| **Item** | **Criteria** | +| --- | --- | +|**id** | must be assigned (optional) | +| **required-permissions** | must match with the used permissions (optional) | + + + +**** +**Copyright** +© Bosch Rexroth AG 2023 - +This document, as well as the data, specifications and other information set forth in it, are the exclusive property of Bosch \ No newline at end of file diff --git a/doc/appdevguide_other-technologies.md b/doc/appdevguide_other-technologies.md index 56b66f728..b2c81014b 100644 --- a/doc/appdevguide_other-technologies.md +++ b/doc/appdevguide_other-technologies.md @@ -74,4 +74,4 @@ In addition to general aspects, Node-RED Palettes must support the following top **Copyright** -Copyright (c) 2022 Bosch Rexroth AG \ No newline at end of file +SPDX-FileCopyrightText: Bosch Rexroth AG \ No newline at end of file diff --git a/doc/appdevguide_reserved-interfaces.md b/doc/appdevguide_reserved-interfaces.md new file mode 100644 index 000000000..8ec3a6366 --- /dev/null +++ b/doc/appdevguide_reserved-interfaces.md @@ -0,0 +1,109 @@ +# Document Overview + +This document is part of the Bosch Rexroth ctrlX OS App Development Guideline, and describes which interfaces (port, plugs and slots) are reserved and may not be used by a ctrlX OS App + +Please refer to the App Development Guide for further information. + +The content of this document may be subject of change in future. + +# 1. Reserved slots and plugs + + + +The following operating system interfaces are denied or restricted for usage. See also https://snapcraft.io/docs/supported-interfaces. + +| Interface | Direction | Parameters | Exceptions | Reason | +| --- | --- | --- |--- | --- | +| system-files | Plug | null | "'read=^(\\/dev\\/shm\| \\/dev\\/shm\\/.+)', 'write=^(\\/dev\\/shm\| \\/dev\\/shm\\/.+)$'" | Prevent access to system files, except shared memory | +|account-control|Plug|null|null|Prevent uncontrolled access to user and group databases| +|snapd-control|Plug|null|null|Prevent uncontrolled access to system configuration| +|content|Plug|content=package-certificates|null|Prevent apps to act as device admin| +|content|Plug|content=package-run|null|Prevent apps to act as device admin| +|content|Slot|content=active-solution|null|Prevent apps to act as solution snap| +|content|Slot|content=auth-service|null|Prevent unauthorized access, service to service authentication| +|content|Slot|content=rda-proxy-service|null|Prevent uncontrolled access to proxy service| +|content|plug|content=rda-proxy-service|null|Prevent unacontrolled access to proxy service| +|block-devices|plug|null|null|Prevent mounting of partitions| +|raw-volumes|Plug|null|null|Prevent mounting of partitions| +|udisk2|Slot|null|null|Prevent mounting of partitions| +|udisk2|Plug|null|null|Prevent mounting of partitions| +|docker|Plug|null|null|Prevent access to docker socket| +|docker-support|Slot|null|null|Prevent operating as the docker daemon because of possibility of privileg escalation| +|docker-support|Plug|null|null|Prevent operating as the docker daemon because of possibility of privileg escalation| +|acrn-support|Plug|null|null|Not being supported and potential dangerous| +|bool-file|Plug|null|null|Bool files are normally located in /sys - no write access to this folder| +|browser-support|Plug|null|null|Denylist| +|classic-support|Plug|null|null|Classic support bypass all snapd security mechanism| +|core-support|Plug|null|null|Deprecated| +|cpu-control|Plug|null|null|Allows setting CPU tunables| +|daemon-notify|Plug|null|null|Allows sending daemon status changes to the service manager.| +|dm-crypt|Plug|null|null|Storage support including encryption is part of the DeviceAdmin| +|firewall-control|Plug|null|null|Firewall app handles firewall rules| +|fpga|Plug|null|null|Allows access to fpga subsystem| +|use-support|Plug|null|null|Allows access to fuse subsyten| +|fwupd|Plug|null|null|Enabling privileged access to update UEFI firmware| +|gconf|Plug|null|null|Allows configuration of Gconf, typically used by old GNOME libs| +|gpg-keys|Plug|null|null|Allows reading GNU Privacy Guard (GPG) user configuration and keys as well as enabling GPG’s random seed to be updated| +|gpio-control|Plug|null|null|Super-privileged access to gpio pins| +|gpio-memory-control|Plug|null|null|Allows write access to all GPIO memory| +|greengrass-support|Plug|null|null|Allows operating as the Greengrass service to access resources and syscalls necessary to run Amazon Greengrass services and lambda functions| +|hardware-random-control|Plug|null|null|Enables control over the hardware random number generator by allowing read/write access to /dev/hwrng| +|hidraw|Plug|null|null|Enables raw access to USB and Bluetooth Human Interface (hidraw) devices. This interface is restricted because it provides privileged access to hardware devices| +|home|Plug|null|"read:all"|Allows access to non-hidden files owned by the user in the user’s home directory. There is no home folder for the users on ctrlX CORE| +|hugepages-control|Plug|null|null|Handle memory is part of the DeviceAdmin| +|intel-mei|Plug|null|null|Enables access to the Intel MEI management interface| +|io-ports-control|Plug|null|null|Allows access to all I/O ports, including the ability to write to /dev/port to change the I/O port permissions, the privilege level of the calling process, and disabling interrupts| +|ion-memory-control|Plug|null|null|Allows access to the Android ION memory allocator, a Linux kernel feature for managing one or more memory pools| +|kernel-module-control|Plug|null|null|Provides the ability to insert, remove and query kernel modules. This interface gives privileged access to the device| +|kernel-module-load|Plug|null|null|Provides the ability to load, or deny loading, specific kernel modules. This interface gives privileged access to the device| +|kubernetes-support|Plug|null|null|Allows operating as the Kubernetes service and running application containers| +|kvm|Plug|null|null|Allows access to the /dev/kvm device, providing privileged access and control of the KVM hypervisor| +|libvirt|Plug|null|null|Enables access to the libvirt control socket, which gives privileged access to control libvirtd on the host| +|login-session-control|Plug|null|null|Allows setup of login sessions and grants privileged access to user sessions.| +|lxd|Plug|null|null|Allows access to the LXD API via the socket provided by the lxd snap| +|lxd-support|Plug|null|null|Enables operating as the LXD service| +|microstack-support|Plug|null|null|Interface enables multiple service access for the Microstack infrastructure| +|mount-control|Plug|null|"Except storage-extension concept"|Allows the mounting and unmounting of both transient (non-persistent) and persistent filesystem mount points. This interface gives privileged access to the device| +|multipass-support|Plug|null|null|Allows operating as the Multipass service| +|netlink-audit|Plug|null|null|Allows access to the kernel part of the Linux Audit Subsystem through Netlink| +|netlink-connector|Plug|null|null|Allows communication through the kernel Netlink connector| +|netlink-driver|Plug|null|null|Allows a kernel module to expose itself to user-space via the Netlink protocol, typically to transfer information between the kernel and user-space processes| +|network-control|Plug|null|null|Gives access to wifi credentials| +|network-manager|Plug|null|null|Gives access to wifi credentials| +|network-manager-observe|Plug|null|null|Gives access to wifi credentials| +|network-setup-control|Plug|null|null|Gives access to wifi credentials| +|network-setup-observe|Plug|null|null|Gives access to wifi credentials| + |packagekit-control|Plug|null|null|Allows control of the PackageKit service, giving privileged access to native package management on the system| +|password-manager-service|Plug|null|null|Provides access to the global password manager services provided by popular desktop environments, such as Secret Service and Kwallet| +|personal-files|Plug|null|null|Provides access to the specified files in the user’s home. This interface gives privileged access to the user’s data| +|physical-memory-control|Plug|null|null|Allows write access the to physical address space via the /dev/mem device| +|physical-memory-observe|Plug|null|null|Allows read access the to physical address space via the /dev/mem device| +|polkit-interface|Plug|null|null|Provides daemons with the permission to use the polkit authorisation manager (polkitd) to make access control decisions for requests from unprivileged clients| +|process-control|Plug|null|null|Prevent tampering with running processes| +|scsi-generic|Plug|null|null|Allows read and write access to SCSI Generic driver (sg) devices| +|sd-control|Plug|null|null|Allows for the management and control of SD cards on certain devices using the DualSD driver| +|shared-memory|Plug|null|"shared-memory=^(datalayer-shm)$"|Allows two snaps to communicate with each other using a specific predefined shared-memory path or directory in /dev/sh| +|snap-refresh-control|Plug|null, "Exceptions":null |Super privileged interface to allow extended control, via snapctl, of refreshes targeting the snap| +|ssh-keys|Plug|null|null|Allows a user’s SSH (Secure Socket Shell) configuration to be read, along with both their public and private keys| +|storage-framework-service|Plug|null|null|Allows operating as, or interacting with, the Storage Framework - storage is part of the DeviceAdmin| +|system-backup|Plug|null|null|Provides read-only access to the system via /var/lib/snapd/hostfs. This interface gives privileged access to system data| +|system-trace|Plug|null|null|Enables the monitoring and control of any running program, via kernel tracing facilities. This interface is restricted because it gives privileged access to all processes on the system and should only be used with trusted apps| +|tee|Plug|null|null|Permits access to Trusted Execution Environment (TEE) devices via the TEE subsystem in the Linux kernel| +|tpm|Plug|null|null|tpm allows access to the Trusted Platform Module (tpm) device, /dev/tpm0, and to the in-kernel resource manager, /dev/tpmrm0, on recent kernels (at least v4.12)| +|uhid|Plug|null|null|Enables the creation of kernel USB Human Interface Devices (HID) from user-space, via /dev/uhid , giving privileged access to HID transport drivers| +|uinput|Plug|null|null|Super privileged interface to allows write access to /dev/uinput on the host system for emulating input devices from userspace that can send input events| + + + # 2. Blocked ports + +The following ports are blocked and cannot be used by an app. + +| Reserved by | Reserved ports | +| --- | --- | +| ctrlX OS | 22, 80, 81, 443, 1338, 1880, 1900, 2069, 2070, 4840, 5355, 5353, 6000, 7878, 8069, 11740, 11741 | +| Other apps | 1884, 2883, 4222, 8000, 8080, 8088, 8142, 8840, 8883, 16620, 16700, 16701, 16800, 16810, 18500, 47808, 48898, 49250-50250, 56090 | + + **** +**Copyright** +© Bosch Rexroth AG 2023 - +This document, as well as the data, specifications and other information set forth in it, are the exclusive property of Bosch \ No newline at end of file diff --git a/doc/changelog.md b/doc/changelog.md index 582023b7d..3fa7b6bde 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -1,9 +1,15 @@ ## Software Development Kit for ctrlX AUTOMATION -### Version 1.20.0 April 02, 2023 +### Version 2.2.0 August, 2023 -* Add new samples in angular and go -* Update documentation +* Use base: core22 as basis for each sample project +* Bump sample projects to core22 +* Use new ctrlX Data Layer with version 2.x + +### Version 1.20.0 March 10, 2023 + +* Documentation and examples for the use of (external) media added +* Documentation how to use an extenable denylist ### Version 1.18.0 November 30, 2022 diff --git a/doc/connecting_qemu_vm_ctrlx.md b/doc/connecting_qemu_vm_ctrlx.md index f348bd2f5..984e8bc06 100644 --- a/doc/connecting_qemu_vm_ctrlx.md +++ b/doc/connecting_qemu_vm_ctrlx.md @@ -50,7 +50,7 @@ To connect the Windows host with the ctrlX COREvirtual a so called TA ![ctrlX CORE](images/ctrlx-sdk.png) -The connection string for Data Layer access in this case is: +The connection string for ctrlX Data Layer access in this case is: tcp://boschrexroth:boschrexroth@192.168.1.1 @@ -58,7 +58,7 @@ The connection string for Data Layer access in this case is: The ctrlX CORE is connected to the Windows host via its network adapter. -The connection string for Data Layer access e.g. is: +The connection string for ctrlX Data Layer access e.g. is: tcp://boschrexroth:boschrexroth@10.52.244.123 diff --git a/doc/data-exchange.md b/doc/data-exchange.md new file mode 100644 index 000000000..c09393e78 --- /dev/null +++ b/doc/data-exchange.md @@ -0,0 +1,64 @@ +# Introduction + +You can use external storage (μSD card / USB device) for data exchange purpose (removable media). Can be used from Device Admin 1.16. + +If a storage extension is required, please see documentation of [Storage extension](storage-extension.md). + + +!!! attention + - **The data on the external storage (μSD card / USB device) is not encrypted. Others can unplug the device and can read the data on another devices.** + - **The storage with ext4 and fat32 format are supported (formatting can be done in ctrlX UI: Settings->Storage).** + - **There is no exclusive access to the medium for a singe application. Your data can be overwritten by other applications.** + - **The data written to the storage cannot be encrypted.** + + +## Requirements + +A storage is inserted, formatted and mounted: + +If the storage is not formatted as fat32 or ext4, please format it first. + +To format or mount a storage, use the according buttons in the details window of the Storage. The details window appears, when you select the according tile of the storage: + +After the storage is mounted, the path is displayed on the details page of the storage: + +Alternatively, the mount point is determinable in the ctrlX Data Layer (in Settings menu) under **system/resources/storage** + +## Configuration steps +To access the storage from your app (e.g. storage-test), use the **removable-media** interface as plug in the **[snapcraft.yaml](https://snapcraft.io/docs/snapcraft-yaml-reference)** of your application: + + +!!! example + ```yaml title="snapcraft.yaml" + name: storage—test # you probably want to 'snapcraft register ' + base: core20 # the base snap is the execution environment for this snap + version: '0.1' # just for humans, typically 'i.2+git' or '1.3.2' + summary: Single—line elevator pitch for your amazing snap # 79 char long summary + description: | + This is my—snap's description. + You have a paragraph or two to tell the most important story about your snap. + Keep it under 100 words though, + we live in tweet space and your description wants to look good in the snap store. + + grade: devel # must be 'stable' to release into candidate/stable channeis + confinement: strict # use 'strict' once you have the right plugs and slots + architectures: + - all + parts: + storage: + plugin: dump + source: storage + apps: + storage: + command: bin/storage + daemon: simple + plugs: + - removab1e—media + ``` + + +## Usage + +- Install your app in ctrlX UI via Settings → Apps → Install from file. + +- After installation, you have permissions to read and write data in the mounted directory. The path is displayed in Storage details page `/media/`. diff --git a/doc/datalayer.md b/doc/datalayer.md index f05bd151d..52b93fe5f 100644 --- a/doc/datalayer.md +++ b/doc/datalayer.md @@ -29,98 +29,6 @@ Similarly, a singleton resource ```account``` inside the sub-collection resource ```accounts``` can be identified as follows: ```/customers/{customerId}/accounts/{accountId}```. -## Node naming conventions - -### Use small capital node names - -Always use small capital node names! - -### Hierarchical relationships - -Use subnodes to indicate hierarchical relationship between resources - -``` Text -device-management -device-management/managed-devices -device-management/managed-devices/{id} -device-management/managed-devices/{id}/scripts -device-management/managed-devices/{id}/scripts/{id} -``` - -### Use nouns to represent resources - -Nodes should refer to a resource that is a thing (noun) instead of referring to -an action (verb) because nouns have properties which verbs do not have - similar -to resources have attributes. Some examples of a resource are: - -* Users of the system -* User Accounts -* Network Devices etc. - -and their resource URIs can be designed as below: - -``` Text -device-management/managed-devices -device-management/managed-devices/{device-id} -user-management/users/ -user-management/users/{id} -``` - -### Use verbs to represent actions - -Has to return method in metadata. - -### Use hyphens (-) to improve the readability of nodes - -To make your nodes easy for people to interpret, use the hyphen (-) -character to improve the readability of names in long path segments. - -``` Text -inventory-management/managed-entities/{id}/install-script-location //More readable -inventory-management/managedEntities/{id}/installScriptLocation //Less readable -``` - -**Do not use underscores ( _ )** -It's possible to use an underscore in place of a hyphen to be used as -separator. But depending on the applications font, it's possible that the -underscore (_) character can either get partially obscured or completely hidden -in some browsers or screens. - -To avoid this confusion, use hyphens (-) instead of underscores ( _ ). - -``` Text -inventory-management/managed-entities/{id}/install-script-location //More readable -inventory_management/managed_entities/{id}/install_script_location //More error prone -``` - -### Do not use file extensions - -File extensions look bad and do not add any advantage. Removing them decreases -the length of URIs as well. No reason to keep them. - -Apart from above reason, if you want to highlight the media type of API using -file extension then you should use metadata type. - -``` Text -device-management/managed-devices.xml /*Do not use it*/ -device-management/managed-devices /*This is correct path*/ -``` - -### Never use CRUD function names in path - -Paths should not be used to indicate that a CRUD (Create/Read/Update/Delete) -function is performed. Paths should be used to uniquely identify resources and -not any action upon them. Request methods should be used to indicate which CRUD -function is performed. - -``` Text -browse device-management/managed-devices //Get all devices -create device-management/managed-devices //Create new Device -read device-management/managed-devices/{id} //Get device for given Id -write device-management/managed-devices/{id} //Update device for given Id -delete device-management/managed-devices/{id} //Delete device for given Id -``` - ## Provider A provider is responsible for nodes. One provider can handle an unlimited amount diff --git a/doc/debug-overview.md b/doc/debug-overview.md index ce36e83b8..2ca82af4d 100644 --- a/doc/debug-overview.md +++ b/doc/debug-overview.md @@ -7,7 +7,7 @@ In general there are three different ways to debug. Here is an overview of the d | # | Description | Usage |Disadvanges | | :--| :-------------------------| :----------------------------------------------------- |:-------------| | __1__| __Snap Logs__
output in terminal and logbook
| | | -| __2__| __Debugging in Build Environment__
+ Connection to Data Layer via TCP
| | | +| __2__| __Debugging in Build Environment__
+ Connection to ctrlX Data Layer via TCP
| | | | __3__| __Remote Debugging__ | | | We recommend to test your application extensively in the build environment (type #2). Testing an application running in it's confined Ubuntu Core snap enviroment can be done by looking at the snap logs (type #1). Remote Debugging (type #3) while the snap is running in the confined Ubuntu Core snap environment of a ctrlX CORE should only be used as the last step, if the other two debug types don't help to debug your application. diff --git a/doc/dotnet.md b/doc/dotnet.md index 631faef18..e640edeae 100644 --- a/doc/dotnet.md +++ b/doc/dotnet.md @@ -133,7 +133,7 @@ Now you're ready to code .NET on ctrlX! ### Provider Concepts -There different concepts to write a Data Layer provider: +There different concepts to write a ctrlX Data Layer provider: #### Create and register nodes with individual node handlers @@ -150,7 +150,7 @@ __Recommendation:__ __Pros:__ -+ The Data Layer is managaging your node hierarchy: No implementation of _OnBrowse()_ required (return DL_UNSUPPORTED or DL_OK with an empty list). ++ The ctrlX Data Layer is managaging your node hierarchy: No implementation of _OnBrowse()_ required (return DL_UNSUPPORTED or DL_OK with an empty list). __Contras:__ @@ -175,7 +175,7 @@ __Recommendation:__ __Pros:__ -+ The Data Layer is managaging your node hierarchy: No Implementation of _OnBrowse()_ required (return DL_UNSUPPORTED or DL_OK with an empty list). ++ The ctrlX Data Layer is managaging your node hierarchy: No Implementation of _OnBrowse()_ required (return DL_UNSUPPORTED or DL_OK with an empty list). __Contras:__ @@ -189,7 +189,7 @@ __Samples:__ #### Virtual provider (lightweight): Register on wildcard and manage virtual nodes Create just _one_ node with a single node handler, registered to a _wildcard_ address (e.g. myroot/**) and managing the nodes for your own. This _lightweight_ handler returns _virtual_ nodes in _OnBrowse()_ method. -See Data Layer documentation for details. +See ctrlX Data Layer documentation for details. 1 x CreateNode 1 x Register @@ -206,7 +206,7 @@ __Pros:__ __Contras:__ -+ The Data Layer is _not_ managaging your node hierarchy: You have to return the valid data in _OnBrowse()_. ++ The ctrlX Data Layer is _not_ managaging your node hierarchy: You have to return the valid data in _OnBrowse()_. __Samples:__ @@ -257,27 +257,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - - +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/doc/extenable-denylist.md b/doc/extenable-denylist.md new file mode 100644 index 000000000..5768a8796 --- /dev/null +++ b/doc/extenable-denylist.md @@ -0,0 +1,90 @@ + +# How to protect content interface connections + +## Introduction + Each app can provide or consume multiple interface connections. The usage of some of these connections can destroy the integrity of the system. + These connections are defined in the denylist which avoids an automatic connection by the Device Admin. + +### Extend the denylist + The app developer may want to protect own content interfaces and restrict them to specific apps. An example for such a connection is an unix socket to communicate + between two apps (server and client). The functionality of the extended denylist was created for this purpose. + + The app should be able to indicate whether a particular content interface that it declares should be protected, and if so, what rules it can use. + Therefore, the app developer can provide a denylist.json as a package asset. + + In order to make this possible, a few requirements must be met. + +!!! attention + - **The denylist.json must be part of the app and must not be changeable at runtime** + - **The denylist.json must be part of the validation and checked by Rexroth** + - **denylist.json is only accepted by Rexroth signed apps** + - **Connectors must include partner/OEM prefix to avoid interferences** + + +## Requirements + + The extendable deny list is part of a customer app. Only signed customer apps can provide an own deny list, all deny lists in unsigned apps are ignored. + + The denylist.json file is located in the `package-assets` folder of the app, which is connected to the package-assets of the Device Admin. + The *.package-manifest.json file is also located in this folder. + + +!!! example + `$SNAP/package-assets/$SNAP_NAME/$SNAP_NAME.package-manifest.json` + + Only content interface (see: `https://snapcraft.io/docs/content-interface`) connections are supported! The content target has to contain the "parent" app name, e.g. the app "ctrlx-customer-app" can provide the protected content interface "ctrlx-customer-app-abc". + +### Content interfaces + Then there is a differentiation between content interfaces and all other interfaces. + If the interface is a content interface the content property will be compared. If they where equal, the connection is allowed. + +!!! info + ```yaml title="plugs" + + ... + plugs: + ctrlx-customer-app-abc: + interface: content + content: ctrlx-customer-app-abc + target: $SNAP_DATA/abc-folder + ... + ``` + ```yaml title="slots" + ... + slots: + ctrlx-customer-app-abc: + interface: content + content: ctrlx-customer-app-abc + source: + write: + - $SNAP_DATA/abc-folder-name/$SNAP_NAME + ... + ``` + + Following this rule leads to a connection for the slot ctrlx-customer-app-abc with the plug ctrlx-customer-app-abc. + + The rules (location, deny list entries, ...) will be checked during the validation process. + +## denylist.json + +!!! example + `$SNAP/package-assets/$SNAP_NAME/denylist.json` + + The denylist.json has the following format: + +!!! info + ```json title="denylist.json" + + [ + { + "interface": "content", + "direction": "slot", + "parameters": "content=ctrlx-customer-app-data" + }, + { + "interface": "content", + "direction": "plug", + "parameters": "content=ctrlx-customer-app-additional-data" + } + ] + ``` diff --git a/doc/fbs2plc.md b/doc/fbs2plc.md index 57157ae81..b6a2d3eb8 100644 --- a/doc/fbs2plc.md +++ b/doc/fbs2plc.md @@ -33,14 +33,14 @@ For fbs2plc.exe: ### 3. sdk-cpp-alldata as Provider -Reading and writing a Flatbuffer Data Layer node within our IEC 61131-3 code requires an instance which provides this node to the ctrlX Data Layer. Therefor we use the snap sdk-cpp-alldata deployed by the ctrlX AUTOMATION SDK in the folder __samples-cpp/datalayer.provider.all-data__. +Reading and writing a Flatbuffer ctrlX Data Layer node within our IEC 61131-3 code requires an instance which provides this node to the ctrlX Data Layer. Therefor we use the snap sdk-cpp-alldata deployed by the ctrlX AUTOMATION SDK in the folder __samples-cpp/datalayer.provider.all-data__. This snap has to be build and installed in the ctrlX CORE, see: * [Quick Start Guide](setup_qemu_ctrlx_works.md) * [Building Snaps](samples.md) -If the snap is installed and the ctrlX CORE is in Operation Mode it will provide a Flatbuffer variable with this Data Layer path: __sdk-cpp-alldata/dynamic/fbs__ +If the snap is installed and the ctrlX CORE is in Operation Mode it will provide a Flatbuffer variable with this ctrlX Data Layer path: __sdk-cpp-alldata/dynamic/fbs__ This node can be read, changed and written by our IEC 61131-3 sample code. @@ -137,7 +137,7 @@ The PLC program should run without failure. ### 4. Check the Flatbuffer Access * From a web browser login into your ctrlX CORE Web UI -* Select Settings - Data Layer -* Expand the Data Layer tree: sdk-cpp-alldata/dynamic/fbs +* Select Settings - ctrlX Data Layer +* Expand the ctrlX Data Layer tree: sdk-cpp-alldata/dynamic/fbs The values of the x, y, z variables should be changed by our PLC program. diff --git a/doc/images/artifacts.png b/doc/images/artifacts.png new file mode 100644 index 000000000..7cb5752b6 Binary files /dev/null and b/doc/images/artifacts.png differ diff --git a/doc/licensing.md b/doc/licensing.md index 7c08bb183..7bdb6877f 100644 --- a/doc/licensing.md +++ b/doc/licensing.md @@ -32,18 +32,18 @@ Please refer to the App Development Guide for further information. # 1 Introduction -Licenses are issued by the Bosch Rexroth Licensing Center [https://licensing.boschrexroth.com](https://licensing.boschrexroth.com). +From a user's perspective, device licenses are managed by the Bosch Rexroth Licensing Center [https://licensing.boschrexroth.com](https://licensing.boschrexroth.com). -There a user can assign licenses to devices and can download a capability response, which contains all assigned licenses for a specific device. The downloaded capability response can than be deployed on the corresponding device. +Using the portal it is possible to assign licenses to a device and to download a capability response, which contains all assigned licenses for a specific device. The downloaded capability response can than be deployed to the corresponding device. -The ctrlX CORE User Interfaces comes with a screen to upload the provided capability response and the possibility to check the currently available licenses on the device. The license manager feature on the ctrlX CORE offers a restful API via an internal unix domain socket, that can be used by Apps to request and release a specific license. +The ctrlX CORE User Interfaces therefore provides a page which allows to upload a capability response and to check the currently available licenses on the device. For developers, the ctrlX CORE offers a restful API via an internal unix domain socket which can be used by an app to request and release a specific license. # 2 License Enforcement -In order to integrate license enforcement into your App, please follow the instructions below. +To integrate an app into the license management, please follow the instructions below. ## 2.1 Add Content Plug to snapcraft.yaml () -To get access to the unix domain socket that provides the restful API, add the following content plug to the snapcraft.yaml: +To get access to the unix domain socket that provides the restful API, add the following content plug definition to the snapcraft.yaml: ```yaml plugs: @@ -53,51 +53,42 @@ plugs: target: $SNAP_DATA/licensing-service ``` -This will create a folder "license-service" during installation of the App on the ctrlX CORE and provide access to the unix domain socket "licensing-service.sock". - -## 2.2 Adapt package-manifest.json () - -The App shall provide a human readable text and a description with it´s package-manifest.json for each license that the App supports. -The "required" flag indicates, if the license is necessary for operation. Optional licenses (flag is false) extends the functionality of an application. - -``` json -"licenses": [ - { - "name": "SWL-XCx-FRW-BASIC_FOOBAR-NNNN", - "title": "ctrlX CORE - Foobar License", - "description": "Unlock the App's functionality.", - "required": true - }, - { - "name": "SWL-XCx-FRW-ADVANCED_FOOBAR", - "title": "ctrlX CORE - Foobar License Extension", - "description": "This license extends the functionality of the App.", - "required": false - } - ], - +This will create a folder "license-service" during installation of the app on the ctrlX CORE and provide access to the unix domain socket "licensing-service.sock" which will be located in the folder. + +## 2.2 Adapt package-manifest.json + +The app shall provide information in the package-manifest about each license that is supported. Description and title shall be human readable. +The "required" flag indicates whether a license is mandatory to use the application. Set the flag to true when the license is required and to false, when the license is optional. + + ```json + "licenses": [ + { + "name": "SWL-XCx-FRW-BASIC_FOOBAR-NNNN", + "title": "ctrlX CORE - Foobar License", + "description": "Unlock the App's functionality.", + "required": true + }, + { + "name": "SWL-XCx-FRW-ADVANCED_FOOBAR", + "title": "ctrlX CORE - Foobar License Extension", + "description": "This license extends the functionality of the App.", + "required": false + } + ], ``` - - - -## 2.3 Use REST API to Enforce Licenses +## 2.3 Use REST API to enforce licenses ### 2.3.1 License Integration -A license model must be defined for each ctrlX CORE App, so that users have the same experience across all Apps when it comes to licensing. The App shall enforce licensing, according to the App's business model as part of the contract addendum. - -Each software license (SWL) bought by a customer generates one or more capabilities for an App on a ctrlX CORE. -Every App has to aquire a license capability from the ctrlX CORE license pool when it starts, and while it is running to check if the license is activated or removed. -One or more licenses may be defined for a particular App. In case of multiple licenses, each license has to be aquired separately (unique license ID for each license) from the ctrlX License Manager. +How an app reacts when no license is present or the license is removed during runtime, can be freely chosen by the app. Nevertheless, to provide a unique user experience across multiple apps, the following best practices are recommended. -If the license is not needed anymore, it should be returned to the license pool. This is also necessary if an App is stopped or uninstalled. -If an application crashes and the license was not returned properly, a reboot of the device is required. The reboot resets the license pool and all licenses can be aquired again. +The app should acquire the license when started or (each time) when a function is called which requires a license. Additionally, the app should check whether the license is still present on the device in regular intervals or if the license has been removed or expired. Therefore, either release and re-acquire the license or use the getCapabilities() function. This applies for both, mandatory and optional, types of licenses. -It is recommended to return the license back to the pool to re-aquire it again from time to time. So the App can detect if an license was removed or has expired. With this method, the App can detect license expiration very easily, and it does not need to handle expiration time by itself. +In case a license is not required anymore - e.g. when the app is stopped or uninstalled - the license should be released so that it is returned to the license pool and can be acquired by another app. Otherwise, the license will become available again only after a reboot of the device. -If a license is missing, an according warning or error must be shown, and the user should be informed, which licences are defined for the App. +In case a license is missing, a warning or an error shall be displayed and/or logged and the user should be informed which licences are required to execute the specific functionality of the app. !!! important @@ -124,39 +115,34 @@ Implementing this API, an app is able to -### 2.3.3 License ID +### 2.3.3 Acquiring & releasing a license -The API call to aquire a license generates a unique license ID for that particular license -name. This unique ID can be stored in temp file. +Acquiring a license generates a unique license ID for that particular license. > ![](images/licensing2.png) -Hint: Know more about mounting temporary disk in memory system type:tmpfs from snap documentation. +This ID is required to release the license. Therefore, this ID should be stored in a directory which is not affected when your application goes into a faulty state and needs to be restarted. The usage of /tmp is recommended for this. +!!! hint + Know more about mounting temporary disk in memory system type:tmpfs from snap documentation. -### 2.3.4 Capability Response -The capability response contains list of activated license capabilities for the particular ctrlX CORE device. The App shall verify / check the licenses, which are assigned to the App, with the licenses from capabilities from response. +### 2.3.4 Available licenses on the device (activated capabilities) +Upon request, an app may retrieve the list of available licenses on the device including all details (e.g. expiration, counter, ...). This may be used to check whether a specific license is available (and not in use) before trying to acquire it. +Nevertheless, this is optional - it is sufficient to just try to acquire a license and then check whether the acquisition request was successful. -Sample capability response: +Sample response: > ![](images/licensing1.png) +### 2.3.5 Update license status +The API allows to upload a capability response from the license portal to update the license status on the device (e.g. add new licenses). This functionality is not required by an app itself. # 3 Licensing Modes ## 3.1 Overview - -On a **ctrlX CORE** controller, an App specific license is provided in the ctrlX CORE License Manager, if an according license capability response file was uploaded to the ctrlX CORE. -The capability response file contains the App specific key, for example , and the License Manager returns information for this license key. - -On a **ctrlX COREvirtual**, currently no licenses for productive use are available . -To allow a user to run and evaluate an App that enforces licensing on the ctrlX COREvirtual, the runtime on the ctrlX COREvirtual is limited to four hours - -The following table lists the three different license mode on a ctrlX CORE and the ctrlX COREvirtual, together with additional information which is provided by the License Manager for the specific license type. - - +The license management on the **ctrlX CORE** supports several different licensing modes. THe following table gives an overview about the license modes. | License Mode | Target | Key | Usage | Additional information | |---|---|---|---|---| @@ -165,22 +151,26 @@ The following table lists the three different license mode on a ctrlX CORE and t | 10 Day Trial License |ctrlX CORE |`SWL_XCR_{YOUR_APP_LICENSE_CODE}` | optional |`isPermanent` flag is `false` |Four Hour Engineering Demo License |ctrlX COREvirtual|`SWL_XCR_ENGINEERING_4H`|optional|(none specific) +As displayed in the table, there is only the "four hour engineering demo license" available on the **ctrlX COREvirtual**, which allows to evaluate a new app for a limited time (the trlX COREvirtual is terminated after four hours to prevent productive use) -These different license modes, and the expected behaviour of the App for these modes, are briefly described below. +The different license modes, and the expected behaviour of the App for these modes, are briefly described below. ## 3.2 ctrlX CORE Main License **Purpose:** Standard License **Description:** + - This is the standard license that a user obtains when buying an app. Therefore, the support of this license mode is **mandatory**. - The license is obtained (bought) in the Bosch Rexroth Licensing Center and then assigned to a specific device by the user. - The standard license can be either permanent (unlimited) or time based (expires) **Expected App Behaviour**: + - The app shall start and run as intended, when the standard license is available. - If acquiring a license is not possible (no license is available), the app shall inform the user that a license needs to be obtained. -- In case of time based licenses, the app should inform the user on time before the license expires. As a best practice, a user should be informed four weeks prior to expiration. +- In case of time based licenses, the app should inform the user on time before the license expires. As a best practice, a user should be informed +four weeks prior to expiration. - When no standard app specific license is available on the device, an app shall only run if one of the other licenses is active. @@ -189,6 +179,7 @@ These different license modes, and the expected behaviour of the App for these m **Purpose:** Avoid machine downtime **Description:** + - On a ctrlX CORE, the user has the possibility to activate a special mode that is called "Temporary usage rights". The mode can be activated using the License Manager UI. - Enabling this mode allows users to operate the ctrlX CORE in a productive environment for ten consecutive days. The single purpose of this mode is to prevent a downtime when a defect device is replaced and no licenses have been assigned, yet. ==**This mode can only be activated once on a device**== - Within these ten days, the user has to either add licenses to the new device or move the licenses from the broken device to the replacement device. @@ -199,43 +190,46 @@ These different license modes, and the expected behaviour of the App for these m **Expected App Behaviour:** - Support of this license is **mandatory**. - - The App is informed with the `tampered` flag which is set to `true` in the response when acquiring such a license from the License Manager. - + - The app is able to detect whether the system runs in this mode by evaluating the `tampered` flag in the response to the acquisition request (the flag is set to `true`) + - When this mode is active, the app should work as if a standard license is available. ## 3.4 ctrX CORE 10 Day Trial License **Purpose:** Test Mode on ctrlX CORE Hardware **Description:** -- Users can aquire a 10 day test license for ctrlX CORE, which allows the usage of all ctrlX CORE Apps for this time. -- It is intended for test and evaluation only, and not for use in a production environment -- This license will automatically expire after 10 days. -- Differently from the Temporary Usage Rights (which is av ailable to avoid machine downtime in case of broken devices), several 10 Day Trial Licenses can be used one after another on a device, if an according contractual agreement is available for all involved parties (Bosch Rexroth, Customer, ctrlX World Partner). + +- The 10 day trial license allows to use all apps - which support this license mode - for a restricted time for testing purposes. +- The license is intended for test and evaluation only and not for use in a production environment +- The license will automatically expire after 10 days. +- Other than the temporary usage rights mode, 10 day trial licenses may be used (consecutively) in case an according contractual agreement is available for all involved parties (Bosch Rexroth, Customer, ctrlX World Partner). **Expected App Behaviour:** - Support of this mode is **optional**. -- The App is informed with the `isPermanent` flag set to `false` in the response when acquiring such a license from the License Manager. +- The app is able to detect whether the system runs in this mode by evaluating the `isPermanent` flag in the response to the acquisition request (the flag is set to `false`) + - When this mode is active, the app should work as if a standard license is available. ## 3.5 Four Hour Engineering Demo License on ctrlX COREvirtual -**Purpose**: Demonstration Mode on a virtual control (no ctrlX CORE hardware) - +**Purpose**: Evaluation mode on a ctrlX COREvirtual **Description**: - An according special license key (`SWL_XCR_ENGINEERING_4H`) indicates that currently the limited evaluation mode is active -- After 4 hours the virtual device shuts down itself to prevent a productive use. +- After 4 hours the ctrlX COREvirtual shuts down itself to prevent a productive use. **Expected App Behaviour:** - Support of this mode is **optional**. -- In order to support this non-productive mode, Apps must check for the license `SWL_XCR_ENGINEERING_4H`, which guarantees that the runtime is limited to 4 hours. +- In order to support this non-productive mode, apps must check for the license `SWL_XCR_ENGINEERING_4H`, which guarantees that the runtime is limited to 4 hours. ## 3.6 Additional License Mode: ctrX CORE 3 Month Test License -**Purpose:** Time limited test and evaluation of Apps which are in beta/prototype phase (B-Sample phase) +**Purpose:** Time limited test and evaluation of apps which are in beta/prototype phase (B-Sample phase) **Description:** + - This mode is not intended / available for partner apps by default. - Please get in touch with Bosch Rexroth directly, if this mode might be of interest for you. **Copyright** -Copyright (c) 2022-2023 Bosch Rexroth AG \ No newline at end of file + +SPDX-FileCopyrightText: Bosch Rexroth AG \ No newline at end of file diff --git a/doc/localizaction.md b/doc/localizaction.md index 3ff3ef232..d75594144 100644 --- a/doc/localizaction.md +++ b/doc/localizaction.md @@ -1,4 +1,4 @@ -This document is part of the Bosch Rexroth ctrlX CORE App Development Guideline, and gives hints on how to use the License Manager service that is operated by Bosch Rexroth. +This document is part of the Bosch Rexroth ctrlX OS App Development Guideline, and gives hints on how to support user interface localization on ctrlX OS. Please refer to the App Development Guide for further information. @@ -12,7 +12,7 @@ Please refer to the App Development Guide for further information. # 1 Introduction -ctrlX CORE uses the NGX-Translate library to localize Apps +ctrlX OS uses the NGX-Translate library to localize Apps Details of this library can be found here: >http://www.ngx-translate.com/ @@ -64,7 +64,7 @@ Keys have to follow the following convention to avoid conflicts when several loc * **component**: denotes the building block (angular component, service etc.) within an app where the translatable text is located * **element**: denotes the ui-element within a component on which the text is placed * **type** (optional): denotes the type of the ui-element. This can give translators additional information, that may be relevant for translation. -For example, types in the ctrlX CORE are: +For example, types in ctrlX OS are: * title (page / dialog titles) * header (column headers etc.) * tab (tab page titles) @@ -123,7 +123,7 @@ Comments and remarks are not supported in localization files **Note**: -This chapter describes a ctrlX CORE best practice to add localization to an app. +This chapter describes a ctrlX OS best practice to add localization to an app. Bosch Rexroth does not guarantee that this practice will work for Partner Apps. Please see http://www.ngx-translate.com/ for additional information. @@ -190,7 +190,7 @@ export function createMultiTranslateHttpLoader(http: HttpClient): TranslateLoade Note that TranslateModule.forRoot() must be called. -For ctrlX CORE, English (en) is defined as defaultLanguage. That means English is the fallback language if a translation is not available in the currently selected language. +For ctrlX OS, English (en) is defined as defaultLanguage. That means English is the fallback language if a translation is not available in the currently selected language. ## 3.4 Localize the UI related parts of your app @@ -199,5 +199,6 @@ Please see details here: https://github.com/ngx-translate/core **** **Copyright** -© Bosch Rexroth AG 2022 - +© Bosch Rexroth AG 2022-2023 + This document, as well as the data, specifications and other information set forth in it, are the exclusive property of Bosch \ No newline at end of file diff --git a/doc/log.md b/doc/log.md index 33a57b2e9..140b8d258 100644 --- a/doc/log.md +++ b/doc/log.md @@ -24,7 +24,7 @@ __Be carefull with level EMERGENCY: Messages with this level are sent to all con ## Logging Samples in the SDK -In these folders of ctrlX SDK logging samples for different programming languages are provided: +These folders of the ctrlX AUTOMATION SDK contain logging samples for different programming languages: - samples-cpp/diagnostics.logbook - samples-net/diagnostics.logbook @@ -39,24 +39,8 @@ ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ diff --git a/doc/package-assets.md b/doc/package-assets.md index 2778c7043..67f587f59 100644 --- a/doc/package-assets.md +++ b/doc/package-assets.md @@ -26,19 +26,19 @@ The following example shows the procedure step-by-step. name: rexroth-myapp [...] parts: - [...] - configs: - plugin: dump - source: ./configs + configs: + plugin: dump + source: ./configs + organize: + 'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/ [...] slots: - [...] - package-assets: - interface: content - content: package-assets - source: - read: - - $SNAP/package-assets/${SNAPCRAFT_PROJECT_NAME} + package-assets: + interface: content + content: package-assets + source: + read: + - $SNAP/package-assets/${SNAPCRAFT_PROJECT_NAME} [...] ``` @@ -81,7 +81,9 @@ An item is defined as an object with the following elements: ??? example ```json - [...] + { + "$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.schema.json", + [...] "menus": { "sidebar": [ { @@ -147,8 +149,9 @@ An item is defined as an object with the following elements: ] } ] - } - [...] + }, + [...] + } ``` @@ -171,25 +174,30 @@ If you want to open your application in your own tab, you can define the target ??? Example ```json - ... - "menus": { - "sidebar": [ - { - "id": "app-name", - "title": "My App Name", - "icon": "myApp-Icon", - "permissions": [], - "items": [ - { - "id": "myApp-Id", - "title": "MySideBarTitle", - "link": "/app-name?access_token=${bearertoken}", - "target":"myApp-Id", - "permissions": [] - },... + { + [...] + "menus": { + "sidebar": [ + { + "id": "app-name", + "title": "My App Name", + "icon": "myApp-Icon", + "permissions": [], + "items": [ + { + "id": "myApp-Id", + "title": "MySideBarTitle", + "link": "/app-name?access_token=${bearertoken}", + "target":"myApp-Id", + "permissions": [] + }, + [...] + ] + } ] - }] - [...] + }, + [...] + } ``` ### Reverse Proxy @@ -207,20 +215,20 @@ The proxy mapping provides the configuration required by the reverse proxy to re ```json { - [...] - "services": { + [...] + "services": { "proxyMapping": [ - { + { "name": "rexroth-solutions.web", "url": "/rexroth-solutions", "binding": ":5000", "restricted": [ - "/rexroth-solutions/api/v1.0" + "/rexroth-solutions/api/v1.0" ] - } + } ] - } - [...] + }, + [...] } ``` @@ -495,6 +503,17 @@ The following predefined folder structure applies to every certificate store: !!! hint You can store your keys using a [TPM](https://en.wikipedia.org/wiki/Trusted_Platform_Module). +### Required apps (optional) + +You can prohibit the uninstallation and deactivation of your app by setting `"required": true`. + +!!! example + + ```json + { + "required": true + } + ``` ### Example package-manifest.json @@ -600,7 +619,6 @@ The following predefined folder structure applies to every certificate store: } } ``` - ## The language files Language files are used to translate text sections into different languages. Bosch Rexroth Apps are shipped with english and german language files. Currently the multi language system (MLS) supports translations for the content of the [package manifest](#the-package-manifest) texts which are organized in the `./package-assets/i18n` folder of the app. @@ -620,7 +638,7 @@ Additionally you have to provide the language files for the package-manifest in { "id": "_myapp", "title": "My App", - "description": "A cool app you should not miss", + "description": "A cool app, you should not miss", "icon": "Bosch-Ic-home-outline", "link": "/myapp/home", "i18n": "sidebar.myapp" @@ -633,7 +651,7 @@ Additionally you have to provide the language files for the package-manifest in ```json title="i18n/myapp.package-manifest.de.json (dot notation)" { "sidebar.myapp.title": "Meine App", - "sidebar.myapp.description": "Eine kühle App die du nicht verpassen solltest" + "sidebar.myapp.description": "Eine coole App, die du nicht verpassen solltest" } ``` @@ -642,10 +660,10 @@ Additionally you have to provide the language files for the package-manifest in "sidebar": { "myapp": { "title": : "Meine App", - "description": "Eine kühle App die du nicht verpassen solltest" + "description": "Eine coole App, die du nicht verpassen solltest" } } } ``` -Basically you can translate every aspect of the package-manifest this way. +Basically you can translate every aspect of the package-manifest this way. \ No newline at end of file diff --git a/doc/persistdata.md b/doc/persistdata.md index 7be29483d..2c40c23b4 100644 --- a/doc/persistdata.md +++ b/doc/persistdata.md @@ -172,9 +172,9 @@ For each command, the following elements must be specified: By default there is no defined order of command execution. Starting with version XCR-V-0112, a command may declare that it needs to be executed **after** other commands. If this is required (which should be the exception), add an after element to your command declaration with an array containing the IDs of the predecessor commands. ->**Hint for developers providing Data Layer endpoints for loading and saving** +>**Hint for developers providing ctrlX Data Layer endpoints for loading and saving** > ->In order to make the Data Layer endpoints for saving and loading a configuration consistent, the respective URLs should adhere to the following pattern: +>In order to make the ctrlX Data Layer endpoints for saving and loading a configuration consistent, the respective URLs should adhere to the following pattern: > >\/\<**technology**\>/admin/cfg/\ > @@ -535,20 +535,21 @@ The configuration files are available via WebDAV protocol under the ctrlx-device https://localhost:8443/solutions/webdav/appdata/configuration.json -See also: [golang WebDAV client](../samples-go/webdav.client/readme.md) and [nodejs WebDAV client](../samples-node/webdav-client/readme.md) +See also: [golang WebDAV client](https://github.com/boschrexroth/ctrlx-automation-sdk/blob/main/samples-go/webdav.client/README.md) +and [nodejs WebDAV client](https://github.com/boschrexroth/ctrlx-automation-sdk/blob/main/samples-node/solutions.webdav.interface/README.md) ### Accessing configuration files with WinSCP [WinSCP](https://winscp.net/) is a windows app, which allows access to a remote file system via WebDAV. -#### Connect to a crtlX device +#### Connect to a ctrlX CORE Start WinSCP, login with: File protocol: WebDAV - Host name: IP-address or hostname of the device - Port number: 443 or 8443 for a virtual control - User name and Password: credentials on the ctrlX-device + Host name: IP-address or hostname of the ctrlX CORE + Port number: 443 or 8443 for a ctrlX COREvirtual + User name and Password: credentials on the ctrlX CORE ![](images/winscp-sites.png) diff --git a/doc/px.md b/doc/px.md index 1ec924298..65883786d 100644 --- a/doc/px.md +++ b/doc/px.md @@ -48,7 +48,6 @@ For automatically run at startup do following steps: Px provides both http and https access via default port __3128__. If this port is not available on the host it can be changed in px.ini BUT: The alternative port has to be changed in the VM too - see [Setup a QEMU VM](setup_qemu_ubuntu.md) and [Setup a Virtual Box VM](setup_windows_virtualbox_ubuntu.md). - ## Proxy Settings in the App Build Environment As mentioned a VM running on a host without direct internet access has to use a proxy server too. diff --git a/doc/quick-start-guide.md b/doc/quick-start-guide.md index 5de44fae9..768acc93d 100644 --- a/doc/quick-start-guide.md +++ b/doc/quick-start-guide.md @@ -25,13 +25,13 @@ Call this script: ~/scripts/install-sdk.sh -The script downloads downloads ctrlx-automation-sdk.zip from github and unzips it to the folder /home/boschrexroth/ctrlx-automation-sdk/ +The script downloads ctrlx-automation-sdk.zip from github and unzips it to the folder /home/boschrexroth/ctrlx-automation-sdk/ * __Change to project folder /home/boschrexroth/ctrlx-automation-sdk/samples-cpp/datalayer.register.node__ * __Build one or both snaps__ -To build a snap for a ctrlX CORE virtual enter: +To build a snap for a ctrlX COREvirtual enter: ./build-snap-amd64.sh @@ -41,9 +41,7 @@ To build a snap for a ctrlX CORE enter: As a result a snap file `sdk-cpp-registernode_...._amd64.snap` respectively `sdk-cpp-registernode_...._arm64.snap` will be created. -* From your __Windows host__ copy the snaps from your App Build Environment to your Windows file system__ - -Start cmd.exe and enter this command: +To copy the snap(s) into your Windows file system start cmd.exe on __your Windows host__ and enter this command: scp -P 10022 boschrexroth@localhost:~/ctrlx-automation-sdk/samples-cpp/datalayer.register.node/*.snap . @@ -51,7 +49,7 @@ Start cmd.exe and enter this command: Don't forget to set option 'Allow installation from unknown source' under Apps --> Settings -* __Select Settings --> Data Layer and check the nodes under path sdk-cpp-registernode/__ +* __Select Settings --> ctrlX Data Layer and check the nodes under path sdk-cpp-registernode/__ There should appear several nodes created by the snap. diff --git a/doc/remote-debug-cpp.md b/doc/remote-debug-cpp.md index 8d6a6b552..41572c7e7 100644 --- a/doc/remote-debug-cpp.md +++ b/doc/remote-debug-cpp.md @@ -71,10 +71,10 @@ This overview will give you a short explenation how remote debugging of a C++ sn These are the basics points: * Your C++ code has to raise a SIGSTOP signal in debug mode. This is done typically in the startup sequence or somewhere else where needed. -* You have to build your C++ snap in __debug mode__ and install it on your ctrlX. +* You have to build your C++ snap in __debug mode__ and install it on your ctrlX CORE. * The snap application will be restarted manually via ssh with the command `sudo snap run --experimental-gdbserver=:12345 .` * The execution of the application will stop when the SIGSTOP signal is raised so that the gdb server is able to connect. -* From your build environment the gdb debugger is started in remote mode. Provided with IP address and port nummber he can communicate with the gdb server on the ctrlX. +* From your build environment the gdb debugger is started in remote mode. Provided with IP address and port nummber he can communicate with the gdb server on the ctrlX CORE. * Now the debug process can be started using gdb debugger commands. Normally this is done from an IDE like VisualStudio Code. ### Prerequisites @@ -142,7 +142,7 @@ As second action we want to start the gdb debugger in remote mode so that he con "name": "aarch64 ctrlX (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-aarch64/Debug/registerNode", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-aarch64/Debug/registerNode", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "192.168.1.1:12345", diff --git a/doc/remote-debug-python.md b/doc/remote-debug-python.md index fc82dddd9..f093f854f 100644 --- a/doc/remote-debug-python.md +++ b/doc/remote-debug-python.md @@ -70,8 +70,8 @@ The Python Visual Studio Code extension has a Python debug client. For a remote Here you can find the complete file: samples-python/datalayer.remote.debug/.vscode/launch.json There are three launch configurations for remote debugging: -* "Remote ctrlX CORE virtual - Port forwarding" -* "Remote ctrlX CORE virtual - Network adapter" +* "Remote ctrlX COREvirtual - Port forwarding" +* "Remote ctrlX COREvirtual - Network adapter" * "Remote ctrlX CORE" ### Preparing your Python Project for Remote Debugging diff --git a/doc/setup_overview.md b/doc/setup_overview.md index 189f07a26..7420bc305 100644 --- a/doc/setup_overview.md +++ b/doc/setup_overview.md @@ -10,7 +10,7 @@ To develop ctrlX CORE applications with the ctrlX AUTOMATION SDK we need a so ca * [VirtualBox Virtual Machine](setup_windows_virtualbox_ubuntu.md) describes how to setup such a VM to use it as App Build Environment. -* [Native Ubuntu 20.04](setup_ubuntu.md) shows how to setup a bare-metal machine to use it as App Build Environment. +* [Native Ubuntu](setup_ubuntu.md) shows how to setup a bare-metal machine to use it as App Build Environment. * [Install Sources from github](install-sources-from-github.md) describes how to download and install the github repository __ctrlX AUTOMATION Software Development Kit__ [https://github.com/boschrexroth/ctrlx-automation-sdk](https://github.com/boschrexroth/ctrlx-automation-sdk) diff --git a/doc/setup_qemu_ctrlx_works.md b/doc/setup_qemu_ctrlx_works.md index d5b1d39a5..d83742d26 100644 --- a/doc/setup_qemu_ctrlx_works.md +++ b/doc/setup_qemu_ctrlx_works.md @@ -1,9 +1,18 @@ -If in the ctrlX WORKS setup the function 'ctrlX CORE App Build Environment' is enabled ctrlX WORKS allows to create App Build Environments. Internally these are QEMU Virtual Machines running Ubuntu server 20.04 LTS which are configured during first startup. +If in the ctrlX WORKS setup the function 'ctrlX CORE App Build Environment' is enabled ctrlX WORKS allows to create App Build Environments. Internally these are QEMU Virtual Machines running Ubuntu server LTS which are configured during first startup. From the ctrlX WORKS UI each environment can be started, stopped or deleted. Furthermore a SSH shell can be started to login. Apart from ctrlX WORKS and px.exe, no other software tools are required. +## Checking the Internet Connection + +!!! important + For the installation of an App Build Environment a functioning internet connection is required. + +If your host uses a proxy server install and run [px.exe](px.md). + +You can test whether your internet connection is working by clicking this link [Ubuntu 22.04 LTS](https://cloud-images.ubuntu.com/releases/jammy/release). A site with Ubuntu server cloud images should appear. + ## Installation of the App Build Environment Function in ctrlX WORKS During the ctrlX WORKS setup select function 'ctrlX CORE App Build Environment'. @@ -12,7 +21,7 @@ Out of an already installed ctrlX WORKS you can start the setup wizard with Sett ## Handling of App Build Environments -Select App Build Environments on the side bar of ctrlX WORKS. The list of installed App Build Environments will be shown. +Select 'App Build Environments' on the side bar of ctrlX WORKS. The list of installed App Build Environments will be shown. ### Create an App Build Environment @@ -21,7 +30,7 @@ Select App Build Environments on the side bar of ctrlX WORKS. The list of instal * Name: Enter a unique name. * Storage location: Enter/select a destination directory where the files are stored. * Port forwarding: Here port forwardings from the Windows host to the VM guest are defined. Per default for SSH the port 10022 of the Windows host is forwarded to port 22 of the guest VM. Do NOT change 22! You can change 10022 if you want to run several environments concurrently. -* Select 'Use HTTP and HTTPS proxy on localhost:3128' if your host is behind a proxy. In this case install and run [px.exe](px.md) +* Select 'Use HTTP and HTTPS proxy on localhost:3128' if your host uses a proxy. In this case install and run [px.exe](px.md) * Create a new Add Build Environment with OK or abort with Cancel !!! important @@ -36,13 +45,25 @@ Select App Build Environments on the side bar of ctrlX WORKS. The list of instal ### Working with an App Build Environment -You can open a SSH connection (secure shell) by clicking the according link in the column SSH of ctrlX WORKS 'App Build Environments' view. +#### Preparations + +On your Windows host start cmd.exe and run these commands: + +* Delete entry regarding 127.0.0.1 in the file know_hosts + + ssh-keygen.exe -R [127.0.0.1]:10022 + +* Copy your public key (here: id_rsa.pub) to the App Build Environment (on password promt enter: boschrexroth) -For the login a password is required, it is __boschrexroth__. + ssh.exe -p 10022 boschrexroth@127.0.0.1 "mkdir -p ~/.ssh" + scp.exe -P 10022 %USERPROFILE%\.ssh\id_rsa.pub boschrexroth@127.0.0.1:~/.ssh/id_rsa.pub.tmp + ssh.exe -p 10022 boschrexroth@127.0.0.1 "cat ~/.ssh/id_rsa.pub.tmp >>~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && rm ~/.ssh/id_rsa.pub.tmp" -We recommend to add your public key contained in the __hosts__ id_rsa.pub file to the file authorized_keys in the VMs directory /home/boschrexroth/.ssh/. So password input on each login is obsolete. +#### Start a ssh session -Therefor you can use the bat file ssh-keygen-copy-id.bat in the destination directory of the VM (see below). +You can open a SSH connection (secure shell) by clicking the according link in the column SSH of ctrlX WORKS 'App Build Environments' view. + +If your preparations succeeded no password is needed otherwise enter __boschrexroth__ Please regard instructions in chapter [Important Install Scripts](install-scripts.md). @@ -64,16 +85,4 @@ If the environment has the State Offline a click of the Pencil icon opens the co ### Delete an App Build Environment -If the environment is Offline you can delete it by clicking the Waste Bin icon. The whole folder will be deleted. - -### Helper Functions - -The storage location folder on your host system for each environment also contains two helper bat files which can be useful: - -* __ssh-keygen-copy-id.bat__ Adds your public key id_rsa.pub to the ~/.ssh/authorized_keys file of the environment to avoid password input on each login. You will be asked for the SSHPORT, enter the host port (e.g. 10022) here. - -* __shrink-qcow2.bat__ The snapshot file of an environment can get very big. With this script you can shrink it. - -!!! important - The environment must be stopped. The shrinking process can take a while - Do NOT abort it. - +If the environment is Offline you can delete it by clicking the Waste Bin icon. The whole folder will be deleted. \ No newline at end of file diff --git a/doc/setup_qemu_ubuntu.md b/doc/setup_qemu_ubuntu.md index f11357689..0ff166a76 100644 --- a/doc/setup_qemu_ubuntu.md +++ b/doc/setup_qemu_ubuntu.md @@ -1,13 +1,13 @@ -This chapter describes how to setup and run App Build Environments without using ctrlX WORKS. +This chapter describes how to setup and run App Build Environments __without using ctrlX WORKS__. -Remember ctrlX WORKS provides all necessary actions required to deal with app build environments. +Remember ctrlX WORKS provides all necessary actions required to deal with App Build Environments. This is the recommended constellation: * Despite QEMU supports both Windows and Linux we are recommending to use a Windows host operating system . -* Host and guest machine should use CPU architecture amd64. Snaps for an arm64 target are build via cross build. +* Host and guest machine should use CPU architecture amd64. Snaps for a arm64 targets are build via cross build. ## Installation on Windows 10 Host @@ -57,16 +57,9 @@ See [Use PX.exe as Local Proxy on a Windows Host](./px.md). ## Installation on Linux Host You have to install both QEMU and KVM on your host system. +Therefor you can run this script: -The installation process is descriped in the internet e.g. - -[How to Install QEMU on Ubuntu to Set Up a Virtual Machine](https://www.makeuseof.com/how-to-install-qemu-ubuntu-set-up-virtual-machine/). - -See also: - -[How to Install Kvm on Ubuntu 20.04](https://linuxize.com/post/how-to-install-kvm-on-ubuntu-20-04/) - -[KVM](https://www.linux-kvm.org/page/Documents) + scripts/environment/install-qemu.sh ## Running the QEMU Virtual Machine diff --git a/doc/setup_windows_virtualbox_ubuntu.md b/doc/setup_windows_virtualbox_ubuntu.md index 1d8f4837c..1410dfe0e 100644 --- a/doc/setup_windows_virtualbox_ubuntu.md +++ b/doc/setup_windows_virtualbox_ubuntu.md @@ -9,9 +9,9 @@ This guide shows how to use an [Ubuntu Desktop](https://ubuntu.com/desktop/devel The software can be downloaded from here: -## Setup Virtual Machine and install Ubuntu Desktop 20.04 LTS +## Setup Virtual Machine and Install Ubuntu Desktop 22.04 LTS -Download an iso-image from +Download an iso-image from [Ubuntu 22.04.2 LTS](https://releases.ubuntu.com/releases/jammy/) Create a virtual machine, select these settings: diff --git a/doc/storage-extension.md b/doc/storage-extension.md new file mode 100644 index 000000000..2eb053237 --- /dev/null +++ b/doc/storage-extension.md @@ -0,0 +1,175 @@ +# Introduction + +Storage extension is a feature to extend the internal storage by an external media like μSD card or USB device. Storage extension was introduced with Device Admin 1.18. + +This storage is encrypted and bond to one ctrlX CORE, so it cannot be used to transfer data from one ctrlX CORE to another one. If a data transfer is required, please see documentation of [Data exchange](data-exchange.md). + +!!! attention + > + - All data on the storage extension partition will be erased! Be sure you back up your data before. + - The partition will be formatted with ext4 and encrypted with dmcrypt. + - Each app has an own, exclusive area on the storage extension partition, no other app can access this location. + +# Requirements +To use the extended storage in your app, some changes are needed in your app. The minimum requirements are shown in the samples. + +The storage extension mount point must be added as a mount-control plug in the [snapcraft.yaml](https://snapcraft.io/docs/snapcraft-yaml-reference). Additionally your app needs the mount-observe plug and a remove hook. + +And as the last step some modifications of the start script of your app are required. + +The storage extension parent for your app is mounted by the Device Admin. The location is `/writable/system-data/var/run/mnt/storage-extension/${SNAPCRAFT_PROJECT_NAME}`. + +# Development + +!!! attention + + **Root user required** + + The storage extension plug is on the denylist. + Therefore only signed apps can use storage extension. + To avoid trouble during the development, a root user for the ctrlX is required + and the denylist has to be empty. + + + **Empty the denylist** + + sudo -s + mkdir -p /etc/writable/integrity + echo [] >/etc/writable/integrity/denylist.json + snap restart rexroth-deviceadminw.web + + +After clearing the denylist it's possible to test storage extension without signed apps. + +# Configuration + +Some modifications in your app are required to use storage extension. + +# Snapcraft.yaml + +The storage extension plug is required in **[snapcraft.yaml](https://snapcraft.io/docs/snapcraft-yaml-reference)**. The type of the plug is **mount-control**, the necessary parameters are shown in the sample: + +!!! example + ```yaml title="snapcraft.yaml" + name: storage-extension-sample + title: Storage extension sample app + base: core20 + version: 0.0.1 + summary: Storage extension sample + description: | + Storage extension sample + grade: stable + confinement: strict + + parts: + <...> + backup: + plugin: nil + source: backup + overrride-build: | + snapcraftctl build + mkdir -p $SNAPCRAFT_PART_INSTALL/meta + cp $SNAPCRAFT_PART_SRC/snapshots.yaml $SNAPCRAFT_PART_INSTALL/meta + + plugs: + storage-extension-mnt: + interface: mount-control + mount: + - what: /writable/system-data/var/run/mnt/storage-extension/${SNAPCRAFT_PROJECT_NAME} + where: $SNAP_COMMON/storage-extension/${SNAPCRAFT_PROJECT_NAME} + options: + - rw + - bind + + apps: + sample: + command: bin/sample + plugs: + - storage-extension-mnt + - mount-observe + ``` + +Remark: the variable `${SNAPCRAFT_PROJECT_NAME}` is a known variable by snapcraft and will be replaced with the project name (here: **storage-extension-sample**). So no modifications in this block is required! The variable `$SNAP_COMMON` is known in the snap context. + +Your app needs the plugs **mount-observe** and the defined storage extension plug (here: **storage-extension-mnt**). If one of the plugs are missing, your app won't run like expected. + +# Remove hook +There has to be a remove hook in your app. Otherwise, it's not possible to remove your app if a storage extension is available. + +To add the remove hook, the file `remove` has to be placed in the `snap/hooks` folder. + +Don't forget to mark the file as executable: + + chmod +x remove + +!!! remove + ```title="" + snapctl umount $SNAP_COMMON/storage-extension/$SNAP_NAME + ``` + + + +Remark: The variables `$SNAP_COMMON` and `$SNAP_NAME` are known in the snap context. + +# App start script +Before your app can start and use the storage extension, the storage extension mount must be done. Therefore, your start script has to mount the storage extension. + +!!! example + ```bash title="script.sh" + + #!/usr/bin/env bash + + # check if storage extension is ready to use (prepared by Device Admin) + mount | grep /var/snap/rexroth-deviceadmin/common/storage-extension + if [ $? -ne 0 ]; then + # No storage extension detected - abort script + echo No storage extension found + exit 1 + fi + + # storage extension detected, mount for your app + snapctl mount -o rw,bind /writable/system-data/var/run/mnt/storage-extension/$SNAP_NAME $SNAP_COMMON/storage-extension/$SNAP_NAME + + $SNAP/your-app.sh + ``` + +# Exclude from backup support +All your data from the storage extension are added to the backup by default. You typically use the storage extension when you have increased memory requirements in your app. Therefore it is necessary to exclude the storage extension from the backup. + +This will be done by adding a "part" in your snapcraft.yaml and add a snapshots.yaml to the project. + +!!! example + ```yaml title="snapshots.yaml" + exclude: + # Exclude storage-extension partition from backup + - $SNAP_COMMON/storage-extension/* + ``` + + +# Sample app + +This sample app ( [storage-extension-sample](./samples-go/storage-extension)) is the minimum set to use storage extension. +Feel free to add the content to your app. + +# Use storage extension + +To use storage extension, mount the media with the option "To extend system data". + +!!! attention + The partition will be formatted and encrypted. All data on the partition will be lost! + +After clicking "continue" the storage extension will be added to the system and the control will be rebooted. + +After the next reboot the storage extension will be available for the system. + + +Each app has its own area, the path is `$SNAP_COMMON/storage-extension/`. + +!!! Remarks + - By pressing the remove safely button, you can remove the storage extension (this will be finished with a restart of the control). + - !!! warning + Be careful: You cannot reuse the partition without formatting and encrypting it again. So all data will be lost! + + - **Only one** partition can be used as storage-extension at one time + - Data on storage-extension is **not** part of backup/restore + - If necessary, you have to switch to service state to mount or unmount storage-extension partitions diff --git a/doc/working-with-app-builder-envs.md b/doc/working-with-app-builder-envs.md index 4bcc0874a..56d5e4db6 100644 --- a/doc/working-with-app-builder-envs.md +++ b/doc/working-with-app-builder-envs.md @@ -4,7 +4,7 @@ This document describes how to work with App Build Environments (QEMU based VMs) We recommend to use App Build Environments (QEMU VMs) as follows: -1. Create a new App Build Environment with ctrlX WORKS and start it (the newest version of Ubuntu 20.04 LTS is automatically downloaded). +1. Create a new App Build Environment with ctrlX WORKS and start it (the Ubuntu Server Cloud Image is automatically downloaded). 2. After first boot login and install only necessary additional software components using the install scripts in /home/boschrexroth/e.g.: install-sdk.sh, install-deb.sh and install-go.sh 3. We recommend to work with the free and open source distributed version control system __git__: Create a repository for your project and clone it into your App Buiulder Environment. 4. Create a new branch for your working package. @@ -17,9 +17,9 @@ __Working in such a manner ensures that you are always working with the latest s The file system of an App Build Environment is loaded from two files. -The first one is the Ubuntu cloud image file __ubuntu-20.04-server-cloudimg-amd64.img__ originally downloaded from which has a file size of about 600MB. This file is static - no changes are made during runtime or shutdown of your VM. So there is no need to handle it. +The first one is the Ubuntu cloud image file __ubuntu-22.04-server-cloudimg-amd64.img__ originally downloaded from which has a file size of about 600MB. This file is static - no changes are made during runtime or shutdown of your VM. So there is no need to handle it. -The second one is the so called snapshot file __ubuntu-20.04-server-cloudimg-amd64-snapshot-proxy.qcow2__. This file can be very big (30 GB and more). +The second one is the so called snapshot file __ubuntu-22.04-server-cloudimg-amd64-snapshot-proxy.qcow2__. This file can be very big (30 GB and more). All changes are stored into the snapshot files. Our backup procedure handles this file. !!! important @@ -32,11 +32,11 @@ Open the storage location of your App Build Environment. Rename the actual qcow2 file: - ren ubuntu-20.04-server-cloudimg-amd64-snapshot-noproxy.qcow2 ubuntu-20.04-server-cloudimg-amd64-snapshot-noproxy.qcow2.bak + ren ubuntu-22.04-server-cloudimg-amd64-snapshot-noproxy.qcow2 ubuntu-22.04-server-cloudimg-amd64-snapshot-noproxy.qcow2.bak Convert the bak file to the new qcow2 file: - "c:\Program Files\Rexroth\ctrlX WORKS\qemu\qemu-img.exe" convert ubuntu-20.04-server-cloudimg-amd64-snapshot-noproxy.qcow2.bak -O qcow2 ubuntu-20.04-server-cloudimg-amd64-snapshot-proxy.qcow2 + "c:\Program Files\Rexroth\ctrlX WORKS\qemu\qemu-img.exe" convert ubuntu-22.04-server-cloudimg-amd64-snapshot-noproxy.qcow2.bak -O qcow2 ubuntu-22.04-server-cloudimg-amd64-snapshot-proxy.qcow2 Be patient this process takes some times. diff --git a/mkdocs.yml b/mkdocs.yml index a9c6845bd..694cff652 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -3,7 +3,7 @@ site_name: Software Development Kit site_url: https://boschrexroth.github.io/ctrlx-automation-sdk site_description: ctrlX AUTOMATION Software Development Kit site_author: Bosch Rexroth AG -copyright: Copyright © 2020-2022 Bosch Rexroth AG +copyright: Copyright © 2020-2023 Bosch Rexroth AG # Repository Settings repo_name: boschrexroth/ctrlx-automation-sdk @@ -23,6 +23,7 @@ theme: - navigation.instant - navigation.tabs - navigation.sections + - content.code.copy favicon: assets/favicon.png icon: admonition: @@ -98,6 +99,10 @@ nav: - Using Flatbuffers in IEC 61131-3 Code: fbs2plc.md - Configure maximal Number of Open File Handles: numopenfilehandles.md - Using Localizaction: localizaction.md + - External Storages: + - Date exchange: data-exchange.md + - Storage extension: storage-extension.md + - Extendable Denylist: extenable-denylist.md - Releases: - Changelog: changelog.md - Setup: @@ -107,7 +112,7 @@ nav: - Important Installation Scripts: install-scripts.md - QEMU Virtual Machine: setup_qemu_ubuntu.md - VirtualBox Virtual Machine: setup_windows_virtualbox_ubuntu.md - - Native Ubuntu 20.04: setup_ubuntu.md + - Native Ubuntu: setup_ubuntu.md - Install Sources from github: install-sources-from-github.md - Toolchain: - Px.exe as Proxy on a Windows Host: px.md @@ -124,6 +129,7 @@ nav: - Samples Python: samples-python/README.md - Samples .NET: samples-net/README.md - Samples Nodejs: samples-node/README.md + - Samples ANGULAR: samples-angular/README.md - Samples Shell: samples-sh/README.md - Samples Snap: samples-snap/README.md - Samples IEC 61131-3: samples-iec61131/README.md diff --git a/samples-angular/README.md b/samples-angular/README.md index d48769009..1cf224d2e 100644 --- a/samples-angular/README.md +++ b/samples-angular/README.md @@ -1,5 +1,12 @@ +![ANGULAR](https://upload.wikimedia.org/wikipedia/commons/c/cf/Angular_full_color_logo.svg){width=120} + ## Find out the supported samples + ### Basic Samples -* [Hello Multilanguage ](./hello.multilanguage/README.md) \ No newline at end of file +* [Hello Multilanguage ](./hello.multilanguage/README.md) + +## Build a Snap + +See [Samples Overview](../samples.md) \ No newline at end of file diff --git a/samples-angular/hello.multilanguage/README.md b/samples-angular/hello.multilanguage/README.md index 6f82bbdf0..2bb54eb90 100644 --- a/samples-angular/hello.multilanguage/README.md +++ b/samples-angular/hello.multilanguage/README.md @@ -340,24 +340,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-angular/hello.multilanguage/build-snap-amd64.sh b/samples-angular/hello.multilanguage/build-snap-amd64.sh index d090a57a9..92f432dad 100644 --- a/samples-angular/hello.multilanguage/build-snap-amd64.sh +++ b/samples-angular/hello.multilanguage/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-angular/hello.multilanguage/build-snap-arm64.sh b/samples-angular/hello.multilanguage/build-snap-arm64.sh index b41b7fd26..8cd17b41a 100644 --- a/samples-angular/hello.multilanguage/build-snap-arm64.sh +++ b/samples-angular/hello.multilanguage/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-angular/hello.multilanguage/configs/package-assets/ctrlx-hello-multilanguage.package-manifest.json b/samples-angular/hello.multilanguage/configs/package-assets/ctrlx-hello-multilanguage.package-manifest.json index 3e6cb9c2c..603adaf41 100644 --- a/samples-angular/hello.multilanguage/configs/package-assets/ctrlx-hello-multilanguage.package-manifest.json +++ b/samples-angular/hello.multilanguage/configs/package-assets/ctrlx-hello-multilanguage.package-manifest.json @@ -1,4 +1,5 @@ { + "$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.schema.json", "version": "1.0.0", "id": "ctrlx-hello-multilanguage", "menus": { diff --git a/samples-angular/hello.multilanguage/karma.conf.js b/samples-angular/hello.multilanguage/karma.conf.js index 57d5d8d6f..f8ec6c788 100644 --- a/samples-angular/hello.multilanguage/karma.conf.js +++ b/samples-angular/hello.multilanguage/karma.conf.js @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + // Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html diff --git a/samples-angular/hello.multilanguage/snap/snapcraft.yaml b/samples-angular/hello.multilanguage/snap/snapcraft.yaml index c80394c83..5f0edce24 100644 --- a/samples-angular/hello.multilanguage/snap/snapcraft.yaml +++ b/samples-angular/hello.multilanguage/snap/snapcraft.yaml @@ -2,7 +2,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-hello-multilanguage version: '1.0.0' -base: core20 +base: core22 title: Hello Multilanguage summary: Multilanguage sample in Angular for ctrlX description: | diff --git a/samples-angular/hello.multilanguage/src/app/app.component.spec.ts b/samples-angular/hello.multilanguage/src/app/app.component.spec.ts index 19c4be85b..c05a48172 100644 --- a/samples-angular/hello.multilanguage/src/app/app.component.spec.ts +++ b/samples-angular/hello.multilanguage/src/app/app.component.spec.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import { TestBed } from '@angular/core/testing'; import { AppComponent } from './app.component'; import { TranslateModule} from '@ngx-translate/core'; diff --git a/samples-angular/hello.multilanguage/src/app/app.component.ts b/samples-angular/hello.multilanguage/src/app/app.component.ts index 9a8db0f2f..439771462 100644 --- a/samples-angular/hello.multilanguage/src/app/app.component.ts +++ b/samples-angular/hello.multilanguage/src/app/app.component.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import { Component } from '@angular/core'; @Component({ diff --git a/samples-angular/hello.multilanguage/src/app/app.module.ts b/samples-angular/hello.multilanguage/src/app/app.module.ts index e85fe1235..f2fcd8c51 100644 --- a/samples-angular/hello.multilanguage/src/app/app.module.ts +++ b/samples-angular/hello.multilanguage/src/app/app.module.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import { NgModule, APP_INITIALIZER } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; diff --git a/samples-angular/hello.multilanguage/src/app/books/book-list.component.spec.ts b/samples-angular/hello.multilanguage/src/app/books/book-list.component.spec.ts index 73903c896..a007dc978 100644 --- a/samples-angular/hello.multilanguage/src/app/books/book-list.component.spec.ts +++ b/samples-angular/hello.multilanguage/src/app/books/book-list.component.spec.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { RouterModule } from '@angular/router' diff --git a/samples-angular/hello.multilanguage/src/app/books/book-list.component.ts b/samples-angular/hello.multilanguage/src/app/books/book-list.component.ts index cf063de25..5c61ebb00 100644 --- a/samples-angular/hello.multilanguage/src/app/books/book-list.component.ts +++ b/samples-angular/hello.multilanguage/src/app/books/book-list.component.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import { AfterViewInit, Component } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { IBook } from './book'; diff --git a/samples-angular/hello.multilanguage/src/app/books/book.ts b/samples-angular/hello.multilanguage/src/app/books/book.ts index 9cc917f5e..a23d9db66 100644 --- a/samples-angular/hello.multilanguage/src/app/books/book.ts +++ b/samples-angular/hello.multilanguage/src/app/books/book.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ export interface IBook { id : number; author: string; diff --git a/samples-angular/hello.multilanguage/src/environments/environment.prod.ts b/samples-angular/hello.multilanguage/src/environments/environment.prod.ts index babe05e3e..0d9d28610 100644 --- a/samples-angular/hello.multilanguage/src/environments/environment.prod.ts +++ b/samples-angular/hello.multilanguage/src/environments/environment.prod.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ export const environment = { production: true }; \ No newline at end of file diff --git a/samples-angular/hello.multilanguage/src/environments/environment.ts b/samples-angular/hello.multilanguage/src/environments/environment.ts index 9923be365..7c5e1f8a1 100644 --- a/samples-angular/hello.multilanguage/src/environments/environment.ts +++ b/samples-angular/hello.multilanguage/src/environments/environment.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ export const environment = { production: false }; \ No newline at end of file diff --git a/samples-angular/hello.multilanguage/src/main.ts b/samples-angular/hello.multilanguage/src/main.ts index b31d8ef06..60d6d7dda 100644 --- a/samples-angular/hello.multilanguage/src/main.ts +++ b/samples-angular/hello.multilanguage/src/main.ts @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; diff --git a/samples-angular/hello.multilanguage/src/polyfills.ts b/samples-angular/hello.multilanguage/src/polyfills.ts index 429bb9ef2..620ecb682 100644 --- a/samples-angular/hello.multilanguage/src/polyfills.ts +++ b/samples-angular/hello.multilanguage/src/polyfills.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ /** * This file includes polyfills needed by Angular and is loaded before the app. * You can add your own extra polyfills to this file. diff --git a/samples-angular/hello.multilanguage/src/test.ts b/samples-angular/hello.multilanguage/src/test.ts index c04c87607..7e957aaa4 100644 --- a/samples-angular/hello.multilanguage/src/test.ts +++ b/samples-angular/hello.multilanguage/src/test.ts @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + // This file is required by karma.conf.js and loads recursively all the .spec and framework files import 'zone.js/testing'; diff --git a/samples-cpp/README.md b/samples-cpp/README.md index 33d930126..d5e7768f6 100644 --- a/samples-cpp/README.md +++ b/samples-cpp/README.md @@ -10,11 +10,11 @@ ## Find out the supported samples - ### Basic Samples * [Hello World](./hello.world/README.md) recommendation -> start with this example * [Hello PLC](./hello.plc/README.md) +* [ctrlX Data Layer Easy Client](./datalayer.easy.client/README.md) * [ctrlX Data Layer Client](./datalayer.client/README.md) * [ctrlX Data Layer Client Subscription](./datalayer.client.sub/README.md) * [ctrlX Data Layer RegisterNode](./datalayer.register.node/README.md) @@ -29,33 +29,35 @@ ## Getting Started -- Launch Visual Studio Code as your IDE -- If the IDE is started remote connect via Remote Explorer extension to your builder environment (SSH target) -- Ensure that Visual Studio Code extensions "C/C++ Extension Pack" and "CMake Tools" are installed in your SSH target. -- Open the folder of the desired cpp sample under `samples-cpp/` +* Launch Visual Studio Code as your IDE +* If the IDE is started remote connect via Remote Explorer extension to your builder environment (SSH target) +* Ensure that Visual Studio Code extensions "C/C++ Extension Pack" and "CMake Tools" are installed in your SSH target. +* Open the folder of the desired cpp sample under `samples-cpp/` ### Build a Snap See [Samples Overview](../samples.md) +__Important:__ Before building an arm64 snap run script `public/scripts/environment/scripts/install-cpp-aarch64-libs.sh` once! + ### Create an Executable for Debugging Select the CMake symbol in the sidebar, click '...' at the top of the explorer window and select 'Clean Reconfigure All Projects'. Then make these settings in the status bar (blue area) : -- CMake (Current build variant): Select 'Debug' -- Active kit: Select 'GCC ... x86...' -- Select 'x64...' as build target +* CMake (Current build variant): Select 'Debug' +* Active kit: Select 'GCC ... x86...' +* Select 'x64...' as build target Click Build and observe the progress in the output window - the build process should finish without errors (exit code 0). -Now the executable for debugging is available in the subdirectory: generated/__ubuntu20-gcc-x64/Debug/__ +Now the executable for debugging is available in the subdirectory: generated/__ubuntu22-gcc-x64/Debug/__ To start debugging select 'Run and Debug' in the side bar, select 'x64...' as launch configuration an press F5 (or green start button). The executable will be started and the debugger will set automatically a breakpoint at the beginning of the main() function. - + ## Troubleshooting All automatically created files are located in subfolders `build` and `generated`. diff --git a/samples-cpp/datalayer.client.sub/.vscode/launch.json b/samples-cpp/datalayer.client.sub/.vscode/launch.json index 6c5e3e951..c48648899 100644 --- a/samples-cpp/datalayer.client.sub/.vscode/launch.json +++ b/samples-cpp/datalayer.client.sub/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/datalayerClientSub", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerClientSub", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,7 +23,7 @@ }, { "description": "Set path variable to .", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] diff --git a/samples-cpp/datalayer.client.sub/.vscode/settings.json b/samples-cpp/datalayer.client.sub/.vscode/settings.json index e16018ddf..daadbbba9 100644 --- a/samples-cpp/datalayer.client.sub/.vscode/settings.json +++ b/samples-cpp/datalayer.client.sub/.vscode/settings.json @@ -1,5 +1,5 @@ { - "window.zoomLevel": 1, + "window.zoomLevel": 0, "cmake.configureArgs": [ "-DCMAKE_BUILD_KIT=${buildKit}" ], diff --git a/samples-cpp/datalayer.client.sub/.vscode/tasks.json b/samples-cpp/datalayer.client.sub/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-cpp/datalayer.client.sub/.vscode/tasks.json +++ b/samples-cpp/datalayer.client.sub/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/datalayer.client.sub/CMakeLists.txt b/samples-cpp/datalayer.client.sub/CMakeLists.txt index 682f0acfb..b2b1a0852 100644 --- a/samples-cpp/datalayer.client.sub/CMakeLists.txt +++ b/samples-cpp/datalayer.client.sub/CMakeLists.txt @@ -42,12 +42,12 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET(PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET(PLATFORM_NAME "ubuntu22-gcc-aarch64") SET(SNAP_ARCH "arm64") SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET(PLATFORM_NAME "ubuntu20-gcc-x64") + SET(PLATFORM_NAME "ubuntu22-gcc-x64") SET(SNAP_ARCH "amd64") SET(CMAKE_C_COMPILER gcc) SET(CMAKE_CXX_COMPILER g++) diff --git a/samples-cpp/datalayer.client.sub/LICENSE b/samples-cpp/datalayer.client.sub/LICENSE deleted file mode 100644 index 3ecaa04c3..000000000 --- a/samples-cpp/datalayer.client.sub/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/datalayer.client.sub/README.md b/samples-cpp/datalayer.client.sub/README.md index 6f931ac6d..79f895924 100644 --- a/samples-cpp/datalayer.client.sub/README.md +++ b/samples-cpp/datalayer.client.sub/README.md @@ -1,19 +1,19 @@ # README datalayer.client.sub -This sample app demonstrates how Data Layer nodes are subscribed in single and multi mode. +This sample app demonstrates how ctrlX Data Layer nodes are subscribed in single and multi mode. ## Functional Description -The sample app subscribes to two different Data Layer nodes: +The sample app subscribes to two different ctrlX Data Layer nodes: - framework/metrics/system/cpu-utilisation-percent - framework/metrics/system/memavailable-mb -If a value changes the app writes it to the terminal and also the size, type, address and timestamp. +If a value changes the app writes it to the terminal and also the size, type, address and timestamp. ## Implementation Description ctrlx_datalayer_helper.h contains helper functions the create ctrlX Data Layer provider and/or client instances. -In datalayerclientsub.cpp the class DataLayerClientSub is implemented. Here all activities for the Data Layer access are handled. +In datalayerclientsub.cpp the class DataLayerClientSub is implemented. Here all activities for the ctrlX Data Layer access are handled. In main.cpp the main function first creates an instance of DataLayerClientSub and then runs an endless loop. If an error occurs the application is exited. @@ -32,24 +32,5 @@ ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/datalayer.client.sub/build-snap-amd64.sh b/samples-cpp/datalayer.client.sub/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/datalayer.client.sub/build-snap-amd64.sh +++ b/samples-cpp/datalayer.client.sub/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.client.sub/build-snap-arm64.sh b/samples-cpp/datalayer.client.sub/build-snap-arm64.sh index f48f8a433..8be304510 100644 --- a/samples-cpp/datalayer.client.sub/build-snap-arm64.sh +++ b/samples-cpp/datalayer.client.sub/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.client.sub/ctrlx_datalayer_helper.h b/samples-cpp/datalayer.client.sub/ctrlx_datalayer_helper.h index 3fdec3b7d..d0683514f 100644 --- a/samples-cpp/datalayer.client.sub/ctrlx_datalayer_helper.h +++ b/samples-cpp/datalayer.client.sub/ctrlx_datalayer_helper.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef CTRLX_DATALAYER_HELPER_H @@ -43,17 +25,17 @@ * If these values do not suit your use case, explicitly pass the parameters that require different values. * Here some examples: * - * 1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: + * 1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: * * client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") * - * 2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): + * 2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): * * client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) * * Remarks: * 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual * * * IMPORTANT: @@ -84,10 +66,10 @@ static bool isSnap() } //! Get Datalayer connection string -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result Connection string static std::string getConnectionString( const std::string& ip = "192.168.1.1", @@ -112,10 +94,10 @@ static std::string getConnectionString( //! Get Datalayer Client instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IClient instance or nullptr on error static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", @@ -136,10 +118,10 @@ static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& dat //! Get Datalayer Provider instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IProvider instance or nullptr on error static comm::datalayer::IProvider* getProvider(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", diff --git a/samples-cpp/datalayer.client.sub/datalayerclientsub.cpp b/samples-cpp/datalayer.client.sub/datalayerclientsub.cpp index e78b53066..762176778 100644 --- a/samples-cpp/datalayer.client.sub/datalayerclientsub.cpp +++ b/samples-cpp/datalayer.client.sub/datalayerclientsub.cpp @@ -1,184 +1,172 @@ -/** - * MIT License - * - * Copyright (c) 2021 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include - -#include "comm/datalayer/sub_properties_generated.h" - -#include "datalayerclientsub.h" -DataLayerClientSub::DataLayerClientSub(const comm::datalayer::DatalayerSystem &datalayerSystem) -{ - _datalayerSystem = datalayerSystem; -} - -comm::datalayer::DlResult DataLayerClientSub::connect(const std::string &clientConnection) -{ - std::cout << "_datalayerSystem.factory()->createClient2: " << clientConnection << std::endl; - _datalayerClient = _datalayerSystem.factory()->createClient2(clientConnection); - if (_datalayerClient == nullptr) - { - std::cout << "ERROR: Could not create datalayer client instance" << std::endl; - return DL_CREATION_FAILED; - } - - return isConnected(); -} - -comm::datalayer::DlResult DataLayerClientSub::isConnected() -{ - if (_datalayerClient == nullptr || _datalayerClient->isConnected() == false) - { - return DL_CLIENT_NOT_CONNECTED; - } - - return DL_OK; -} - -comm::datalayer::DlResult DataLayerClientSub ::createSubscriptionSync(const std::string &id) -{ - flatbuffers::FlatBufferBuilder builder; - auto dataChange = comm::datalayer::CreateSampling(builder, 250000); - auto rule = comm::datalayer::CreateProperty(builder, comm::datalayer::Properties::Properties_Sampling, dataChange.Union()); - auto rules = builder.CreateVector(&rule, 1); - auto idTmp = builder.CreateString(id); - builder.Finish(comm::datalayer::CreateSubscriptionProperties(builder, idTmp, 60000, 250, rules)); - comm::datalayer::Variant subscriptionProperties; - subscriptionProperties.shareFlatbuffers(builder); - - auto result = _datalayerClient->createSubscriptionSync(subscriptionProperties, publishCallback()); - if (STATUS_FAILED(result)) - { - std::cout << "createSubscriptionSync failed with " << std::string(result.toString()) << std::endl; - return result; - } - - return result; -} - -// This method returns a comm::datalayer::PublishCallback function as lambda expression. -// See: -// https://en.cppreference.com/w/cpp/language/lambda -// https://de.cppreference.com/w/cpp/language/lambda -comm::datalayer::PublishCallback DataLayerClientSub::publishCallback() -{ - return [&](comm::datalayer::DlResult result, const std::vector &items) - { - std::cout << "--------------- Data has been changed! Result: " << result.toString() << std::endl; - - // check if datalayer-exess was ok - if (result != DL_OK) - { - std::cout << "DL Error" << std::endl; - return; - } - - // check if items is not a nullpointer - if (items.empty()) - { - std::cout << "No items" << std::endl; - return; - } - - for (int n = 0; n < items.size(); n++) - { - std::cout << "Item #" << n << std::endl; - std::cout << " type:" << items[n].data.typeAsString() << std::endl; - std::cout << " size:" << items[n].data.getSize() << std::endl; - - if (comm::datalayer::STATUS_SUCCEEDED(items[n].data.checkConvert(comm::datalayer::VariantType::FLOAT64))) - { - std::cout << " value: " << static_cast(items[n].data) << std::endl; - } - else if (comm::datalayer::STATUS_SUCCEEDED(items[n].data.checkConvert(comm::datalayer::VariantType::STRING))) - { - std::cout << " value: " << static_cast(items[n].data) << std::endl; - } - else - { - std::cout << " can't print value with this data type" << std::endl; - continue; - } - - // get the info of the notify_item (defined in notify_info.fbs) - - auto result = (items[n].info.verifyFlatbuffers(comm::datalayer::VerifyNotifyInfoBuffer)); // VerifyNotifyInfoBuffer is generated out of notify_info.fbs file - if (STATUS_FAILED(result)) - { - std::cout << "Invalid Flatbuffer: Not a NotifyInfoBuffer " << std::string(result.toString()) << std::endl; - continue; - } - - auto info = comm::datalayer::GetNotifyInfo(items[n].info.getData()); // GetNotifyData is generated out of .fbs file - std::cout << " address: " << info->node()->c_str() << std::endl; - std::cout << " timestamp: " << info->timestamp() << std::endl; - std::cout << " notifyType: " << comm::datalayer::EnumNamesNotifyType()[info->notifyType()] << std::endl; - } - }; -} - -comm::datalayer::DlResult DataLayerClientSub::subscribeSync(const std::string &id, const std::string &address) -{ - auto result = _datalayerClient->subscribeSync(id, address); - if (STATUS_FAILED(result)) - { - std::cout << "subscribeSync of " << address << " with " << id << " failed with: " << std::string(result.toString()) << std::endl; - return result; - } - - std::cout << "subscribeSync of " << address << " with " << id << " was successful " << std::string(result.toString()) << std::endl; - return result; -} - -comm::datalayer::DlResult DataLayerClientSub::subscribeSync_Multi(const std::string &id, const std::set &addresses) -{ - auto result = _datalayerClient->subscribeSync(id, addresses); - if (STATUS_FAILED(result)) - { - std::cout << "subscribeSync_Multi " - << " with " << id << " failed with: " << std::string(result.toString()) << std::endl; - return result; - } - std::cout << "subscribeSync_Multi " - << " with " << id << " was successful " << std::string(result.toString()) << std::endl; - return result; -} - -comm::datalayer::DlResult DataLayerClientSub::unsubscribeSync(const std::string &id) -{ - auto result = _datalayerClient->unsubscribeSync(id); - if (STATUS_FAILED(result)) - { - std::cout << "unsubscribeSync from " << id << " failed with: " << std::string(result.toString()) << std::endl; - return result; - } - std::cout << "unsubscribeSync from " << id << " was successful: " << std::string(result.toString()) << std::endl; - return DL_OK; -} - -void DataLayerClientSub::disconnect() -{ - delete _datalayerClient; -} +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +#include "comm/datalayer/sub_properties_generated.h" + +#include "datalayerclientsub.h" +DataLayerClientSub::DataLayerClientSub(const comm::datalayer::DatalayerSystem& datalayerSystem) + : m_datalayerSystem(datalayerSystem) + , m_datalayerClient(nullptr) +{} + +DataLayerClientSub::~DataLayerClientSub() +{ + disconnect(); +} + +comm::datalayer::DlResult DataLayerClientSub::connect(const std::string& clientConnection) +{ + std::cout << "_datalayerSystem.factory()->createClient2: " << clientConnection << std::endl; + m_datalayerClient = m_datalayerSystem.factory()->createClient2(clientConnection); + if (m_datalayerClient == nullptr) + { + std::cout << "ERROR: Could not create datalayer client instance" << std::endl; + return DL_CREATION_FAILED; + } + + return isConnected(); +} + +comm::datalayer::DlResult DataLayerClientSub::isConnected() +{ + if (m_datalayerClient == nullptr || m_datalayerClient->isConnected() == false) + { + return DL_CLIENT_NOT_CONNECTED; + } + + return DL_OK; +} + +comm::datalayer::DlResult DataLayerClientSub::createSubscriptionSync(const std::string& id) +{ + flatbuffers::FlatBufferBuilder builder; + auto dataChange = comm::datalayer::CreateSampling(builder, 250000); + auto rule = comm::datalayer::CreateProperty(builder, comm::datalayer::Properties::Properties_Sampling, dataChange.Union()); + auto rules = builder.CreateVector(&rule, 1); + auto idTmp = builder.CreateString(id); + builder.Finish(comm::datalayer::CreateSubscriptionProperties(builder, idTmp, 60000, 250, rules)); + comm::datalayer::Variant subscriptionProperties; + subscriptionProperties.shareFlatbuffers(builder); + + auto result = m_datalayerClient->createSubscriptionSync(subscriptionProperties, publishCallback()); + if (STATUS_FAILED(result)) + { + std::cout << "createSubscriptionSync failed with " << std::string(result.toString()) << std::endl; + return result; + } + + return result; +} + +// This method returns a comm::datalayer::PublishCallback function as lambda expression. +// See: +// https://en.cppreference.com/w/cpp/language/lambda +// https://de.cppreference.com/w/cpp/language/lambda +comm::datalayer::PublishCallback DataLayerClientSub::publishCallback() +{ + return [&](comm::datalayer::DlResult result, const std::vector& items) + { + std::cout << "--------------- Data has been changed! Result: " << result.toString() << std::endl; + + // check if datalayer-exess was ok + if (result != DL_OK) + { + std::cout << "DL Error" << std::endl; + return; + } + + // check if items is not a nullpointer + if (items.empty()) + { + std::cout << "No items" << std::endl; + return; + } + + for (int n = 0; n < items.size(); n++) + { + std::cout << "Item #" << n << std::endl; + std::cout << " type:" << items[n].data.typeAsString() << std::endl; + std::cout << " size:" << items[n].data.getSize() << std::endl; + + if (comm::datalayer::STATUS_SUCCEEDED(items[n].data.checkConvert(comm::datalayer::VariantType::FLOAT64))) + { + std::cout << " value: " << static_cast(items[n].data) << std::endl; + } + else if (comm::datalayer::STATUS_SUCCEEDED(items[n].data.checkConvert(comm::datalayer::VariantType::STRING))) + { + std::cout << " value: " << static_cast(items[n].data) << std::endl; + } + else + { + std::cout << " can't print value with this data type" << std::endl; + continue; + } + + // get the info of the notify_item (defined in notify_info.fbs) + + auto result = (items[n].info.verifyFlatbuffers(comm::datalayer::VerifyNotifyInfoBuffer)); // VerifyNotifyInfoBuffer is generated out of notify_info.fbs file + if (STATUS_FAILED(result)) + { + std::cout << "Invalid Flatbuffer: Not a NotifyInfoBuffer " << std::string(result.toString()) << std::endl; + continue; + } + + auto info = comm::datalayer::GetNotifyInfo(items[n].info.getData()); // GetNotifyData is generated out of .fbs file + std::cout << " address: " << info->node()->c_str() << std::endl; + std::cout << " timestamp: " << info->timestamp() << std::endl; + std::cout << " notifyType: " << comm::datalayer::EnumNamesNotifyType()[info->notifyType()] << std::endl; + } + }; +} + +comm::datalayer::DlResult DataLayerClientSub::subscribeSync(const std::string& id, const std::string& address) +{ + auto result = m_datalayerClient->subscribeSync(id, address); + if (STATUS_FAILED(result)) + { + std::cout << "subscribeSync of " << address << " with " << id << " failed with: " << std::string(result.toString()) << std::endl; + return result; + } + + std::cout << "subscribeSync of " << address << " with " << id << " was successful " << std::string(result.toString()) << std::endl; + return result; +} + +comm::datalayer::DlResult DataLayerClientSub::subscribeSyncMulti(const std::string& id, const std::set& addresses) +{ + auto result = m_datalayerClient->subscribeSync(id, addresses); + if (STATUS_FAILED(result)) + { + std::cout << "subscribeSync_Multi " + << " with " << id << " failed with: " << std::string(result.toString()) << std::endl; + return result; + } + std::cout << "subscribeSync_Multi " + << " with " << id << " was successful " << std::string(result.toString()) << std::endl; + return result; +} + +comm::datalayer::DlResult DataLayerClientSub::unsubscribeSync(const std::string& id) +{ + auto result = m_datalayerClient->unsubscribeSync(id); + if (STATUS_FAILED(result)) + { + std::cout << "unsubscribeSync from " << id << " failed with: " << std::string(result.toString()) << std::endl; + return result; + } + std::cout << "unsubscribeSync from " << id << " was successful: " << std::string(result.toString()) << std::endl; + return DL_OK; +} + +void DataLayerClientSub::disconnect() +{ + delete m_datalayerClient; + m_datalayerClient = nullptr; +} diff --git a/samples-cpp/datalayer.client.sub/datalayerclientsub.h b/samples-cpp/datalayer.client.sub/datalayerclientsub.h index ca97a6a98..9bd9c23ef 100644 --- a/samples-cpp/datalayer.client.sub/datalayerclientsub.h +++ b/samples-cpp/datalayer.client.sub/datalayerclientsub.h @@ -1,59 +1,43 @@ -/** - * MIT License - * - * Copyright (c) 2021 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include - -#include "comm/datalayer/datalayer.h" -#include "comm/datalayer/datalayer_system.h" -#include "comm/datalayer/metadata_generated.h" -#include "comm/datalayer/notify_info_generated.h" - -class DataLayerClientSub -{ -private: - comm::datalayer::DatalayerSystem _datalayerSystem; - - comm::datalayer::IClient2 *_datalayerClient; - - comm::datalayer::PublishCallback publishCallback(); - -public: - - DataLayerClientSub(const comm::datalayer::DatalayerSystem &datalayerSystem); - - comm::datalayer::DlResult connect(const std::string &clientConnection); - - comm::datalayer::DlResult isConnected(); - - comm::datalayer::DlResult createSubscriptionSync(const std::string &id); - - comm::datalayer::DlResult subscribeSync(const std::string &id, const std::string &address); - - comm::datalayer::DlResult subscribeSync_Multi(const std::string &id, const std::set &addresses); - - comm::datalayer::DlResult unsubscribeSync(const std::string &id); - - void disconnect(); -}; +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include "comm/datalayer/datalayer.h" +#include "comm/datalayer/datalayer_system.h" +#include "comm/datalayer/metadata_generated.h" +#include "comm/datalayer/notify_info_generated.h" + +class DataLayerClientSub final +{ +private: + comm::datalayer::DatalayerSystem m_datalayerSystem; + + comm::datalayer::IClient2* m_datalayerClient; + + comm::datalayer::PublishCallback publishCallback(); + +public: + + DataLayerClientSub(const comm::datalayer::DatalayerSystem& datalayerSystem); + + ~DataLayerClientSub(); + + comm::datalayer::DlResult connect(const std::string& clientConnection); + + comm::datalayer::DlResult isConnected(); + + comm::datalayer::DlResult createSubscriptionSync(const std::string& id); + + comm::datalayer::DlResult subscribeSync(const std::string& id, const std::string& address); + + comm::datalayer::DlResult subscribeSyncMulti(const std::string& id, const std::set& addresses); + + comm::datalayer::DlResult unsubscribeSync(const std::string& id); + + void disconnect(); +}; diff --git a/samples-cpp/datalayer.client.sub/main.cpp b/samples-cpp/datalayer.client.sub/main.cpp index 893114132..fb258a11f 100644 --- a/samples-cpp/datalayer.client.sub/main.cpp +++ b/samples-cpp/datalayer.client.sub/main.cpp @@ -1,87 +1,64 @@ -/** - * MIT License - * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "ctrlx_datalayer_helper.h" - -#include "datalayerclientsub.h" - -int main() -{ - -#ifdef MY_DEBUG - std::cout << "Raising SIGSTOP" << std::endl; - raise(SIGSTOP); - std::cout << "... Continue..." << std::endl; -#endif - - comm::datalayer::DatalayerSystem datalayerSystem; - datalayerSystem.start(false); - - auto dataLayerClientSub = new DataLayerClientSub(datalayerSystem); - - auto clientConnectionString = getConnectionString(); - auto result = dataLayerClientSub->connect(clientConnectionString); - if (STATUS_FAILED(result)) - { - std::cout << "ERROR Connection failed: " << clientConnectionString << std::endl; - dataLayerClientSub->disconnect(); - datalayerSystem.stop(false); - return 1; - } - - int counter = 1; - unsigned int sleepTime = 10; - for (;;) - { - result = dataLayerClientSub->isConnected(); - if (STATUS_FAILED(result)) - { - break; - } - - std::cout << "Loop #" << counter++ << std::endl; - std::cout << "--------------------------------------------" << std::endl; - - dataLayerClientSub->createSubscriptionSync("Sub1"); - dataLayerClientSub->subscribeSync("Sub1", "framework/metrics/system/cpu-utilisation-percent"); - dataLayerClientSub->subscribeSync("Sub1", "framework/metrics/system/memavailable-mb"); - std::cout << "Sleeping ..." << std::endl; - sleep(sleepTime); - dataLayerClientSub->unsubscribeSync("Sub1"); - - dataLayerClientSub->createSubscriptionSync("Sub2"); - std::set addresses; - addresses.insert("framework/metrics/system/memused-percent"); - addresses.insert("framework/metrics/system/memused-mb"); - dataLayerClientSub->subscribeSync_Multi("Sub2", addresses); - std::cout << "Sleeping ..." << std::endl; - sleep(sleepTime); - dataLayerClientSub->unsubscribeSync("Sub2"); - } - - std::cout << "ERROR Data Layer is disconnected" << std::endl; - dataLayerClientSub->disconnect(); - datalayerSystem.stop(false); // Attention: Doesn't return if any provider or client instance is still runnning - return 1; -} \ No newline at end of file +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + +#include "ctrlx_datalayer_helper.h" + +#include "datalayerclientsub.h" + +int main() +{ + + comm::datalayer::DatalayerSystem datalayerSystem; + datalayerSystem.start(false); + + auto dataLayerClientSub = new DataLayerClientSub(datalayerSystem); + + auto clientConnectionString = getConnectionString(); // default: ctrlX CORE or ctrlX COREvirtual with Network Adpater + //auto clientConnectionString = getConnectionString("10.0.2.2","boschrexroth","boschrexroth", 8443); // ctrlX COREvirtual with Port Forwarding + auto result = dataLayerClientSub->connect(clientConnectionString); + if (STATUS_FAILED(result)) + { + std::cout << "ERROR Connection failed: " << clientConnectionString << std::endl; + dataLayerClientSub->disconnect(); + datalayerSystem.stop(false); + return 1; + } + + int counter = 1; + unsigned int sleepTime = 10; + for (;;) + { + result = dataLayerClientSub->isConnected(); + if (STATUS_FAILED(result)) + { + break; + } + + std::cout << "Loop #" << counter++ << std::endl; + std::cout << "--------------------------------------------" << std::endl; + + dataLayerClientSub->createSubscriptionSync("Sub1"); + dataLayerClientSub->subscribeSync("Sub1", "framework/metrics/system/cpu-utilisation-percent"); + dataLayerClientSub->subscribeSync("Sub1", "framework/metrics/system/memavailable-mb"); + std::cout << "Sleeping ..." << std::endl; + sleep(sleepTime); + dataLayerClientSub->unsubscribeSync("Sub1"); + + dataLayerClientSub->createSubscriptionSync("Sub2"); + std::set addresses; + addresses.insert("framework/metrics/system/memused-percent"); + addresses.insert("framework/metrics/system/memused-mb"); + dataLayerClientSub->subscribeSyncMulti("Sub2", addresses); + std::cout << "Sleeping ..." << std::endl; + sleep(sleepTime); + dataLayerClientSub->unsubscribeSync("Sub2"); + } + + std::cout << "ERROR ctrlX Data Layer is disconnected" << std::endl; + dataLayerClientSub->disconnect(); + datalayerSystem.stop(false); // Attention: Doesn't return if any provider or client instance is still runnning + return 0; +} diff --git a/samples-cpp/datalayer.client.sub/snap/snapcraft.yaml b/samples-cpp/datalayer.client.sub/snap/snapcraft.yaml index 7584eed36..2255443f8 100644 --- a/samples-cpp/datalayer.client.sub/snap/snapcraft.yaml +++ b/samples-cpp/datalayer.client.sub/snap/snapcraft.yaml @@ -6,12 +6,12 @@ name: sdk-cpp-sub version: "2.2.0" grade: stable -summary: SDK sample app in cpp - subscribes Data Layer nodes +summary: SDK sample app in cpp - subscribes ctrlX Data Layer nodes description: | - This sample demonstrates how to use Data Layer subscriptions on Datalayer. + This sample demonstrates how to use ctrlX Data Layer subscriptions on Datalayer. It subscribes the nodes: framework/metrics/system/cpu-utilisation-percent and .../memavailable-mb. If a value of a node has changed it writes the new value to the console. -base: core20 +base: core22 confinement: strict # define how apps & services are exposed to the target operating system diff --git a/samples-cpp/datalayer.client/.vscode/launch.json b/samples-cpp/datalayer.client/.vscode/launch.json index 08e16775a..4b7c5caae 100644 --- a/samples-cpp/datalayer.client/.vscode/launch.json +++ b/samples-cpp/datalayer.client/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/datalayerClient", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerClient", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,8 +23,8 @@ }, { "description": "Set path variable to .", - //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu20-gcc-x64/debug/usr/lib/", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu22-gcc-x64/debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] diff --git a/samples-cpp/datalayer.client/.vscode/tasks.json b/samples-cpp/datalayer.client/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-cpp/datalayer.client/.vscode/tasks.json +++ b/samples-cpp/datalayer.client/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/datalayer.client/CMakeLists.txt b/samples-cpp/datalayer.client/CMakeLists.txt index b23f140e2..2b2c2ab71 100644 --- a/samples-cpp/datalayer.client/CMakeLists.txt +++ b/samples-cpp/datalayer.client/CMakeLists.txt @@ -42,12 +42,12 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET(PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET(PLATFORM_NAME "ubuntu22-gcc-aarch64") SET(SNAP_ARCH "arm64") SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET(PLATFORM_NAME "ubuntu20-gcc-x64") + SET(PLATFORM_NAME "ubuntu22-gcc-x64") SET(SNAP_ARCH "amd64") SET(CMAKE_C_COMPILER gcc) SET(CMAKE_CXX_COMPILER g++) @@ -70,7 +70,6 @@ SET ( PRIVATE_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/include ${USER_DEPENDENCY_DIR}/include - ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers.1.12 ${USER_DEPENDENCY_DIR}/include/comm.datalayer ) @@ -80,13 +79,13 @@ SET ( PRIVATE_INCLUDE_DIRS # execute_process(COMMAND uname -a OUTPUT_VARIABLE HOST_SYSTEM_ARCH) IF( ${HOST_SYSTEM_ARCH} MATCHES "aarch64") - set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers.1.12/ubuntu20-gcc-aarch64/release/flatc) + set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers/ubuntu22-gcc-aarch64/release/flatc) ELSE() - set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers.1.12/ubuntu20-gcc-x64/release/flatc) + set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers/ubuntu22-gcc-x64/release/flatc) ENDIF() execute_process(COMMAND chmod +x ${FLATBUFFERS_FLATC_EXECUTABLE}) -set (FLATBUFFERS_INCLUDE_DIR ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers.1.12) -include (${USER_DEPENDENCY_DIR}/cmake/oss.flatbuffers.1.12/FindFlatBuffers.cmake) +set (FLATBUFFERS_INCLUDE_DIR ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers) +include (${USER_DEPENDENCY_DIR}/cmake/oss.flatbuffers/FindFlatBuffers.cmake) set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--gen-object-api") set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--no-warnings") set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--gen-compare") diff --git a/samples-cpp/datalayer.client/LICENSE b/samples-cpp/datalayer.client/LICENSE deleted file mode 100644 index d1231b68e..000000000 --- a/samples-cpp/datalayer.client/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/datalayer.client/README.md b/samples-cpp/datalayer.client/README.md index 64b7e97b5..e910b9a9d 100644 --- a/samples-cpp/datalayer.client/README.md +++ b/samples-cpp/datalayer.client/README.md @@ -2,31 +2,31 @@ ## Introduction -The sample app __datalayer.client__ performs Data Layer operations in cpp. +The sample app __datalayer.client__ performs ctrlX Data Layer operations in cpp. ## Prerequisites -The sample requires that the app datalayer.provider.all-data is running in the SDK build environment or as snap on the crlX CORE. +The sample requires that the app datalayer.provider.all-data is running in the SDK build environment or as snap on the crlX CORE. ## Function Description The app reads demonstrates how values of existing nodes of the ctrlX Data Layer can be accessed. -## Implementation Description +## Implementation Description ctrlx_datalayer_helper.h Cpontains helper methods for creating ctrlX Datalayer Client and/or Provider instances. -datalayerclient.cpp und datalayerclient.h are defining a class which manages the Data Layer client access: +datalayerclient.cpp und datalayerclient.h are defining a class which manages the ctrlX Data Layer client access: -* Starting/stopping the Data Layer access -* Access of Data Layer nodes of different data type -* Callback methods for Data Layer access +* Starting/stopping the ctrlX Data Layer access +* Access of ctrlX Data Layer nodes of different data type +* Callback methods for ctrlX Data Layer access In main.cpp an endless loop is running: * An instance of the class DataLayerClient is created -* The instance is called to do Data Layer access +* The instance is called to do ctrlX Data Layer access * The instance is deleted * Sleep some time @@ -43,24 +43,5 @@ ___ ## License -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/datalayer.client/build-snap-amd64.sh b/samples-cpp/datalayer.client/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/datalayer.client/build-snap-amd64.sh +++ b/samples-cpp/datalayer.client/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.client/build-snap-arm64.sh b/samples-cpp/datalayer.client/build-snap-arm64.sh index e736dbbda..68cc05e73 100644 --- a/samples-cpp/datalayer.client/build-snap-arm64.sh +++ b/samples-cpp/datalayer.client/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.client/ctrlx_datalayer_helper.h b/samples-cpp/datalayer.client/ctrlx_datalayer_helper.h index 3fdec3b7d..d0683514f 100644 --- a/samples-cpp/datalayer.client/ctrlx_datalayer_helper.h +++ b/samples-cpp/datalayer.client/ctrlx_datalayer_helper.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef CTRLX_DATALAYER_HELPER_H @@ -43,17 +25,17 @@ * If these values do not suit your use case, explicitly pass the parameters that require different values. * Here some examples: * - * 1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: + * 1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: * * client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") * - * 2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): + * 2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): * * client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) * * Remarks: * 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual * * * IMPORTANT: @@ -84,10 +66,10 @@ static bool isSnap() } //! Get Datalayer connection string -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result Connection string static std::string getConnectionString( const std::string& ip = "192.168.1.1", @@ -112,10 +94,10 @@ static std::string getConnectionString( //! Get Datalayer Client instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IClient instance or nullptr on error static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", @@ -136,10 +118,10 @@ static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& dat //! Get Datalayer Provider instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IProvider instance or nullptr on error static comm::datalayer::IProvider* getProvider(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", diff --git a/samples-cpp/datalayer.client/datalayerclient.cpp b/samples-cpp/datalayer.client/datalayerclient.cpp index 5f8559a9a..99e6d398d 100644 --- a/samples-cpp/datalayer.client/datalayerclient.cpp +++ b/samples-cpp/datalayer.client/datalayerclient.cpp @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2020-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #include @@ -29,13 +11,13 @@ #include "ctrlx_datalayer_helper.h" #include "datalayerclient.h" -// Function to print out array of all nodes from VariantType on ctrlX Data Layer -void printStringList(comm::datalayer::Variant &data) + // Function to print out array of all nodes from VariantType on ctrlX Data Layer +static void printStringList(comm::datalayer::Variant& data) { if (data.getType() == comm::datalayer::VariantType::ARRAY_OF_STRING) { std::cout << "Node List: "; - const char **strArray = data; + const char** strArray = data; for (uint32_t i = 0; i < data.getCount(); i++) { std::cout << strArray[i] << " "; @@ -44,7 +26,7 @@ void printStringList(comm::datalayer::Variant &data) } } -void printMetadata(comm::datalayer::Variant &data) +static void printMetadata(comm::datalayer::Variant& data) { if (STATUS_FAILED(data.verifyFlatbuffers(comm::datalayer::VerifyMetadataBuffer))) { @@ -69,30 +51,24 @@ void printMetadata(comm::datalayer::Variant &data) } } -DataLayerClient::DataLayerClient(const std::string &ip, const std::string &user, const std::string &password, int sslPort) -{ - _ip = ip; - _user = user; - _password = password; - _sslPort = sslPort; -} +DataLayerClient::DataLayerClient(const std::string& ip, const std::string& user, const std::string& password, int sslPort) + : m_ip(ip) + , m_user(user) + , m_password(password) + , m_sslPort(sslPort) + , m_client(nullptr) +{} -comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) +comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant* data) { - std::string valueText; - comm::datalayer::DlResult result = comm::datalayer::DlResult::DL_OK; auto variantType = data->getType(); - int16_t x; - int16_t y; - int16_t z; - if (variantType == comm::datalayer::VariantType::FLATBUFFERS) { - result = data->verifyFlatbuffers(sample::schema::VerifyInertialValueBuffer); + comm::datalayer::DlResult result = data->verifyFlatbuffers(sample::schema::VerifyInertialValueBuffer); if (comm::datalayer::STATUS_FAILED(result)) { - valueText = "Node is no InertialValue flatbuffers"; + std::cout << "Node is no InertialValue flatbuffers" << std::endl; return result; } @@ -100,12 +76,15 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) auto buffer = data->getData(); auto inertialValue = sample::schema::GetInertialValue(buffer); + int16_t x; + int16_t y; + int16_t z; + x = inertialValue->x(); y = inertialValue->y(); z = inertialValue->z(); - valueText = "x=" + std::to_string(x) + " y=" + std::to_string(y) + " z=" + std::to_string(z); - std::cout << valueText; + std::cout << "x=" + std::to_string(x) + " y=" + std::to_string(y) + " z=" + std::to_string(z) << std::endl; return comm::datalayer::DlResult::DL_OK; } @@ -115,7 +94,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_BOOL8) { - const bool *values = *data; + const bool* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -126,7 +105,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_FLOAT32) { - const float *values = *data; + const float* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -137,7 +116,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_FLOAT64) { - const double *values = *data; + const double* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -148,7 +127,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_INT16) { - const int16_t *values = *data; + const int16_t* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -159,7 +138,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_INT32) { - const int32_t *values = *data; + const int32_t* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -170,7 +149,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_INT64) { - const int64_t *values = *data; + const int64_t* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -181,7 +160,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_INT8) { - const int8_t *values = *data; + const int8_t* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << std::to_string(values[i]); @@ -192,7 +171,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_STRING) { - const char **values = *data; + const char** values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i] << " "; @@ -202,7 +181,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_UINT16) { - const uint16_t *values = *data; + const uint16_t* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -213,7 +192,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_UINT32) { - const uint32_t *values = *data; + const uint32_t* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -224,7 +203,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_UINT64) { - const uint64_t *values = *data; + const uint64_t* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << values[i]; @@ -235,7 +214,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::ARRAY_OF_UINT8) { - const uint8_t *values = *data; + const uint8_t* values = *data; for (uint32_t i = 0; i < data->getCount(); i++) { std::cout << std::to_string(values[i]); @@ -302,7 +281,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) if (variantType == comm::datalayer::VariantType::STRING) { - const char *value = *data; + const char* value = *data; std::cout << value; return comm::datalayer::DlResult::DL_OK; @@ -336,7 +315,7 @@ comm::datalayer::DlResult DataLayerClient::print(comm::datalayer::Variant *data) return comm::datalayer::DlResult::DL_UNSUPPORTED; } -void DataLayerClient::println(const std::string &text, comm::datalayer::DlResult result, comm::datalayer::Variant *data) +void DataLayerClient::println(const std::string& text, comm::datalayer::DlResult result, comm::datalayer::Variant* data) { std::cout << text; std::cout << " " << result.toString() << " "; @@ -348,12 +327,12 @@ void DataLayerClient::println(const std::string &text, comm::datalayer::DlResult bool DataLayerClient::start() { - std::cout << "_datalayer.start(..)" << std::endl; - _datalayerSystem.start(false); + std::cout << "m_datalayer.start(..)" << std::endl; + m_datalayerSystem.start(false); - _client = getClient(_datalayerSystem, _ip, _user, _password, _sslPort); + m_client = getClient(m_datalayerSystem, m_ip, m_user, m_password, m_sslPort); - return _client != nullptr && _client->isConnected(); + return m_client != nullptr && m_client->isConnected(); } // This method returns a comm::datalayer::IClient::ResponseCallback function as lambda expression. @@ -364,17 +343,17 @@ comm::datalayer::IClient::ResponseCallback DataLayerClient::responseCallback() { // [&] All needed symbols are provided per reference // (...) Parameter provided by the calling site - return [&](comm::datalayer::DlResult result, const comm::datalayer::Variant *data) + return [&](comm::datalayer::DlResult result, const comm::datalayer::Variant* data) { - _resultAsync = result; + m_resultAsync = result; if (data != nullptr) { // data must not be nullptr otherwise the '=' operator crashes - _dataAsync = *data; + m_dataAsync = *data; - if (_dataAsync.getType() == comm::datalayer::VariantType::ARRAY_OF_STRING) + if (m_dataAsync.getType() == comm::datalayer::VariantType::ARRAY_OF_STRING) { - printStringList(_dataAsync); + printStringList(m_dataAsync); } } @@ -390,14 +369,16 @@ bool DataLayerClient::waitForResponseCallback(int counter) { counter--; if (counter <= 0) + { return false; + } } sleep(1); - if (_resultAsync != -1) + if (m_resultAsync != -1) { - std::cout << "ResponseCallback finished: " << _resultAsync.toString() << std::endl; + std::cout << "ResponseCallback finished: " << m_resultAsync.toString() << std::endl; return true; } } @@ -405,19 +386,19 @@ bool DataLayerClient::waitForResponseCallback(int counter) void DataLayerClient::ping() { - _result = _client->pingSync(); - std::cout << "_client->pingSync() " << _result.toString() << std::endl; + m_result = m_client->pingSync(); + std::cout << "m_client->pingSync() " << m_result.toString() << std::endl; - _resultAsync = -1; - _result = _client->pingAsync(responseCallback()); + m_resultAsync = -1; + m_result = m_client->pingAsync(responseCallback()); waitForResponseCallback(10); } -void DataLayerClient::readSync(const std::string &node) +void DataLayerClient::readSync(const std::string& node) { std::string address = "sdk-cpp-alldata/static/" + node; - _result = _client->readSync(address, &_data); - println("readSync() " + address, _result, &_data); + m_result = m_client->readSync(address, &m_data); + println("readSync() " + address, m_result, &m_data); } void DataLayerClient::read() @@ -427,9 +408,9 @@ void DataLayerClient::read() std::string address = "sdk-cpp-alldata/static/bool8"; - _result = _client->readAsync(address, _data, responseCallback()); + m_result = m_client->readAsync(address, m_data, responseCallback()); - std::cout << "readAsync()" << _result.toString() << std::endl; + std::cout << "readAsync()" << m_result.toString() << std::endl; waitForResponseCallback(10); @@ -482,173 +463,173 @@ void DataLayerClient::read() readSync("array-of-uint64"); } -void DataLayerClient::createSync(const std::string &node) +void DataLayerClient::createSync(const std::string& node) { std::string address = "/sdk-cpp-alldata/dynamic/_cpp/" + node; - _client->removeSync(address); // First remove - may be node exists - _result = _client->createSync(address, &_data); + m_client->removeSync(address); // First remove - may be node exists + m_result = m_client->createSync(address, &m_data); } void DataLayerClient::create() { - _data.setValue(false); + m_data.setValue(false); createSync("bool8"); - _data.setValue(-0.123456789f); + m_data.setValue(-0.123456789f); createSync("float32"); - _data.setValue(-0.987654321); + m_data.setValue(-0.987654321); createSync("float64"); - _data.setValue((int8_t)-127); + m_data.setValue((int8_t)-127); createSync("int8"); - _data.setValue((int16_t)-32767); + m_data.setValue((int16_t)-32767); createSync("int16"); - _data.setValue((int32_t)0x80000001); + m_data.setValue((int32_t)0x80000001); createSync("int32"); - _data.setValue((int64_t)0x8000000000000001); + m_data.setValue((int64_t)0x8000000000000001); createSync("int64"); - _data.setValue("Changed by cpp Data Layer Client"); + m_data.setValue("Changed by cpp ctrlX Data Layer Client"); createSync("string"); // Flatbuffers bool arrBool[] = {false, true, false}; - _data.setValue(arrBool); + m_data.setValue(arrBool); createSync("array-of-bool8"); int8_t arrInt8[] = {-127, -1, 0, 127}; - _data.setValue(arrBool); + m_data.setValue(arrBool); createSync("array-of-int8"); uint8_t arrUint8[] = {0, 127, 128, 255}; - _data.setValue(arrUint8); + m_data.setValue(arrUint8); createSync("array-of-uint8"); int16_t arrInt16[] = {-32767, -1, 0, 32767}; - _data.setValue(arrInt16); + m_data.setValue(arrInt16); createSync("array-of-int16"); uint16_t arrUint16[] = {0, 32767, 32768, 65535}; - _data.setValue(arrUint16); + m_data.setValue(arrUint16); createSync("array-of-uint16"); int32_t arrInt32[] = {-2147483647, -1, 0, 2147483647}; - _data.setValue(arrInt32); + m_data.setValue(arrInt32); createSync("array-of-int32"); uint32_t arrUint32[] = {0, 2147483647, 2147483648, 4294967295}; - _data.setValue(arrUint32); + m_data.setValue(arrUint32); createSync("array-of-uint32"); int64_t arrInt64[] = {-9223372036854775807, -1, 0, 9223372036854775807}; - _data.setValue(arrInt64); + m_data.setValue(arrInt64); createSync("array-of-int64"); // https://en.cppreference.com/w/cpp/types/numeric_limits/max uint64_t arrUint64[] = {0, 9223372036854775807, std::numeric_limits::max() - 1, std::numeric_limits::max()}; - _data.setValue(arrUint64); + m_data.setValue(arrUint64); createSync("array-of-uint64"); float_t arrFloat32[] = {32.1, 32.2, 32.3, 32.4}; - _data.setValue(arrFloat32); + m_data.setValue(arrFloat32); createSync("array-of-float32"); double_t arrFloat64[] = {64.1, 64.2, 64.3, 64.4}; - _data.setValue(arrFloat64); + m_data.setValue(arrFloat64); createSync("array-of-float64"); std::string arrString[] = {"Red", "Green", "Yellow", "Blue"}; - _data.setValue(arrString); + m_data.setValue(arrString); createSync("array-of-string"); } void DataLayerClient::remove() { - _data.setValue("Will be removed"); + m_data.setValue("Will be removed"); createSync("xxx"); std::string address = "/sdk-cpp-alldata/dynamic/_cpp/xxx"; - _result = _client->removeSync(address); + m_result = m_client->removeSync(address); createSync("xxx"); - _result = _client->removeAsync(address, responseCallback()); + m_result = m_client->removeAsync(address, responseCallback()); waitForResponseCallback(10); } void DataLayerClient::browse() { - _data.setValue(""); - _result = _client->browseSync("", &_data); - if (_result == comm::datalayer::DlResult::DL_OK) + m_data.setValue(""); + m_result = m_client->browseSync("", &m_data); + if (m_result == comm::datalayer::DlResult::DL_OK) { - printStringList(_data); + printStringList(m_data); } - _result = _client->browseAsync("", responseCallback()); + m_result = m_client->browseAsync("", responseCallback()); waitForResponseCallback(10); } -void DataLayerClient::writeSync(const std::string &node) +void DataLayerClient::writeSync(const std::string& node) { std::string address = "sdk-cpp-alldata/dynamic/" + node; - _result = _client->writeSync(address, &_data); - println("writeSync() " + address, _result, &_data); + m_result = m_client->writeSync(address, &m_data); + println("writeSync() " + address, m_result, &m_data); } void DataLayerClient::write() { - _data.setValue(false); + m_data.setValue(false); writeSync("bool8"); - _data.setValue(-0.123456789f); + m_data.setValue(-0.123456789f); writeSync("float32"); - _data.setValue(-0.987654321); + m_data.setValue(-0.987654321); writeSync("float64"); - _data.setValue((int8_t)-127); + m_data.setValue((int8_t)-127); writeSync("int8"); - _data.setValue((int16_t)-32767); + m_data.setValue((int16_t)-32767); writeSync("int16"); - _data.setValue((int32_t)0x80000001); + m_data.setValue((int32_t)0x80000001); writeSync("int32"); - _data.setValue((int64_t)0x8000000000000001); + m_data.setValue((int64_t)0x8000000000000001); writeSync("int64"); - _data.setValue("Changed by cpp Data Layer Client"); + m_data.setValue("Changed by cpp ctrlX Data Layer Client"); writeSync("string"); } void DataLayerClient::metadata() { std::string address = "scheduler/admin/state"; - _result = _client->metadataSync(address, &_data); + m_result = m_client->metadataSync(address, &m_data); - printMetadata(_data); + printMetadata(m_data); } void DataLayerClient::stop() { - delete _client; + delete m_client; + m_client = nullptr; } -void DataLayerClient::Run() +void DataLayerClient::run() { std::cout << "Simple Snap for ctrlX Datalayer Client in cpp" << std::endl; std::cout << "--------------------------------------------" << std::endl; if (start()) { - ping(); read(); create(); diff --git a/samples-cpp/datalayer.client/datalayerclient.h b/samples-cpp/datalayer.client/datalayerclient.h index fc79c102a..1aca0cbea 100644 --- a/samples-cpp/datalayer.client/datalayerclient.h +++ b/samples-cpp/datalayer.client/datalayerclient.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #include @@ -32,20 +14,20 @@ #include "sampleSchema_generated.h" -class DataLayerClient +class DataLayerClient final { private: - std::string _ip; - std::string _user; - std::string _password; - int _sslPort; - comm::datalayer::IClient* _client; - comm::datalayer::DlResult _result; - comm::datalayer::DlResult _resultAsync; - comm::datalayer::Variant _data; - comm::datalayer::Variant _dataAsync; - - comm::datalayer::DatalayerSystem _datalayerSystem; + std::string m_ip; + std::string m_user; + std::string m_password; + int m_sslPort; + comm::datalayer::IClient* m_client; + comm::datalayer::DlResult m_result; + comm::datalayer::DlResult m_resultAsync; + comm::datalayer::Variant m_data; + comm::datalayer::Variant m_dataAsync; + + comm::datalayer::DatalayerSystem m_datalayerSystem; comm::datalayer::IClient::ResponseCallback responseCallback(); @@ -60,19 +42,15 @@ class DataLayerClient bool start(); void ping(); void read(); - void create(); - void remove(); - void browse(); - void write(); - void metadata(); void stop(); public: DataLayerClient(const std::string& ip = "192.168.1.1", const std::string& user = "boschrexroth", const std::string& password = "boschrexroth", int sslPort = 443); - void Run(); + ~DataLayerClient() = default; + void run(); }; diff --git a/samples-cpp/datalayer.client/main.cpp b/samples-cpp/datalayer.client/main.cpp index a162c5d55..3977a18a6 100644 --- a/samples-cpp/datalayer.client/main.cpp +++ b/samples-cpp/datalayer.client/main.cpp @@ -1,51 +1,29 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2020-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #include "datalayerclient.h" -int main() +int main(void) { -#ifdef MY_DEBUG - std::cout << "Raising SIGSTOP" << std::endl; - raise(SIGSTOP); - std::cout << "... Continue..." << std::endl; -#endif int counter = 1; for (;;) { std::cout << "Loop #" << counter++ << std::endl; - // ctrlX CORE or ctrlX CORE virtual with network adapter: + // ctrlX CORE or ctrlX COREvirtual with network adapter: auto dataLayerClient = new DataLayerClient("192.168.1.1", "boschrexroth", "boschrexroth", 443); - // ctrlX CORE virtual with port forwarding: + // ctrlX COREvirtual with port forwarding: // auto dataLayerClient = new DataLayerClient("10.0.2.2", "boschrexroth", "boschrexroth", 8443); - dataLayerClient->Run(); + dataLayerClient->run(); delete dataLayerClient; // Callback are no more called std::cout << "Sleeping..." << std::endl; sleep(2); } + return 0; } diff --git a/samples-cpp/datalayer.client/snap/snapcraft.yaml b/samples-cpp/datalayer.client/snap/snapcraft.yaml index 70d39a15a..c2c8931a3 100644 --- a/samples-cpp/datalayer.client/snap/snapcraft.yaml +++ b/samples-cpp/datalayer.client/snap/snapcraft.yaml @@ -10,7 +10,7 @@ summary: Sample app for datalayer client description: | This app will modify values of 'myData' node provider on Datalayer (requires sample app 'registernode') -base: core20 +base: core22 confinement: strict # define how apps & services are exposed to host system diff --git a/samples-cpp/datalayer.diagnosis/.vscode/launch.json b/samples-cpp/datalayer.diagnosis/.vscode/launch.json index b3ea50c47..2c2ee57a8 100644 --- a/samples-cpp/datalayer.diagnosis/.vscode/launch.json +++ b/samples-cpp/datalayer.diagnosis/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/datalayerDiagnosis", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerDiagnosis", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,8 +23,8 @@ }, { "description": "Set path variable to .", - //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu20-gcc-x64/debug/usr/lib/", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu22-gcc-x64/debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] @@ -33,7 +33,7 @@ "name": "aarch64 ctrlX (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-aarch64/Debug/datalayerDiagnosis", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-aarch64/Debug/datalayerDiagnosis", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "192.168.1.1:12345", @@ -53,7 +53,7 @@ "name": "x64 ctrlX virt. Network Adapter (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/datalayerDiagnosis", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerDiagnosis", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "192.168.1.1:12345", @@ -73,7 +73,7 @@ "name": "x64 ctrlX virt. Port Forwarding (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/datalayerDiagnosis", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerDiagnosis", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "127.0.0.1:12345", diff --git a/samples-cpp/datalayer.diagnosis/.vscode/tasks.json b/samples-cpp/datalayer.diagnosis/.vscode/tasks.json index 4c6318d49..f6039cf35 100644 --- a/samples-cpp/datalayer.diagnosis/.vscode/tasks.json +++ b/samples-cpp/datalayer.diagnosis/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -139,12 +139,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -155,7 +151,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -192,12 +188,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/datalayer.diagnosis/CMakeLists.txt b/samples-cpp/datalayer.diagnosis/CMakeLists.txt index 8d86b9e4f..29ec208be 100644 --- a/samples-cpp/datalayer.diagnosis/CMakeLists.txt +++ b/samples-cpp/datalayer.diagnosis/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required( VERSION 3.9 ) # Project information # Set project, VERSION should be same as snap version # -set(VERSION 1.2.0) +set(VERSION 2.2.0) project( datalayer_diagnosis_snap_project VERSION ${VERSION} ) # @@ -44,16 +44,16 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") # if( UNIX ) IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - MESSAGE(STATUS "Set Platformname to: ubuntu20-gcc-aarch64") + MESSAGE(STATUS "Set Platformname to: ubuntu22-gcc-aarch64") SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) - SET(PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET(PLATFORM_NAME "ubuntu22-gcc-aarch64") SET(SNAP_ARCH "arm64") ELSE() - MESSAGE(STATUS "Set Platformname to: ubuntu20-gcc-x64") + MESSAGE(STATUS "Set Platformname to: ubuntu22-gcc-x64") SET(CMAKE_C_COMPILER gcc) SET(CMAKE_CXX_COMPILER g++) - SET(PLATFORM_NAME "ubuntu20-gcc-x64") + SET(PLATFORM_NAME "ubuntu22-gcc-x64") SET(SNAP_ARCH "amd64") ENDIF() endif() diff --git a/samples-cpp/datalayer.diagnosis/LICENSE b/samples-cpp/datalayer.diagnosis/LICENSE deleted file mode 100644 index 0c6425ecc..000000000 --- a/samples-cpp/datalayer.diagnosis/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/datalayer.diagnosis/README.md b/samples-cpp/datalayer.diagnosis/README.md index ddf3dfc68..a095f1cea 100644 --- a/samples-cpp/datalayer.diagnosis/README.md +++ b/samples-cpp/datalayer.diagnosis/README.md @@ -1,56 +1,37 @@ -# ctrlX Data Layer Diagnosis - -This sample app uses some Data Layer addresses to handle with diagnostics. - -## Introduction - -It demonstrates how to -* register and unregister diagnostics -* subscribe to specific diagnostic events -* set and reset diagnostic logs -* confirm diagnostic errors -* get the highest priority pending log -* get the actual pending list of errors and warnings -* get diagnostic texts from diagnostic numbers - -## Prerequisites - -* Installed app rexroth-automationcore - -## Build and Install the Snap - -Build and install the snap like described [here](../README.md). - -## Test the Snap - -* Open the web interface of your ctrlX CORE -* Check output in the web interface - - -![Output in diagnosis logbook](docs/images/datalayer.diagnosis/datalayer_tree_diagnosis.png) - -___ - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# ctrlX Data Layer Diagnosis + +This sample app uses some ctrlX Data Layer addresses to handle with diagnostics. + +## Introduction + +It demonstrates how to +* register and unregister diagnostics +* subscribe to specific diagnostic events +* set and reset diagnostic logs +* confirm diagnostic errors +* get the highest priority pending log +* get the actual pending list of errors and warnings +* get diagnostic texts from diagnostic numbers + +## Prerequisites + +* Installed app rexroth-automationcore + +## Build and Install the Snap + +Build and install the snap like described [here](../README.md). + +## Test the Snap + +* Open the web interface of your ctrlX CORE +* Check output in the web interface + + +![Output in diagnosis logbook](docs/images/datalayer.diagnosis/datalayer_tree_diagnosis.png) + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/datalayer.diagnosis/build-snap-amd64.sh b/samples-cpp/datalayer.diagnosis/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/datalayer.diagnosis/build-snap-amd64.sh +++ b/samples-cpp/datalayer.diagnosis/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.diagnosis/build-snap-arm64.sh b/samples-cpp/datalayer.diagnosis/build-snap-arm64.sh index f48f8a433..8be304510 100644 --- a/samples-cpp/datalayer.diagnosis/build-snap-arm64.sh +++ b/samples-cpp/datalayer.diagnosis/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.diagnosis/ctrlx_datalayer_helper.h b/samples-cpp/datalayer.diagnosis/ctrlx_datalayer_helper.h index 3fdec3b7d..d0683514f 100644 --- a/samples-cpp/datalayer.diagnosis/ctrlx_datalayer_helper.h +++ b/samples-cpp/datalayer.diagnosis/ctrlx_datalayer_helper.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef CTRLX_DATALAYER_HELPER_H @@ -43,17 +25,17 @@ * If these values do not suit your use case, explicitly pass the parameters that require different values. * Here some examples: * - * 1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: + * 1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: * * client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") * - * 2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): + * 2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): * * client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) * * Remarks: * 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual * * * IMPORTANT: @@ -84,10 +66,10 @@ static bool isSnap() } //! Get Datalayer connection string -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result Connection string static std::string getConnectionString( const std::string& ip = "192.168.1.1", @@ -112,10 +94,10 @@ static std::string getConnectionString( //! Get Datalayer Client instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IClient instance or nullptr on error static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", @@ -136,10 +118,10 @@ static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& dat //! Get Datalayer Provider instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IProvider instance or nullptr on error static comm::datalayer::IProvider* getProvider(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", diff --git a/samples-cpp/datalayer.diagnosis/main.cpp b/samples-cpp/datalayer.diagnosis/main.cpp index 367925468..7dd615cdb 100644 --- a/samples-cpp/datalayer.diagnosis/main.cpp +++ b/samples-cpp/datalayer.diagnosis/main.cpp @@ -1,639 +1,612 @@ -/** - * MIT License - * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include - -#include "comm/datalayer/datalayer.h" -#include "comm/datalayer/datalayer_system.h" -#include "comm/datalayer/metadata_helper.h" -#include "comm/datalayer/sub_properties_generated.h" -#include "comm/datalayer/notify_info_generated.h" - -#include "common/log/diagnosis/registration_file_generated.h" -#include "common/log/diagnosis/set_generated.h" -#include "common/log/diagnosis/diagnosis_identification_generated.h" -#include "common/log/diagnosis/list_diagnosis_identification_with_timestamp_generated.h" -#include "common/log/diagnosis/get_main_text_generated.h" -#include "common/log/diagnosis/get_detailed_text_generated.h" -#include "common/log/diagnosis/event_type_1_generated.h" -#include "common/log/diagnosis/event_type_2_generated.h" -#include "common/log/diagnosis/pending_diagnostic_state_generated.h" -#include "common/log/diagnosis/i_log2.h" - -#include "ctrlx_datalayer_helper.h" - -comm::datalayer::PublishCallback eventsCallback() -{ - return [&](comm::datalayer::DlResult status, const std::vector &items) - { - std::cout << " Got notification" << std::endl; - - if (comm::datalayer::STATUS_FAILED(status)) - { - std::cerr << " Status: " << status.toString() << std::endl; - return; - } - - for (auto item = items.begin(); item != items.end(); item++) - { - auto info = comm::datalayer::GetNotifyInfo(item->info.getData()); - - std::cout << " Got notification '" << comm::datalayer::EnumNameNotifyType(info->notifyType()) << "' for node '" << info->node()->c_str() << "'." << std::endl; - if (comm::datalayer::NotifyType_Data != info->notifyType()) - { - continue; - } - comm::datalayer::Variant value = item->data; - std::string nodeAdress = info->node()->c_str(); - if (0 == nodeAdress.compare("diagnosis/events/message-set")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); - std::cout << " Event counter (diagnosis/events/message-set): " << eventData->eventCounter() << std::endl; - continue; - } - - if (0 == nodeAdress.compare("diagnosis/events/warning-set")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); - std::cout << " Event counter (diagnosis/events/warning-set): " << eventData->eventCounter() << std::endl; - continue; - } - - if (0 == nodeAdress.compare("diagnosis/events/error-set-F0")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); - std::cout << " Event counter (diagnosis/events/error-set-F0): " << eventData->eventCounter() << std::endl; - continue; - } - - if (0 == nodeAdress.compare("diagnosis/events/error-set-F2")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); - std::cout << " Event counter (diagnosis/events/error-set-F2): " << eventData->eventCounter() << std::endl; - continue; - } - - if (0 == nodeAdress.compare("diagnosis/events/error-set-F6")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); - std::cout << " Event counter (diagnosis/events/error-set-F6): " << eventData->eventCounter() << std::endl; - continue; - } - if (0 == nodeAdress.compare("diagnosis/events/highest-pending-log-none")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); - std::cout << " Event counter (diagnosis/events/highest-pending-log-none): " << eventData->eventCounter() << std::endl; - continue; - } - if (0 == nodeAdress.compare("diagnosis/events/highest-pending-log-warning")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); - std::cout << " Event counter (diagnosis/events/highest-pending-log-warning): " << eventData->eventCounter() << std::endl; - continue; - } - - if (0 == nodeAdress.compare("diagnosis/events/highest-pending-log-error")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); - std::cout << " Event counter (diagnosis/events/highest-pending-log-error): " << eventData->eventCounter() << std::endl; - continue; - } - - if (0 == nodeAdress.compare("diagnosis/events/reset-all-pending")) - { - if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType2Buffer))) - { - std::cerr << " Invalid argument type for data" << std::endl; - return; - } - - auto eventData = common::log::diagnosis::fbs::GetEventType2(value.getData()); - std::cout << " Event counter (diagnosis/events/reset-all-pending): " << eventData->eventCounter() << std::endl; - } - } - }; -} - -int main() -{ -#ifdef MY_DEBUG - std::cout << "Raising SIGSTOP" << std::endl; - raise(SIGSTOP); - std::cout << "... Continue..." << std::endl; -#endif - - comm::datalayer::DatalayerSystem datalayer; - datalayer.start(false); - - auto clientConnectionString = getConnectionString(); - comm::datalayer::IClient2 *client = datalayer.factory()->createClient2(clientConnectionString); - if (client->isConnected() == false) - { - std::cout << "ERROR Client connection " << clientConnectionString << " failed" << std::endl; - delete client; - client = nullptr; - datalayer.stop(); - - return 1; - } - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Register diagnostics" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - // std::cout << "Register diagnostics with file path on ctrlX CORE (Alternative 1)" << std::endl; - //// For this variant it is necessary to upload the json file to a path on control that is accessible. - //// It is possible to upload the file via WebDAV to the active configuration: - //// - Create the folder "diagnostics" in the root of the active configuration. - //// - Upload the json file (sdk_diagnosis_datalayer.diagnostics.en-US.json) to the folder "diagnostics". - //// - If you followed all steps of the description, it is sufficient to only declare the file name for the registration via Data Layer. See example below. - //// It is also possible to upload a complete configuration with the json file, e.g.: - //// - Save actual configuration and upload to PC. - //// - Unzip the configuration file. - //// - Add the json file to configuration (e.g. create folder "diagnostics" and copy the json file (sdk_diagnosis_datalayer.diagnostics.en-US.json) to it). - //// - Upload the configuration and load the configuration. - //// - The resulting accessible path of the json file should be "/var/snap/rexroth-solutions/common/solutions/DefaultSolution/configurations/appdata/diagnostics/sdk_diagnosis_datalayer.diagnostics.en-US.json". - //// Features supported later: - //// - Upload of a single file to the active configuration via configuration web interface. - // comm::datalayer::Variant registrationPathData; - // registrationPathData.setValue("sdk_diagnosis_datalayer.diagnostics.en-US.json"); - //// registrationPathData.setValue("/var/snap/rexroth-solutions/common/solutions/DefaultSolution/configurations/appdata/diagnostics/sdk_diagnosis_datalayer.diagnostics.en-US.json"); - // comm::datalayer::DlResult dlResult = dlClient->writeSync("diagnosis/registration/register-file", ®istrationPathData); - // if (comm::datalayer::STATUS_FAILED(dlResult)) - // { - // std::cerr << "Register diagnostics failed with error code" << dlResult.toString() << std::endl; - // return 1; - // } - - std::cout << "Register diagnostics with file path on PC or with file path in own app for interprocess communication (Alternative 2)" << std::endl; - char workingDirectory[512]; - char *buffer = getcwd(workingDirectory, 512); - if (nullptr == buffer) - { - if (client) - { - delete client; - client = nullptr; - } - - datalayer.stop(); - - return 1; - } - - std::string registrationFilePath = std::string(workingDirectory) + "/resources/diagnostics/sdk_diagnosis_datalayer.diagnostics.en-US.json"; - comm::datalayer::MetadataHelper metadataHelper; - comm::datalayer::Variant binaryFileContent; - - comm::datalayer::DlResult dlResult = metadataHelper.getFileContent(registrationFilePath, binaryFileContent); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Failed to get type information of file " << registrationFilePath << ", error code: " << dlResult.toString() << std::endl; - - if (client) - { - delete client; - client = nullptr; - } - - datalayer.stop(); - return 1; - } - - dlResult = client->writeSync("diagnosis/registration/register-file-content", &binaryFileContent); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Register diagnostics failed with error code " << dlResult.toString() << std::endl; - - if (client) - { - delete client; - client = nullptr; - } - - datalayer.stop(); - return 1; - } - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Subscribe to diagnosis events" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - flatbuffers::FlatBufferBuilder builder; - comm::datalayer::Variant subscriptionProperties; - std::string subscriptionName = "eventsNotifier"; - - std::cout << "Create subscription with name '" << subscriptionName << "'" << std::endl; - auto id = builder.CreateString(subscriptionName); - builder.Finish(comm::datalayer::CreateSubscriptionProperties(builder, id, 60000, 100)); - subscriptionProperties.shareFlatbuffers(builder); - dlResult = client->createSubscriptionSync(subscriptionProperties, eventsCallback()); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Failed to create subscription with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Subscribe to all diagnosis event nodes" << std::endl; - std::set addresses = {"diagnosis/events/message-set", "diagnosis/events/warning-set", "diagnosis/events/error-set-F0", "diagnosis/events/error-set-F2", "diagnosis/events/error-set-F6", "diagnosis/events/highest-pending-log-none", "diagnosis/events/highest-pending-log-warning", "diagnosis/events/highest-pending-log-error", "diagnosis/events/reset-all-pending"}; - dlResult = client->subscribeSync(subscriptionName, addresses); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Failed to subscribe with error code " << dlResult.toString() << std::endl; - } - - // Wait for the finish of the initialization events - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Set diagnostics" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - comm::datalayer::Variant dataSet; - - std::cout << "Set message (0E0A0001, 00000001, -)" << std::endl; - auto logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0A0001", "00000001", nullptr, nullptr, "datalayerdiagnosis", "common.bootup", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Set active warning(0E0E0001, 00000001, diagnosis/temperature)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0E0001", "00000001", nullptr, "diagnosis/temperature", "datalayerdiagnosis", "common.log.diagnosis", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, "Maximum temperature: 99°C"); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Set active error (0E0F2001, 00000001, motion/axs/z3)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F2001", "00000001", nullptr, "motion/axs/z3", "datalayerdiagnosis", "motion.core", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Set and reset error (0E0F0001, 00000001, devices/io)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F0001", "00000001", nullptr, "devices/io/5", "datalayerdiagnosis", "io.manager", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/set-and-reset", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "set-and-reset failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Reset error (0E0F2001, 00000001, motion/axs/z3)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F2001", "00000001", nullptr, "motion/axs/z3", "datalayerdiagnosis", "motion.core", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/reset-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "reset-active failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Reset warning (0E0E0001, 00000001, diagnosis/temperature)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0E0001", "00000001", nullptr, "diagnosis/temperature", "datalayerdiagnosis", "common.log.diagnosis", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/reset-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "reset-active failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Set active error (0E0F6001, 00000001, -)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F6001", "00000001", nullptr, nullptr, "datalayerdiagnosis", "motion.core", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Set active warning (0E0E0003, 00000001, scheduler/watchdog)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0E0003", "00000001", nullptr, "scheduler/watchdog", "datalayerdiagnosis", "common.scheduler", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; - } - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Get highest priority pending diagnostic" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - comm::datalayer::Variant logData; - - dlResult = client->readSync("diagnosis/get/actual/log", &logData); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Get actual log failed with error code '" << dlResult.toString() << "'. Could not highest priority log." << std::endl; - } - - if (comm::datalayer::STATUS_FAILED(logData.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyDiagnosisIdentificationWithTimestampBuffer))) - { - std::cerr << "Invalid data type for logData. Expected flatbuffer type DiagnosisIdentificationWithTimestamp." << std::endl; - } - else - { - auto fbsLog = common::log::diagnosis::fbs::GetDiagnosisIdentificationWithTimestamp(logData.getData()); - std::string mainDiagnosisString = std::string(fbsLog->diagnosisIdentification()->mainDiagnosisNumber()->c_str()); - std::string detailedDiagnosisString = std::string(fbsLog->diagnosisIdentification()->detailedDiagnosisNumber()->c_str()); - std::string entity = std::string(fbsLog->diagnosisIdentification()->entity()->c_str()); - std::string timestamp = std::string(fbsLog->timestamp()->c_str()); - - std::cout << "Content of actual highest priority log: {" << mainDiagnosisString << "," << detailedDiagnosisString << "," << entity << "}(" << timestamp << ")" << std::endl; - } - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Get pending diagnostics list" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - comm::datalayer::Variant listData; - - dlResult = client->readSync("diagnosis/get/actual/list", &listData); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Get actual list failed with error code '" << dlResult.toString() << "'. Could not read error and warning list." << std::endl; - } - - if (comm::datalayer::STATUS_FAILED(listData.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyListDiagnosisIdentificationWithTimestampBuffer))) - { - std::cerr << "Invalid data type for listData. Expected flatbuffer type ListDiagnosisIdentificationWithTimestamp." << std::endl; - } - else - { - auto fbsList = common::log::diagnosis::fbs::GetListDiagnosisIdentificationWithTimestamp(listData.getData()); - auto fbsListSize = fbsList->listDiagnosisIdentificationWithTimestamp()->size(); - - std::cout << "Content of actual list:" << std::endl; - for (std::uint32_t listElement = 0; listElement < fbsListSize; ++listElement) - { - std::string mainDiagnosisString = std::string(fbsList->listDiagnosisIdentificationWithTimestamp()->Get(listElement)->diagnosisIdentification()->mainDiagnosisNumber()->c_str()); - std::string detailedDiagnosisString = std::string(fbsList->listDiagnosisIdentificationWithTimestamp()->Get(listElement)->diagnosisIdentification()->detailedDiagnosisNumber()->c_str()); - std::string entity = std::string(fbsList->listDiagnosisIdentificationWithTimestamp()->Get(listElement)->diagnosisIdentification()->entity()->c_str()); - std::string timestamp = std::string(fbsList->listDiagnosisIdentificationWithTimestamp()->Get(listElement)->timestamp()->c_str()); - - std::cout << "{" << mainDiagnosisString << "," << detailedDiagnosisString << "," << entity << "}(" << timestamp << ")" << std::endl; - } - } - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Verify logs in pending diagnostics list" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - struct DiagIdentification - { - std::string mainDiag; - std::string detailedDiag; - std::string entity; - }; - - std::vector listDiagnosisIdentification = - { - {"0E0E0003", "00000001", "scheduler/watchdog"}, - {"0E0F2001", "00000001", "motion/axs/z3"}, - {"0E0F6001", "00000001", "notExisting"}, - }; - - for (const auto &listElement : listDiagnosisIdentification) - { - std::cout << "Verify state of log {" << listElement.mainDiag << "," << listElement.detailedDiag << "," << listElement.entity << "}: "; - - comm::datalayer::Variant dataVerifyLog; - auto diagnosisIdentification = common::log::diagnosis::fbs::CreateDiagnosisIdentificationDirect(builder, listElement.mainDiag.c_str(), listElement.detailedDiag.c_str(), listElement.entity.c_str()); - - builder.Finish(diagnosisIdentification); - dataVerifyLog.shareFlatbuffers(builder); - - dlResult = client->readSync("diagnosis/get/actual/list/verify-log", &dataVerifyLog); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Verify specific log failed with error code " << dlResult.toString() << std::endl; - } - else - { - if (comm::datalayer::STATUS_FAILED(dataVerifyLog.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyPendingDiagnosticStateBuffer))) - { - std::cerr << "Invalid data type for dataVerifyLog. Expected flatbuffer type PendingDiagnosticState." << std::endl; - } - else - { - std::cout << common::log::diagnosis::fbs::EnumNameState(common::log::diagnosis::fbs::GetPendingDiagnosticState(dataVerifyLog.getData())->pendingDiagnosticState()) << std::endl; - } - } - } - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Confirm errors" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - std::cout << "Confirm all errors" << std::endl; - dlResult = client->writeSync("diagnosis/confirm/all-errors", nullptr); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Confirm all errors failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Confirm specific error (but before: reset error (0E0F6001, 00000001, -), so that it is able to confirm)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F6001", "00000001", nullptr, nullptr, "datalayerdiagnosis", "motion.core", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/reset-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "reset-active failed with error code " << dlResult.toString() << std::endl; - } - - auto diagnosisIdentification = common::log::diagnosis::fbs::CreateDiagnosisIdentificationDirect(builder, "0E0F6001", "00000001", ""); - - builder.Finish(diagnosisIdentification); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/confirm/error", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Confirm specific error failed with error code " << dlResult.toString() << std::endl; - } - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Get diagnostic texts" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - std::string mainDiagnosisNumber = "0E0F0001"; - std::string detailedDiagnosisNumber = "00000001"; - comm::datalayer::Variant dataGetText; - - std::cout << "Get main diagnostic text of number " << mainDiagnosisNumber << std::endl; - auto getMainTextElement = common::log::diagnosis::fbs::CreateGetMainDiagnosisTextDirect(builder, mainDiagnosisNumber.c_str()); - builder.Finish(getMainTextElement); - dataGetText.shareFlatbuffers(builder); - - dlResult = client->readSync("diagnosis/get/text/main", &dataGetText); - - if (comm::datalayer::VariantType::STRING != dataGetText.getType()) - { - std::cerr << "Expected '" << comm::datalayer::DATALAYER_TYPE_STRING << "' as result type, but got '" << dataGetText.typeAsCharString() << "'" << std::endl; - } - else - { - std::string diagnosisText = static_cast(dataGetText); - std::cout << "Diagnosis text of main diagnosis number " << mainDiagnosisNumber << ":" << diagnosisText << std::endl; - } - - std::cout << "Get detailed diagnostic text of number " << detailedDiagnosisNumber << " with related main diagnostic number " << mainDiagnosisNumber << std::endl; - auto getDetailedTextElement = common::log::diagnosis::fbs::CreateGetDetailedDiagnosisTextDirect(builder, detailedDiagnosisNumber.c_str(), mainDiagnosisNumber.c_str()); - builder.Finish(getDetailedTextElement); - dataGetText.shareFlatbuffers(builder); - - dlResult = client->readSync("diagnosis/get/text/detailed", &dataGetText); - - if (comm::datalayer::VariantType::STRING != dataGetText.getType()) - { - std::cerr << "Expected '" << comm::datalayer::DATALAYER_TYPE_STRING << "' as result type, but got '" << dataGetText.typeAsCharString() << "'" << std::endl; - } - else - { - std::string diagnosisText = static_cast(dataGetText); - std::cout << "Diagnosis text of detailed diagnosis number " << detailedDiagnosisNumber << " with related main diagnosis number " << mainDiagnosisNumber << ":" << diagnosisText << std::endl; - } - - ////////////////////////////////////////////////////////////////////////////////// - std::cout << "Reset remaining warning, and unregister diagnostics" << std::endl; - ////////////////////////////////////////////////////////////////////////////////// - - std::cout << "Reset warning (0E0E0003, 00000001, scheduler/watchdog)" << std::endl; - logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0E0003", "00000001", nullptr, "scheduler/watchdog", "datalayerdiagnosis", "common.scheduler", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); - - builder.Finish(logParameters); - dataSet.shareFlatbuffers(builder); - - dlResult = client->writeSync("diagnosis/set/reset-active", &dataSet); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "reset-active failed with error code " << dlResult.toString() << std::endl; - } - - std::cout << "Unregister diagnostics with file path on PC or with file path in own app for interprocess communication (Alternative 2)" << std::endl; - dlResult = metadataHelper.getFileContent(registrationFilePath, binaryFileContent); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Failed to get type information of file " << registrationFilePath << ", error code: " << dlResult.toString() << std::endl; - } - else - { - dlResult = client->writeSync("diagnosis/registration/unregister-file-content", &binaryFileContent); - if (comm::datalayer::STATUS_FAILED(dlResult)) - { - std::cerr << "Unregister diagnostics failed with error code " << dlResult.toString() << std::endl; - } - } - - delete client; - client = nullptr; - - datalayer.stop(); - - return 0; -} +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include "comm/datalayer/datalayer.h" +#include "comm/datalayer/datalayer_system.h" +#include "comm/datalayer/metadata_helper.h" +#include "comm/datalayer/sub_properties_generated.h" +#include "comm/datalayer/notify_info_generated.h" + +#include "common/log/diagnosis/registration_file_generated.h" +#include "common/log/diagnosis/set_generated.h" +#include "common/log/diagnosis/diagnosis_identification_generated.h" +#include "common/log/diagnosis/list_diagnosis_identification_with_timestamp_generated.h" +#include "common/log/diagnosis/get_main_text_generated.h" +#include "common/log/diagnosis/get_detailed_text_generated.h" +#include "common/log/diagnosis/event_type_1_generated.h" +#include "common/log/diagnosis/event_type_2_generated.h" +#include "common/log/diagnosis/pending_diagnostic_state_generated.h" +#include "common/log/diagnosis/i_log2.h" + +#include "ctrlx_datalayer_helper.h" + +static comm::datalayer::PublishCallback eventsCallback() +{ + return [&](comm::datalayer::DlResult status, const std::vector& items) + { + std::cout << " Got notification" << std::endl; + + if (comm::datalayer::STATUS_FAILED(status)) + { + std::cerr << " Status: " << status.toString() << std::endl; + return; + } + + for (auto item = items.begin(); item != items.end(); item++) + { + auto info = comm::datalayer::GetNotifyInfo(item->info.getData()); + + std::cout << " Got notification '" << comm::datalayer::EnumNameNotifyType(info->notifyType()) << "' for node '" << info->node()->c_str() << "'." << std::endl; + if (comm::datalayer::NotifyType_Data != info->notifyType()) + { + continue; + } + comm::datalayer::Variant value = item->data; + std::string nodeAdress = info->node()->c_str(); + if (0 == nodeAdress.compare("diagnosis/events/message-set")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); + std::cout << " Event counter (diagnosis/events/message-set): " << eventData->eventCounter() << std::endl; + continue; + } + + if (0 == nodeAdress.compare("diagnosis/events/warning-set")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); + std::cout << " Event counter (diagnosis/events/warning-set): " << eventData->eventCounter() << std::endl; + continue; + } + + if (0 == nodeAdress.compare("diagnosis/events/error-set-F0")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); + std::cout << " Event counter (diagnosis/events/error-set-F0): " << eventData->eventCounter() << std::endl; + continue; + } + + if (0 == nodeAdress.compare("diagnosis/events/error-set-F2")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); + std::cout << " Event counter (diagnosis/events/error-set-F2): " << eventData->eventCounter() << std::endl; + continue; + } + + if (0 == nodeAdress.compare("diagnosis/events/error-set-F6")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); + std::cout << " Event counter (diagnosis/events/error-set-F6): " << eventData->eventCounter() << std::endl; + continue; + } + if (0 == nodeAdress.compare("diagnosis/events/highest-pending-log-none")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); + std::cout << " Event counter (diagnosis/events/highest-pending-log-none): " << eventData->eventCounter() << std::endl; + continue; + } + if (0 == nodeAdress.compare("diagnosis/events/highest-pending-log-warning")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); + std::cout << " Event counter (diagnosis/events/highest-pending-log-warning): " << eventData->eventCounter() << std::endl; + continue; + } + + if (0 == nodeAdress.compare("diagnosis/events/highest-pending-log-error")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType1Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType1(value.getData()); + std::cout << " Event counter (diagnosis/events/highest-pending-log-error): " << eventData->eventCounter() << std::endl; + continue; + } + + if (0 == nodeAdress.compare("diagnosis/events/reset-all-pending")) + { + if (comm::datalayer::STATUS_FAILED(value.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyEventType2Buffer))) + { + std::cerr << " Invalid argument type for data" << std::endl; + return; + } + + auto eventData = common::log::diagnosis::fbs::GetEventType2(value.getData()); + std::cout << " Event counter (diagnosis/events/reset-all-pending): " << eventData->eventCounter() << std::endl; + } + } + }; +} + +int main(void) +{ + + comm::datalayer::DatalayerSystem datalayer; + datalayer.start(false); + + auto clientConnectionString = getConnectionString(); // default: ctrlX CORE or ctrlX COREvirtual with Network Adpater + //auto clientConnectionString = getConnectionString("10.0.2.2","boschrexroth","boschrexroth",8443); ctrlX COREvirtual with Port Forwarding + comm::datalayer::IClient2* client = datalayer.factory()->createClient2(clientConnectionString); + if (client == nullptr || client->isConnected() == false) + { + std::cout << "ERROR Client connection " << clientConnectionString << " failed" << std::endl; + delete client; + datalayer.stop(); + return 1; + } + +/* + std::cout << "Register diagnostics with file path on ctrlX CORE (Alternative 1)" << std::endl; + + // For this variant it is necessary to upload the json file to a path on control that is accessible. + // It is possible to upload the file via WebDAV to the active configuration: + // - Create the folder "diagnostics" in the root of the active configuration. + // - Upload the json file (sdk_diagnosis_datalayer.diagnostics.en-US.json) to the folder "diagnostics". + // - If you followed all steps of the description, it is sufficient to only declare the file name for the registration via ctrlX Data Layer. See example below. + // It is also possible to upload a complete configuration with the json file, e.g.: + // - Save actual configuration and upload to PC. + // - Unzip the configuration file. + // - Add the json file to configuration (e.g. create folder "diagnostics" and copy the json file (sdk_diagnosis_datalayer.diagnostics.en-US.json) to it). + // - Upload the configuration and load the configuration. + // - The resulting accessible path of the json file should be "/var/snap/rexroth-solutions/common/solutions/DefaultSolution/configurations/appdata/diagnostics/sdk_diagnosis_datalayer.diagnostics.en-US.json". + // Features supported later: + // - Upload of a single file to the active configuration via configuration web interface. + + comm::datalayer::Variant registrationPathData; + registrationPathData.setValue("sdk_diagnosis_datalayer.diagnostics.en-US.json"); + // registrationPathData.setValue("/var/snap/rexroth-solutions/common/solutions/DefaultSolution/configurations/appdata/diagnostics/sdk_diagnosis_datalayer.diagnostics.en-US.json"); + comm::datalayer::DlResult dlResult = dlClient->writeSync("diagnosis/registration/register-file", ®istrationPathData); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Register diagnostics failed with error code" << dlResult.toString() << std::endl; + return 1; + } +*/ + + std::cout << "Register diagnostics with file path on PC or with file path in own app for interprocess communication (Alternative 2)" << std::endl; + + auto basePath = snapPath(); + if (nullptr == basePath) + { + // Not in snap environment + char workingDirectory[512]; + basePath = getcwd(workingDirectory, 512); + if (nullptr == basePath) + { + std::cerr << "ERROR Failed to get base directory" << std::endl; + delete client; + datalayer.stop(); + return 1; + } + } + + std::string registrationFilePath = std::string(basePath) + "/resources/diagnostics/sdk_diagnosis_datalayer.diagnostics.en-US.json"; + std::cerr << "Using type information from file " << registrationFilePath << std::endl; + + comm::datalayer::MetadataHelper metadataHelper; + comm::datalayer::Variant binaryFileContent; + comm::datalayer::DlResult dlResult = metadataHelper.getFileContent(registrationFilePath, binaryFileContent); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Failed to get type information of file " << registrationFilePath << ", error code: " << dlResult.toString() << std::endl; + delete client; + datalayer.stop(); + return 1; + } + + dlResult = client->writeSync("diagnosis/registration/register-file-content", &binaryFileContent); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Register diagnostics failed with error code " << dlResult.toString() << std::endl; + + delete client; + datalayer.stop(); + return 1; + } + + ////////////////////////////////////////////////////////////////////////////////// + std::cout << "Subscribe to diagnosis events" << std::endl; + ////////////////////////////////////////////////////////////////////////////////// + + flatbuffers::FlatBufferBuilder builder; + comm::datalayer::Variant subscriptionProperties; + std::string subscriptionName = "eventsNotifier"; + + std::cout << "Create subscription with name '" << subscriptionName << "'" << std::endl; + auto id = builder.CreateString(subscriptionName); + builder.Finish(comm::datalayer::CreateSubscriptionProperties(builder, id, 60000, 100)); + subscriptionProperties.shareFlatbuffers(builder); + dlResult = client->createSubscriptionSync(subscriptionProperties, eventsCallback()); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Failed to create subscription with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Subscribe to all diagnosis event nodes" << std::endl; + std::set addresses = {"diagnosis/events/message-set", "diagnosis/events/warning-set", "diagnosis/events/error-set-F0", "diagnosis/events/error-set-F2", "diagnosis/events/error-set-F6", "diagnosis/events/highest-pending-log-none", "diagnosis/events/highest-pending-log-warning", "diagnosis/events/highest-pending-log-error", "diagnosis/events/reset-all-pending"}; + dlResult = client->subscribeSync(subscriptionName, addresses); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Failed to subscribe with error code " << dlResult.toString() << std::endl; + } + + // Wait for the finish of the initialization events + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + ////////////////////////////////////////////////////////////////////////////////// + std::cout << "Set diagnostics" << std::endl; + ////////////////////////////////////////////////////////////////////////////////// + + comm::datalayer::Variant dataSet; + + std::cout << "Set message (0E0A0001, 00000001, -)" << std::endl; + auto logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0A0001", "00000001", nullptr, nullptr, "datalayerdiagnosis", "common.bootup", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Set active warning(0E0E0001, 00000001, diagnosis/temperature)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0E0001", "00000001", nullptr, "diagnosis/temperature", "datalayerdiagnosis", "common.log.diagnosis", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, "Maximum temperature: 99°C"); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Set active error (0E0F2001, 00000001, motion/axs/z3)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F2001", "00000001", nullptr, "motion/axs/z3", "datalayerdiagnosis", "motion.core", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Set and reset error (0E0F0001, 00000001, devices/io)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F0001", "00000001", nullptr, "devices/io/5", "datalayerdiagnosis", "io.manager", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/set-and-reset", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "set-and-reset failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Reset error (0E0F2001, 00000001, motion/axs/z3)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F2001", "00000001", nullptr, "motion/axs/z3", "datalayerdiagnosis", "motion.core", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/reset-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "reset-active failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Reset warning (0E0E0001, 00000001, diagnosis/temperature)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0E0001", "00000001", nullptr, "diagnosis/temperature", "datalayerdiagnosis", "common.log.diagnosis", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/reset-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "reset-active failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Set active error (0E0F6001, 00000001, -)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F6001", "00000001", nullptr, nullptr, "datalayerdiagnosis", "motion.core", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Set active warning (0E0E0003, 00000001, scheduler/watchdog)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0E0003", "00000001", nullptr, "scheduler/watchdog", "datalayerdiagnosis", "common.scheduler", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/set-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "set-active failed with error code " << dlResult.toString() << std::endl; + } + + ////////////////////////////////////////////////////////////////////////////////// + std::cout << "Get highest priority pending diagnostic" << std::endl; + ////////////////////////////////////////////////////////////////////////////////// + + comm::datalayer::Variant logData; + + dlResult = client->readSync("diagnosis/get/actual/log", &logData); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Get actual log failed with error code '" << dlResult.toString() << "'. Could not highest priority log." << std::endl; + } + + if (comm::datalayer::STATUS_FAILED(logData.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyDiagnosisIdentificationWithTimestampBuffer))) + { + std::cerr << "Invalid data type for logData. Expected flatbuffer type DiagnosisIdentificationWithTimestamp." << std::endl; + } + else + { + auto fbsLog = common::log::diagnosis::fbs::GetDiagnosisIdentificationWithTimestamp(logData.getData()); + std::string mainDiagnosisString = std::string(fbsLog->diagnosisIdentification()->mainDiagnosisNumber()->c_str()); + std::string detailedDiagnosisString = std::string(fbsLog->diagnosisIdentification()->detailedDiagnosisNumber()->c_str()); + std::string entity = std::string(fbsLog->diagnosisIdentification()->entity()->c_str()); + std::string timestamp = std::string(fbsLog->timestamp()->c_str()); + + std::cout << "Content of actual highest priority log: {" << mainDiagnosisString << "," << detailedDiagnosisString << "," << entity << "}(" << timestamp << ")" << std::endl; + } + + ////////////////////////////////////////////////////////////////////////////////// + std::cout << "Get pending diagnostics list" << std::endl; + ////////////////////////////////////////////////////////////////////////////////// + + comm::datalayer::Variant listData; + + dlResult = client->readSync("diagnosis/get/actual/list", &listData); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Get actual list failed with error code '" << dlResult.toString() << "'. Could not read error and warning list." << std::endl; + } + + if (comm::datalayer::STATUS_FAILED(listData.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyListDiagnosisIdentificationWithTimestampBuffer))) + { + std::cerr << "Invalid data type for listData. Expected flatbuffer type ListDiagnosisIdentificationWithTimestamp." << std::endl; + } + else + { + auto fbsList = common::log::diagnosis::fbs::GetListDiagnosisIdentificationWithTimestamp(listData.getData()); + auto fbsListSize = fbsList->listDiagnosisIdentificationWithTimestamp()->size(); + + std::cout << "Content of actual list:" << std::endl; + for (std::uint32_t listElement = 0; listElement < fbsListSize; ++listElement) + { + std::string mainDiagnosisString = std::string(fbsList->listDiagnosisIdentificationWithTimestamp()->Get(listElement)->diagnosisIdentification()->mainDiagnosisNumber()->c_str()); + std::string detailedDiagnosisString = std::string(fbsList->listDiagnosisIdentificationWithTimestamp()->Get(listElement)->diagnosisIdentification()->detailedDiagnosisNumber()->c_str()); + std::string entity = std::string(fbsList->listDiagnosisIdentificationWithTimestamp()->Get(listElement)->diagnosisIdentification()->entity()->c_str()); + std::string timestamp = std::string(fbsList->listDiagnosisIdentificationWithTimestamp()->Get(listElement)->timestamp()->c_str()); + + std::cout << "{" << mainDiagnosisString << "," << detailedDiagnosisString << "," << entity << "}(" << timestamp << ")" << std::endl; + } + } + + ////////////////////////////////////////////////////////////////////////////////// + std::cout << "Verify logs in pending diagnostics list" << std::endl; + ////////////////////////////////////////////////////////////////////////////////// + + struct DiagIdentification + { + std::string mainDiag; + std::string detailedDiag; + std::string entity; + }; + + std::vector listDiagnosisIdentification = + { + {"0E0E0003", "00000001", "scheduler/watchdog"}, + {"0E0F2001", "00000001", "motion/axs/z3"}, + {"0E0F6001", "00000001", "notExisting"}, + }; + + for (const auto& listElement : listDiagnosisIdentification) + { + std::cout << "Verify state of log {" << listElement.mainDiag << "," << listElement.detailedDiag << "," << listElement.entity << "}: "; + + comm::datalayer::Variant dataVerifyLog; + auto diagnosisIdentification = common::log::diagnosis::fbs::CreateDiagnosisIdentificationDirect(builder, listElement.mainDiag.c_str(), listElement.detailedDiag.c_str(), listElement.entity.c_str()); + + builder.Finish(diagnosisIdentification); + dataVerifyLog.shareFlatbuffers(builder); + + dlResult = client->readSync("diagnosis/get/actual/list/verify-log", &dataVerifyLog); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Verify specific log failed with error code " << dlResult.toString() << std::endl; + } + else + { + if (comm::datalayer::STATUS_FAILED(dataVerifyLog.verifyFlatbuffers(common::log::diagnosis::fbs::VerifyPendingDiagnosticStateBuffer))) + { + std::cerr << "Invalid data type for dataVerifyLog. Expected flatbuffer type PendingDiagnosticState." << std::endl; + } + else + { + std::cout << common::log::diagnosis::fbs::EnumNameState(common::log::diagnosis::fbs::GetPendingDiagnosticState(dataVerifyLog.getData())->pendingDiagnosticState()) << std::endl; + } + } + } + + ////////////////////////////////////////////////////////////////////////////////// + std::cout << "Confirm errors" << std::endl; + ////////////////////////////////////////////////////////////////////////////////// + + std::cout << "Confirm all errors" << std::endl; + dlResult = client->writeSync("diagnosis/confirm/all-errors", nullptr); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Confirm all errors failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Confirm specific error (but before: reset error (0E0F6001, 00000001, -), so that it is able to confirm)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0F6001", "00000001", nullptr, nullptr, "datalayerdiagnosis", "motion.core", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/reset-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "reset-active failed with error code " << dlResult.toString() << std::endl; + } + + auto diagnosisIdentification = common::log::diagnosis::fbs::CreateDiagnosisIdentificationDirect(builder, "0E0F6001", "00000001", ""); + + builder.Finish(diagnosisIdentification); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/confirm/error", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Confirm specific error failed with error code " << dlResult.toString() << std::endl; + } + + ////////////////////////////////////////////////////////////////////////////////// + std::cout << "Get diagnostic texts" << std::endl; + ////////////////////////////////////////////////////////////////////////////////// + + std::string mainDiagnosisNumber = "0E0F0001"; + std::string detailedDiagnosisNumber = "00000001"; + comm::datalayer::Variant dataGetText; + + std::cout << "Get main diagnostic text of number " << mainDiagnosisNumber << std::endl; + auto getMainTextElement = common::log::diagnosis::fbs::CreateGetMainDiagnosisTextDirect(builder, mainDiagnosisNumber.c_str()); + builder.Finish(getMainTextElement); + dataGetText.shareFlatbuffers(builder); + + dlResult = client->readSync("diagnosis/get/text/main", &dataGetText); + + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "read failed with error code " << dlResult.toString() << std::endl; + } + + if (comm::datalayer::VariantType::STRING != dataGetText.getType()) + { + std::cerr << "Expected '" << comm::datalayer::DATALAYER_TYPE_STRING << "' as result type, but got '" << dataGetText.typeAsCharString() << "'" << std::endl; + } + else + { + std::string diagnosisText = static_cast(dataGetText); + std::cout << "Diagnosis text of main diagnosis number " << mainDiagnosisNumber << ":" << diagnosisText << std::endl; + } + + std::cout << "Get detailed diagnostic text of number " << detailedDiagnosisNumber << " with related main diagnostic number " << mainDiagnosisNumber << std::endl; + auto getDetailedTextElement = common::log::diagnosis::fbs::CreateGetDetailedDiagnosisTextDirect(builder, detailedDiagnosisNumber.c_str(), mainDiagnosisNumber.c_str()); + builder.Finish(getDetailedTextElement); + dataGetText.shareFlatbuffers(builder); + + dlResult = client->readSync("diagnosis/get/text/detailed", &dataGetText); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "read failed with error code " << dlResult.toString() << std::endl; + } + + if (comm::datalayer::VariantType::STRING != dataGetText.getType()) + { + std::cerr << "Expected '" << comm::datalayer::DATALAYER_TYPE_STRING << "' as result type, but got '" << dataGetText.typeAsCharString() << "'" << std::endl; + } + else + { + std::string diagnosisText = static_cast(dataGetText); + std::cout << "Diagnosis text of detailed diagnosis number " << detailedDiagnosisNumber << " with related main diagnosis number " << mainDiagnosisNumber << ":" << diagnosisText << std::endl; + } + + ////////////////////////////////////////////////////////////////////////////////// + std::cout << "Reset remaining warning, and unregister diagnostics" << std::endl; + ////////////////////////////////////////////////////////////////////////////////// + + std::cout << "Reset warning (0E0E0003, 00000001, scheduler/watchdog)" << std::endl; + logParameters = common::log::diagnosis::fbs::CreateLogParametersDirect(builder, "0E0E0003", "00000001", nullptr, "scheduler/watchdog", "datalayerdiagnosis", "common.scheduler", common::log::diagnosis::getFileName(__FILE__), __FUNCTION__, __LINE__, ""); + + builder.Finish(logParameters); + dataSet.shareFlatbuffers(builder); + + dlResult = client->writeSync("diagnosis/set/reset-active", &dataSet); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "reset-active failed with error code " << dlResult.toString() << std::endl; + } + + std::cout << "Unregister diagnostics with file path on PC or with file path in own app for interprocess communication (Alternative 2)" << std::endl; + dlResult = metadataHelper.getFileContent(registrationFilePath, binaryFileContent); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Failed to get type information of file " << registrationFilePath << ", error code: " << dlResult.toString() << std::endl; + } + else + { + dlResult = client->writeSync("diagnosis/registration/unregister-file-content", &binaryFileContent); + if (comm::datalayer::STATUS_FAILED(dlResult)) + { + std::cerr << "Unregister diagnostics failed with error code " << dlResult.toString() << std::endl; + } + } + + delete client; + datalayer.stop(); + + return 0; +} diff --git a/samples-cpp/datalayer.diagnosis/snap/snapcraft.yaml b/samples-cpp/datalayer.diagnosis/snap/snapcraft.yaml index 5ae7cd637..95cdaeeba 100644 --- a/samples-cpp/datalayer.diagnosis/snap/snapcraft.yaml +++ b/samples-cpp/datalayer.diagnosis/snap/snapcraft.yaml @@ -4,12 +4,12 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: sdk-cpp-datalayerdiagnosis -version: "1.2.0" +version: "2.2.0" grade: stable -summary: Sample app for processing diagnosis data via Data Layer +summary: Sample app for processing diagnosis data via ctrlX Data Layer description: | - This app will call diagnosis functions via Data Layer -base: core20 + This app will call diagnosis functions via ctrlX Data Layer +base: core22 confinement: strict # define how apps & services are exposed to host system @@ -35,6 +35,11 @@ parts: stage-packages: - libzmq5 - ctrlx-datalayer + resourcesdiagnosis: + plugin: dump + source: ./resources/diagnostics + organize: + '*': ./resources/diagnostics/ # describes which interface slots are supported by defining the plugs plugs: diff --git a/samples-cpp/datalayer.ecat.io/.vscode/launch.json b/samples-cpp/datalayer.ecat.io/.vscode/launch.json index eb6746827..230b390c9 100644 --- a/samples-cpp/datalayer.ecat.io/.vscode/launch.json +++ b/samples-cpp/datalayer.ecat.io/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/datalayerEcatio", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerEcatio", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,8 +23,8 @@ }, { "description": "Set path variable to .", - //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu20-gcc-x64/debug/usr/lib/", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu22-gcc-x64/debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] diff --git a/samples-cpp/datalayer.ecat.io/.vscode/tasks.json b/samples-cpp/datalayer.ecat.io/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-cpp/datalayer.ecat.io/.vscode/tasks.json +++ b/samples-cpp/datalayer.ecat.io/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/datalayer.ecat.io/CMakeLists.txt b/samples-cpp/datalayer.ecat.io/CMakeLists.txt index 00aaa8b3c..7ee855c58 100644 --- a/samples-cpp/datalayer.ecat.io/CMakeLists.txt +++ b/samples-cpp/datalayer.ecat.io/CMakeLists.txt @@ -42,12 +42,12 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET(PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET(PLATFORM_NAME "ubuntu22-gcc-aarch64") SET(SNAP_ARCH "arm64") SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET(PLATFORM_NAME "ubuntu20-gcc-x64") + SET(PLATFORM_NAME "ubuntu22-gcc-x64") SET(SNAP_ARCH "amd64") SET(CMAKE_C_COMPILER gcc) SET(CMAKE_CXX_COMPILER g++) diff --git a/samples-cpp/datalayer.ecat.io/LICENSE b/samples-cpp/datalayer.ecat.io/LICENSE deleted file mode 100644 index 8eae5c210..000000000 --- a/samples-cpp/datalayer.ecat.io/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/datalayer.ecat.io/README.md b/samples-cpp/datalayer.ecat.io/README.md index d23a5d8bf..5f16266f2 100644 --- a/samples-cpp/datalayer.ecat.io/README.md +++ b/samples-cpp/datalayer.ecat.io/README.md @@ -1,52 +1,33 @@ -# README datalayer.client - -The sample app __datalayer.ecat.io__ toggles some Fieldbus I/O's. - -## Introduction - -It demonstrate how it is possible to read inputs and write outputs. It starts to toggle the outputs while the first channel of the input is set to true. - -## Prerequisites - -* ctrlX EtherCAT Master App -* ctrlX I/O Engineering -* S20-EC-BK -* S20-DI-16 -* S20-DO-16 - -## Build and Install the Snap - -Build and install the snap like described [here](../README.md). - -## Test the Snap - -* Open the web interface of your ctrlX CORE -* Check output in the web interface - -![Output in diagnosis logbook](docs/images/datalayer.ecat.io/logbook.png) - -___ - -## License - -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README datalayer.client + +The sample app __datalayer.ecat.io__ toggles some Fieldbus I/O's. + +## Introduction + +It demonstrate how it is possible to read inputs and write outputs. It starts to toggle the outputs while the first channel of the input is set to true. + +## Prerequisites + +* ctrlX EtherCAT Master App +* ctrlX I/O Engineering +* S20-EC-BK +* S20-DI-16 +* S20-DO-16 + +## Build and Install the Snap + +Build and install the snap like described [here](../README.md). + +## Test the Snap + +* Open the web interface of your ctrlX CORE +* Check output in the web interface + +![Output in diagnosis logbook](docs/images/datalayer.ecat.io/logbook.png) + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/datalayer.ecat.io/build-snap-amd64.sh b/samples-cpp/datalayer.ecat.io/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/datalayer.ecat.io/build-snap-amd64.sh +++ b/samples-cpp/datalayer.ecat.io/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.ecat.io/build-snap-arm64.sh b/samples-cpp/datalayer.ecat.io/build-snap-arm64.sh index f48f8a433..8be304510 100644 --- a/samples-cpp/datalayer.ecat.io/build-snap-arm64.sh +++ b/samples-cpp/datalayer.ecat.io/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.ecat.io/ctrlx_datalayer_helper.h b/samples-cpp/datalayer.ecat.io/ctrlx_datalayer_helper.h index 3fdec3b7d..d0683514f 100644 --- a/samples-cpp/datalayer.ecat.io/ctrlx_datalayer_helper.h +++ b/samples-cpp/datalayer.ecat.io/ctrlx_datalayer_helper.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef CTRLX_DATALAYER_HELPER_H @@ -43,17 +25,17 @@ * If these values do not suit your use case, explicitly pass the parameters that require different values. * Here some examples: * - * 1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: + * 1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: * * client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") * - * 2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): + * 2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): * * client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) * * Remarks: * 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual * * * IMPORTANT: @@ -84,10 +66,10 @@ static bool isSnap() } //! Get Datalayer connection string -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result Connection string static std::string getConnectionString( const std::string& ip = "192.168.1.1", @@ -112,10 +94,10 @@ static std::string getConnectionString( //! Get Datalayer Client instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IClient instance or nullptr on error static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", @@ -136,10 +118,10 @@ static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& dat //! Get Datalayer Provider instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IProvider instance or nullptr on error static comm::datalayer::IProvider* getProvider(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", diff --git a/samples-cpp/datalayer.ecat.io/main.cpp b/samples-cpp/datalayer.ecat.io/main.cpp index c08e85d33..7bf475390 100644 --- a/samples-cpp/datalayer.ecat.io/main.cpp +++ b/samples-cpp/datalayer.ecat.io/main.cpp @@ -1,279 +1,266 @@ -/** - * MIT License - * - * Copyright (c) 2020-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "comm/datalayer/datalayer.h" -#include "comm/datalayer/datalayer_system.h" -#include "comm/datalayer/memory_map_generated.h" -#include -#include -#include -#include -#include -#include "signal.h" - -#include "ctrlx_datalayer_helper.h" - -bool endProcess = false; -static void hdl(int sig, siginfo_t *siginfo, void *context) -{ - endProcess = true; -} - -int main(int ac, char *av[]) -{ -#ifdef MY_DEBUG - std::cout << "Raising SIGSTOP" << std::endl; - raise(SIGSTOP); - std::cout << "... Continue..." << std::endl; -#endif - - comm::datalayer::DlResult result; - comm::datalayer::Variant data; - comm::datalayer::Variant dataIn; - comm::datalayer::DatalayerSystem datalayer; - datalayer.start(false); - - comm::datalayer::IClient *client = getClient(datalayer); - if (client == nullptr) - { - std::cout << "ERROR Client connected" << std::endl; - datalayer.stop(); - return 1; - } - - result = client->readSync("fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/output/map", &data); - std::cout << "Read returned: " << result.toString() << std::endl; - - result = client->readSync("fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/input/map", &dataIn); - std::cout << "Read returned: " << result.toString() << std::endl; - - // Create abort struct - struct sigaction act; - memset(&act, '\0', sizeof(act)); - act.sa_sigaction = &hdl; - act.sa_flags = SA_SIGINFO; - sigaction(SIGINT, &act, NULL); - - // First we have to open the realtimememory, reading the whole outputs. - uint8_t *outData; - std::cout << "Opening some realtime memory" << std::endl; - std::shared_ptr output; - result = datalayer.factory()->openMemory(output, "fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/output"); - if (comm::datalayer::STATUS_FAILED(result)) - std::cout << "Open the memory failed with: " << result.toString() << std::endl; - - // We can read the Inputs to get a Start trigger for example - uint8_t *inData; - std::cout << "Opening some realtime memory" << std::endl; - std::shared_ptr input; - result = datalayer.factory()->openMemory(input, "fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/input"); - if (comm::datalayer::STATUS_FAILED(result)) - std::cout << "Open the memory failed with: " << result.toString() << std::endl; - - // After successful reading the outputs we must take the memorylayout. - // A Memory owner defines the layout of the realtime memory - // You see it in the datalayer.realtime example (memoryowner.cpp) - do - { - std::cout << "Try to get MemoryMap" << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - result = output->getMemoryMap(data); - std::cout << "Getting MemoryMap with: " << result.toString() << std::endl; - } while (comm::datalayer::STATUS_FAILED(result)); - - do - { - std::cout << "Try to get MemoryMap (Inputs)" << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - result = input->getMemoryMap(dataIn); - std::cout << "Getting MemoryMap with: " << result.toString() << std::endl; - } while (comm::datalayer::STATUS_FAILED(result)); - - // Now we got the layout, but we have to convert it cause it is a flatbuffer - // To imagen the result after converting the data you can take a look at the datalayertree - // "devices/ethercatmaster/0/outputs -> map" - result = data.verifyFlatbuffers(comm::datalayer::VerifyMemoryMapBuffer); - if (comm::datalayer::STATUS_FAILED(result)) - { - std::cout << "Verify Flatbuffers failed with: " << result.toString() << std::endl; - return -1; - } - - // Verify the Input layout, similar to the output - result = dataIn.verifyFlatbuffers(comm::datalayer::VerifyMemoryMapBuffer); - if (comm::datalayer::STATUS_FAILED(result)) - { - std::cout << "Verify Flatbuffers (Inputs) failed with: " << result.toString() << std::endl; - return -1; - } - - // At this point we can take the data. It is important to always check the revision number. - // The revision number will be different if the layout will be changed. - auto memMap = comm::datalayer::GetMemoryMap(data.getData()); - auto revision = memMap->revision(); - std::string name; - uint32_t offset = 0; - std::map mapOfOutputs; - std::cout << "Get Bitoffset and Name from Memory Map" << std::endl; - - // Iputs - auto memMapInputs = comm::datalayer::GetMemoryMap(dataIn.getData()); - auto revisionIn = memMapInputs->revision(); - std::string nameIn; - uint32_t offsetIn = 0; - std::map mapOfInputs; - std::cout << "Get Bitoffset and Name from Memory Map (Inputs) " << std::endl; - - // Save all the outputs (name and offset) into a map - for (auto variable = memMap->variables()->begin(); variable != memMap->variables()->end(); variable++) - { - if (variable->bitsize() == 1) - { - name = variable->name()->str(); - std::cout << "Name of Output we found: " << name << std::endl; - offset = variable->bitoffset(); - std::cout << "Bitoffset: " << offset << std::endl; - mapOfOutputs.insert(std::make_pair(name, offset)); - } - } - - // Save all the inputs (name and offset) into a map - for (auto variable = memMapInputs->variables()->begin(); variable != memMapInputs->variables()->end(); variable++) - { - if (variable->bitsize() == 1) - { - nameIn = variable->name()->str(); - std::cout << "Name of Input we found: " << nameIn << std::endl; - offsetIn = variable->bitoffset(); - std::cout << "Bitoffset: " << offsetIn << std::endl; - mapOfInputs.insert(std::make_pair(nameIn, offsetIn)); - } - } - - // Check every second the first input channel if it's true start to toggle - bool startbit = false; - while (!startbit) - { - std::map::iterator it = mapOfInputs.find("S20_EC_BK/S20_DI_16_1/Digital_Input_Channels.DI_Channel_01_Terminal_Point_00_"); - std::cout << "Read Input: " << it->first << " at Offset " << it->second << std::endl; - - result = input->beginAccess(inData, revisionIn); - if (comm::datalayer::STATUS_FAILED(result)) - break; - - uint8_t value = inData[it->second / 8]; - if (value) - { - startbit = true; - } - - input->endAccess(); - std::this_thread::sleep_for(std::chrono::seconds(1)); - } - - // Begin to write outputs until SIGINT is send - bool temp = false; - while (!endProcess) - { - std::cout << "Start to toggle" << std::endl; - - // If first channel would be unset -> end toggle - std::map::iterator itInput = mapOfInputs.find("S20_EC_BK/S20_DI_16_1/Digital_Input_Channels.DI_Channel_01_Terminal_Point_00_"); - result = input->beginAccess(inData, revisionIn); - if (comm::datalayer::STATUS_FAILED(result)) - break; - - uint8_t value = inData[itInput->second / 8]; - if (!value) - { - endProcess = true; - } - - input->endAccess(); - if (!temp) - { - // Create iterator for the map, after that we can iterate through all variables and set the - std::map::iterator it = mapOfOutputs.begin(); - while (it != mapOfOutputs.end()) - { - std::cout << "Set Output: " << it->first << " :: Offset " << it->second << std::endl; - - // Memory is form beginAccess till endAccess locked, so do not do stuff you won't need - result = output->beginAccess(outData, revision); - if (comm::datalayer::STATUS_FAILED(result)) - break; - - // set toggle bit - uint8_t value = outData[it->second / 8]; - value |= 1 << (it->second % 8); - outData[it->second / 8] = value; - output->endAccess(); - it++; - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - - temp = true; - } - else - { - std::map::iterator it = mapOfOutputs.begin(); - while (it != mapOfOutputs.end()) - { - std::cout << "Unset Output: " << it->first << " :: Offset " << it->second << std::endl; - - // Memory is form beginAccess till endAccess locked, so do not do stuff you won't need - result = output->beginAccess(outData, revision); - if (comm::datalayer::STATUS_FAILED(result)) - break; - - // Set toggle bit - uint8_t value = outData[it->second / 8]; - value &= ~(1 << (it->second % 8)); - outData[it->second / 8] = value; - output->endAccess(); - it++; - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - - temp = false; - } - - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } - - // Set all outputs to save state - std::map::iterator it = mapOfOutputs.begin(); - while (it != mapOfOutputs.end()) - { - std::cout << "Shutting down application" << std::endl; - result = output->beginAccess(outData, revision); - if (comm::datalayer::STATUS_FAILED(result)) - break; - - // Shutting down application - outData[it->second / 8] = 0x00; - output->endAccess(); - it++; - } -} \ No newline at end of file +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ +#include +#include +#include +#include +#include +#include + +#include "comm/datalayer/datalayer.h" +#include "comm/datalayer/datalayer_system.h" +#include "comm/datalayer/memory_map_generated.h" + +#include "ctrlx_datalayer_helper.h" + +static bool g_endProcess = false; +static void signalHandler(int signal) +{ + std::cout << "signal: " << signal << std::endl; + g_endProcess = true; +} + +int main(void) +{ + comm::datalayer::DlResult result; + comm::datalayer::Variant data; + comm::datalayer::Variant dataIn; + comm::datalayer::DatalayerSystem datalayer; + datalayer.start(false); + + comm::datalayer::IClient* client = getClient(datalayer); + if (client == nullptr) + { + std::cout << "ERROR Client connected" << std::endl; + datalayer.stop(); + return 1; + } + + result = client->readSync("fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/output/map", &data); + std::cout << "Read returned: " << result.toString() << std::endl; + + result = client->readSync("fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/input/map", &dataIn); + std::cout << "Read returned: " << result.toString() << std::endl; + + std::signal(SIGINT, signalHandler); + + // First we have to open the realtimememory, reading the whole outputs. + uint8_t* outData; + std::cout << "Opening some realtime memory" << std::endl; + std::shared_ptr output; + result = datalayer.factory()->openMemory(output, "fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/output"); + if (comm::datalayer::STATUS_FAILED(result)) + { + std::cout << "Open the memory failed with: " << result.toString() << std::endl; + } + + // We can read the Inputs to get a Start trigger for example + uint8_t* inData; + std::cout << "Opening some realtime memory" << std::endl; + std::shared_ptr input; + result = datalayer.factory()->openMemory(input, "fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/input"); + if (comm::datalayer::STATUS_FAILED(result)) + { + std::cout << "Open the memory failed with: " << result.toString() << std::endl; + } + + // After successful reading the outputs we must take the memorylayout. + // A Memory owner defines the layout of the realtime memory + // You see it in the datalayer.realtime example (memoryowner.cpp) + do + { + std::cout << "Try to get MemoryMap" << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + result = output->getMemoryMap(data); + std::cout << "Getting MemoryMap with: " << result.toString() << std::endl; + } while (comm::datalayer::STATUS_FAILED(result)); + + do + { + std::cout << "Try to get MemoryMap (Inputs)" << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + result = input->getMemoryMap(dataIn); + std::cout << "Getting MemoryMap with: " << result.toString() << std::endl; + } while (comm::datalayer::STATUS_FAILED(result)); + + // Now we got the layout, but we have to convert it cause it is a flatbuffer + // To imagen the result after converting the data you can take a look at the datalayertree + // "devices/ethercatmaster/0/outputs -> map" + result = data.verifyFlatbuffers(comm::datalayer::VerifyMemoryMapBuffer); + if (comm::datalayer::STATUS_FAILED(result)) + { + std::cout << "Verify Flatbuffers failed with: " << result.toString() << std::endl; + return -1; + } + + // Verify the Input layout, similar to the output + result = dataIn.verifyFlatbuffers(comm::datalayer::VerifyMemoryMapBuffer); + if (comm::datalayer::STATUS_FAILED(result)) + { + std::cout << "Verify Flatbuffers (Inputs) failed with: " << result.toString() << std::endl; + return -1; + } + + // At this point we can take the data. It is important to always check the revision number. + // The revision number will be different if the layout will be changed. + auto memMap = comm::datalayer::GetMemoryMap(data.getData()); + auto revision = memMap->revision(); + std::string name; + uint32_t offset = 0; + std::map mapOfOutputs; + std::cout << "Get Bitoffset and Name from Memory Map" << std::endl; + + // Iputs + auto memMapInputs = comm::datalayer::GetMemoryMap(dataIn.getData()); + auto revisionIn = memMapInputs->revision(); + std::string nameIn; + uint32_t offsetIn = 0; + std::map mapOfInputs; + std::cout << "Get Bitoffset and Name from Memory Map (Inputs) " << std::endl; + + // Save all the outputs (name and offset) into a map + for (auto variable = memMap->variables()->begin(); variable != memMap->variables()->end(); variable++) + { + if (variable->bitsize() == 1) + { + name = variable->name()->str(); + std::cout << "Name of Output we found: " << name << std::endl; + offset = variable->bitoffset(); + std::cout << "Bitoffset: " << offset << std::endl; + mapOfOutputs.insert(std::make_pair(name, offset)); + } + } + + // Save all the inputs (name and offset) into a map + for (auto variable = memMapInputs->variables()->begin(); variable != memMapInputs->variables()->end(); variable++) + { + if (variable->bitsize() == 1) + { + nameIn = variable->name()->str(); + std::cout << "Name of Input we found: " << nameIn << std::endl; + offsetIn = variable->bitoffset(); + std::cout << "Bitoffset: " << offsetIn << std::endl; + mapOfInputs.insert(std::make_pair(nameIn, offsetIn)); + } + } + + // Check every second the first input channel if it's true start to toggle + bool startbit = false; + while (!startbit) + { + std::map::iterator it = mapOfInputs.find("S20_EC_BK/S20_DI_16_1/Digital_Input_Channels.DI_Channel_01_Terminal_Point_00_"); + std::cout << "Read Input: " << it->first << " at Offset " << it->second << std::endl; + + result = input->beginAccess(inData, revisionIn); + if (comm::datalayer::STATUS_FAILED(result)) + { + break; + } + + uint8_t value = inData[it->second / 8]; + if (value) + { + startbit = true; + } + + input->endAccess(); + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + // Begin to write outputs until SIGINT is send + bool temp = false; + while (!g_endProcess) + { + std::cout << "Start to toggle" << std::endl; + + // If first channel would be unset -> end toggle + std::map::iterator itInput = mapOfInputs.find("S20_EC_BK/S20_DI_16_1/Digital_Input_Channels.DI_Channel_01_Terminal_Point_00_"); + result = input->beginAccess(inData, revisionIn); + if (comm::datalayer::STATUS_FAILED(result)) + { + break; + } + + uint8_t value = inData[itInput->second / 8]; + if (!value) + { + g_endProcess = true; + } + + input->endAccess(); + if (!temp) + { + // Create iterator for the map, after that we can iterate through all variables and set the + std::map::iterator it = mapOfOutputs.begin(); + while (it != mapOfOutputs.end()) + { + std::cout << "Set Output: " << it->first << " :: Offset " << it->second << std::endl; + + // Memory is form beginAccess till endAccess locked, so do not do stuff you won't need + result = output->beginAccess(outData, revision); + if (comm::datalayer::STATUS_FAILED(result)) + { + break; + } + + // set toggle bit + uint8_t value = outData[it->second / 8]; + value |= 1 << (it->second % 8); + outData[it->second / 8] = value; + output->endAccess(); + it++; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + temp = true; + } + else + { + std::map::iterator it = mapOfOutputs.begin(); + while (it != mapOfOutputs.end()) + { + std::cout << "Unset Output: " << it->first << " :: Offset " << it->second << std::endl; + + // Memory is form beginAccess till endAccess locked, so do not do stuff you won't need + result = output->beginAccess(outData, revision); + if (comm::datalayer::STATUS_FAILED(result)) + { + break; + } + + // Set toggle bit + uint8_t value = outData[it->second / 8]; + value &= ~(1 << (it->second % 8)); + outData[it->second / 8] = value; + output->endAccess(); + it++; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + temp = false; + } + + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } + + // Set all outputs to save state + std::map::iterator it = mapOfOutputs.begin(); + while (it != mapOfOutputs.end()) + { + std::cout << "Shutting down application" << std::endl; + result = output->beginAccess(outData, revision); + if (comm::datalayer::STATUS_FAILED(result)) + { + break; + } + + // Shutting down application + outData[it->second / 8] = 0x00; + output->endAccess(); + it++; + } + return 0; +} diff --git a/samples-cpp/datalayer.ecat.io/snap/snapcraft.yaml b/samples-cpp/datalayer.ecat.io/snap/snapcraft.yaml index 194c4e384..9bf0feae7 100644 --- a/samples-cpp/datalayer.ecat.io/snap/snapcraft.yaml +++ b/samples-cpp/datalayer.ecat.io/snap/snapcraft.yaml @@ -8,8 +8,8 @@ version: "2.2.0" grade: stable summary: Sample app for processing rt data from EtherCAT description: | - This app will read EtherCAT nodes from the Data Layer. -base: core20 + This app will read EtherCAT nodes from the ctrlX Data Layer. +base: core22 confinement: strict # define how apps & services are exposed to host system diff --git a/samples-cpp/datalayer.provider.all-data/.vscode/launch.json b/samples-cpp/datalayer.provider.all-data/.vscode/launch.json index dc7791482..1c953ac54 100644 --- a/samples-cpp/datalayer.provider.all-data/.vscode/launch.json +++ b/samples-cpp/datalayer.provider.all-data/.vscode/launch.json @@ -9,8 +9,8 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/allDataProvider", - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/allDataProvider", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,7 +23,7 @@ }, { "description": "Set path variable to .", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false }, { @@ -37,7 +37,7 @@ "name": "aarch64 ctrlX (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-aarch64/Debug/allDataProvider", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-aarch64/Debug/allDataProvider", "args": ["boschrexroth:boschrexroth@192.168.1.1"], "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", diff --git a/samples-cpp/datalayer.provider.all-data/.vscode/settings.json b/samples-cpp/datalayer.provider.all-data/.vscode/settings.json index f8b0309e4..bfbc7c484 100644 --- a/samples-cpp/datalayer.provider.all-data/.vscode/settings.json +++ b/samples-cpp/datalayer.provider.all-data/.vscode/settings.json @@ -1,5 +1,5 @@ { - "window.zoomLevel": 1, + "window.zoomLevel": 0, "cmake.configureArgs": [ "-DCMAKE_BUILD_KIT=${buildKit}" ], @@ -53,6 +53,11 @@ "thread": "cpp", "typeinfo": "cpp", "list": "cpp", - "bit": "cpp" + "bit": "cpp", + "csignal": "cpp", + "numeric": "cpp", + "random": "cpp", + "iomanip": "cpp", + "cinttypes": "cpp" } } \ No newline at end of file diff --git a/samples-cpp/datalayer.provider.all-data/.vscode/tasks.json b/samples-cpp/datalayer.provider.all-data/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-cpp/datalayer.provider.all-data/.vscode/tasks.json +++ b/samples-cpp/datalayer.provider.all-data/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/datalayer.provider.all-data/CMakeLists.txt b/samples-cpp/datalayer.provider.all-data/CMakeLists.txt index cd3eeefc0..4e64a3cc0 100644 --- a/samples-cpp/datalayer.provider.all-data/CMakeLists.txt +++ b/samples-cpp/datalayer.provider.all-data/CMakeLists.txt @@ -44,12 +44,12 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DMY_DEBUG") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET(PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET(PLATFORM_NAME "ubuntu22-gcc-aarch64") SET(SNAP_ARCH "arm64") SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET(PLATFORM_NAME "ubuntu20-gcc-x64") + SET(PLATFORM_NAME "ubuntu22-gcc-x64") SET(SNAP_ARCH "amd64") SET(CMAKE_C_COMPILER gcc) SET(CMAKE_CXX_COMPILER g++) @@ -71,7 +71,6 @@ SET ( PRIVATE_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/include ${USER_DEPENDENCY_DIR}/include - ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers.1.12 ${USER_DEPENDENCY_DIR}/include/comm.datalayer ) @@ -80,12 +79,12 @@ SET ( PRIVATE_INCLUDE_DIRS # execute_process(COMMAND uname -a OUTPUT_VARIABLE HOST_SYSTEM_ARCH) IF( ${HOST_SYSTEM_ARCH} MATCHES "aarch64") - set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers.1.12/ubuntu20-gcc-aarch64/release/flatc) + set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers/ubuntu22-gcc-aarch64/release/flatc) ELSE() - set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers.1.12/ubuntu20-gcc-x64/release/flatc) + set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers/ubuntu22-gcc-x64/release/flatc) ENDIF() -set (FLATBUFFERS_INCLUDE_DIR ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers.1.12) -include (${USER_DEPENDENCY_DIR}/cmake/oss.flatbuffers.1.12/FindFlatBuffers.cmake) +set (FLATBUFFERS_INCLUDE_DIR ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers) +include (${USER_DEPENDENCY_DIR}/cmake/oss.flatbuffers/FindFlatBuffers.cmake) set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--gen-object-api") set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--no-warnings") set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--gen-compare") diff --git a/samples-cpp/datalayer.provider.all-data/LICENSE b/samples-cpp/datalayer.provider.all-data/LICENSE deleted file mode 100644 index d1231b68e..000000000 --- a/samples-cpp/datalayer.provider.all-data/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/datalayer.provider.all-data/README.md b/samples-cpp/datalayer.provider.all-data/README.md index fc1b6f891..c0b711d34 100644 --- a/samples-cpp/datalayer.provider.all-data/README.md +++ b/samples-cpp/datalayer.provider.all-data/README.md @@ -1,77 +1,58 @@ -# AllDataProvider App - -This cpp sample app is a Data Layer Provider which can be used in two wayes: - -1. As a sample how in cpp variables of different data types can be involved into Data Layer Variants. -2. As a test Data Layer Provider during development of a Data Layer Client. These client apps can be written in one of the SDK supported languages or can be Node-RED or REST API applications. - -## Introduction - -The AllDataProvider creates two Data Layer branches: `all-data/dynamic` and `all-data/static`. - -The branches are providing sub nodes for most of the Data Layer Variant types. - -The static branch and its nodes cannot be changed by Data Layer Client interactions. It can be used to read data and to test the min and max data values within the own application. - -The dynamic branch however is changeable. Nodes can be written or even deleted by clients. Furthermore new nodes or whole sub branches can be created. - -## Implementation - -### main.cpp - -The main function establishes the Data Layer connection. If the app is running within a snap on the ctrlX a IPC connection is used automatically. This connection doesn't need user credentials. - -For a debugging session or in remote mode a tcp connection which need user credentials and an address is used. Therefore in the code user, password and address are predefined with default values. - -**Important:** -Do NOT use this default values! -* Add a separate user/password for this app in your ctrlX and change values in the code. -* Check the IP address of your ctrlX and change the value in the code if it is different. - -Hint: Use 127.0.0.1 as address if you are working with a ctrlX COREvirtual connected with Port Forwarding. - -### DataContainer Class - -DataContainer is a simple data container class representing the data and error state of a node seen in the dynamic and/or static branch. - -### ProviderNodeAllData Class - -ProviderNodeAllData is a IProviderNode implementation and provides a Data Layer sub branch. The sub branch can be static or dynamic. -Static means that the values of the nodes and the structure of he branch cannot be changed by Data Layer clients. In a dynamic branch everything can be changed. - -All nodes of such a sub branch are 'virtual' because the node behind is always the same ProviderNodeAllData instance. Therefore it registers itself with a wildcard address (e.g. all-data/dynamic/\*\*) at the Data Layer. The 'seen' nodes are DataContainer instances managed in a list and accessed by the on... callback functions of the ProviderNodeAllData class. - -## Build and Install the Snap - -Build and install the snap like described [here](../README.md). - -## Test the Snap - -* Open the web interface of your ctrlX CORE -* Check output in the web interface - -___ - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# AllDataProvider App + +This cpp sample app is a ctrlX Data Layer Provider which can be used in two wayes: + +1. As a sample how in cpp variables of different data types can be involved into ctrlX Data Layer Variants. +2. As a test ctrlX Data Layer Provider during development of a ctrlX Data Layer Client. These client apps can be written in one of the SDK supported languages or can be Node-RED or REST API applications. + +## Introduction + +The AllDataProvider creates two ctrlX Data Layer branches: `all-data/dynamic` and `all-data/static`. + +The branches are providing sub nodes for most of the ctrlX Data Layer Variant types. + +The static branch and its nodes cannot be changed by ctrlX Data Layer Client interactions. It can be used to read data and to test the min and max data values within the own application. + +The dynamic branch however is changeable. Nodes can be written or even deleted by clients. Furthermore new nodes or whole sub branches can be created. + +## Implementation + +### main.cpp + +The main function establishes the ctrlX Data Layer connection. If the app is running within a snap on the ctrlX a IPC connection is used automatically. This connection doesn't need user credentials. + +For a debugging session or in remote mode a tcp connection which need user credentials and an address is used. Therefore in the code user, password and address are predefined with default values. + +**Important:** +Do NOT use this default values! +* Add a separate user/password for this app in your ctrlX and change values in the code. +* Check the IP address of your ctrlX and change the value in the code if it is different. + +Hint: Use 127.0.0.1 as address if you are working with a ctrlX COREvirtual connected with Port Forwarding. + +### DataContainer Class + +DataContainer is a simple data container class representing the data and error state of a node seen in the dynamic and/or static branch. + +### ProviderNodeAllData Class + +ProviderNodeAllData is a IProviderNode implementation and provides a ctrlX Data Layer sub branch. The sub branch can be static or dynamic. +Static means that the values of the nodes and the structure of he branch cannot be changed by ctrlX Data Layer clients. In a dynamic branch everything can be changed. + +All nodes of such a sub branch are 'virtual' because the node behind is always the same ProviderNodeAllData instance. Therefore it registers itself with a wildcard address (e.g. all-data/dynamic/\*\*) at the ctrlX Data Layer. The 'seen' nodes are DataContainer instances managed in a list and accessed by the on... callback functions of the ProviderNodeAllData class. + +## Build and Install the Snap + +Build and install the snap like described [here](../README.md). + +## Test the Snap + +* Open the web interface of your ctrlX CORE +* Check output in the web interface + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/datalayer.provider.all-data/build-snap-amd64.sh b/samples-cpp/datalayer.provider.all-data/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/datalayer.provider.all-data/build-snap-amd64.sh +++ b/samples-cpp/datalayer.provider.all-data/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.provider.all-data/build-snap-arm64.sh b/samples-cpp/datalayer.provider.all-data/build-snap-arm64.sh index f48f8a433..8be304510 100644 --- a/samples-cpp/datalayer.provider.all-data/build-snap-arm64.sh +++ b/samples-cpp/datalayer.provider.all-data/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.provider.all-data/ctrlx_datalayer_helper.h b/samples-cpp/datalayer.provider.all-data/ctrlx_datalayer_helper.h index a46ddf714..20d27398b 100644 --- a/samples-cpp/datalayer.provider.all-data/ctrlx_datalayer_helper.h +++ b/samples-cpp/datalayer.provider.all-data/ctrlx_datalayer_helper.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef CTRLX_DATALAYER_HELPER_H #define CTRLX_DATALAYER_HELPER_H @@ -42,17 +24,17 @@ * If these values do not suit your use case, explicitly pass the parameters that require different values. * Here some examples: * - * 1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: + * 1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: * * client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") * - * 2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): + * 2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): * * client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) * * Remarks: * 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual * * * IMPORTANT: @@ -83,10 +65,10 @@ static bool isSnap() } //! Get Datalayer connection string -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result Connection string static std::string getConnectionString( const std::string& ip = "192.168.1.1", @@ -111,10 +93,10 @@ static std::string getConnectionString( //! Get Datalayer Client instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IClient instance or nullptr on error static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", @@ -135,10 +117,10 @@ static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& dat //! Get Datalayer Provider instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IProvider instance or nullptr on error static comm::datalayer::IProvider* getProvider(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", diff --git a/samples-cpp/datalayer.provider.all-data/dataContainer.h b/samples-cpp/datalayer.provider.all-data/dataContainer.h index 435f0e3a0..6d72584b2 100644 --- a/samples-cpp/datalayer.provider.all-data/dataContainer.h +++ b/samples-cpp/datalayer.provider.all-data/dataContainer.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef DATA_CONTAINER_H @@ -42,40 +24,36 @@ Class DataContainer: This class is just a Data Container used by the class ProviderNodeAllData. - Under a ProviderNodeAllData instance the whole Data Layer sub branch and the seen nodes are 'virtual'. + Under a ProviderNodeAllData instance the whole ctrlX Data Layer sub branch and the seen nodes are 'virtual'. Instead of heavy IProviderNode instances a ProviderNodeAllData node creates and manages lightweight DataContainer instances. Within a DataContainer instance only a comm::datalayer::Variant is stored to represent the node data. - ErrorCode and Error are used to 'simulate' an error state. + m_errorCode and m_error are used to 'simulate' an error state. */ -class DataContainer +class DataContainer final { - public: - // The Data Layer address of the virtual node - std::string Address; + // The ctrlX Data Layer address of the virtual node + std::string m_address; // The Data of the virtual node - comm::datalayer::Variant Data; + comm::datalayer::Variant m_data; // The Metadata of the virtual node - comm::datalayer::Variant Metadata; + comm::datalayer::Variant m_metadata; // The error code of the virtual node: <0: Error, ==0: OK; >0: Warning - int ErrorCode = 0; - - // The error text - std::string Error = ""; + int m_errorCode = 0; // Constructor - DataContainer(const std::string& address, const comm::datalayer::Variant& data, const comm::datalayer::Variant& meatadata) - { - Address = address; - Data = data; // A copy is made - Metadata = meatadata; // A copy is made - } + DataContainer(const std::string& address, const comm::datalayer::Variant& data, const comm::datalayer::Variant& metadata) + : m_address(address) + , m_data(data) + , m_metadata(metadata) + {} + ~DataContainer() = default; }; #endif diff --git a/samples-cpp/datalayer.provider.all-data/main.cpp b/samples-cpp/datalayer.provider.all-data/main.cpp index f6d59b074..c16923255 100644 --- a/samples-cpp/datalayer.provider.all-data/main.cpp +++ b/samples-cpp/datalayer.provider.all-data/main.cpp @@ -1,41 +1,24 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2020-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ -#include +#include #include #include #include "ctrlx_datalayer_helper.h" #include "providerNodeAllData.h" -static std::string dl_addr_base = "sdk-cpp-alldata/"; // snap/snapcraft.yaml name: +static std::string g_dataLayerAddrBase = "sdk-cpp-alldata/"; // snap/snapcraft.yaml name: // Add some signal Handling so we are able to abort the program with sending sigint -bool endProcess = false; -static void sigHandler(int sig, siginfo_t* siginfo, void* context) +static bool g_endProcess = false; +static void signalHandler(int signal) { - endProcess = true; + std::cout << "signal: " << signal << std::endl; + g_endProcess = true; } static void shutdownMessage() @@ -44,8 +27,8 @@ static void shutdownMessage() std::cout << "Check physical network connection!" << std::endl; std::cout << "Check connection parameters:" << std::endl; - std::cout << "ctrlX CORE virtual via port forwarding: IP=10.0.2.2, is port 2070 forwarded?" << std::endl; - std::cout << "ctrlX CORE virtual with network adapter or real: Is IP address correct?" << std::endl; + std::cout << "ctrlX COREvirtual via port forwarding: IP=10.0.2.2, is port 2070 forwarded?" << std::endl; + std::cout << "ctrlX COREvirtual with network adapter or real: Is IP address correct?" << std::endl; std::cout << "Is ctrlX CORE in Operation mode? " << std::endl; std::cout << std::endl; @@ -56,27 +39,17 @@ static void shutdownMessage() } } -int main() +int main(void) { -#ifdef MY_DEBUG - std::cout << "Raising SIGSTOP" << std::endl; - //raise(SIGSTOP); - std::cout << "... Continue..." << std::endl; -#endif - // Prepare signal structure to interrupt the endless loop with ctrl + c - struct sigaction act; - memset(&act, '\0', sizeof(act)); - act.sa_sigaction = &sigHandler; - act.sa_flags = SA_SIGINFO; - sigaction(SIGINT, &act, NULL); + std::signal(SIGINT, signalHandler); comm::datalayer::DatalayerSystem datalayerSystem; datalayerSystem.start(false); - // ip="192.168.1.1" or any other IP address if a ctrlX CORE or ctrlX CORE virtual - // ip="10.0.2.2" ctrlX CORE virtual with port forwarding + // ip="192.168.1.1" or any other IP address if a ctrlX CORE or ctrlX COREvirtual + // ip="10.0.2.2" ctrlX COREvirtual with port forwarding auto* provider = getProvider(datalayerSystem); if (provider == nullptr) { @@ -85,15 +58,15 @@ int main() return 1; } - std::cout << "INFO Creating Data Layer branch " << dl_addr_base << std::endl; - auto providerNodeStatic = new ProviderNodeAllData(provider, dl_addr_base, false); - providerNodeStatic->RegisterNodes(); + std::cout << "INFO Creating ctrlX Data Layer branch " << g_dataLayerAddrBase << std::endl; + auto providerNodeStatic = new ProviderNodeAllData(provider, g_dataLayerAddrBase, false); + providerNodeStatic->registerNodes(); - auto providerNodeDynamic = new ProviderNodeAllData(provider, dl_addr_base, true); - providerNodeDynamic->RegisterNodes(); + auto providerNodeDynamic = new ProviderNodeAllData(provider, g_dataLayerAddrBase, true); + providerNodeDynamic->registerNodes(); std::cout << "INFO Running endless loop - end with Ctrl+C" << std::endl; - while (endProcess == false) + while (g_endProcess == false) { if (provider->isConnected() == false) { @@ -113,5 +86,5 @@ int main() datalayerSystem.stop(false); // Attention: Doesn't return if any provider or client instance is still runnning - return endProcess ? 0 : 1; + return g_endProcess ? 0 : 1; } diff --git a/samples-cpp/datalayer.provider.all-data/providerNodeAllData.cpp b/samples-cpp/datalayer.provider.all-data/providerNodeAllData.cpp index e19faa328..42c8339f0 100644 --- a/samples-cpp/datalayer.provider.all-data/providerNodeAllData.cpp +++ b/samples-cpp/datalayer.provider.all-data/providerNodeAllData.cpp @@ -1,37 +1,20 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2020-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #include #include "providerNodeAllData.h" #include "sampleSchema_generated.h" +#include "ctrlx_datalayer_helper.h" DataContainer* ProviderNodeAllData::getDataContainer(const std::string& address) { - for (auto dataContainer : _dataContainers) + for (auto dataContainer : m_dataContainers) { - if (dataContainer->Address == address) + if (dataContainer->m_address == address) { return dataContainer; } @@ -52,11 +35,11 @@ comm::datalayer::DlResult ProviderNodeAllData::createDataContainer( auto metadata = createMetadata(data, address); auto dataContainer = new DataContainer(address, data, metadata); - _dataContainers.emplace_back(dataContainer); + m_dataContainers.emplace_back(dataContainer); - // We register the address of our datacontainer now so that the Data Layer will show it as "virtual node". + // We register the address of our datacontainer now so that the ctrlX Data Layer will show it as "virtual node". // The "virtual node" has as provider this instance. - return _provider->registerNode(address, this); + return m_provider->registerNode(address, this); } void ProviderNodeAllData::createDataContainer( @@ -64,7 +47,7 @@ void ProviderNodeAllData::createDataContainer( const std::string& addressNode, const comm::datalayer::Variant& data) { - const std::string address = _addressBase + addressNode; + const std::string address = m_addressBase + addressNode; if (comm::datalayer::DlResult::DL_OK != setValueResult) { std::cout << "ERROR - Data could not be set: " << address; @@ -83,7 +66,7 @@ comm::datalayer::Variant ProviderNodeAllData::createMetadata(const comm::datalay auto description = builder.CreateString("This is a description for " + address); comm::datalayer::NodeClass nodeClass = comm::datalayer::NodeClass_Variable; - bool isBaseFolder = address == _addressBase; + bool isBaseFolder = address == m_addressBase; if (isBaseFolder) { nodeClass = comm::datalayer::NodeClass_Folder; @@ -91,22 +74,22 @@ comm::datalayer::Variant ProviderNodeAllData::createMetadata(const comm::datalay comm::datalayer::AllowedOperationsBuilder allowedOperations(builder); allowedOperations.add_read(!isBaseFolder); - allowedOperations.add_write(!isBaseFolder && _dynamic); - allowedOperations.add_create(!isBaseFolder && _dynamic); - allowedOperations.add_delete_(!isBaseFolder && _dynamic); + allowedOperations.add_write(!isBaseFolder && m_dynamic); + allowedOperations.add_create(!isBaseFolder && m_dynamic); + allowedOperations.add_delete_(!isBaseFolder && m_dynamic); auto operations = allowedOperations.Finish(); flatbuffers::Offset>> references; if (data.getType() == comm::datalayer::VariantType::FLATBUFFERS) { - const char* type_addr = "types/sampleSchema/inertialValue"; + const char* typeAddr = "types/sampleSchema/inertialValue"; - if (_dynamic) + if (m_dynamic) { flatbuffers::Offset vecReferences[] = { - comm::datalayer::CreateReferenceDirect(builder, "readType", type_addr), - comm::datalayer::CreateReferenceDirect(builder, "writeType", type_addr), + comm::datalayer::CreateReferenceDirect(builder, "readType", typeAddr), + comm::datalayer::CreateReferenceDirect(builder, "writeType", typeAddr), }; references = builder.CreateVectorOfSortedTables(vecReferences, 2); } @@ -114,7 +97,7 @@ comm::datalayer::Variant ProviderNodeAllData::createMetadata(const comm::datalay { flatbuffers::Offset vecReferences[] = { - comm::datalayer::CreateReferenceDirect(builder, "readType", type_addr), + comm::datalayer::CreateReferenceDirect(builder, "readType", typeAddr), }; references = builder.CreateVectorOfSortedTables(vecReferences, 1); } @@ -140,22 +123,19 @@ comm::datalayer::Variant ProviderNodeAllData::createMetadata(const comm::datalay } ProviderNodeAllData::ProviderNodeAllData(comm::datalayer::IProvider* provider, const std::string& addressRoot, bool dynamic) + : m_provider(provider) + , m_addressRoot(addressRoot) + , m_dynamic(dynamic) + , m_addressBase(dynamic ? m_addressRoot + "dynamic/" : m_addressRoot + "static/") { - _provider = provider; - _addressRoot = addressRoot; - _dynamic = dynamic; - - _addressBase = dynamic ? _addressRoot + "dynamic/" : _addressRoot + "static/"; - - const comm::datalayer::Variant data; - _metadata = createMetadata(data, _addressBase); + m_metadata = createMetadata(comm::datalayer::Variant(), m_addressBase); } -void ProviderNodeAllData::RegisterNodes() +void ProviderNodeAllData::registerNodes() { comm::datalayer::DlResult result; - result = _provider->registerNode(_addressBase + "**", this); - + result = m_provider->registerNode(m_addressBase + "**", this); + std::cout << "registerNodes: " << result.toString() << std::endl; comm::datalayer::Variant data; result = data.setValue(true); @@ -207,54 +187,54 @@ void ProviderNodeAllData::RegisterNodes() createDataContainer(result, "timestamp-2014-07-13-germany-soccer-world-champion", data); // Arrays ---------------------- - bool a_bool[] = {true, false, true}; - result = data.setValue(a_bool); + bool abool[] = {true, false, true}; + result = data.setValue(abool); createDataContainer(result, "array-of-bool8", data); - int8_t a_int8_t[] = {INT8_MIN, -1, 0, INT8_MAX}; - result = data.setValue(a_int8_t); + int8_t aint8[] = {INT8_MIN, -1, 0, INT8_MAX}; + result = data.setValue(aint8); createDataContainer(result, "array-of-int8", data); - uint8_t a_uint8_t[] = {0, UINT8_MAX}; - result = data.setValue(a_uint8_t); + uint8_t auint8[] = {0, UINT8_MAX}; + result = data.setValue(auint8); createDataContainer(result, "array-of-uint8", data); - int16_t a_int16_t[] = {INT16_MIN, -1, 0, INT16_MAX}; - result = data.setValue(a_int16_t); + int16_t aint16[] = {INT16_MIN, -1, 0, INT16_MAX}; + result = data.setValue(aint16); createDataContainer(result, "array-of-int16", data); - uint16_t a_uint16_t[] = {0, 32767, 32768, UINT16_MAX}; - result = data.setValue(a_uint16_t); + uint16_t auint16[] = {0, 32767, 32768, UINT16_MAX}; + result = data.setValue(auint16); createDataContainer(result, "array-of-uint16", data); - int32_t a_int32_t[] = {INT32_MIN, -1, 0, INT32_MAX}; - result = data.setValue(a_int32_t); + int32_t aint32[] = {INT32_MIN, -1, 0, INT32_MAX}; + result = data.setValue(aint32); createDataContainer(result, "array-of-int32", data); - uint32_t a_uint32_t[] = {0, UINT32_MAX}; - result = data.setValue(a_uint32_t); + uint32_t auint32[] = {0, UINT32_MAX}; + result = data.setValue(auint32); createDataContainer(result, "array-of-uint32", data); - int64_t a_int64_t[] = {INT64_MIN, -1, 0, INT64_MAX}; - result = data.setValue(a_int64_t); + int64_t aint64[] = {INT64_MIN, -1, 0, INT64_MAX}; + result = data.setValue(aint64); createDataContainer(result, "array-of-int64", data); - uint64_t a_uint64_t[] = {0, UINT64_MAX}; - result = data.setValue(a_uint64_t); + uint64_t auint64[] = {0, UINT64_MAX}; + result = data.setValue(auint64); createDataContainer(result, "array-of-uint64", data); - float a_float[] = {FLT_MIN, -1.0, 0.0, FLT_MAX}; - result = data.setValue(a_float); + float afloat[] = {FLT_MIN, -1.0, 0.0, FLT_MAX}; + result = data.setValue(afloat); createDataContainer(result, "array-of-float32", data); - double a_double[] = {DBL_MIN, -1.0, 0.0, DBL_MAX}; - result = data.setValue(a_double); + double adouble[] = {DBL_MIN, -1.0, 0.0, DBL_MAX}; + result = data.setValue(adouble); createDataContainer(result, "array-of-float64", data); - // std::string a_string[] = {"Blue", "Red", "Orange", "Yellow"}; - // const char *a_string[] = {"Blue", "Red", "Orange", "Yellow"}; - std::vector a_string = {"Blue", "Red", "Orange", "Yellow"}; // Only vector is supported 03/2021 - result = data.setValue(a_string); + // std::string astring[] = {"Blue", "Red", "Orange", "Yellow"}; + // const char *astring[] = {"Blue", "Red", "Orange", "Yellow"}; + std::vector astring = {"Blue", "Red", "Orange", "Yellow"}; // Only vector is supported 03/2021 + result = data.setValue(astring); createDataContainer(result, "array-of-string", data); unsigned char bytes[] = {0x43, 0x4d, 0x30, 0x30, 0x0f, 0x0D}; @@ -263,8 +243,8 @@ void ProviderNodeAllData::RegisterNodes() // Register the FlatBuffers type std::string typeAddress = "types/sampleSchema/inertialValue"; - std::string bfbs = is_snap() ? std::string(snap_path()).append("/sampleSchema.bfbs") : "bfbs/sampleSchema.bfbs"; - result = _provider->registerType(typeAddress, bfbs); + std::string bfbs = isSnap() ? std::string(snapPath()).append("/sampleSchema.bfbs") : "bfbs/sampleSchema.bfbs"; + result = m_provider->registerType(typeAddress, bfbs); if (result != comm::datalayer::DlResult::DL_OK) { std::cout << "ERROR registerType(): " << typeAddress << " code: 0x" << std::hex << result.value << std::endl; @@ -292,7 +272,7 @@ void ProviderNodeAllData::onCreate( { comm::datalayer::DlResult result; - if (_dynamic == false) + if (m_dynamic == false) { result = comm::datalayer::DlResult::DL_PERMISSION_DENIED; std::cout << "onCreate(): " << address << " " << result.toString() << std::endl; @@ -326,8 +306,8 @@ void ProviderNodeAllData::onRead( return; } - comm::datalayer::Variant myData = dataContainer->Data; - result = dataContainer->ErrorCode >= 0 ? comm::datalayer::DlResult::DL_OK : comm::datalayer::DlResult::DL_INVALID_VALUE; + comm::datalayer::Variant myData = dataContainer->m_data; + result = dataContainer->m_errorCode >= 0 ? comm::datalayer::DlResult::DL_OK : comm::datalayer::DlResult::DL_INVALID_VALUE; //std::cout << "onRead(): " << address << " " << result.toString() << std::endl; callback(result, &myData); @@ -341,7 +321,7 @@ void ProviderNodeAllData::onWrite( { comm::datalayer::DlResult result; - if (_dynamic == false) + if (m_dynamic == false) { result = comm::datalayer::DlResult::DL_PERMISSION_DENIED; std::cout << "onWrite(): " << address << " "; @@ -355,7 +335,7 @@ void ProviderNodeAllData::onWrite( if (nullptr == dataContainer) { // A virtual node which is not registered should be written. - // We a creating and registering the virtual node now. This makes Data Layer usage easy for a client. + // We a creating and registering the virtual node now. This makes ctrlX Data Layer usage easy for a client. result = createDataContainer(address, *data); std::cout << "onWrite() CREATE: " << address << " " << result.toString() << std::endl; } @@ -364,7 +344,7 @@ void ProviderNodeAllData::onWrite( // The virtual node is already registered. result = comm::datalayer::DlResult::DL_OK; // We are take the data without data type check. - dataContainer->Data = *data; + dataContainer->m_data = *data; // No trace to improve performance // std::cout << "onWrite(): " << address << " OK" << std::endl; } @@ -379,7 +359,7 @@ void ProviderNodeAllData::onRemove( { comm::datalayer::DlResult result; - if (_dynamic == false) + if (m_dynamic == false) { result = comm::datalayer::DlResult::DL_PERMISSION_DENIED; std::cout << "onRemove(): " << address << " " << result.toString() << std::endl; @@ -390,8 +370,8 @@ void ProviderNodeAllData::onRemove( DataContainer* dataContainer = getDataContainer(address); if (nullptr != dataContainer) { - _provider->unregisterNode(dataContainer->Address); - remove(_dataContainers.begin(), _dataContainers.end(), dataContainer); + m_provider->unregisterNode(dataContainer->m_address); + std::remove(m_dataContainers.begin(), m_dataContainers.end(), dataContainer); delete dataContainer; } @@ -408,7 +388,7 @@ void ProviderNodeAllData::onBrowse( // No trace to improve performance //std::cout << "onBrowse(): " << address << std::endl; - callback(comm::datalayer::DlResult::DL_OK, nullptr); // Data Layer Broker "knows" all sub node, we don't add further nodes here. + callback(comm::datalayer::DlResult::DL_OK, nullptr); // ctrlX Data Layer Broker "knows" all sub node, we don't add further nodes here. } // Read function of metadata of an object. Function will be called whenever the metadata of a node should be written. @@ -420,9 +400,9 @@ void ProviderNodeAllData::onMetadata( DataContainer* dataContainer = getDataContainer(address); // For .../dynamic or .../static we get also nullptr if (nullptr == dataContainer) { - if (address + "/" == _addressBase) + if (address + "/" == m_addressBase) { - callback(comm::datalayer::DlResult::DL_OK, &_metadata); + callback(comm::datalayer::DlResult::DL_OK, &m_metadata); return; } result = comm::datalayer::DlResult::DL_INVALID_ADDRESS; @@ -430,5 +410,5 @@ void ProviderNodeAllData::onMetadata( callback(result, nullptr); return; } - callback(comm::datalayer::DlResult::DL_OK, &dataContainer->Metadata); -} \ No newline at end of file + callback(comm::datalayer::DlResult::DL_OK, &dataContainer->m_metadata); +} diff --git a/samples-cpp/datalayer.provider.all-data/providerNodeAllData.h b/samples-cpp/datalayer.provider.all-data/providerNodeAllData.h index 901888421..42b72d586 100644 --- a/samples-cpp/datalayer.provider.all-data/providerNodeAllData.h +++ b/samples-cpp/datalayer.provider.all-data/providerNodeAllData.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef PROVIDER_NODE_ALL_DATA_H @@ -41,35 +23,35 @@ /* ProviderNodeAllData - This class implements the IProviderNode interface and provides an 'all-data' Data Layer sub branch. - The branch and it's nodes are virtual - Data Layer clients will see normal Data Layer nodes + This class implements the IProviderNode interface and provides an 'all-data' ctrlX Data Layer sub branch. + The branch and it's nodes are virtual - ctrlX Data Layer clients will see normal ctrlX Data Layer nodes but they are all 'simulated' by an instance of this class. For each virtual node a DataContainer instance is used. The branch can be dynamic. In this case the branch itself and it's nodes can be manipulated (write, remove,..) by clients. If the branch is declared as static now changes can be made. This is useful for integration test and so on. */ -class ProviderNodeAllData : public comm::datalayer::IProviderNode +class ProviderNodeAllData: public comm::datalayer::IProviderNode { protected: // List of DataContainer instances ('virtual nodes') - std::vector _dataContainers; + std::vector m_dataContainers; - // The Data Layer Provider instance - comm::datalayer::IProvider* _provider; + // The ctrlX Data Layer Provider instance + comm::datalayer::IProvider* m_provider; - // Data Layer root path - std::string _addressRoot; + // ctrlX Data Layer root path + std::string m_addressRoot; // Flag: True branch is dynamic (can be changed by clients) - bool _dynamic; + bool m_dynamic; // Root path combined with 'static' or 'dynamic' - std::string _addressBase; + std::string m_addressBase; //metadata for the providerNode - comm::datalayer::Variant _metadata; + comm::datalayer::Variant m_metadata; // Search an existing DataContainer instance for this address DataContainer* getDataContainer(const std::string& address); @@ -87,53 +69,44 @@ class ProviderNodeAllData : public comm::datalayer::IProviderNode // Constructor ProviderNodeAllData(comm::datalayer::IProvider* provider, const std::string& addressRoot, bool dynamic); - // Create virtual nodes and register them in the Data Layer - void RegisterNodes(); + virtual ~ProviderNodeAllData() = default; + // Create virtual nodes and register them in the ctrlX Data Layer + void registerNodes(); - // Will be called by the Data Layer broker whenever a sub node should be created. + // Will be called by the ctrlX Data Layer broker whenever a sub node should be created. virtual void onCreate( const std::string& address, const comm::datalayer::Variant* data, const comm::datalayer::IProviderNode::ResponseCallback& callback); - // Will be called by the Data Layer broker whenever a sub node should be read. + // Will be called by the ctrlX Data Layer broker whenever a sub node should be read. virtual void onRead( const std::string& address, const comm::datalayer::Variant* data, const comm::datalayer::IProviderNode::ResponseCallback& callback); - // Will be called by the Data Layer broker whenever a sub node should be written. + // Will be called by the ctrlX Data Layer broker whenever a sub node should be written. virtual void onWrite( const std::string& address, const comm::datalayer::Variant* data, const comm::datalayer::IProviderNode::ResponseCallback& callback); - // Will be called by the Data Layer broker whenever a sub node should be removed. + // Will be called by the ctrlX Data Layer broker whenever a sub node should be removed. virtual void onRemove( const std::string& address, const comm::datalayer::IProviderNode::ResponseCallback& callback); - // Will be called by the Data Layer broker to list sub nodes. + // Will be called by the ctrlX Data Layer broker to list sub nodes. // The returned list is merged with the list of nodes known by the broker himself. // So normally we return nothing. virtual void onBrowse( const std::string& address, const comm::datalayer::IProviderNode::ResponseCallback& callback); - // Will be called by the Data Layer broker when he needs the properties (meta data) of the node. + // Will be called by the ctrlX Data Layer broker when he needs the properties (meta data) of the node. virtual void onMetadata( const std::string& address, const comm::datalayer::IProviderNode::ResponseCallback& callback); }; -static const char* snap_path() -{ - return std::getenv("SNAP"); -} - -static bool is_snap() -{ - return snap_path() != nullptr; -} - #endif diff --git a/samples-cpp/datalayer.provider.all-data/snap/snapcraft.yaml b/samples-cpp/datalayer.provider.all-data/snap/snapcraft.yaml index 3b2b1f413..b5995de1a 100644 --- a/samples-cpp/datalayer.provider.all-data/snap/snapcraft.yaml +++ b/samples-cpp/datalayer.provider.all-data/snap/snapcraft.yaml @@ -6,14 +6,14 @@ name: sdk-cpp-alldata version: "2.2.0" grade: stable -summary: SDK sample app in cpp - provides Data Layer nodes with different data types +summary: provides ctrlX Data Layer nodes with different data types description: | - This app provides two Data Layer branches, each branch initialy has nodes with all simple data types and one flatbuffers type. + This app provides two ctrlX Data Layer branches, each branch initialy has nodes with all simple data types and one flatbuffers type. The 'static' branch allows only read access. The 'dynamic' branch allows read and write access of each node. Furthermore nodes can be added. title: sdk-cpp-alldata -base: core20 +base: core22 confinement: strict # define how apps & services are exposed to host system diff --git a/samples-cpp/datalayer.realtime/.vscode/launch.json b/samples-cpp/datalayer.realtime/.vscode/launch.json index 172b6b27b..b7c1e7ac7 100644 --- a/samples-cpp/datalayer.realtime/.vscode/launch.json +++ b/samples-cpp/datalayer.realtime/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "Owner - Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/datalayerRealtimeOwner", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerRealtimeOwner", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,8 +23,8 @@ }, { "description": "Set path variable to .", - //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu20-gcc-x64/debug/usr/lib/", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu22-gcc-x64/debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] @@ -33,9 +33,9 @@ "name": "User - Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/datalayerRealtimeUser", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerRealtimeUser", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -48,8 +48,8 @@ }, { "description": "Set path variable to .", - //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu20-gcc-x64/debug/usr/lib/", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu22-gcc-x64/debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] @@ -58,7 +58,7 @@ "name": "User - ctrlX (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-aarch64/Debug/datalayerRealtimeUser", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-aarch64/Debug/datalayerRealtimeUser", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "192.168.1.1:12345", @@ -78,7 +78,7 @@ "name": "Owner - ctrlX (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-aarch64/Debug/datalayerRealtimeOwner", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-aarch64/Debug/datalayerRealtimeOwner", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "192.168.1.1:12345", diff --git a/samples-cpp/datalayer.realtime/.vscode/tasks.json b/samples-cpp/datalayer.realtime/.vscode/tasks.json index fee057f94..5cd27e3be 100644 --- a/samples-cpp/datalayer.realtime/.vscode/tasks.json +++ b/samples-cpp/datalayer.realtime/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -145,12 +145,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -161,7 +157,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -198,12 +194,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/datalayer.realtime/CMakeLists.txt b/samples-cpp/datalayer.realtime/CMakeLists.txt index e78de670f..0a719ba25 100644 --- a/samples-cpp/datalayer.realtime/CMakeLists.txt +++ b/samples-cpp/datalayer.realtime/CMakeLists.txt @@ -46,12 +46,12 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DMY_DEBUG") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET(PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET(PLATFORM_NAME "ubuntu22-gcc-aarch64") SET(SNAP_ARCH "arm64") SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET(PLATFORM_NAME "ubuntu20-gcc-x64") + SET(PLATFORM_NAME "ubuntu22-gcc-x64") SET(SNAP_ARCH "amd64") SET(CMAKE_C_COMPILER gcc) SET(CMAKE_CXX_COMPILER g++) diff --git a/samples-cpp/datalayer.realtime/LICENSE b/samples-cpp/datalayer.realtime/LICENSE deleted file mode 100644 index d1231b68e..000000000 --- a/samples-cpp/datalayer.realtime/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/datalayer.realtime/README.md b/samples-cpp/datalayer.realtime/README.md index 1f74f3ff9..ef49351d9 100644 --- a/samples-cpp/datalayer.realtime/README.md +++ b/samples-cpp/datalayer.realtime/README.md @@ -1,97 +1,79 @@ -# README datalayer.realtime - -## Introduction - -This sample project shows how shared memory is used for data exchange between two applications. Therefor the features of the ctrlX Data Layer are used. - -Normally realtime applications (Celix bundles) are using this kind of data exchange, but non realtime apps are also able to use it - like our two apps. - -!!! important - Apps using shared memory for data exchange have to run within the same environment (ctrlX CORE or App Builder Environment). - -## Function Description - -* An owner app provides two shared memory areas. -* From the perspective of the user app their names are 'input' and 'output'. -* The data of the output area is preset by the owner app with 0. -* As soon as the user app has access to the input area, it reads the data, increments the values and writes them to the output area. -* If the output area was written the owner app copies the changed values to the input area. -* Then again the user reads and increases them. -* When the numerical value has reached 225, the user app sets it back to 1. - -__If the input values are 0 this indicates that the user had no access - this is an error situation.__ - - -## Implementation - -__main_owner.cpp__ implements the owner app and __main_user.cpp__ the user app. - -### main_owner.cpp - -If the app is running in the App Builder Environment it has to start the Data Layer system with the parameter `boStartBroker=true`. -In this case the Data Layer broker which handles the shared memory features is started also within the App Builder Environment. - -Running on the ctrlX CORE the owner has to start the Data Layer system with the parameter `boStartBroker=false` because the Data Layer broker has already been started by the rexroth-automationcore snap. - -Because shared memory is used, the Data Layer (and it's broker) must run on the same environment. Accordingly, the provider connection string must always be __DL_IPC__ (ipc://). - -After connecting to the Data Layer shared memories for input and output are created and both fitted with the same memory map. The memory map is internally a Flatbuffers describing the data structure of the shared memory. - -After the values of the shared memory are set to 0 the owner apps waits in an endless loop for our user app to read and change the values. - -### main_user.cpp - -* The user app starts the Data Layer system always with `boStartBroker=false`. For the access of shared memory provided by an other process the user app does not require a Data Layer client connection. - -* The user tries to read the memory map of the input area. This is done in a loop until it succeeds. - -* In an endless loop all values of the input area are read, incremented and written to the output area. - -* The value is changed from 255 to 1 - 0 is skipped. - -## Build and Install the Snap - -Build and install the snap like described [here](../README.md). - -To use shared memory in the restricted snap environment of the ctrlX CORE our snap has to be connected to the datalayer-shm slot provided by the snp rexroth-automation-core snap. - -Unfortunately for unsigned snaps this is not done automatically during the ctrlX snap installation. - -As a workaround this has to be done manually. Therefor open a ssh connection to the ctrlX and enter: - - sudo snap connect sdk-cpp-realtime:datalayer-shm rexroth-automationcore:datalayer-shm - -## Test the Snap - -* Open the web interface of your ctrlX CORE -* Select Settings --> Data Layer -* Select the node sdk-cpp-realtime/rt/input/data -* __The values in the byte array should be changed - AND NEVER be 0. This can be used by a test criterion.__ - -![ctrlX datalayer realtime data](docs/images/datalayer.realtime.png) - -___ - -## License - -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README datalayer.realtime + +## Introduction + +This sample project shows how shared memory is used for data exchange between two applications. Therefor the features of the ctrlX Data Layer are used. + +Normally realtime applications (Celix bundles) are using this kind of data exchange, but non realtime apps are also able to use it - like our two apps. + +!!! important + Apps using shared memory for data exchange have to run within the same environment (ctrlX CORE or App Builder Environment). + +## Function Description + +* An owner app provides two shared memory areas. +* From the perspective of the user app their names are 'input' and 'output'. +* The data of the output area is preset by the owner app with 0. +* As soon as the user app has access to the input area, it reads the data, increments the values and writes them to the output area. +* If the output area was written the owner app copies the changed values to the input area. +* Then again the user reads and increases them. +* When the numerical value has reached 225, the user app sets it back to 1. + +__If the input values are 0 this indicates that the user had no access - this is an error situation.__ + + +## Implementation + +__main_owner.cpp__ implements the owner app and __main_user.cpp__ the user app. + +### main_owner.cpp + +If the app is running in the App Builder Environment it has to start the ctrlX Data Layer system with the parameter `boStartBroker=true`. +In this case the ctrlX Data Layer broker which handles the shared memory features is started also within the App Builder Environment. + +Running on the ctrlX CORE the owner has to start the ctrlX Data Layer system with the parameter `boStartBroker=false` because the ctrlX Data Layer broker has already been started by the rexroth-automationcore snap. + +Because shared memory is used, the ctrlX Data Layer (and it's broker) must run on the same environment. Accordingly, the provider connection string must always be __DL_IPC__ (ipc://). + +After connecting to the ctrlX Data Layer shared memories for input and output are created and both fitted with the same memory map. The memory map is internally a Flatbuffers describing the data structure of the shared memory. + +After the values of the shared memory are set to 0 the owner apps waits in an endless loop for our user app to read and change the values. + +### main_user.cpp + +* The user app starts the ctrlX Data Layer system always with `boStartBroker=false`. For the access of shared memory provided by an other process the user app does not require a ctrlX Data Layer client connection. + +* The user tries to read the memory map of the input area. This is done in a loop until it succeeds. + +* In an endless loop all values of the input area are read, incremented and written to the output area. + +* The value is changed from 255 to 1 - 0 is skipped. + +## Build and Install the Snap + +Build and install the snap like described [here](../README.md). + +To use shared memory in the restricted snap environment of the ctrlX CORE our snap has to be connected to the datalayer-shm slot provided by the snp rexroth-automation-core snap. + +Unfortunately for unsigned snaps this is not done automatically during the ctrlX snap installation. + +As a workaround this has to be done manually. Therefor open a ssh connection to the ctrlX and enter: + + sudo snap connect sdk-cpp-realtime:datalayer-shm rexroth-automationcore:datalayer-shm + +## Test the Snap + +* Open the web interface of your ctrlX CORE +* Select Settings --> ctrlX Data Layer +* Select the node sdk-cpp-realtime/rt/input/data +* __The values in the byte array should be changed - AND NEVER be 0. This can be used by a test criterion.__ + +![ctrlX datalayer realtime data](docs/images/datalayer.realtime.png) + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT + diff --git a/samples-cpp/datalayer.realtime/build-snap-amd64.sh b/samples-cpp/datalayer.realtime/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/datalayer.realtime/build-snap-amd64.sh +++ b/samples-cpp/datalayer.realtime/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.realtime/build-snap-arm64.sh b/samples-cpp/datalayer.realtime/build-snap-arm64.sh index c49100336..f4fd03bbe 100644 --- a/samples-cpp/datalayer.realtime/build-snap-arm64.sh +++ b/samples-cpp/datalayer.realtime/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/datalayer.realtime/main_owner.cpp b/samples-cpp/datalayer.realtime/main_owner.cpp index 66b72d27c..4850b4f2f 100644 --- a/samples-cpp/datalayer.realtime/main_owner.cpp +++ b/samples-cpp/datalayer.realtime/main_owner.cpp @@ -1,48 +1,31 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2020-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #include "comm/datalayer/datalayer.h" #include "comm/datalayer/datalayer_system.h" #include "comm/datalayer/memory_map_generated.h" #include -#include +#include #include #include #define MEM_SIZE (100) -// Revision should be unique for this Layout, if you need a new memory layout define a new revision, or use checksum algorithms + // Revision should be unique for this Layout, if you need a new memory layout define a new revision, or use checksum algorithms #define REVISION (0) // Create end process flag witch is set to true if SIGINT is send -bool endProcess = false; -static void hdl(int sig, siginfo_t* siginfo, void* context) +static bool g_endProcess = false; +static void signalHandler(int signal) { - endProcess = true; + std::cout << "signal: " << signal << std::endl; + g_endProcess = true; } -void deleteOwnerMemory(comm::datalayer::DatalayerSystem* datalayer, - std::shared_ptr ownerMemory) +static void deleteOwnerMemory(comm::datalayer::DatalayerSystem* datalayer, + std::shared_ptr ownerMemory) { if (ownerMemory == nullptr) { @@ -58,10 +41,10 @@ void deleteOwnerMemory(comm::datalayer::DatalayerSystem* datalayer, } // Cleanup closes the memory and stop the datalayersystem -void cleanup(comm::datalayer::DatalayerSystem* datalayer, - comm::datalayer::IProvider* provider, - std::shared_ptr input, - std::shared_ptr output) +static void cleanup(comm::datalayer::DatalayerSystem* datalayer, + comm::datalayer::IProvider* provider, + std::shared_ptr input, + std::shared_ptr output) { deleteOwnerMemory(datalayer, input); deleteOwnerMemory(datalayer, output); @@ -75,7 +58,7 @@ void cleanup(comm::datalayer::DatalayerSystem* datalayer, datalayer->stop(); } -comm::datalayer::Variant createMemMap(size_t size, uint32_t revision) +static comm::datalayer::Variant createMemMap(size_t size, uint32_t revision) { // A memory map defines the layout of memory // Memory Map contains: @@ -123,22 +106,21 @@ static bool isSnap() return std::getenv("SNAP") != nullptr; } -int main(int ac, char* av[]) +int main(void) { comm::datalayer::DlResult result; - comm::datalayer::Variant data; comm::datalayer::DatalayerSystem datalayer; if (isSnap()) { // Running on ctrlX CORE: Start datalayer without a broker - a broker already exists in rexroth-automationcore snap - std::cout << "INFO Using existing Data Layer." << std::endl; + std::cout << "INFO Using existing ctrlX Data Layer." << std::endl; datalayer.start(false); } else { // Running in App Builder Env: Start datalayer WITH a broker - we need him for exchange of data via shared memory - std::cout << "INFO Starting own Data Layer." << std::endl; + std::cout << "INFO Starting own ctrlX Data Layer." << std::endl; datalayer.start(true); } @@ -147,7 +129,7 @@ int main(int ac, char* av[]) comm::datalayer::IProvider* provider = datalayer.factory()->createProvider(DL_IPC); if (provider == nullptr) { - std::cout << "ERROR Creating Data Layer provider connection." << std::endl; + std::cout << "ERROR Creating ctrlX Data Layer provider connection." << std::endl; cleanup(&datalayer, nullptr, nullptr, nullptr); return 1; } @@ -229,11 +211,7 @@ int main(int ac, char* av[]) input->endAccess(); // Structure to interrupt the do while loop with SIGINT ---------------------------------- - struct sigaction act; - memset(&act, '\0', sizeof(act)); - act.sa_sigaction = &hdl; - act.sa_flags = SA_SIGINFO; - sigaction(SIGINT, &act, NULL); + std::signal(SIGINT, signalHandler); std::cout << "INFO Start copy output to input" << std::endl; do @@ -267,7 +245,7 @@ int main(int ac, char* av[]) input->endAccess(); output->endAccess(); - } while (!endProcess); + } while (!g_endProcess); cleanup(&datalayer, provider, input, output); diff --git a/samples-cpp/datalayer.realtime/main_user.cpp b/samples-cpp/datalayer.realtime/main_user.cpp index ab7a5bb55..57fcbc876 100644 --- a/samples-cpp/datalayer.realtime/main_user.cpp +++ b/samples-cpp/datalayer.realtime/main_user.cpp @@ -1,44 +1,27 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2020-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #include "comm/datalayer/datalayer.h" #include "comm/datalayer/datalayer_system.h" #include "comm/datalayer/memory_map_generated.h" #include -#include +#include #include #include // Create end process flag witch is set to true if SIGINT is send -bool endProcess = false; -static void hdl(int sig, siginfo_t* siginfo, void* context) +static bool g_endProcess = false; +static void signalHandler(int signal) { - endProcess = true; + std::cout << "signal: " << signal << std::endl; + g_endProcess = true; } -void closeUserMemory(comm::datalayer::DatalayerSystem* datalayer, - std::shared_ptr userMemory) +static void closeUserMemory(comm::datalayer::DatalayerSystem* datalayer, + std::shared_ptr userMemory) { if (userMemory == nullptr) { @@ -54,9 +37,9 @@ void closeUserMemory(comm::datalayer::DatalayerSystem* datalayer, } } // Cleanup closes the memory and stop the datalayersystem -void cleanup(comm::datalayer::DatalayerSystem* datalayer, - std::shared_ptr input, - std::shared_ptr output) +static void cleanup(comm::datalayer::DatalayerSystem* datalayer, + std::shared_ptr input, + std::shared_ptr output) { closeUserMemory(datalayer, input); closeUserMemory(datalayer, output); @@ -64,7 +47,7 @@ void cleanup(comm::datalayer::DatalayerSystem* datalayer, datalayer->stop(); } -int main(int ac, char* av[]) +int main() { comm::datalayer::DlResult result; comm::datalayer::Variant data; @@ -72,7 +55,7 @@ int main(int ac, char* av[]) uint8_t* inData; uint8_t* outData; - // A realtime memory user always starts the Data Layer WITHOUT a broker: + // A realtime memory user always starts the ctrlX Data Layer WITHOUT a broker: // On the ctrlX the rexroth-automationcore snap has started the broker, // in an App Builder Env the realtime memory owner has started it. datalayer.start(false); @@ -98,11 +81,7 @@ int main(int ac, char* av[]) } // Structure to interrupt the do while loops with SIGINT - struct sigaction act; - memset(&act, '\0', sizeof(act)); - act.sa_sigaction = &hdl; - act.sa_flags = SA_SIGINFO; - sigaction(SIGINT, &act, NULL); + std::signal(SIGINT, signalHandler); while (true) { @@ -117,7 +96,7 @@ int main(int ac, char* av[]) std::this_thread::sleep_for(std::chrono::seconds(1)); - if (endProcess) + if (g_endProcess) { cleanup(&datalayer, input, output); return 0; @@ -173,7 +152,7 @@ int main(int ac, char* av[]) input->endAccess(); output->endAccess(); - } while (!endProcess); + } while (!g_endProcess); cleanup(&datalayer, input, output); diff --git a/samples-cpp/datalayer.realtime/snap/snapcraft.yaml b/samples-cpp/datalayer.realtime/snap/snapcraft.yaml index bc791f815..ded553470 100644 --- a/samples-cpp/datalayer.realtime/snap/snapcraft.yaml +++ b/samples-cpp/datalayer.realtime/snap/snapcraft.yaml @@ -12,7 +12,7 @@ description: | - a data provider - mem owner - creates some memory 'input' and 'output' - a data consumer - mem user - can read 'input' and write 'output' When the user has written outputs once, the owner will start copying from output to input. -base: core20 +base: core22 confinement: strict # define how apps & services are exposed to host system diff --git a/samples-cpp/datalayer.register.node/.vscode/launch.json b/samples-cpp/datalayer.register.node/.vscode/launch.json index e7647c88d..226d7ad74 100644 --- a/samples-cpp/datalayer.register.node/.vscode/launch.json +++ b/samples-cpp/datalayer.register.node/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/registerNode", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/registerNode", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,7 +23,7 @@ }, { "description": "Set path variable to .", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] @@ -32,7 +32,7 @@ "name": "aarch64 ctrlX (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-aarch64/Debug/registerNode", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-aarch64/Debug/registerNode", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "192.168.1.1:12345", @@ -52,7 +52,7 @@ "name": "x64 ctrlX virt. Network Adapter (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/registerNode", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/registerNode", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "192.168.1.1:12345", @@ -66,13 +66,21 @@ "text": "-enable-pretty-printing", "ignoreFailures": true }, + { + "description": "Do not stop on SIGSTOP", + "text": "handle SIGSTOP nostop" + }, + { + "description": "Do not print a message on SIGSTOP", + "text": "handle SIGSTOP noprint" + } ] }, { "name": "x64 ctrlX virt. Port Forwarding (remote)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/registerNode", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/registerNode", "cwd": "${workspaceFolder}", "miDebuggerPath": "/usr/bin/gdb-multiarch", "miDebuggerServerAddress": "10.0.2.2:12345", @@ -86,6 +94,14 @@ "text": "-enable-pretty-printing", "ignoreFailures": true }, + { + "description": "Do not stop on SIGSTOP", + "text": "handle SIGSTOP nostop" + }, + { + "description": "Do not print a message on SIGSTOP", + "text": "handle SIGSTOP noprint" + } ] } ] diff --git a/samples-cpp/datalayer.register.node/.vscode/settings.json b/samples-cpp/datalayer.register.node/.vscode/settings.json index e405fbedd..9c0a9da4b 100644 --- a/samples-cpp/datalayer.register.node/.vscode/settings.json +++ b/samples-cpp/datalayer.register.node/.vscode/settings.json @@ -3,6 +3,8 @@ "cmake.configureArgs": [ "-DCMAKE_BUILD_KIT=${buildKit}" ], - "cmake.configureOnOpen": false - + "cmake.configureOnOpen": false, + "files.associations": { + "ostream": "cpp" + } } \ No newline at end of file diff --git a/samples-cpp/datalayer.register.node/.vscode/tasks.json b/samples-cpp/datalayer.register.node/.vscode/tasks.json index 99893f7de..7b98dc889 100644 --- a/samples-cpp/datalayer.register.node/.vscode/tasks.json +++ b/samples-cpp/datalayer.register.node/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,14 +100,14 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { "label": "Launch Remote GDB Server", "type": "shell", "problemMatcher": "$gcc", - "command": "ssh ${input:SSHUser}@${input:IPAddress} \"sudo snap run --experimental-gdbserver=:12345 registernode.registerNode\" ", + "command": "sshpass -p rexroot ssh ${input:SSHUser}@${input:IPAddress} \"snap run --experimental-gdbserver=:12345 sdk-cpp-registernode.registerNode\" ", }, ], "inputs": [ @@ -139,12 +139,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -155,7 +151,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -192,12 +188,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/datalayer.register.node/CMakeLists.txt b/samples-cpp/datalayer.register.node/CMakeLists.txt index 97fb1effb..04ae227ea 100644 --- a/samples-cpp/datalayer.register.node/CMakeLists.txt +++ b/samples-cpp/datalayer.register.node/CMakeLists.txt @@ -31,7 +31,7 @@ build_mddb(registernodemddb "${MDDB_FILES}" ${CMAKE_CURRENT_LIST_DIR}/compiled " # # Option to Build the Snap # -option (BUILD_SNAP "Build Snap Package" OFF) +option (BUILD_SNAP "Build Snap Package" OFF) MESSAGE( STATUS "Selected BuildKit: ${CMAKE_BUILD_KIT}") MESSAGE( STATUS "######################################") @@ -52,12 +52,12 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DMY_DEBUG") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET(PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET(PLATFORM_NAME "ubuntu22-gcc-aarch64") SET(SNAP_ARCH "arm64") SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET(PLATFORM_NAME "ubuntu20-gcc-x64") + SET(PLATFORM_NAME "ubuntu22-gcc-x64") SET(SNAP_ARCH "amd64") SET(CMAKE_C_COMPILER gcc) SET(CMAKE_CXX_COMPILER g++) @@ -78,7 +78,6 @@ SET ( PRIVATE_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/include ${USER_DEPENDENCY_DIR}/include - ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers.1.12 ${USER_DEPENDENCY_DIR}/include/comm.datalayer ) @@ -87,12 +86,12 @@ SET ( PRIVATE_INCLUDE_DIRS # execute_process(COMMAND uname -a OUTPUT_VARIABLE HOST_SYSTEM_ARCH) IF( ${HOST_SYSTEM_ARCH} MATCHES "aarch64") - set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers.1.12/ubuntu20-gcc-aarch64/release/flatc) + set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers/ubuntu22-gcc-aarch64/release/flatc) ELSE() - set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers.1.12/ubuntu20-gcc-x64/release/flatc) + set (FLATBUFFERS_FLATC_EXECUTABLE ${USER_DEPENDENCY_DIR}/bin/oss.flatbuffers/ubuntu22-gcc-x64/release/flatc) ENDIF() -set (FLATBUFFERS_INCLUDE_DIR ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers.1.12) -include (${USER_DEPENDENCY_DIR}/cmake/oss.flatbuffers.1.12/FindFlatBuffers.cmake) +set (FLATBUFFERS_INCLUDE_DIR ${USER_DEPENDENCY_DIR}/include/oss.flatbuffers) +include (${USER_DEPENDENCY_DIR}/cmake/oss.flatbuffers/FindFlatBuffers.cmake) set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--gen-object-api") set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--no-warnings") set( FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS "--gen-compare") diff --git a/samples-cpp/datalayer.register.node/LICENSE b/samples-cpp/datalayer.register.node/LICENSE deleted file mode 100644 index d1231b68e..000000000 --- a/samples-cpp/datalayer.register.node/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/datalayer.register.node/README.md b/samples-cpp/datalayer.register.node/README.md index cd32dd82c..4a55c2b84 100644 --- a/samples-cpp/datalayer.register.node/README.md +++ b/samples-cpp/datalayer.register.node/README.md @@ -1,65 +1,46 @@ -# README datalayer.register.node - -## Introduction - -The sample app __datalayer.register.node__ creates a new Data Layer folder '__sdk-cpp-registernode__' with nodes of different datatypes. - -## Functional Description - -It demonstrates how you can create Data Layer nodes with different data types. -These nodes can be accessed by a Data Layer client app e.g. ctrlX-Node-RED. -The metadata of the nodes are provides by a metadata database. - -## Implementation Description - -All actions are implemented in main.cpp: - -* Start Data Layer system -* Connect as Data Layer provider -* Register a flatbuffers schema -* Register metadata database -* Register several Data Layer nodes -* Endless loop where the Data Layer connection is observed -* Shutdown if the Data Layer connection is broken - - -!!! important - If the app is running as snap on a ctrlX CORE it will be restarted if it has exited on error. - -## Build and Install the Snap - -Build and install the snap like described [here](../README.md). - -## Test the Snap - -* Open the web interface of your ctrlX CORE -* Check output in the web interface - -![Output in diagnosis logbook](docs/images/datalayer.register.node/messages.in.logbook.png) -![Data Layer tree](docs/images/datalayer.register.node/datalayer.register.node.png) - -___ - -## License - -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README datalayer.register.node + +## Introduction + +The sample app __datalayer.register.node__ creates a new ctrlX Data Layer folder '__sdk-cpp-registernode__' with nodes of different datatypes. + +## Functional Description + +It demonstrates how you can create ctrlX Data Layer nodes with different data types. +These nodes can be accessed by a ctrlX Data Layer client app e.g. ctrlX-Node-RED. +The metadata of the nodes are provides by a metadata database. + +## Implementation Description + +All actions are implemented in main.cpp: + +* Start ctrlX Data Layer system +* Connect as ctrlX Data Layer provider +* Register a flatbuffers schema +* Register metadata database +* Register several ctrlX Data Layer nodes +* Endless loop where the ctrlX Data Layer connection is observed +* Shutdown if the ctrlX Data Layer connection is broken + + +!!! important + If the app is running as snap on a ctrlX CORE it will be restarted if it has exited on error. + +## Build and Install the Snap + +Build and install the snap like described [here](../README.md). + +## Test the Snap + +* Open the web interface of your ctrlX CORE +* Check output in the web interface + +![Output in diagnosis logbook](docs/images/datalayer.register.node/messages.in.logbook.png) +![ctrlX Data Layer tree](docs/images/datalayer.register.node/datalayer.register.node.png) + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/datalayer.register.node/build-snap-amd64.sh b/samples-cpp/datalayer.register.node/build-snap-amd64.sh index 0952a4b6d..dd60d2729 100644 --- a/samples-cpp/datalayer.register.node/build-snap-amd64.sh +++ b/samples-cpp/datalayer.register.node/build-snap-amd64.sh @@ -1,10 +1,12 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ mkdir build/ pushd build cmake -DCMAKE_BUILD_KIT='GCC x86_64-linux-gnu' -DBUILD_SNAP=ON .. +#cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_KIT='GCC x86_64-linux-gnu' -DBUILD_SNAP=ON .. make install make clean popd \ No newline at end of file diff --git a/samples-cpp/datalayer.register.node/build-snap-arm64.sh b/samples-cpp/datalayer.register.node/build-snap-arm64.sh index f48f8a433..39d73d92e 100644 --- a/samples-cpp/datalayer.register.node/build-snap-arm64.sh +++ b/samples-cpp/datalayer.register.node/build-snap-arm64.sh @@ -1,10 +1,12 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ mkdir build/ pushd build cmake -DCMAKE_BUILD_KIT='GCC aarch64-linux-gnu' -DBUILD_SNAP=ON .. +#cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_KIT='GCC aarch64-linux-gnu' -DBUILD_SNAP=ON .. make install make clean popd \ No newline at end of file diff --git a/samples-cpp/datalayer.register.node/cmake-apps-command.sh b/samples-cpp/datalayer.register.node/cmake-apps-command.sh deleted file mode 100644 index c579d8bd3..000000000 --- a/samples-cpp/datalayer.register.node/cmake-apps-command.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash - -mddb_compiler -in metadata.csv -out metadata.mddb - -ARCH=x86_64 -CONFIG=Debug - -for arg in "$@" -do - if grep -q "ar" <<<${arg}; then - ARCH=aarch64 - fi - - if grep -q "re" <<<${arg}; then - CONFIG=Release - fi - - if grep -q "help" <<<${arg}; then - echo "Build (one) executable of a cpp project" - echo "Parameters:" - echo " CPU Architecture: amd64 (default) | arm64 | aarch64" - echo " Configuration: debug (default) | release" - echo " Search pattern in snap/snapcraft: command (default) | source" - echo " Help (this info): help" - exit 1 - fi - -done - -# The name of the (first) executable (here e.g. xxx) will be read from snap/snapcraft.yaml -# -# apps: -# xxx: -# command: xxx -# -# Result of grep is: ' command: xxx' -# Result of cut is: ' xxx' -# Result of xargs is: 'xxx' -EXE=$(grep command: snap/snapcraft.yaml | cut -d':' -f2 | xargs) - -if test -z "${EXE}" -then - echo "ERROR: snap/snapcraft.yaml doesn't contain 'apps: ... command:'" - echo ${EXE} - exit 1 -fi - -echo ------------------------------------------------------------------- -echo Architecture: ${ARCH} -echo Configuration: ${CONFIG} -echo Executable: ${EXE} -echo ------------------------------------------------------------------- - -rm -rf generated/ - -cmake --no-warn-unused-cli \ - -DCMAKE_BUILD_KIT=${ARCH} \ - -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \ - -DCMAKE_BUILD_TYPE:STRING=${CONFIG} \ - -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/${ARCH}-linux-gnu-gcc-9 \ - -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/${ARCH}-linux-gnu-g++-9 \ - -H/$(pwd) \ - -B/$(pwd)/build \ - -G "Unix Makefiles" - -cd $(pwd)/build -cmake --build . --config ${CONFIG} --target ${EXE} -j 6 -- \ No newline at end of file diff --git a/samples-cpp/datalayer.register.node/ctrlx_datalayer_helper.h b/samples-cpp/datalayer.register.node/ctrlx_datalayer_helper.h index 3fdec3b7d..f4e02fab6 100644 --- a/samples-cpp/datalayer.register.node/ctrlx_datalayer_helper.h +++ b/samples-cpp/datalayer.register.node/ctrlx_datalayer_helper.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef CTRLX_DATALAYER_HELPER_H @@ -43,17 +25,17 @@ * If these values do not suit your use case, explicitly pass the parameters that require different values. * Here some examples: * - * 1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: + * 1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: * * client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") * - * 2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): + * 2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): * * client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) * * Remarks: * 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual * * * IMPORTANT: @@ -84,10 +66,10 @@ static bool isSnap() } //! Get Datalayer connection string -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result Connection string static std::string getConnectionString( const std::string& ip = "192.168.1.1", @@ -97,6 +79,7 @@ static std::string getConnectionString( { if (isSnap()) { + std::cout << "INFO Is snap" << std::endl; return DL_IPC; } @@ -112,10 +95,10 @@ static std::string getConnectionString( //! Get Datalayer Client instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IClient instance or nullptr on error static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", @@ -136,10 +119,10 @@ static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& dat //! Get Datalayer Provider instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IProvider instance or nullptr on error static comm::datalayer::IProvider* getProvider(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", diff --git a/samples-cpp/datalayer.register.node/main.cpp b/samples-cpp/datalayer.register.node/main.cpp index 1d2c88b95..d57a6945a 100644 --- a/samples-cpp/datalayer.register.node/main.cpp +++ b/samples-cpp/datalayer.register.node/main.cpp @@ -1,33 +1,15 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2020-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ -// The example app datalayer.register.node creates a new provider -// with node 'sdk-cpp-registernode' and different type elements to the ctrlX Data Layer. + // The example app datalayer.register.node creates a new provider + // with node 'sdk-cpp-registernode' and different type elements to the ctrlX Data Layer. #include #include -#include +#include #include #include "comm/datalayer/datalayer.h" @@ -39,20 +21,21 @@ #include "sampleSchema_generated.h" // Add some signal Handling so we are able to abort the program with sending sigint -bool endProcess = false; +static bool g_endProcess = false; -static void sigHandler(int sig, siginfo_t *siginfo, void *context) +static void signalHandler(int signal) { - endProcess = true; + std::cout << "signal: " << signal << std::endl; + g_endProcess = true; } using comm::datalayer::IProviderNode; // Basic class Provider node interface for providing data to the system -class MyProviderNode : public IProviderNode +class MyProviderNode: public IProviderNode { private: - comm::datalayer::Variant _data; + comm::datalayer::Variant m_data; /* Keep this comment section - it can be used as a sample for creating metadata programmatically. @@ -65,7 +48,7 @@ class MyProviderNode : public IProviderNode auto emptyString = builder.CreateString("This is a Description"); - auto isFlatbuffers = _data.getType() == comm::datalayer::VariantType::FLATBUFFERS; + auto isFlatbuffers = m_data.getType() == comm::datalayer::VariantType::FLATBUFFERS; if (isFlatbuffers) { flatbuffers::Offset vecReferences[] = @@ -104,53 +87,53 @@ class MyProviderNode : public IProviderNode public: MyProviderNode(comm::datalayer::Variant data) - { - _data = data; - //createMetadata(); - }; + : m_data(data) + {}; - virtual ~MyProviderNode() override{}; + virtual ~MyProviderNode() override {}; // Create function of an object. Function will be called whenever a object should be created. - virtual void onCreate(const std::string &address, const comm::datalayer::Variant *data, const comm::datalayer::IProviderNode::ResponseCallback &callback) override + virtual void onCreate(const std::string& address, const comm::datalayer::Variant* data, const comm::datalayer::IProviderNode::ResponseCallback& callback) override { callback(comm::datalayer::DlResult::DL_FAILED, nullptr); } // Read function of a node. Function will be called whenever a node should be read. - virtual void onRead(const std::string &address, const comm::datalayer::Variant *data, const comm::datalayer::IProviderNode::ResponseCallback &callback) override + virtual void onRead(const std::string& address, const comm::datalayer::Variant* data, const comm::datalayer::IProviderNode::ResponseCallback& callback) override { comm::datalayer::Variant dataRead; - dataRead = _data; + dataRead = m_data; callback(comm::datalayer::DlResult::DL_OK, &dataRead); } // Write function of a node. Function will be called whenever a node should be written. - virtual void onWrite(const std::string &address, const comm::datalayer::Variant *data, const comm::datalayer::IProviderNode::ResponseCallback &callback) override + virtual void onWrite(const std::string& address, const comm::datalayer::Variant* data, const comm::datalayer::IProviderNode::ResponseCallback& callback) override { - if (data->getType() != _data.getType()) + std::cout << "INFO onWrite " << address << std::endl; + + if (data->getType() != m_data.getType()) { callback(comm::datalayer::DlResult::DL_TYPE_MISMATCH, nullptr); } - _data = *data; + m_data = *data; callback(comm::datalayer::DlResult::DL_OK, data); } // Remove function for an object. Function will be called whenever a object should be removed. - virtual void onRemove(const std::string &address, const comm::datalayer::IProviderNode::ResponseCallback &callback) override + virtual void onRemove(const std::string& address, const comm::datalayer::IProviderNode::ResponseCallback& callback) override { callback(comm::datalayer::DlResult::DL_FAILED, nullptr); } // Browse function of a node. Function will be called to determine children of a node. - virtual void onBrowse(const std::string &address, const comm::datalayer::IProviderNode::ResponseCallback &callback) override + virtual void onBrowse(const std::string& address, const comm::datalayer::IProviderNode::ResponseCallback& callback) override { callback(comm::datalayer::DlResult::DL_FAILED, nullptr); } // Read function of metadata of an object. Function will be called whenever a node should be written. - virtual void onMetadata(const std::string &address, const comm::datalayer::IProviderNode::ResponseCallback &callback) override + virtual void onMetadata(const std::string& address, const comm::datalayer::IProviderNode::ResponseCallback& callback) override { // Keep this comment! Can be used as sample creating metadata programmatically. // callback(comm::datalayer::DlResult::DL_OK, &_metaData); @@ -162,25 +145,19 @@ class MyProviderNode : public IProviderNode int main() { -#ifdef MY_DEBUG - // TODO Remove block comment to enable remote debugging - // For further information about C++ remote debugging see public/doc/debug.md - /* - std::cout << "Raising SIGSTOP - waiting for attaching debugger ... " << std::endl; - raise(SIGSTOP); // Process - std::cout << "... Continue..." << std::endl; - */ -#endif comm::datalayer::DatalayerSystem datalayerSystem; - comm::datalayer::DlResult result; - // Starts the ctrlX Data Layer system without a new broker because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker because one broker is already running on ctrlX CORE datalayerSystem.start(false); std::cout << "INFO Register 'sdk-cpp-registernode' as root element with 4 nodes 'myFlatbuffer', 'myFloat', 'myString' and 'myInt64'" << std::endl; - comm::datalayer::IProvider *provider = getProvider(datalayerSystem); // ctrlX CORE (virtual) - //comm::datalayer::IProvider *provider = getProvider(datalayerSystem, "10.0.2.2", "boschrexroth", "boschrexroth", 8443); // ctrlX CORE virtual with port forwarding + comm::datalayer::IProvider* provider = getProvider(datalayerSystem); // ctrlX CORE (virtual) + if (provider == nullptr) + { + provider = getProvider(datalayerSystem, "10.0.2.2", "boschrexroth", "boschrexroth", 8443); // ctrlX COREvirtual with port forwarding + } + if (provider == nullptr) { std::cout << "ERROR Getting provider connection failed." << std::endl; @@ -192,7 +169,7 @@ int main() comm::datalayer::Variant myString; myString.setValue("Hello ctrlX AUTOMATION sample string"); std::cout << "INFO Register node 'sdk-cpp-registernode/myString' " << std::endl; - result = provider->registerNode("sdk-cpp-registernode/myString", new MyProviderNode(myString)); + comm::datalayer::DlResult result = provider->registerNode("sdk-cpp-registernode/myString", new MyProviderNode(myString)); if (STATUS_FAILED(result)) { std::cout << "WARN Register node 'sdk-cpp-registernode/myString' failed with: " << result.toString() << std::endl; @@ -220,11 +197,11 @@ int main() // Register type of flatbuffer value auto snapDir = snapPath(); - std::filesystem::path dir; - if (snapDir == nullptr) - dir = "compiled"; // Build environment: Compiled files are stored into that sub directory - else + std::filesystem::path dir = "compiled"; // Build environment: Compiled files are stored into that sub directory + if (snapDir != nullptr) + { dir = snapDir; // Snap environment: Compiled files are stored into the $SNAP directory + } std::filesystem::path fileBfbs = dir / "sampleSchema.bfbs"; @@ -256,14 +233,9 @@ int main() } // Prepare signal structure to interrupt the endless loop with ctrl + c - struct sigaction act; - memset(&act, '\0', sizeof(act)); - act.sa_sigaction = &sigHandler; - act.sa_flags = SA_SIGINFO; - sigaction(SIGINT, &act, NULL); - + std::signal(SIGINT, signalHandler); std::cout << "INFO Running endless loop - end with Ctrl+C" << std::endl; - while (endProcess == false) + while (g_endProcess == false) { if (provider->isConnected() == false) { @@ -293,5 +265,5 @@ int main() datalayerSystem.stop(false); // Attention: Doesn't return if any provider or client instance is still runnning - return endProcess ? 0 : 1; -} \ No newline at end of file + return g_endProcess ? 0 : 1; +} diff --git a/samples-cpp/datalayer.register.node/snap/snapcraft.yaml b/samples-cpp/datalayer.register.node/snap/snapcraft.yaml index 5aa1a995d..1a66558c4 100644 --- a/samples-cpp/datalayer.register.node/snap/snapcraft.yaml +++ b/samples-cpp/datalayer.register.node/snap/snapcraft.yaml @@ -6,10 +6,10 @@ name: sdk-cpp-registernode version: "2.2.0" grade: stable -summary: Sample app in cpp to register a Data Layer branch with several nodes +summary: Sample app in cpp to register a ctrlX Data Layer branch with several nodes description: | - This app will create a Data Layer branch 'sdk-cpp-registernode' with node of different data types. -base: core20 + This app will create a ctrlX Data Layer branch 'sdk-cpp-registernode' with node of different data types. +base: core22 confinement: strict # define how apps & services are exposed to host system diff --git a/samples-cpp/datalayer.simple.client/.vscode/c_cpp_properties.json b/samples-cpp/datalayer.simple.client/.vscode/c_cpp_properties.json new file mode 100644 index 000000000..7c4b8ca17 --- /dev/null +++ b/samples-cpp/datalayer.simple.client/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/../../include", + "${workspaceFolder}/../../include/comm.datalayer" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "clang-x64", + "configurationProvider": "vector-of-bool.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/samples-cpp/datalayer.simple.client/.vscode/launch.json b/samples-cpp/datalayer.simple.client/.vscode/launch.json new file mode 100644 index 000000000..4b7c5caae --- /dev/null +++ b/samples-cpp/datalayer.simple.client/.vscode/launch.json @@ -0,0 +1,66 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "1.0.0", + "configurations": [ + { + "name": "x64 Build Environment (local)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/datalayerClient", + "args": [], + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", + "stopAtEntry": true, + "cwd": "${workspaceFolder}", + "environment": [], + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set path variable to .", + //"text": "set solib-search-path ${workspaceFolder}/generated/ubuntu22-gcc-x64/debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", + "ignoreFailures": false + } + ] + }, + { + "name": "aarch64 ctrlX (remote)", + "type": "cppdbg", + "request": "launch", + "program": "~/remote-debug/datalayerClient", + "cwd": "~/remote-debug", + "sourceFileMap": { + "${workspaceFolder}": "${workspaceFolder}" + }, + "stopAtEntry": true, + //"preLaunchTask": "PrepareEnv", + "pipeTransport": { + "debuggerPath": "stdbuf -i0 -o0 -e0 /snap/rexroth-analysistools/current/bin/gdb", + "pipeProgram": "/usr/bin/ssh", + "pipeArgs": [ + "boschrexroth@192.168.1.1" + ], + "pipeCwd": "${workspaceFolder}", + }, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set path variable to .", + "text": "set env LD_LIBRARY_PATH=/home/boschrexroth/remote-debug/usr/lib/", + "ignoreFailures": false + } + ] + } + ] +} \ No newline at end of file diff --git a/samples-cpp/datalayer.simple.client/.vscode/settings.json b/samples-cpp/datalayer.simple.client/.vscode/settings.json new file mode 100644 index 000000000..d580d3099 --- /dev/null +++ b/samples-cpp/datalayer.simple.client/.vscode/settings.json @@ -0,0 +1,58 @@ +{ + "window.zoomLevel": 0, + "cmake.configureArgs": [ + "-DCMAKE_BUILD_KIT=${buildKit}" + ], + "files.associations": { + "ostream": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp" + } + +} \ No newline at end of file diff --git a/samples-cpp/datalayer.simple.client/.vscode/tasks.json b/samples-cpp/datalayer.simple.client/.vscode/tasks.json new file mode 100644 index 000000000..ac2c3f4eb --- /dev/null +++ b/samples-cpp/datalayer.simple.client/.vscode/tasks.json @@ -0,0 +1,196 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build snap amd64", + "type": "shell", + "command": "bash", + "args": [ + "build-snap-amd64.sh" + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build snap arm64", + "type": "shell", + "command": "bash", + "args": [ + "build-snap-arm64.sh" + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", + "type": "shell", + "command": "../../scripts/build-upload-log-snap.sh", + "args": [ + "-ctrlx-virt-NA" + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", + "type": "shell", + "command": "../../scripts/build-upload-log-snap.sh", + "args": [ + "-ctrlx-virt-PF" + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build upload snap - ctrlX CORE 192.168.1.1", + "type": "shell", + "command": "../../scripts/build-upload-log-snap.sh", + "args": [ + "-addr", + "192.168.1.1" + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build upload snap - ctrlX CORE", + "type": "shell", + "command": "../../scripts/build-upload-log-snap.sh", + "args": [ + "-build", + "${input:Build}", + "-upload", + "${input:Upload}", + "-logs", + "${input:Logs}", + "-svc", + "${input:Service}", + "-addr", + "${input:IPAddress}", + "-ssl-port", + "${input:SSLPort}", + "-ssl-usr", + "${input:SSLUser}", + "-ssl-pwd", + "${input:SSLPwd}", + "-arch", + "${input:Arch}", + "-ssh-port", + "${input:SSHPort}", + "-ssh-usr", + "${input:SSHUser}", + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + ], + "inputs": [ + { + "id": "Build", + "type": "pickString", + "description": "Build snap?", + "options": [ + "y", + "n" + ], + "default": "y" + }, + { + "id": "Upload", + "type": "pickString", + "description": "Upload snap?", + "options": [ + "y", + "n" + ], + "default": "y" + }, + { + "id": "IPAddress", + "type": "promptString", + "description": "IP address", + "default": "192.168.1.1" + }, + { + "id": "SSLPort", + "type": "promptString", + "description": "HTTPS (SSL) port number", + "default": "443" + }, + { + "id": "Service", + "type": "pickString", + "description": "Switch to state SERVICE before installing the snap: y/n", + "options": [ + "y", + "n" + ], + "default": "y" + }, + { + "id": "SSLUser", + "type": "promptString", + "description": "HTTPS (SSL) user name", + "default": "boschrexroth" + }, + { + "id": "SSLPwd", + "type": "promptString", + "password": true, + "description": "HTTPS (SSL) password", + "default": "boschrexroth" + }, + { + "id": "Arch", + "type": "pickString", + "description": "CPU architecture?", + "options": [ + "arm64", + "amd64" + ], + "default": "arm64" + }, + { + "id": "Logs", + "type": "pickString", + "description": "Show logs - SSH must be enabled on ctrlX: y/n", + "options": [ + "y", + "n" + ], + "default": "y" + }, + { + "id": "SSHPort", + "type": "promptString", + "description": "SSH port number", + "default": "22" + }, + { + "id": "SSHUser", + "type": "promptString", + "description": "SSH user name", + "default": "rexroot" + } + ] +} \ No newline at end of file diff --git a/samples-cpp/datalayer.simple.client/CMakeLists.txt b/samples-cpp/datalayer.simple.client/CMakeLists.txt new file mode 100644 index 000000000..ff1f855d9 --- /dev/null +++ b/samples-cpp/datalayer.simple.client/CMakeLists.txt @@ -0,0 +1,154 @@ +# +# Set CMAKE version +# +cmake_minimum_required( VERSION 3.9 ) + +# +# Project information +# Set project, VERSION should be same as snap version +# +set(VERSION 2.2.0) +project( datalayer_client_snap_project VERSION ${VERSION} ) + +# +# Set TARGET_PROJECT_NAME for each executable (same as snap "app name" =ExeName) +# +set(TARGET_PROJECT_NAME datalayerClient) + +# +# User dependency directory +# +set (USER_DEPENDENCY_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) + +# +# Option to Build the Snap +# +option (BUILD_SNAP "Build Snap Package" OFF) + +MESSAGE( STATUS "Selected BuildKit: ${CMAKE_BUILD_KIT}") +MESSAGE( STATUS "######################################") +MESSAGE( STATUS "Option: BUILD_SNAP ${BUILD_SNAP}") +MESSAGE( STATUS "######################################") + +# +# Compiler setting +# +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + +# +# set libraries dirs and includes +# +IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") + SET(PLATFORM_NAME "ubuntu22-gcc-aarch64") + SET(SNAP_ARCH "arm64") + SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) + SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) +ELSE() + SET(PLATFORM_NAME "ubuntu22-gcc-x64") + SET(SNAP_ARCH "amd64") + SET(CMAKE_C_COMPILER gcc) + SET(CMAKE_CXX_COMPILER g++) +ENDIF() + + +# +# set source files for each executable +# +set( SOURCE_FILES_DATALAYERCLIENT + ./main.cpp +) + +# +# set private include directories +# +SET ( PRIVATE_INCLUDE_DIRS + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_LIST_DIR}/include + ${USER_DEPENDENCY_DIR}/include + ${USER_DEPENDENCY_DIR}/include/comm.datalayer + ) + + + + +# +# Set link directories +# +MESSAGE( STATUS "Libraries directory: ${LIBRARY_DIR}") +link_directories( + ${LIBRARY_DIR} + ${LIBRARY_DEP_DIR} + ) + + +# +# Define Executables to add from project files and their depending source files +# +add_executable( ${TARGET_PROJECT_NAME} + ${SOURCE_FILES_DATALAYERCLIENT} + ) + +# +# Set target include directories +# +target_include_directories ( ${TARGET_PROJECT_NAME} + PUBLIC ${PUBLIC_INCLUDE_DIRS} + PUBLIC ${LIBRARY_INCLUDES} + PRIVATE ${PRIVATE_INCLUDE_DIRS} +) + +# +# Set target link libraries +# +target_link_libraries(${TARGET_PROJECT_NAME} -Wl,--no-undefined) +target_link_libraries(${TARGET_PROJECT_NAME} + libcomm_datalayer.so + pthread + systemd + zmq + ssl + crypto +) + +# +# Set destination paths for installation +# +install( TARGETS ${TARGET_PROJECT_NAME} + RUNTIME DESTINATION ${CMAKE_CURRENT_LIST_DIR}/generated/${PLATFORM_NAME}/${CMAKE_BUILD_TYPE} + LIBRARY DESTINATION ${CMAKE_CURRENT_LIST_DIR}/generated/${PLATFORM_NAME}/${CMAKE_BUILD_TYPE} + ARCHIVE DESTINATION ${CMAKE_CURRENT_LIST_DIR}/generated/${PLATFORM_NAME}/${CMAKE_BUILD_TYPE} + COMPONENT ${BUNDLE_PROJECT_NAME} +) + +if (BUILD_SNAP) + # + # Set destination paths for installation + # + install( TARGETS ${TARGET_PROJECT_NAME} + RUNTIME DESTINATION ${CMAKE_CURRENT_LIST_DIR}/generated/build + LIBRARY DESTINATION ${CMAKE_CURRENT_LIST_DIR}/generated/build + ARCHIVE DESTINATION ${CMAKE_CURRENT_LIST_DIR}/generated/build + COMPONENT ${BUNDLE_PROJECT_NAME} + ) +endif(BUILD_SNAP) + +# +# Installation of files +# +add_custom_command(TARGET ${TARGET_PROJECT_NAME} +POST_BUILD +COMMAND make install +) + +if (BUILD_SNAP) + add_custom_command( TARGET ${TARGET_PROJECT_NAME} + POST_BUILD + COMMAND snapcraft clean --destructive-mode + COMMAND snapcraft --enable-experimental-target-arch --target-arch=${SNAP_ARCH} --destructive-mode + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + ) +endif(BUILD_SNAP) diff --git a/samples-cpp/datalayer.simple.client/README.md b/samples-cpp/datalayer.simple.client/README.md new file mode 100644 index 000000000..eb8cfdf73 --- /dev/null +++ b/samples-cpp/datalayer.simple.client/README.md @@ -0,0 +1,53 @@ +# README datalayer.easy.client + +## Introduction + +The sample app reads the values of the ctrlX Data Layer nodes of a ctrlX CORE. + +## Prerequisite + +A running ctrlX WORKS App Build Environment like described [here](https://boschrexroth.github.io/ctrlx-automation-sdk/setup_qemu_ctrlx_works.html) + +## Function Description + +The app demonstrates how values of the ctrlX Data Layer nodes can be read. + +## Implementation Description + +In main.cpp the ctrlX Data Layer system is started and a client connection is established. + +Then an endless loop is running: + +* Some ctrlX Data Layer values are read and their values are printed. +* After a sleep of the loop is repeated. + +The loop ends and the main method exits when the ctrlX Data Layer client connection was broken. + +With the help of the entry 'restart-condition: always' in snapcraft.yaml the snap is automatically restarted. + +## Debug the Snap + +1. Start your ctrlX CORE +2. Make sure you can connect from your Host PC +3. Fill in your connection settings +4. Run the script build-debug.sh +5. Press F5 + +Prerequisite to debug is the VS Code extension: C/C++. + +## Build and Install the Snap + +Build and install the snap like described [here](../README.md). + +## Test the Snap running on a ctrlX CORE + +* Install the snap +* Open a SSH connection to your ctrlX CORE +* Check trace output: `sudo snap logs -f sdk-simple-client` + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/datalayer.simple.client/build-debug.sh b/samples-cpp/datalayer.simple.client/build-debug.sh new file mode 100644 index 000000000..cd1b48afc --- /dev/null +++ b/samples-cpp/datalayer.simple.client/build-debug.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +rm -rf bfbs/ +rm -rf generated/ +rm -rf build/ +mkdir build/ +pushd build +cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_KIT='GCC x86_64-linux-gnu' -DBUILD_SNAP=OFF .. +make install +#make clean +popd \ No newline at end of file diff --git a/samples-cpp/datalayer.simple.client/build-snap-amd64.sh b/samples-cpp/datalayer.simple.client/build-snap-amd64.sh new file mode 100644 index 000000000..d90725bd2 --- /dev/null +++ b/samples-cpp/datalayer.simple.client/build-snap-amd64.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -e +rm -rf bfbs/ +rm -rf generated/ +rm -rf build/ +mkdir build/ +pushd build +cmake -DCMAKE_BUILD_KIT='GCC x86_64-linux-gnu' -DBUILD_SNAP=ON .. +make install +make clean +popd \ No newline at end of file diff --git a/samples-cpp/datalayer.simple.client/build-snap-arm64.sh b/samples-cpp/datalayer.simple.client/build-snap-arm64.sh new file mode 100644 index 000000000..68cc05e73 --- /dev/null +++ b/samples-cpp/datalayer.simple.client/build-snap-arm64.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e +rm -rf bfbs/ +rm -rf generated/ +rm -rf build/ +mkdir build/ + +pushd build +cmake -DCMAKE_BUILD_KIT='GCC aarch64-linux-gnu' -DBUILD_SNAP=ON .. +make install +make clean +popd diff --git a/samples-cpp/datalayer.simple.client/main.cpp b/samples-cpp/datalayer.simple.client/main.cpp new file mode 100644 index 000000000..03ca101aa --- /dev/null +++ b/samples-cpp/datalayer.simple.client/main.cpp @@ -0,0 +1,122 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include "comm/datalayer/datalayer.h" +#include "comm/datalayer/datalayer_system.h" + + +//! Retrieve environment variable SNAP +//! @result The content of SNAP ales nullptr if not available +static const char* snapPath() +{ + return std::getenv("SNAP"); +} + +//! Test if code is runnning in snap environment +//! @result True if running snap environment +static bool isSnap() +{ + return snapPath() != nullptr; +} + +//! Get Datalayer connection string +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding +//! @param[in] user User name +//! @param[in] password The password +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 +//! @result Connection string +static std::string getConnectionString( + const std::string& ip = "192.168.1.1", + const std::string& user = "boschrexroth", + const std::string& password = "boschrexroth", + int sslPort = 443) +{ + if (isSnap()) + { + return DL_IPC; + } + + std::string connectionString = DL_TCP + user + std::string(":") + password + std::string("@") + ip; + + if (443 == sslPort) + { + return connectionString; + } + + return connectionString + std::string("?sslport=") + std::to_string(sslPort); +} + +// The enry point of the snap. +// Runs an endless loop until stopped or ctrlX Data Layer clientconnection breaks. +int main() +{ + + std::cout << "INFO Starting ctrlX Data Layer system (without broker)" << std::endl; + comm::datalayer::DatalayerSystem datalayerSystem; + datalayerSystem.start(false); + + auto connectionString = getConnectionString(); // default: ctrlX CORE or ctrlX COREvirtual with Network Adpater + std::cout << "INFO Creating ctrlX Data Layer client connection to " << connectionString << " ..." << std::endl; + auto dataLayerClient = datalayerSystem.factory()->createClient(connectionString); + + int counter = 1; + while (dataLayerClient->isConnected()) + { + std::cout << "Loop #" << counter++ << std::endl; + + //Synchronous read of a ctrlX Data Layer node with a simple data type ----------------------------------------------------------- + auto cpuUtilisationPercentAddress = "framework/metrics/system/cpu-utilisation-percent"; + comm::datalayer::Variant cpuUtilisationPercentValue; + std::cout << "INFO Reading " << cpuUtilisationPercentAddress << " synchronously..." << std::endl; + auto result = dataLayerClient->readSync(cpuUtilisationPercentAddress, &cpuUtilisationPercentValue); + if (result != DL_OK){ + std::cout <<"WARN Reading " << cpuUtilisationPercentAddress << " failed with: " << result.toString() << std::endl; + } + else + { + if (cpuUtilisationPercentValue.getType() == comm::datalayer::VariantType::FLOAT64) + { + std::cout << "INFO Value of " << cpuUtilisationPercentAddress << ": " << double(cpuUtilisationPercentValue) << " %" << std::endl; + } + else + { + std::cout << "WARN Value of " << cpuUtilisationPercentAddress << " has unexpected type: " << cpuUtilisationPercentValue.typeAsString() << std::endl; + } + } + + //Synchronous read of a ctrlX Data Layer node with a simple flatbuffers data type ----------------------------------------------------------- + auto stateAddress = "framework/state"; + comm::datalayer::Variant stateValue; + std::cout << "INFO Reading " << stateAddress << " synchronously..." << std::endl; + result = dataLayerClient->readSync(stateAddress, &stateValue); + if (result != DL_OK){ + std::cout <<"WARN Reading " << stateAddress << " failed with: " << result.toString() << std::endl; + } + else + { + auto stateTypeAddress = "types/systemhandler/state"; + comm::datalayer::Variant stateType; + result = dataLayerClient->readSync(stateTypeAddress, &stateType); + std::cout << "INFO " << stateAddress << " has type: " << stateValue.typeAsString() << std::endl; + std::string stateAsJsonString; + result = datalayerSystem.jsonConverter()->generateJson(stateValue,stateType, &stateAsJsonString); + std::cout << "INFO Value of " << stateAddress << ":" << std::endl << stateAsJsonString << std::endl; + } + + std::cout << "INFO Sleeping..." << std::endl; + sleep(2); + } + + std::cout << "ERROR ctrlX Data Layer connection is broken" << std::endl; + + delete dataLayerClient; + datalayerSystem.stop(); + + return 1; // We exit because an error happend +} diff --git a/samples-cpp/datalayer.simple.client/snap/snapcraft.yaml b/samples-cpp/datalayer.simple.client/snap/snapcraft.yaml new file mode 100644 index 000000000..489e919e4 --- /dev/null +++ b/samples-cpp/datalayer.simple.client/snap/snapcraft.yaml @@ -0,0 +1,41 @@ +# Getting started +# See https://snapcraft.io/docs/getting-started +# Snapcraft references +# See https://snapcraft.io/docs/snapcraft-yaml-reference + +name: sdk-simple-client +version: "2.2.0" +grade: stable +summary: Sample app for datalayer client +description: | + This app will read ctrlX Data Layer nodes and print out their value. +base: core22 +confinement: strict + +# define how apps & services are exposed to host system +apps: + datalayerClient: + command: datalayerClient + # interfaces to connect to https://snapcraft.io/docs/supported-interfaces + plugs: + - network + - datalayer + daemon: simple + passthrough: + restart-condition: always + restart-delay: 10s + +parts: + datalayerclient: + plugin: dump + source: ./generated/build + stage-packages: + - libzmq5 + - ctrlx-datalayer + +# describes which interface slots are supported by defining the plugs +plugs: + datalayer: + interface: content + content: datalayer + target: $SNAP_DATA/.datalayer diff --git a/samples-cpp/diagnostics.logbook/.vscode/c_cpp_properties.json b/samples-cpp/diagnostics.logbook/.vscode/c_cpp_properties.json index b409ec982..e4d94e62b 100644 --- a/samples-cpp/diagnostics.logbook/.vscode/c_cpp_properties.json +++ b/samples-cpp/diagnostics.logbook/.vscode/c_cpp_properties.json @@ -10,7 +10,8 @@ "cStandard": "gnu11", "cppStandard": "gnu++14", "intelliSenseMode": "linux-gcc-x64", - "compileCommands": "${workspaceFolder}/build/compile_commands.json" + "compileCommands": "${workspaceFolder}/build/compile_commands.json", + "configurationProvider": "ms-vscode.cmake-tools" } ], "version": 4 diff --git a/samples-cpp/diagnostics.logbook/.vscode/launch.json b/samples-cpp/diagnostics.logbook/.vscode/launch.json index 60474be7c..91c45fa5e 100644 --- a/samples-cpp/diagnostics.logbook/.vscode/launch.json +++ b/samples-cpp/diagnostics.logbook/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/logbook", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/logbook", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,7 +23,7 @@ }, { "description": "Set path variable to .", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] diff --git a/samples-cpp/diagnostics.logbook/.vscode/settings.json b/samples-cpp/diagnostics.logbook/.vscode/settings.json index ba3a59f2b..76b14fc53 100644 --- a/samples-cpp/diagnostics.logbook/.vscode/settings.json +++ b/samples-cpp/diagnostics.logbook/.vscode/settings.json @@ -1,5 +1,5 @@ { - "window.zoomLevel": 1, + "window.zoomLevel": 0, "cmake.configureArgs": [ "-DCMAKE_BUILD_KIT=${buildKit}", ], diff --git a/samples-cpp/diagnostics.logbook/.vscode/tasks.json b/samples-cpp/diagnostics.logbook/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-cpp/diagnostics.logbook/.vscode/tasks.json +++ b/samples-cpp/diagnostics.logbook/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/diagnostics.logbook/CMakeLists.txt b/samples-cpp/diagnostics.logbook/CMakeLists.txt index 364b7c653..5044e1b7c 100644 --- a/samples-cpp/diagnostics.logbook/CMakeLists.txt +++ b/samples-cpp/diagnostics.logbook/CMakeLists.txt @@ -37,12 +37,12 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET( PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET( PLATFORM_NAME "ubuntu22-gcc-aarch64") SET( SNAP_ARCH "arm64") set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET( PLATFORM_NAME "ubuntu20-gcc-x64") + SET( PLATFORM_NAME "ubuntu22-gcc-x64") SET( SNAP_ARCH "amd64") set(CMAKE_C_COMPILER gcc) set(CMAKE_CXX_COMPILER g++) diff --git a/samples-cpp/diagnostics.logbook/LICENSE b/samples-cpp/diagnostics.logbook/LICENSE deleted file mode 100644 index 3ecaa04c3..000000000 --- a/samples-cpp/diagnostics.logbook/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/diagnostics.logbook/README.md b/samples-cpp/diagnostics.logbook/README.md index 2e2ef88d5..92f08298c 100644 --- a/samples-cpp/diagnostics.logbook/README.md +++ b/samples-cpp/diagnostics.logbook/README.md @@ -1,58 +1,39 @@ -# README - -The sample App __diaglogbook__ demonstates how messages are sent to journald and the CtrlX Diagnostics Logbook. - -## The using of Linux Kernel Log Levels - -We recommend to use Linux log levels to define the severity of a log message. - -There are eight log levels defined by the Linux kernel: - -0. EMERGENCY The system is unusable (and will be shut down) -1. ALERT There is a severe error, action must be taken immediately -2. CRITICAL There is a critical error -3. ERROR A job was aborted in case of an error -4. WARNING There is an abnormal condition but the actual job can be finished -5. NOTICE There is a normal but significant condition -6. INFO A messages informs about an internal state -7. DEBUG Message shows details regarding program flow or results - -__Be carefull with level EMERGENCY: Messages with this level are sent to all consoles!__ - - -## Build and Install the Snap - -Build and install the snap like described [here](../README.md). - -## Test the Snap - -* Open the web interface of your ctrlX CORE -* Check the output of the diagnosis logbook - -![Output in diagnosis logbook](docs/images/diagnostics.logbook/messages.in.logbook.png) - -___ - -## License - -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README + +The sample App __diaglogbook__ demonstates how messages are sent to journald and the CtrlX Diagnostics Logbook. + +## The using of Linux Kernel Log Levels + +We recommend to use Linux log levels to define the severity of a log message. + +There are eight log levels defined by the Linux kernel: + +0. EMERGENCY The system is unusable (and will be shut down) +1. ALERT There is a severe error, action must be taken immediately +2. CRITICAL There is a critical error +3. ERROR A job was aborted in case of an error +4. WARNING There is an abnormal condition but the actual job can be finished +5. NOTICE There is a normal but significant condition +6. INFO A messages informs about an internal state +7. DEBUG Message shows details regarding program flow or results + +__Be carefull with level EMERGENCY: Messages with this level are sent to all consoles!__ + + +## Build and Install the Snap + +Build and install the snap like described [here](../README.md). + +## Test the Snap + +* Open the web interface of your ctrlX CORE +* Check the output of the diagnosis logbook + +![Output in diagnosis logbook](docs/images/diagnostics.logbook/messages.in.logbook.png) + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/diagnostics.logbook/build-snap-amd64.sh b/samples-cpp/diagnostics.logbook/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/diagnostics.logbook/build-snap-amd64.sh +++ b/samples-cpp/diagnostics.logbook/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/diagnostics.logbook/build-snap-arm64.sh b/samples-cpp/diagnostics.logbook/build-snap-arm64.sh index f48f8a433..8be304510 100644 --- a/samples-cpp/diagnostics.logbook/build-snap-arm64.sh +++ b/samples-cpp/diagnostics.logbook/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/diagnostics.logbook/main.cpp b/samples-cpp/diagnostics.logbook/main.cpp index 5091aef57..b3181d814 100644 --- a/samples-cpp/diagnostics.logbook/main.cpp +++ b/samples-cpp/diagnostics.logbook/main.cpp @@ -1,31 +1,13 @@ -/** - * MIT License - * - * Copyright (c) 2021 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT */ #include #include // lib systemd required --> CMakeLists.txt -int main(int ac, char *av[]) +int main() { std::cout << "This is an EMERGENCY message simply written to std::cout" << std::endl; std::cout << "This is an ALERT message simply written to std::cout" << std::endl; @@ -46,4 +28,4 @@ int main(int ac, char *av[]) sd_journal_print(LOG_DEBUG, "%s", "This is a DEBUG message written with sd_journal_print()"); return 0; -} \ No newline at end of file +} diff --git a/samples-cpp/diagnostics.logbook/snap/snapcraft.yaml b/samples-cpp/diagnostics.logbook/snap/snapcraft.yaml index c87b6f670..e0ff30683 100644 --- a/samples-cpp/diagnostics.logbook/snap/snapcraft.yaml +++ b/samples-cpp/diagnostics.logbook/snap/snapcraft.yaml @@ -9,7 +9,7 @@ grade: stable summary: Writes messages to journald and the ctrlX logbook description: | This is a simple App to show how messages with different log levels are written to journald and the ctrlX logbook. -base: core20 +base: core22 confinement: strict # define how apps & services are exposed to host system diff --git a/samples-cpp/hello.plc/.vscode/launch.json b/samples-cpp/hello.plc/.vscode/launch.json index 1e322552d..1cf917890 100644 --- a/samples-cpp/hello.plc/.vscode/launch.json +++ b/samples-cpp/hello.plc/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/helloPlc", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/helloPlc", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,7 +23,7 @@ }, { "description": "Set path variable to .", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] diff --git a/samples-cpp/hello.plc/.vscode/tasks.json b/samples-cpp/hello.plc/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-cpp/hello.plc/.vscode/tasks.json +++ b/samples-cpp/hello.plc/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/hello.plc/CMakeLists.txt b/samples-cpp/hello.plc/CMakeLists.txt index 647db1173..728712d06 100644 --- a/samples-cpp/hello.plc/CMakeLists.txt +++ b/samples-cpp/hello.plc/CMakeLists.txt @@ -42,12 +42,12 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET( PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET( PLATFORM_NAME "ubuntu22-gcc-aarch64") SET( SNAP_ARCH "arm64") set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET( PLATFORM_NAME "ubuntu20-gcc-x64") + SET( PLATFORM_NAME "ubuntu22-gcc-x64") SET( SNAP_ARCH "amd64") set(CMAKE_C_COMPILER gcc) set(CMAKE_CXX_COMPILER g++) diff --git a/samples-cpp/hello.plc/LICENSE b/samples-cpp/hello.plc/LICENSE deleted file mode 100644 index 57874ee50..000000000 --- a/samples-cpp/hello.plc/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/hello.plc/README.md b/samples-cpp/hello.plc/README.md index 30cd6985f..bfd885681 100644 --- a/samples-cpp/hello.plc/README.md +++ b/samples-cpp/hello.plc/README.md @@ -1,77 +1,55 @@ -# README hello.plc - -## Introduction - -The sample project __hello.plc__ shows the write access to some ctrlX PLC variables as a Data Layer client on ctrlX CORE or ctrlX CORE virtual. - -## Prerequisites - -* Running ctrlX CORE with app Rexroth PLC installed. -* From ctrlX WORKS start `ctrlX PLC Engineering`: -* Open, compile, download and start the PLC project hello.plc.project of the subfolder plc_application - -With a web browser login into your ctrlX CORE and check the Datalayer folder plc/app/hello_plc_application/sym/PLC_PRG. -Here all PLC variables should appear. - -## Function Description - -When the app has been started, all variables from the PLC program "PLC_PRG" that are present in the PLC symbol configuration will be read out. - -Then the following is executed once: - -* the value "HelloDeveloper" is written to each variable of type STRING. -* the value "1337" is written to each variable of type INT16 (ctrlX-Plc: INT). -* the value "0.815f" is written in each variable of type FLOAT32 (ctrlX-Plc: REAL). - -All variables with another data type are ignored. - -## Build and Install the Snap - -Build and install the snap like described [here](../README.md). - -## Test the Snap - -* Open the web interface of your ctrlX CORE -* Login with `ctrlX PLC Engineering` and watch the values of the variables. Variables in the PLC program "PLC_PRG" that are available in the PLC symbol configuration should have the following values: - * STRING variables should have the value "HelloDeveloper". - * INTEGER variables should have the value "1337" - * REAL variables should have the value "0.815f" - -## Screenshots - -![Declare some plc variables](docs/images/hello.plc/hello.plc.declare.variables.offline.png) -_Declare some plc variables_ -![Declare some plc variables](docs/images/hello.plc/hello.plc.symbolconfiguration.png) -_symbolconfiguration PLC_PRG selected_ -![Status of the plc-variables before the snap runs](docs/images/hello.plc/hello.plc.status.variables.online.png) -_Status of the plc-variables before the snap runs_ -![Status of the plc-variables after the snap runs](docs/images/hello.plc/hello.plc.status.variables.online2.png) -_Status of the plc-variables after the snap runs_ -![Output in diagnosis logbook](docs/images/hello.plc/messages.in.logbook.png) -_Output in diagnosis logbook_ - -___ - -## License - -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +# README hello.plc + +## Introduction + +This sample project shows the ctrlX Data Layer access to ctrlX PLC variables of a ctrlX CORE or ctrlX COREvirtual. + +## Prerequisites + +* ctrlX WORKS with `ctrlX PLC Engineering` installed. +* ctrlX CORE with app PLC installed. +* __IMPORTANT: Do not use this project in a control that is in production or in which the PLC program or its variables must not be changed.__ + +## Function Description + +The app browses all PLC variables mapped to the ctrlX Data Layer. + +If the attached app 'hello_plc_application' has been installed, its variables will be overwritten: + +* "HelloDeveloper" is written to each variable of type STRING. +* "1337" is written to each variable of type INT16 (ctrlX-Plc: INT). +* "0.815f" is written in each variable of type FLOAT32 (ctrlX-Plc: REAL). + +All variables with another data type are ignored. + +## Build and Install the Snap + +Build and install the snap like described [here](../README.md). + +## Test the Snap + +### Read Access to Variables of your PLC Application + +* Install your default PLC application in the ctrlX CORE. +* Install this sample project as snap or start it in the App Build Environment + +All DL variables will be listet but not overwritten. + +### Read/Write Access to the Variables of our Test PLC Application + +* Download the file hello_plc_application.export from sub folder plc_application/ +* Create a new PLC project with ctrlX PLC Engineering. +* Select the node PLC Logic in the project tree with the cursor. +* Click main menu item Project -> Import... and import the whole content. +* Login into your PLC runtime (project will be compiled and downloaded). +* Start your PLC application (F5) - be sure your ctrlX is in Operting +* Install this sample project as snap or start it in the App Build Environment + +All DL variables will be listet, INT, REAL (Float) and STRING values are overwritten. + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/hello.plc/build-snap-amd64.sh b/samples-cpp/hello.plc/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/hello.plc/build-snap-amd64.sh +++ b/samples-cpp/hello.plc/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/hello.plc/build-snap-arm64.sh b/samples-cpp/hello.plc/build-snap-arm64.sh index f48f8a433..8be304510 100644 --- a/samples-cpp/hello.plc/build-snap-arm64.sh +++ b/samples-cpp/hello.plc/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/hello.plc/ctrlx_datalayer_helper.h b/samples-cpp/hello.plc/ctrlx_datalayer_helper.h index 3fdec3b7d..d0683514f 100644 --- a/samples-cpp/hello.plc/ctrlx_datalayer_helper.h +++ b/samples-cpp/hello.plc/ctrlx_datalayer_helper.h @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ #ifndef CTRLX_DATALAYER_HELPER_H @@ -43,17 +25,17 @@ * If these values do not suit your use case, explicitly pass the parameters that require different values. * Here some examples: * - * 1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: + * 1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: * * client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") * - * 2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): + * 2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): * * client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) * * Remarks: * 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + * 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual * * * IMPORTANT: @@ -84,10 +66,10 @@ static bool isSnap() } //! Get Datalayer connection string -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result Connection string static std::string getConnectionString( const std::string& ip = "192.168.1.1", @@ -112,10 +94,10 @@ static std::string getConnectionString( //! Get Datalayer Client instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IClient instance or nullptr on error static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", @@ -136,10 +118,10 @@ static comm::datalayer::IClient* getClient(comm::datalayer::DatalayerSystem& dat //! Get Datalayer Provider instance //! @param[in] datalayerSystem Datalayer.System instance -//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX CORE virtual with port forwarding +//! @param[in] ip IP address of the ctrlX CORE: 10.0.2.2 is ctrlX COREvirtual with port forwarding //! @param[in] user User name //! @param[in] password The password -//! @param[in] sslPort The port number for SSL: 8443 if ctrlX CORE virtual with port forwarding 8443:443 +//! @param[in] sslPort The port number for SSL: 8443 if ctrlX COREvirtual with port forwarding 8443:443 //! @result IProvider instance or nullptr on error static comm::datalayer::IProvider* getProvider(comm::datalayer::DatalayerSystem& datalayerSystem, const std::string& ip = "192.168.1.1", diff --git a/samples-cpp/hello.plc/docs/images/hello.plc/dummy.png b/samples-cpp/hello.plc/docs/images/hello.plc/dummy.png deleted file mode 100644 index e69de29bb..000000000 diff --git a/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.declare.variables.offline.png b/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.declare.variables.offline.png deleted file mode 100644 index 0e51541d3..000000000 Binary files a/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.declare.variables.offline.png and /dev/null differ diff --git a/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.status.variables.online.png b/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.status.variables.online.png deleted file mode 100644 index 6b852941c..000000000 Binary files a/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.status.variables.online.png and /dev/null differ diff --git a/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.status.variables.online2.png b/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.status.variables.online2.png deleted file mode 100644 index ea917bf92..000000000 Binary files a/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.status.variables.online2.png and /dev/null differ diff --git a/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.symbolconfiguration.png b/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.symbolconfiguration.png deleted file mode 100644 index 97ce1b894..000000000 Binary files a/samples-cpp/hello.plc/docs/images/hello.plc/hello.plc.symbolconfiguration.png and /dev/null differ diff --git a/samples-cpp/hello.plc/docs/images/hello.plc/messages.in.logbook.png b/samples-cpp/hello.plc/docs/images/hello.plc/messages.in.logbook.png deleted file mode 100644 index 0c2a3f683..000000000 Binary files a/samples-cpp/hello.plc/docs/images/hello.plc/messages.in.logbook.png and /dev/null differ diff --git a/samples-cpp/hello.plc/main.cpp b/samples-cpp/hello.plc/main.cpp index a155caded..a8773763d 100644 --- a/samples-cpp/hello.plc/main.cpp +++ b/samples-cpp/hello.plc/main.cpp @@ -1,60 +1,50 @@ -/** - * MIT License - * - * Copyright (c) 2020-2021 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ -/* - * This snap-program determines symbolic PLC variables from plc-program 'PLC_PRG' and writes in all variables of - * the type string 'HelloDeveloper', in all integers '1337' and in all floats the value '0.815f'. - */ + /* + * This snap-program determines symbolic PLC variables from plc-program 'PLC_PRG' and writes in all variables of + * the type string 'HelloDeveloper', in all integers '1337' and in all floats the value '0.815f'. + */ #include #include +#include #include "comm/datalayer/datalayer.h" #include "comm/datalayer/datalayer_system.h" #include "ctrlx_datalayer_helper.h" -//! Get PLC apps from vector -comm::datalayer::DlResult getApps(comm::datalayer::Variant &data, std::vector &apps) +comm::datalayer::IClient* client; +comm::datalayer::Variant variant; + +std::string helloPlcApplication = "hello_plc_application"; + + +static comm::datalayer::DlResult getStrings(comm::datalayer::Variant& data, std::vector& strings) { - if (data.getType() == comm::datalayer::VariantType::ARRAY_OF_STRING) + if (data.getType() != comm::datalayer::VariantType::ARRAY_OF_STRING) { - const char **str = data; - for (uint32_t i = 0; i < data.getCount(); i++) - { - std::cout << "Apps: " << str[i] << std::endl; - apps.push_back(str[i]); - } - return comm::datalayer::DlResult::DL_OK; + return comm::datalayer::DlResult::DL_RT_NOVALIDDATA; } - return comm::datalayer::DlResult::DL_RT_NOVALIDDATA; + strings.clear(); + + const char** str = data; + for (uint32_t i = 0; i < data.getCount(); i++) + { + std::cout << str[i] << std::endl; + strings.push_back(str[i]); + } + return comm::datalayer::DlResult::DL_OK; } // Function takes the value from "i" to "data" and -// then writes the new "data" to the address "addr" of the data layer client "IClient" -comm::datalayer::DlResult setIntValue(comm::datalayer::Variant &data, comm::datalayer::IClient *client, std::string addr, int16_t i) +// then writes the new "data" to the address "addr" of the ctrlX Data Layer client "IClient" +static comm::datalayer::DlResult setIntValue(comm::datalayer::Variant& data, comm::datalayer::IClient* client, std::string addr, int16_t i) { comm::datalayer::DlResult result; result = data.setValue(i); @@ -72,8 +62,8 @@ comm::datalayer::DlResult setIntValue(comm::datalayer::Variant &data, comm::data } // Function takes the value from "str" to "data" and -// then writes the new "data" to the address "addr" of the data layer client "IClient" -comm::datalayer::DlResult setStringValue(comm::datalayer::Variant &data, comm::datalayer::IClient *client, std::string addr, std::string str) +// then writes the new "data" to the address "addr" of the ctrlX Data Layer client "IClient" +static comm::datalayer::DlResult setStringValue(comm::datalayer::Variant& data, comm::datalayer::IClient* client, std::string addr, std::string str) { comm::datalayer::DlResult result; result = data.setValue(str); @@ -91,8 +81,8 @@ comm::datalayer::DlResult setStringValue(comm::datalayer::Variant &data, comm::d } // Function takes the value from "value" to "data" and -// then writes the new "data" to the address "addr" of the data layer client "IClient" -comm::datalayer::DlResult setFloatValue(comm::datalayer::Variant &data, comm::datalayer::IClient *client, std::string addr, float value) +// then writes the new "data" to the address "addr" of the ctrlX Data Layer client "IClient" +static comm::datalayer::DlResult setFloatValue(comm::datalayer::Variant& data, comm::datalayer::IClient* client, std::string addr, float value) { comm::datalayer::DlResult result; result = data.setValue(value); @@ -109,114 +99,161 @@ comm::datalayer::DlResult setFloatValue(comm::datalayer::Variant &data, comm::da return comm::datalayer::DlResult::DL_FAILED; } -int run(comm::datalayer::IClient *client) +static void scanVariable(std::string address) { + auto writeNotAllowed = address.find(helloPlcApplication) == std::string::npos; - // getting all PLC Applications nodes - comm::datalayer::Variant data; - comm::datalayer::DlResult result = client->browseSync("plc/app", &data); - if (STATUS_FAILED(result)) - { - std::cout << "ERROR Browsing of PLC nodes 'plc/app' failed with: " << result.toString() << std::endl; - return 1; - } - - // Create dynamic string-array - std::vector plcApp; - // write all Plc-Applications from "data" in the dynamic string-array "plcApp" - result = getApps(data, plcApp); - if (STATUS_FAILED(result)) - { - std::cout << "ERROR Reading data of PLC nodes 'plc/app' failed with: " << result.toString() << std::endl; - return 1; - } - - if (plcApp.size() <= 0) - { - std::cout << "ERROR No PLC application available" << std::endl; - return 4; - } - - // set the path to the symbol variables of the first application in the plc-program "PLC_PRG" - std::string addr = "plc/app/" + plcApp[0] + "/sym/PLC_PRG/"; - // read all symbol variables into "data" - result = client->browseSync(addr, &data); - if (STATUS_FAILED(result)) - { - std::cout << "ERROR Browsing of symbols of '"<< addr << "' failed with: " << result.toString() << std::endl; - return 5; - } + comm::datalayer::DlResult result; - // Create dynamic string-array - std::vector symVar; - // write all symbol-variables from "data" in the dynamic string-array "symVar" - result = getApps(data, symVar); - if (STATUS_FAILED(result)) + // determine the data type of the symbol-variable read + switch (variant.getType()) { - std::cout << "ERROR Reading data failed with: " << result.toString() << std::endl; - return 6; - } + case comm::datalayer::VariantType::STRING: - // run through the loop for each symbol-variable in "data" - for (uint32_t i = 0; i < data.getCount(); i++) - { - comm::datalayer::Variant value; - // write the path to the current symbol variable in "temp" - // set the path to the symbol-variable - std::string temp = addr + symVar[i]; - // read the value of this symbol-variable - result = client->readSync(temp, &value); - if (STATUS_FAILED(result)) - { - std::cout << "WARN Reading of " << temp << "failed with: " << result.toString() << std::endl; - } + std::cout << "Actual value of '" << address << "' : " << std::string(variant) << std::endl; - // determine the data type of the symbol-variable read - switch (value.getType()) - { - // Set 'helloDeveloper' to string-Variable in the plc application - case comm::datalayer::VariantType::STRING: - result = setStringValue(value, client, temp, "HelloDeveloper"); + if (writeNotAllowed) + { + std::cout << "Skip writing of '" << address << std::endl; + return; + } + + result = setStringValue(variant, client, address, "HelloDeveloper"); if (STATUS_FAILED(result)) { - std::cout << "WARN Set STRING value into '" << temp << "' failed with: " << result.toString() << std::endl; + std::cout << "WARN Set STRING value into '" << address << "' failed with: " << result.toString() << std::endl; } else { - std::cout << "INFO Set STRING value into '" << temp << "' succeeded" << std::endl; + std::cout << "INFO Set STRING value into '" << address << "' succeeded" << std::endl; } break; - // Set '1337' to INT-Variable in the plc application + // Set '1337' to INT-Variable in the plc application case comm::datalayer::VariantType::INT16: - result = setIntValue(value, client, temp, 1337); + + std::cout << "Actual value of '" << address << "' : " << int16_t(variant) << std::endl; + + if (writeNotAllowed) + { + std::cout << "Skip writing of '" << address << std::endl; + return; + } + + result = setIntValue(variant, client, address, 1337); if (STATUS_FAILED(result)) { - std::cout << "WARN Set INT16 value into '" << temp << "' failed with: " << result.toString() << std::endl; + std::cout << "WARN Set INT16 value into '" << address << "' failed with: " << result.toString() << std::endl; } else { - std::cout << "INFO Set INT16 value into '" << temp << "' succeeded" << std::endl; + std::cout << "INFO Set INT16 value into '" << address << "' succeeded" << std::endl; } - break; + break;; - // Set '0.815f' to Float-Variable in the plc application + // Set '0.815f' to Float-Variable in the plc application case comm::datalayer::VariantType::FLOAT32: - result = setFloatValue(value, client, temp, 0.815f); + + std::cout << "Actual value of '" << address << "' : " << float(variant) << std::endl; + + if (writeNotAllowed) + { + std::cout << "Skip writing of '" << address << std::endl; + return; + } + + result = setFloatValue(variant, client, address, 0.815f); if (STATUS_FAILED(result)) { - std::cout << "WARN Set FLOAT32 value into '" << temp << "' failed with: " << result.toString() << std::endl; + std::cout << "WARN Set FLOAT32 value into '" << address << "' failed with: " << result.toString() << std::endl; } else { - std::cout << "INFO Set FLOAT32 value into '" << temp << "' succeeded" << std::endl; + std::cout << "INFO Set FLOAT32 value into '" << address << "' succeeded" << std::endl; } break; default: - std::cout << "WARN Variant type not supported - only STRING, INT16 or FLOAT32 supported" << std::endl; + std::cout << "WARN Variant type of '" << address << "' not supported - only STRING, INT16 or FLOAT32" << std::endl; break; + } +} + +// address without / at the end +static int scanFolder(std::string address) +{ + comm::datalayer::DlResult result = client->browseSync(address, &variant); + if (STATUS_FAILED(result)) + { + std::cout << "ERROR Browsing of '" << address << "' failed with: " << result.toString() << std::endl; + return 1; + } + + std::vector children; + result = getStrings(variant, children); + if (STATUS_FAILED(result)) + { + std::cout << "ERROR Reading '" << address << "' failed with: " << result.toString() << std::endl; + return 1; + } + + if (children.size() <= 0) + { + std::cout << "ERROR '" << address << "' has no sub elements" << std::endl; + return 2; + } + + // Loop over all children + int exitCode; + for (int i=0; i < children.size(); i++) + { + std::string childAddress = address +"/" + children[i]; + + // If readSync succeeds then we have a variable + result = client->readSync(childAddress, &variant); + if (STATUS_SUCCEEDED(result)) + { + scanVariable(childAddress); + continue; } + + exitCode = scanFolder(childAddress); + + if (exitCode != 0) return exitCode; + } + + return 0; +} +static int scanPlcApp() +{ + std::string address = "plc/app"; + comm::datalayer::DlResult result = client->browseSync(address, &variant); + if (STATUS_FAILED(result)) + { + std::cout << "ERROR Browsing of '" << address << "' failed with: " << result.toString() << std::endl; + return 1; + } + + std::vector apps; + result = getStrings(variant, apps); + if (STATUS_FAILED(result)) + { + std::cout << "ERROR Reading '" << address << "' failed with: " << result.toString() << std::endl; + return 2; + } + + if (apps.size() <= 0) + { + std::cout << "ERROR '" << address << "' has no sub elements" << std::endl; + return 3; + } + + // Loop over all apps + for (int i=0; i < apps.size(); i++) + { + std::string symAddress = address +"/" + apps[i] + "/sym"; + auto result = scanFolder(symAddress); + if (result > 0) return result; } return 0; @@ -228,13 +265,11 @@ int main() comm::datalayer::DatalayerSystem datalayer; datalayer.start(false); - comm::datalayer::IClient *client; - // Try ctrlX CORE (virtual) client = getClient(datalayer); if (client == nullptr) { - // Try ctrlX CORE virtual with port forwarding + // Try ctrlX COREvirtual with port forwarding client = getClient(datalayer, "10.0.2.2", "boschrexroth", "boschrexroth", 8443); } if (client == nullptr) @@ -244,11 +279,11 @@ int main() } else { - exitCode = run(client); + exitCode = scanPlcApp(); delete client; } datalayer.stop(); return exitCode; -} \ No newline at end of file +} diff --git a/samples-cpp/hello.plc/plc_application/hello.plc.project b/samples-cpp/hello.plc/plc_application/hello.plc.project deleted file mode 100644 index 63e2eaa0b..000000000 Binary files a/samples-cpp/hello.plc/plc_application/hello.plc.project and /dev/null differ diff --git a/samples-cpp/hello.plc/plc_application/hello_plc_application.export b/samples-cpp/hello.plc/plc_application/hello_plc_application.export new file mode 100644 index 000000000..1c2326076 --- /dev/null +++ b/samples-cpp/hello.plc/plc_application/hello_plc_application.export @@ -0,0 +1,489 @@ + + + + + + + True + + cd962606-261d-41b5-ac1c-cfc7177d4e1c + a8581699-cc10-451a-8b04-22e026abf1be + hello_plc_application + + 639b491f-5557-464c-af91-1471bac9f549 + + 638204288377458884 + + + -1 + True + False + 801b75f1-f7a6-48ec-8fbc-c51265046882 + 00000000-0000-0000-0000-000000000000 + + True + True + True + True + + False + 8192 + 8192 + 8192 + 0 + False + + + + False + 0 + 0 + False + + a8581699-cc10-451a-8b04-22e026abf1be + + Device + SPS-Logik + + -1 + + + False + + 1b0bd995-630b-4c0f-87af-ff768741cffb + cd962606-261d-41b5-ac1c-cfc7177d4e1c + Library Manager + + adb5cb65-8e1d-4a00-b70a-375ea27582f3 + + 638204288420588931 + + + + + + IecVarAccess, 3.3.1.20 (System) + False + + IecVarAccess + b303f5ce-75ff-4668-a777-7da8debb449c + 851852413 + IecVarAccessLibrary + True + False + False + False + False + + + IoStandard, 3.5.17.0 (System) + False + + IoStandard + b303f5ce-75ff-4668-a777-7da8debb449c + 2353270750 + IoStandard + True + False + False + False + True + + + CXAC_Base, 1.18.2.0 (Bosch Rexroth AG) + False + + CXA_BASE + b303f5ce-75ff-4668-a777-7da8debb449c + 1211194795 + CXAC_Base + True + False + False + False + False + + + CXA_CommonTypes, 1.18.0.0 (Bosch Rexroth AG) + False + + CXA_COMMONTYPES + b303f5ce-75ff-4668-a777-7da8debb449c + 3534099241 + CXA_CommonTypes + True + False + False + False + False + + + CXA_Utilities, 1.20.0.0 (Bosch Rexroth AG) + False + + CXA_UTILITIES + b303f5ce-75ff-4668-a777-7da8debb449c + 3372890138 + CXA_Utilities + True + False + False + False + False + + + Standard, 3.5.18.0 (System) + False + + Standard + b303f5ce-75ff-4668-a777-7da8debb449c + 575299980 + Standard + True + False + False + False + False + + + 3SLicense, 0.0.0.0 (3S - Smart Software Solutions GmbH) + False + + 3SLicense + 97c3b452-d9fa-4ac2-9d0c-3d420aa6d95b + 1886350887 + _3S_LICENSE + True + False + False + False + False + + + Breakpoint Logging Functions, * (3S - Smart Software Solutions GmbH) + False + + BreakpointLogging + b303f5ce-75ff-4668-a777-7da8debb449c + 3635765733 + BPLog + True + False + False + False + False + + + + + + Standard + + + Standard, 3.5.18.0 (System) + + + + + StringUtils + + + StringUtils, 3.5.18.0 (System) + + + + + Util + + + Util, 3.5.19.0 (System) + + + + + CBML + + + Common Behaviour Model, 3.5.17.0 (3S - Smart Software Solutions GmbH) + + + + + cd962606-261d-41b5-ac1c-cfc7177d4e1c + + Device + SPS-Logik + hello_plc_application + + -1 + + + False + + 5b4f221c-da89-4f16-9097-7c41a638ab2d + cd962606-261d-41b5-ac1c-cfc7177d4e1c + PLC_PRG + + 6f9dac99-8de1-4efc-8465-68ac443b7d08 + + a9ed5b7e-75c5-4651-af16-d2c27e98cb94 + 3b83b776-fb25-43b8-99f2-3c507c9143fc + + 638204288377498908 + + + None + + + // Dummy code to avoid warnings +IF (strVar01 <> strVar02) THEN + ; +END_IF + +IF (rVar01 <> rVar02) THEN + ; +END_IF + +IF (iVar01 <> iVar02) THEN + ; +END_IF + 5b4f221c-da89-4f16-9097-7c41a638ab2d_Impl_LineIds + + + + + {attribute 'symbol' := 'readwrite'} + +PROGRAM PLC_PRG +VAR + + strVar01 : STRING(255):='Empty string #1'; + strVar02 : STRING(255):='Empty string #2'; + + rVar01 : REAL:=0.0; + rVar02 : REAL:=0.0; + + iVar01 : INT:=0; + iVar02 : INT:=0; +END_VAR + 5b4f221c-da89-4f16-9097-7c41a638ab2d_Decl_LineIds + + + 40 + Standard + + False + + cd962606-261d-41b5-ac1c-cfc7177d4e1c + + Device + SPS-Logik + hello_plc_application + + -1 + + + False + + 876188bf-34a4-4326-bbb5-93228b10c2c1 + cd962606-261d-41b5-ac1c-cfc7177d4e1c + Symbols + + 21d4fe94-4123-4e23-9091-ead220afbd1f + + 638204288377529265 + + + 697af87d-6ae1-450f-bba7-a5ceb9dee719 + 51dd0bca-5e16-4cc1-9e8c-9ad74a2e4a2b + + + PLC_PRG + -1 + + + 3 + 3 + STRING(255) + strVar01 + + + 3 + 3 + STRING(255) + strVar02 + + + 3 + 3 + REAL + rVar01 + + + 3 + 3 + REAL + rVar02 + + + 3 + 3 + INT + iVar01 + + + 3 + 3 + INT + iVar02 + + + 5b4f221c-da89-4f16-9097-7c41a638ab2d + + + + + + + + e72ff02e-aaa2-48c8-9018-8a4061e23a03 + False + False + False + None + None + + None + False + a03e0162-d1a8-4479-9e86-fe2da28c8869 + 0141eb75-141b-4ea1-9a8c-75f952b22a6c + + + + + cd962606-261d-41b5-ac1c-cfc7177d4e1c + + Device + SPS-Logik + hello_plc_application + + -1 + + + False + + 990ce5e4-4198-425b-937a-e4802e73b225 + cd962606-261d-41b5-ac1c-cfc7177d4e1c + Task Configuration + + ae1de277-a207-4a28-9efb-456c06bd52f3 + + 638204288377589267 + + + + + + 8d2725f1-9099-584e-8f2d-94f41d5431f0 + 9b721cad-916f-54db-b9bc-ce7cfcbe05ad + f97a4e6b-f936-5b8d-8890-e33d792d6b01 + 6a5a726b-b81c-5e83-b7a8-6da214124bc4 + 6c5610ed-c230-5535-8ece-541e0c8e3b55 + 226e1216-5c02-5409-8ed2-6ae80d78720c + f08ef53e-694c-5e67-a158-b933006027d6 + 9eac5f19-ae03-5b39-8cac-39a23305e1da + d371bcc0-0a32-5b03-b89d-dbe7783629e3 + 29c60f57-817e-59e7-a756-c0e5db5f4e33 + bcf65e36-330e-5ff4-a71a-f45fe7ff1d2e + dce2adf7-42ec-5e10-a67d-eec0ca7afa3e + 5e39ee03-fe05-5704-9ac4-aaf5127711af + 12ea01a0-6f77-510b-8469-ce9b118b5998 + 3443929a-8463-5da6-8769-ebc38af7ca21 + + + + IEC-Tasks + -2 + True + False + + + c2db22ea-6cd9-5410-a049-a33babe1f1f4 + 49ce8da9-ede7-5589-b6d7-b5ebb226e159 + e51d0a6e-53a2-5638-b14c-11ce4bb74026 + 020d86e7-5573-565a-a88d-f6c7cd71e727 + de22d734-8a18-5d4e-9c42-b9fd619d1482 + 0c1348e1-8ba2-5668-af12-0c2b1127830b + + 00000000-0000-0000-0000-000000000000 + + cd962606-261d-41b5-ac1c-cfc7177d4e1c + + Device + SPS-Logik + hello_plc_application + + -1 + + + False + + 0666f89d-a02a-4d36-b931-bb3a44300dc4 + 990ce5e4-4198-425b-937a-e4802e73b225 + MainTask + + 98a2708a-9b18-4f31-82ed-a1465b24fa2d + + 638204288377619275 + + + False + Cyclic + + + + + + 30 + + True + + 20 + ms + + 1 + + + 200 + ms + + + + c3292d31-7a2a-4649-bd90-8335a03bc7b7 + eb89a6e2-c523-4225-a7af-17a2aca8a03e + + + PLC_PRG + + + + False + True + -1 + -2 + IEC-Tasks + + + 990ce5e4-4198-425b-937a-e4802e73b225 + + Device + SPS-Logik + hello_plc_application + Taskkonfiguration + + -1 + + + ctrlX PLC 2.1.0 + + diff --git a/samples-cpp/hello.plc/snap/snapcraft.yaml b/samples-cpp/hello.plc/snap/snapcraft.yaml index 825b836b5..efc48cfb1 100644 --- a/samples-cpp/hello.plc/snap/snapcraft.yaml +++ b/samples-cpp/hello.plc/snap/snapcraft.yaml @@ -10,7 +10,7 @@ summary: Write PLC variables description: | This app determines symbolic PLC variables from plc-program 'PLC_PRG' and writes in all variables of the type string 'HelloDeveloper', in all integers '1337' and in all floats the value '0.815f'. -base: core20 +base: core22 confinement: strict # define how apps & services are exposed to host system diff --git a/samples-cpp/hello.world/.vscode/launch.json b/samples-cpp/hello.world/.vscode/launch.json index c68ae9479..4ad8dc4b1 100644 --- a/samples-cpp/hello.world/.vscode/launch.json +++ b/samples-cpp/hello.world/.vscode/launch.json @@ -8,9 +8,9 @@ "name": "x64 Build Environment (local)", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/HelloWorld", + "program": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/HelloWorld", "args": [], - "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "additionalSOLibSearchPath": "${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], @@ -23,7 +23,7 @@ }, { "description": "Set path variable to .", - "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu20-gcc-x64/Debug/usr/lib/", + "text": "set env LD_LIBRARY_PATH=${workspaceFolder}/generated/ubuntu22-gcc-x64/Debug/usr/lib/", "ignoreFailures": false } ] diff --git a/samples-cpp/hello.world/.vscode/tasks.json b/samples-cpp/hello.world/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-cpp/hello.world/.vscode/tasks.json +++ b/samples-cpp/hello.world/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-cpp/hello.world/CMakeLists.txt b/samples-cpp/hello.world/CMakeLists.txt index 3abe86de2..dd44dbfcd 100644 --- a/samples-cpp/hello.world/CMakeLists.txt +++ b/samples-cpp/hello.world/CMakeLists.txt @@ -37,12 +37,12 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") # set libraries dirs and includes # IF( ${CMAKE_BUILD_KIT} MATCHES "aarch64") - SET( PLATFORM_NAME "ubuntu20-gcc-aarch64") + SET( PLATFORM_NAME "ubuntu22-gcc-aarch64") SET( SNAP_ARCH "arm64") set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ELSE() - SET( PLATFORM_NAME "ubuntu20-gcc-x64") + SET( PLATFORM_NAME "ubuntu22-gcc-x64") SET( SNAP_ARCH "amd64") set(CMAKE_C_COMPILER gcc) set(CMAKE_CXX_COMPILER g++) diff --git a/samples-cpp/hello.world/LICENSE b/samples-cpp/hello.world/LICENSE deleted file mode 100644 index 57874ee50..000000000 --- a/samples-cpp/hello.world/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-cpp/hello.world/README.md b/samples-cpp/hello.world/README.md index fee627166..c5a866477 100644 --- a/samples-cpp/hello.world/README.md +++ b/samples-cpp/hello.world/README.md @@ -1,46 +1,27 @@ -# README hello.world - -The sample __hello.world__ print out "Hello World" on CtrlX CORE. - -## Introduction - -This sample demonstrates how you can build your first C/C++ snap. - -The project __hello.world__ provides a simple application example to print out "Hello World" in ctrlX CORE devices: ctrlX CORE or ctrlX CORE virtual. - -![Output in diagnosis logbook](docs/images/hello.world/messages.in.logbook.png) - -## Troubleshooting - -All automatically created files are located in folders `build` and `generated`. -If there are unclear messages during the build process, it might help to delete the folders `build` and `generated` and restart the build process. - -## Support - -If you've any questions visit the [ctrlX AUTOMATION Community](https://developer.community.boschrexroth.com/) - -___ - -## License - -MIT License - -Copyright (c) 2020-2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README hello.world + +The sample __hello.world__ print out "Hello World" on CtrlX CORE. + +## Introduction + +This sample demonstrates how you can build your first C/C++ snap. + +The project __hello.world__ provides a simple application example to print out "Hello World" in ctrlX CORE devices: ctrlX CORE or ctrlX COREvirtual. + +![Output in diagnosis logbook](docs/images/hello.world/messages.in.logbook.png) + +## Troubleshooting + +All automatically created files are located in folders `build` and `generated`. +If there are unclear messages during the build process, it might help to delete the folders `build` and `generated` and restart the build process. + +## Support + +If you've any questions visit the [ctrlX AUTOMATION Community](https://developer.community.boschrexroth.com/) + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-cpp/hello.world/build-snap-amd64.sh b/samples-cpp/hello.world/build-snap-amd64.sh index 0952a4b6d..d90725bd2 100644 --- a/samples-cpp/hello.world/build-snap-amd64.sh +++ b/samples-cpp/hello.world/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/hello.world/build-snap-arm64.sh b/samples-cpp/hello.world/build-snap-arm64.sh index f48f8a433..8be304510 100644 --- a/samples-cpp/hello.world/build-snap-arm64.sh +++ b/samples-cpp/hello.world/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e rm -rf bfbs/ rm -rf generated/ rm -rf build/ diff --git a/samples-cpp/hello.world/main.cpp b/samples-cpp/hello.world/main.cpp index a5a2b3e0b..243b5628d 100644 --- a/samples-cpp/hello.world/main.cpp +++ b/samples-cpp/hello.world/main.cpp @@ -1,32 +1,14 @@ -/** - * MIT License - * - * Copyright (c) 2020-2021 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT */ - + #include -int main(int ac, char* av[]) +int main() { std::cout << "Hello World" << std::endl; return 0; -} \ No newline at end of file +} diff --git a/samples-cpp/hello.world/snap/snapcraft.yaml b/samples-cpp/hello.world/snap/snapcraft.yaml index 67ae03203..ca335b975 100644 --- a/samples-cpp/hello.world/snap/snapcraft.yaml +++ b/samples-cpp/hello.world/snap/snapcraft.yaml @@ -9,7 +9,7 @@ grade: stable summary: Print 'Hello World' to console output description: | This App is a simple example to show how to make an App. -base: core20 +base: core22 confinement: strict # define how apps & services are exposed to host system diff --git a/samples-go/appdata/.vscode/tasks.json b/samples-go/appdata/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-go/appdata/.vscode/tasks.json +++ b/samples-go/appdata/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-go/appdata/LICENSE b/samples-go/appdata/LICENSE deleted file mode 100644 index 3ecaa04c3..000000000 --- a/samples-go/appdata/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-go/appdata/README.md b/samples-go/appdata/README.md index 403c43060..db95ca80f 100644 --- a/samples-go/appdata/README.md +++ b/samples-go/appdata/README.md @@ -14,7 +14,7 @@ This sample shows how to load and save data according to the ctrlx storage conce ## Build a Snap Select main menu item Termninal - Run Build Task select the architecture of your ctrlX CORE: - amd64 for ctrlX CORE virtual + amd64 for ctrlX COREvirtual arm64 for ctrlX CORE A snap file will be build. @@ -90,24 +90,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/samples-go/appdata/build-snap-amd64.sh b/samples-go/appdata/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-go/appdata/build-snap-amd64.sh +++ b/samples-go/appdata/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-go/appdata/build-snap-arm64.sh b/samples-go/appdata/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-go/appdata/build-snap-arm64.sh +++ b/samples-go/appdata/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-go/appdata/cmd/appdata/appdata.go b/samples-go/appdata/cmd/appdata/appdata.go index 5832d089c..79c24f806 100644 --- a/samples-go/appdata/cmd/appdata/appdata.go +++ b/samples-go/appdata/cmd/appdata/appdata.go @@ -1,10 +1,16 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + package main import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "log" "net" "net/http" "os" @@ -19,8 +25,8 @@ import ( const ( //Setup HTTP listener and load/save routes we're interested in - RestUrlLoad = "ctrlx-go-appdata/api/v1/load" - RestUrlSave = "ctrlx-go-appdata/api/v1/save" + RestUrlLoad = "sdk-go-appdata/api/v1/load" + RestUrlSave = "sdk-go-appdata/api/v1/save" // The name of the storage file StorageFileName = "appdata.json" @@ -68,27 +74,15 @@ func IsSnapped() bool { // Starts the Rest API func RestApiStart() error { - // Create http handle - http.HandleFunc("/"+RestUrlLoad, handler) - http.HandleFunc("/"+RestUrlSave, handler) - // Depending on running as snap or as external app, start webserver with unix sockets or tcp if IsSnapped() { - fmt.Print("App is running as snap\n") - sockpath := filepath.Join(os.Getenv("SNAP_DATA"), "/package-run/ctrlx-go-appdata/") - sockfile := filepath.Join(sockpath, "web.sock") - if _, err := os.Stat(sockpath); os.IsNotExist(err) { - os.MkdirAll(sockpath, os.ModePerm) - } - os.Remove(sockfile) - unixListener, err := net.Listen("unix", sockfile) - if err != nil { - return err - } - fmt.Printf("Server UP - UNIX SOCKET - File: %s ", sockfile) - http.Serve(unixListener, nil) - + err := unixSocketServe() + return err } else { + // Create http handle + http.HandleFunc("/"+RestUrlLoad, handler) + http.HandleFunc("/"+RestUrlSave, handler) + fmt.Print("App is not running as snap\n") tcpListener, err := net.Listen("tcp", ":"+strconv.Itoa(HttpPort)) if err != nil { @@ -96,7 +90,44 @@ func RestApiStart() error { } fmt.Printf("Server UP - TCP - Port: %s \n", strconv.Itoa(HttpPort)) http.Serve(tcpListener, nil) + } + return nil +} +func unixSocketServe() error { + fmt.Println("App is running as snap") + sockpath := filepath.Join(os.Getenv("SNAP_DATA"), "/package-run/sdk-go-appdata/") + sockfile := filepath.Join(sockpath, "web.sock") + //remo + if _, err := os.Stat(sockpath); err == nil { + fmt.Println("Unix domain socket already exists, deleting") + _ = os.Remove(sockfile) + } + + if _, err := os.Stat(sockpath); os.IsNotExist(err) { + fmt.Println("Unix domain socket creating") + os.MkdirAll(sockpath, os.ModePerm) + } + fmt.Println("App socket listening") + unixListener, err := net.Listen("unix", sockfile) + if err != nil { + fmt.Println("App Socket error: ", err) + return err + } + + fmt.Print("App socket register handler\n") + m := http.NewServeMux() + m.HandleFunc("/"+RestUrlLoad, handler) + m.HandleFunc("/"+RestUrlSave, handler) + + server := http.Server{ + Handler: m, + } + + fmt.Printf("Server UP - UNIX SOCKET - File: %s ", sockfile) + if err := server.Serve(unixListener); err != nil { + log.Fatal(err) + return err } return nil } @@ -202,7 +233,7 @@ func LoadAppData() error { } - jsonFile, err := ioutil.ReadFile(path) + jsonFile, err := os.ReadFile(path) if err != nil { fmt.Printf("Loading application data from file '%s' failed! %s", path, err.Error()) return err @@ -243,7 +274,7 @@ func SaveAppData() error { return err } - err = ioutil.WriteFile(path, jsonb, 0644) + err = os.WriteFile(path, jsonb, 0644) if err != nil { fmt.Printf("Saving application data to file '%s' failed! %s\n", path, err.Error()) return err diff --git a/samples-go/appdata/cmd/appdata/main.go b/samples-go/appdata/cmd/appdata/main.go index 43a5901c2..da1f1bd85 100644 --- a/samples-go/appdata/cmd/appdata/main.go +++ b/samples-go/appdata/cmd/appdata/main.go @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ + package main import "fmt" diff --git a/samples-go/appdata/configs/package-assets/sdk-go-appdata.package-manifest.json b/samples-go/appdata/configs/package-assets/sdk-go-appdata.package-manifest.json index 4fe52cfe0..aa1b1ba6f 100644 --- a/samples-go/appdata/configs/package-assets/sdk-go-appdata.package-manifest.json +++ b/samples-go/appdata/configs/package-assets/sdk-go-appdata.package-manifest.json @@ -1,15 +1,15 @@ { "$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.schema.json", "version": "1.0.0", - "id": "ctrlx-go-appdata", + "id": "sdk-go-appdata", "services": { "proxyMapping": [ { - "name": "ctrlx-go-appdata.web", - "url": "/ctrlx-go-appdata", - "binding": "unix://{$SNAP_DATA}/package-run/ctrlx-go-appdata/web.sock", + "name": "sdk-go-appdata.web", + "url": "/sdk-go-appdata", + "binding": "unix://{$SNAP_DATA}/package-run/sdk-go-appdata/web.sock", "restricted": [ - "/ctrlx-go-appdata/api/v1" + "/sdk-go-appdata/api/v1" ] } ] @@ -18,33 +18,33 @@ "activeConfiguration": { "load": [ { - "id": "ctrlx-go-appdata", + "id": "sdk-go-appdata", "subject": "Application data of the ctrlX go appdata.sample", - "url": "https://localhost/ctrlx-go-appdata/api/v1/load" + "url": "https://localhost/sdk-go-appdata/api/v1/load" } ], "save": [ { - "id": "ctrlx-go-appdata", + "id": "sdk-go-appdata", "subject": "Application data of the ctrlX go appdata.sample", - "url": "https://localhost/ctrlx-go-appdata/api/v1/save" + "url": "https://localhost/sdk-go-appdata/api/v1/save" } ] } }, "scopes-declaration": [ { - "identifier": "ctrlx-go-appdata.web", - "name": "ctrlx-go-appdata", - "description": "ctrlx-go-appdata permissions", + "identifier": "sdk-go-appdata.web", + "name": "sdk-go-appdata", + "description": "sdk-go-appdata permissions", "scopes": [ { - "identifier": "ctrlx-go-appdata.web.rwx", + "identifier": "sdk-go-appdata.web.rwx", "name": "Manage AppData Sample", "description": "" }, { - "identifier": "ctrlx-go-appdata.web.r", + "identifier": "sdk-go-appdata.web.r", "name": "View AppData Sample", "description": "" } @@ -57,9 +57,8 @@ "name": "AppDataSampleGo", "description": "Application data of the ctrlX go appdata.sample", "icon": "bosch-ic-directory", - "scopes": [ - ], - "copyOnLoad": true + "scopes": [], + "copyOnLoad": true } ] } diff --git a/samples-go/appdata/go.mod b/samples-go/appdata/go.mod index 4a7fa7ed4..dd0e41a6a 100644 --- a/samples-go/appdata/go.mod +++ b/samples-go/appdata/go.mod @@ -1,5 +1,5 @@ module samples-go/appdata -go 1.19 +go 1.20 require github.com/golang-jwt/jwt v3.2.2+incompatible diff --git a/samples-go/appdata/snap/snapcraft.yaml b/samples-go/appdata/snap/snapcraft.yaml index 72d3d4fcc..5cab350c0 100644 --- a/samples-go/appdata/snap/snapcraft.yaml +++ b/samples-go/appdata/snap/snapcraft.yaml @@ -4,13 +4,13 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: sdk-go-appdata -version: '2.0.0' +version: '3.0.0' summary: Application data sample written in go for ctrlX description: | - This sample demonstrates how to persist your application data in ctrlX environment + This sample demonstrates how to persist your application data in ctrlX CORE grade: stable confinement: strict -base: core20 +base: core22 apps: app: diff --git a/samples-go/datalayer.client.ext/.vscode/tasks.json b/samples-go/datalayer.client.ext/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-go/datalayer.client.ext/.vscode/tasks.json +++ b/samples-go/datalayer.client.ext/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-go/datalayer.client.ext/README.md b/samples-go/datalayer.client.ext/README.md index 2f6219cf6..4ff364a44 100644 --- a/samples-go/datalayer.client.ext/README.md +++ b/samples-go/datalayer.client.ext/README.md @@ -10,7 +10,7 @@ The app connects to the ctrlX Data Layer using either port 8443 or 443. A subscription is used to get values by data change event in a deterministic publish interval. The single read is performed every 10 seconds in an endless loop. -If the Data Layer connection breaks the app will exit. After 10s it will be automatically restarted by snapd. +If the ctrlX Data Layer connection breaks the app will exit. After 10s it will be automatically restarted by snapd. ## Prerequisites @@ -36,24 +36,5 @@ This application needs "sdk-cpp-alldata" as provider. ## License -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-go/datalayer.client.ext/build-snap-amd64.sh b/samples-go/datalayer.client.ext/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-go/datalayer.client.ext/build-snap-amd64.sh +++ b/samples-go/datalayer.client.ext/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-go/datalayer.client.ext/build-snap-arm64.sh b/samples-go/datalayer.client.ext/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-go/datalayer.client.ext/build-snap-arm64.sh +++ b/samples-go/datalayer.client.ext/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-go/datalayer.client.ext/pkg/client/bulk.go b/samples-go/datalayer.client.ext/pkg/client/bulk.go index c76d0dfa1..27b74755c 100644 --- a/samples-go/datalayer.client.ext/pkg/client/bulk.go +++ b/samples-go/datalayer.client.ext/pkg/client/bulk.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2023 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package client diff --git a/samples-go/datalayer.client.ext/pkg/client/calldatalayerclient.go b/samples-go/datalayer.client.ext/pkg/client/calldatalayerclient.go index 897e6b428..f3f8b529a 100644 --- a/samples-go/datalayer.client.ext/pkg/client/calldatalayerclient.go +++ b/samples-go/datalayer.client.ext/pkg/client/calldatalayerclient.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2023 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package client diff --git a/samples-go/datalayer.client.ext/pkg/client/subscription.go b/samples-go/datalayer.client.ext/pkg/client/subscription.go index 4652228d8..5918d45b0 100644 --- a/samples-go/datalayer.client.ext/pkg/client/subscription.go +++ b/samples-go/datalayer.client.ext/pkg/client/subscription.go @@ -1,25 +1,7 @@ -/** - * MIT License - * - * Copyright (c) 2021-2023 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package client diff --git a/samples-go/datalayer.client.ext/snap/snapcraft.yaml b/samples-go/datalayer.client.ext/snap/snapcraft.yaml index f9c753485..790fa9e98 100644 --- a/samples-go/datalayer.client.ext/snap/snapcraft.yaml +++ b/samples-go/datalayer.client.ext/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: sdk-go-client-ext -base: core20 +base: core22 version: '0.1' summary: ctrlX Data Layer client sample written in Go description: | diff --git a/samples-go/datalayer.client/.vscode/tasks.json b/samples-go/datalayer.client/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-go/datalayer.client/.vscode/tasks.json +++ b/samples-go/datalayer.client/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-go/datalayer.client/README.md b/samples-go/datalayer.client/README.md index 04e42a059..dbf70d488 100644 --- a/samples-go/datalayer.client/README.md +++ b/samples-go/datalayer.client/README.md @@ -10,7 +10,7 @@ The app connects to the ctrlX Data Layer using either port 8443 or 443. A subscription is used to get values by data change event in a deterministic publish interval. The single read is performed every 10 seconds in an endless loop. -If the Data Layer connection breaks the app will exit. After 10s it will be automatically restarted by snapd. +If the ctrlX Data Layer connection breaks the app will exit. After 10s it will be automatically restarted by snapd. ## Prerequisites @@ -36,24 +36,5 @@ This application needs "sdk-cpp-alldata" as provider. ## License -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-go/datalayer.client/build-snap-amd64.sh b/samples-go/datalayer.client/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-go/datalayer.client/build-snap-amd64.sh +++ b/samples-go/datalayer.client/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-go/datalayer.client/build-snap-arm64.sh b/samples-go/datalayer.client/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-go/datalayer.client/build-snap-arm64.sh +++ b/samples-go/datalayer.client/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-go/datalayer.client/cmd/datalayerclient/client.go b/samples-go/datalayer.client/cmd/datalayerclient/client.go index 31efe159b..7a646ffc6 100644 --- a/samples-go/datalayer.client/cmd/datalayerclient/client.go +++ b/samples-go/datalayer.client/cmd/datalayerclient/client.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2023 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package main @@ -39,7 +21,7 @@ func main() { system := datalayer.NewSystem("") defer datalayer.DeleteSystem(system) - fmt.Println("INFO starting Data Layer system") + fmt.Println("INFO starting ctrlX Data Layer system") system.Start(false) // Try SSL port 8443 @@ -59,7 +41,7 @@ func main() { } // client connected - fmt.Println("INFO creating Data Layer client instance") + fmt.Println("INFO creating ctrlX Data Layer client instance") callClient := dlc.NewCallDatalayerClient(c) @@ -71,7 +53,7 @@ func main() { dlc.DeleteCallDatalayerClient(callClient) system.Stop(false) - fmt.Println("INFO stopping Data Layer system") + fmt.Println("INFO stopping ctrlX Data Layer system") } // This is the connection string for TCP in the format: tcp://USER:PASSWORD@IP_ADDRESS:2070?sslport=SSL_PORT @@ -79,10 +61,10 @@ func main() { // // - USER: Enter your user name here - default is boschrexroth // - PASSWORD: Enter your password here - default is boschrexroth -// - IP_ADDRESS: 127.0.0.1 If you develop in WSL and you want to connect to a ctrlX CORE virtual with port forwarding -// 10.0.2.2 If you develop in a VM (Virtual Box, QEMU,...) and you want to connect to a ctrlX virtual with port forwarding -// 192.168.1.1 If you are using a ctrlX CORE or ctrlX CORE virtual with TAP adpater -// - SSL_PORT: 8443 If you use a ctrlX virtual with default port forwarding +// - IP_ADDRESS: 127.0.0.1 If you develop in WSL and you want to connect to a ctrlX COREvirtual with port forwarding +// 10.0.2.2 If you develop in a VM (Virtual Box, QEMU,...) and you want to connect to a ctrlX COREvirtual with port forwarding +// 192.168.1.1 If you are using a ctrlX CORE or ctrlX COREvirtual with TAP adpater +// - SSL_PORT: 8443 If you use a ctrlX COREvirtual with default port forwarding // Connection address dependent on the runtime func getClientConnection(p int) string { diff --git a/samples-go/datalayer.client/pkg/client/calldatalayerclient.go b/samples-go/datalayer.client/pkg/client/calldatalayerclient.go index c1a19f421..94f996a4b 100644 --- a/samples-go/datalayer.client/pkg/client/calldatalayerclient.go +++ b/samples-go/datalayer.client/pkg/client/calldatalayerclient.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2023 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package client @@ -204,7 +186,9 @@ func (c *CallDatalayerClient) readAsync() { rc := func(res datalayer.Result, v *datalayer.Variant) { val := datalayer.NewVariant() - v.Copy(val) + if res == datalayer.ResultOk { + v.Copy(val) + } done <- callbackvalue{res: res, val: val} } @@ -235,7 +219,9 @@ func (c *CallDatalayerClient) createAsync() { rc := func(res datalayer.Result, v *datalayer.Variant) { val := datalayer.NewVariant() - v.Copy(val) + if res == datalayer.ResultOk { + v.Copy(val) + } done <- callbackvalue{res: res, val: val} } @@ -269,7 +255,9 @@ func (c *CallDatalayerClient) removeAsync() { rc := func(res datalayer.Result, v *datalayer.Variant) { val := datalayer.NewVariant() - v.Copy(val) + if res == datalayer.ResultOk { + v.Copy(val) + } done <- callbackvalue{res: res, val: val} } v := datalayer.NewVariant() @@ -306,7 +294,9 @@ func (c *CallDatalayerClient) browseAsync() { rc := func(res datalayer.Result, v *datalayer.Variant) { val := datalayer.NewVariant() - v.Copy(val) + if res == datalayer.ResultOk { + v.Copy(val) + } done <- callbackvalue{res: res, val: val} } @@ -332,7 +322,9 @@ func (c *CallDatalayerClient) writeAsync() { rc := func(res datalayer.Result, v *datalayer.Variant) { val := datalayer.NewVariant() - v.Copy(val) + if res == datalayer.ResultOk { + v.Copy(val) + } done <- callbackvalue{res: res, val: val} } diff --git a/samples-go/datalayer.client/snap/snapcraft.yaml b/samples-go/datalayer.client/snap/snapcraft.yaml index 606f1e14a..9d244ead6 100644 --- a/samples-go/datalayer.client/snap/snapcraft.yaml +++ b/samples-go/datalayer.client/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: sdk-go-client -base: core20 +base: core22 version: '0.2' summary: ctrlX Data Layer client sample written in Go description: | diff --git a/samples-go/datalayer.provider/.vscode/tasks.json b/samples-go/datalayer.provider/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-go/datalayer.provider/.vscode/tasks.json +++ b/samples-go/datalayer.provider/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-go/datalayer.provider/README.md b/samples-go/datalayer.provider/README.md index 0953220ad..6b843b39e 100644 --- a/samples-go/datalayer.provider/README.md +++ b/samples-go/datalayer.provider/README.md @@ -2,13 +2,13 @@ ## Introduction -The app demonstrates how a Data Layer connecion is established and a string and flatbuffers node are provided. +The app demonstrates how a ctrlX Data Layer connecion is established and a string and flatbuffers node are provided. ## Function Description The app connects to the ctrlX Data Layer and provides a string and flatbuffers node . -If the Data Layer connection breaks the app will exit. After 10s it will be automatically restarted by snapd. +If the ctrlX Data Layer connection breaks the app will exit. After 10s it will be automatically restarted by snapd. ## Prerequisites @@ -26,17 +26,13 @@ This app uses a flatbuffer defined in the schema file sampleSchema.fbs. From thi This tool is provided by this SDK under /bin/oss.flatbuffers/..insert OS version here../release/ -Do following steps - OS version here is 'ubuntu20-gcc-x64': - -* `chmod +x ../../bin/oss.flatbuffers/ubuntu20-gcc-x64/release/flatc` - * Create a binary flatbuffers file: - `../../bin/oss.flatbuffers/ubuntu20-gcc-x64/release/flatc -o bfbs/ -b --schema fbs/sampleSchema.fbs` + `/flatc -o bfbs/ -b --schema fbs/sampleSchema.fbs` * Generate the Go code: - `../../bin/oss.flatbuffers/ubuntu20-gcc-x64/release/flatc --go fbs/sampleSchema.fbs` + `/flatc --go fbs/sampleSchema.fbs` The generated code is stored in sample/schema/InertialValue.go @@ -50,24 +46,5 @@ Build the snap with `snapcraft --destructive-mode` ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-go/datalayer.provider/build-snap-amd64.sh b/samples-go/datalayer.provider/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-go/datalayer.provider/build-snap-amd64.sh +++ b/samples-go/datalayer.provider/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-go/datalayer.provider/build-snap-arm64.sh b/samples-go/datalayer.provider/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-go/datalayer.provider/build-snap-arm64.sh +++ b/samples-go/datalayer.provider/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-go/datalayer.provider/cmd/provider/main.go b/samples-go/datalayer.provider/cmd/provider/main.go index 2e0087708..ea01ff3ff 100644 --- a/samples-go/datalayer.provider/cmd/provider/main.go +++ b/samples-go/datalayer.provider/cmd/provider/main.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package main diff --git a/samples-go/datalayer.provider/pkg/node/nodearraytimestamp.go b/samples-go/datalayer.provider/pkg/node/nodearraytimestamp.go index 6ba2292c6..c81d7020a 100644 --- a/samples-go/datalayer.provider/pkg/node/nodearraytimestamp.go +++ b/samples-go/datalayer.provider/pkg/node/nodearraytimestamp.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package node diff --git a/samples-go/datalayer.provider/pkg/node/nodedata.go b/samples-go/datalayer.provider/pkg/node/nodedata.go index efb527827..99c668ecf 100644 --- a/samples-go/datalayer.provider/pkg/node/nodedata.go +++ b/samples-go/datalayer.provider/pkg/node/nodedata.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package node diff --git a/samples-go/datalayer.provider/pkg/node/nodefbs.go b/samples-go/datalayer.provider/pkg/node/nodefbs.go index 28cf885b8..93d695338 100644 --- a/samples-go/datalayer.provider/pkg/node/nodefbs.go +++ b/samples-go/datalayer.provider/pkg/node/nodefbs.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package node diff --git a/samples-go/datalayer.provider/pkg/node/nodestring.go b/samples-go/datalayer.provider/pkg/node/nodestring.go index 40eef5b83..1f5beef44 100644 --- a/samples-go/datalayer.provider/pkg/node/nodestring.go +++ b/samples-go/datalayer.provider/pkg/node/nodestring.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package node diff --git a/samples-go/datalayer.provider/pkg/node/nodetimestamp.go b/samples-go/datalayer.provider/pkg/node/nodetimestamp.go index 3b3e956c8..6f7458a76 100644 --- a/samples-go/datalayer.provider/pkg/node/nodetimestamp.go +++ b/samples-go/datalayer.provider/pkg/node/nodetimestamp.go @@ -1,25 +1,7 @@ -/** - * MIT License +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package node diff --git a/samples-go/datalayer.provider/pkg/utils/connectionbuilder.go b/samples-go/datalayer.provider/pkg/utils/connectionbuilder.go index bf537687e..7a185c8f8 100644 --- a/samples-go/datalayer.provider/pkg/utils/connectionbuilder.go +++ b/samples-go/datalayer.provider/pkg/utils/connectionbuilder.go @@ -1,25 +1,7 @@ -/** - * MIT License - * - * Copyright (c) 2021-2022 Bosch Rexroth AG - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * SPDX-License-Identifier: MIT */ package utils @@ -51,17 +33,17 @@ import ( * * Here some examples: * -* 1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +* 1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: * * var connection = utils.NewConnectionBuilder().Ip("192.168.1.100").User("admin").Password("-$_U/{X$aG}Z3/e<"").Build() * -* 2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +* 2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): * * var connection = utils.NewConnectionBuilder().Ip("10.0.2.2").SslPort(443).Build() * * Remarks: * 10.0.2.2 is the IP address of the host from the point of view of the app build environment(QEMU VM). -* 8443 is the host port which is forwarded to the SSL port(=433) of the ctrlX CORE virtual +* 8443 is the host port which is forwarded to the SSL port(=433) of the ctrlX COREvirtual * * IMPORTANT: * You need not change the parameter settings before building a snap and installing the snap on a ctrlX CORE. @@ -86,13 +68,13 @@ func NewConnectionBuilder() *ConnectionBuilder { return cb } -// IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding +// IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding func (cb *ConnectionBuilder) Ip(ip string) *ConnectionBuilder { cb.ip = ip return cb } -// Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual +// Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual func (cb *ConnectionBuilder) SslPort(sslPort int) *ConnectionBuilder { cb.sslPort = sslPort return cb diff --git a/samples-go/datalayer.provider/snap/snapcraft.yaml b/samples-go/datalayer.provider/snap/snapcraft.yaml index 034cc978d..9c62db1d4 100644 --- a/samples-go/datalayer.provider/snap/snapcraft.yaml +++ b/samples-go/datalayer.provider/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: sdk-go-provider -base: core20 +base: core22 version: '1.0' summary: ctrlX Data Layer provider sample written in Go description: | diff --git a/samples-go/hello.webserver/.vscode/launch.json b/samples-go/hello.webserver/.vscode/launch.json index 1345ff1aa..38f5c7407 100644 --- a/samples-go/hello.webserver/.vscode/launch.json +++ b/samples-go/hello.webserver/.vscode/launch.json @@ -9,7 +9,8 @@ "type": "go", "request": "launch", "mode": "auto", - "program": "${workspaceRoot}/webserver" + "program": "${workspaceRoot}/cmd/webserver/main.go", + "cwd": "${workspaceRoot}" } ] } \ No newline at end of file diff --git a/samples-go/hello.webserver/.vscode/tasks.json b/samples-go/hello.webserver/.vscode/tasks.json index 381529449..ac2c3f4eb 100644 --- a/samples-go/hello.webserver/.vscode/tasks.json +++ b/samples-go/hello.webserver/.vscode/tasks.json @@ -13,7 +13,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -26,11 +26,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -39,11 +39,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -52,7 +52,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -66,7 +66,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -100,7 +100,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -133,12 +133,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -149,7 +145,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -186,12 +182,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-go/hello.webserver/LICENSE b/samples-go/hello.webserver/LICENSE deleted file mode 100644 index 78b442521..000000000 --- a/samples-go/hello.webserver/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020, Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-go/hello.webserver/README.md b/samples-go/hello.webserver/README.md index 2f4120d40..76f180035 100644 --- a/samples-go/hello.webserver/README.md +++ b/samples-go/hello.webserver/README.md @@ -1,56 +1,37 @@ -# Example hello.webserver - -The sample __hello-webserver__ contains simple webserver. - -## Introduction - -## Pre-requisites - -* Recommended: ctrlX WORKS App Build Environment (QEMU Virtual Machine) - see Setup -* ctrlX COREvirtual or ctrlX CORE - -## Getting Started - -1. Launch Visual Studio Code -2. Open the sample directory `samples-go/hello-webserver` -3. Build and install the snap as described in `Setup` section -4. Check output in the web interface - -## Detailed Informations - -For the best webserver integration take a look at [package-assets](../../package-assets.md) - -## Screenshots - -![Landingpage](./docs/images/landingpage.png) - -## Support - -If you've any questions visit the [ctrlX AUTOMATION Community](https://developer.community.boschrexroth.com/) - -___ - -## License - -MIT License - -Copyright (c) 2020 - 2021, Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - +# Example hello.webserver + +The sample __hello-webserver__ contains simple webserver. + +## Introduction + +## Pre-requisites + +* Recommended: ctrlX WORKS App Build Environment (QEMU Virtual Machine) - see Setup +* ctrlX COREvirtual or ctrlX CORE + +## Getting Started + +1. Launch Visual Studio Code +2. Open the sample directory `samples-go/hello-webserver` +3. Build and install the snap as described in `Setup` section +4. Check output in the web interface + +## Detailed Informations + +For the best webserver integration take a look at [package-assets](../../package-assets.md) + +## Screenshots + +![Landingpage](./docs/images/landingpage.png) + +## Support + +If you've any questions visit the [ctrlX AUTOMATION Community](https://developer.community.boschrexroth.com/) + +___ + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT + diff --git a/samples-go/hello.webserver/build-snap-amd64.sh b/samples-go/hello.webserver/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-go/hello.webserver/build-snap-amd64.sh +++ b/samples-go/hello.webserver/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-go/hello.webserver/build-snap-arm64.sh b/samples-go/hello.webserver/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-go/hello.webserver/build-snap-arm64.sh +++ b/samples-go/hello.webserver/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-go/hello.webserver/cmd/webserver/main.go b/samples-go/hello.webserver/cmd/webserver/main.go index fa3b166b1..f48d0f14d 100644 --- a/samples-go/hello.webserver/cmd/webserver/main.go +++ b/samples-go/hello.webserver/cmd/webserver/main.go @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ package main import ( @@ -17,7 +22,7 @@ func main() { if _, snapped = os.LookupEnv("SNAP"); !snapped { fmt.Printf("App is running as external Application (Debug)") dir, _ := os.Getwd() - www = filepath.FromSlash(filepath.Join(filepath.Dir(dir), "www")) + www = filepath.FromSlash(filepath.Join(dir, "www")) } else { fmt.Printf("App is running as snap inside ctrlX") www = filepath.FromSlash(filepath.Join(os.Getenv("SNAP"), "www")) diff --git a/samples-go/hello.webserver/configs/package-assets/rexroth-hello-webserver.package-manifest.json b/samples-go/hello.webserver/configs/package-assets/rexroth-hello-webserver.package-manifest.json index 6526cbcf6..0129ff71a 100644 --- a/samples-go/hello.webserver/configs/package-assets/rexroth-hello-webserver.package-manifest.json +++ b/samples-go/hello.webserver/configs/package-assets/rexroth-hello-webserver.package-manifest.json @@ -1,4 +1,5 @@ { + "$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.schema.json", "version": "1.0.0", "id": "hello-webserver", "services": { diff --git a/samples-go/hello.webserver/snap/snapcraft.yaml b/samples-go/hello.webserver/snap/snapcraft.yaml index 3f2085ce4..1727a5917 100644 --- a/samples-go/hello.webserver/snap/snapcraft.yaml +++ b/samples-go/hello.webserver/snap/snapcraft.yaml @@ -10,7 +10,7 @@ summary: Simple Go-Webserver description: This sample app shows how to create a webserver app in ctrlX CORE grade: stable confinement: strict -base: core20 +base: core22 apps: my-server: diff --git a/samples-go/tpm2.srk/README.md b/samples-go/tpm2.srk/README.md index f6e43378e..9eb5ea601 100644 --- a/samples-go/tpm2.srk/README.md +++ b/samples-go/tpm2.srk/README.md @@ -26,24 +26,5 @@ ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-go/tpm2.srk/cmd/tpm2/main.go b/samples-go/tpm2.srk/cmd/tpm2/main.go index a97fed0d2..86c9db531 100644 --- a/samples-go/tpm2.srk/cmd/tpm2/main.go +++ b/samples-go/tpm2.srk/cmd/tpm2/main.go @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ package main import ( diff --git a/samples-go/tpm2.srk/cmd/tpm2/util/util.go b/samples-go/tpm2.srk/cmd/tpm2/util/util.go index 78290b9e3..cfb8fba11 100644 --- a/samples-go/tpm2.srk/cmd/tpm2/util/util.go +++ b/samples-go/tpm2.srk/cmd/tpm2/util/util.go @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ package util import ( diff --git a/samples-go/webdav.client/README.md b/samples-go/webdav.client/README.md index dae931d7b..55b4605df 100644 --- a/samples-go/webdav.client/README.md +++ b/samples-go/webdav.client/README.md @@ -2,7 +2,7 @@ ## Introduction -The sample demonstrates how to access to configuration files of a ctrlX device remotely using the WebDAV protocol. +The sample demonstrates how to access to configuration files of a ctrlX CORE remotely using the WebDAV protocol. ## Function Description @@ -22,24 +22,5 @@ Build the executable with `go build ./cmd/...` ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-go/webdav.client/cmd/client/main.go b/samples-go/webdav.client/cmd/client/main.go index daa4ce03d..95cacc16f 100644 --- a/samples-go/webdav.client/cmd/client/main.go +++ b/samples-go/webdav.client/cmd/client/main.go @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ package main import ( diff --git a/samples-iec61131/fbs-read-write/README.md b/samples-iec61131/fbs-read-write/README.md index 983bfc8a1..88b790533 100644 --- a/samples-iec61131/fbs-read-write/README.md +++ b/samples-iec61131/fbs-read-write/README.md @@ -1,36 +1,49 @@ # Using Flatbuffers in IEC 61131-3 ST Code -Using Flatbuffers in IEC 61131-3 Code is described [here](../../fbs2plc.md). +The ctrlX data layer contains many nodes that provide their data in Flatbuffers. -## Files +The sample shows how a Flatbuffers node can be read, changed and written. -This folder contains files to be used in the described workflow: +## Prequisites for your Windows host -* __start.bat__ - Starts the command line tool fbs2plc.exe provided with all necessary parameters. -* __ctrlXVirtual.export__ - Contains a ready to compile PLC program. +* ctrlX WORKS >= 2.3.0 installed +* ctrlX PLC Engineering >= 2.3.0 installed +* ctrlX COREvirtual with running app PLC +* ctrlX AUTOMATION SDK >= 2.2.0 installed -___ -## License +## Steps to build and download the PLC project + +We describe the usage of a ctrlX COREvirtual. + +* Start ctrlX PLC Engineering. +* Create a new project, use __ctrlX CORE x64 Project__ as template. +* Within the device view select the node Application and delete it. +* Select node PLC Logic. +* Select main menu item Project -> PLCOpenXML import +* From ctrlX AUTOMATION SDK select file __samples-iec61131\fbs-read-write\fbs-datalayer-subscriptions-settings.xml__ +* Import complete content. +* Select PLC node Libray Manager +* Delete placeholder StringUtils and add the library with the same name. +* Select PLC node Application, right click and select context menu item 'Import from Flatbuffers File...' +* From ctrlX AUTOMATION SDK select file __fbs\comm\datalayer\sub_settings.fbs__. -MIT License +The fbs file is compiled into IEC61131 Structed Text and imported into your PLC project. -Copyright (c) 2021-2022 Bosch Rexroth AG +* Compile the project - there should by no error +* Connect your PLC device node with the COREvirtual +* Login (download) and start your PLC project. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +## Test the project -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +* Open a web browser, log in into your ctrlX COREvirtual +* Select Settings - Data layer +* Select node datalayer/subscriptions/settings + +The value of maximumBufferSize should be changed by your PLC project. +___ + +## License -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-iec61131/fbs-read-write/ctrlxVirtual.export b/samples-iec61131/fbs-read-write/ctrlxVirtual.export deleted file mode 100644 index 0645bc3c5..000000000 --- a/samples-iec61131/fbs-read-write/ctrlxVirtual.export +++ /dev/null @@ -1,6374 +0,0 @@ - - - - - - - True - - 6f3aacde-2588-4b29-b06e-da191dcc3c67 - 00000000-0000-0000-0000-000000000000 - Device - - - - cdadfc2b-8598-4621-ad56-5b1df7db910f - - - - - 4096 - 1001 0081 - 1.14.0.0 - - - - - - - 225bfe47-7336-4dbc-9419-4105a7c831fa - - 637884947258643193 - - - 4107 - - False - - 4096 - 1001 0081 - 1.14.0.0 - - - - ctrlX COREvirtual - ctrlX COREvirtual -Eingänge: 8192 -Ausgänge: 8192 -Merker: 8192 -Remanenter Speicher: default 64KB auf 128KB konfigurierbar - - Bosch Rexroth AG - dependent on customer specific configuration - ABAAAA== - - - - - - - - False - 2147483920 - None - None - True - False - None - None - True - - - local - UseSchedPrio - Use scheduler priority - - - local - UseSchedPrio.Desc - Use scheduler priority as IEC task priority. - - - - - - True - - - - - - - - - - - - True - BOOL - True - 2147483920 - - - 4100 - 4101 - None - None - - -1 - False - std:BOOL - - False - - OnlyIfUnused - - False - False - False - False - False - False - False - False - False - False - False - 0 - False - False - 0 - 0 - - - 4d35f877-7f96-5b61-9bfa-626c68a10935 - - False - - OnlyIfUnused - False - - False - False - - - - - - - - BRC:DataLayer - - 00000000-0000-0000-0000-000000000000 - False - 42400 - BRC:DataLayer - Parent - 0 - -1 - - - - - - 42420 - 1001 0000 - 1.8.0.0 - $(DeviceName) - - - - f37f42d0-39c3-4517-a10d-f32bfdec9649 - - - - - - - b7bf3882-446f-5ee2-89c3-30790e62589f - - False - - OnlyIfUnused - False - - 00000000-0000-0000-0000-000000000000 - - - - False - - 00000000-0000-0000-0000-000000000000 - False - BhAAAAAAAAAHEAAAAAAAAAgQAAAAAAAA - False - False - False - False - 0 - False - Enabled - False - False - False - False - False - False - KeepCurrentValues - - 00000000-0000-0000-0000-000000000000 - False - OnlyIfUnused - - - -1 - - - - False - True - - - False - - 1 - False - OnlyIfUnused - 0 - - False - - 0 - 0 - 0 - 00000000-0000-0000-0000-000000000000 - - -1 - False - - - - - - Common.PCI - - 00000000-0000-0000-0000-000000000000 - False - 256 - Common.PCI - Parent - 1 - -1 - - - - - 2147483647 - - - - - - 32cbc6a8-e4fa-5573-94b8-86676d660342 - - False - - OnlyIfUnused - False - - 00000000-0000-0000-0000-000000000000 - - - - False - - 00000000-0000-0000-0000-000000000000 - False - CRAAAAAAAAAKEAAAAAAAAAsQAAAAAAAA - False - False - False - False - 0 - False - Enabled - False - False - False - False - False - False - KeepCurrentValues - - 00000000-0000-0000-0000-000000000000 - False - OnlyIfUnused - - - -1 - - - - False - True - - - False - - 1 - False - OnlyIfUnused - 0 - - False - - 0 - 0 - 0 - 00000000-0000-0000-0000-000000000000 - - -1 - False - - - - - - - - StdCommunicationLink - - - True - - - - - - False - 1 - 0 - 5 - 6e14de9e-7d40-42d3-89b9-fa2e2676b96d - - - - Azk= - - - IAA= - - - IiQ= - - - fwA= - - - AAE= - - - - False - False - False - False - VirtualControl-1-14 - 200 - - VirtualControl-1-14 - 127.0.0.1:8740 - 1001 0081 - ctrlX COREvirtual - 4096 - Bosch Rexroth AG - 1.14.0.0 - - True - False - - - - - - - - - 00000000-0000-0000-0000-000000000000 - - - - IoStandard - System - 3.5.17.0 - iostandardlib - - IoStandard - True - False - False - - - - CXAC_Base - Bosch Rexroth - 0.0.0.0 - cxa_base - - CXA_BASE - True - False - False - - - - CXA_CommonTypes - Bosch Rexroth - 0.0.0.0 - cxa_commontypes - - CXA_COMMONTYPES - True - False - False - - - - CXA_Utilities - Bosch Rexroth - 0.0.0.0 - cxa_utilities - - CXA_UTILITIES - True - False - False - - - - Standard - System - 0.0.0.0 - standardlib - - Standard - True - False - False - - - - - False - - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - True - ARAAAAAAAAACEAAAAAAAAAMQAAAAAAAA - False - False - False - False - 0 - False - Enabled - False - False - False - False - False - True - SetToDefault - - 00000000-0000-0000-0000-000000000000 - False - OnlyIfUnused - - - b940ef4e-51f8-5fb0-97f6-89f9762ef47d - 1d5e6cc9-6030-5004-ac00-1b67b912c1e8 - 1360a5bc-f99b-5a45-b580-e0239746a9eb - 57346d06-f4f4-5f02-8a5a-2fccf745fb4f - -1 - - - 40b404f9-e5dc-42c6-907f-c89f4a517386 - - - - False - - - 6f3aacde-2588-4b29-b06e-da191dcc3c67 - False - False - - http://www.ctrlx-automation.com - -1 - False - False - - - - -1 - - False - False - - - - 00000000-0000-0000-0000-000000000000 - - -1 - - - False - - f07bbb24-2727-44f6-8d9d-387d89dfd7bb - 6f3aacde-2588-4b29-b06e-da191dcc3c67 - Plc Logic - - 40b404f9-e5dc-42c6-907f-c89f4a517386 - - 637871887878440296 - - - 6f3aacde-2588-4b29-b06e-da191dcc3c67 - - Device - - 0 - - - False - - f37f42d0-39c3-4517-a10d-f32bfdec9649 - 6f3aacde-2588-4b29-b06e-da191dcc3c67 - Realtime_Data - - - - cdadfc2b-8598-4621-ad56-5b1df7db910f - - - - - 42420 - 1001 0000 - 1.8.0.0 - $(DeviceName) - - - - - - 225bfe47-7336-4dbc-9419-4105a7c831fa - - 637871887911580992 - - - 4105 - - False - - 42420 - 1001 0000 - 1.8.0.0 - $(DeviceName) - - - DataLayer - DataLayer - Bosch Rexroth AG - - tKUAAA== - - 1001:4 - - - Realtime_Data - - - - a3987221-be16-5b18-a4b4-edcad8b7bded - - False - - OnlyIfUnused - False - - False - False - - - - - - local - DataLayerClients - DataLayer - - 00000000-0000-0000-0000-000000000000 - False - 42420 - BRC:DataLayer - Child - 0 - -1 - - - - False - - - 6f3aacde-2588-4b29-b06e-da191dcc3c67 - - False - 0 - - False - - - - - - ddf74280-b8ac-5ce1-a88d-c7486d4977fa - - False - - OnlyIfUnused - False - - 00000000-0000-0000-0000-000000000000 - - - - False - - 00000000-0000-0000-0000-000000000000 - False - BBAAAAAAAAAFEAAAAAAAAAYQAAAAAAAA - False - False - False - False - 0 - False - Enabled - False - False - False - False - False - False - KeepCurrentValues - - 00000000-0000-0000-0000-000000000000 - False - OnlyIfUnused - - - -1 - - - - False - True - - - False - - 1 - False - OnlyIfUnused - 0 - - False - - 0 - 0 - 0 - 00000000-0000-0000-0000-000000000000 - - -1 - False - - - - local - DataLayerUser - DataLayerUser - - 00000000-0000-0000-0000-000000000000 - False - 42421 - BRC:DataLayerPath - Parent - 1 - -1 - - - - - 2147483647 - - - - - - 296e8bbf-d6e6-5409-8820-8b1e57262cd4 - - False - - OnlyIfUnused - False - - 00000000-0000-0000-0000-000000000000 - - - - False - - 00000000-0000-0000-0000-000000000000 - False - BxAAAAAAAAAIEAAAAAAAAAkQAAAAAAAA - False - False - False - False - 0 - False - Enabled - False - False - False - False - False - False - KeepCurrentValues - - 00000000-0000-0000-0000-000000000000 - False - OnlyIfUnused - - - -1 - - - - True - True - - - False - - 1 - False - OnlyIfUnused - 0 - - False - - 0 - 0 - 0 - 00000000-0000-0000-0000-000000000000 - - -1 - False - - - - - - - - False - 1 - 0 - 5 - 00000000-0000-0000-0000-000000000000 - - False - False - False - False - - 200 - - False - False - - - - - - - - - 00000000-0000-0000-0000-000000000000 - - - - False - - 00000000-0000-0000-0000-000000000000 - False - ARAAAAAAAAACEAAAAAAAAAMQAAAAAAAA - False - False - False - False - 0 - False - Enabled - False - False - False - False - False - False - KeepCurrentValues - - 00000000-0000-0000-0000-000000000000 - False - OnlyIfUnused - - - df92c2b2-3ded-50bd-99ce-ce73683079dd - 407e8c2a-8cd4-5b74-9eb9-bd9c909f5d21 - a5b38d34-0621-53e9-b33f-a20c8a144c8b - de43ec7b-e6b1-5d8c-8017-f0fd59996e36 - -1 - - - - - False - - - 6f3aacde-2588-4b29-b06e-da191dcc3c67 - False - False - - - -1 - False - False - - - - -1 - - False - False - - - - 6f3aacde-2588-4b29-b06e-da191dcc3c67 - - Device - - 1 - - - False - - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - f07bbb24-2727-44f6-8d9d-387d89dfd7bb - Application - - 639b491f-5557-464c-af91-1471bac9f549 - - 637871887912990727 - - - -1 - True - False - bbad7477-5d52-460a-b76c-0534bc3e5db5 - 00000000-0000-0000-0000-000000000000 - - True - True - True - True - - False - 0 - 0 - 0 - 0 - False - - - - False - 0 - 0 - False - - f07bbb24-2727-44f6-8d9d-387d89dfd7bb - - Device - SPS-Logik - - -1 - - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - 00000000-0000-0000-0000-000000000000 - CheckFunctions - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - - - - - - - - 738bea1e-99bb-4f04-90bb-a7a567e74e3a - - 637871887915460638 - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - - Device - SPS-Logik - Application - - -1 - - - False - - a3e584b7-7d0d-41e4-ac7b-180d79cc0a66 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - Library Manager - - adb5cb65-8e1d-4a00-b70a-375ea27582f3 - - 637871888176358420 - - - - - IoStandard, 3.5.17.0 (System) - False - - IoStandard - b303f5ce-75ff-4668-a777-7da8debb449c - 769200895 - IoStandard - True - False - False - False - True - - - CXAC_Base, 1.11.0.0 (Bosch Rexroth AG) - False - - CXA_BASE - b303f5ce-75ff-4668-a777-7da8debb449c - 2329531040 - CXAC_Base - True - False - False - False - False - - - CXA_CommonTypes, 1.14.0.0 (Bosch Rexroth AG) - False - - CXA_COMMONTYPES - b303f5ce-75ff-4668-a777-7da8debb449c - 3482163335 - CXA_CommonTypes - True - False - False - False - False - - - CXA_Utilities, 1.14.0.1 (Bosch Rexroth AG) - False - - CXA_UTILITIES - b303f5ce-75ff-4668-a777-7da8debb449c - 258411049 - CXA_Utilities - True - False - False - False - False - - - Standard, 3.5.17.0 (System) - False - - Standard - b303f5ce-75ff-4668-a777-7da8debb449c - 3212985154 - Standard - True - False - False - False - False - - - - False - - CmpLog - b303f5ce-75ff-4668-a777-7da8debb449c - 1194009179 - CmpLog - False - False - False - False - False - - - Breakpoint Logging Functions, 3.5.5.0 (3S - Smart Software Solutions GmbH) - False - - BreakpointLogging - b303f5ce-75ff-4668-a777-7da8debb449c - 484393237 - BPLog - True - False - False - False - False - - - False - - SampleSchema, 0.0.1 (Bosch Rexroth) - 2474330877 - SampleSchema - False - False - False - False - False - - - - - - CBML - - - Common Behaviour Model, 3.5.17.0 (3S - Smart Software Solutions GmbH) - - - - - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - - Device - SPS-Logik - Application - - -1 - - - False - - 63ac73d1-ffba-4b01-9d0e-8b65a8ef1bb5 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - PLC_PRG - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871974258707816 - - - None - - - - - 44 - - IF bStart_read THEN - - - 45 - - bStart_read := FALSE; - - - 46 - - bExecute_read := TRUE; - - - 47 - - END_IF - - - 162 - - - - - 164 - - - - - 48 - - fbDL_ReadNodeValue( - - - 49 - - Execute:= bExecute_read, - - - 50 - - Done=> bDone_read, - - - 51 - - Active=> bActive_read, - - - 52 - - Error=> bErrorRead, - - - 53 - - ErrorID=> ErrorIDRead, - - - 54 - - ErrorIdent=> ErrorIdent_read, - - - 55 - - ClientId:= , - - - 56 - - NodeName:= strNodePath, - - - 57 - - NodeValue:= DataRead); - - - 158 - - - - - 147 - - IF bDone_read AND bExecute_read THEN - - - 186 - - bExecute_read := FALSE; - - - 187 - - - - - 188 - - fbFlatbuffer.getRootAsInertialValue(data:= - - - 189 - - DataRead.GetData(), size:= DataRead.GetSize()); - - - 190 - - - - - 191 - - iRead_X := fbFlatbuffer.getX(); - - - 192 - - iRead_Y := fbFlatbuffer.getY(); - - - 193 - - iRead_Z := fbFlatbuffer.getZ(); - - - 194 - - iRead := iRead + 1; - - - 195 - - - - - 211 - - bStart_write := TRUE; - - - 160 - - END_IF - - - 161 - - - - - 163 - - - - - 73 - - IF bStart_write THEN - - - 154 - - bStart_write := FALSE; - - - 207 - - - - - 204 - - iWrite_X := iRead_X + 100; - - - 205 - - iWrite_Y := iRead_Y + 100; - - - 206 - - iWrite_Z := iRead_Z + 100; - - - 155 - - - - - 74 - - fbBuilder(forceDefaults := TRUE); - - - 75 - - fbFlatbuffer.startInertialValue(fbBuilder); - - - 76 - - fbFlatbuffer.addX(iWrite_X); - - - 77 - - fbFlatbuffer.addY(iWrite_Y); - - - 78 - - fbFlatbuffer.addZ(iWrite_Z); - - - 79 - - fbBuilder.finish(fbFlatbuffer.endInertialValue()); - - - 80 - - fbValueIn.SetFlatbuffer(fbBuilder); - - - 135 - - - - - 150 - - bExecute_write := TRUE; - - - 71 - - END_IF - - - 156 - - - - - 203 - - - - - 85 - - fbDL_WriteNodeValue( - - - 86 - - Execute:= bExecute_write, - - - 87 - - Done=> bDone_write, - - - 88 - - Active=> bActive_write, - - - 89 - - Error=> bError_write, - - - 90 - - ErrorID=> ErrorID_write, - - - 91 - - ErrorIdent=> ErrorIdent_write, - - - 92 - - ClientId:= , - - - 93 - - NodeName:= strNodePath, - - - 94 - - NodeValueIn:= fbValueIn, - - - 95 - - NodeValueOut:= fbValueOut); - - - 100 - - - - - 97 - - IF bDone_write AND bExecute_write THEN - - - 152 - - bExecute_write := FALSE; - - - 117 - - iWritten := iWritten + 1; - - - 209 - - - - - 210 - - bStart_read := TRUE; - - - 70 - - END_IF - - - 208 - - - - - 105 - - - - - - - - - - - 2 - - PROGRAM PLC_PRG - - - 3 - - VAR - - - 8 - - bStart_read: BOOL := TRUE; - - - 126 - - bStart_write: BOOL; - - - 121 - - - - - 127 - - // Read values - - - 9 - - bExecute_read: BOOL; - - - 137 - - fbDL_ReadNodeValue: sampleSchema.DL_ReadNodeValue; - - - 138 - - bActive_read: BOOL; - - - 12 - - bDone_read: BOOL; - - - 136 - - - - - 5 - - DataRead: sampleSchema.DL_NodeValue; - - - 16 - - bErrorRead: BOOL; - - - 17 - - ErrorIDRead: ERROR_CODE; - - - 18 - - ErrorIdent_read: ERROR_STRUCT; - - - 123 - - - - - 19 - - fbR_TRIG_read: R_TRIG; - - - 124 - - - - - 20 - - fbFlatbuffer : sampleSchema.sample_schema_InertialValue; - - - 125 - - - - - 21 - - iRead_X: INT; - - - 22 - - iRead_Y: INT; - - - 23 - - iRead_Z: INT; - - - 13 - - iRead: INT; - - - 24 - - - - - 26 - - ///Write values - - - 28 - - fbBuilder: sampleSchema.FlatBufferBuilder(); - - - 109 - - - - - 29 - - iWrite_X: INT; - - - 30 - - iWrite_Y: INT; - - - 31 - - iWrite_Z: INT; - - - 142 - - iWritten: INT; - - - 110 - - - - - 139 - - bExecute_write: BOOL; - - - 32 - - fbDL_WriteNodeValue: sampleSchema.DL_WriteNodeValue; - - - 140 - - bActive_write: BOOL; - - - 141 - - bDone_write: BOOL; - - - 34 - - fbValueIn: sampleSchema.DL_NodeValue; - - - 35 - - fbValueOut: sampleSchema.DL_NodeValue; - - - 38 - - bError_write: BOOL; - - - 39 - - ErrorID_write: ERROR_CODE; - - - 40 - - ErrorIdent_write: ERROR_STRUCT; - - - 112 - - - - - 41 - - fbR_TRIG_write: R_TRIG; - - - 113 - - - - - 119 - - - - - 120 - - strNodePath: STRING(255) := 'sdk-cpp-alldata/dynamic/fbs'; - - - 42 - - - - - 1 - - END_VAR - - - - - 211 - Standard - - False - - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - - Device - SPS-Logik - Application - - -1 - - - False - - 4ed6029a-ed3f-417e-a394-37731d5c06be - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - Task Configuration - - ae1de277-a207-4a28-9efb-456c06bd52f3 - - 637871887912150678 - - - - - - 5c6dbf25-7bba-5475-a660-329c03b021d9 - 079bfcf3-5e69-541b-a65b-c3e705e48bdc - 5e652b2e-c043-5a37-90cd-fceb952c71e3 - cd55cd36-e3b0-591d-bd91-1a71874eec3d - 44f9d4b5-76d4-5e9d-9f7e-7a5ae3b38629 - 4beb1e06-1ae6-53d3-901c-695e82efb79e - 00c31f2c-3b1f-50e4-a049-ba5c72d4df16 - d95a396a-f8cb-5d38-a528-2ae49f449299 - 65e0ee1b-7749-5896-999d-aac3ca5251a8 - 561dc4da-f2d2-516c-9016-84ea752f2a27 - 26eb94dc-a284-522c-8ae7-719bb309bffd - eb1983e7-2a8e-5a4e-b853-b3b2795f4b17 - df2d910f-b577-509c-9034-ce6017266e3f - 7fe478ab-b580-5b6c-9677-35645da9244d - 396a638f-6867-56f1-866b-8e48d1ea23ea - - - - IEC-Tasks - -2 - True - False - - - d83d35b9-4fb8-5b1f-a2ad-9bbc705ebf6b - 5e442825-31ee-518b-baa9-7021aaed187c - eda58d6f-c1b2-5f06-85c5-d97ba808ccb5 - 5d63ee7e-73f7-56e6-8a65-b435663da4a8 - d702e128-9814-55c4-b8ec-23edf713f079 - 8ecd21b7-b1cb-5c95-a036-11b40995e717 - - 00000000-0000-0000-0000-000000000000 - - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - - Device - SPS-Logik - Application - - -1 - - - False - - 58c0f176-f4bb-46bb-8dab-1ed03dd53ad8 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckDivDInt - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - - 97c1f2ea-5995-48b9-abd5-a3ab983c5def - - - - False - - - - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887917620670 - - - None - - - - - 413 - - (**************************************************************************************************) - - - 414 - - (* The implementation has to be adjusted to your application/machine. *) - - - 415 - - (* This is an exemplary implementation of the function. *) - - - 416 - - (* Per default, an access violation is generated to avoid machine damage *) - - - 417 - - (* Check the Call Stack (menu Debug/Callstack) and modify the faulty logic! *) - - - 418 - - (**************************************************************************************************) - - - 419 - - - - - 420 - - IF divisor = 0 THEN - - - 421 - - strError:= 'CheckDivDInt: Invalid division by 0 - check the callstack'; - - - 422 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 423 - - // Set an error into the plc logger - - - 424 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 425 - - // Triggering an access violation --> Application will be stopped - - - 426 - - ptNull^ := 0;(* Triggering an access violation *) - - - 427 - - - - - 428 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 429 - - // // Set the divisor to 1 - - - 430 - - // // --> no access violation (div by zero) will be triggered - - - 431 - - // // --> keep PLC-task running - - - 432 - - // // Set a warning into the plc logger - - - 433 - - // // NOTE: There is still an implementation error in your application code! - - - 441 - - // - - - 434 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 436 - - // CheckDivDint := 1; //Division by 1 instead of zero - - - 437 - - // return; - - - 438 - - - - - 439 - - ELSE // division is ok - - - 440 - - CheckDivDInt:=divisor; - - - 7 - - END_IF; - - - - - - - - - 380 - - // Short description: Test function to increase machine safety by detecting unauthorized division by zero of INT, UINT, DINT, UDINT, WORD and DWORD variables - - - 381 - - // - - - 382 - - // Functional description: This function will be called implicitly before the division takes places. - - - 383 - - // The divisor will be checked for 0. - - - 384 - - // In case of 0, an error is entered in the plc logger and the application is stopped due to an access violation to avoid machine damage. - - - 385 - - // In this case, check the callstack (menu Debug/Callstack) and modify the faulty logic. - - - 386 - - // - - - 387 - - // Handling particularities: This function increases the cycle time of all tasks using divisions. - - - 388 - - // The increase depends on the number of the divisions. - - - 389 - - // After inserting/removing this function, no online-change will be possible! - - - 390 - - // A complete download will be necessary! - - - 391 - - // The implementation has to be adjusted to your application/machine. - - - 392 - - // In case of a division by zero, the PLC-Task will generate an access violation which leads to an application stop. - - - 393 - - // Please verify whether this default behaviour can damage your machine or lead to a complex recommissioning. - - - 394 - - // In this case, adapt the error reaction to your application. - - - 395 - - // - - - 396 - - // If your application isn't too time-critical, you should leave this function whil comissioning the machine and production in your application. - - - 397 - - // If you remove this function, ensure that your code is faultless. - - - 398 - - // - - - 399 - - // Do not change the declaration of this function! Add only local variables. - - - 400 - - // Do not change the attributes above the function header! - - - 401 - - {attribute 'check_div_int32'} - - - 402 - - {attribute 'no_check'} - - - 403 - - {attribute 'signature_flag' := '1073741824'} - - - 404 - - FUNCTION CheckDivDInt : DINT - - - 405 - - VAR_INPUT - - - 406 - - divisor: DINT; // Divisor of the division - - - 407 - - END_VAR - - - 408 - - VAR - - - 409 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 410 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 412 - - END_VAR - - - 1 - - - - - - - 442 - Standard - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - 609648a1-2e58-455b-9c4e-d880496e9f4a - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckDivLInt - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - - 97c1f2ea-5995-48b9-abd5-a3ab983c5def - - - - False - - - - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887917980670 - - - None - - - - - 256 - - (**************************************************************************************************) - - - 257 - - (* The implementation has to be adjusted to your application/machine. *) - - - 258 - - (* This is an exemplary implementation of the function. *) - - - 259 - - (* Per default, an access violation is generated to avoid machine damage *) - - - 260 - - (* Check the Call Stack (menu Debug/Callstack) and modify the faulty logic! *) - - - 261 - - (**************************************************************************************************) - - - 262 - - - - - 263 - - IF divisor = 0 THEN - - - 264 - - strError:= 'CheckDivLInt: Invalid division by 0 - check the callstack'; - - - 265 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 266 - - // Set an error into the plc logger - - - 267 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 268 - - // Triggering an access violation --> Application will be stopped - - - 269 - - ptNull^ := 0;(* Triggering an access violation *) - - - 320 - - - - - 271 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 272 - - // // Set the divisor to 1 - - - 273 - - // // --> no access violation (div by zero) will be triggered - - - 274 - - // // --> keep PLC-task running - - - 275 - - // // Set a warning into the plc logger - - - 276 - - // // NOTE: There is still an implementation error in your application code! - - - 319 - - // - - - 277 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 279 - - // CheckDivLInt := 1; //Division by 1 instead of zero - - - 280 - - // return; - - - 282 - - - - - 283 - - ELSE // division is ok - - - 284 - - CheckDivLInt:=divisor; - - - 7 - - END_IF; - - - - - - - - - 285 - - // Short description: Test function to increase machine safety by detecting unauthorized division by zero of LINT, ULINT and LWORD variables - - - 286 - - // - - - 287 - - // Functional description: This function will be called implicitly before the division takes places. - - - 288 - - // The divisor will be checked for 0. - - - 289 - - // In case of 0, an error is entered in the plc logger and the application is stopped due to an access violation to avoid machine damage. - - - 290 - - // In this case, check the callstack (menu Debug/Callstack) and modify the faulty logic. - - - 291 - - // - - - 292 - - // Handling particularities: This function increases the cycle time of all tasks using divisions. - - - 293 - - // The increase depends on the number of the divisions. - - - 294 - - // After inserting/removing this function, no online-change will be possible! - - - 295 - - // A complete download will be necessary! - - - 296 - - // The implementation has to be adjusted to your application/machine. - - - 297 - - // In case of a division by zero, the PLC-Task will generate an access violation which leads to an application stop. - - - 298 - - // Please verify whether this default behaviour can damage your machine or lead to a complex recommissioning. - - - 299 - - // In this case, adapt the error reaction to your application. - - - 300 - - // - - - 301 - - // If your application isn't too time-critical, you should leave this function whil comissioning the machine and production in your application. - - - 302 - - // If you remove this function, ensure that your code is faultless. - - - 303 - - // - - - 318 - - // Do not change the declaration of this function! Add only local variables. - - - 305 - - // Do not change the attributes above the function header! - - - 306 - - {attribute 'check_div_int64'} - - - 307 - - {attribute 'no_check'} - - - 308 - - {attribute 'signature_flag' := '1073741824'} - - - 309 - - FUNCTION CheckDivLInt : LINT - - - 310 - - VAR_INPUT - - - 311 - - divisor: LINT; // Divisor of the division - - - 312 - - END_VAR - - - 313 - - VAR - - - 314 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 316 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 317 - - END_VAR - - - - - 320 - Standard - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - 9803d488-e75a-4e11-a200-6e673d6e224f - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckDivLReal - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - - 97c1f2ea-5995-48b9-abd5-a3ab983c5def - - - - False - - - - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887918300658 - - - None - - - - - 270 - - (**************************************************************************************************) - - - 271 - - (* The implementation has to be adjusted to your application/machine. *) - - - 272 - - (* This is an exemplary implementation of the function. *) - - - 273 - - (* Per default, an access violation is generated to avoid machine damage *) - - - 274 - - (* Check the Call Stack (menu Debug/Callstack) and modify the faulty logic! *) - - - 275 - - (**************************************************************************************************) - - - 303 - - - - - 276 - - IF divisor = 0 THEN - - - 277 - - strError:= 'CheckDivLReal: Invalid division by 0 - check the callstack'; - - - 301 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 302 - - // Set an error into the plc logger - - - 282 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 283 - - // Triggering an access violation --> Application will be stopped - - - 284 - - ptNull^ := 0;(* Triggering an access violation *) - - - 304 - - - - - 286 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 287 - - // // Set the divisor to 1.0 - - - 288 - - // // --> no access violation (div by zero) will be triggered - - - 289 - - // // --> keep PLC-task running - - - 290 - - // // Set a warning into the plc logger - - - 291 - - // // NOTE: There is still an implementation error in your application code! - - - 292 - - // - - - 293 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 294 - - // CheckDivLReal := 1.0; //Division by 1 instead of zero - - - 295 - - // return; - - - 298 - - - - - 299 - - ELSE // division is ok - - - 300 - - CheckDivLReal:=divisor; - - - 7 - - END_IF; - - - - - - - - - 229 - - // Short description: Test function to increase machine safety by detecting unauthorized division by zero of variables of type LREAL - - - 230 - - // - - - 231 - - // Functional description: This function will be called implicitly before the division takes places. - - - 232 - - // The divisor will be checked for 0.0. - - - 233 - - // In case of 0.0, an error is entered in the plc logger and the application is stopped due to an access violation to avoid machine damage. - - - 234 - - // In this case, check the callstack (menu Debug/Callstack) and modify the faulty logic. - - - 235 - - // - - - 236 - - // Handling particularities: This function increases the cycle time of all tasks using divisions. - - - 237 - - // The increase depends on the number of the divisions. - - - 238 - - // After inserting/removing this function, no online-change will be possible! - - - 239 - - // A complete download will be necessary! - - - 240 - - // The implementation has to be adjusted to your application/machine. - - - 241 - - // In case of a division by zero, the PLC-Task will generate an access violation which leads to an application stop. - - - 242 - - // Please verify whether this default behaviour can damage your machine or lead to a complex recommissioning. - - - 243 - - // In this case, adapt the error reaction to your application. - - - 244 - - // - - - 245 - - // If your application isn't too time-critical, you should leave this function whil comissioning the machine and production in your application. - - - 246 - - // If you remove this function, ensure that your code is faultless. - - - 247 - - // - - - 248 - - // Do not change the declaration of this function! Add only local variables. - - - 249 - - // Do not change the attributes above the function header! - - - 250 - - {attribute 'check_div_real64'} - - - 251 - - {attribute 'no_check'} - - - 252 - - {attribute 'signature_flag' := '1073741824'} - - - 253 - - FUNCTION CheckDivLReal : LREAL - - - 254 - - VAR_INPUT - - - 255 - - divisor: LREAL; // Divisor of the division - - - 256 - - END_VAR - - - 257 - - VAR - - - 258 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 259 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 261 - - END_VAR - - - 1 - - - - - - - 304 - Standard - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - eeb3df6d-e42d-4119-9c95-6f1833bef139 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckDivReal - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - - 97c1f2ea-5995-48b9-abd5-a3ab983c5def - - - - False - - - - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887918801128 - - - None - - - - - 255 - - (**************************************************************************************************) - - - 256 - - (* The implementation has to be adjusted to your application/machine. *) - - - 257 - - (* This is an exemplary implementation of the function. *) - - - 258 - - (* Per default, an access violation is generated to avoid machine damage *) - - - 259 - - (* Check the Call Stack (menu Debug/Callstack) and modify the faulty logic! *) - - - 260 - - (**************************************************************************************************) - - - 261 - - - - - 262 - - IF divisor = 0 THEN - - - 263 - - strError:= 'CheckDivReal: Invalid division by 0 - check the callstack'; - - - 264 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 265 - - // Set an error into the plc logger - - - 266 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 267 - - // Triggering an access violation --> Application will be stopped - - - 268 - - ptNull^ := 0;(* Triggering an access violation *) - - - 283 - - - - - 270 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 271 - - // // Set the divisor to 1 - - - 272 - - // // --> no access violation (div by zero) will be triggered - - - 273 - - // // --> keep PLC-task running - - - 274 - - // // Set a warning into the plc logger - - - 275 - - // // NOTE: There is still an implementation error in your application code! - - - 276 - - // - - - 277 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 278 - - // CheckDivReal := 1.0; //Division by 1 instead of zero - - - 279 - - // return; - - - 280 - - - - - 281 - - ELSE // division is ok - - - 282 - - CheckDivReal:=divisor; - - - 7 - - END_IF; - - - - - - - - - 212 - - // Short description: Test function to increase machine safety by detecting unauthorized division by zero of variables of type REAL. - - - 213 - - // - - - 214 - - // Functional description: This function will be called implicitly before the division takes places. - - - 215 - - // The divisor will be checked for 0.0. - - - 216 - - // In case of 0.0, an error is entered in the plc logger and the application is stopped due to an access violation to avoid machine damage. - - - 217 - - // In this case, check the callstack (menu Debug/Callstack) and modify the faulty logic. - - - 218 - - // - - - 219 - - // Handling particularities: This function increases the cycle time of all tasks using divisions. - - - 220 - - // The increase depends on the number of the divisions. - - - 221 - - // After inserting/removing this function, no online-change will be possible! - - - 222 - - // A complete download will be necessary! - - - 223 - - // The implementation has to be adjusted to your application/machine. - - - 224 - - // In case of a division by zero, the PLC-Task will generate an access violation which leads to an application stop. - - - 225 - - // Please verify whether this default behaviour can damage your machine or lead to a complex recommissioning. - - - 226 - - // In this case, adapt the error reaction to your application. - - - 227 - - // - - - 228 - - // If your application isn't too time-critical, you should leave this function whil comissioning the machine and production in your application. - - - 229 - - // If you remove this function, ensure that your code is faultless. - - - 230 - - // - - - 231 - - // Do not change the declaration of this function! Add only local variables. - - - 232 - - // Do not change the attributes above the function header! - - - 233 - - {attribute 'check_div_real32'} - - - 234 - - {attribute 'no_check'} - - - 235 - - {attribute 'signature_flag' := '1073741824'} - - - 236 - - FUNCTION CheckDivReal : REAL - - - 237 - - VAR_INPUT - - - 238 - - divisor: REAL; // Divisor of the division - - - 239 - - END_VAR - - - 240 - - VAR - - - 241 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 242 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 244 - - END_VAR - - - 1 - - - - - - - 283 - Standard - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - 8ef16baf-6c68-4fe0-b526-10ef481f2fe5 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckLRangeSigned - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - - 97c1f2ea-5995-48b9-abd5-a3ab983c5def - - - - False - - - - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887919101090 - - - None - - - - - 469 - - (**************************************************************************************************) - - - 470 - - (* The implementation has to be adjusted to your application/machine. *) - - - 471 - - (* This is an exemplary implementation of the function. *) - - - 472 - - (* Per default, an access violation is generated to avoid machine damage *) - - - 473 - - (* Check the Call Stack (menu Debug/Callstack) and modify the faulty logic! *) - - - 474 - - (**************************************************************************************************) - - - 519 - - - - - 475 - - IF (value < lower) THEN - - - 477 - - strError:= 'CheckLRangeSigned: Lower value '; - - - 478 - - strError:=CONCAT(STR1:=strError , STR2:= LINT_TO_STRING(lower)); - - - 479 - - strError:=CONCAT(STR1:=strError , STR2:= ' underrunned by '); - - - 480 - - strError:=CONCAT(STR1:=strError , STR2:= LINT_TO_STRING(value)); - - - 481 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 482 - - // Set an error into the plc logger - - - 483 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 484 - - // Triggering an access violation --> Application will be stopped - - - 485 - - ptNull^ := 0;(* Triggering an access violation *) - - - 486 - - - - - 487 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 488 - - // // Limit the faulty value to the lower value - - - 489 - - // // Set a warning into the plc logger - - - 490 - - // // NOTE: There is still an implementation error in your application code! - - - 491 - - // - - - 492 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 493 - - // CheckLRangeSigned := lower; //set value to lower value - - - 494 - - // return; - - - 495 - - - - - 496 - - ELSIF(value > upper) THEN - - - 497 - - strError:= 'CheckLRangeSigned: Upper value '; - - - 498 - - strError:=CONCAT(STR1:=strError , STR2:= LINT_TO_STRING(upper)); - - - 499 - - strError:=CONCAT(STR1:=strError , STR2:= ' overrunned by '); - - - 500 - - strError:=CONCAT(STR1:=strError , STR2:= LINT_TO_STRING(value)); - - - 501 - - - - - 502 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 503 - - // Set an error into the plc logger - - - 504 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 505 - - // Triggering an access violation --> Application will be stopped - - - 506 - - ptNull^ := 0;(* Triggering an access violation *) - - - 520 - - - - - 508 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 509 - - // // Limit the faulty value to the upper value - - - 510 - - // // Set a warning into the plc logger - - - 511 - - // // NOTE: There is still an implementation error in your application code! - - - 512 - - // - - - 513 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 514 - - // CheckLRangeSigned := upper; //set value to upper value - - - 515 - - // return; - - - 516 - - - - - 517 - - ELSE // value ist within valid range - - - 518 - - CheckLRangeSigned := value; - - - 7 - - END_IF - - - - - - - - - 425 - - // Short description: Test function to increase machine safety by checking if value is within signed range (LINT) - - - 426 - - // - - - 427 - - // Functional description: This function will be called implicitly before any access to range signed values. - - - 428 - - // In case of invalid access, an error is entered in the diagnostic logbook and the application is stopped due to an access violation to avoid machine damage. - - - 429 - - // In this case, check the callstack (menu Debug/Callstack) and modify the faulty logic. - - - 430 - - // - - - 431 - - // Handling particularities: This function increases the cycle time of all tasks accessing range signed values. - - - 432 - - // The increase depends on the number of the read/write accesses. - - - 433 - - // - - - 434 - - // After inserting/removing this function, no online-change will be possible! - - - 435 - - // A complete download will be necessary! - - - 436 - - // The implementation has to be adjusted to your application/machine. - - - 437 - - // In case of a division by zero, the PLC-Task will generate an access violation which leads to an application stop. - - - 438 - - // Please verify whether this default behaviour can damage your machine or lead to a complex recommissioning. - - - 439 - - // In this case, adapt the error reaction to your application. - - - 440 - - // - - - 441 - - // If your application isn't too time-critical, you should leave this function whil comissioning the machine and production in your application. - - - 442 - - // If you remove this function, ensure that your code is faultless. - - - 443 - - // - - - 444 - - // Do not change the declaration of this function! Add only local variables. - - - 445 - - // Do not change the attributes above the function header! - - - 446 - - {attribute 'no_check'} - - - 447 - - {attribute 'check_lrange_signed'} - - - 448 - - {attribute 'signature_flag' := '1073741824'} - - - 449 - - FUNCTION CheckLRangeSigned : LINT - - - 450 - - VAR_INPUT - - - 451 - - value: LINT; - - - 452 - - lower: LINT; - - - 453 - - upper: LINT; - - - 454 - - END_VAR - - - 455 - - VAR - - - 456 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 457 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 459 - - END_VAR - - - 1 - - - - - - - 520 - Standard - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - 521ddf74-7d27-4f28-a796-a061adfdde45 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckLRangeUnsigned - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - - 97c1f2ea-5995-48b9-abd5-a3ab983c5def - - - - False - - - - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887919411100 - - - None - - - - - 512 - - (**************************************************************************************************) - - - 513 - - (* The implementation has to be adjusted to your application/machine. *) - - - 514 - - (* This is an exemplary implementation of the function. *) - - - 515 - - (* Per default, an access violation is generated to avoid machine damage *) - - - 516 - - (* Check the Call Stack (menu Debug/Callstack) and modify the faulty logic! *) - - - 517 - - (**************************************************************************************************) - - - 518 - - - - - 519 - - IF (value < lower) THEN - - - 520 - - strError:= 'CheckLRangeUnsigned: Lower value '; - - - 521 - - strError:=CONCAT(STR1:=strError , STR2:= ULINT_TO_STRING(lower)); - - - 522 - - strError:=CONCAT(STR1:=strError , STR2:= ' underrunned by '); - - - 523 - - strError:=CONCAT(STR1:=strError , STR2:= ULINT_TO_STRING(value)); - - - 524 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 525 - - // Set an error into the plc logger - - - 526 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 527 - - // Triggering an access violation --> Application will be stopped - - - 528 - - ptNull^ := 0;(* Triggering an access violation *) - - - 561 - - - - - 530 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 531 - - // // Limit the faulty value to the lower value - - - 532 - - // // Set a warning into the plc logger - - - 533 - - // // NOTE: There is still an implementation error in your application code! - - - 534 - - // - - - 535 - - // CheckLRangeUnsigned := lower; //set value to lower value - - - 536 - - // return; - - - 537 - - - - - 538 - - ELSIF(value > upper) THEN - - - 539 - - strError:= 'CheckLRangeUnsigned: Upper value '; - - - 540 - - strError:=CONCAT(STR1:=strError , STR2:= ULINT_TO_STRING(upper)); - - - 541 - - strError:=CONCAT(STR1:=strError , STR2:= ' overrunned by '); - - - 542 - - strError:=CONCAT(STR1:=strError , STR2:= ULINT_TO_STRING(value)); - - - 543 - - - - - 544 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 545 - - // Set an error into the plc logger - - - 546 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 547 - - // Triggering an access violation --> Application will be stopped - - - 548 - - ptNull^ := 0;(* Triggering an access violation *) - - - 562 - - - - - 550 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 551 - - // // Limit the faulty value to the upper value - - - 552 - - // // Set a warning into the plc logger - - - 553 - - // // NOTE: There is still an implementation error in your application code! - - - 554 - - // - - - 555 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 556 - - // CheckLRangeUnsigned := upper; //set value to upper value - - - 557 - - // return; - - - 558 - - - - - 559 - - ELSE // value ist within valid range - - - 560 - - CheckLRangeUnsigned := value; - - - 7 - - END_IF - - - - - - - - - 445 - - // Short description: Test function to increase machine safety by checking if value is within unsigned range (ULINT, LWORD) - - - 446 - - // - - - 447 - - // Functional description: This function will be called implicitly before any access to range signed values. - - - 448 - - // In case of invalid access, an error is entered in the diagnostic logbook and the application is stopped due to an access violation to avoid machine damage. - - - 449 - - // In this case, check the callstack (menu Debug/Callstack) and modify the faulty logic. - - - 450 - - // - - - 451 - - // Handling particularities: This function increases the cycle time of all tasks accessing range signed values. - - - 452 - - // The increase depends on the number of the read/write accesses. - - - 453 - - // - - - 454 - - // After inserting/removing this function, no online-change will be possible! - - - 455 - - // A complete download will be necessary! - - - 456 - - // The implementation has to be adjusted to your application/machine. - - - 457 - - // In case of a division by zero, the PLC-Task will generate an access violation which leads to an application stop. - - - 458 - - // Please verify whether this default behaviour can damage your machine or lead to a complex recommissioning. - - - 459 - - // In this case, adapt the error reaction to your application. - - - 460 - - // - - - 461 - - // If your application isn't too time-critical, you should leave this function whil comissioning the machine and production in your application. - - - 462 - - // If you remove this function, ensure that your code is faultless. - - - 463 - - // - - - 464 - - // Do not change the declaration of this function! Add only local variables. - - - 465 - - // Do not change the attributes above the function header! - - - 466 - - {attribute 'no_check'} - - - 467 - - {attribute 'check_lrange_unsigned'} - - - 468 - - {attribute 'signature_flag' := '1073741824'} - - - 469 - - FUNCTION CheckLRangeUnsigned : ULINT - - - 470 - - VAR_INPUT - - - 471 - - value: ULINT; - - - 472 - - lower: ULINT; - - - 473 - - upper: ULINT; - - - 474 - - END_VAR - - - 475 - - VAR - - - 476 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 477 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 479 - - END_VAR - - - 1 - - - - - - - 562 - Standard - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - 6003db3f-7c51-4503-b0d5-21bc7b4782e5 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckRangeSigned - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - - 97c1f2ea-5995-48b9-abd5-a3ab983c5def - - - - False - - - - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887920160740 - - - None - - - - - 383 - - (**************************************************************************************************) - - - 384 - - (* The implementation has to be adjusted to your application/machine. *) - - - 385 - - (* This is an exemplary implementation of the function. *) - - - 386 - - (* Per default, an access violation is generated to avoid machine damage *) - - - 387 - - (* Check the Call Stack (menu Debug/Callstack) and modify the faulty logic! *) - - - 388 - - (**************************************************************************************************) - - - 389 - - - - - 390 - - IF (value < lower) THEN - - - 391 - - strError:= 'CheckRangeSigned: Lower value '; - - - 392 - - strError:=CONCAT(STR1:=strError , STR2:= DINT_TO_STRING(lower)); - - - 393 - - strError:=CONCAT(STR1:=strError , STR2:= ' underrunned by '); - - - 394 - - strError:=CONCAT(STR1:=strError , STR2:= DINT_TO_STRING(value)); - - - 395 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 396 - - // Set an error into the plc logger - - - 397 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 398 - - // Triggering an access violation --> Application will be stopped - - - 399 - - ptNull^ := 0;(* Triggering an access violation *) - - - 433 - - - - - 401 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 402 - - // // Limit the faulty value to the lower value - - - 403 - - // // Set a warning into the plc logger - - - 404 - - // // NOTE: There is still an implementation error in your application code! - - - 405 - - // - - - 406 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 407 - - // CheckRangeSigned := lower; //set value to lower value - - - 408 - - // return; - - - 409 - - - - - 410 - - ELSIF(value > upper) THEN - - - 411 - - strError:= 'CheckRangeSigned: Upper value '; - - - 412 - - strError:=CONCAT(STR1:=strError , STR2:= DINT_TO_STRING(upper)); - - - 413 - - strError:=CONCAT(STR1:=strError , STR2:= ' overrunned by '); - - - 414 - - strError:=CONCAT(STR1:=strError , STR2:= DINT_TO_STRING(value)); - - - 415 - - - - - 416 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 417 - - // Set an error into the plc logger - - - 418 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 419 - - // Triggering an access violation --> Application will be stopped - - - 420 - - ptNull^ := 0;(* Triggering an access violation *) - - - 434 - - - - - 422 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 423 - - // // Limit the faulty value to the upper value - - - 424 - - // // Set a warning into the plc logger - - - 425 - - // // NOTE: There is still an implementation error in your application code! - - - 426 - - // - - - 427 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 428 - - // CheckRangeSigned := upper; //set value to upper value - - - 429 - - // return; - - - 430 - - - - - 431 - - ELSE // value ist within valid range - - - 432 - - CheckRangeSigned := value; - - - 7 - - END_IF - - - - - - - - - 333 - - // Short description: Test function to increase machine safety by checking if value is within signed range (INT, DINT) - - - 334 - - // - - - 335 - - // Functional description: This function will be called implicitly before any access to range signed values. - - - 336 - - // In case of invalid access, an error is entered in the diagnostic logbook and the application is stopped due to an access violation to avoid machine damage. - - - 337 - - // In this case, check the callstack (menu Debug/Callstack) and modify the faulty logic. - - - 338 - - // - - - 339 - - // Handling particularities: This function increases the cycle time of all tasks accessing range signed values. - - - 340 - - // The increase depends on the number of the read/write accesses. - - - 341 - - // - - - 342 - - // After inserting/removing this function, no online-change will be possible! - - - 343 - - // A complete download will be necessary! - - - 344 - - // The implementation has to be adjusted to your application/machine. - - - 345 - - // In case of a division by zero, the PLC-Task will generate an access violation which leads to an application stop. - - - 346 - - // Please verify whether this default behaviour can damage your machine or lead to a complex recommissioning. - - - 347 - - // In this case, adapt the error reaction to your application. - - - 348 - - // - - - 349 - - // If your application isn't too time-critical, you should leave this function whil comissioning the machine and production in your application. - - - 350 - - // If you remove this function, ensure that your code is faultless. - - - 351 - - // - - - 352 - - // Do not change the declaration of this function! Add only local variables. - - - 353 - - // Do not change the attributes above the function header! - - - 354 - - {attribute 'no_check'} - - - 355 - - {attribute 'check_range_signed'} - - - 356 - - {attribute 'signature_flag' := '1073741824'} - - - 357 - - FUNCTION CheckRangeSigned : DINT - - - 358 - - VAR_INPUT - - - 359 - - value: DINT; - - - 360 - - lower: DINT; - - - 361 - - upper: DINT; - - - 362 - - END_VAR - - - 363 - - VAR - - - 364 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 365 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 367 - - END_VAR - - - 1 - - - - - - - 434 - Standard - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - ec010e8d-bce5-4419-adff-2749696bf6d1 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckRangeUnsigned - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - - 97c1f2ea-5995-48b9-abd5-a3ab983c5def - - - - False - - - - - 6f9dac99-8de1-4efc-8465-68ac443b7d08 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887920520718 - - - None - - - - - 424 - - (**************************************************************************************************) - - - 425 - - (* The implementation has to be adjusted to your application/machine. *) - - - 426 - - (* This is an exemplary implementation of the function. *) - - - 427 - - (* Per default, an access violation is generated to avoid machine damage *) - - - 428 - - (* Check the Call Stack (menu Debug/Callstack) and modify the faulty logic! *) - - - 429 - - (**************************************************************************************************) - - - 430 - - - - - 431 - - IF (value < lower) THEN - - - 432 - - strError:= 'CheckRangeUnsigned: Lower value '; - - - 433 - - strError:=CONCAT(STR1:=strError , STR2:= UDINT_TO_STRING(lower)); - - - 434 - - strError:=CONCAT(STR1:=strError , STR2:= ' underrunned by '); - - - 435 - - strError:=CONCAT(STR1:=strError , STR2:= UDINT_TO_STRING(value)); - - - 436 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 437 - - // Set an error into the plc logger - - - 438 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 439 - - // Triggering an access violation --> Application will be stopped - - - 440 - - ptNull^ := 0;(* Triggering an access violation *) - - - 474 - - - - - 442 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 443 - - // // Limit the faulty value to the lower value - - - 444 - - // // Set a warning into the plc logger - - - 445 - - // // NOTE: There is still an implementation error in your application code! - - - 446 - - // - - - 447 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 448 - - // CheckRangeUnsigned := lower; //set value to lower value - - - 449 - - // return; - - - 450 - - - - - 451 - - ELSIF(value > upper) THEN - - - 452 - - strError:= 'CheckRangeUnsigned: Upper value '; - - - 453 - - strError:=CONCAT(STR1:=strError , STR2:= UDINT_TO_STRING(upper)); - - - 454 - - strError:=CONCAT(STR1:=strError , STR2:= ' overrunned by '); - - - 455 - - strError:=CONCAT(STR1:=strError , STR2:= UDINT_TO_STRING(value)); - - - 456 - - - - - 457 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 458 - - // Set an error into the plc logger - - - 459 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 460 - - // Triggering an access violation --> Application will be stopped - - - 461 - - ptNull^ := 0;(* Triggering an access violation *) - - - 475 - - - - - 463 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 464 - - // // Limit the faulty value to the upper value - - - 465 - - // // Set a warning into the plc logger - - - 466 - - // // NOTE: There is still an implementation error in your application code! - - - 467 - - // - - - 468 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 469 - - // CheckRangeUnsigned := upper; //set value to upper value - - - 470 - - // return; - - - 471 - - - - - 472 - - ELSE // value ist within valid range - - - 473 - - CheckRangeUnsigned := value; - - - 7 - - END_IF - - - - - - - - - 375 - - // Short description: Test function to increase machine safety by checking if value is within unsigned range (UINT, UDINT, WORD, DWORD) - - - 376 - - // - - - 377 - - // Functional description: This function will be called implicitly before any access to range unsigned values. - - - 378 - - // In case of invalid access, an error is entered in the diagnostic logbook and the application is stopped due to an access violation to avoid machine damage. - - - 379 - - // In this case, check the callstack (menu Debug/Callstack) and modify the faulty logic. - - - 380 - - // - - - 381 - - // Handling particularities: This function increases the cycle time of all tasks accessing range signed values. - - - 382 - - // The increase depends on the number of the read/write accesses. - - - 383 - - // - - - 384 - - // After inserting/removing this function, no online-change will be possible! - - - 385 - - // A complete download will be necessary! - - - 386 - - // The implementation has to be adjusted to your application/machine. - - - 387 - - // In case of a division by zero, the PLC-Task will generate an access violation which leads to an application stop. - - - 388 - - // Please verify whether this default behaviour can damage your machine or lead to a complex recommissioning. - - - 389 - - // In this case, adapt the error reaction to your application. - - - 390 - - // - - - 391 - - // If your application isn't too time-critical, you should leave this function whil comissioning the machine and production in your application. - - - 392 - - // If you remove this function, ensure that your code is faultless. - - - 393 - - // - - - 394 - - // Do not change the declaration of this function! Add only local variables. - - - 395 - - // Do not change the attributes above the function header! - - - 396 - - {attribute 'check_range_unsigned'} - - - 397 - - {attribute 'signature_flag' := '1073741824'} - - - 398 - - {attribute 'no_check'} - - - 399 - - FUNCTION CheckRangeUnsigned : UDINT - - - 400 - - VAR_INPUT - - - 401 - - value: UDINT; - - - 402 - - lower: UDINT; - - - 403 - - upper: UDINT; - - - 404 - - END_VAR - - - 405 - - VAR - - - 406 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 407 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 409 - - END_VAR - - - 1 - - - - - - - 475 - Standard - - False - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - 5c57242d-0abc-44e9-a367-983e29473911 - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckBounds - - - - 24568a24-c491-472c-a21f-ee5d33859fab - - - - 0 - False - False - False - - False - - - - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - c3fc9989-e24b-4002-a2c7-827a0a2595f4 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887917150682 - - - - - - - 499 - - (*****************************************************************************************************) - - - 500 - - (* The implementation has to be adjusted to your application/machine. *) - - - 501 - - (* This is an exemplary implementation of the function. *) - - - 502 - - (* Per default, an access violation is generated in case of an faulty acces to avoid machine damage. *) - - - 503 - - (* In this case, check the Call Stack (menu Debug/Callstack) and modify the faulty logic. *) - - - 504 - - (*****************************************************************************************************) - - - 505 - - - - - 506 - - IF index < lower THEN - - - 507 - - strError:= 'CheckBounds: Lower arrayindex '; - - - 508 - - strError:=CONCAT(STR1:=strError , STR2:= DINT_TO_STRING(lower)); - - - 509 - - strError:=CONCAT(STR1:=strError , STR2:= ' underrunned by '); - - - 510 - - strError:=CONCAT(STR1:=strError , STR2:= DINT_TO_STRING(index)); - - - 511 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 512 - - // Set an error into the plc logger - - - 513 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 514 - - // Triggering an access violation --> Application will be stopped - - - 515 - - ptNull^ := 0;(* Triggering an access violation *) - - - 516 - - - - - 517 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 518 - - // // Limit the faulty index to the lower index - - - 519 - - // // --> no memory will be overwritten - - - 520 - - // // --> Keep PLC-task running - - - 521 - - // // Set a warning into the plc logger - - - 522 - - // // NOTE: There is still an implementation error in your application code! - - - 523 - - // // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 524 - - // // - - - 525 - - // CheckBounds := lower; //access to the lower index only - - - 526 - - // return; - - - 527 - - - - - 528 - - ELSIF index > upper THEN - - - 529 - - strError:= 'CheckBounds: Higher arrayindex '; - - - 530 - - strError:=CONCAT(STR1:=strError , STR2:= DINT_TO_STRING(upper)); - - - 531 - - strError:=CONCAT(STR1:=strError , STR2:= ' overrunned by '); - - - 532 - - strError:=CONCAT(STR1:=strError , STR2:= DINT_TO_STRING(index)); - - - 533 - - - - - 534 - - // Default implementation for APPLICATION WILL BE STOPPED: - - - 535 - - // Set an error into the plc logger - - - 536 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 537 - - // Triggering an access violation --> Application will be stopped - - - 538 - - ptNull^ := 0;(* Triggering an access violation *) - - - 539 - - - - - 540 - - // // Example for APPLICATION WILL NOT BE STOPPED: - - - 541 - - // // Limit the faulty index to the upper index - - - 542 - - // // --> no memory will be overwritten - - - 543 - - // // --> Keep PLC-task running - - - 544 - - // // Set a warning into the plc logger - - - 545 - - // // NOTE: There is still an implementation error in your application code! - - - 546 - - // LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_WARNING,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 547 - - // - - - 548 - - // CheckBounds := upper; //access to the upper index only - - - 549 - - // return; - - - 550 - - - - - 551 - - ELSE // access to array is within lower and upper index --> ok - - - 552 - - CheckBounds := index; - - - 553 - - END_IF - - - 2 - - - - - - - - - - - 443 - - // Short description: Test function to increase machine safety by checking for unauthorized array indices accesses. - - - 444 - - // - - - 445 - - // Functional description: This function is implicitly called prior to each array access and verifies if the access is within the valid array bounds. - - - 446 - - // If the access is authorized, the function returns the index to the calling POU and the access is completed. - - - 447 - - // If the access is unauthorized, an exception is triggered as default error reaction. This exception results in an application stop and the system is set to safe state. - - - 448 - - // - - - 449 - - // Handling particularities: Sporadically, the implemented default error reaction has TO be adjusted TO the application. - - - 450 - - // For example, stopping of the application can be invalid and can result in complicated recommissioning or even injury to people or damage to machines. - - - 451 - - // Thus, adjust the default error reaction to your application. - - - 452 - - // After inserting/removing this function in/from the project, no online change is possible. - - - 453 - - // A complete download is required. - - - 454 - - // - - - 455 - - // Further information: The implicit calls of this check function are realized in all POUs but not in POUs of protected (*.compiled library) - - - 456 - - // and open (*.library) libraries or in POUs with the attribute {attribute 'no_check'}. Consequently, they do not increase the runtime. - - - 457 - - // If the check is also to be performed in open libraries, enter the compiler definition - - - 458 - - // checks_in_libs in the field Compiler-Defines of the Build tab in the property dialog of the application node. - - - 459 - - // An increased runtime depends on the number of programmed array accesses. - - - 460 - - // - - - 461 - - // To reduce task runtimes, add the attribute 'no_check' to the POUs. - - - 462 - - // Checks performed by the check functions (CheckPointer, CheckBounds, CheckDiv, CheckRange) are not performed in these POUs. - - - 463 - - // Thus, these POUs have to be checked by the user regarding pointer programming, divisions and array accesses. - - - 464 - - // For more information, refer to the F1-help. - - - 465 - - // - - - 466 - - // In the standard implementation, it is checked if the array access takes place within the valid array boundaries. - - - 467 - - // - - - 468 - - // In case of invalid access (outside the valid array boundaries), an error is entered in the PLC logger and the application is stopped to avoid injury to persons and damage to machines. - - - 469 - - // In this case, check the callstack (menu Debug/Callstack) and change the incorrect logic. - - - 470 - - // - - - 471 - - // If your application is not time-critical, use this function during commissioning as well as during the production phase of the machine. - - - 472 - - // Only remove this function if you are sure that your user code is free from errors! - - - 473 - - // - - - 474 - - // Do not change the declaration of this function! Add only local variables. - - - 475 - - // Do not change the attributes above the function header! - - - 476 - - {attribute 'check_bounds'} - - - 477 - - {attribute 'no_check'} - - - 478 - - {attribute 'signature_flag' := '1073741824'} - - - 479 - - FUNCTION CheckBounds : DINT - - - 480 - - VAR_INPUT - - - 481 - - index, lower, upper: DINT; // Index of the array, lower bound and upper bound - - - 482 - - END_VAR - - - 483 - - VAR - - - 486 - - ptNull: POINTER TO BYTE :=0; // Nullpointer for triggering an access violation - - - 487 - - strError: STRING; // Diagnostic text for the PLC logger entry - - - 1 - - END_VAR - - - - - CheckBounds - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - 5958a7c4-4190-4632-9e8d-a0514bb4166b - a756c95a-3bd5-44f9-990a-ff4d038fd9d1 - CheckPointer - - - - 24568a24-c491-472c-a21f-ee5d33859fab - - - - 0 - False - False - False - - False - - - - - - - 829a18f2-c514-4f6e-9634-1df173429203 - - - - - - - d9b2b2cc-ea99-4c3b-aa42-1e5c49e65b84 - - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - - - - - - - c3fc9989-e24b-4002-a2c7-827a0a2595f4 - - a9ed5b7e-75c5-4651-af16-d2c27e98cb94 - 3b83b776-fb25-43b8-99f2-3c507c9143fc - - 637871887919830732 - - - - - - - 1268 - - IF ptToTest = 0 THEN //Just check NULL-Pointer - - - 1307 - - - - - 1294 - - IF bWrite THEN // write access - - - 1295 - - strError:='CheckPointer: Invalid write-access to 16#0'; - - - 1296 - - ELSE - - - 1297 - - strError:='CheckPointer: Invalid read-access to 16#0'; - - - 1298 - - END_IF - - - 1299 - - strError:=CONCAT(STR1:=strError , STR2:= ' - Size: '); - - - 1301 - - strError:=CONCAT(STR1:=strError , STR2:=TO_STRING(iSize)); - - - 1302 - - strError:=CONCAT(STR1:=strError , STR2:=' - See callstack for reason!'); - - - 1303 - - - - - 1304 - - LogAdd2(hLogger:= CmpLog.LOG_STD_LOGGER,udiCmpID:= 16#1000,udiClassID:= LogClass.LOG_ERROR,udiErrorID:= 1,udiInfoID:= 1,pszInfo:= strError); - - - 1305 - - // Triggering an access violation --> Application will be stopped - - - 1309 - - // Sporadically, this default error reaction has to be adjusted to the application. - - - 1310 - - // For example, stopping of the application can be invalid and can result in complicated recommissioning or even injury to people or damage to machines. - - - 1308 - - // Thus, adjust the default error reaction to your application. - - - 1306 - - ptNull^ := 0; //Triggering an access violation - - - 1289 - - - - - 1290 - - ELSE // pointer is not a NULL-Pointer - - - 1291 - - CheckPointer := ptToTest; - - - 1292 - - END_IF - - - 399 - - - - - - - - - - - 1104 - - // Short description: Test function to increase machine safety by detecting unauthorized accesses via POINTER and REFERENCE variables - - - 1105 - - // - - - 1106 - - // Functional description: This function is implicitly called prior to each pointer access and verifies if the access is invalid to 0. - - - 1107 - - // If the access is authorized, the function returns the pointer to the calling POU and the access is completed. - - - 1108 - - // If the access is unauthorized, an exception is triggered as default error reaction. This exception results in an application stop and the system is set to safe state. - - - 1109 - - // It is recommended to adapt an appropriate error response to the machine application. - - - 1110 - - // - - - 1111 - - // Handling particularities: Sporadically, the implemented default error reaction has to be adjusted to the application. - - - 1112 - - // For example, stopping of the application can be invalid and can result in complicated recommissioning or even injury to people or damage to machines. - - - 1113 - - // Thus, adjust the default error reaction to your application. - - - 1114 - - // After inserting/removing this function in/from the project, no online change is possible. - - - 1115 - - // A complete download is required. - - - 1116 - - // - - - 1117 - - // Further information: The implicit calls of this check function are realized in all POUs but not in POUs of protected (*.compiled library) - - - 1118 - - // and open (*.library) libraries or in POUs with the attribute {attribute 'no_check'}. Consequently, they do not increase the runtime. - - - 1119 - - // If the check is also to be performed in open libraries, enter the compiler definition - - - 1120 - - // checks_in_libs in the field Compiler-Defines of the Build tab in the property dialog of the application node. - - - 1121 - - // An increased runtime depends on the number of programmed pointer accesses or the use of REFERENCE variables. - - - 1122 - - // - - - 1123 - - // To reduce task runtimes, add the attribute 'no_check' to the POUs. - - - 1124 - - // Checks performed by the check functions (CheckPointer, CheckBounds, CheckDiv, CheckRange) are not performed in these POUs. - - - 1125 - - // Thus, these POUs have to be checked by the user regarding pointer programming, divisions and array accesses. - - - 1126 - - // For more information, refer to the F1-help. - - - 1127 - - // - - - 1128 - - // In the standard implementation, it is checked if the pointer access takes place to Adress 16#0 (NULL-Pointer). - - - 1248 - - // In this case, check the callstack (menu Debug/Callstack) and change the incorrect logic. - - - 1140 - - // - - - 1149 - - // If your application is not time-critical, use this function during commissioning as well as during the production phase of the machine. - - - 1150 - - // Only remove this function if you are sure that your user code is free from errors! - - - 1151 - - // - - - 1152 - - // Do not change the declaration of this function! Add only local variables. - - - 1153 - - // Do not change the attributes above the function header! - - - 1154 - - {attribute 'check_pointer'} - - - 1155 - - {attribute 'signature_flag' := '1073741824'} - - - 1156 - - {attribute 'no_check'} - - - 1157 - - FUNCTION CheckPointer : POINTER TO BYTE - - - 1158 - - VAR_INPUT - - - 1159 - - ptToTest : POINTER TO BYTE; // Pointer target address - - - 1160 - - iSize : DINT; // Size of the type to which the pointer points. (z.B.: 20 für POINTER TO ARRAY [1..10] OF WORD) - - - 1161 - - iGran : DINT; // Granularity of the pointer access. This is the size of the largest unstructured data type in the type to which the pointer points. - - - 1220 - - // (e.g.: 2 for POINTER TO ARRAY [0..9] OF INT). - - - 1219 - - bWrite: BOOL; // Indicates read or write access. TRUE = write access. - - - 1163 - - END_VAR - - - 1164 - - VAR - - - 1165 - - ptNull: POINTER TO BYTE := 0; // Nullpointer for triggering an access violation - - - 1166 - - strError: STRING(128); // Diagnostic text for the PLC logger entry - - - 1167 - - i: INT; // Index variable - - - 1 - - END_VAR - - - - - CheckPointer - - 61d7527e-1fe8-41a0-8264-e4dc2af772f1 - - Device - SPS-Logik - Application - CheckFunctions - - -1 - - - False - - 571b7390-a39a-4ae2-93de-9f3486a0fead - 4ed6029a-ed3f-417e-a394-37731d5c06be - MainTask - - 98a2708a-9b18-4f31-82ed-a1465b24fa2d - - 637871918942205497 - - - False - Cyclic - - - - - - 30 - - False - - 20 - ms - - 1 - - - 200 - ms - - - - 6a0fc402-56c7-45c5-8f51-39b42e55b054 - dc6dc8c4-5514-421e-b9d3-af788541aa10 - - - PLC_PRG - - - - False - True - -1 - -2 - IEC-Tasks - - - 4ed6029a-ed3f-417e-a394-37731d5c06be - - Device - SPS-Logik - Application - Taskkonfiguration - - -1 - - - ctrlX PLC 1.14.1 - - diff --git a/samples-iec61131/fbs-read-write/fbs-datalayer-subscriptions-settings.xml b/samples-iec61131/fbs-read-write/fbs-datalayer-subscriptions-settings.xml new file mode 100644 index 000000000..e09cbb431 --- /dev/null +++ b/samples-iec61131/fbs-read-write/fbs-datalayer-subscriptions-settings.xml @@ -0,0 +1,334 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a3774601-103a-4459-8d0b-d2da2e07e234 + + + + + + + + + + + + + + + + + + + + + + + + + + + Read values + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Write values + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IF bStart_read THEN + bStart_read := FALSE; + bExecute_read := TRUE; +END_IF + + +fbDL_ReadNodeValue( + Execute:= bExecute_read, + Done=> bDone_read, + Active=> bActive_read, + Error=> bErrorRead, + ErrorID=> ErrorIDRead, + ErrorIdent=> ErrorIdent_read, + ClientId:= , + NodeName:= strNodePath, + NodeValue:= DataRead); + +IF bDone_read AND bExecute_read THEN + bExecute_read := FALSE; + + fbFlatbuffer.getRootAsSubscriptionSettings(data:= + DataRead.GetData(), size:= DataRead.GetSize()); + + maximumBufferSize := fbFlatbuffer.getMaximumBufferSize(); + + bStart_write := TRUE; +END_IF + + +IF bStart_write THEN + bStart_write := FALSE; + + maximumBufferSize := (maximumBufferSize + 1); + IF maximumBufferSize > 55 THEN + maximumBufferSize := 50; + END_IF + + fbBuilder(forceDefaults := TRUE); + fbFlatbuffer.startSubscriptionSettings(fbBuilder); + + fbFlatbuffer.addMaximumBufferSize(maximumBufferSize); + + fbBuilder.finish(fbFlatbuffer.endSubscriptionSettings()); + fbValueIn.SetFlatbuffer(fbBuilder); + + bExecute_write := TRUE; +END_IF + + +fbDL_WriteNodeValue( + Execute:= bExecute_write, + Done=> bDone_write, + Active=> bActive_write, + Error=> bError_write, + ErrorID=> ErrorID_write, + ErrorIdent=> ErrorIdent_write, + ClientId:= , + NodeName:= strNodePath, + NodeValueIn:= fbValueIn, + NodeValueOut:= fbValueOut); + +IF bDone_write AND bExecute_write THEN + bExecute_write := FALSE; + iWritten := iWritten + 1; + + bStart_read := TRUE; +END_IF + + + + + + + 63ac73d1-ffba-4b01-9d0e-8b65a8ef1bb5 + + + + + + + + + + + + + + + + + + + + 537708a0-13a8-4eac-b3c1-951511e8106d + + + + + + a756c95a-3bd5-44f9-990a-ff4d038fd9d1 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples-iec61131/fbs-read-write/start.bat b/samples-iec61131/fbs-read-write/start.bat deleted file mode 100644 index 54c85ebcc..000000000 --- a/samples-iec61131/fbs-read-write/start.bat +++ /dev/null @@ -1,18 +0,0 @@ -c:\ctrlx-automation-sdk\bin\fbs2plc\win-x64\fbs2plc.exe ^ --verbose ^ --src c:\ctrlx-automation-sdk\samples-cpp\datalayer.provider.all-data\sampleSchema.fbs ^ --dest FBS/sampleSchema ^ --flatc c:\ctrlx-automation-sdk\bin\oss.flatbuffers\win-msvc-x64\release\flatc.exe ^ --plc "c:\Program Files\Rexroth\ctrlX WORKS\Studio\Common\ctrlX-PLC-Engineering.exe" ^ --addr localhost ^ --port 9002 ^ --timeout 5 ^ --plcWaitAfterStart 60 ^ --libTitle "SampleSchema Flatbuffers Handling" ^ --libCompany "Bosch Rexroth AG" ^ --libVersion 1.0.0.0 ^ --libReleased ^ --libAuthor "Bosch Rexroth AG" ^ --libPlaceHolder "SampleSchema" ^ --libDescription "Function block to read/write flatbuffers described in sampleSchema.fbs." ^ --libDefaultNamespace sampleSchema \ No newline at end of file diff --git a/samples-net/appdata/.vscode/tasks.json b/samples-net/appdata/.vscode/tasks.json index 732c3c25c..3785dc933 100644 --- a/samples-net/appdata/.vscode/tasks.json +++ b/samples-net/appdata/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/appdata/MyApplication.cs b/samples-net/appdata/MyApplication.cs index 48af3809d..9be60467b 100644 --- a/samples-net/appdata/MyApplication.cs +++ b/samples-net/appdata/MyApplication.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using Microsoft.IdentityModel.JsonWebTokens; diff --git a/samples-net/appdata/Program.cs b/samples-net/appdata/Program.cs index ce3ea4024..e62acc8ab 100644 --- a/samples-net/appdata/Program.cs +++ b/samples-net/appdata/Program.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; diff --git a/samples-net/appdata/README.md b/samples-net/appdata/README.md index 0281f1cdd..42625aaa0 100644 --- a/samples-net/appdata/README.md +++ b/samples-net/appdata/README.md @@ -1,6 +1,6 @@ # README .NET appdata -This .NET sample shows how to persist application data in ctrlX environment using an +This .NET sample shows how to persist application data in ctrlX CORE using an HTTP Listener. Please read the available [HOW-TO persist your app data](../../persistdata.md) documention for details. ## Introduction @@ -22,7 +22,7 @@ Please read the common .NET docs [here](./../../doc/dotnet.md), first. 3. Choose __Open Folder__. 4. Open the directory __appdata__. 5. Build and install snap as described [here](../README.md). -6. Checkout ctrlX Data Layer web frontend (System | Data Layer) +6. Checkout ctrlX Data Layer web frontend (Settings | Data Layer) 7. Check the output using __Diagnostics__: - Login into your ctrlX @@ -60,24 +60,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/samples-net/appdata/appdata.csproj b/samples-net/appdata/appdata.csproj index 8a53aebbb..0c0dae90b 100644 --- a/samples-net/appdata/appdata.csproj +++ b/samples-net/appdata/appdata.csproj @@ -1,4 +1,4 @@ - + Exe net6.0 @@ -14,8 +14,8 @@ - - - + + + \ No newline at end of file diff --git a/samples-net/appdata/build-snap-amd64.sh b/samples-net/appdata/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/appdata/build-snap-amd64.sh +++ b/samples-net/appdata/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/appdata/build-snap-arm64.sh b/samples-net/appdata/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/appdata/build-snap-arm64.sh +++ b/samples-net/appdata/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/appdata/snap/snapcraft.yaml b/samples-net/appdata/snap/snapcraft.yaml index 6d3fbb8a8..ac6d39bc0 100644 --- a/samples-net/appdata/snap/snapcraft.yaml +++ b/samples-net/appdata/snap/snapcraft.yaml @@ -4,14 +4,14 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-dotnet-appdata version: '1.0.0' -summary: Application data sample written in .NET for ctrlX. +summary: Application data sample written in .NET for ctrlX CORE. description: | - The sample demonstrates how to persist your application data inside ctrlX environment. + The sample demonstrates how to persist your application data inside ctrlX CORE. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -25,6 +25,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/datalayer.client.browse/.vscode/tasks.json b/samples-net/datalayer.client.browse/.vscode/tasks.json index cea2f6705..3892233f0 100644 --- a/samples-net/datalayer.client.browse/.vscode/tasks.json +++ b/samples-net/datalayer.client.browse/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/datalayer.client.browse/ClientExtensions.cs b/samples-net/datalayer.client.browse/ClientExtensions.cs index 36218ea3a..946dbe7e2 100644 --- a/samples-net/datalayer.client.browse/ClientExtensions.cs +++ b/samples-net/datalayer.client.browse/ClientExtensions.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; diff --git a/samples-net/datalayer.client.browse/Program.cs b/samples-net/datalayer.client.browse/Program.cs index d367bedaa..005414eaf 100644 --- a/samples-net/datalayer.client.browse/Program.cs +++ b/samples-net/datalayer.client.browse/Program.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using System; @@ -38,7 +20,7 @@ static void Main(string[] args) // Create a new ctrlX Data Layer system using var system = new DatalayerSystem(); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE system.Start(startBroker: false); Console.WriteLine("ctrlX Data Layer system started."); diff --git a/samples-net/datalayer.client.browse/README.md b/samples-net/datalayer.client.browse/README.md index 213599129..06291527e 100644 --- a/samples-net/datalayer.client.browse/README.md +++ b/samples-net/datalayer.client.browse/README.md @@ -95,24 +95,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-net/datalayer.client.browse/build-snap-amd64.sh b/samples-net/datalayer.client.browse/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/datalayer.client.browse/build-snap-amd64.sh +++ b/samples-net/datalayer.client.browse/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/datalayer.client.browse/build-snap-arm64.sh b/samples-net/datalayer.client.browse/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/datalayer.client.browse/build-snap-arm64.sh +++ b/samples-net/datalayer.client.browse/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/datalayer.client.browse/datalayer.client.browse.csproj b/samples-net/datalayer.client.browse/datalayer.client.browse.csproj index d43676616..742c934d7 100644 --- a/samples-net/datalayer.client.browse/datalayer.client.browse.csproj +++ b/samples-net/datalayer.client.browse/datalayer.client.browse.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples-net/datalayer.client.browse/snap/snapcraft.yaml b/samples-net/datalayer.client.browse/snap/snapcraft.yaml index 3e6d946f6..d1a2fb823 100644 --- a/samples-net/datalayer.client.browse/snap/snapcraft.yaml +++ b/samples-net/datalayer.client.browse/snap/snapcraft.yaml @@ -4,14 +4,14 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-dotnet-datalayer-client-browse version: '1.0.0' -summary: Data Layer browse sample written in .NET for ctrlX. +summary: ctrlX Data Layer browse sample written in .NET for ctrlX CORE. description: | - The sample app shows how to browse the Data Layer tree. + The sample app shows how to browse the ctrlX Data Layer tree. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -25,6 +25,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/datalayer.client.bulkread/.vscode/tasks.json b/samples-net/datalayer.client.bulkread/.vscode/tasks.json index a4bb740f2..1b907b629 100644 --- a/samples-net/datalayer.client.bulkread/.vscode/tasks.json +++ b/samples-net/datalayer.client.bulkread/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/datalayer.client.bulkread/Program.cs b/samples-net/datalayer.client.bulkread/Program.cs index 52325f34e..45ceb817d 100644 --- a/samples-net/datalayer.client.bulkread/Program.cs +++ b/samples-net/datalayer.client.bulkread/Program.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using System; @@ -40,7 +22,7 @@ static async Task Main(string[] args) // Create a new ctrlX Data Layer system using var system = new DatalayerSystem(); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE system.Start(startBroker: false); Console.WriteLine("ctrlX Data Layer system started."); diff --git a/samples-net/datalayer.client.bulkread/README.md b/samples-net/datalayer.client.bulkread/README.md index f208a13e9..6deffa6f6 100644 --- a/samples-net/datalayer.client.bulkread/README.md +++ b/samples-net/datalayer.client.bulkread/README.md @@ -86,24 +86,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-net/datalayer.client.bulkread/build-snap-amd64.sh b/samples-net/datalayer.client.bulkread/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/datalayer.client.bulkread/build-snap-amd64.sh +++ b/samples-net/datalayer.client.bulkread/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/datalayer.client.bulkread/build-snap-arm64.sh b/samples-net/datalayer.client.bulkread/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/datalayer.client.bulkread/build-snap-arm64.sh +++ b/samples-net/datalayer.client.bulkread/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/datalayer.client.bulkread/datalayer.client.bulkread.csproj b/samples-net/datalayer.client.bulkread/datalayer.client.bulkread.csproj index 21380eb6a..acf227441 100644 --- a/samples-net/datalayer.client.bulkread/datalayer.client.bulkread.csproj +++ b/samples-net/datalayer.client.bulkread/datalayer.client.bulkread.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples-net/datalayer.client.bulkread/snap/snapcraft.yaml b/samples-net/datalayer.client.bulkread/snap/snapcraft.yaml index df982aa73..d022e3824 100644 --- a/samples-net/datalayer.client.bulkread/snap/snapcraft.yaml +++ b/samples-net/datalayer.client.bulkread/snap/snapcraft.yaml @@ -4,7 +4,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-dotnet-datalayer-client-bulkread version: '1.0.0' -summary: Data Layer client bulk read sample written in .NET for ctrlX. +summary: ctrlX Data Layer client bulk read sample written in .NET for ctrlX CORE. description: | The sample demonstrates how to read values from ctrlX Data Layer tree and write out the values to console. The bulk read is performed synchron and asynchron every 10 seconds in an endless loop. @@ -12,7 +12,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -26,6 +26,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/datalayer.client/.vscode/tasks.json b/samples-net/datalayer.client/.vscode/tasks.json index 3e9a4819c..ace8047c4 100644 --- a/samples-net/datalayer.client/.vscode/tasks.json +++ b/samples-net/datalayer.client/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/datalayer.client/Program.cs b/samples-net/datalayer.client/Program.cs index b7852d90c..ac6c8bd47 100644 --- a/samples-net/datalayer.client/Program.cs +++ b/samples-net/datalayer.client/Program.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using comm.datalayer; using Datalayer; @@ -41,7 +23,7 @@ static async Task Main(string[] args) // Create a new ctrlX Data Layer system using var system = new DatalayerSystem(); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE system.Start(startBroker: false); Console.WriteLine("ctrlX Data Layer system started."); diff --git a/samples-net/datalayer.client/README.md b/samples-net/datalayer.client/README.md index 8fbbf237d..033b540d1 100644 --- a/samples-net/datalayer.client/README.md +++ b/samples-net/datalayer.client/README.md @@ -95,24 +95,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-net/datalayer.client/build-snap-amd64.sh b/samples-net/datalayer.client/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/datalayer.client/build-snap-amd64.sh +++ b/samples-net/datalayer.client/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/datalayer.client/build-snap-arm64.sh b/samples-net/datalayer.client/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/datalayer.client/build-snap-arm64.sh +++ b/samples-net/datalayer.client/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/datalayer.client/datalayer.client.csproj b/samples-net/datalayer.client/datalayer.client.csproj index 21380eb6a..acf227441 100644 --- a/samples-net/datalayer.client/datalayer.client.csproj +++ b/samples-net/datalayer.client/datalayer.client.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples-net/datalayer.client/snap/snapcraft.yaml b/samples-net/datalayer.client/snap/snapcraft.yaml index 7284daec3..9ad4fc9da 100644 --- a/samples-net/datalayer.client/snap/snapcraft.yaml +++ b/samples-net/datalayer.client/snap/snapcraft.yaml @@ -4,7 +4,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-dotnet-datalayer-client version: '1.0.0' -summary: Data Layer client sample written in .NET for ctrlX. +summary: ctrlX Data Layer client sample written in .NET for ctrlX CORE. description: | The sample demonstrates how to read values from ctrlX Data Layer tree and write out the values to console. A subscription is used to get values by data change event in a deterministic publish interval. @@ -13,7 +13,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -27,6 +27,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/datalayer.mqtt/.vscode/tasks.json b/samples-net/datalayer.mqtt/.vscode/tasks.json index 4fdc1ad82..984433da7 100644 --- a/samples-net/datalayer.mqtt/.vscode/tasks.json +++ b/samples-net/datalayer.mqtt/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/datalayer.mqtt/Base/MqttBaseNodeHandler.cs b/samples-net/datalayer.mqtt/Base/MqttBaseNodeHandler.cs index a4a5c5d59..ef3076e25 100644 --- a/samples-net/datalayer.mqtt/Base/MqttBaseNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Base/MqttBaseNodeHandler.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using comm.datalayer; using Datalayer; diff --git a/samples-net/datalayer.mqtt/Base/MqttRootNodeHandler.cs b/samples-net/datalayer.mqtt/Base/MqttRootNodeHandler.cs index c15fda8c5..3bdd9f9c9 100644 --- a/samples-net/datalayer.mqtt/Base/MqttRootNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Base/MqttRootNodeHandler.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using Samples.Datalayer.MQTT.Client; @@ -62,12 +44,12 @@ public MqttRootNodeHandler(IClient client, IProvider provider, string brokerAddr public ManualResetEvent Lock { get; } = new(false); /// - /// Gets the Data Layer provider + /// Gets the ctrlX Data Layer provider /// public IProvider Provider { get; private set; } /// - /// Gets the Data Layer client + /// Gets the ctrlX Data Layer client /// public IClient Client { get; private set; } @@ -94,7 +76,7 @@ public override DLR_RESULT Start() //Wait until client connected if (WaitUntilConnected(Client, TimeoutMillis).IsBad()) { - Console.WriteLine("Data Layer client could not be connected!"); + Console.WriteLine("ctrlX Data Layer client could not be connected!"); return DLR_RESULT.DL_FAILED; } @@ -111,7 +93,7 @@ public override DLR_RESULT Start() // Start the Provider if (Provider.Start().IsBad()) { - Console.WriteLine("Data Layer provider could not be started!"); + Console.WriteLine("ctrlX Data Layer provider could not be started!"); return DLR_RESULT.DL_FAILED; } @@ -132,7 +114,7 @@ public override DLR_RESULT Start() /// public override DLR_RESULT Stop() { - // Stop Data Layer provider + // Stop ctrlX Data Layer provider var result = Provider.Stop(); Console.Write(value: $"Provider stopped: {result}"); diff --git a/samples-net/datalayer.mqtt/Base/Names.cs b/samples-net/datalayer.mqtt/Base/Names.cs index fdb134577..30b6d066b 100644 --- a/samples-net/datalayer.mqtt/Base/Names.cs +++ b/samples-net/datalayer.mqtt/Base/Names.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Samples.Datalayer.MQTT.Base { /// diff --git a/samples-net/datalayer.mqtt/Base/ProviderExtensions.cs b/samples-net/datalayer.mqtt/Base/ProviderExtensions.cs index e8958249d..2634e0151 100644 --- a/samples-net/datalayer.mqtt/Base/ProviderExtensions.cs +++ b/samples-net/datalayer.mqtt/Base/ProviderExtensions.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using comm.datalayer; using Datalayer; diff --git a/samples-net/datalayer.mqtt/Base/VariantExtensions.cs b/samples-net/datalayer.mqtt/Base/VariantExtensions.cs index 9b2c4f8b2..e860f7e1d 100644 --- a/samples-net/datalayer.mqtt/Base/VariantExtensions.cs +++ b/samples-net/datalayer.mqtt/Base/VariantExtensions.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using System; diff --git a/samples-net/datalayer.mqtt/Client/MqttClientNodeHandler.cs b/samples-net/datalayer.mqtt/Client/MqttClientNodeHandler.cs index 20a9463ef..b649e30da 100644 --- a/samples-net/datalayer.mqtt/Client/MqttClientNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Client/MqttClientNodeHandler.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using Samples.Datalayer.MQTT.Base; @@ -45,7 +27,7 @@ public MqttClientNodeHandler(MqttRootNodeHandler root, MqttBaseNodeHandler paren //Add MQTT Client connected event handler Root.MqttClient.Connected += args => { - UpdateStatus(DLR_RESULT.DL_OK); + return Task.Run(() => UpdateStatus(DLR_RESULT.DL_OK)); }; //Add MQTT Client disconnected event handler @@ -348,7 +330,7 @@ private async Task ConnectMqttAsync() Root.MqttClient.CleanSession = GetNode(Names.CleanSession).Value.ToBool(); Root.MqttClient.Username = GetNode(Names.Username).Value.ToString(); Root.MqttClient.Password = GetNode(Names.Password).Value.ToString(); - Root.MqttClient.CommunicationTimeout = TimeSpan.FromMilliseconds(GetNode(Names.CommunicationTimeoutMillis).Value.ToInt32()); + Root.MqttClient.Timeout = TimeSpan.FromMilliseconds(GetNode(Names.CommunicationTimeoutMillis).Value.ToInt32()); Root.MqttClient.KeepAlivePeriod = TimeSpan.FromMilliseconds(GetNode(Names.KeepAlivePeriodMillis).Value.ToInt32()); var task = Root.MqttClient.ConnectAsync(); diff --git a/samples-net/datalayer.mqtt/Client/MqttClientWrapper.cs b/samples-net/datalayer.mqtt/Client/MqttClientWrapper.cs index ae2eb202b..be0d71047 100644 --- a/samples-net/datalayer.mqtt/Client/MqttClientWrapper.cs +++ b/samples-net/datalayer.mqtt/Client/MqttClientWrapper.cs @@ -1,40 +1,17 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using MQTTnet; using MQTTnet.Client; -using MQTTnet.Client.Connecting; -using MQTTnet.Client.Disconnecting; -using MQTTnet.Client.Options; -using MQTTnet.Client.Publishing; -using MQTTnet.Client.Subscribing; -using MQTTnet.Client.Unsubscribing; using MQTTnet.Exceptions; using MQTTnet.Formatter; using MQTTnet.Protocol; using System; +using System.Linq; using System.Net; using System.Threading.Tasks; @@ -55,17 +32,17 @@ internal sealed class MqttClientWrapper /// /// Message Received event /// - public event Action MessageReceived; + public event Func MessageReceived; /// /// Connected event /// - public event Action Connected; + public event Func Connected; /// /// Disconnected event /// - public event Action Disconnected; + public event Func Disconnected; /// /// Creates a MQTT client wrapper @@ -77,11 +54,12 @@ public MqttClientWrapper() _client = new MqttFactory().CreateMqttClient(); //Add handlers - _client.UseConnectedHandler(OnConnected); - _client.UseDisconnectedHandler(OnDisconnected); - _client.UseApplicationMessageReceivedHandler(OnMessageReceived); + _client.ConnectedAsync += OnConnected; + _client.DisconnectedAsync += OnDisconnected; + _client.ApplicationMessageReceivedAsync += OnMessageReceived; } + #region Properties /// @@ -112,7 +90,7 @@ public MqttClientWrapper() /// /// Gets or sets the communication timeout /// - public TimeSpan CommunicationTimeout { get; set; } = TimeSpan.FromMilliseconds(10_000); + public TimeSpan Timeout { get; set; } = TimeSpan.FromMilliseconds(10_000); /// /// Gets or sets the keepalive period @@ -162,7 +140,7 @@ public async Task ConnectAsync() .WithProtocolVersion(MqttProtocolVersion.V500) //Version 5 is Mandatory, because we make use of the SubscriptionIdentifier feature .WithCleanSession(CleanSession) .WithCredentials(username: Username, password: Password) - .WithCommunicationTimeout(CommunicationTimeout) + .WithTimeout(Timeout) .WithKeepAlivePeriod(KeepAlivePeriod) //.WithSessionExpiryInterval(60000) //.WithTls() @@ -208,7 +186,7 @@ public async Task DisconnectAsync() var options = new MqttClientDisconnectOptions { - ReasonCode = MqttClientDisconnectReason.NormalDisconnection, + Reason = MqttClientDisconnectOptionsReason.NormalDisconnection, ReasonString = "normal disconnection" }; @@ -342,7 +320,7 @@ public async Task SubscribeAsync( var task = _client.SubscribeAsync(options); await task; - var resultCode = task.Result.Items[0].ResultCode; + var resultCode = task.Result.Items.FirstOrDefault()?.ResultCode; var success = (quality == MqttQualityOfServiceLevel.AtMostOnce && resultCode == MqttClientSubscribeResultCode.GrantedQoS0) || @@ -400,7 +378,7 @@ public async Task UnsubscribeAsync(string topic) var task = _client.UnsubscribeAsync(options); var result = await task; - var resultCode = result.Items[0].ReasonCode; + var resultCode = task.Result.Items.FirstOrDefault()?.ResultCode; //Failed if (resultCode != MqttClientUnsubscribeResultCode.Success) @@ -465,36 +443,37 @@ public static string DefaultClientId() /// Client connected event handler /// /// - private void OnConnected(MqttClientConnectedEventArgs args) + private Task OnConnected(MqttClientConnectedEventArgs args) { - Console.WriteLine($"Client Connected. {args.AuthenticateResult?.ResultCode}"); + Console.WriteLine($"Client Connected. {args.ConnectResult?.ResultCode}"); //Forward - Connected?.Invoke(args); + return Connected?.Invoke(args); } + /// /// Client disconnected event handler /// /// - private void OnDisconnected(MqttClientDisconnectedEventArgs args) + private Task OnDisconnected(MqttClientDisconnectedEventArgs args) { Console.WriteLine($"Client Disconnected. WasConnected: {args.ClientWasConnected}, Reason: {args.Reason}"); //Forward - Disconnected?.Invoke(args); + return Disconnected?.Invoke(args); } /// /// Client message received eventhandler /// /// - private void OnMessageReceived(MqttApplicationMessageReceivedEventArgs args) + private Task OnMessageReceived(MqttApplicationMessageReceivedEventArgs args) { - //Console.WriteLine($"Message Received: {args.ApplicationMessage.Topic}, PayLoad: {Encoding.UTF8.GetString(args.ApplicationMessage.Payload)}, SubscriptionId: {args.ApplicationMessage.SubscriptionIdentifiers?[0]}"); + //Console.WriteLine($"Message Received: {args.ApplicationMessage.Topic}, PayLoad: {Encoding.UTF8.GetString(args.ApplicationMessage.PayloadSegment)}, SubscriptionId: {args.ApplicationMessage.SubscriptionIdentifiers?[0]}"); //Forward - MessageReceived?.Invoke(args); + return MessageReceived?.Invoke(args); } #endregion } diff --git a/samples-net/datalayer.mqtt/Program.cs b/samples-net/datalayer.mqtt/Program.cs index 4826d5435..3e2999b35 100644 --- a/samples-net/datalayer.mqtt/Program.cs +++ b/samples-net/datalayer.mqtt/Program.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using Samples.Datalayer.MQTT.Base; @@ -41,7 +23,7 @@ static void Main(string[] args) // Create a new ctrlX Data Layer system using var system = new DatalayerSystem(); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE system.Start(startBroker: false); Console.WriteLine("ctrlX Data Layer system started."); diff --git a/samples-net/datalayer.mqtt/Pub/MqttPubConfigNodeHandler.cs b/samples-net/datalayer.mqtt/Pub/MqttPubConfigNodeHandler.cs index 7f8d6ec2b..8afd388d7 100644 --- a/samples-net/datalayer.mqtt/Pub/MqttPubConfigNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Pub/MqttPubConfigNodeHandler.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using comm.datalayer; using Datalayer; @@ -130,7 +112,7 @@ public override DLR_RESULT Start() } Nodes.Add(node.Address, node); - //Subscribe to Data layer + //Subscribe to ctrlX Data Layer if (SubscribeDatalayer().IsBad()) { return DLR_RESULT.DL_FAILED; @@ -333,7 +315,7 @@ public override void OnRemove(string address, IProviderNodeResult result) #region Private /// - /// Gets or creates a Data Layer subscription by current publish interval + /// Gets or creates a ctrlX Data Layer subscription by current publish interval /// /// private (DLR_RESULT, ISubscription) GetOrCreateDatalayerSubscriptionByPublishInterval() @@ -378,7 +360,7 @@ public override void OnRemove(string address, IProviderNodeResult result) private DLR_RESULT SubscribeDatalayer() { var address = GetNode(Names.SourceAddress).Value.ToString(); - Console.WriteLine($"Subscribe Data Layer: {address}"); + Console.WriteLine($"Subscribe ctrlX Data Layer: {address}"); //Request matching subscription var (result, subscription) = GetOrCreateDatalayerSubscriptionByPublishInterval(); @@ -397,13 +379,13 @@ private DLR_RESULT SubscribeDatalayer() /// - /// Unsubscribes the given address from the Data Layer + /// Unsubscribes the given address from the ctrlX Data Layer /// /// private DLR_RESULT UnsubscribeDatalayer() { var address = GetNode(Names.SourceAddress).Value.ToString(); - Console.WriteLine($"Unsubscribe Data Layer: {address}"); + Console.WriteLine($"Unsubscribe ctrlX Data Layer: {address}"); //Request matching Subscription var (result, subscription) = GetOrCreateDatalayerSubscriptionByPublishInterval(); @@ -427,7 +409,7 @@ private DLR_RESULT UnsubscribeDatalayer() } /// - /// Indicates whether the given address can be unsubscribed from Data Layer + /// Indicates whether the given address can be unsubscribed from ctrlX Data Layer /// /// /// @@ -438,7 +420,7 @@ private bool IsSubscriptionInUse(string address) } /// - /// Data Layer subscription data changed event + /// ctrlX Data Layer subscription data changed event /// /// /// @@ -465,7 +447,7 @@ private async void OnDataChanged(ISubscription subscription, IDataChangedEventAr } /// - /// Publishes the value of a Data Layer address to current topic + /// Publishes the value of a ctrlX Data Layer address to current topic /// /// /// diff --git a/samples-net/datalayer.mqtt/Pub/MqttPubNodeHandler.cs b/samples-net/datalayer.mqtt/Pub/MqttPubNodeHandler.cs index 01c8db22f..fa3a7676f 100644 --- a/samples-net/datalayer.mqtt/Pub/MqttPubNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Pub/MqttPubNodeHandler.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using Samples.Datalayer.MQTT.Base; diff --git a/samples-net/datalayer.mqtt/README.md b/samples-net/datalayer.mqtt/README.md index 00e72d065..21308e76b 100644 --- a/samples-net/datalayer.mqtt/README.md +++ b/samples-net/datalayer.mqtt/README.md @@ -1,6 +1,6 @@ # README .NET datalayer.mqtt -This .NET sample connects the __Data Layer__ to a __MQTT 5__ broker. +This .NET sample connects the __ctrlX Data Layer__ to a __MQTT 5__ broker. The sample is based on [MQTT.net](https://github.com/chkr1011/MQTTnet). __IMPORTANT__: @@ -11,7 +11,7 @@ Please read the _Best Practise_ section in common .NET documentation for more de ## Introduction -MQTT sample showing PUB/SUB with Data Layer in full interaction. +MQTT sample showing PUB/SUB with ctrlX Data Layer in full interaction. Connect Datalayer to any MQTT Broker for data synchronization (SUB) or publishing (PUB) or even full broker synchronisation (__Topic Scanner__). @@ -29,17 +29,17 @@ We recommend to use [mosquitto MQTT Broker](https://mosquitto.org/download/), wh The MQTT sample demonstrates -+ How easy it is to interact __Data Layer with MQTT__ ++ How easy it is to interact __ctrlX Data Layer with MQTT__ + A proposal to organize a set of logical grouped provided nodes using a handler hierarchy and how to populate nodes using some __level node handlers__ , responsible for it's own set of children nodes + How to create an __light-weight node handler__, returning just his own managed _virtual_ nodes on _OnBrowse()_ without the need of registering all nodes one-by-one which is very efficient for a large set of dynamically created nodes. -+ A concept of creating configurable __PUB configurations__, publishing the value of a Data Layer source address to a MQTT topic. ++ A concept of creating configurable __PUB configurations__, publishing the value of a ctrlX Data Layer source address to a MQTT topic. -+ A concept of creating configurable __SUB configurations__, subscribing a MQTT topic (wildcards supported) and writing it back to a Data Layer target address. ++ A concept of creating configurable __SUB configurations__, subscribing a MQTT topic (wildcards supported) and writing it back to a ctrlX Data Layer target address. -+ On top a fully functional __Topic Scanner__, scanning all topics present on the broker and revealing it into the address space of the Data Layer, which is very handy for other Data Layer clients to access MQTT related data _immediately_ without connecting to MQTT itself. The most recent message of the topic will be memory-persisted as and accessible via a simple Data Layer address. ++ On top a fully functional __Topic Scanner__, scanning all topics present on the broker and revealing it into the address space of the ctrlX Data Layer, which is very handy for other ctrlX Data Layer clients to access MQTT related data _immediately_ without connecting to MQTT itself. The most recent message of the topic will be memory-persisted as and accessible via a simple ctrlX Data Layer address. __Notes__: @@ -57,7 +57,7 @@ Please read the common .NET docs [here](./../../doc/dotnet.md), first. 3. Choose __Open Folder__. 4. Open the directory __datalayer.mqtt__. 5. Build and install snap as described [here](./../README.md). -6. Checkout ctrlX Data Layer web frontend (System | Data Layer) +6. Checkout ctrlX Data Layer web frontend (Settings | Data Layer) 7. Check the output using __Diagnostics__: - Login into your ctrlX @@ -94,24 +94,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/samples-net/datalayer.mqtt/Sub/MqttSubBaseNodeHandler.cs b/samples-net/datalayer.mqtt/Sub/MqttSubBaseNodeHandler.cs index e96df3f69..b61ca5976 100644 --- a/samples-net/datalayer.mqtt/Sub/MqttSubBaseNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Sub/MqttSubBaseNodeHandler.cs @@ -1,29 +1,11 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; -using MQTTnet; +using MQTTnet.Client; using MQTTnet.Protocol; using Samples.Datalayer.MQTT.Base; using System; @@ -80,7 +62,7 @@ public MqttSubBaseNodeHandler(MqttRootNodeHandler root, MqttBaseNodeHandler pare /// MQTT message received event handler /// /// - protected abstract void OnMessageReceived(MqttApplicationMessageReceivedEventArgs args); + protected abstract Task OnMessageReceived(MqttApplicationMessageReceivedEventArgs args); #endregion diff --git a/samples-net/datalayer.mqtt/Sub/MqttSubConfigNodeHandler.cs b/samples-net/datalayer.mqtt/Sub/MqttSubConfigNodeHandler.cs index 093698180..cfb74eb18 100644 --- a/samples-net/datalayer.mqtt/Sub/MqttSubConfigNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Sub/MqttSubConfigNodeHandler.cs @@ -1,35 +1,18 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using MQTTnet; +using MQTTnet.Client; using MQTTnet.Protocol; -using MQTTnet.Server; using Samples.Datalayer.MQTT.Base; using Samples.Datalayer.MQTT.Client; using System; using System.Text; +using System.Threading.Tasks; namespace Samples.Datalayer.MQTT.Sub { @@ -257,7 +240,7 @@ public override void OnRemove(string address, IProviderNodeResult result) /// MQTT message received event handler /// /// - protected override async void OnMessageReceived(MqttApplicationMessageReceivedEventArgs args) + protected override async Task OnMessageReceived(MqttApplicationMessageReceivedEventArgs args) { //We have to filter for our subscription to prevent duplicates if any other SUB is interested in same topic if (args.ApplicationMessage.SubscriptionIdentifiers[0] != SubscriptionId) @@ -272,7 +255,7 @@ protected override async void OnMessageReceived(MqttApplicationMessageReceivedEv } //Filter for null payload which may occure - if (args.ApplicationMessage.Payload == null) + if (args.ApplicationMessage.PayloadSegment== null) { return; } @@ -281,14 +264,14 @@ protected override async void OnMessageReceived(MqttApplicationMessageReceivedEv var topic = GetNode(Names.Topic).Value.ToString(); //Match (filter) for our topic - if (!MqttTopicFilterComparer.IsMatch(args.ApplicationMessage.Topic, topic)) + if (MqttTopicFilterComparer.Compare(args.ApplicationMessage.Topic, topic) == MqttTopicFilterCompareResult.NoMatch) { return; } var targetAddress = GetNode(Names.TargetAddress).Value.ToString(); var jsonDataType = GetNode(Names.JsonDataType).Value.ToString(); - var stringifiedPayload = Encoding.UTF8.GetString(args.ApplicationMessage.Payload); + var stringifiedPayload = Encoding.UTF8.GetString(args.ApplicationMessage.PayloadSegment); //Convert to write variant var (result, writeValue) = ToVariant(jsonDataType, stringifiedPayload); @@ -298,7 +281,7 @@ protected override async void OnMessageReceived(MqttApplicationMessageReceivedEv return; } - //Write the Value to the Data Layer + //Write the Value to the ctrlX Data Layer var task = Root.Client.WriteAsync(targetAddress, writeValue); var taskResult = await task; if (taskResult.Result.IsBad()) diff --git a/samples-net/datalayer.mqtt/Sub/MqttSubNodeHandler.cs b/samples-net/datalayer.mqtt/Sub/MqttSubNodeHandler.cs index ab74e8956..3bec749aa 100644 --- a/samples-net/datalayer.mqtt/Sub/MqttSubNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Sub/MqttSubNodeHandler.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using Samples.Datalayer.MQTT.Base; diff --git a/samples-net/datalayer.mqtt/Sub/MqttSubScannerNodeHandler.cs b/samples-net/datalayer.mqtt/Sub/MqttSubScannerNodeHandler.cs index 3582bf28b..4be1cb1d7 100644 --- a/samples-net/datalayer.mqtt/Sub/MqttSubScannerNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Sub/MqttSubScannerNodeHandler.cs @@ -1,37 +1,20 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using comm.datalayer; using Datalayer; using Google.FlatBuffers; -using MQTTnet; +using MQTTnet.Client; using MQTTnet.Protocol; using Samples.Datalayer.MQTT.Base; using System; using System.Collections.Concurrent; using System.Linq; using System.Text; +using System.Threading.Tasks; namespace Samples.Datalayer.MQTT.Sub { @@ -222,35 +205,38 @@ public override void OnBrowse(string address, IProviderNodeResult result) /// MQTT message received event handler /// /// - protected override void OnMessageReceived(MqttApplicationMessageReceivedEventArgs args) + protected override Task OnMessageReceived(MqttApplicationMessageReceivedEventArgs args) { - //We have to filter for our subscription to prevent duplicates if any other SUB is interested in same topic - if (args.ApplicationMessage.SubscriptionIdentifiers[0] != SubscriptionId) + return Task.Run(() => { - return; - } - - //Filter for null topic which may occure - if (args.ApplicationMessage.Topic == null) - { - return; - } - - //Filter for null payload which may occure - if (args.ApplicationMessage.Payload == null) - { - return; - } - - //Stringify the payload - var stringifiedPayload = Encoding.UTF8.GetString(args.ApplicationMessage.Payload); - - //Create a Variant of best matching type (Supported int32, double, string) - var value = ToVariant(stringifiedPayload); - var address = $"{FullAddress}/{args.ApplicationMessage.Topic}"; - - //Add node if not existing or update with current value - _nodes.AddOrUpdate(address, value, (k, v) => value); + //We have to filter for our subscription to prevent duplicates if any other SUB is interested in same topic + if (args.ApplicationMessage.SubscriptionIdentifiers[0] != SubscriptionId) + { + return; + } + + //Filter for null topic which may occure + if (args.ApplicationMessage.Topic == null) + { + return; + } + + //Filter for null payload which may occure + if (args.ApplicationMessage.PayloadSegment == null) + { + return; + } + + //Stringify the payload + var stringifiedPayload = Encoding.UTF8.GetString(args.ApplicationMessage.PayloadSegment); + + //Create a Variant of best matching type (Supported int32, double, string) + var value = ToVariant(stringifiedPayload); + var address = $"{FullAddress}/{args.ApplicationMessage.Topic}"; + + //Add node if not existing or update with current value + _nodes.AddOrUpdate(address, value, (k, v) => value); + }); } #endregion diff --git a/samples-net/datalayer.mqtt/Test/MqttTestNodeHandler.cs b/samples-net/datalayer.mqtt/Test/MqttTestNodeHandler.cs index 87adbc72c..e05b8f7c5 100644 --- a/samples-net/datalayer.mqtt/Test/MqttTestNodeHandler.cs +++ b/samples-net/datalayer.mqtt/Test/MqttTestNodeHandler.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using Samples.Datalayer.MQTT.Base; diff --git a/samples-net/datalayer.mqtt/build-snap-amd64.sh b/samples-net/datalayer.mqtt/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/datalayer.mqtt/build-snap-amd64.sh +++ b/samples-net/datalayer.mqtt/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/datalayer.mqtt/build-snap-arm64.sh b/samples-net/datalayer.mqtt/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/datalayer.mqtt/build-snap-arm64.sh +++ b/samples-net/datalayer.mqtt/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/datalayer.mqtt/datalayer.mqtt.csproj b/samples-net/datalayer.mqtt/datalayer.mqtt.csproj index 3915a4774..e63498993 100644 --- a/samples-net/datalayer.mqtt/datalayer.mqtt.csproj +++ b/samples-net/datalayer.mqtt/datalayer.mqtt.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/samples-net/datalayer.mqtt/snap/snapcraft.yaml b/samples-net/datalayer.mqtt/snap/snapcraft.yaml index 66286b789..7cd4f8833 100644 --- a/samples-net/datalayer.mqtt/snap/snapcraft.yaml +++ b/samples-net/datalayer.mqtt/snap/snapcraft.yaml @@ -4,14 +4,14 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-dotnet-datalayer-mqtt version: '1.0.0' -summary: Data Layer MQTT sample written in .NET for ctrlX. +summary: ctrlX Data Layer MQTT sample written in .NET for ctrlX CORE. description: | - MQTT sample showing PUB/SUB with Data Layer in full interaction. + MQTT sample showing PUB/SUB with ctrlX Data Layer in full interaction. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -25,6 +25,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/datalayer.provider.alldata/.vscode/tasks.json b/samples-net/datalayer.provider.alldata/.vscode/tasks.json index 79e04b37b..f9863daea 100644 --- a/samples-net/datalayer.provider.alldata/.vscode/tasks.json +++ b/samples-net/datalayer.provider.alldata/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/datalayer.provider.alldata/DataType.cs b/samples-net/datalayer.provider.alldata/DataType.cs index cfe7e079d..53ed49eb4 100644 --- a/samples-net/datalayer.provider.alldata/DataType.cs +++ b/samples-net/datalayer.provider.alldata/DataType.cs @@ -1,4 +1,9 @@ -namespace Samples.Datalayer.Provider.Alldata +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ +namespace Samples.Datalayer.Provider.Alldata { /// /// Defines the . diff --git a/samples-net/datalayer.provider.alldata/DataTypes.cs b/samples-net/datalayer.provider.alldata/DataTypes.cs index 7453cb1d2..955e739eb 100644 --- a/samples-net/datalayer.provider.alldata/DataTypes.cs +++ b/samples-net/datalayer.provider.alldata/DataTypes.cs @@ -1,4 +1,9 @@ -namespace Samples.Datalayer.Provider.Alldata +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ +namespace Samples.Datalayer.Provider.Alldata { /// /// Defines the . diff --git a/samples-net/datalayer.provider.alldata/Node.cs b/samples-net/datalayer.provider.alldata/Node.cs index ae8c65009..815fcf916 100644 --- a/samples-net/datalayer.provider.alldata/Node.cs +++ b/samples-net/datalayer.provider.alldata/Node.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; diff --git a/samples-net/datalayer.provider.alldata/Program.cs b/samples-net/datalayer.provider.alldata/Program.cs index 3202f8024..b346480e1 100644 --- a/samples-net/datalayer.provider.alldata/Program.cs +++ b/samples-net/datalayer.provider.alldata/Program.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; @@ -52,7 +34,7 @@ internal static void Main(string[] args) // Create a new ctrlX Data Layer system using var system = new DatalayerSystem(); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE system.Start(); Console.WriteLine("ctrlX Data Layer system started."); @@ -101,7 +83,8 @@ internal static void Main(string[] args) CreateStaticNode(new Variant(new DateTime[] { utcNow, DateTime.Now, DateTime.Today }), DataTypes.ArrayOfTimestamp) }; - // Register all static nodes with ReadOnlyNodeHandler + // Register all static nodes (read/write) using the ReadWriteNodeHandler. + // Change to ReadOnlyNodeHandler for read-only. foreach (var node in staticNodes) { var handler = new ReadWriteNodeHandler(node); @@ -140,10 +123,11 @@ internal static void Main(string[] args) CreateDynamicNode(new Variant(new DateTime[] { utcNow, utcNow, utcNow, utcNow, utcNow, utcNow, utcNow, utcNow }), DataTypes.ArrayOfTimestamp) }; - // Register all dynamic nodes with ReadWriteNodeHandler + // Register all dynamic nodes (read/write) using the ReadWriteNodeHandler. + // Change to ReadOnlyNodeHandler for read-only. foreach (var node in dynamicNodes) { - var handler = new ReadOnlyNodeHandler(node); + var handler = new ReadWriteNodeHandler(node); provider.RegisterNode(node.Address, handler); } diff --git a/samples-net/datalayer.provider.alldata/README.md b/samples-net/datalayer.provider.alldata/README.md index 854976072..17cb2ad61 100644 --- a/samples-net/datalayer.provider.alldata/README.md +++ b/samples-net/datalayer.provider.alldata/README.md @@ -40,7 +40,7 @@ Please read the common .NET docs [here](./../../doc/dotnet.md), first. 3. Choose __Open Folder__. 4. Open the directory __datalayer.provider.alldata__. 5. Build and install snap as described [here](./../README.md). -6. Checkout ctrlX Data Layer web frontend (System | Data Layer) +6. Checkout ctrlX Data Layer web frontend (Settings | Data Layer) 7. Check the output using __Diagnostics__: - Login into your ctrlX @@ -57,7 +57,7 @@ Please read the common .NET docs [here](./../../doc/dotnet.md), first. ``` ## Screenshot -![crtrX Data Layer tree](./docs/images/datalayer.provider.alldata/datalayer.provider.alldata.png) +![crtrX ctrlX Data Layer tree](./docs/images/datalayer.provider.alldata/datalayer.provider.alldata.png) ## Install the App @@ -81,24 +81,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/samples-net/datalayer.provider.alldata/ReadOnlyNodeHandler.cs b/samples-net/datalayer.provider.alldata/ReadOnlyNodeHandler.cs index 4ce460cbc..fda5c0f51 100644 --- a/samples-net/datalayer.provider.alldata/ReadOnlyNodeHandler.cs +++ b/samples-net/datalayer.provider.alldata/ReadOnlyNodeHandler.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; diff --git a/samples-net/datalayer.provider.alldata/ReadWriteNodeHandler.cs b/samples-net/datalayer.provider.alldata/ReadWriteNodeHandler.cs index c59d603dd..6a49fbc3d 100644 --- a/samples-net/datalayer.provider.alldata/ReadWriteNodeHandler.cs +++ b/samples-net/datalayer.provider.alldata/ReadWriteNodeHandler.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; diff --git a/samples-net/datalayer.provider.alldata/build-snap-amd64.sh b/samples-net/datalayer.provider.alldata/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/datalayer.provider.alldata/build-snap-amd64.sh +++ b/samples-net/datalayer.provider.alldata/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/datalayer.provider.alldata/build-snap-arm64.sh b/samples-net/datalayer.provider.alldata/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/datalayer.provider.alldata/build-snap-arm64.sh +++ b/samples-net/datalayer.provider.alldata/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/datalayer.provider.alldata/datalayer.provider.alldata.csproj b/samples-net/datalayer.provider.alldata/datalayer.provider.alldata.csproj index 3295a8819..45f79fe9e 100644 --- a/samples-net/datalayer.provider.alldata/datalayer.provider.alldata.csproj +++ b/samples-net/datalayer.provider.alldata/datalayer.provider.alldata.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples-net/datalayer.provider.alldata/sample/schema/InertialValue.cs b/samples-net/datalayer.provider.alldata/sample/schema/InertialValue.cs index 685fdddfe..c6b7e9e29 100644 --- a/samples-net/datalayer.provider.alldata/sample/schema/InertialValue.cs +++ b/samples-net/datalayer.provider.alldata/sample/schema/InertialValue.cs @@ -13,7 +13,7 @@ public struct InertialValue : IFlatbufferObject { private Table __p; public ByteBuffer ByteBuffer { get { return __p.bb; } } - public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_3_3(); } + public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_5_26(); } public static InertialValue GetRootAsInertialValue(ByteBuffer _bb) { return GetRootAsInertialValue(_bb, new InertialValue()); } public static InertialValue GetRootAsInertialValue(ByteBuffer _bb, InertialValue obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); } diff --git a/samples-net/datalayer.provider.alldata/snap/snapcraft.yaml b/samples-net/datalayer.provider.alldata/snap/snapcraft.yaml index 0e6da57d6..1ab186cd7 100644 --- a/samples-net/datalayer.provider.alldata/snap/snapcraft.yaml +++ b/samples-net/datalayer.provider.alldata/snap/snapcraft.yaml @@ -4,7 +4,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-dotnet-datalayer-provider-alldata version: '1.0.0' -summary: Data Layer provider all data sample written in .NET for ctrlX. +summary: ctrlX Data Layer provider all data sample written in .NET for ctrlX CORE. description: | The sample demonstrates how to provide all available data types to the ctrlX Data Layer. The demo creates a 'static' and a 'dynamic' folder under the root node 'samples'. @@ -14,7 +14,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -28,6 +28,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/datalayer.provider.virtual/.vscode/tasks.json b/samples-net/datalayer.provider.virtual/.vscode/tasks.json index 6b6df449f..2a914e175 100644 --- a/samples-net/datalayer.provider.virtual/.vscode/tasks.json +++ b/samples-net/datalayer.provider.virtual/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/datalayer.provider.virtual/Program.cs b/samples-net/datalayer.provider.virtual/Program.cs index 3a317883f..a0ba99edd 100644 --- a/samples-net/datalayer.provider.virtual/Program.cs +++ b/samples-net/datalayer.provider.virtual/Program.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using System; @@ -38,7 +20,7 @@ static void Main(string[] args) // Create a new ctrlX Data Layer system using var system = new DatalayerSystem(); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE system.Start(startBroker: false); Console.WriteLine("ctrlX Data Layer system started."); diff --git a/samples-net/datalayer.provider.virtual/ProviderExtensions.cs b/samples-net/datalayer.provider.virtual/ProviderExtensions.cs index 4ab79974b..fc19f9731 100644 --- a/samples-net/datalayer.provider.virtual/ProviderExtensions.cs +++ b/samples-net/datalayer.provider.virtual/ProviderExtensions.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; using System; diff --git a/samples-net/datalayer.provider.virtual/README.md b/samples-net/datalayer.provider.virtual/README.md index 561392db4..4fb2385ac 100644 --- a/samples-net/datalayer.provider.virtual/README.md +++ b/samples-net/datalayer.provider.virtual/README.md @@ -27,7 +27,7 @@ Please read the common .NET docs [here](./../../doc/dotnet.md), first. 3. Choose __Open Folder__. 4. Open the directory __datalayer.provider.virtual__. 5. Build and install snap as described [here](./../README.md). -6. Checkout ctrlX Data Layer web frontend (System | Data Layer) +6. Checkout ctrlX Data Layer web frontend (Settings | Data Layer) 7. Check the output using __Diagnostics__: - Login into your ctrlX @@ -65,24 +65,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/samples-net/datalayer.provider.virtual/VirtualNodeHandler.cs b/samples-net/datalayer.provider.virtual/VirtualNodeHandler.cs index 89f2b5f62..9f648b0d7 100644 --- a/samples-net/datalayer.provider.virtual/VirtualNodeHandler.cs +++ b/samples-net/datalayer.provider.virtual/VirtualNodeHandler.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using comm.datalayer; using Datalayer; @@ -73,7 +55,7 @@ private record VirtualNode(string Address, IVariant Value, NodeClass Category, b public ManualResetEvent Lock { get; } = new(false); /// - /// Gets the Data Layer provider + /// Gets the ctrlX Data Layer provider /// public IProvider Provider { get; private set; } @@ -136,7 +118,7 @@ public DLR_RESULT Start() // Start the Provider if (Provider.Start().IsBad()) { - Console.WriteLine("Data Layer provider could not be started!"); + Console.WriteLine("ctrlX Data Layer provider could not be started!"); return DLR_RESULT.DL_FAILED; } @@ -149,7 +131,7 @@ public DLR_RESULT Start() /// public DLR_RESULT Stop() { - // Stop Data Layer provider + // Stop ctrlX Data Layer provider var result = Provider.Stop(); Console.Write(value: $"Provider stopped: {result}"); diff --git a/samples-net/datalayer.provider.virtual/build-snap-amd64.sh b/samples-net/datalayer.provider.virtual/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/datalayer.provider.virtual/build-snap-amd64.sh +++ b/samples-net/datalayer.provider.virtual/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/datalayer.provider.virtual/build-snap-arm64.sh b/samples-net/datalayer.provider.virtual/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/datalayer.provider.virtual/build-snap-arm64.sh +++ b/samples-net/datalayer.provider.virtual/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/datalayer.provider.virtual/datalayer.provider.virtual.csproj b/samples-net/datalayer.provider.virtual/datalayer.provider.virtual.csproj index 06ab8f0a5..55e2ac191 100644 --- a/samples-net/datalayer.provider.virtual/datalayer.provider.virtual.csproj +++ b/samples-net/datalayer.provider.virtual/datalayer.provider.virtual.csproj @@ -18,8 +18,8 @@ - - + + diff --git a/samples-net/datalayer.provider.virtual/snap/snapcraft.yaml b/samples-net/datalayer.provider.virtual/snap/snapcraft.yaml index ebc8bc8ed..ff6ca1e38 100644 --- a/samples-net/datalayer.provider.virtual/snap/snapcraft.yaml +++ b/samples-net/datalayer.provider.virtual/snap/snapcraft.yaml @@ -4,14 +4,14 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-dotnet-datalayer-provider-virtual version: '1.0.0' -summary: Data Layer provider virtual sample written in .NET for ctrlX. +summary: ctrlX Data Layer provider virtual sample written in .NET for ctrlX CORE. description: | This .NET sample demonstrates how to write a light-weight provider, listing to a wildcard address and managing virtual nodes. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -25,6 +25,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/datalayer.provider/.vscode/tasks.json b/samples-net/datalayer.provider/.vscode/tasks.json index 7e5f81f81..fb9e23e5f 100644 --- a/samples-net/datalayer.provider/.vscode/tasks.json +++ b/samples-net/datalayer.provider/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/datalayer.provider/Node.cs b/samples-net/datalayer.provider/Node.cs index 1c827fc65..7eee68d89 100644 --- a/samples-net/datalayer.provider/Node.cs +++ b/samples-net/datalayer.provider/Node.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; diff --git a/samples-net/datalayer.provider/Program.cs b/samples-net/datalayer.provider/Program.cs index 21ef2dc48..c7638010c 100644 --- a/samples-net/datalayer.provider/Program.cs +++ b/samples-net/datalayer.provider/Program.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; @@ -50,7 +32,7 @@ internal static void Main(string[] args) // Create a new ctrlX Data Layer system using var system = new DatalayerSystem(); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE system.Start(startBroker: false); Console.WriteLine("ctrlX Data Layer system started."); @@ -66,12 +48,12 @@ internal static void Main(string[] args) var (resultMyInt, _) = provider.RegisterNode(myIntNode.Address, new ReadOnlyNodeHandler(myIntNode)); Console.WriteLine($"Registering Node with address='{myIntNode.Address}', result='{resultMyInt}'"); - // Create and register node on given address and read-only callbacks. + // Create and register node on given address (read-only). var myDoubleNode = CreateReadOnlyNode($"{ROOT}/myDouble", "types/datalayer/float64", "MyDouble Description", new Variant(Math.PI)); var (resultMyDouble, _) = provider.RegisterNode(myDoubleNode.Address, new ReadOnlyNodeHandler(myDoubleNode)); Console.WriteLine($"Registering Node with address='{myDoubleNode.Address}', result='{resultMyDouble}'"); - // Create and register node on given address and read-write callbacks. + // Create and register node on given address (read/write). var myStringNode = CreateReadWriteNode($"{ROOT}/myString", "types/datalayer/string", "MyDouble Description", new Variant("Hello ctrlX")); var (resultMyString, _) = provider.RegisterNode(myStringNode.Address, new ReadWriteNodeHandler(myStringNode)); Console.WriteLine($"Registering Node with address='{myStringNode.Address}', result='{resultMyString}'"); diff --git a/samples-net/datalayer.provider/README.md b/samples-net/datalayer.provider/README.md index ef5dc0fc7..e8a433aba 100644 --- a/samples-net/datalayer.provider/README.md +++ b/samples-net/datalayer.provider/README.md @@ -37,7 +37,7 @@ Please read the common .NET docs [here](./../../doc/dotnet.md), first. 3. Choose __Open Folder__. 4. Open the directory __datalayer.provider__. 5. Build and install snap as described [here](./../README.md). -6. Checkout ctrlX Data Layer web frontend (System | Data Layer) +6. Checkout ctrlX Data Layer web frontend (Settings | Data Layer) 7. Check the output using __Diagnostics__: - Login into your ctrlX @@ -54,7 +54,7 @@ Please read the common .NET docs [here](./../../doc/dotnet.md), first. ## Screenshot -![crtrX Data Layer tree](./docs/images/datalayer.provider/datalayer.provider.png) +![crtrX ctrlX Data Layer tree](./docs/images/datalayer.provider/datalayer.provider.png) ## Install the App @@ -78,24 +78,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-net/datalayer.provider/ReadOnlyNodeHandler.cs b/samples-net/datalayer.provider/ReadOnlyNodeHandler.cs index 8501c68d7..96d8f3124 100644 --- a/samples-net/datalayer.provider/ReadOnlyNodeHandler.cs +++ b/samples-net/datalayer.provider/ReadOnlyNodeHandler.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; diff --git a/samples-net/datalayer.provider/ReadWriteNodeHandler.cs b/samples-net/datalayer.provider/ReadWriteNodeHandler.cs index a5c5b622c..d7610e740 100644 --- a/samples-net/datalayer.provider/ReadWriteNodeHandler.cs +++ b/samples-net/datalayer.provider/ReadWriteNodeHandler.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Datalayer; diff --git a/samples-net/datalayer.provider/build-snap-amd64.sh b/samples-net/datalayer.provider/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/datalayer.provider/build-snap-amd64.sh +++ b/samples-net/datalayer.provider/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/datalayer.provider/build-snap-arm64.sh b/samples-net/datalayer.provider/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/datalayer.provider/build-snap-arm64.sh +++ b/samples-net/datalayer.provider/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/datalayer.provider/datalayer.provider.csproj b/samples-net/datalayer.provider/datalayer.provider.csproj index f4822a3a8..6b43bbb4a 100644 --- a/samples-net/datalayer.provider/datalayer.provider.csproj +++ b/samples-net/datalayer.provider/datalayer.provider.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples-net/datalayer.provider/sample/schema/InertialValue.cs b/samples-net/datalayer.provider/sample/schema/InertialValue.cs index 685fdddfe..c6b7e9e29 100644 --- a/samples-net/datalayer.provider/sample/schema/InertialValue.cs +++ b/samples-net/datalayer.provider/sample/schema/InertialValue.cs @@ -13,7 +13,7 @@ public struct InertialValue : IFlatbufferObject { private Table __p; public ByteBuffer ByteBuffer { get { return __p.bb; } } - public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_3_3(); } + public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_5_26(); } public static InertialValue GetRootAsInertialValue(ByteBuffer _bb) { return GetRootAsInertialValue(_bb, new InertialValue()); } public static InertialValue GetRootAsInertialValue(ByteBuffer _bb, InertialValue obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); } diff --git a/samples-net/datalayer.provider/snap/snapcraft.yaml b/samples-net/datalayer.provider/snap/snapcraft.yaml index 80d2901f6..36fbfe1d9 100644 --- a/samples-net/datalayer.provider/snap/snapcraft.yaml +++ b/samples-net/datalayer.provider/snap/snapcraft.yaml @@ -4,7 +4,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-dotnet-datalayer-provider version: '1.0.0' -summary: Data Layer provider sample written in .NET for ctrlX. +summary: ctrlX Data Layer provider sample written in .NET for ctrlX CORE. description: | The sample demonstrates how to provide nodes to the ctrlX Data Layer tree. The provider creates nodes with types of int/double/string. @@ -13,7 +13,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -27,8 +27,9 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' - + parts: app: plugin: dump diff --git a/samples-net/diagnostics.logbook/.vscode/tasks.json b/samples-net/diagnostics.logbook/.vscode/tasks.json index a85b39fa6..d5f4be951 100644 --- a/samples-net/diagnostics.logbook/.vscode/tasks.json +++ b/samples-net/diagnostics.logbook/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/diagnostics.logbook/KernelLogLevel.cs b/samples-net/diagnostics.logbook/KernelLogLevel.cs index ac1feb7f0..ac11685c7 100644 --- a/samples-net/diagnostics.logbook/KernelLogLevel.cs +++ b/samples-net/diagnostics.logbook/KernelLogLevel.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Samples.Diagnostics.Logbook { diff --git a/samples-net/diagnostics.logbook/KernelLogger.cs b/samples-net/diagnostics.logbook/KernelLogger.cs index 3378fb26f..8c1635ea6 100644 --- a/samples-net/diagnostics.logbook/KernelLogger.cs +++ b/samples-net/diagnostics.logbook/KernelLogger.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Samples.Diagnostics.Logbook { diff --git a/samples-net/diagnostics.logbook/KernelLoggerSample.cs b/samples-net/diagnostics.logbook/KernelLoggerSample.cs index 535a6cb3d..1f59dcfa6 100644 --- a/samples-net/diagnostics.logbook/KernelLoggerSample.cs +++ b/samples-net/diagnostics.logbook/KernelLoggerSample.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Samples.Diagnostics.Logbook { diff --git a/samples-net/diagnostics.logbook/MicrosoftLoggerFactory.cs b/samples-net/diagnostics.logbook/MicrosoftLoggerFactory.cs index 0a07f7a50..b42e63c9a 100644 --- a/samples-net/diagnostics.logbook/MicrosoftLoggerFactory.cs +++ b/samples-net/diagnostics.logbook/MicrosoftLoggerFactory.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Samples.Diagnostics.Logbook { diff --git a/samples-net/diagnostics.logbook/MicrosoftLoggerSample.cs b/samples-net/diagnostics.logbook/MicrosoftLoggerSample.cs index 59716235d..e89b889f3 100644 --- a/samples-net/diagnostics.logbook/MicrosoftLoggerSample.cs +++ b/samples-net/diagnostics.logbook/MicrosoftLoggerSample.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Samples.Diagnostics.Logbook { diff --git a/samples-net/diagnostics.logbook/Program.cs b/samples-net/diagnostics.logbook/Program.cs index 0ba5a96fb..615301048 100644 --- a/samples-net/diagnostics.logbook/Program.cs +++ b/samples-net/diagnostics.logbook/Program.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Samples.Diagnostics.Logbook { diff --git a/samples-net/diagnostics.logbook/README.md b/samples-net/diagnostics.logbook/README.md index 2f72de7d8..b49ed690f 100644 --- a/samples-net/diagnostics.logbook/README.md +++ b/samples-net/diagnostics.logbook/README.md @@ -1,10 +1,10 @@ # README .NET diagnostics.logbook -This .NET sample is logging messages to the logbook of ctrlX. +This .NET sample is logging messages to the logbook of the ctrlX CORE. ## Introduction -The project __diagnostics.logbook__ provides a simple application example to log messages to the logbook of ctrlX. +The project __diagnostics.logbook__ provides a simple application example to log messages to the logbook of the ctrlX CORE. ## Description @@ -64,24 +64,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-net/diagnostics.logbook/build-snap-amd64.sh b/samples-net/diagnostics.logbook/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/diagnostics.logbook/build-snap-amd64.sh +++ b/samples-net/diagnostics.logbook/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/diagnostics.logbook/build-snap-arm64.sh b/samples-net/diagnostics.logbook/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/diagnostics.logbook/build-snap-arm64.sh +++ b/samples-net/diagnostics.logbook/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/diagnostics.logbook/diagnostics.logbook.csproj b/samples-net/diagnostics.logbook/diagnostics.logbook.csproj index cb7951b52..63a1b51bb 100644 --- a/samples-net/diagnostics.logbook/diagnostics.logbook.csproj +++ b/samples-net/diagnostics.logbook/diagnostics.logbook.csproj @@ -8,10 +8,10 @@ - - - - + + + + diff --git a/samples-net/diagnostics.logbook/snap/snapcraft.yaml b/samples-net/diagnostics.logbook/snap/snapcraft.yaml index 1e74c95d4..d819575b8 100644 --- a/samples-net/diagnostics.logbook/snap/snapcraft.yaml +++ b/samples-net/diagnostics.logbook/snap/snapcraft.yaml @@ -4,14 +4,14 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference version: '1.0.0' name: ctrlx-dotnet-logbook -summary: Logbook sample written in .NET for ctrlX. +summary: Logbook sample written in .NET for ctrlX CORE. description: | - Programm is logging messages to the logbook of ctrlX. + Programm is logging messages to the logbook of the ctrlX CORE. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -23,6 +23,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/hello.web.asp/.vscode/tasks.json b/samples-net/hello.web.asp/.vscode/tasks.json index 941901937..9bac0b288 100644 --- a/samples-net/hello.web.asp/.vscode/tasks.json +++ b/samples-net/hello.web.asp/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/hello.web.asp/Program.cs b/samples-net/hello.web.asp/Program.cs index 248fbf38a..5b5225c4d 100644 --- a/samples-net/hello.web.asp/Program.cs +++ b/samples-net/hello.web.asp/Program.cs @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Hello.Web.Asp { using Microsoft.AspNetCore.Hosting; diff --git a/samples-net/hello.web.asp/README.md b/samples-net/hello.web.asp/README.md index e7053152d..a406a4bae 100644 --- a/samples-net/hello.web.asp/README.md +++ b/samples-net/hello.web.asp/README.md @@ -4,7 +4,7 @@ This .NET sample is a simple ASP.NET application. ## Introduction -Programm shows how to write a ASP.NET application running on ctrlX. +Programm shows how to write a ASP.NET application running on ctrlX CORE. ## Description @@ -61,24 +61,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-net/hello.web.asp/Startup.cs b/samples-net/hello.web.asp/Startup.cs index 291ee10e5..c901bf34a 100644 --- a/samples-net/hello.web.asp/Startup.cs +++ b/samples-net/hello.web.asp/Startup.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using Hello.Web.Asp.services; namespace Hello.Web.Asp diff --git a/samples-net/hello.web.asp/build-snap-amd64.sh b/samples-net/hello.web.asp/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/hello.web.asp/build-snap-amd64.sh +++ b/samples-net/hello.web.asp/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/hello.web.asp/build-snap-arm64.sh b/samples-net/hello.web.asp/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/hello.web.asp/build-snap-arm64.sh +++ b/samples-net/hello.web.asp/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/hello.web.asp/configs/package-assets/ctrlx-hello-web-asp.package-manifest.json b/samples-net/hello.web.asp/configs/package-assets/ctrlx-hello-web-asp.package-manifest.json index 12cb125b9..568ebdbea 100644 --- a/samples-net/hello.web.asp/configs/package-assets/ctrlx-hello-web-asp.package-manifest.json +++ b/samples-net/hello.web.asp/configs/package-assets/ctrlx-hello-web-asp.package-manifest.json @@ -1,4 +1,5 @@ { + "$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.schema.json", "version": "1.0.0", "id": "ctrlx-hello-web-asp", "services": { diff --git a/samples-net/hello.web.asp/hello.web.asp.csproj b/samples-net/hello.web.asp/hello.web.asp.csproj index c1762db08..babcc815d 100644 --- a/samples-net/hello.web.asp/hello.web.asp.csproj +++ b/samples-net/hello.web.asp/hello.web.asp.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples-net/hello.web.asp/services/DataLayerService.cs b/samples-net/hello.web.asp/services/DataLayerService.cs index 7fb919b14..09ccc6144 100644 --- a/samples-net/hello.web.asp/services/DataLayerService.cs +++ b/samples-net/hello.web.asp/services/DataLayerService.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using System.Globalization; namespace Hello.Web.Asp.services @@ -56,7 +38,7 @@ private static IClient CreateClient() // Create a new ctrlX Data Layer system var system = new DatalayerSystem(); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE system.Start(startBroker: false); Console.WriteLine("ctrlX Data Layer system started."); diff --git a/samples-net/hello.web.asp/services/GreetService.cs b/samples-net/hello.web.asp/services/GreetService.cs index 3d3c54d1b..0e2bf2979 100644 --- a/samples-net/hello.web.asp/services/GreetService.cs +++ b/samples-net/hello.web.asp/services/GreetService.cs @@ -1,26 +1,8 @@ /* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ namespace Hello.Web.Asp.services { /// diff --git a/samples-net/hello.web.asp/snap/snapcraft.yaml b/samples-net/hello.web.asp/snap/snapcraft.yaml index c89115a53..b0c67b050 100644 --- a/samples-net/hello.web.asp/snap/snapcraft.yaml +++ b/samples-net/hello.web.asp/snap/snapcraft.yaml @@ -7,12 +7,12 @@ name: ctrlx-dotnet-hello-web-asp version: '1.0.0' summary: Hello World sample written in ASP.NET for ctrlX description: | - The sample provides a web page written in ASP.NET that shows some data layer values. + The sample provides a web page written in ASP.NET that shows some ctrlX Data Layer values. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -30,6 +30,7 @@ apps: - network-control environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-net/hello.world/.vscode/tasks.json b/samples-net/hello.world/.vscode/tasks.json index 802d433d4..95b3b74c5 100644 --- a/samples-net/hello.world/.vscode/tasks.json +++ b/samples-net/hello.world/.vscode/tasks.json @@ -37,7 +37,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -50,11 +50,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -63,11 +63,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -76,7 +76,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -90,7 +90,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -124,7 +124,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -157,12 +157,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -173,7 +169,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -210,12 +206,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-net/hello.world/Program.cs b/samples-net/hello.world/Program.cs index 29a80509a..ce2c193e4 100644 --- a/samples-net/hello.world/Program.cs +++ b/samples-net/hello.world/Program.cs @@ -1,26 +1,8 @@ -/* -MIT License - -Copyright (c) 2021-2023 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ using System; diff --git a/samples-net/hello.world/README.md b/samples-net/hello.world/README.md index 022ea0490..a6e62cde3 100644 --- a/samples-net/hello.world/README.md +++ b/samples-net/hello.world/README.md @@ -67,24 +67,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-net/hello.world/build-snap-amd64.sh b/samples-net/hello.world/build-snap-amd64.sh index 376f1820c..9f2cd99f9 100644 --- a/samples-net/hello.world/build-snap-amd64.sh +++ b/samples-net/hello.world/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-x64 TARGET_ARCH=amd64 diff --git a/samples-net/hello.world/build-snap-arm64.sh b/samples-net/hello.world/build-snap-arm64.sh index f73ea641c..a40f50c16 100644 --- a/samples-net/hello.world/build-snap-arm64.sh +++ b/samples-net/hello.world/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_DOTNET=linux-arm64 TARGET_ARCH=arm64 diff --git a/samples-net/hello.world/hello.world.csproj b/samples-net/hello.world/hello.world.csproj index 999165f79..3bf04c26b 100644 --- a/samples-net/hello.world/hello.world.csproj +++ b/samples-net/hello.world/hello.world.csproj @@ -6,7 +6,7 @@ Samples.HelloWorld - + diff --git a/samples-net/hello.world/snap/snapcraft.yaml b/samples-net/hello.world/snap/snapcraft.yaml index 31ccd18fd..776668333 100644 --- a/samples-net/hello.world/snap/snapcraft.yaml +++ b/samples-net/hello.world/snap/snapcraft.yaml @@ -4,14 +4,14 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference version: '1.0.0' name: ctrlx-dotnet-hello-world -summary: Hello World sample written in .NET for ctrlX. +summary: Hello World sample written in .NET for ctrlX CORE. description: | Programm is prompting "Hello World" to standard output. Enter 'sudo snap logs ctrlx-dotnet-hello-world.app -f | more' to see the output. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -23,6 +23,7 @@ apps: restart-delay: 10s environment: + LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 'true' parts: diff --git a/samples-node/datalayer.client.browse/.vscode/tasks.json b/samples-node/datalayer.client.browse/.vscode/tasks.json index 32bbc1337..76c075f17 100644 --- a/samples-node/datalayer.client.browse/.vscode/tasks.json +++ b/samples-node/datalayer.client.browse/.vscode/tasks.json @@ -42,7 +42,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -55,11 +55,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -68,11 +68,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -81,7 +81,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -95,7 +95,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -129,7 +129,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -162,12 +162,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -178,7 +174,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -215,12 +211,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-node/datalayer.client.browse/README.md b/samples-node/datalayer.client.browse/README.md index 1330ecae3..0b09cdbb7 100644 --- a/samples-node/datalayer.client.browse/README.md +++ b/samples-node/datalayer.client.browse/README.md @@ -1,118 +1,99 @@ -# README Node.js datalayer.client.browse - -This Node.js sample writes out all node values from ctrlX Data Layer to console. - -## Introduction - -The sample demonstrates how to traverse the whole ctrlX Data Layer tree. The values of the nodes if readable are printed out to console as human readable strings. Also complex values with structure (encoded by [FlatBuffers](https://google.github.io/flatbuffers/)) are written as JSON string to console. - -## Description - -The sample demonstrates how to browse th values from ctrlX Data Layer tree and write out the values to console. A subscription is used to get values by data change event in a deterministic publish interval. The single read is performed every 10 seconds in an endless loop. - -## Description - -The sample demonstrates - -+ How to browse nodes of the __ctrlX Data Layer__ - -+ How to read value as json from a node - -## Getting Started - -1. Launch Visual Studio Code -2. Click on the __Remote Explorer__ from the menu. -3. Choose __Open Folder__. -4. Open the directory __datalayer.client.browse__. -5. Build and install snap as described [here](./../README.md). -6. Check the output using __Diagnostics__: - - - Login into your ctrlX - - Navigate to __Diagnostics -> Logbook__ - - Click __Settings__ on the right top corner - - Enable __Show system messages__ - - Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-datalayer-client-browse.app.service__ - - Now you should the see the app output diagnostics. - - Press __Refresh__ to update. - -7. If you have root permissions, you can also watch the output on any ssh console with the command: - ```bash - sudo snap logs ctrlx-node-datalayer-client-browse.app -f | more - ``` - -## Console Output - -```bash -Running inside snap: False -ctrlX Data Layer system started. -ctrlX Data Layer client created. -Client connected: True -\-[] - |-[datalayer] - | |-[curvemq] - | | \-[publickey] V=tGQ43.RsrvZ#K0]eLTs?vpyfCNN?^/sV6MGh7N - | |-[debug] - | |-[nodes] [datalayer/debug/*,datalayer/curvemq/publickey,datalayer/nodes,datalayer/nodesrt,datalayer/subscriptions/clients/*,datalayer/subscriptions/clients/*/subscriptions/*,datalayer/subscriptions/clients/*/subscriptions/*/nodes,datalayer/subscriptions/clients/*/subscriptions/*/properties,datalayer/subscriptions/settings,datalayer/retain/emu/data,datalayer/retain/emu/data/__,datalayer/retain/emu/info,datalayer/retain/emu/map,datalayer/retain/chunks,datalayer/retain/chunks/__,datalayer/retain/stats,datalayer/retain/stats/free,datalayer/retain/stats/used,datalayer/retain/stats/total,datalayer/retain/stats/biggest-free,datalayer/retain/stats/info,datalayer/retain/stats/sync-counter,datalayer/retain/stats/last-used,types/datalayer/metadata,types/datalayer/reflection,types/datalayer/memory,types/datalayer/memory_map,types/datalayer/token,types/datalayer/problem,types/datalayer/retain_stats,types/datalayer/subscription_properties,types/datalayer/subscription_data,types/datalayer/subscription_settings,types/datalayer/persistence_param,types/datalayer/subscription,types/datalayer/bool8,types/datalayer/int8,types/datalayer/uint8,types/datalayer/int16,types/datalayer/uint16,types/datalayer/int32,types/datalayer/uint32,types/datalayer/int64,types/datalayer/uint64,types/datalayer/float32,types/datalayer/float64,types/datalayer/string,types/datalayer/array-of-bool8,types/datalayer/array-of-int8,types/datalayer/array-of-uint8,types/datalayer/array-of-int16,types/datalayer/array-of-uint16,types/datalayer/array-of-int32,types/datalayer/array-of-uint32,types/datalayer/array-of-int64,types/datalayer/array-of-uint64,types/datalayer/array-of-float32,types/datalayer/array-of-float64,types/datalayer/array-of-string,types/datalayer/raw,types/datalayer/remoteconfig,types/datalayer/framework/bundle,types/datalayer/framework/bundlelist,types/datalayer/framework/dependency,types/datalayer/framework/dependencylist,types/datalayer/framework/interface,types/datalayer/framework/interfacelist,types/datalayer/framework/component,types/datalayer/framework/componentlist,types/datalayer/framework/property,types/datalayer/framework/propertylist,types/diagnosis/cfg-class,types/diagnosis/identification,types/diagnosis/list-identification-timestamp,types/diagnosis/identification-timestamp,types/diagnosis/registration,types/diagnosis/set,types/scheduler/callable,types/scheduler/duration,types/scheduler/duration-timer,types/scheduler/histogram,types/scheduler/programs,types/scheduler/state,types/scheduler/task,types/scheduler/trigger-source,types/scheduler/startup-error-reaction,types/scheduler/admin,types/scheduler/watchdog-type,types/scheduler/watchdog-error-reaction-class,types/scheduler/watchdog-error-reaction-configuration,types/scheduler/watchdog,types/scheduler/controls,types/systemhandler/state,types/script/cfg,types/script/cfg/init-script,types/script/instances,types/script/instances/cmd/file,types/script/instances/cmd/string,types/script/instances/diag,types/script/state/languages,devices/remotes/__,framework/bundles,framework/bundles/__,framework/metrics/system/cpu-utilisation-percent,framework/metrics/system/memtotal-mb,framework/metrics/system/memfree-mb,framework/metrics/system/memavailable-mb,framework/metrics/system/memused-mb,framework/metrics/system/membuffers-mb,framework/metrics/system/memcache-mb,framework/metrics/system/memused-percent,framework/metrics/process/vmsize-kb,framework/metrics/process/vmrss-kb,framework/metrics/process/vmshared-kb,framework/metrics/process/memused-percent,framework/state,framework/events/framework-started,diagnosis/cfg/realtime/numbers,diagnosis/cfg/realtime/numbers/class,diagnosis/clear/error,diagnosis/confirm/error,diagnosis/get/actual/list,diagnosis/get/actual/log,diagnosis/get/text,diagnosis/registration/detailed/register,diagnosis/registration/detailed/unregister,diagnosis/registration/main/register,diagnosis/registration/main/unregister,diagnosis/set,diagnosis/set/reset-active,diagnosis/set/set-active,diagnosis/set/set-and-reset,trace/rexroth-automationcore/units,trace/rexroth-automationcore/units/__,trace/rexroth-automationcore/admin/cfg/*,scheduler/tasks/*/watchdog,scheduler/tasks/*/watchdog/__,scheduler/__,script/cfg,script/cfg/load-all,script/cfg/save-all,script/cfg/init-script,script/cfg/init-script/file,script/cfg/init-script/language,script/cfg/init-script/parameter,script/admin/cfg/load,script/admin/cfg/save,script/instances/*,script/instances/*/cmd/file,script/instances/*/cmd/string,script/instances/*/cmd/reset,script/instances/*/cmd/abort,script/instances/*/state/opstate,script/instances/*/state/script,script/instances/*/state/line,script/instances/*/state/attached-to,script/instances/*/state/pid,script/instances/*/diag,script/instances/*/diag/last-main-diag,script/instances/*/diag/last-detail-diag,script/instances/*/diag/err-msg,script/instances/*/diag/err-trace,script/state/languages/*] - | |-[nodesrt] [datalayer/retain/emu] - | |-[retain] - | | |-[chunks] [] - | | |-[emu] - | | | |-[data] [] - | | | |-[info] {"type": "Shared","id": "/snap.rexroth-automationcore.405e2e7a-63ae-0039-056b-deadbe000002","sizeBytes": 122880} - | | | \-[map] {"revision": 0} - | | \-[stats] {"total": 122880,"free": 122848,"used": 32,"biggestFree": 122848,"syncCounter": 124,"lastUsed": 32} - | | |-[biggest-free] 122848 - | | |-[free] 122848 - | | |-[info] emulated - | | |-[last-used] 32 - | | |-[sync-counter] 124 - | | |-[total] 122880 - | | \-[used] 32 - | \-[subscriptions] - ... - Elapsed time for browsing ctrlX Data Layer tree: 9351 milliseconds -``` - -## Install the App - -Login into ctrlX and install the App (Apps). - -## Gratulations - We're finished - Let's start coding! - -## Support - -### Developer Community - -Please join the [Developer Community](https://developer.community.boschrexroth.com/) - -### SDK Forum - -Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) - -### Issues - -If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README Node.js datalayer.client.browse + +This Node.js sample writes out all node values from ctrlX Data Layer to console. + +## Introduction + +The sample demonstrates how to traverse the whole ctrlX Data Layer tree. The values of the nodes if readable are printed out to console as human readable strings. Also complex values with structure (encoded by [FlatBuffers](https://google.github.io/flatbuffers/)) are written as JSON string to console. + +## Description + +The sample demonstrates how to browse th values from ctrlX Data Layer tree and write out the values to console. A subscription is used to get values by data change event in a deterministic publish interval. The single read is performed every 10 seconds in an endless loop. + +## Description + +The sample demonstrates + ++ How to browse nodes of the __ctrlX Data Layer__ + ++ How to read value as json from a node + +## Getting Started + +1. Launch Visual Studio Code +2. Click on the __Remote Explorer__ from the menu. +3. Choose __Open Folder__. +4. Open the directory __datalayer.client.browse__. +5. Build and install snap as described [here](./../README.md). +6. Check the output using __Diagnostics__: + + - Login into your ctrlX + - Navigate to __Diagnostics -> Logbook__ + - Click __Settings__ on the right top corner + - Enable __Show system messages__ + - Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-datalayer-client-browse.app.service__ + - Now you should the see the app output diagnostics. + - Press __Refresh__ to update. + +7. If you have root permissions, you can also watch the output on any ssh console with the command: + ```bash + sudo snap logs ctrlx-node-datalayer-client-browse.app -f | more + ``` + +## Console Output + +```bash +Running inside snap: False +ctrlX Data Layer system started. +ctrlX Data Layer client created. +Client connected: True +\-[] + |-[datalayer] + | |-[curvemq] + | | \-[publickey] V=tGQ43.RsrvZ#K0]eLTs?vpyfCNN?^/sV6MGh7N + | |-[debug] + | |-[nodes] [datalayer/debug/*,datalayer/curvemq/publickey,datalayer/nodes,datalayer/nodesrt,datalayer/subscriptions/clients/*,datalayer/subscriptions/clients/*/subscriptions/*,datalayer/subscriptions/clients/*/subscriptions/*/nodes,datalayer/subscriptions/clients/*/subscriptions/*/properties,datalayer/subscriptions/settings,datalayer/retain/emu/data,datalayer/retain/emu/data/__,datalayer/retain/emu/info,datalayer/retain/emu/map,datalayer/retain/chunks,datalayer/retain/chunks/__,datalayer/retain/stats,datalayer/retain/stats/free,datalayer/retain/stats/used,datalayer/retain/stats/total,datalayer/retain/stats/biggest-free,datalayer/retain/stats/info,datalayer/retain/stats/sync-counter,datalayer/retain/stats/last-used,types/datalayer/metadata,types/datalayer/reflection,types/datalayer/memory,types/datalayer/memory_map,types/datalayer/token,types/datalayer/problem,types/datalayer/retain_stats,types/datalayer/subscription_properties,types/datalayer/subscription_data,types/datalayer/subscription_settings,types/datalayer/persistence_param,types/datalayer/subscription,types/datalayer/bool8,types/datalayer/int8,types/datalayer/uint8,types/datalayer/int16,types/datalayer/uint16,types/datalayer/int32,types/datalayer/uint32,types/datalayer/int64,types/datalayer/uint64,types/datalayer/float32,types/datalayer/float64,types/datalayer/string,types/datalayer/array-of-bool8,types/datalayer/array-of-int8,types/datalayer/array-of-uint8,types/datalayer/array-of-int16,types/datalayer/array-of-uint16,types/datalayer/array-of-int32,types/datalayer/array-of-uint32,types/datalayer/array-of-int64,types/datalayer/array-of-uint64,types/datalayer/array-of-float32,types/datalayer/array-of-float64,types/datalayer/array-of-string,types/datalayer/raw,types/datalayer/remoteconfig,types/datalayer/framework/bundle,types/datalayer/framework/bundlelist,types/datalayer/framework/dependency,types/datalayer/framework/dependencylist,types/datalayer/framework/interface,types/datalayer/framework/interfacelist,types/datalayer/framework/component,types/datalayer/framework/componentlist,types/datalayer/framework/property,types/datalayer/framework/propertylist,types/diagnosis/cfg-class,types/diagnosis/identification,types/diagnosis/list-identification-timestamp,types/diagnosis/identification-timestamp,types/diagnosis/registration,types/diagnosis/set,types/scheduler/callable,types/scheduler/duration,types/scheduler/duration-timer,types/scheduler/histogram,types/scheduler/programs,types/scheduler/state,types/scheduler/task,types/scheduler/trigger-source,types/scheduler/startup-error-reaction,types/scheduler/admin,types/scheduler/watchdog-type,types/scheduler/watchdog-error-reaction-class,types/scheduler/watchdog-error-reaction-configuration,types/scheduler/watchdog,types/scheduler/controls,types/systemhandler/state,types/script/cfg,types/script/cfg/init-script,types/script/instances,types/script/instances/cmd/file,types/script/instances/cmd/string,types/script/instances/diag,types/script/state/languages,devices/remotes/__,framework/bundles,framework/bundles/__,framework/metrics/system/cpu-utilisation-percent,framework/metrics/system/memtotal-mb,framework/metrics/system/memfree-mb,framework/metrics/system/memavailable-mb,framework/metrics/system/memused-mb,framework/metrics/system/membuffers-mb,framework/metrics/system/memcache-mb,framework/metrics/system/memused-percent,framework/metrics/process/vmsize-kb,framework/metrics/process/vmrss-kb,framework/metrics/process/vmshared-kb,framework/metrics/process/memused-percent,framework/state,framework/events/framework-started,diagnosis/cfg/realtime/numbers,diagnosis/cfg/realtime/numbers/class,diagnosis/clear/error,diagnosis/confirm/error,diagnosis/get/actual/list,diagnosis/get/actual/log,diagnosis/get/text,diagnosis/registration/detailed/register,diagnosis/registration/detailed/unregister,diagnosis/registration/main/register,diagnosis/registration/main/unregister,diagnosis/set,diagnosis/set/reset-active,diagnosis/set/set-active,diagnosis/set/set-and-reset,trace/rexroth-automationcore/units,trace/rexroth-automationcore/units/__,trace/rexroth-automationcore/admin/cfg/*,scheduler/tasks/*/watchdog,scheduler/tasks/*/watchdog/__,scheduler/__,script/cfg,script/cfg/load-all,script/cfg/save-all,script/cfg/init-script,script/cfg/init-script/file,script/cfg/init-script/language,script/cfg/init-script/parameter,script/admin/cfg/load,script/admin/cfg/save,script/instances/*,script/instances/*/cmd/file,script/instances/*/cmd/string,script/instances/*/cmd/reset,script/instances/*/cmd/abort,script/instances/*/state/opstate,script/instances/*/state/script,script/instances/*/state/line,script/instances/*/state/attached-to,script/instances/*/state/pid,script/instances/*/diag,script/instances/*/diag/last-main-diag,script/instances/*/diag/last-detail-diag,script/instances/*/diag/err-msg,script/instances/*/diag/err-trace,script/state/languages/*] + | |-[nodesrt] [datalayer/retain/emu] + | |-[retain] + | | |-[chunks] [] + | | |-[emu] + | | | |-[data] [] + | | | |-[info] {"type": "Shared","id": "/snap.rexroth-automationcore.405e2e7a-63ae-0039-056b-deadbe000002","sizeBytes": 122880} + | | | \-[map] {"revision": 0} + | | \-[stats] {"total": 122880,"free": 122848,"used": 32,"biggestFree": 122848,"syncCounter": 124,"lastUsed": 32} + | | |-[biggest-free] 122848 + | | |-[free] 122848 + | | |-[info] emulated + | | |-[last-used] 32 + | | |-[sync-counter] 124 + | | |-[total] 122880 + | | \-[used] 32 + | \-[subscriptions] + ... + Elapsed time for browsing ctrlX Data Layer tree: 9351 milliseconds +``` + +## Install the App + +Login into ctrlX and install the App (Apps). + +## Gratulations - We're finished - Let's start coding! + +## Support + +### Developer Community + +Please join the [Developer Community](https://developer.community.boschrexroth.com/) + +### SDK Forum + +Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) + +### Issues + +If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-node/datalayer.client.browse/build-snap-amd64.sh b/samples-node/datalayer.client.browse/build-snap-amd64.sh index d090a57a9..92f432dad 100644 --- a/samples-node/datalayer.client.browse/build-snap-amd64.sh +++ b/samples-node/datalayer.client.browse/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.client.browse/build-snap-arm64.sh b/samples-node/datalayer.client.browse/build-snap-arm64.sh index b41b7fd26..8cd17b41a 100644 --- a/samples-node/datalayer.client.browse/build-snap-arm64.sh +++ b/samples-node/datalayer.client.browse/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.client.browse/package.json b/samples-node/datalayer.client.browse/package.json index 26ada5a0b..3f7235c3f 100644 --- a/samples-node/datalayer.client.browse/package.json +++ b/samples-node/datalayer.client.browse/package.json @@ -1,7 +1,7 @@ { "name": "datalayer-client-browse", "version": "1.0.0", - "description": "Data Layer browse sample for ctrlX.", + "description": "ctrlX Data Layer browse sample for ctrlX CORE.", "bin": { "app": "dist/app.js" }, @@ -11,19 +11,19 @@ "dist" ], "devDependencies": { - "@types/node": "^18.13.0", - "@typescript-eslint/parser": "^5.52.0", - "eslint": "^8.34.0", - "typescript": "^4.9.5", - "ts-node": "^10.9.1" + "@types/node": "^20.4.4", + "@typescript-eslint/parser": "^6.2.0", + "eslint": "^8.45.0", + "ts-node": "^10.9.1", + "typescript": "^5.1.6" }, "dependencies": { - "ctrlx-datalayer": "^1.6.0", - "ctrlx-datalayer-flatbuffers": "^1.20.0" + "ctrlx-datalayer": "^2.0.0", + "ctrlx-datalayer-flatbuffers": "^2.2.0" }, "scripts": { "getName": "echo $npm_package_name", "prepare": "npm run tsc", "tsc": "tsc" } -} \ No newline at end of file +} diff --git a/samples-node/datalayer.client.browse/snap/snapcraft.yaml b/samples-node/datalayer.client.browse/snap/snapcraft.yaml index 0804f45f3..d7b4f182c 100644 --- a/samples-node/datalayer.client.browse/snap/snapcraft.yaml +++ b/samples-node/datalayer.client.browse/snap/snapcraft.yaml @@ -4,14 +4,14 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-node-datalayer-client-browse version: "1.0.0" -summary: Data Layer browse sample written in Node.js for ctrlX. +summary: ctrlX Data Layer browse sample written in Node.js for ctrlX CORE. description: | - The sample app shows how to browse the Data Layer tree. + The sample app shows how to browse the ctrlX Data Layer tree. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -29,13 +29,14 @@ parts: source: . build-environment: # Set the node version here. We recommend to use the latest LTS version. - - NODE_VERSION: "18.15.0" + - NODE_VERSION: "18.17.0" # We don't use the npm plugin here, because it has no X-build capability (can't build arm64 target snaps on amd64). # plugin: npm - # npm-node-version: "18.15.0" + # npm-node-version: "18.17.0" plugin: nil override-build: | + # set target arch if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then arch="arm64" @@ -51,11 +52,12 @@ parts: curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1 fi - # install the app (full) to compile (tsc -> ./dist) - npm install --unsafe-perm + # install and compile (tsc -> ./dist) + npm install --ignore-scripts --no-fund --unsafe-perm + npm run tsc # pack and install the app (only production) - npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --only=prod --production --no-fund --unsafe-perm + npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm # remove ctrlx-datalayer prebuilds of unused archs to reduce snap size package_name=$(npm run getName -s) diff --git a/samples-node/datalayer.client.browse/src/app.ts b/samples-node/datalayer.client.browse/src/app.ts index f5bdecd45..852969b88 100644 --- a/samples-node/datalayer.client.browse/src/app.ts +++ b/samples-node/datalayer.client.browse/src/app.ts @@ -1,22 +1,8 @@ -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import DatalayerSystem from 'ctrlx-datalayer/dist/datalayersystem'; import { Remote } from 'ctrlx-datalayer/dist/remote'; @@ -29,7 +15,7 @@ async function main() { // Create a new ctrlX Data Layer system const system = new DatalayerSystem(''); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE await system.start(false); // Create a remote address with the parameters according to your environment @@ -45,13 +31,13 @@ async function main() { return; } - // Create a Data Layer browser. + // Create a ctrlX Data Layer browser. const browser = new Browser(client); - // Traverse the complete Data Layer tree. + // Traverse the complete ctrlX Data Layer tree. await browser.traverse(); - // Stop the Data Layer system. + // Stop the ctrlX Data Layer system. await system.stop(); } diff --git a/samples-node/datalayer.client.browse/src/browser.ts b/samples-node/datalayer.client.browse/src/browser.ts index 2f0ae5195..15156965f 100644 --- a/samples-node/datalayer.client.browse/src/browser.ts +++ b/samples-node/datalayer.client.browse/src/browser.ts @@ -1,22 +1,8 @@ -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import IClient from 'ctrlx-datalayer/dist/client'; @@ -28,7 +14,7 @@ class Browser { } /** - * Traverses the Data Layer tree and write node with value to console. + * Traverses the ctrlX Data Layer tree and write node with value to console. * @param address * @param leaf * @param indent diff --git a/samples-node/datalayer.client.bulkread/.vscode/tasks.json b/samples-node/datalayer.client.bulkread/.vscode/tasks.json index 43749bb09..7d98b131d 100644 --- a/samples-node/datalayer.client.bulkread/.vscode/tasks.json +++ b/samples-node/datalayer.client.bulkread/.vscode/tasks.json @@ -42,7 +42,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -55,11 +55,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -68,11 +68,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -81,7 +81,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -95,7 +95,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -129,7 +129,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -162,12 +162,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -178,7 +174,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -215,12 +211,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-node/datalayer.client.bulkread/README.md b/samples-node/datalayer.client.bulkread/README.md index 8c2819ef9..8e70bd8e2 100644 --- a/samples-node/datalayer.client.bulkread/README.md +++ b/samples-node/datalayer.client.bulkread/README.md @@ -75,24 +75,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-node/datalayer.client.bulkread/build-snap-amd64.sh b/samples-node/datalayer.client.bulkread/build-snap-amd64.sh index d090a57a9..92f432dad 100644 --- a/samples-node/datalayer.client.bulkread/build-snap-amd64.sh +++ b/samples-node/datalayer.client.bulkread/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.client.bulkread/build-snap-arm64.sh b/samples-node/datalayer.client.bulkread/build-snap-arm64.sh index b41b7fd26..8cd17b41a 100644 --- a/samples-node/datalayer.client.bulkread/build-snap-arm64.sh +++ b/samples-node/datalayer.client.bulkread/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.client.bulkread/package.json b/samples-node/datalayer.client.bulkread/package.json index 5aacff7ed..7d69d34cb 100644 --- a/samples-node/datalayer.client.bulkread/package.json +++ b/samples-node/datalayer.client.bulkread/package.json @@ -11,19 +11,19 @@ "dist" ], "devDependencies": { - "@types/node": "^18.13.0", - "@typescript-eslint/parser": "^5.52.0", - "eslint": "^8.34.0", - "typescript": "^4.9.5", - "ts-node": "^10.9.1" + "@types/node": "^20.4.4", + "@typescript-eslint/parser": "^6.2.0", + "eslint": "^8.45.0", + "ts-node": "^10.9.1", + "typescript": "^5.1.6" }, "dependencies": { - "ctrlx-datalayer": "^1.6.0", - "ctrlx-datalayer-flatbuffers": "^1.20.0" + "ctrlx-datalayer": "^2.0.0", + "ctrlx-datalayer-flatbuffers": "^2.2.0" }, "scripts": { "getName": "echo $npm_package_name", "prepare": "npm run tsc", "tsc": "tsc" } -} \ No newline at end of file +} diff --git a/samples-node/datalayer.client.bulkread/snap/snapcraft.yaml b/samples-node/datalayer.client.bulkread/snap/snapcraft.yaml index 0330d4e43..b84683d12 100644 --- a/samples-node/datalayer.client.bulkread/snap/snapcraft.yaml +++ b/samples-node/datalayer.client.bulkread/snap/snapcraft.yaml @@ -4,7 +4,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-node-datalayer-client-bulkread version: "1.0.0" -summary: Data Layer client bulk read sample written in node.js for ctrlX. +summary: ctrlX Data Layer client bulk read sample written in node.js for ctrlX CORE. description: | The sample demonstrates how to bulk read values from ctrlX Data Layer tree and write out the values to console. The bulk read is performed synchron and asynchron every 10 seconds in an endless loop. @@ -12,7 +12,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -30,13 +30,14 @@ parts: source: . build-environment: # Set the node version here. We recommend to use the latest LTS version. - - NODE_VERSION: "18.15.0" + - NODE_VERSION: "18.17.0" # We don't use the npm plugin here, because it has no X-build capability (can't build arm64 target snaps on amd64). # plugin: npm - # npm-node-version: "18.15.0" + # npm-node-version: "18.17.0" plugin: nil override-build: | + # set target arch if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then arch="arm64" @@ -52,11 +53,12 @@ parts: curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1 fi - # install the app (full) to compile (tsc -> ./dist) - npm install --unsafe-perm + # install and compile (tsc -> ./dist) + npm install --ignore-scripts --no-fund --unsafe-perm + npm run tsc # pack and install the app (only production) - npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --only=prod --production --no-fund --unsafe-perm + npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm # remove ctrlx-datalayer prebuilds of unused archs to reduce snap size package_name=$(npm run getName -s) diff --git a/samples-node/datalayer.client.bulkread/src/app.ts b/samples-node/datalayer.client.bulkread/src/app.ts index 59ac308fb..ce000da94 100644 --- a/samples-node/datalayer.client.bulkread/src/app.ts +++ b/samples-node/datalayer.client.bulkread/src/app.ts @@ -1,25 +1,11 @@ #!/usr/bin/env node // !!! DO NOT REMOVE THE SHEBANG ON TOP OF THE FILE, WHICH SPECIFIES THIS APP TO BE EXECUTED BY NODE.JS !!! -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import DatalayerSystem from 'ctrlx-datalayer/dist/datalayersystem'; import { Remote } from 'ctrlx-datalayer/dist/remote'; @@ -30,7 +16,7 @@ async function main() { // Create a new ctrlX Data Layer system const system = new DatalayerSystem(''); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE await system.start(false); // Create a remote address with the parameters according to your environment diff --git a/samples-node/datalayer.client/.vscode/tasks.json b/samples-node/datalayer.client/.vscode/tasks.json index 32bbc1337..76c075f17 100644 --- a/samples-node/datalayer.client/.vscode/tasks.json +++ b/samples-node/datalayer.client/.vscode/tasks.json @@ -42,7 +42,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -55,11 +55,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -68,11 +68,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -81,7 +81,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -95,7 +95,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -129,7 +129,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -162,12 +162,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -178,7 +174,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -215,12 +211,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-node/datalayer.client/README.md b/samples-node/datalayer.client/README.md index b59130d29..790e3d953 100644 --- a/samples-node/datalayer.client/README.md +++ b/samples-node/datalayer.client/README.md @@ -1,100 +1,81 @@ -# README Node.js datalayer.client - -This Node.js sample reads values from ctrlX Data Layer. - -## Introduction - -The sample demonstrates how to read values from ctrlX Data Layer tree and write out the values to console. - -## Description - -The sample __datalayer.client__ demonstrates - -+ How easy to create a client for ctrlX Data Layer - -+ How to read values from ctrlX Data Layer nodes - -+ How to create a subscription to a ctrlX Data Layer node - -## Prerequisites - -Please read the common Node.js docs [here](./../README.md), first. - -## Getting Started - -1. Launch Visual Studio Code -2. Click on the __Remote Explorer__ from the menu. -3. Choose __Open Folder in QEMU VM__. -4. Open the directory __datalayer.client__. -5. Build and install snap as described [here](./../README.md). -6. Check the output using __Diagnostics__: - - + Login into your ctrlX - + Navigate to __Diagnostics -> Logbook__ - + Click __Settings__ on the right top corner - + Enable __Show system messages__ - + Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-datalayer-client.app.service__ - + Now you should the see the app output diagnostics. - + Press __Refresh__ to update. - -7. If you have root permissions, you can also watch the output on any ssh console with the command: - ```bash - sudo snap logs ctrlx-node-datalayer-client.app -f | more - ``` -## Console Output -```bash -running inside snap: false -client remote address: tcp://boschrexroth:boschrexroth@10.0.2.2 -framework/metrics/system/cpu-utilisation-percent:{"value":1.9,"type":"double","timestamp":"2021-10-20T13:40:45.892Z"} -framework/metrics/system/memavailable-mb:{"value":680.578125,"type":"double","timestamp":"2021-10-20T13:40:45.896Z"} -framework/metrics/system/membuffers-mb:{"value":119.00390625,"type":"double","timestamp":"2021-10-20T13:40:45.902Z"} -framework/metrics/system/memcache-mb:{"value":514.56640625,"type":"double","timestamp":"2021-10-20T13:40:45.905Z"} -framework/metrics/system/memfree-mb:{"value":164.43359375,"type":"double","timestamp":"2021-10-20T13:40:45.909Z"} -framework/metrics/system/memtotal-mb:{"value":985.0078125,"type":"double","timestamp":"2021-10-20T13:40:45.913Z"} -framework/metrics/system/memused-mb:{"value":187.00390625,"type":"double","timestamp":"2021-10-20T13:40:45.918Z"} -framework/metrics/system/memused-percent:{"value":19.4,"type":"double","timestamp":"2021-10-20T13:40:45.923Z"} -``` - -## Install the App - -Login into ctrlX and install the App (Apps). - -## Gratulations - We're finished - Let's start coding! - - -## Support -### Developer Community - -Please join the [Developer Community](https://developer.community.boschrexroth.com/) - -### SDK Forum - -Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) - -### Issues - -If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README Node.js datalayer.client + +This Node.js sample reads values from ctrlX Data Layer. + +## Introduction + +The sample demonstrates how to read values from ctrlX Data Layer tree and write out the values to console. + +## Description + +The sample __datalayer.client__ demonstrates + ++ How easy to create a client for ctrlX Data Layer + ++ How to read values from ctrlX Data Layer nodes + ++ How to create a subscription to a ctrlX Data Layer node + +## Prerequisites + +Please read the common Node.js docs [here](./../README.md), first. + +## Getting Started + +1. Launch Visual Studio Code +2. Click on the __Remote Explorer__ from the menu. +3. Choose __Open Folder in QEMU VM__. +4. Open the directory __datalayer.client__. +5. Build and install snap as described [here](./../README.md). +6. Check the output using __Diagnostics__: + + + Login into your ctrlX + + Navigate to __Diagnostics -> Logbook__ + + Click __Settings__ on the right top corner + + Enable __Show system messages__ + + Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-datalayer-client.app.service__ + + Now you should the see the app output diagnostics. + + Press __Refresh__ to update. + +7. If you have root permissions, you can also watch the output on any ssh console with the command: + ```bash + sudo snap logs ctrlx-node-datalayer-client.app -f | more + ``` +## Console Output +```bash +running inside snap: false +client remote address: tcp://boschrexroth:boschrexroth@10.0.2.2 +framework/metrics/system/cpu-utilisation-percent:{"value":1.9,"type":"double","timestamp":"2021-10-20T13:40:45.892Z"} +framework/metrics/system/memavailable-mb:{"value":680.578125,"type":"double","timestamp":"2021-10-20T13:40:45.896Z"} +framework/metrics/system/membuffers-mb:{"value":119.00390625,"type":"double","timestamp":"2021-10-20T13:40:45.902Z"} +framework/metrics/system/memcache-mb:{"value":514.56640625,"type":"double","timestamp":"2021-10-20T13:40:45.905Z"} +framework/metrics/system/memfree-mb:{"value":164.43359375,"type":"double","timestamp":"2021-10-20T13:40:45.909Z"} +framework/metrics/system/memtotal-mb:{"value":985.0078125,"type":"double","timestamp":"2021-10-20T13:40:45.913Z"} +framework/metrics/system/memused-mb:{"value":187.00390625,"type":"double","timestamp":"2021-10-20T13:40:45.918Z"} +framework/metrics/system/memused-percent:{"value":19.4,"type":"double","timestamp":"2021-10-20T13:40:45.923Z"} +``` + +## Install the App + +Login into ctrlX and install the App (Apps). + +## Gratulations - We're finished - Let's start coding! + + +## Support +### Developer Community + +Please join the [Developer Community](https://developer.community.boschrexroth.com/) + +### SDK Forum + +Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) + +### Issues + +If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-node/datalayer.client/build-snap-amd64.sh b/samples-node/datalayer.client/build-snap-amd64.sh index d090a57a9..92f432dad 100644 --- a/samples-node/datalayer.client/build-snap-amd64.sh +++ b/samples-node/datalayer.client/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.client/build-snap-arm64.sh b/samples-node/datalayer.client/build-snap-arm64.sh index b41b7fd26..8cd17b41a 100644 --- a/samples-node/datalayer.client/build-snap-arm64.sh +++ b/samples-node/datalayer.client/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.client/package.json b/samples-node/datalayer.client/package.json index 770918b0b..92f23f513 100644 --- a/samples-node/datalayer.client/package.json +++ b/samples-node/datalayer.client/package.json @@ -11,19 +11,19 @@ "dist" ], "devDependencies": { - "@types/node": "^18.13.0", - "@typescript-eslint/parser": "^5.52.0", - "eslint": "^8.34.0", - "typescript": "^4.9.5", - "ts-node": "^10.9.1" + "@types/node": "^20.4.4", + "@typescript-eslint/parser": "^6.2.0", + "eslint": "^8.45.0", + "ts-node": "^10.9.1", + "typescript": "^5.1.6" }, "dependencies": { - "ctrlx-datalayer": "^1.6.0", - "ctrlx-datalayer-flatbuffers": "^1.20.0" + "ctrlx-datalayer": "^2.0.0", + "ctrlx-datalayer-flatbuffers": "^2.2.0" }, "scripts": { "getName": "echo $npm_package_name", "prepare": "npm run tsc", "tsc": "tsc" } -} \ No newline at end of file +} diff --git a/samples-node/datalayer.client/snap/snapcraft.yaml b/samples-node/datalayer.client/snap/snapcraft.yaml index bac5d799c..ed6ca154f 100644 --- a/samples-node/datalayer.client/snap/snapcraft.yaml +++ b/samples-node/datalayer.client/snap/snapcraft.yaml @@ -4,7 +4,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-node-datalayer-client version: "1.0.0" -summary: Data Layer client sample written in Node.js for ctrlX. +summary: ctrlX Data Layer client sample written in Node.js for ctrlX CORE. description: | The sample demonstrates how to read values from ctrlX Data Layer tree and write out the values to console. A subscription is used to get values by data change event in a deterministic publish interval. @@ -13,7 +13,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -31,13 +31,14 @@ parts: source: . build-environment: # Set the node version here. We recommend to use the latest LTS version. - - NODE_VERSION: "18.15.0" + - NODE_VERSION: "18.17.0" # We don't use the npm plugin here, because it has no X-build capability (can't build arm64 target snaps on amd64). # plugin: npm - # npm-node-version: "18.15.0" + # npm-node-version: "18.17.0" plugin: nil override-build: | + # set target arch if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then arch="arm64" @@ -53,11 +54,12 @@ parts: curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1 fi - # install the app (full) to compile (tsc -> ./dist) - npm install --unsafe-perm + # install and compile (tsc -> ./dist) + npm install --ignore-scripts --no-fund --unsafe-perm + npm run tsc # pack and install the app (only production) - npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --only=prod --production --no-fund --unsafe-perm + npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm # remove ctrlx-datalayer prebuilds of unused archs to reduce snap size package_name=$(npm run getName -s) diff --git a/samples-node/datalayer.client/src/app.ts b/samples-node/datalayer.client/src/app.ts index 6bb86fa8c..4e00e135e 100644 --- a/samples-node/datalayer.client/src/app.ts +++ b/samples-node/datalayer.client/src/app.ts @@ -1,25 +1,11 @@ #!/usr/bin/env node // !!! DO NOT REMOVE THE SHEBANG ON TOP OF THE FILE, WHICH SPECIFIES THIS APP TO BE EXECUTED BY NODE.JS !!! -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import DatalayerSystem from 'ctrlx-datalayer/dist/datalayersystem'; import INotifyItem from 'ctrlx-datalayer/dist/notifyitem'; @@ -34,7 +20,7 @@ async function main() { // Create a new ctrlX Data Layer system const system = new DatalayerSystem(''); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE await system.start(false); // Create a remote address with the parameters according to your environment diff --git a/samples-node/datalayer.provider.alldata/.vscode/tasks.json b/samples-node/datalayer.provider.alldata/.vscode/tasks.json index 32bbc1337..76c075f17 100644 --- a/samples-node/datalayer.provider.alldata/.vscode/tasks.json +++ b/samples-node/datalayer.provider.alldata/.vscode/tasks.json @@ -42,7 +42,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -55,11 +55,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -68,11 +68,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -81,7 +81,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -95,7 +95,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -129,7 +129,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -162,12 +162,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -178,7 +174,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -215,12 +211,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-node/datalayer.provider.alldata/README.md b/samples-node/datalayer.provider.alldata/README.md index d2de8721b..1baae59c8 100644 --- a/samples-node/datalayer.provider.alldata/README.md +++ b/samples-node/datalayer.provider.alldata/README.md @@ -1,104 +1,85 @@ -# README Node.js datalayer.provider.alldata - -This Node.js sample provides all types of data to the ctrlX Data Layer tree. - -__IMPORTANT__: - -The sample creates and registers all nodes individually, which is recommended for _small_ to _medium_ sized set of nodes to handle. If you're dealing with a _large_ set of nodes (big data provider) or any _dynamic node hierarchy_, we recommend to use a _virtual provider_ approach, listening just to any _wildcarded address_ ( e.g. myRoot/**) and using _self-managed virtual nodes_, just returned in _OnBrowse()_ method, which is more efficient. - -Please read the _Best Practise_ section in common Node.js documentation for more details and recommended samples. - - -## Introduction - -The sample demonstrates how to provide all available data types to ctrlX Data Layer tree. The demo creates a 'static' and a 'dynamic' folder under the root node 'samples'. The 'static' folder provides nodes with constant values. In the 'dynamic' folder the same nodes are provided as in 'static' folder but with changing value every second. - -## Description - -The sample demonstrates - -+ How to provide nodes with different data types to __ctrlX Data Layer__ - -+ How to create and provide meta data to nodes - -+ How to provide nodes with read-only or read-write support - -+ How to change node values dynamically - -+ How to register a user defined flatbuffers type - -+ How to read and write user defined flatbuffers nodes - -## Prerequisites - -Please read the common Node.js docs [here](./../README.md), first. - -## Getting Started - -1. Launch Visual Studio Code -2. Click on the __Remote Explorer__ from the menu. -3. Choose __Open Folder__. -4. Open the directory __datalayer.provider.alldata__. -5. Build and install snap as described [here](./../README.md). -6. Checkout ctrlX Data Layer web frontend (System | Data Layer) -7. Check the output using __Diagnostics__: - - - Login into your ctrlX - - Navigate to __Diagnostics -> Logbook__ - - Click __Settings__ on the right top corner - - Enable __Show system messages__ - - Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-datalayer-provider-alldata.app.service__ - - Now you should the see the app output diagnostics. - - Press __Refresh__ to update. - -8. If you have root permissions, you can also watch the output on any ssh console with the command: - ```bash - sudo snap logs ctrlx-node-datalayer-provider-alldata.app -f | more - ``` -## Screenshot - -![crtrX Data Layer tree](./docs/images/datalayer.provider.alldata/datalayer.provider.alldata.png) - -## Install the App - -Login into ctrlX and install the App (Apps). - -## Gratulations - We're finished - Let's start coding! - - -## Support -### Developer Community - -Please join the [Developer Community](https://developer.community.boschrexroth.com/) - -### SDK Forum - -Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) - -### Issues - -If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +# README Node.js datalayer.provider.alldata + +This Node.js sample provides all types of data to the ctrlX Data Layer tree. + +__IMPORTANT__: + +The sample creates and registers all nodes individually, which is recommended for _small_ to _medium_ sized set of nodes to handle. If you're dealing with a _large_ set of nodes (big data provider) or any _dynamic node hierarchy_, we recommend to use a _virtual provider_ approach, listening just to any _wildcarded address_ ( e.g. myRoot/**) and using _self-managed virtual nodes_, just returned in _OnBrowse()_ method, which is more efficient. + +Please read the _Best Practise_ section in common Node.js documentation for more details and recommended samples. + + +## Introduction + +The sample demonstrates how to provide all available data types to ctrlX Data Layer tree. The demo creates a 'static' and a 'dynamic' folder under the root node 'samples'. The 'static' folder provides nodes with constant values. In the 'dynamic' folder the same nodes are provided as in 'static' folder but with changing value every second. + +## Description + +The sample demonstrates + ++ How to provide nodes with different data types to __ctrlX Data Layer__ + ++ How to create and provide meta data to nodes + ++ How to provide nodes with read-only or read-write support + ++ How to change node values dynamically + ++ How to register a user defined flatbuffers type + ++ How to read and write user defined flatbuffers nodes + +## Prerequisites + +Please read the common Node.js docs [here](./../README.md), first. + +## Getting Started + +1. Launch Visual Studio Code +2. Click on the __Remote Explorer__ from the menu. +3. Choose __Open Folder__. +4. Open the directory __datalayer.provider.alldata__. +5. Build and install snap as described [here](./../README.md). +6. Checkout ctrlX Data Layer web frontend (Settings | Data Layer) +7. Check the output using __Diagnostics__: + + - Login into your ctrlX + - Navigate to __Diagnostics -> Logbook__ + - Click __Settings__ on the right top corner + - Enable __Show system messages__ + - Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-datalayer-provider-alldata.app.service__ + - Now you should the see the app output diagnostics. + - Press __Refresh__ to update. + +8. If you have root permissions, you can also watch the output on any ssh console with the command: + ```bash + sudo snap logs ctrlx-node-datalayer-provider-alldata.app -f | more + ``` +## Screenshot + +![crtrX ctrlX Data Layer tree](./docs/images/datalayer.provider.alldata/datalayer.provider.alldata.png) + +## Install the App + +Login into ctrlX and install the App (Apps). + +## Gratulations - We're finished - Let's start coding! + + +## Support +### Developer Community + +Please join the [Developer Community](https://developer.community.boschrexroth.com/) + +### SDK Forum + +Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) + +### Issues + +If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/samples-node/datalayer.provider.alldata/build-snap-amd64.sh b/samples-node/datalayer.provider.alldata/build-snap-amd64.sh index d090a57a9..92f432dad 100644 --- a/samples-node/datalayer.provider.alldata/build-snap-amd64.sh +++ b/samples-node/datalayer.provider.alldata/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.provider.alldata/build-snap-arm64.sh b/samples-node/datalayer.provider.alldata/build-snap-arm64.sh index b41b7fd26..8cd17b41a 100644 --- a/samples-node/datalayer.provider.alldata/build-snap-arm64.sh +++ b/samples-node/datalayer.provider.alldata/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.provider.alldata/package.json b/samples-node/datalayer.provider.alldata/package.json index d0f009fa9..d132395f5 100644 --- a/samples-node/datalayer.provider.alldata/package.json +++ b/samples-node/datalayer.provider.alldata/package.json @@ -11,15 +11,15 @@ "dist" ], "devDependencies": { - "@types/node": "^18.13.0", - "@typescript-eslint/parser": "^5.52.0", - "eslint": "^8.34.0", - "typescript": "^4.9.5", - "ts-node": "^10.9.1" + "@types/node": "^20.4.4", + "@typescript-eslint/parser": "^6.2.0", + "eslint": "^8.45.0", + "ts-node": "^10.9.1", + "typescript": "^5.1.6" }, "dependencies": { - "ctrlx-datalayer": "^1.6.0", - "ctrlx-datalayer-flatbuffers": "^1.20.0" + "ctrlx-datalayer": "^2.0.0", + "ctrlx-datalayer-flatbuffers": "^2.2.0" }, "scripts": { "getName": "echo $npm_package_name", @@ -27,4 +27,4 @@ "tsc": "tsc", "copy-bfbs": "mkdir -p ./dist && cp ./src/*.bfbs ./dist/" } -} \ No newline at end of file +} diff --git a/samples-node/datalayer.provider.alldata/snap/snapcraft.yaml b/samples-node/datalayer.provider.alldata/snap/snapcraft.yaml index d1496f96d..cefba3ce7 100644 --- a/samples-node/datalayer.provider.alldata/snap/snapcraft.yaml +++ b/samples-node/datalayer.provider.alldata/snap/snapcraft.yaml @@ -4,7 +4,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-node-datalayer-provider-alldata version: "1.0.0" -summary: Data Layer provider all data sample written in Node.js for ctrlX. +summary: ctrlX Data Layer provider all data sample written in Node.js for ctrlX CORE. description: | The sample demonstrates how to provide all available data types to the ctrlX Data Layer. The demo creates a 'static' and a 'dynamic' folder under the root node 'samples'. @@ -14,7 +14,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -32,13 +32,14 @@ parts: source: . build-environment: # Set the node version here. We recommend to use the latest LTS version. - - NODE_VERSION: "18.15.0" + - NODE_VERSION: "18.17.0" # We don't use the npm plugin here, because it has no X-build capability (can't build arm64 target snaps on amd64). # plugin: npm - # npm-node-version: "18.15.0" + # npm-node-version: "18.17.0" plugin: nil override-build: | + # set target arch if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then arch="arm64" @@ -54,11 +55,12 @@ parts: curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1 fi - # install the app (full) to compile (tsc -> ./dist) - npm install --unsafe-perm + # install and compile (tsc -> ./dist) + npm install --ignore-scripts --no-fund --unsafe-perm + npm run tsc # pack and install the app (only production) - npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --only=prod --production --no-fund --unsafe-perm + npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm # remove ctrlx-datalayer prebuilds of unused archs to reduce snap size package_name=$(npm run getName -s) diff --git a/samples-node/datalayer.provider.alldata/src/app.ts b/samples-node/datalayer.provider.alldata/src/app.ts index 267c91fa8..e822b0842 100644 --- a/samples-node/datalayer.provider.alldata/src/app.ts +++ b/samples-node/datalayer.provider.alldata/src/app.ts @@ -1,25 +1,11 @@ #!/usr/bin/env node // !!! DO NOT REMOVE THE SHEBANG ON TOP OF THE FILE, WHICH SPECIFIES THIS APP TO BE EXECUTED BY NODE.JS !!! -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ // DatalayerSystem import DatalayerSystem from 'ctrlx-datalayer/dist/datalayersystem'; @@ -46,7 +32,7 @@ async function main() { // Create a new ctrlX Data Layer system const system = new DatalayerSystem(''); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE await system.start(false); // Create a remote address with the parameters according to your environment diff --git a/samples-node/datalayer.provider.alldata/src/datarange.ts b/samples-node/datalayer.provider.alldata/src/datarange.ts index 2337e1bb0..ae22b0c73 100644 --- a/samples-node/datalayer.provider.alldata/src/datarange.ts +++ b/samples-node/datalayer.provider.alldata/src/datarange.ts @@ -1,22 +1,8 @@ -// Copyright (c) 2021-2022 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ /** * The IDataRange interface. diff --git a/samples-node/datalayer.provider.alldata/src/dataranges.ts b/samples-node/datalayer.provider.alldata/src/dataranges.ts index e6a719fb0..35d15e97b 100644 --- a/samples-node/datalayer.provider.alldata/src/dataranges.ts +++ b/samples-node/datalayer.provider.alldata/src/dataranges.ts @@ -1,22 +1,8 @@ -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import DataRange from './datarange'; diff --git a/samples-node/datalayer.provider.alldata/src/datatype.ts b/samples-node/datalayer.provider.alldata/src/datatype.ts index f637ddbbc..dcf77d091 100644 --- a/samples-node/datalayer.provider.alldata/src/datatype.ts +++ b/samples-node/datalayer.provider.alldata/src/datatype.ts @@ -1,21 +1,8 @@ -// Copyright (c) 2021-2022 Bosch Rexroth AG -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ /** * The interface IDataType. diff --git a/samples-node/datalayer.provider.alldata/src/datatypes.ts b/samples-node/datalayer.provider.alldata/src/datatypes.ts index fa1fad5d8..d685db0db 100644 --- a/samples-node/datalayer.provider.alldata/src/datatypes.ts +++ b/samples-node/datalayer.provider.alldata/src/datatypes.ts @@ -1,22 +1,8 @@ -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import VariantTypes from 'ctrlx-datalayer/dist/varianttypes'; diff --git a/samples-node/datalayer.provider.alldata/src/node.ts b/samples-node/datalayer.provider.alldata/src/node.ts index f58a50884..fec60fc77 100644 --- a/samples-node/datalayer.provider.alldata/src/node.ts +++ b/samples-node/datalayer.provider.alldata/src/node.ts @@ -1,25 +1,8 @@ -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// DatalayerSystem -import DatalayerSystem from 'ctrlx-datalayer/dist/datalayersystem'; +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ // Flatbuffers import * as flatbuffers from 'flatbuffers'; diff --git a/samples-node/datalayer.provider/.vscode/tasks.json b/samples-node/datalayer.provider/.vscode/tasks.json index 32bbc1337..76c075f17 100644 --- a/samples-node/datalayer.provider/.vscode/tasks.json +++ b/samples-node/datalayer.provider/.vscode/tasks.json @@ -42,7 +42,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -55,11 +55,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -68,11 +68,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -81,7 +81,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -95,7 +95,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -129,7 +129,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -162,12 +162,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -178,7 +174,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -215,12 +211,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-node/datalayer.provider/README.md b/samples-node/datalayer.provider/README.md index 913c7de1c..36cf6f7dc 100644 --- a/samples-node/datalayer.provider/README.md +++ b/samples-node/datalayer.provider/README.md @@ -1,124 +1,105 @@ -# README Node.js datalayer.provider - -This Node.js sample provides some registered nodes to the ctrlX Data Layer tree. - -__IMPORTANT__: - -The sample creates and registers all nodes individually, which is recommended for _small_ to _medium_ sized set of nodes to handle. If you're dealing with a _large_ set of nodes (big data provider) or any _dynamic node hierarchy_, we recommend to use a _virtual provider_ approach, listening just to any _wildcarded address_ ( e.g. myRoot/**) and using _self-managed virtual nodes_, just returned in _OnBrowse()_ method, which is more efficient. - -Please read the _Best Practise_ section in common Node.js documentation for more details and recommended samples. - -## Introduction - -The sample demonstrates how to provide nodes to ctrlX Data Layer tree. -The provider creates nodes with types of int/double/string. -Also a complex type encoded by [FlatBuffers](https://google.github.io/flatbuffers/) is provided. - -## Description - -The sample demonstrates - -+ How to provide nodes with different data types to __ctrlX Data Layer__ - -+ How to create and provide meta data to nodes - -+ How to provide nodes with read-only or read-write support - -+ How to register a user defined flatbuffers type - -## Prerequisites - -Please read the common Node.js docs [here](./../README.md), first. - -## Compile Flatbuffers Schema - -This app uses a flatbuffer defined in the schema file sampleSchema.fbs. From this schema file we have to create a binary file which is registered on the ctrlX and a Node.js class to create and access the defined flatbuffer data. These tasks can be done with the command line tool flatc. - -This tool is provided by this SDK under /bin/oss.flatbuffers/..insert OS version here../release/ - -Do following steps - -* Create a binary flatbuffers file with Visual Studio Code tasks: - - - "flatc binary (x64)" - - "flatc binary (arm64)" - - The generated file is stored in src/sampleSchema.bfbs - -* Generate the Node.js class with Visual Studio Code tasks: - - - "flatc class (x64)" - - "flatc class (arm64)" - - The generated code is stored in src/sampleSchema_generated.js - -## Getting Started - -1. Launch Visual Studio Code -2. Click on the __Remote Explorer__ from the menu. -3. Choose __Open Folder in QEMU VM__. -4. Open the directory __datalayer.provider__. -5. Build and install snap as described [here](./../README.md). -6. Checkout ctrlX Data Layer web frontend (System | Data Layer) -7. Check the output using __Diagnostics__: - - - Login into your ctrlX - - Navigate to __Diagnostics -> Logbook__ - - Click __Settings__ on the right top corner - - Enable __Show system messages__ - - Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-datalayer-provider.app.service__ - - Now you should the see the app output diagnostics. - - Press __Refresh__ to update. - -8. If you have root permissions, you can also watch the output on any ssh console with the command: - - ```bash - sudo snap logs ctrlx-node-datalayer-provider.app -f | more - ``` -## Screenshot - -![crtrX Data Layer tree](./docs/images/datalayer.provider/datalayer.provider.png) - -## Install the App - -Login into ctrlX and install the App (Apps). - -## Gratulations - We're finished - Let's start coding! - - -## Support -### Developer Community - -Please join the [Developer Community](https://developer.community.boschrexroth.com/) - -### SDK Forum - -Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) - -### Issues - -If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README Node.js datalayer.provider + +This Node.js sample provides some registered nodes to the ctrlX Data Layer tree. + +__IMPORTANT__: + +The sample creates and registers all nodes individually, which is recommended for _small_ to _medium_ sized set of nodes to handle. If you're dealing with a _large_ set of nodes (big data provider) or any _dynamic node hierarchy_, we recommend to use a _virtual provider_ approach, listening just to any _wildcarded address_ ( e.g. myRoot/**) and using _self-managed virtual nodes_, just returned in _OnBrowse()_ method, which is more efficient. + +Please read the _Best Practise_ section in common Node.js documentation for more details and recommended samples. + +## Introduction + +The sample demonstrates how to provide nodes to ctrlX Data Layer tree. +The provider creates nodes with types of int/double/string. +Also a complex type encoded by [FlatBuffers](https://google.github.io/flatbuffers/) is provided. + +## Description + +The sample demonstrates + ++ How to provide nodes with different data types to __ctrlX Data Layer__ + ++ How to create and provide meta data to nodes + ++ How to provide nodes with read-only or read-write support + ++ How to register a user defined flatbuffers type + +## Prerequisites + +Please read the common Node.js docs [here](./../README.md), first. + +## Compile Flatbuffers Schema + +This app uses a flatbuffer defined in the schema file sampleSchema.fbs. From this schema file we have to create a binary file which is registered on the ctrlX and a Node.js class to create and access the defined flatbuffer data. These tasks can be done with the command line tool flatc. + +This tool is provided by this SDK under /bin/oss.flatbuffers/..insert OS version here../release/ + +Do following steps + +* Create a binary flatbuffers file with Visual Studio Code tasks: + + - "flatc binary (x64)" + - "flatc binary (arm64)" + + The generated file is stored in src/sampleSchema.bfbs + +* Generate the Node.js class with Visual Studio Code tasks: + + - "flatc class (x64)" + - "flatc class (arm64)" + + The generated code is stored in src/sampleSchema_generated.js + +## Getting Started + +1. Launch Visual Studio Code +2. Click on the __Remote Explorer__ from the menu. +3. Choose __Open Folder in QEMU VM__. +4. Open the directory __datalayer.provider__. +5. Build and install snap as described [here](./../README.md). +6. Checkout ctrlX Data Layer web frontend (Settings | Data Layer) +7. Check the output using __Diagnostics__: + + - Login into your ctrlX + - Navigate to __Diagnostics -> Logbook__ + - Click __Settings__ on the right top corner + - Enable __Show system messages__ + - Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-datalayer-provider.app.service__ + - Now you should the see the app output diagnostics. + - Press __Refresh__ to update. + +8. If you have root permissions, you can also watch the output on any ssh console with the command: + + ```bash + sudo snap logs ctrlx-node-datalayer-provider.app -f | more + ``` +## Screenshot + +![crtrX ctrlX Data Layer tree](./docs/images/datalayer.provider/datalayer.provider.png) + +## Install the App + +Login into ctrlX and install the App (Apps). + +## Gratulations - We're finished - Let's start coding! + + +## Support +### Developer Community + +Please join the [Developer Community](https://developer.community.boschrexroth.com/) + +### SDK Forum + +Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) + +### Issues + +If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-node/datalayer.provider/build-snap-amd64.sh b/samples-node/datalayer.provider/build-snap-amd64.sh index d090a57a9..92f432dad 100644 --- a/samples-node/datalayer.provider/build-snap-amd64.sh +++ b/samples-node/datalayer.provider/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.provider/build-snap-arm64.sh b/samples-node/datalayer.provider/build-snap-arm64.sh index b41b7fd26..8cd17b41a 100644 --- a/samples-node/datalayer.provider/build-snap-arm64.sh +++ b/samples-node/datalayer.provider/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/datalayer.provider/package.json b/samples-node/datalayer.provider/package.json index 5c385f2af..f99c9de04 100644 --- a/samples-node/datalayer.provider/package.json +++ b/samples-node/datalayer.provider/package.json @@ -11,15 +11,15 @@ "dist" ], "devDependencies": { - "@types/node": "^18.13.0", - "@typescript-eslint/parser": "^5.52.0", - "eslint": "^8.34.0", - "typescript": "^4.9.5", - "ts-node": "^10.9.1" + "@types/node": "^20.4.4", + "@typescript-eslint/parser": "^6.2.0", + "eslint": "^8.45.0", + "ts-node": "^10.9.1", + "typescript": "^5.1.6" }, "dependencies": { - "ctrlx-datalayer": "^1.6.0", - "ctrlx-datalayer-flatbuffers": "^1.20.0" + "ctrlx-datalayer": "^2.0.0", + "ctrlx-datalayer-flatbuffers": "^2.2.0" }, "scripts": { "getName": "echo $npm_package_name", @@ -27,4 +27,4 @@ "tsc": "tsc", "copy-bfbs": "mkdir -p ./dist && cp ./src/*.bfbs ./dist/" } -} \ No newline at end of file +} diff --git a/samples-node/datalayer.provider/snap/snapcraft.yaml b/samples-node/datalayer.provider/snap/snapcraft.yaml index 8d7a51277..5e2b3ebd9 100644 --- a/samples-node/datalayer.provider/snap/snapcraft.yaml +++ b/samples-node/datalayer.provider/snap/snapcraft.yaml @@ -4,7 +4,7 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference name: ctrlx-node-datalayer-provider version: "1.0.0" -summary: Data Layer provider sample written in Node.js for ctrlX. +summary: ctrlX Data Layer provider sample written in Node.js for ctrlX CORE. description: | The sample demonstrates how to provide nodes to the ctrlX Data Layer tree. The provider creates nodes with types of int/double/string. @@ -13,7 +13,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -31,13 +31,14 @@ parts: source: . build-environment: # Set the node version here. We recommend to use the latest LTS version. - - NODE_VERSION: "18.15.0" + - NODE_VERSION: "18.17.0" # We don't use the npm plugin here, because it has no X-build capability (can't build arm64 target snaps on amd64). # plugin: npm - # npm-node-version: "18.15.0" + # npm-node-version: "18.17.0" plugin: nil override-build: | + # set target arch if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then arch="arm64" @@ -53,11 +54,12 @@ parts: curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1 fi - # install the app (full) to compile (tsc -> ./dist) - npm install --unsafe-perm + # install and compile (tsc -> ./dist) + npm install --ignore-scripts --no-fund --unsafe-perm + npm run tsc # pack and install the app (only production) - npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --only=prod --production --no-fund --unsafe-perm + npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm # remove ctrlx-datalayer prebuilds of unused archs to reduce snap size package_name=$(npm run getName -s) diff --git a/samples-node/datalayer.provider/src/app.ts b/samples-node/datalayer.provider/src/app.ts index ec8bc08f7..e63c8c18e 100644 --- a/samples-node/datalayer.provider/src/app.ts +++ b/samples-node/datalayer.provider/src/app.ts @@ -1,25 +1,11 @@ #!/usr/bin/env node // !!! DO NOT REMOVE THE SHEBANG ON TOP OF THE FILE, WHICH SPECIFIES THIS APP TO BE EXECUTED BY NODE.JS !!! -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import DatalayerSystem from 'ctrlx-datalayer/dist/datalayersystem'; import Result from 'ctrlx-datalayer/dist/result'; @@ -40,7 +26,7 @@ async function main() { // Create a new ctrlX Data Layer system const system = new DatalayerSystem(''); - // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX device + // Starts the ctrlX Data Layer system without a new broker (startBroker = false) because one broker is already running on ctrlX CORE await system.start(false); // Create a remote address with the parameters according to your environment diff --git a/samples-node/hello-world/.vscode/tasks.json b/samples-node/hello-world/.vscode/tasks.json index 32bbc1337..76c075f17 100644 --- a/samples-node/hello-world/.vscode/tasks.json +++ b/samples-node/hello-world/.vscode/tasks.json @@ -42,7 +42,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -55,11 +55,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -68,11 +68,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -81,7 +81,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -95,7 +95,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -129,7 +129,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -162,12 +162,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -178,7 +174,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -215,12 +211,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-node/hello-world/README.md b/samples-node/hello-world/README.md index 2913f42d6..e8b8a6481 100644 --- a/samples-node/hello-world/README.md +++ b/samples-node/hello-world/README.md @@ -1,89 +1,70 @@ -# README node hello.world - -This node sample prints out "Hello World from Node.js!" to the console. - -## Introduction - -Programm is prompting "Hello World from Node.js!" to standard output. - -## Description - -The samples demonstrates how to snap a simple Node.js script with the snapcraft [npm plugin](https://snapcraft.io/docs/npm-plugin). - -## Prerequisites - -Please read the common node docs [here](./../README.md), first. - -## Getting Started - -1. Launch Visual Studio Code -2. Click on the __Remote Explorer__ from the menu. -3. Choose __Open Folder__. -4. Open the directory __datalayer.browse__. -5. Build and install snap as described [here](./../README.md). -6. Check the output using __Diagnostics__: - - + Login into your ctrlX - + Navigate to __Diagnostics -> Logbook__ - + Click __Settings__ on the right top corner - + Enable __Show system messages__ - + Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-hello-world.app.service__ - + Now you should the see the app output diagnostics. - + Press __Refresh__ to update. - -7. If you have root permissions, you can also watch the output on any ssh console with the command: - ```bash - sudo snap logs ctrlx-node-hello-world.app -f | more - ``` -## Console Output -```bash -Hello World from Node.js! Thu, 07 Oct 2021 11:35:08 GMT -Hello World from Node.js! Thu, 07 Oct 2021 11:35:09 GMT -Hello World from Node.js! Thu, 07 Oct 2021 11:35:10 GMT -Hello World from Node.js! Thu, 07 Oct 2021 11:35:11 GMT -Hello World from Node.js! Thu, 07 Oct 2021 11:35:12 GMT - ``` - -## Install the App - -Login into ctrlX and install the App (Apps). - -## Gratulations - We're finished - Let's start coding! - - -## Support -### Developer Community - -Please join the [Developer Community](https://developer.community.boschrexroth.com/) - -### SDK Forum - -Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) - -### Issues - -If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +# README node hello.world + +This node sample prints out "Hello World from Node.js!" to the console. + +## Introduction + +Programm is prompting "Hello World from Node.js!" to standard output. + +## Description + +The samples demonstrates how to snap a simple Node.js script with the snapcraft [npm plugin](https://snapcraft.io/docs/npm-plugin). + +## Prerequisites + +Please read the common node docs [here](./../README.md), first. + +## Getting Started + +1. Launch Visual Studio Code +2. Click on the __Remote Explorer__ from the menu. +3. Choose __Open Folder__. +4. Open the directory __datalayer.browse__. +5. Build and install snap as described [here](./../README.md). +6. Check the output using __Diagnostics__: + + + Login into your ctrlX + + Navigate to __Diagnostics -> Logbook__ + + Click __Settings__ on the right top corner + + Enable __Show system messages__ + + Navigate to __Filter -> Units__ and check your __snap.ctrlx-node-hello-world.app.service__ + + Now you should the see the app output diagnostics. + + Press __Refresh__ to update. + +7. If you have root permissions, you can also watch the output on any ssh console with the command: + ```bash + sudo snap logs ctrlx-node-hello-world.app -f | more + ``` +## Console Output +```bash +Hello World from Node.js! Thu, 07 Oct 2021 11:35:08 GMT +Hello World from Node.js! Thu, 07 Oct 2021 11:35:09 GMT +Hello World from Node.js! Thu, 07 Oct 2021 11:35:10 GMT +Hello World from Node.js! Thu, 07 Oct 2021 11:35:11 GMT +Hello World from Node.js! Thu, 07 Oct 2021 11:35:12 GMT + ``` + +## Install the App + +Login into ctrlX and install the App (Apps). + +## Gratulations - We're finished - Let's start coding! + + +## Support +### Developer Community + +Please join the [Developer Community](https://developer.community.boschrexroth.com/) + +### SDK Forum + +Please visit the [SDK Forum](https://developer.community.boschrexroth.com/t5/ctrlX-AUTOMATION/ct-p/dcdev_community-bunit-dcae/) + +### Issues + +If you've found an error in these sample, please [file an issue](https://github.com/boschrexroth) + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-node/hello-world/build-snap-amd64.sh b/samples-node/hello-world/build-snap-amd64.sh index d090a57a9..92f432dad 100644 --- a/samples-node/hello-world/build-snap-amd64.sh +++ b/samples-node/hello-world/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/hello-world/build-snap-arm64.sh b/samples-node/hello-world/build-snap-arm64.sh index b41b7fd26..8cd17b41a 100644 --- a/samples-node/hello-world/build-snap-arm64.sh +++ b/samples-node/hello-world/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch \ No newline at end of file diff --git a/samples-node/hello-world/package.json b/samples-node/hello-world/package.json index f9f119365..7739158f9 100644 --- a/samples-node/hello-world/package.json +++ b/samples-node/hello-world/package.json @@ -11,14 +11,14 @@ "dist" ], "devDependencies": { - "@types/node": "^18.13.0", - "@typescript-eslint/parser": "^5.52.0", - "eslint": "^8.34.0", - "typescript": "^4.9.5", - "ts-node": "^10.9.1" + "@types/node": "^20.4.4", + "@typescript-eslint/parser": "^6.2.0", + "eslint": "^8.45.0", + "ts-node": "^10.9.1", + "typescript": "^5.1.6" }, "scripts": { "prepare": "npm run tsc", "tsc": "tsc" } -} \ No newline at end of file +} diff --git a/samples-node/hello-world/snap/snapcraft.yaml b/samples-node/hello-world/snap/snapcraft.yaml index fa0d40622..11becf97d 100644 --- a/samples-node/hello-world/snap/snapcraft.yaml +++ b/samples-node/hello-world/snap/snapcraft.yaml @@ -4,14 +4,14 @@ # See https://snapcraft.io/docs/snapcraft-yaml-reference version: "1.0.0" name: ctrlx-node-hello-world -summary: Hello World sample written in Node.js for ctrlX. +summary: Hello World sample written in Node.js for ctrlX CORE. description: | Programm is prompting "Hello World" to standard output. Enter 'sudo snap logs ctrlx-node-hello-world.app -f | more' to see the output. confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: @@ -29,13 +29,14 @@ parts: source: . build-environment: # Set the node version here. We recommend to use the latest LTS version. - - NODE_VERSION: "18.15.0" + - NODE_VERSION: "18.17.0" # We don't use the npm plugin here, because it has no X-build capability (can't build arm64 target snaps on amd64). # plugin: npm - # npm-node-version: "18.15.0" + # npm-node-version: "18.17.0" plugin: nil override-build: | + # set target arch if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then arch="arm64" @@ -51,11 +52,12 @@ parts: curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1 fi - # install the app (full) to compile (tsc -> ./dist) - npm install --unsafe-perm + # install and compile (tsc -> ./dist) + npm install --ignore-scripts --no-fund --unsafe-perm + npm run tsc # pack and install the app (only production) - npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --only=prod --production --no-fund --unsafe-perm + npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm # remove unused node_modules rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/npm diff --git a/samples-node/hello-world/src/app.ts b/samples-node/hello-world/src/app.ts index 235a1cc43..7b41e41d9 100644 --- a/samples-node/hello-world/src/app.ts +++ b/samples-node/hello-world/src/app.ts @@ -1,25 +1,11 @@ #!/usr/bin/env node // !!! DO NOT REMOVE THE SHEBANG ON TOP OF THE FILE, WHICH SPECIFIES THIS APP TO BE EXECUTED BY NODE.JS !!! -// Copyright (c) 2021-2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ function helloWorld() { setInterval(() => console.log('Hello World from Node.js!', new Date().toUTCString()), 1000) diff --git a/samples-node/solutions.webdav.interface/README.md b/samples-node/solutions.webdav.interface/README.md index 983690c83..ad68ff72a 100644 --- a/samples-node/solutions.webdav.interface/README.md +++ b/samples-node/solutions.webdav.interface/README.md @@ -2,11 +2,11 @@ ## Introduction -The sample demonstrates how to access the active and archived configurations of a ctrlX device remotely using the WebDAV protocol. +The sample demonstrates how to access the active and archived configurations of a ctrlX CORE remotely using the WebDAV protocol. ## Description -The application creates a WebDAV client and connects to a Virtual Control (localhost:8443) with the default credentials. +The application creates a WebDAV client and connects to a ctrlX CORE (localhost:8443) with the default credentials. It executes some file operations using the following WebDAV library: https://github.com/perry-mitchell/webdav-client. ## Getting Started @@ -30,24 +30,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-node/solutions.webdav.interface/package.json b/samples-node/solutions.webdav.interface/package.json index 5c027e9fe..1d312fd74 100644 --- a/samples-node/solutions.webdav.interface/package.json +++ b/samples-node/solutions.webdav.interface/package.json @@ -11,18 +11,18 @@ "dist" ], "devDependencies": { - "@types/node": "^18.13.0", - "@typescript-eslint/eslint-plugin": "^5.52.0", - "@typescript-eslint/parser": "^5.52.0", - "eslint": "^8.34.0", + "@types/node": "^20.4.4", + "@typescript-eslint/eslint-plugin": "^5.62.0", + "@typescript-eslint/parser": "^6.2.0", + "eslint": "^8.45.0", "ts-node": "^10.9.1", - "typescript": "^4.9.5" + "typescript": "^5.1.6" }, "scripts": { "prepare": "npm run tsc", "tsc": "tsc" }, "dependencies": { - "webdav": "^4.0.0" + "webdav": "^5.2.3" } } diff --git a/samples-node/solutions.webdav.interface/src/app.ts b/samples-node/solutions.webdav.interface/src/app.ts index 14515f5c9..3b38895df 100644 --- a/samples-node/solutions.webdav.interface/src/app.ts +++ b/samples-node/solutions.webdav.interface/src/app.ts @@ -1,25 +1,11 @@ #!/usr/bin/env node // !!! DO NOT REMOVE THE SHEBANG ON TOP OF THE FILE, WHICH SPECIFIES THIS APP TO BE EXECUTED BY NODE.JS !!! -// Copyright (c) 2023 Bosch Rexroth AG - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +/* + * SPDX-FileCopyrightText: Bosch Rexroth AG + * + * SPDX-License-Identifier: MIT + */ import { createClient } from "webdav"; @@ -47,7 +33,7 @@ async function webdavClient() { // Get file contents as text const txt = await client.getFileContents("/webdavArchive/configuration.json", { format: "text" }); - + // Get file contents binary const bin = await client.getFileContents("/webdavArchive/configuration.json"); @@ -80,7 +66,7 @@ async function webdavClient() { // Delete directory await client.deleteFile('webdavArchive'); - } catch(err) { + } catch (err) { console.log(`${err}`); } } diff --git a/samples-python/README.md b/samples-python/README.md index f11c40f25..e21603e84 100644 --- a/samples-python/README.md +++ b/samples-python/README.md @@ -36,9 +36,13 @@ See [Samples Overview](../samples.md) ### Working with a Python Sample Project - * From the main menu click File --> Open Folder and select the folder of your desired Python project. * Start a bash terminal within the main menu item - Terminal - New Terminal. +* Install or upgrade the ctrlX Data Layer build and runtime environment. + +```bash +sudo dpkg -i ../..deb/ctrlx-datalayer*.deb +``` #### Install a Virtual Environment @@ -54,7 +58,11 @@ The script runs following commands: source venv/bin/activate pip3 install -r requirements.txt -A subfolder venv/ will be created and activated as virtual environment which contains the Python runtime and all required packages. +A subfolder venv/ will be created and activated as virtual environment which contains the Python runtime and all required packages. + +*Hints:* The terminal console path begins with **(venv)**. With **Ctrl+Shift+P** open the *"Command Palette..."* and select *"Python: Select Interpreter"*, then *'venv/bin/python'* from the virtual environment. + + #### Debugging with Visual Studio Code diff --git a/samples-python/appdata/.vscode/tasks.json b/samples-python/appdata/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/appdata/.vscode/tasks.json +++ b/samples-python/appdata/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/appdata/LICENSE b/samples-python/appdata/LICENSE deleted file mode 100644 index e2327431a..000000000 --- a/samples-python/appdata/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/appdata/README.md b/samples-python/appdata/README.md index b6dc934ec..fc174c871 100644 --- a/samples-python/appdata/README.md +++ b/samples-python/appdata/README.md @@ -2,7 +2,7 @@ ## Introduction -This Python sample app shows how to persist application data in ctrlX environment. +This Python sample app shows how to persist application data in ctrlX CORE. ## Function Description @@ -22,24 +22,5 @@ ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/samples-python/appdata/appdata/app_data_control.py b/samples-python/appdata/appdata/app_data_control.py index f48c1dca8..77a5df959 100644 --- a/samples-python/appdata/appdata/app_data_control.py +++ b/samples-python/appdata/appdata/app_data_control.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os import platform @@ -28,8 +10,11 @@ class AppDataControl(): - + """AppDataControl + """ def __init__(self, storage_folder_name="AppDataSamplePy", storage_file_name="appdata.json"): + """__init__ + """ # The name of the application storage folder # MUST be same as specified in your *.package-manifest.json file self.storage_folder_name = storage_folder_name @@ -62,6 +47,8 @@ def __init__(self, storage_folder_name="AppDataSamplePy", storage_file_name="app } def load(self): + """load + """ print("INFO Starting load routine", flush=True) path = self.storage_file @@ -94,6 +81,8 @@ def load(self): return False def save(self): + """save + """ print("INFO Starting save routine", flush=True) # Check if storage location exists @@ -112,6 +101,9 @@ def save(self): return False def set_default(self): + """set_default + """ + # Set default application data data = { "hostname": platform.node(), @@ -127,6 +119,8 @@ def set_default(self): return AppDataControl.save(self) def ensure_storage_location(self): + """ensure_storage_location + """ # Check if storage location exist path = self.storage_location @@ -154,6 +148,8 @@ def ensure_storage_location(self): return True def set_appdata(self, data): + """set_appdata + """ # Check if present values are a subset of new values if self.appdata.keys() <= data.keys(): self.appdata = data @@ -162,4 +158,6 @@ def set_appdata(self, data): return False def get_appdata(self): + """get_appdata + """ return self.appdata diff --git a/samples-python/appdata/build-snap-amd64.sh b/samples-python/appdata/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/appdata/build-snap-amd64.sh +++ b/samples-python/appdata/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/appdata/build-snap-arm64.sh b/samples-python/appdata/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/appdata/build-snap-arm64.sh +++ b/samples-python/appdata/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/appdata/configs/package-assets/package-manifest.json b/samples-python/appdata/configs/package-assets/sdk-py-appdata.package-manifest.json similarity index 91% rename from samples-python/appdata/configs/package-assets/package-manifest.json rename to samples-python/appdata/configs/package-assets/sdk-py-appdata.package-manifest.json index 11d14f521..61504d971 100644 --- a/samples-python/appdata/configs/package-assets/package-manifest.json +++ b/samples-python/appdata/configs/package-assets/sdk-py-appdata.package-manifest.json @@ -1,63 +1,65 @@ -{ - "$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.schema.json", - "version": "1.0.0", - "id": "sdk-py-appdata", - "services": { - "proxyMapping": [ - { - "name": "sdk-py-appdata.web", - "url": "/sdk-py-appdata", - "binding": "unix://{$SNAP_DATA}/package-run/sdk-py-appdata/web.sock" - } - ] - }, - "commands": { - "activeConfiguration": { - "load": [ - { - "id": "sdk-py-appdata", - "subject": "appdata.sample.py", - "url": "https://localhost/sdk-py-appdata/api/v1/load" - } - ], - "save": [ - { - "id": "sdk-py-appdata", - "subject": "appdata.sample.py", - "url": "https://localhost/sdk-py-appdata/api/v1/save" - } - ] - } - }, - "scopes-declaration": [ - { - "identifier": "sdk-py-appdata.web", - "name": "sdk-py-appdata", - "description": "sdk-py-appdata permissions", - "scopes": [ - { - "identifier": "sdk-py-appdata.web.rwx", - "name": "Manage AppData Sample", - "description": "" - }, - { - "identifier": "sdk-py-appdata.web.r", - "name": "View AppData Sample", - "description": "" - } - ] - } - ], - "configuration": { - "appDirectories": [ - { - "name": "AppDataSamplePy", - "description": "Python AppData Sample", - "icon": "bosch-ic-directory", - "scopes": [ - ], - "copyOnLoad": true - } - ] - } +{ + "$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.schema.json", + "version": "1.0.0", + "id": "sdk-py-appdata", + "services": { + "proxyMapping": [ + { + "name": "sdk-py-appdata.web", + "url": "/sdk-py-appdata", + "binding": "unix://{$SNAP_DATA}/package-run/sdk-py-appdata/web.sock", + "restricted": [ + "/sdk-py-appdata/api/v1" + ] + } + ] + }, + "commands": { + "activeConfiguration": { + "load": [ + { + "id": "sdk-py-appdata", + "subject": "appdata.sample.py", + "url": "https://localhost/sdk-py-appdata/api/v1/load" + } + ], + "save": [ + { + "id": "sdk-py-appdata", + "subject": "appdata.sample.py", + "url": "https://localhost/sdk-py-appdata/api/v1/save" + } + ] + } + }, + "scopes-declaration": [ + { + "identifier": "sdk-py-appdata.web", + "name": "sdk-py-appdata", + "description": "sdk-py-appdata permissions", + "scopes": [ + { + "identifier": "sdk-py-appdata.web.rwx", + "name": "Manage AppData Sample", + "description": "" + }, + { + "identifier": "sdk-py-appdata.web.r", + "name": "View AppData Sample", + "description": "" + } + ] + } + ], + "configuration": { + "appDirectories": [ + { + "name": "AppDataSamplePy", + "description": "Python AppData Sample", + "icon": "bosch-ic-directory", + "scopes": [], + "copyOnLoad": true + } + ] + } } \ No newline at end of file diff --git a/samples-python/appdata/main.py b/samples-python/appdata/main.py index 1f535e360..7220bd698 100644 --- a/samples-python/appdata/main.py +++ b/samples-python/appdata/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os from http.server import HTTPServer @@ -29,6 +11,8 @@ def main(): + """main + """ # Start webserver to get load/save rest requests # Use unix sockets if app is running as snap if 'SNAP' in os.environ: @@ -42,6 +26,8 @@ def main(): def create_webserver_tcp(): + """create_webserver_tcp + """ serverPort = 1234 hostname = 'localhost' @@ -51,6 +37,8 @@ def create_webserver_tcp(): def create_webserver_unixsock(): + """create_webserver_unixsock + """ sock_dir = os.getenv('SNAP_DATA') + '/package-run/sdk-py-appdata/' sock_file = sock_dir + 'web.sock' if not os.path.exists(sock_dir): diff --git a/samples-python/appdata/setup.py b/samples-python/appdata/setup.py index 6cecc80c5..82a8eacbe 100644 --- a/samples-python/appdata/setup.py +++ b/samples-python/appdata/setup.py @@ -1,11 +1,14 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name = 'sdk-py-appdata', - version='2.3.0', - description = 'This sample demonstrates how to persist your application data in ctrlX environment', + version='3.0.0', + description = 'This sample demonstrates how to persist your application data in ctrlX CORE', author = 'SDK Team', packages = ['appdata','web'], install_requires=['PyJWT', 'ctrlx-datalayer', 'ctrlx-fbs'], scripts = ['main.py'], - license = 'Copyright (c) 2021-2022 Bosch Rexroth AG, Licensed under MIT License' + license = 'MIT License' ) diff --git a/samples-python/appdata/snap/snapcraft.yaml b/samples-python/appdata/snap/snapcraft.yaml index 23e9ffb39..5c503dee6 100644 --- a/samples-python/appdata/snap/snapcraft.yaml +++ b/samples-python/appdata/snap/snapcraft.yaml @@ -1,11 +1,11 @@ name: sdk-py-appdata -version: 2.3.0 +version: 3.0.0 summary: Application data sample written in Python for ctrlX title: sdk-py-appdata description: | - This sample demonstrates how to persist your application data in ctrlX environment + This sample demonstrates how to persist your application data in ctrlX CORE -base: core20 +base: core22 confinement: strict grade: stable diff --git a/samples-python/appdata/web/server.py b/samples-python/appdata/web/server.py index f69b75d6d..b05a3d1d1 100644 --- a/samples-python/appdata/web/server.py +++ b/samples-python/appdata/web/server.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT from http import HTTPStatus from http.server import BaseHTTPRequestHandler @@ -28,13 +10,14 @@ from appdata.app_data_control import AppDataControl -import token +from web.token import TokenValidation # Simple Webserver to get rest requests class Server(BaseHTTPRequestHandler): - + """Server + """ rest_url_load = '/sdk-py-appdata/api/v1/load' rest_url_save = '/sdk-py-appdata/api/v1/save' @@ -46,9 +29,9 @@ class Server(BaseHTTPRequestHandler): "phase": "" } - def do_POST(self): - # Check if url valid - request_url = self.path + def __check_url_valid(self, request_url) -> bool: + """__check_url_valid + """ print("INFO REST Command:", request_url, flush=True) if request_url != Server.rest_url_load and request_url != Server.rest_url_save: self.send_error(HTTPStatus.FORBIDDEN) @@ -56,17 +39,20 @@ def do_POST(self): # Check if command valid if self.command != 'POST': self.send_error(HTTPStatus.METHOD_NOT_ALLOWED) - return + return False # Check Request Token - token_validation = webtoken.TokenValidation() + token_validation = TokenValidation() result, token, token_decoded = token_validation.get_token(self.headers) if result is False or token_validation.is_authorized("rexroth-device.all.rwx") is False: self.send_error(HTTPStatus.UNAUTHORIZED) print("ERROR Not authorized (Bearer invalid)", flush=True) - return + return False print("INFO Check scope passed", flush=True) + return True - # Get payload from request + def __check_request_payload(self): + """__check_request_payload + """ content_length = int(self.headers['Content-Length']) # Get the size of data payload_string = unquote(self.rfile.read(content_length).decode("utf-8")) # parse = parse_qs(post_data) @@ -75,6 +61,20 @@ def do_POST(self): if payload.keys() != Server.config_payload.keys(): self.send_error(HTTPStatus.BAD_REQUEST) print("ERROR wrong request payload", flush=True) + return False, None + return True, payload + + def do_POST(self): + """do_POST + """ + # Check if url valid + request_url = self.path + if self.__check_url_valid(request_url) == False: + return + + # Get payload from request + check, payload = self.__check_request_payload() + if check == False: return # Command evaluation @@ -156,10 +156,13 @@ def do_POST(self): # Because http.server lib is designed for tcp, we need to write our own class to use unix sockets class UnixSocketHttpServer(UnixStreamServer): - + """UnixSocketHttpServer + """ allow_reuse_address = True def get_request(self): + """get_request + """ # dummy client address to avoid errors request, client_address = super().get_request() return (request, ["local", 0]) diff --git a/samples-python/appdata/web/token.py b/samples-python/appdata/web/token.py index 1e9ed0157..25511764e 100644 --- a/samples-python/appdata/web/token.py +++ b/samples-python/appdata/web/token.py @@ -1,31 +1,16 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import jwt class TokenValidation(): - + """TokenValidation + """ def get_token(self, header): + """get_token + """ self.header = header # Check token from request header if 'Authorization' in self.header: @@ -43,6 +28,8 @@ def get_token(self, header): return False, None, None def is_authorized(self, role): + """is_authorized + """ if 'scope' in self.token_decoded is None: print("ERROR Decoding Bearer token: No scope found", flush=True) return False diff --git a/samples-python/datalayer.calc/.vscode/tasks.json b/samples-python/datalayer.calc/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/datalayer.calc/.vscode/tasks.json +++ b/samples-python/datalayer.calc/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.calc/LICENSE b/samples-python/datalayer.calc/LICENSE deleted file mode 100644 index fdb0c59ec..000000000 --- a/samples-python/datalayer.calc/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-2022, Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.calc/README.md b/samples-python/datalayer.calc/README.md index c6d45d51f..4773a3c0b 100644 --- a/samples-python/datalayer.calc/README.md +++ b/samples-python/datalayer.calc/README.md @@ -6,11 +6,11 @@ This app is a ctrlX Data Layer Provider and Client written in Python. ## Function Description -The app reads two Data Layer values and calculates the output value 'out'. All values are float64 value types. +The app reads two ctrlX Data Layer values and calculates the output value 'out'. All values are float64 value types. -The Data Layer addresses of the input values are configured by the string input values 'in1' and 'in2'. +The ctrlX Data Layer addresses of the input values are configured by the string input values 'in1' and 'in2'. -How the out value is calculated can be configured as string value of the node 'mode'. +How the out value is calculated can be configured as string value with the node 'mode'. Supported operations are: @@ -28,51 +28,30 @@ There are two Python scripts: ### main.py -This function manages the Data Layer Provider and Client connection. +This function manages the ctrlX Data Layer Provider and Client connection. Furthermore it creates one instance of the BasicArithmeticOperations class and starts it. -If the client connection is lost the main function exits with an error code. - -If the app is installed as snap the system will restart the application after a short period of time. +If the client connection is lost the main function exits with an error code. If the app is installed as snap the system will restart the application after a short period of time. ### calculations.basic_arithmetic_operations.py This class BasicArithmeticOperations has several functions. -It is a Data Layer Provider for four nodes: +It is a ctrlX Data Layer Provider for four nodes: 1. in1: string, specifies the DL address of the first operand 2. in2: string, specifies the DL address of the second operand 3. mode: string, specifies the operation 4. out: float64, the result !!! important - The operands have to be 'double' values (FLOAT64)! + The operands have to be __double__ values (FLOAT64)! -With the address values of in1 and in2 a subscription is started. Every time when new values are published the value of out is recalculated. +With the address values of in1 and in2 a subscription is started. Every time when new values are published the value of 'out' is recalculated. ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.calc/build-snap-amd64.sh b/samples-python/datalayer.calc/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.calc/build-snap-amd64.sh +++ b/samples-python/datalayer.calc/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.calc/build-snap-arm64.sh b/samples-python/datalayer.calc/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.calc/build-snap-arm64.sh +++ b/samples-python/datalayer.calc/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.calc/calculations/__init__.py b/samples-python/datalayer.calc/calculations/__init__.py index 570569dd9..a103a0bd6 100644 --- a/samples-python/datalayer.calc/calculations/__init__.py +++ b/samples-python/datalayer.calc/calculations/__init__.py @@ -1,5 +1,8 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT __version__ = '2.4.0' __description__ = 'Sample for calculations with data from the ctrlX Data Layer' __author__ = 'Fantastic Python Developers' __licence__ = 'MIT License' -__copyright__ = 'Copyright (c) 2021-2022 Bosch Rexroth AG' \ No newline at end of file +__copyright__ = 'Bosch Rexroth AG' \ No newline at end of file diff --git a/samples-python/datalayer.calc/calculations/basic_arithmetic_operations.py b/samples-python/datalayer.calc/calculations/basic_arithmetic_operations.py index 24403b9b0..983624860 100644 --- a/samples-python/datalayer.calc/calculations/basic_arithmetic_operations.py +++ b/samples-python/datalayer.calc/calculations/basic_arithmetic_operations.py @@ -1,33 +1,14 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import typing -from comm.datalayer import NodeClass - import ctrlxdatalayer -from ctrlxdatalayer.provider import Provider +from comm.datalayer import NodeClass from ctrlxdatalayer.client import Client -from ctrlxdatalayer.provider_node import ProviderNodeCallbacks, NodeCallback +from ctrlxdatalayer.provider import Provider +from ctrlxdatalayer.provider_node import NodeCallback, ProviderNodeCallbacks from ctrlxdatalayer.variant import Result, Variant, VariantType from calculations.convert import Convert @@ -36,14 +17,17 @@ class BasicArithmeticOperations: + """BasicArithmeticOperations + """ def __init__(self, provider: Provider, client: Client, addressRoot: str, id: str, mode: str, update_time: int): - + """__init__ + """ self.provider = provider self.client = client self.addressRoot = addressRoot + "/" + id + "/" - + self.in1_address = Variant() self.in1_address.set_string( "framework/metrics/system/cpu-utilisation-percent") @@ -90,6 +74,8 @@ def __init__(self, provider: Provider, client: Client, addressRoot: str, id: st def response_notify_callback(self, result: Result, items: typing.List[ctrlxdatalayer.subscription.NotifyItem], userdata: ctrlxdatalayer.clib.userData_c_void_p): + """response_notify_callback + """ if result != Result.OK: print("response_notify_callback parameter result:", result, flush=True) @@ -122,34 +108,37 @@ def response_notify_callback(self, result: Result, items: typing.List[ctrlxdatal self.value_changed = True def get_float64_safe(self, v: Variant): + """get_float64_safe + """ if v.get_type() == VariantType.FLOAT64: return v.get_float64() if v.get_type() == VariantType.FLOAT32: - self.float64_value.set_float64( v.get_float32()) + self.float64_value.set_float64(v.get_float32()) return self.float64_value.get_float64() if v.get_type() == VariantType.INT64: - self.float64_value.set_float64( v.get_int64()) + self.float64_value.set_float64(v.get_int64()) return self.float64_value.get_float64() if v.get_type() == VariantType.INT32: - self.float64_value.set_float64( v.get_int32()) + self.float64_value.set_float64(v.get_int32()) return self.float64_value.get_float64() if v.get_type() == VariantType.INT16: - self.float64_value.set_float64( v.get_int16()) + self.float64_value.set_float64(v.get_int16()) return self.float64_value.get_float64() if v.get_type() == VariantType.INT8: - self.float64_value.set_float64( v.get_int8()) + self.float64_value.set_float64(v.get_int8()) return self.float64_value.get_float64() return None def calc(self): - + """calc + """ self.calc_internal() print() @@ -161,7 +150,8 @@ def calc(self): self.in2_value.get_float64(), "=", self.out.get_float64(), flush=True) def calc_internal(self): - + """calc_internal + """ self.out_error = False v1 = Convert.get_float64(self.in1_value) @@ -170,13 +160,13 @@ def calc_internal(self): self.out_error = True return self.in1_value.set_float64(v1) - + v2 = Convert.get_float64(self.in2_value) if v2 is None: self.out_error_text = "Converting in2 to float64 failed" self.out_error = True return - + self.in2_value.set_float64(v2) mode = self.mode.get_string() @@ -193,7 +183,7 @@ def calc_internal(self): self.out.set_float64(v1 * v2) return - if "/" in mode | ":" in mode: + if "/" in mode or ":" in mode: try: self.out.set_float64(v1 / v2) except ZeroDivisionError: @@ -213,29 +203,34 @@ def calc_internal(self): self.out_error_text = "Unsupported mode" self.out_error = True - def register_node(self, name: str): + def register_node(self, name: str) -> Result: + """register_node + """ address = self.addressRoot + name print("Registering node", address, flush=True) - self.provider.register_node( + return self.provider.register_node( address, self.providerNode) def register_nodes(self): + """register_nodes + """ result = self.register_node("in1") if result != ctrlxdatalayer.variant.Result.OK: return result - + result = self.register_node("in2") if result != ctrlxdatalayer.variant.Result.OK: return result - + result = self.register_node("mode") if result != ctrlxdatalayer.variant.Result.OK: return result - + return self.register_node("out") def subscribe(self): - + """subscribe + """ self.subscription_changed = False if self.subscription_properties is None: @@ -262,32 +257,42 @@ def subscribe(self): return self.subscription.subscribe_multi(addressList) def unsubscribe(self): + """unsubscribe + """ if self.subscription is None: return Result.OK return self.subscription.unsubscribe_all() def create_metadata(self, typeAddress: str, name: str, unit: str, description: str, allowWrite: bool): - + """create_metadata + """ return ctrlxdatalayer.metadata_utils.MetadataBuilder.create_metadata( name, description, unit, description+"_url", NodeClass.NodeClass.Variable, read_allowed=True, write_allowed=allowWrite, create_allowed=False, delete_allowed=False, browse_allowed=True, type_path="dummy") def __on_create(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): + """__on_create + """ cb(Result.OK, None) def __on_remove(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): + """__on_remove + """ # Not implemented because no wildcard is registered cb(Result.UNSUPPORTED, None) def __on_browse(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): - new_data = Variant() - new_data.set_array_string([]) - cb(Result.OK, new_data) + """__on_browse + """ + with Variant() as new_data: + new_data.set_array_string([]) + cb(Result.OK, new_data) def __on_read(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): - + """__on_read + """ if address.endswith("in1"): cb(Result.OK, self.in1_address) return @@ -315,7 +320,8 @@ def __on_read(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: st cb(Result.INVALID_ADDRESS, None) def __on_write(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): - + """__on_write + """ if data.get_type() != VariantType.STRING: cb(Result.TYPE_MISMATCH, None) return @@ -340,6 +346,8 @@ def __on_write(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: s cb(Result.INVALID_ADDRESS, None) def __on_metadata(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): + """__on_metadata + """ if address.endswith("in1"): cb(Result.OK, self.in1_metadata) return diff --git a/samples-python/datalayer.calc/calculations/convert.py b/samples-python/datalayer.calc/calculations/convert.py index c6afb5a32..fbbf468b8 100644 --- a/samples-python/datalayer.calc/calculations/convert.py +++ b/samples-python/datalayer.calc/calculations/convert.py @@ -1,142 +1,128 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT from ctrlxdatalayer.variant import Variant, VariantType class Convert: + """Convert + """ def get_float64(v: Variant): + """get_float64 + """ try: - return Convert.get_float64_internal(v) + return Convert.__get_float64_internal(v) except Exception as e: print(e, flush=True) return None - def get_float64_internal(v: Variant): + def __get_float64_internal(v: Variant): + """__get_float64_internal + """ if v.get_type() == VariantType.FLOAT64: return v.get_float64() - r = Variant() - - if v.get_type() == VariantType.FLOAT32: - r.set_float64(v.get_float32()) - return r.get_float64() - - if v.get_type() == VariantType.INT64: - r.set_float64(v.get_int64()) - return r.get_float64() - - if v.get_type() == VariantType.INT32: - r.set_float64(v.get_int32()) - return r.get_float64() - - if v.get_type() == VariantType.INT16: - r.set_float64(v.get_int16()) - return r.get_float64() - - if v.get_type() == VariantType.INT8: - r.set_float64(v.get_int8()) - return r.get_float64() - - if v.get_type() == VariantType.UINT64: - r.set_float64(v.get_uint64()) - return r.get_float64() - - if v.get_type() == VariantType.UINT32: - r.set_float64(v.get_uint32()) - return r.get_float64() - - if v.get_type() == VariantType.UINT16: - r.set_float64(v.get_uint16()) - return r.get_float64() - - if v.get_type() == VariantType.UINT8: - r.set_float64(v.get_uint8()) - return r.get_float64() - - if v.get_type() == VariantType.BOOL8: - if v.get_bool8(): - r.set_float64(1) - else: - r.set_float64(0) - return r.get_float64() - - if v.get_type() == VariantType.STRING: - r.set_float64(float(v.get_string())) - return r.get_float64() - - # ARRAY --------------------------------------------- - if v.get_type() == VariantType.ARRAY_FLOAT64: - return v.get_array_float64()[0] - - r = Variant() - - if v.get_type() == VariantType.ARRAY_FLOAT32: - r.set_float64(v.get_array_float32()) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_INT64: - r.set_float64(v.get_array_int64()[0]) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_INT32: - r.set_float64(v.get_array_int32()[0]) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_INT16: - r.set_float64(v.get_array_int16()[0]) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_INT8: - r.set_float64(v.get_array_int8()[0]) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_UINT64: - r.set_float64(v.get_array_uint64()[0]) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_UINT32: - r.set_float64(v.get_array_uint32()[0]) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_UINT16: - r.set_float64(v.get_array_uint16()[0]) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_UINT8: - r.set_float64(v.get_array_uint8()[0]) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_BOOL8: - if v.get_array_bool8()[0]: - r.set_float64(1) - else: - r.set_float64(0) - return r.get_float64() - - if v.get_type() == VariantType.ARRAY_STRING: - r.set_float64(float(v.get_array_string()[0])) - return r.get_float64() + with Variant() as r: + + if v.get_type() == VariantType.FLOAT32: + r.set_float64(v.get_float32()) + return r.get_float64() + + if v.get_type() == VariantType.INT64: + r.set_float64(v.get_int64()) + return r.get_float64() + + if v.get_type() == VariantType.INT32: + r.set_float64(v.get_int32()) + return r.get_float64() + + if v.get_type() == VariantType.INT16: + r.set_float64(v.get_int16()) + return r.get_float64() + + if v.get_type() == VariantType.INT8: + r.set_float64(v.get_int8()) + return r.get_float64() + + if v.get_type() == VariantType.UINT64: + r.set_float64(v.get_uint64()) + return r.get_float64() + + if v.get_type() == VariantType.UINT32: + r.set_float64(v.get_uint32()) + return r.get_float64() + + if v.get_type() == VariantType.UINT16: + r.set_float64(v.get_uint16()) + return r.get_float64() + + if v.get_type() == VariantType.UINT8: + r.set_float64(v.get_uint8()) + return r.get_float64() + + if v.get_type() == VariantType.BOOL8: + if v.get_bool8(): + r.set_float64(1) + else: + r.set_float64(0) + return r.get_float64() + + if v.get_type() == VariantType.STRING: + r.set_float64(float(v.get_string())) + return r.get_float64() + + # ARRAY --------------------------------------------- + if v.get_type() == VariantType.ARRAY_FLOAT64: + return v.get_array_float64()[0] + + if v.get_type() == VariantType.ARRAY_FLOAT32: + r.set_float64(v.get_array_float32()) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_INT64: + r.set_float64(v.get_array_int64()[0]) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_INT32: + r.set_float64(v.get_array_int32()[0]) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_INT16: + r.set_float64(v.get_array_int16()[0]) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_INT8: + r.set_float64(v.get_array_int8()[0]) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_UINT64: + r.set_float64(v.get_array_uint64()[0]) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_UINT32: + r.set_float64(v.get_array_uint32()[0]) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_UINT16: + r.set_float64(v.get_array_uint16()[0]) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_UINT8: + r.set_float64(v.get_array_uint8()[0]) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_BOOL8: + if v.get_array_bool8()[0]: + r.set_float64(1) + else: + r.set_float64(0) + return r.get_float64() + + if v.get_type() == VariantType.ARRAY_STRING: + r.set_float64(float(v.get_array_string()[0])) + return r.get_float64() return None diff --git a/samples-python/datalayer.calc/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.calc/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.calc/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.calc/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.calc/main.py b/samples-python/datalayer.calc/main.py index 212f52514..7fc3a3079 100644 --- a/samples-python/datalayer.calc/main.py +++ b/samples-python/datalayer.calc/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import sys @@ -40,6 +22,8 @@ def start_new_basic_arithmetic_operation( client: ctrlxdatalayer.client.Client, id: str, mode: str): + """start_new_basic_arithmetic_operation + """ basicArithmeticOperation = BasicArithmeticOperations( provider, client, addr_root, id, mode) @@ -47,7 +31,7 @@ def start_new_basic_arithmetic_operation( while basicArithmeticOperation.subscribe() != ctrlxdatalayer.variant.Result.OK: basicArithmeticOperation.unsubscribe() - print("WARN Starting Data Layer subscriptions for", + print("WARN Starting ctrlX Data Layer subscriptions for", addr_root + "/" + id, "failed with: " + str(result)) print("INFO Retry in 5s", flush=True) time.sleep(5.0) @@ -59,9 +43,9 @@ def start_new_basic_arithmetic_operation( print() print("===========================================================================") print("ctrlX Application in Python:") - print("- Reads Data Layer values per subscription.") + print("- Reads ctrlX Data Layer values per subscription.") print("- Runs a algorithm") - print("- Provides result as Data Layer Node") + print("- Provides result as ctrlX Data Layer Node") print() print("Will be restarted by the snap system on error.") print("===========================================================================", flush=True) @@ -71,21 +55,20 @@ def start_new_basic_arithmetic_operation( system = ctrlxdatalayer.system.System("") system.start(False) - # Here default argument values are used: ip="192.168.1.1", user="boschrexroth", password="boschrexroth", ssl_port=443 - # Enter ip, user, password etc. if they differ from your application. - client, client_connection_string = get_client(system) + # Change ip, user, password etc. if they differ from your application. + ip="192.168.1.1" # "10.0.2.2" for ctrlX COREvirtual with Port Forwarding + user="boschrexroth" + password="boschrexroth" + ssl_port=443 # 8443 for ctrlX COREvirtual with Port Forwarding + + client, client_connection_string = get_client(system, ip, user, password, ssl_port) if client is None: print("ERROR Could get ctrlX Datalayer client connection:", client_connection_string, flush=True) system.stop(False) sys.exit(1) print("INFO ctrlX Datalayer client connection succeeded:", client_connection_string, flush=True) - # Here default argument values are used: ip="192.168.1.1", user="boschrexroth", password="boschrexroth", ssl_port=443 - # Enter ip, user, password etc. if they differ from your application. - provider, provider_connection_string = get_provider(system, ip="10.52.244.109", - user="boschrexroth", - password="boschrexroth", - ssl_port=443) + provider, provider_connection_string = get_provider(system, ip, user, password, ssl_port) if provider is None: print("ERROR Could get ctrlX Datalayer provider connection:", provider_connection_string, flush=True) provider.close() @@ -96,8 +79,9 @@ def start_new_basic_arithmetic_operation( print("INFO ctrlX Datalayer provider connection succeeded:", provider_connection_string, flush=True) update_time = 1.0 + bao = BasicArithmeticOperations( - provider, client, addr_root, "1", "+", int(update_time)*1000) + provider, client, addr_root, "basic-arithmetic-operation", "+", int(update_time)*1000) result = bao.register_nodes() if result != ctrlxdatalayer.variant.Result.OK: print("ERROR Registering nodes failed with", str(result), flush=True) @@ -130,6 +114,7 @@ def start_new_basic_arithmetic_operation( "disconnected - exiting application. Will be restarted automatically.", flush=True) bao.unsubscribe() + provider.close() client.close() diff --git a/samples-python/datalayer.calc/setup.py b/samples-python/datalayer.calc/setup.py index 6837a8e1d..502d300ed 100644 --- a/samples-python/datalayer.calc/setup.py +++ b/samples-python/datalayer.calc/setup.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup import calculations diff --git a/samples-python/datalayer.calc/snap/snapcraft.yaml b/samples-python/datalayer.calc/snap/snapcraft.yaml index 1a1e1e828..2dc4d626c 100644 --- a/samples-python/datalayer.calc/snap/snapcraft.yaml +++ b/samples-python/datalayer.calc/snap/snapcraft.yaml @@ -2,9 +2,9 @@ name: sdk-py-calc version: 2.4.0 summary: Makes a calculation in Python title: SDK Python Calculation Sample -description: 'Sample App in Python using Data Layer subscriptions +description: 'Sample App in Python using ctrlX Data Layer subscriptions ' -base: core20 +base: core22 confinement: strict grade: stable diff --git a/samples-python/datalayer.client.browse/.vscode/tasks.json b/samples-python/datalayer.client.browse/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/datalayer.client.browse/.vscode/tasks.json +++ b/samples-python/datalayer.client.browse/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.client.browse/LICENSE b/samples-python/datalayer.client.browse/LICENSE deleted file mode 100644 index e2327431a..000000000 --- a/samples-python/datalayer.client.browse/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.client.browse/README.md b/samples-python/datalayer.client.browse/README.md index 06518f823..dba902fb2 100644 --- a/samples-python/datalayer.client.browse/README.md +++ b/samples-python/datalayer.client.browse/README.md @@ -2,7 +2,7 @@ ## Introduction -The app demonstrates how the Data Layer browse functionality works. +The app demonstrates how the ctrlX Data Layer browse functionality works. ## Function Description @@ -11,7 +11,7 @@ The ctrlX Data Layer tree is browsed recursively and the data of the nodes are l ## Implementation Description -Module __main.py__ creates a Data Layer client connection and calls the function browse_tree(). This function tries to read and list the value of the (root) node. Then it scans recursively through all sub nodes. When all nodes are listed the app ends. +Module __main.py__ creates a ctrlX Data Layer client connection and calls the function browse_tree(). This function tries to read and list the value of the (root) node. Then it scans recursively through all sub nodes. When all nodes are listed the app ends. The app is restarted automatically ny snapd because of its restart option in snap/snapcraft.yaml. @@ -19,24 +19,5 @@ ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.client.browse/build-snap-amd64.sh b/samples-python/datalayer.client.browse/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.client.browse/build-snap-amd64.sh +++ b/samples-python/datalayer.client.browse/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client.browse/build-snap-arm64.sh b/samples-python/datalayer.client.browse/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.client.browse/build-snap-arm64.sh +++ b/samples-python/datalayer.client.browse/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client.browse/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.client.browse/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.client.browse/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.client.browse/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.client.browse/main.py b/samples-python/datalayer.client.browse/main.py index ecd602ed3..3d52d97e0 100644 --- a/samples-python/datalayer.client.browse/main.py +++ b/samples-python/datalayer.client.browse/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import sys @@ -33,7 +15,8 @@ def main(): - + """main + """ with ctrlxdatalayer.system.System("") as datalayer_system: datalayer_system.start(False) @@ -56,14 +39,15 @@ def main(): print("Browsing and reading nodes...", flush=True) browse_tree(datalayer_client, datalayer_system.json_converter()) - print("Stopping Data Layer System", flush=True) + print("Stopping ctrlX Data Layer System", flush=True) # Attention: Doesn't return if any provider or client instance is still running stop_ok = datalayer_system.stop(False) print("System Stop", stop_ok, flush=True) def browse_tree(client: ctrlxdatalayer.client.Client, converter: ctrlxdatalayer.system.Converter, address=""): - + """browse_tree + """ # print current address and get value of node node_value = get_value(client, converter, address) if node_value is None: @@ -71,10 +55,10 @@ def browse_tree(client: ctrlxdatalayer.client.Client, converter: ctrlxdatalayer. else: print(address, node_value, flush=True) - # Browse Data Layer tree + # Browse ctrlX Data Layer tree result, data = client.browse_sync(address) if result != Result.OK: - print("ERROR Browsing Data Layer failed with: ", result, flush=True) + print("ERROR Browsing ctrlX Data Layer failed with: ", result, flush=True) return with data: # Recursive loop @@ -84,11 +68,12 @@ def browse_tree(client: ctrlxdatalayer.client.Client, converter: ctrlxdatalayer. def get_value(client: ctrlxdatalayer.client.Client, converter: ctrlxdatalayer.system.Converter, address: str): - + """get_value + """ # get data with read sync result, data = client.read_sync(address) if result != Result.OK: - # print("ERROR Reading Data Layer failed with: ", result, flush=True) + # print("ERROR Reading ctrlX Data Layer failed with: ", result, flush=True) return with data: @@ -194,7 +179,8 @@ def get_value(client: ctrlxdatalayer.client.Client, converter: ctrlxdatalayer.sy def get_typeaddress(client: ctrlxdatalayer.client.Client, address: str): - + """get_typeaddress + """ result, metadata = client.metadata_sync(address) if result != Result.OK: print("ERROR Reading metadata of ", address, " failed with: ", result, flush=True) diff --git a/samples-python/datalayer.client.browse/setup.py b/samples-python/datalayer.client.browse/setup.py index 9f7d3fe74..1a867c0c6 100644 --- a/samples-python/datalayer.client.browse/setup.py +++ b/samples-python/datalayer.client.browse/setup.py @@ -1,11 +1,14 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name = 'sdk-py-browse', version='2.4.0', - description = 'This sample demonstrates how to browse a Data Layer tree', + description = 'This sample demonstrates how to browse a ctrlX Data Layer tree', author = 'SDK Team', install_requires = ['ctrlx-datalayer', 'ctrlx-fbs'], packages = ['helper'], scripts = ['main.py'], - license = 'Copyright (c) 2021-2022 Bosch Rexroth AG, Licensed under MIT License' + license = 'MIT License' ) diff --git a/samples-python/datalayer.client.browse/snap/snapcraft.yaml b/samples-python/datalayer.client.browse/snap/snapcraft.yaml index a55b96dbe..568f3eb89 100644 --- a/samples-python/datalayer.client.browse/snap/snapcraft.yaml +++ b/samples-python/datalayer.client.browse/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-browse version: 2.4.0 -summary: Data Layer browse sample written in Python for ctrlX +summary: ctrlX Data Layer browse sample written in Python for ctrlX title: sdk-py-browse description: | - This sample demonstrates how to browse a Data Layer tree -base: core20 + This sample demonstrates how to browse a ctrlX Data Layer tree +base: core22 confinement: strict grade: stable diff --git a/samples-python/datalayer.client.bulk/.vscode/tasks.json b/samples-python/datalayer.client.bulk/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/datalayer.client.bulk/.vscode/tasks.json +++ b/samples-python/datalayer.client.bulk/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.client.bulk/LICENSE b/samples-python/datalayer.client.bulk/LICENSE deleted file mode 100644 index e2327431a..000000000 --- a/samples-python/datalayer.client.bulk/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.client.bulk/README.md b/samples-python/datalayer.client.bulk/README.md index fe7246d9f..61dffd62f 100644 --- a/samples-python/datalayer.client.bulk/README.md +++ b/samples-python/datalayer.client.bulk/README.md @@ -11,29 +11,10 @@ The code is compact and the performance is much better than single operations. ## Implementation Description -The module __main.py__ connects to the Data Layer and handles the Data Layer access. +The module __main.py__ connects to the ctrlX Data Layer and handles the ctrlX Data Layer access. ___ ## License -MIT License - -Copyright (c) 2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.client.bulk/build-snap-amd64.sh b/samples-python/datalayer.client.bulk/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.client.bulk/build-snap-amd64.sh +++ b/samples-python/datalayer.client.bulk/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client.bulk/build-snap-arm64.sh b/samples-python/datalayer.client.bulk/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.client.bulk/build-snap-arm64.sh +++ b/samples-python/datalayer.client.bulk/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client.bulk/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.client.bulk/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.client.bulk/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.client.bulk/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.client.bulk/main.py b/samples-python/datalayer.client.bulk/main.py index b6fa93431..516b12886 100644 --- a/samples-python/datalayer.client.bulk/main.py +++ b/samples-python/datalayer.client.bulk/main.py @@ -1,36 +1,18 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os import sys import time from typing import List import logging -from systemd.journal import JournaldLogHandler +from cysystemd import journal import ctrlxdatalayer -from ctrlxdatalayer.bulk import Response +from ctrlxdatalayer.bulk import Response, BulkReadRequest, BulkWriteRequest, BulkCreateRequest from ctrlxdatalayer.variant import Result, Variant from comm.datalayer import Metadata @@ -38,12 +20,14 @@ log = logging.getLogger('sdk-py-client-bulk') if 'SNAP' in os.environ: - log.addHandler(JournaldLogHandler()) + log.addHandler(journal.JournaldLogHandler()) else: log.addHandler(logging.StreamHandler(sys.stdout)) log.setLevel(logging.DEBUG) def cb_read_async(responses: List[Response], userdata: ctrlxdatalayer.clib.userData_c_void_p): + """cb_read_async + """ for response in responses: if response.get_result() == Result.OK: dt = response.get_datetime() @@ -53,7 +37,8 @@ def cb_read_async(responses: List[Response], userdata: ctrlxdatalayer.clib.userD def main(): - + """main + """ log.debug("=================================================================") log.debug("sdk-py-client-bulk - A ctrlX Data Layer Client App in Python") log.debug("=================================================================") @@ -70,103 +55,26 @@ def main(): with datalayer_client: # datalayer_client is closed automatically when leaving with block if datalayer_client.is_connected() is False: - log.error("Data Layer is NOT connected:" + datalayer_client_connection_string) + log.error("ctrlX Data Layer is NOT connected:" + datalayer_client_connection_string) sys.exit(2) # Bulk read sync - bulk = datalayer_client.create_bulk() - with bulk: - bulk.add('framework/metrics/system/cpu-utilisation-percent') - bulk.add('framework/metrics/system/memavailable-mb') - result = bulk.read() - if result == Result.OK: - for response in bulk.get_response(): - if response.get_result() == Result.OK: - dt = response.get_datetime() - addr = response.get_address() - data = response.get_data() - log.debug('Bulk read: {a} {b} {c}'.format(a=dt, b=addr, c=data.get_float64())) + __bulk_read(datalayer_client) # Bulk write sync - bulk = datalayer_client.create_bulk() - with bulk: - with Variant() as data: - data.set_bool8(False) - bulk.add('sdk-py-provider-alldata/dynamic/bool8', data) - bulk.add('sdk-cpp-alldata/dynamic/bool8', data) - - data.set_float32(1.2345) - bulk.add('sdk-py-provider-alldata/dynamic/float32', data) - bulk.add('sdk-cpp-alldata/dynamic/float32', data) - - data.set_int8(123) - bulk.add('sdk-py-provider-alldata/dynamic/int8', data) - bulk.add('sdk-cpp-alldata/dynamic/int8', data) - - data.set_string('Changed by bulk write :-)') - bulk.add('sdk-py-provider-alldata/dynamic/string', data) - bulk.add('sdk-cpp-alldata/dynamic/string', data) - - result = bulk.write() - if result == Result.OK: - for response in bulk.get_response(): - log.debug('Bulk write: {a} {b}'.format(a=response.get_address(), b=response.get_result())) + __bulk_write(datalayer_client) # Bulk browse sync - bulk = datalayer_client.create_bulk() - with bulk: - bulk.add('framework/metrics/system') - bulk.add('framework/metrics/process') - result = bulk.browse() - if result == Result.OK: - for response in bulk.get_response(): - log.debug('Bulk browse: {a} {b}'.format(a=response.get_address(), b=response.get_result())) - if response.get_result() == Result.OK: - for node in response.get_data().get_array_string(): - log.debug('\t{a}'.format(a=node)) + __bulk_browse(datalayer_client) # Bulk metadata sync - bulk = datalayer_client.create_bulk() - with bulk: - bulk.add('framework/metrics/system/cpu-utilisation-percent') - bulk.add('framework/metrics/system/memavailable-mb') - result = bulk.metadata() - if result == Result.OK: - for response in bulk.get_response(): - log.debug('Bulk metadata: {a} {b}'.format(a=response.get_address(), b=response.get_result())) - if response.get_result() == Result.OK: - metadata = Metadata.Metadata.GetRootAsMetadata( - response.get_data().get_flatbuffers(), 0) - allowedoperations = metadata.Operations() - log.debug("\tallowedOperations read={a} write={b} create={c} delete={d}" - .format(a=allowedoperations.Read(),b=allowedoperations.Write(),c=allowedoperations.Create(),d=allowedoperations.Delete())) - + __bulk_metadata(datalayer_client) # Bulk create sync - bulk = datalayer_client.create_bulk() - with bulk: - with Variant() as data: - data.set_int8(-127) - bulk.add('sdk-cpp-alldata/dynamic/py-created/int8', data) - data.set_string('Created by bulk create') - bulk.add('sdk-cpp-alldata/dynamic/py-created/string', data) - result = bulk.create() - if result == Result.OK: - for response in bulk.get_response(): - log.debug('Bulk create: {a} {b}'.format(a=response.get_address(), b=response.get_result())) + __bulk_create(datalayer_client) # Bulk delete sync - bulk = datalayer_client.create_bulk() - with bulk: - with Variant() as data: - data.set_int8(-127) - bulk.add('sdk-cpp-alldata/dynamic/py-created/int8', data) - data.set_string('Created by bulk create') - bulk.add('sdk-cpp-alldata/dynamic/py-created/string', data) - result = bulk.delete() - if result == Result.OK: - for response in bulk.get_response(): - log.debug('Bulk delete: {a} {b}'.format(a=response.get_address(), b=response.get_result())) + __bulk_delete(datalayer_client) log.debug("-----------------------------------------------------------------") log.debug("Running async operations") @@ -174,22 +82,145 @@ def main(): # Attention: Keep bulk instance during async operation bulk = datalayer_client.create_bulk() - bulk.add('framework/metrics/system/cpu-utilisation-percent') - bulk.add('framework/metrics/system/memavailable-mb') - + req = [BulkReadRequest('framework/metrics/system/cpu-utilisation-percent'), + BulkReadRequest('framework/metrics/system/memavailable-mb')] while datalayer_client.is_connected(): # Bulk read async - result = bulk.read(cb_read_async) + result = bulk.read(req, cb_read_async) time.sleep(5.0) - log.error("Data Layer is NOT connected") + log.error("ctrlX Data Layer is NOT connected") # Attention: Doesn't return if any provider or client instance is still running stop_ok = datalayer_system.stop(False) log.debug("System Stop {a}".format(a=stop_ok)) +def __bulk_delete(client): + """__bulk_delete + """ + bulk = client.create_bulk() + with bulk: + result = bulk.delete(['sdk-cpp-alldata/dynamic/py-created/int8', 'sdk-cpp-alldata/dynamic/py-created/string']) + if result != Result.OK: + log.debug('Bulk delete error: {a}'.format(result)) + return + for response in bulk.get_response(): + log.debug('Bulk delete: {a} {b}'.format(a=response.get_address(), b=response.get_result())) + +def __bulk_create(client): + """__bulk_create + """ + bulk = client.create_bulk() + with bulk: + with Variant() as data: + data.set_int8(-127) + req = [BulkCreateRequest('sdk-cpp-alldata/dynamic/py-created/int8', data)] + data.set_string('Created by bulk create') + req.append(BulkCreateRequest('sdk-cpp-alldata/dynamic/py-created/int8', data)) + result = bulk.create(req) + if result != Result.OK: + log.debug('Bulk create error: {a}'.format(result)) + return + for response in bulk.get_response(): + log.debug('Bulk create: {a} {b}'.format(a=response.get_address(), b=response.get_result())) + +def __bulk_metadata(client): + """__bulk_metadata + """ + bulk = client.create_bulk() + with bulk: + result = bulk.metadata(['framework/metrics/system/cpu-utilisation-percent','framework/metrics/system/memavailable-mb']) + if result != Result.OK: + log.debug('Bulk metadata error: {a}'.format(result)) + return + for response in bulk.get_response(): + log.debug('Bulk metadata: {a} {b}'.format(a=response.get_address(), b=response.get_result())) + if response.get_result() != Result.OK: + log.debug('Bulk metadata response error: {a}'.format(response.get_result())) + continue + metadata = Metadata.Metadata.GetRootAsMetadata( + response.get_data().get_flatbuffers(), 0) + allowedoperations = metadata.Operations() + log.debug("\tallowedOperations read={a} write={b} create={c} delete={d}" + .format(a=allowedoperations.Read(),b=allowedoperations.Write(),c=allowedoperations.Create(),d=allowedoperations.Delete())) + +def __bulk_browse(client): + """__bulk_browse + """ + bulk = client.create_bulk() + with bulk: + result = bulk.browse(['framework/metrics/system', 'framework/metrics/process']) + if result != Result.OK: + log.debug('Bulk browse error: {a}'.format(result)) + return + for response in bulk.get_response(): + log.debug('Bulk browse: {a} {b}'.format(a=response.get_address(), b=response.get_result())) + if response.get_result() != Result.OK: + log.debug('Bulk browse response error: {a}'.format(response.get_result())) + continue + for node in response.get_data().get_array_string(): + log.debug('\t{a}'.format(a=node)) + +def __bulk_write(client): + """__bulk_write + """ + bulk = client.create_bulk() + with bulk: + req = [] + data = Variant() + data.set_bool8(False) + req.extend([BulkWriteRequest('sdk-py-provider-alldata/dynamic/bool8', data), + BulkWriteRequest('sdk-cpp-alldata/dynamic/bool8', data)]) + + dataf = Variant() + dataf.set_float32(1.2345) + req.extend([BulkWriteRequest('sdk-py-provider-alldata/dynamic/float32', dataf), + BulkWriteRequest('sdk-cpp-alldata/dynamic/float32', dataf)]) + + datai = Variant() + datai.set_int8(123) + req.extend([BulkWriteRequest('sdk-py-provider-alldata/dynamic/int8', datai), + BulkWriteRequest('sdk-cpp-alldata/dynamic/int8', datai)]) + + datas = Variant() + datas.set_string('Changed by bulk write :-)') + req.extend([BulkWriteRequest('sdk-py-provider-alldata/dynamic/string', datas), + BulkWriteRequest('sdk-cpp-alldata/dynamic/string', datas)]) + + result = bulk.write(req) + data.close() + dataf.close() + datai.close() + datas.close() + if result != Result.OK: + log.debug('Bulk write error: {a}'.format(result)) + return + for response in bulk.get_response(): + log.debug('Bulk write: {a} {b}'.format(a=response.get_address(), b=response.get_result())) + +def __bulk_read(client): + """__bulk_read + """ + bulk = client.create_bulk() + with bulk: + req = [BulkReadRequest( + 'framework/metrics/system/cpu-utilisation-percent'), + BulkReadRequest( + 'framework/metrics/system/memavailable-mb')] + result = bulk.read(req) + if result != Result.OK: + log.debug('Bulk read error: {a}'.format(result)) + return + for response in bulk.get_response(): + if response.get_result() != Result.OK: + log.debug('Bulk read response error: {a}'.format(response.get_result())) + continue + dt = response.get_datetime() + addr = response.get_address() + data = response.get_data() + log.debug('Bulk read: {a} {b} {c}'.format(a=dt, b=addr, c=data.get_float64())) if __name__ == '__main__': main() diff --git a/samples-python/datalayer.client.bulk/requirements.txt b/samples-python/datalayer.client.bulk/requirements.txt index b8c07a60e..67e5a04cb 100644 --- a/samples-python/datalayer.client.bulk/requirements.txt +++ b/samples-python/datalayer.client.bulk/requirements.txt @@ -2,4 +2,4 @@ autopep8 flake8 ctrlx-datalayer ctrlx-fbs -systemd +cysystemd diff --git a/samples-python/datalayer.client.bulk/setup.py b/samples-python/datalayer.client.bulk/setup.py index 1241d0f05..60577e2c0 100644 --- a/samples-python/datalayer.client.bulk/setup.py +++ b/samples-python/datalayer.client.bulk/setup.py @@ -1,11 +1,14 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name = 'sdk-py-client-bulk', version='1.0.0', - description = 'Data Layer client bulk operations', + description = 'ctrlX Data Layer client bulk operations', author = 'SDK Team', - install_requires = ['systemd', 'ctrlx-fbs', 'ctrlx_datalayer' ], + install_requires = ['cysystemd', 'ctrlx-fbs', 'ctrlx_datalayer' ], packages = ['helper'], scripts = ['main.py'], - license = 'Copyright (c) 2022 Bosch Rexroth AG, Licensed under MIT License' + license = 'MIT License' ) diff --git a/samples-python/datalayer.client.bulk/snap/snapcraft.yaml b/samples-python/datalayer.client.bulk/snap/snapcraft.yaml index f6a47530a..7c6060b48 100644 --- a/samples-python/datalayer.client.bulk/snap/snapcraft.yaml +++ b/samples-python/datalayer.client.bulk/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-client-bulk version: 2.4.0 -summary: Data Layer client sample written in Python for ctrlX. +summary: ctrlX Data Layer client sample written in Python for ctrlX CORE. title: sdk-py-client-bulk description: | The sample demonstrates ctrlX Data Layer bulk operations. -base: core20 +base: core22 confinement: strict grade: stable @@ -26,6 +26,7 @@ parts: stage-packages: - libzmq5 - ctrlx-datalayer + - libsystemd-dev plugs: datalayer: diff --git a/samples-python/datalayer.client.light/.vscode/tasks.json b/samples-python/datalayer.client.light/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/datalayer.client.light/.vscode/tasks.json +++ b/samples-python/datalayer.client.light/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.client.light/LICENSE b/samples-python/datalayer.client.light/LICENSE deleted file mode 100644 index e2327431a..000000000 --- a/samples-python/datalayer.client.light/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.client.light/README.md b/samples-python/datalayer.client.light/README.md index 48cf7ec69..771ec451a 100644 --- a/samples-python/datalayer.client.light/README.md +++ b/samples-python/datalayer.client.light/README.md @@ -10,29 +10,10 @@ A subscription is used to get values by data change event in a deterministic pub ## Implementation Description -The module __main.py__ connects to the Data Layer and handles the Data Layer access. +The module __main.py__ connects to the ctrlX Data Layer and handles the ctrlX Data Layer access. ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.client.light/build-snap-amd64.sh b/samples-python/datalayer.client.light/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.client.light/build-snap-amd64.sh +++ b/samples-python/datalayer.client.light/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client.light/build-snap-arm64.sh b/samples-python/datalayer.client.light/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.client.light/build-snap-arm64.sh +++ b/samples-python/datalayer.client.light/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client.light/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.client.light/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.client.light/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.client.light/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.client.light/main.py b/samples-python/datalayer.client.light/main.py index e0d269dd0..0a53e2600 100644 --- a/samples-python/datalayer.client.light/main.py +++ b/samples-python/datalayer.client.light/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import sys import time @@ -35,7 +17,8 @@ from helper.ctrlx_datalayer_helper import get_client def main(): - + """main + """ print() print("=================================================================") print("sdk-py-datalayer-client - A ctrlX Data Layer Client App in Python") @@ -52,7 +35,7 @@ def main(): with datalayer_client: # datalayer_client is closed automatically when leaving with block if datalayer_client.is_connected() is False: - print("ERROR Data Layer is NOT connected:", datalayer_client_connection_string, flush=True) + print("ERROR ctrlX Data Layer is NOT connected:", datalayer_client_connection_string, flush=True) sys.exit(2) @@ -118,7 +101,7 @@ def main(): time.sleep(2.0) - print("ERROR Data Layer is NOT connected") + print("ERROR ctrlX Data Layer is NOT connected") print("INFO Closing subscription", flush=True) sub.close() @@ -128,6 +111,8 @@ def main(): # Response notify callback function def cb_subscription_sync(result: Result, items: List[ctrlxdatalayer.subscription.NotifyItem], userdata): + """cb_subscription_sync + """ if result is not Result.OK: print("ERROR notify subscription:", result, flush=True) return diff --git a/samples-python/datalayer.client.light/setup.py b/samples-python/datalayer.client.light/setup.py index a1faca312..d051c3d5c 100644 --- a/samples-python/datalayer.client.light/setup.py +++ b/samples-python/datalayer.client.light/setup.py @@ -1,11 +1,14 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name = 'sdk-py-client-light', version='2.4.0', - description = 'Lightweight Data Layer client', + description = 'Lightweight ctrlX Data Layer client', author = 'SDK Team', install_requires = ['ctrlx-datalayer', 'ctrlx-fbs'], packages = ['helper'], scripts = ['main.py'], - license = 'Copyright (c) 2021-2022 Bosch Rexroth AG, Licensed under MIT License' + license = 'MIT License' ) diff --git a/samples-python/datalayer.client.light/snap/snapcraft.yaml b/samples-python/datalayer.client.light/snap/snapcraft.yaml index d3cf929a0..d413c7179 100644 --- a/samples-python/datalayer.client.light/snap/snapcraft.yaml +++ b/samples-python/datalayer.client.light/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-client-light version: 2.4.0 -summary: Data Layer client sample written in Python for ctrlX. +summary: ctrlX Data Layer client sample written in Python for ctrlX CORE. title: sdk-py-client-light description: | The sample demonstrates how to read values from ctrlX Data Layer tree and write out the values to console. -base: core20 +base: core22 confinement: strict grade: stable diff --git a/samples-python/datalayer.client.sub/.vscode/tasks.json b/samples-python/datalayer.client.sub/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/datalayer.client.sub/.vscode/tasks.json +++ b/samples-python/datalayer.client.sub/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.client.sub/LICENSE b/samples-python/datalayer.client.sub/LICENSE deleted file mode 100644 index e2327431a..000000000 --- a/samples-python/datalayer.client.sub/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.client.sub/README.md b/samples-python/datalayer.client.sub/README.md index 708a2c652..a6bc58528 100644 --- a/samples-python/datalayer.client.sub/README.md +++ b/samples-python/datalayer.client.sub/README.md @@ -11,39 +11,20 @@ The app uses a single node and a multi node subscription. First the single node subscription is started. It will be stopped after a short period of time. -Then the multi node subscription is started. It will run until a connection break to the Data Layer is detected. In this case the app unsubscribes the multi node subscription and ends. The app is restarted automatically by snapd. +Then the multi node subscription is started. It will run until a connection break to the ctrlX Data Layer is detected. In this case the app unsubscribes the multi node subscription and ends. The app is restarted automatically by snapd. ## Implementation Description __main.py__ is the single module. It has following tasks: -* Create a Data Layer client connection -* Subscribe/unsubscribe a Data Layer single node subscription -* Subscribe/unsubscribe a Data Layer multi node subscription -* Close app on Data Layer client connection break +* Create a ctrlX Data Layer client connection +* Subscribe/unsubscribe a ctrlX Data Layer single node subscription +* Subscribe/unsubscribe a ctrlX Data Layer multi node subscription +* Close app on ctrlX Data Layer client connection break ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.client.sub/build-snap-amd64.sh b/samples-python/datalayer.client.sub/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.client.sub/build-snap-amd64.sh +++ b/samples-python/datalayer.client.sub/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client.sub/build-snap-arm64.sh b/samples-python/datalayer.client.sub/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.client.sub/build-snap-arm64.sh +++ b/samples-python/datalayer.client.sub/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client.sub/datalayerclient/app.py b/samples-python/datalayer.client.sub/datalayerclient/app.py index 1d8c63892..89d0f7bff 100644 --- a/samples-python/datalayer.client.sub/datalayerclient/app.py +++ b/samples-python/datalayer.client.sub/datalayerclient/app.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import typing from datetime import datetime @@ -31,6 +13,8 @@ def rncb(result: Result, items: typing.List[ctrlxdatalayer.subscription.NotifyItem], userdata: ctrlxdatalayer.clib.userData_c_void_p): + """rncb + """ now = datetime.now().time() print(now, "----------------------------------------------------------") @@ -59,7 +43,8 @@ def rncb(result: Result, items: typing.List[ctrlxdatalayer.subscription.NotifyIt def subscribe_single(client: Client, subscription_properties: Variant): - + """subscribe_single + """ print("subscribe_single() +++++++++++++++++++++++++++++++++++++++++++++++", flush=True) result, subscription = client.create_subscription_sync( @@ -79,6 +64,8 @@ def subscribe_single(client: Client, subscription_properties: Variant): def get_address_list(client: Client, addressBase: str): + """get_address_list + """ result, data = client.browse_sync(addressBase) with data: if result != Result.OK: @@ -95,7 +82,8 @@ def get_address_list(client: Client, addressBase: str): def subscribe_multi(client: Client, subscription_properties: Variant): - + """subscribe_multi + """ print("subscribe_multi() ++++++++++++++++++++++++++++++++++++++++++++++++", flush=True) addressBase = "framework/metrics/system/" diff --git a/samples-python/datalayer.client.sub/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.client.sub/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.client.sub/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.client.sub/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.client.sub/main.py b/samples-python/datalayer.client.sub/main.py index 000d19a2c..3858bb590 100644 --- a/samples-python/datalayer.client.sub/main.py +++ b/samples-python/datalayer.client.sub/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import sys @@ -38,7 +20,7 @@ print() print("=============================================================================") - print("Simple ctrlX Data Layer Client Snap in Python using Data Layer subscriptions.") + print("Simple ctrlX Data Layer Client Snap in Python using ctrlX Data Layer subscriptions.") print("Will be restarted by the snap system.") print("=============================================================================", flush=True) diff --git a/samples-python/datalayer.client.sub/setup.py b/samples-python/datalayer.client.sub/setup.py index e5791b248..9cc9fb683 100644 --- a/samples-python/datalayer.client.sub/setup.py +++ b/samples-python/datalayer.client.sub/setup.py @@ -1,11 +1,14 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name = 'sdk-py-client-sub', version='2.4.0', - description = 'This sample demonstrates how to use Data Layer subscriptions with Python', + description = 'This sample demonstrates how to use ctrlX Data Layer subscriptions with Python', author = 'SDK Team', install_requires = ['ctrlx-datalayer', 'ctrlx-fbs'], packages = ['datalayerclient', 'helper'], scripts = ['main.py'], - license = 'Copyright (c) 2021-2022 Bosch Rexroth AG, Licensed under MIT License' + license = 'MIT License' ) diff --git a/samples-python/datalayer.client.sub/snap/snapcraft.yaml b/samples-python/datalayer.client.sub/snap/snapcraft.yaml index 81da36865..ad66f8483 100644 --- a/samples-python/datalayer.client.sub/snap/snapcraft.yaml +++ b/samples-python/datalayer.client.sub/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-client-sub version: 2.4.0 -summary: Data Layer client subscription sample written in Python for ctrlX +summary: ctrlX Data Layer client subscription sample written in Python for ctrlX title: sdk-py-client-sub description: | - This sample demonstrates how to use Data Layer subscriptions with Python -base: core20 + This sample demonstrates how to use ctrlX Data Layer subscriptions with Python +base: core22 confinement: strict grade: stable diff --git a/samples-python/datalayer.client/.vscode/tasks.json b/samples-python/datalayer.client/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/datalayer.client/.vscode/tasks.json +++ b/samples-python/datalayer.client/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.client/LICENSE b/samples-python/datalayer.client/LICENSE deleted file mode 100644 index d1231b68e..000000000 --- a/samples-python/datalayer.client/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.client/README.md b/samples-python/datalayer.client/README.md index 35dc2a27f..e3e176b5d 100644 --- a/samples-python/datalayer.client/README.md +++ b/samples-python/datalayer.client/README.md @@ -2,40 +2,21 @@ ## Introduction -This python app runs Data Layer client operations like read, write and so on. It can be used as sample to implement own apps. +This python app runs ctrlX Data Layer client operations like read, write and so on. It can be used as sample to implement own apps. ## Function Description This Python app depends from the C++ sample samples-cpp/datalayer.provider.all-data. -It handles the Data Layer nodes created by the C++ sample. +It handles the ctrlX Data Layer nodes created by the C++ sample. ## Implementation Description -__main.py__ creates the Data Layer connection and and an instance of CallDataLayerClient. +__main.py__ creates the ctrlX Data Layer connection and and an instance of CallDataLayerClient. __app/call_datalayer_client.py__ contains the class CallDataLayerClient. This class runs all the data access activities. ___ ## License -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.client/app/call_datalayer_client.py b/samples-python/datalayer.client/app/call_datalayer_client.py index c0a41d4a4..91774f78c 100644 --- a/samples-python/datalayer.client/app/call_datalayer_client.py +++ b/samples-python/datalayer.client/app/call_datalayer_client.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import logging import time @@ -33,8 +15,12 @@ class CallDataLayerClient: + """CallDataLayerClient + """ def __init__(self, client: Client) -> None: + """__init__ + """ self.client = client self.waiting_for = "" logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', @@ -53,7 +39,8 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.client = None def run(self): - + """run + """ self.auth_token() self.ping() self.read() @@ -64,6 +51,8 @@ def run(self): self.metadata() def wait_for_async_callback(self, result: Result): + """wait_for_async_callback + """ if result != Result.OK: return @@ -81,13 +70,16 @@ def wait_for_async_callback(self, result: Result): logging.error("%s TIME OUT", self.waiting_for) def log_result(self, msg: str, result: Result): + """log_result + """ if result == Result.OK: logging.debug('%s --> %s', msg, result) return logging.error('%s failed with: %s', msg, result) def auth_token(self): - + """auth_token + """ logging.info("get_auth_token()") the_auth_token = self.client.get_auth_token() if the_auth_token is None: @@ -100,11 +92,14 @@ def auth_token(self): self.client.set_auth_token(the_auth_token) def ping_async_callback(self, result: Result, data: Variant, userdata: ctrlxdatalayer.clib.userData_c_void_p): + """ping_async_callback + """ self.waiting_for = None logging.info(">>>ping_async_callback: %s", result) def ping(self): - + """ping + """ self.waiting_for = "ping_async_callback" logging.info("ping_async()") result = self.client.ping_async(self.ping_async_callback, 105) @@ -116,11 +111,15 @@ def ping(self): self.log_result('ping_sync()', result) def read_async_callback(self, result: Result, data: Variant, userdata: ctrlxdatalayer.clib.userData_c_void_p): + """read_async_callback + """ self.waiting_for = None self.log_result(">>>read_async_callback(): ", result) self.print_data(">>>read_async_callback(): ", result, "", data) def read_sync(self, node: str): + """read_sync + """ addressBase = root_node + "/static/" address = addressBase + node @@ -132,7 +131,8 @@ def read_sync(self, node: str): self.print_data("read_async()", result, address, data) def print_data(self, msg: str, result: Result, address: str, data: Variant): - + """print_data + """ if result != Result.OK: return @@ -241,7 +241,8 @@ def print_data(self, msg: str, result: Result, address: str, data: Variant): print("UNHANDLED ---------", flush=True) def read(self): - + """read + """ addressBase = root_node + "/static/" address = addressBase + "bool8" @@ -301,11 +302,15 @@ def read(self): self.read_sync("array-of-uint64") def create_async_callback(self, result: Result, data: Variant, userdata: ctrlxdatalayer.clib.userData_c_void_p): + """create_async_callback + """ self.waiting_for = None logging.info(">>>create_async_callback(): %s %s %s", result, data, userdata) def create_async(self, path, node, data: Variant): + """create_async + """ address = path + node # Remove node so that create will succeed result = self.client.remove_sync(address) # Ignore error @@ -318,6 +323,8 @@ def create_async(self, path, node, data: Variant): self.wait_for_async_callback(result) def create_sync(self, path, node, data: Variant): + """create_sync + """ address = path + node # Remove node so that create will succeed result = self.client.remove_sync(address) # Ignore error @@ -328,6 +335,8 @@ def create_sync(self, path, node, data: Variant): self.log_result("create_sync() " + address, result) def create(self): + """create + """ with Variant() as data: addressBase = root_node + "/dynamic/_py/" @@ -416,11 +425,14 @@ def set_flatbuffers(self, data: bytearray) -> Result: self.create_sync(addressBase, "array-of-string", data) def remove_async_callback(self, result: Result, data: Variant, userdata: ctrlxdatalayer.clib.userData_c_void_p): + """remove_async_callback + """ self.waiting_for = None logging.info(">>>create_async_callback(): %s %s", result, userdata) def remove(self): - + """remove + """ with Variant() as data: addressBase = root_node + "/dynamic/_py/" @@ -443,12 +455,15 @@ def remove(self): self.wait_for_async_callback(result) def browse_async_callback(self, result: Result, data: Variant, userdata: ctrlxdatalayer.clib.userData_c_void_p): + """browse_async_callback + """ self.waiting_for = None logging.info(">>>browse_async_callback: %s %s %s", result, data.get_array_string(), userdata) def browse(self): - + """browse + """ logging.info("browse_sync() /") result, data = self.client.browse_sync("") with data: @@ -461,16 +476,22 @@ def browse(self): self.wait_for_async_callback(result) def write_async_callback(self, result: Result, data: Variant, userdata: ctrlxdatalayer.clib.userData_c_void_p): + """write_async_callback + """ self.waiting_for = None self.log_result(">>>write_async_callback:", result) def write_sync(self, addressBase: str, node: str, data: Variant): + """write_sync + """ address = addressBase + node logging.info("write_sync() %s", address) result, _ = self.client.write_sync(address, data) self.log_result("write_sync()", result) def write(self): + """write + """ with Variant() as data: addressBase = root_node + "/dynamic/" @@ -505,10 +526,12 @@ def write(self): data.set_int64(0x8000000000000001) self.write_sync(addressBase, "int64", data) - data.set_string("Changed by python Data Layer Client") + data.set_string("Changed by python ctrlX Data Layer Client") self.write_sync(addressBase, "string", data) def print_metadata(self, text: str, result: Result, data: Variant): + """print_metadata + """ if result != Result.OK: logging.error("%s failed with %s", text, result) return @@ -533,11 +556,14 @@ def print_metadata(self, text: str, result: Result, data: Variant): "metadata.DisplayFormat()", metadata.DisplayFormat(), flush=True) def metadata_async_callback(self, result: Result, data: Variant, userdata: ctrlxdatalayer.clib.userData_c_void_p): + """metadata_async_callback + """ self.waiting_for = None self.print_metadata(">>>metadata_async_callback", result, data) def metadata(self): - + """metadata + """ address = root_node + "/dynamic/bool8" self.waiting_for = "metadata_async_callback" logging.info("metadata_async() %s", address) diff --git a/samples-python/datalayer.client/build-snap-amd64.sh b/samples-python/datalayer.client/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.client/build-snap-amd64.sh +++ b/samples-python/datalayer.client/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client/build-snap-arm64.sh b/samples-python/datalayer.client/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.client/build-snap-arm64.sh +++ b/samples-python/datalayer.client/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.client/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.client/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.client/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.client/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.client/main.py b/samples-python/datalayer.client/main.py index 0bb641d09..476eb06f6 100644 --- a/samples-python/datalayer.client/main.py +++ b/samples-python/datalayer.client/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import faulthandler import signal @@ -36,6 +18,8 @@ def handler(signum, frame): + """handler + """ global close_app close_app = True # print('Here you go signum: ', signum, close_app, flush=True) @@ -67,7 +51,7 @@ def handler(signum, frame): print("========================================================================", flush=True) with ctrlxdatalayer.system.System("") as datalayer_system: - print("INFO Starting Data Layer system", flush=True) + print("INFO Starting ctrlX Data Layer system", flush=True) datalayer_system.start(False) datalayer_client, connection_string = get_client(datalayer_system) @@ -80,16 +64,16 @@ def handler(signum, frame): with datalayer_client: # datalayer_client is closed automatically when leaving with block - print("INFO Creating Python Data Layer Client instance", flush=True) + print("INFO Creating Python ctrlX Data Layer Client instance", flush=True) calldatalayerclient = CallDataLayerClient(datalayer_client) while datalayer_client.is_connected() and not close_app: calldatalayerclient.run() time.sleep(1.0) - print("ERROR Data Layer is NOT connected", flush=True) + print("ERROR ctrlX Data Layer is NOT connected", flush=True) - print("INFO Stopping Data Layer system") + print("INFO Stopping ctrlX Data Layer system") # Attention: Doesn't return if any provider or client instance is still runnning stop_ok = datalayer_system.stop(False) print("System Stop", stop_ok, flush=True) diff --git a/samples-python/datalayer.client/setup.py b/samples-python/datalayer.client/setup.py index a8f0f61ba..10be7582a 100644 --- a/samples-python/datalayer.client/setup.py +++ b/samples-python/datalayer.client/setup.py @@ -1,12 +1,15 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name = 'sdk-py-client', version = '2.4.0', - description = 'Data Layer client sample written in Python for ctrlX', + description = 'ctrlX Data Layer client sample written in Python for ctrlX', author = 'SDK Team', packages = ['app', 'helper'], install_requires=['ctrlx-datalayer', 'ctrlx-fbs'], scripts = ['main.py'], - license = 'Copyright (c) 2020-2022 Bosch Rexroth AG, Licensed under MIT License' + license = 'MIT License' ) diff --git a/samples-python/datalayer.client/snap/snapcraft.yaml b/samples-python/datalayer.client/snap/snapcraft.yaml index eba2dad12..fd44dfb7d 100644 --- a/samples-python/datalayer.client/snap/snapcraft.yaml +++ b/samples-python/datalayer.client/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-client version: 2.4.0 -summary: Data Layer client sample written in Python for ctrlX. +summary: ctrlX Data Layer client sample written in Python for ctrlX CORE. title: sdk-py-client description: | The sample demonstrates how to read values from ctrlX Data Layer tree and write out the values to console. -base: core20 +base: core22 confinement: strict grade: stable diff --git a/samples-python/datalayer.provider.all-data/.vscode/tasks.json b/samples-python/datalayer.provider.all-data/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/datalayer.provider.all-data/.vscode/tasks.json +++ b/samples-python/datalayer.provider.all-data/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.provider.all-data/LICENSE b/samples-python/datalayer.provider.all-data/LICENSE deleted file mode 100644 index d1231b68e..000000000 --- a/samples-python/datalayer.provider.all-data/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.provider.all-data/README.md b/samples-python/datalayer.provider.all-data/README.md index 5eeb1d9c4..a6c2a3ec3 100644 --- a/samples-python/datalayer.provider.all-data/README.md +++ b/samples-python/datalayer.provider.all-data/README.md @@ -14,32 +14,13 @@ The values of the nodes in the 'dynamic' subtree can be changed (written) by cli ## Implementation Description -__main.py__ starts the Data Layer system and the Data Layer provider. Furthermore two instances of the class ProviderNodeAllData are created. One instance is called for creating static (immutable) Data Layer nodes. The other instance is called for creating dynamic (changeable) Data Layer nodes. +__main.py__ starts the ctrlX Data Layer system and the ctrlX Data Layer provider. Furthermore two instances of the class ProviderNodeAllData are created. One instance is called for creating static (immutable) ctrlX Data Layer nodes. The other instance is called for creating dynamic (changeable) ctrlX Data Layer nodes. -The package __datalayerprovider__ contains the classes for data storage, configuration and Data Layer handling. +The package __datalayerprovider__ contains the classes for data storage, configuration and ctrlX Data Layer handling. ___ ## License -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.provider.all-data/alldataprovider/nodeManagerAllData.py b/samples-python/datalayer.provider.all-data/alldataprovider/nodeManagerAllData.py index 91cadf79a..022c6d6ae 100644 --- a/samples-python/datalayer.provider.all-data/alldataprovider/nodeManagerAllData.py +++ b/samples-python/datalayer.provider.all-data/alldataprovider/nodeManagerAllData.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import datetime @@ -29,19 +11,29 @@ class NodeManagerAllData: + """NodeManagerAllData + """ def __init__(self, provider: Provider, addressRoot: str): + """__init__ + """ self.provider = provider self.addressRoot = addressRoot self.nodes = [] def create_static_nodes(self): + """create_static_nodes + """ self.create_nodes("static/", False) def create_dynamic_nodes(self, ): + """create_dynamic_nodes + """ self.create_nodes("dynamic/", True) def create_nodes(self, address: str, dynamic: bool): + """create_nodes + """ addressBranch = self.addressRoot + address data = Variant() @@ -107,7 +99,7 @@ def create_nodes(self, address: str, dynamic: bool): data.set_datetime(datetime.datetime(2014, 7, 13)) self.create_single_node(addressBranch, "", "timestamp", "unit", "description", dynamic, data) - + # Flatbuffers - see samples-python/datalayer.provider/main.py data = Variant() @@ -172,11 +164,14 @@ def create_nodes(self, address: str, dynamic: bool): "unit", "description", dynamic, data) data = Variant() - data.set_array_datetime([datetime.datetime(1970, 1, 1), datetime.datetime(2014, 7, 13)]) + data.set_array_datetime( + [datetime.datetime(1970, 1, 1), datetime.datetime(2014, 7, 13)]) self.create_single_node(addressBranch, "", "array-of-timestamp", "unit", "description", dynamic, data) - def create_single_node(self, addressBranch: str, addressType : str, name: str, unit: str, description: str, dynamic: bool, data: Variant): + def create_single_node(self, addressBranch: str, addressType: str, name: str, unit: str, description: str, dynamic: bool, data: Variant): + """create_single_node + """ address = addressBranch + name print("Creating", address, flush=True) @@ -191,5 +186,7 @@ def create_single_node(self, addressBranch: str, addressType : str, name: str, u self.provider.register_node(address, node.providerNode) -def is_blank (myString): - return not (myString and myString.strip()) \ No newline at end of file +def is_blank(myString): + """is_blank + """ + return not (myString and myString.strip()) diff --git a/samples-python/datalayer.provider.all-data/alldataprovider/providerNodeAllData.py b/samples-python/datalayer.provider.all-data/alldataprovider/providerNodeAllData.py index 5c553dba6..eb1a851ba 100644 --- a/samples-python/datalayer.provider.all-data/alldataprovider/providerNodeAllData.py +++ b/samples-python/datalayer.provider.all-data/alldataprovider/providerNodeAllData.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import ctrlxdatalayer from comm.datalayer import NodeClass @@ -29,21 +11,24 @@ class ProviderNodeAllData: - - def __init__(self, - provider: Provider, - addressType: str, - address: str, - name : str, - unit : str, - description : str, - dynamic: bool, - data : Variant): - + """ProviderNodeAllData + """ + + def __init__(self, + provider: Provider, + addressType: str, + address: str, + name: str, + unit: str, + description: str, + dynamic: bool, + data: Variant): + """__init__ + """ self.provider = provider self.address = address - self.name= name + self.name = name self.dynamic = dynamic self.data = data @@ -63,32 +48,43 @@ def __init__(self, type_path=addressType) def __on_create(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): + """__on_create + """ # print("__on_create", address, flush=True) cb(Result.OK, None) def __on_remove(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): + """__on_remove + """ # Not implemented because no wildcard is registered print("__on_remove", address, flush=True) cb(Result.UNSUPPORTED, None) def __on_browse(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): + """__on_browse + """ # print("__on_browse", address, flush=True) cb(Result.OK, None) - + def __on_read(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): + """__on_read + """ # print("__on_read", address, flush=True) - this command slows the performance down new_data = self.data cb(Result.OK, new_data) def __on_write(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): - + """__on_write + """ if self.dynamic is False: - print("__on_write PERMISSION_DENIED", address, data.get_type(), flush=True) + print("__on_write PERMISSION_DENIED", + address, data.get_type(), flush=True) cb(Result.PERMISSION_DENIED, None) return if self.data.get_type() != data.get_type(): - print("__on_write TYPE_MISMATCH", address, data.get_type(), flush=True) + print("__on_write TYPE_MISMATCH", address, + data.get_type(), flush=True) cb(Result.TYPE_MISMATCH, None) return @@ -97,5 +93,7 @@ def __on_write(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: s cb(Result.OK, data) def __on_metadata(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): + """__on_metadata + """ # print("__on_metadata", address, flush=True) cb(Result.OK, self.metadata) diff --git a/samples-python/datalayer.provider.all-data/build-snap-amd64.sh b/samples-python/datalayer.provider.all-data/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.provider.all-data/build-snap-amd64.sh +++ b/samples-python/datalayer.provider.all-data/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.provider.all-data/build-snap-arm64.sh b/samples-python/datalayer.provider.all-data/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.provider.all-data/build-snap-arm64.sh +++ b/samples-python/datalayer.provider.all-data/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.provider.all-data/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.provider.all-data/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.provider.all-data/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.provider.all-data/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.provider.all-data/main.py b/samples-python/datalayer.provider.all-data/main.py index 8c7287766..5d29479c7 100644 --- a/samples-python/datalayer.provider.all-data/main.py +++ b/samples-python/datalayer.provider.all-data/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import signal import sys @@ -37,13 +19,16 @@ def handler(signum, frame): + """handler + """ global close_app close_app = True #print('Here you go signum: ', signum, close_app, flush=True) def main(): - + """main + """ signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGABRT, handler) @@ -70,7 +55,7 @@ def main(): while provider.is_connected() and not close_app: time.sleep(5.0) - print("ERROR: Data Layer provider is NOT connected", flush=True) + print("ERROR: ctrlX Data Layer provider is NOT connected", flush=True) provider.stop() diff --git a/samples-python/datalayer.provider.all-data/setup.py b/samples-python/datalayer.provider.all-data/setup.py index fb92a2cf1..ec224c5f0 100644 --- a/samples-python/datalayer.provider.all-data/setup.py +++ b/samples-python/datalayer.provider.all-data/setup.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name = 'sdk-py-provider-alldata', @@ -7,5 +10,5 @@ packages = ['alldataprovider', 'helper'], install_requires = ['ctrlx-datalayer', 'ctrlx-fbs'], scripts = ['main.py'], - license = 'Copyright (c) 2020-2022 Bosch Rexroth AG, Licensed under MIT License' + license = 'MIT License' ) diff --git a/samples-python/datalayer.provider.all-data/snap/snapcraft.yaml b/samples-python/datalayer.provider.all-data/snap/snapcraft.yaml index d973dbddb..f9487d5db 100644 --- a/samples-python/datalayer.provider.all-data/snap/snapcraft.yaml +++ b/samples-python/datalayer.provider.all-data/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-provider-alldata -version: 2.4.0 +version: 2.5.0 summary: ctrlX Data Layer provider sample in Python title: sdk-py-provider-alldata description: | ctrlX Data Layer provider in Python publishing nodes of all data types -base: core20 +base: core22 confinement: strict grade: stable diff --git a/samples-python/datalayer.provider/.vscode/tasks.json b/samples-python/datalayer.provider/.vscode/tasks.json index 32472b3af..b1c407f06 100644 --- a/samples-python/datalayer.provider/.vscode/tasks.json +++ b/samples-python/datalayer.provider/.vscode/tasks.json @@ -31,7 +31,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -44,11 +44,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -57,11 +57,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -70,7 +70,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -84,7 +84,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -118,7 +118,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -151,12 +151,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -167,7 +163,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -204,12 +200,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.provider/LICENSE b/samples-python/datalayer.provider/LICENSE deleted file mode 100644 index e2327431a..000000000 --- a/samples-python/datalayer.provider/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.provider/README.md b/samples-python/datalayer.provider/README.md index ac05cd96e..78d10d15c 100644 --- a/samples-python/datalayer.provider/README.md +++ b/samples-python/datalayer.provider/README.md @@ -1,12 +1,12 @@ # ctrlX Data Layer Provider -The app demonstrates how a Data Layer connection is established and a string and flatbuffers node are provided. +The app demonstrates how a ctrlX Data Layer connection is established and a string and flatbuffers node are provided. ## Function Description The app connects to the ctrlX Data Layer and provides a string and flatbuffers node . -If the Data Layer connection breaks the app will exit. After 10s it will be automatically restarted by snapd. +If the ctrlX Data Layer connection breaks the app will exit. After 10s it will be automatically restarted by snapd. ## Preparation @@ -40,38 +40,19 @@ It can also be called from Visual Studio Code: #### Metadata -* metadata.csv: Defines metadata for the provided Data Layer nodes. If changed compile it - see above. +* metadata.csv: Defines metadata for the provided ctrlX Data Layer nodes. If changed compile it - see above. * metadata.mddb: Compiled information of metadata.csv. ### Modules -* The module __main.py__ manages the Data Layer connection and the creation of the Data Layer nodes. -* The module __helper/ctrlx_datalayer_helper.py__ Provides methods to easily establish a Data Layer connection. -* The module __app/my_provider_node.py__ contains the class MyProviderNode with the callback function needed by the Data Layer. +* The module __main.py__ manages the ctrlX Data Layer connection and the creation of the ctrlX Data Layer nodes. +* The module __helper/ctrlx_datalayer_helper.py__ Provides methods to easily establish a ctrlX Data Layer connection. +* The module __app/my_provider_node.py__ contains the class MyProviderNode with the callback function needed by the ctrlX Data Layer. * The module __sample/schema/InertialValue.py__ is generated by flatc from sampleSchema.fbs. It is used to manage the flatbuffers data struct. ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.provider/app/my_provider_node.py b/samples-python/datalayer.provider/app/my_provider_node.py index 8b1279104..b65821308 100644 --- a/samples-python/datalayer.provider/app/my_provider_node.py +++ b/samples-python/datalayer.provider/app/my_provider_node.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import ctrlxdatalayer from ctrlxdatalayer.provider import Provider @@ -27,12 +9,15 @@ class MyProviderNode: + """MyProviderNode + """ def __init__(self, provider: Provider, address: str, initialValue: Variant): - + """__init__ + """ self.cbs = ProviderNodeCallbacks( self.__on_create, self.__on_remove, @@ -49,35 +34,54 @@ def __init__(self, self.data = initialValue def register_node(self): + """register_node + """ return self.provider.register_node(self.address, self.providerNode) def unregister_node(self): + """unregister_node + """ self.provider.unregister_node(self.address) def set_value(self, value: Variant): + """set_value + """ self.data = value def __on_create(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): - print("__on_create()", "address:", address, "userdata:", userdata, flush=True) + """__on_create + """ + print("__on_create()", "address:", address, + "userdata:", userdata, flush=True) cb(Result.OK, data) def __on_remove(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): - print("__on_remove()", "address:", address, "userdata:", userdata, flush=True) + """__on_remove + """ + print("__on_remove()", "address:", address, + "userdata:", userdata, flush=True) cb(Result.UNSUPPORTED, None) def __on_browse(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): - print("__on_browse()", "address:", address, "userdata:", userdata, flush=True) - new_data = Variant() - new_data.set_array_string([]) - cb(Result.OK, new_data) + """__on_browse + """ + print("__on_browse()", "address:", address, + "userdata:", userdata, flush=True) + with Variant() as new_data: + new_data.set_array_string([]) + cb(Result.OK, new_data) def __on_read(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): + """__on_read + """ print("__on_read()", "address:", address, "data:", self.data, "userdata:", userdata, flush=True) new_data = self.data cb(Result.OK, new_data) def __on_write(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, data: Variant, cb: NodeCallback): + """__on_write + """ print("__on_write()", "address:", address, "data:", data, "userdata:", userdata, flush=True) @@ -89,5 +93,7 @@ def __on_write(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: s cb(Result.OK, self.data) def __on_metadata(self, userdata: ctrlxdatalayer.clib.userData_c_void_p, address: str, cb: NodeCallback): + """__on_metadata + """ print("__on_metadata()", "address:", address, flush=True) cb(Result.FAILED, None) # Take metadata from metadata.mddb diff --git a/samples-python/datalayer.provider/build-snap-amd64.sh b/samples-python/datalayer.provider/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.provider/build-snap-amd64.sh +++ b/samples-python/datalayer.provider/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.provider/build-snap-arm64.sh b/samples-python/datalayer.provider/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.provider/build-snap-arm64.sh +++ b/samples-python/datalayer.provider/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.provider/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.provider/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.provider/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.provider/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.provider/main.py b/samples-python/datalayer.provider/main.py index 5559eb15b..1f6f941c2 100644 --- a/samples-python/datalayer.provider/main.py +++ b/samples-python/datalayer.provider/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os import sys @@ -51,11 +33,12 @@ def main(): - + """main + """ with ctrlxdatalayer.system.System("") as datalayer_system: datalayer_system.start(False) - # ip="10.0.2.2", ssl_port=8443: ctrlX virtual with port forwarding and default port mapping + # ip="10.0.2.2", ssl_port=8443: ctrlX COREvirtual with port forwarding and default port mapping provider, connection_string = get_provider(datalayer_system) if provider is None: print("ERROR Connecting", connection_string, "failed.", flush=True) @@ -65,7 +48,8 @@ def main(): result = provider.start() if result != Result.OK: - print("ERROR Starting Data Layer Provider failed with:", result, flush=True) + print("ERROR Starting ctrlX Data Layer Provider failed with:", + result, flush=True) return # Path to compiled files @@ -83,7 +67,8 @@ def main(): # Register Flatbuffer type # ATTENTION: Use same type as in csv file type_sampleSchema_inertialValue = "types/sampleSchema/inertialValue" - result = provider.register_type(type_sampleSchema_inertialValue, bfbs_path) + result = provider.register_type( + type_sampleSchema_inertialValue, bfbs_path) if result != Result.OK: print("WARNING Registering", type_sampleSchema_inertialValue, "failed with:", result, flush=True) @@ -102,7 +87,7 @@ def main(): while provider.is_connected(): time.sleep(1.0) # Seconds - print("ERROR Data Layer Provider is disconnected", flush=True) + print("ERROR ctrlX Data Layer Provider is disconnected", flush=True) provider_node_fbs.unregister_node() del provider_node_fbs @@ -110,11 +95,12 @@ def main(): provider_node_str.unregister_node() del provider_node_str - print("Unregistering", type_sampleSchema_inertialValue, end=" ", flush=True) + print("Unregistering", type_sampleSchema_inertialValue, + end=" ", flush=True) result = provider.unregister_type(type_sampleSchema_inertialValue) print(result, flush=True) - print("Stopping Data Layer provider:", end=" ", flush=True) + print("Stopping ctrlX Data Layer provider:", end=" ", flush=True) result = provider.stop() print(result, flush=True) @@ -124,7 +110,8 @@ def main(): def provide_fbs(provider: ctrlxdatalayer.provider, name: str): - + """provide_fbs + """ # Create `FlatBufferBuilder`instance. Initial Size 1024 bytes (grows automatically if needed) builder = flatbuffers.Builder(1024) @@ -144,7 +131,8 @@ def provide_fbs(provider: ctrlxdatalayer.provider, name: str): return # Create and register flatbuffers provider node - print("Creating flatbuffers provider node " + address_base + name, flush=True) + print("Creating flatbuffers provider node " + + address_base + name, flush=True) provider_node_fbs = MyProviderNode( provider, address_base + name, variantFlatbuffers) result = provider_node_fbs.register_node() @@ -156,6 +144,8 @@ def provide_fbs(provider: ctrlxdatalayer.provider, name: str): def provide_string(provider: ctrlxdatalayer.provider, name: str): + """provide_string + """ # Create and register simple string provider node print("Creating string provider node " + address_base + name, flush=True) variantString = Variant() diff --git a/samples-python/datalayer.provider/make-bfbs-mddb.sh b/samples-python/datalayer.provider/make-bfbs-mddb.sh index 893ed786c..552e7ce70 100644 --- a/samples-python/datalayer.provider/make-bfbs-mddb.sh +++ b/samples-python/datalayer.provider/make-bfbs-mddb.sh @@ -6,10 +6,10 @@ # Create compiled/sampleSchema.bfbs UNAME=$(uname -a) -UDIR=ubuntu20-gcc-x64 +UDIR=ubuntu22-gcc-x64 if grep -q "aarch64" <<<${UNAME} then - UDIR=ubuntu20-gcc-aarch64 + UDIR=ubuntu22-gcc-aarch64 fi mkdir -p bfbs diff --git a/samples-python/datalayer.provider/setup.py b/samples-python/datalayer.provider/setup.py index 19257eebc..aca1e8e80 100644 --- a/samples-python/datalayer.provider/setup.py +++ b/samples-python/datalayer.provider/setup.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup( @@ -10,5 +13,5 @@ # https://stackoverflow.com/questions/1612733/including-non-python-files-with-setup-py package_data={'./': ['sampleSchema.bfbs']}, scripts=['main.py'], - license='Copyright (c) 2020-2022 Bosch Rexroth AG, Licensed under MIT License' + license='MIT License' ) diff --git a/samples-python/datalayer.provider/snap/snapcraft.yaml b/samples-python/datalayer.provider/snap/snapcraft.yaml index 076dd7c4b..da9a4a6ea 100644 --- a/samples-python/datalayer.provider/snap/snapcraft.yaml +++ b/samples-python/datalayer.provider/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-provider version: 2.4.0 -summary: Data Layer provider sample written in Python for ctrlX +summary: ctrlX Data Layer provider sample written in Python for ctrlX title: sdk-py-provider description: | This sample shows how to provide data to the ctrlX Data Layer -base: core20 +base: core22 confinement: strict grade: stable diff --git a/samples-python/datalayer.remote.debug/.vscode/launch.json b/samples-python/datalayer.remote.debug/.vscode/launch.json index 4d986d34b..e1e516c86 100644 --- a/samples-python/datalayer.remote.debug/.vscode/launch.json +++ b/samples-python/datalayer.remote.debug/.vscode/launch.json @@ -14,12 +14,12 @@ "justMyCode": false }, { - "name": "Remote ctrlX CORE virtual - Port forwarding", + "name": "Remote ctrlX COREvirtual - Port forwarding", "type": "python", "request": "attach", // IP address where the remote debug server is listening for debug connections. // From the QEMU SDK VM (guest) 10.0.2.2 will address the host. - // From the host the ctrlX CORE virtual is connected via Port Forwarding. + // From the host the ctrlX COREvirtual is connected via Port Forwarding. "host": "10.0.2.2", // NOT change // Port where the remote debug server is listening for debug connections. "port": 15678, @@ -31,10 +31,10 @@ ] }, { - "name": "Remote ctrlX CORE virtual - Network adapter", + "name": "Remote ctrlX COREvirtual - Network adapter", "type": "python", "request": "attach", - "host": "192.168.1.1", // Do NOT change - this is the IP address of your ctrlX virtual + "host": "192.168.1.1", // Do NOT change - this is the IP address of your ctrlX COREvirtual "port": 15678, "pathMappings": [ { diff --git a/samples-python/datalayer.remote.debug/.vscode/tasks.json b/samples-python/datalayer.remote.debug/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/datalayer.remote.debug/.vscode/tasks.json +++ b/samples-python/datalayer.remote.debug/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/datalayer.remote.debug/LICENSE b/samples-python/datalayer.remote.debug/LICENSE deleted file mode 100644 index e2327431a..000000000 --- a/samples-python/datalayer.remote.debug/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/datalayer.remote.debug/README.md b/samples-python/datalayer.remote.debug/README.md index e941a9073..005dc491f 100644 --- a/samples-python/datalayer.remote.debug/README.md +++ b/samples-python/datalayer.remote.debug/README.md @@ -1,42 +1,59 @@ -# Sample Project datalayer.remote.debug +# Python sample for remote debugging -## Enabling Remote Debugging +This sample shows how remote debugging can be done with Python. -Remote debugging is enabled when the app is called with a command line parameter --debug-port=.... -If this parameter is missing the debugging functions are disabled, the app starts normally. +## Prerequisites -For debugging in the build environment this parameter doesn't matter. +If you use a ctrlX COREvirtual enable port forwarding of your remote debug port e.g. for port 15678 -## Python Package debugpy and Script debugging.py + 8022:22,8443:443,8740:11740,4840:4840,2069:2069,2070:2070__,15678:15678__ -We use the Python package __debugpy__ for remote debugging. +## Implementation -To simplify the usage of this package the debugging code is outsourced into the script debugging.py. +Remote debugging is enabled with by the package [__debugpy__](https://pypi.org/project/debugpy/) -To use debugpy and the script in your own Python projects too install the package into your project environment, copy the script debugging.py into your project folder and add the function calls into your code. +The script debug.py provides the function __debug.remote_debugging_wait_for_client()__ were debugpy is used. -___ +In main.py __debug.remote_debugging_wait_for_client()__ is called. -## License +Installed on a ctrlX CORE the service stops executing and waits until a remote debug client will attach. + +!!! important + Feel free to use the script debug.py in your own projects. + +## Build snap and install and start it + +For this job we recommend to use our shell script, here for a ctrlX ctrlX COREvirtual with port forwarding + + ../../scripts/build-upload-log-snap.sh -PF + +and here with network adapter + + ../../scripts/build-upload-log-snap.sh -NA + +For a bare metal ctrlX CORE you are able to provide all settings via command line, call this for help: -MIT License + ../../scripts/build-upload-log-snap.sh -help -Copyright (c) 2021-2022 Bosch Rexroth AG +When build and installation succeeded the snap is started as a service waiting for a remote debug client to connect. This print out should be shown e.g.: -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: + __Accepting remote debug client attaches to port 15678__ -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +!!! hint + In Visual Studio Code you can use menu item Terminal - Run Build Task... - Build upload snap ... + +## Start debugging wih Visual Studio Code + + +The file .vscode/launch.json contains launch configurations for remote debugging. + +We assume to debug the snap on a ctrlX ctrlX COREvirtual with port forwarding click the launch icon on the side bar and select configuration 'Remote ctrlX COREvirtual - Port forwarding'. + +The debugging client of Visual Studio Code will connect to the waiting server and debugging will start. + +___ + +## License -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/datalayer.remote.debug/build-snap-amd64.sh b/samples-python/datalayer.remote.debug/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/datalayer.remote.debug/build-snap-amd64.sh +++ b/samples-python/datalayer.remote.debug/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.remote.debug/build-snap-arm64.sh b/samples-python/datalayer.remote.debug/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/datalayer.remote.debug/build-snap-arm64.sh +++ b/samples-python/datalayer.remote.debug/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/datalayer.remote.debug/debug.py b/samples-python/datalayer.remote.debug/debug.py new file mode 100644 index 000000000..de2b5e8c6 --- /dev/null +++ b/samples-python/datalayer.remote.debug/debug.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT + +""" Script to use debug.py + +This module demonstrates the usage of debug.py. + +Usage: + Copy it into your project folder. + Insert the statement 'import debug' + Call debug.remote_debugging_wait_for_client(port=xxx) + +Were xxx is the port number where debug.py is listening e.g. 15678 +""" + +import debugpy + +def remote_debugging_wait_for_client(port: int): + """Waits until a remote debug client connects. + Detailed functions: + - Set the listen parameters: '0.0.0.0' means 'listen on all network interfaces' + - Start the debug server + - Wait until debug client connects. + + Parameters: + port (int): Port number for the debug connection + + Returns: + No value, the function blocks and returns if a debug client has been connected. + + """ + + print('Accepting remote debug client attaches to port', port, flush=True) + address = ('0.0.0.0', port) # Accept incomming calls from all network interfaces + debugpy.listen(address) + + debugpy.wait_for_client() + print('Debugger is attached!', flush=True) + + debugpy.breakpoint() + diff --git a/samples-python/datalayer.remote.debug/debugging.py b/samples-python/datalayer.remote.debug/debugging.py deleted file mode 100644 index a8703b4e6..000000000 --- a/samples-python/datalayer.remote.debug/debugging.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python3 - -# MIT License -# -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -import sys -import getopt - -import debugpy - -debugging_enabled = False - -def breakpoint(): - """Set a breakpoint. - This function can be used to set a fix breakpoint into the programming code. - The call is ineffective if debug is not activated (by providing a valid port number via command line parameter) - """ - if debugging_enabled: - debugpy.breakpoint() - - -def wait_for_client(port: int): - """Waits until a debug client connects. - Detailed functions: - - Set the listen parameters: '0.0.0.0' means listen on all network interfaces - - Start the debug server - - Wait until debug client connects. - - Parameters: - port (int): Port number for the debug connection - - Returns: - No value, the function blocks and returns if a debug client has been connected. - - """ - - address = ('0.0.0.0', port) # Accept incomming calls from all network interfaces - print('Accepting remote debug client attaches to port', port, flush=True) - debugpy.listen(address) - - debugpy.wait_for_client() - print('Debugger is attached!', flush=True) - - breakpoint() - -def init(): - """This function initializes remote debugging. It runs following tasks: - - Scan the command line parameter list for the option 'debug-port'. - If this option is not provided debugging will not be activated otherwise the global flag debugging_enabled is set to True. - If is debugging the wait_for_client function is called. - """ - - port = 0 - - try: - opts, args = getopt.gnu_getopt(sys.argv[1:], '', ['debug-port=']) - except getopt.GetoptError: - return - - for opt, arg in opts: - if opt in ("--debug-port"): - try: - port = int(arg) - except: - return - - if port == 0: - return - - global debugging_enabled - debugging_enabled = True - - wait_for_client(port) - diff --git a/samples-python/datalayer.remote.debug/helper/ctrlx_datalayer_helper.py b/samples-python/datalayer.remote.debug/helper/ctrlx_datalayer_helper.py index db4f6e01e..02a8cafb1 100644 --- a/samples-python/datalayer.remote.debug/helper/ctrlx_datalayer_helper.py +++ b/samples-python/datalayer.remote.debug/helper/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -31,7 +13,7 @@ Feel free to use it in your projects and to change it if necessary. For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/datalayer.remote.debug/main.py b/samples-python/datalayer.remote.debug/main.py index 40f226bd7..09123a7c9 100644 --- a/samples-python/datalayer.remote.debug/main.py +++ b/samples-python/datalayer.remote.debug/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import sys @@ -33,13 +15,40 @@ from ctrlxdatalayer.variant import Result, Variant from comm.datalayer import SubscriptionProperties -import debugging + +import debug from helper.ctrlx_datalayer_helper import get_client -def main(): +def remote_debugging_wait_for_client(port: int): + """Waits until a debug client connects. + Detailed functions: + - Set the listen parameters: '0.0.0.0' means listen on all network interfaces + - Start the debug server + - Wait until debug client connects. + + Parameters: + port (int): Port number for the debug connection + + Returns: + No value, the function blocks and returns if a debug client has been connected. + + """ + + print('Accepting remote debug client attaches to port', port, flush=True) + address = ('0.0.0.0', port) # Accept incomming calls from all network interfaces + debugpy.listen(address) + + debugpy.wait_for_client() + print('Debugger is attached!', flush=True) + + debugpy.breakpoint() + - debugging.breakpoint() + +def main(): + """main + """ print() print("========================================================================") @@ -56,26 +65,13 @@ def main(): with client: # Define the subscription properties by using Flatbuffers class SubscriptionProperties - builder = flatbuffers.Builder(1024) - id = builder.CreateString("sdk-py-remote-debug") - SubscriptionProperties.SubscriptionPropertiesStart(builder) - SubscriptionProperties.SubscriptionPropertiesAddId(builder, id) - SubscriptionProperties.SubscriptionPropertiesAddKeepaliveInterval( - builder, 10000) - SubscriptionProperties.SubscriptionPropertiesAddPublishInterval( - builder, 1000) - SubscriptionProperties.SubscriptionPropertiesAddErrorInterval( - builder, 10000) - properties = SubscriptionProperties.SubscriptionPropertiesEnd( - builder) - builder.Finish(properties) - sub_prop = Variant() - sub_prop.set_flatbuffers(builder.Output()) + sub_prop = __set_sub_prop() # Create subscription print("INFO Creating subscription", flush=True) result, sub = client.create_subscription_sync( sub_prop, cb_subscription_sync) + sub_prop.close() if result is not Result.OK: print("ERROR Creating subscription failed:", result, flush=True) @@ -97,16 +93,38 @@ def main(): time.sleep(5.0) - print("ERROR Data Layer connection", flush=True) + print("ERROR ctrlX Data Layer connection", flush=True) print("INFO Close subscription", flush=True) sub.close() - print("INFO Stopping Data Layer system", flush=True) + print("INFO Stopping ctrlX Data Layer system", flush=True) datalayer_system.stop(True) +def __set_sub_prop(): + """__set_sub_prop + """ + builder = flatbuffers.Builder(1024) + id = builder.CreateString("sdk-py-remote-debug") + SubscriptionProperties.SubscriptionPropertiesStart(builder) + SubscriptionProperties.SubscriptionPropertiesAddId(builder, id) + SubscriptionProperties.SubscriptionPropertiesAddKeepaliveInterval( + builder, 10000) + SubscriptionProperties.SubscriptionPropertiesAddPublishInterval( + builder, 1000) + SubscriptionProperties.SubscriptionPropertiesAddErrorInterval( + builder, 10000) + properties = SubscriptionProperties.SubscriptionPropertiesEnd( + builder) + builder.Finish(properties) + sub_prop = Variant() + sub_prop.set_flatbuffers(builder.Output()) + return sub_prop + # Response notify callback function def cb_subscription_sync(result: Result, items: List[ctrlxdatalayer.subscription.NotifyItem], userdata): + """cb_subscription_sync + """ if result is not Result.OK: print("ERROR notify subscription:", result, flush=True) return @@ -121,7 +139,8 @@ def cb_subscription_sync(result: Result, items: List[ctrlxdatalayer.subscription if __name__ == '__main__': - print('Number of arguments:', len(sys.argv), 'arguments.') - print('Argument List:', str(sys.argv), flush=True) - debugging.init() + # Wait for remote debug client + debug.remote_debugging_wait_for_client(port=15678) + + # Run function main() diff --git a/samples-python/datalayer.remote.debug/setup.py b/samples-python/datalayer.remote.debug/setup.py index 1d9fdf3c9..2668f19ab 100644 --- a/samples-python/datalayer.remote.debug/setup.py +++ b/samples-python/datalayer.remote.debug/setup.py @@ -1,11 +1,15 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT + from setuptools import setup setup(name = 'sdk-py-remote-debug', - version = '2.4.0', - description = 'Data Layer client in Python, enables remote debugging on a ctrlX', + version = '3.0.0', + description = 'ctrlX Data Layer client in Python, enables remote debugging on a ctrlX', author = 'SDK Team', install_requires=['debugpy', 'ctrlx-datalayer', 'ctrlx-fbs'], packages = ['helper'], - scripts = ['main.py', 'debugging.py'], - license = 'Copyright (c) 2021-2022 Bosch Rexroth AG, Licensed under MIT License' + scripts = ['main.py', 'debug.py'], + license = 'MIT License' ) diff --git a/samples-python/datalayer.remote.debug/snap/snapcraft.yaml b/samples-python/datalayer.remote.debug/snap/snapcraft.yaml index e9332b74d..88ee85056 100644 --- a/samples-python/datalayer.remote.debug/snap/snapcraft.yaml +++ b/samples-python/datalayer.remote.debug/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-remote-debug -version: 2.4.0 -summary: Data Layer client sample written in Python enables remote debugging on a ctrlX +version: 3.0.0 +summary: ctrlX Data Layer client demonstates remote debugging on a ctrlX title: sdk-py-remote-debug description: | The sample demonstrates how remote debugging on a ctrlX can be done. -base: core20 +base: core22 confinement: strict grade: stable diff --git a/samples-python/logbook/.vscode/tasks.json b/samples-python/logbook/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/logbook/.vscode/tasks.json +++ b/samples-python/logbook/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/logbook/LICENSE b/samples-python/logbook/LICENSE deleted file mode 100644 index 3ecaa04c3..000000000 --- a/samples-python/logbook/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/logbook/README.md b/samples-python/logbook/README.md index 6080011a1..c91ef1390 100644 --- a/samples-python/logbook/README.md +++ b/samples-python/logbook/README.md @@ -2,7 +2,7 @@ ## Introduction -This python app showes how to log with different log levels into the logbook of the ctrlX. +This python app showes how to log with different log levels into the logbook of the ctrlX CORE. ## Function Description @@ -18,24 +18,5 @@ ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/logbook/build-snap-amd64.sh b/samples-python/logbook/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/logbook/build-snap-amd64.sh +++ b/samples-python/logbook/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/logbook/build-snap-arm64.sh b/samples-python/logbook/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/logbook/build-snap-arm64.sh +++ b/samples-python/logbook/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/logbook/logbook/app.py b/samples-python/logbook/logbook/app.py index 29e2d0e22..12bed4536 100644 --- a/samples-python/logbook/logbook/app.py +++ b/samples-python/logbook/logbook/app.py @@ -1,34 +1,18 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import logging -from systemd.journal import JournaldLogHandler +from cysystemd import journal def run(): + """run + """ print("Simple snap in Python using logging with different log levels", flush=True) log = logging.getLogger() log.setLevel(logging.DEBUG) - log.addHandler(JournaldLogHandler()) + log.addHandler(journal.JournaldLogHandler()) log.exception("I am an exception message") log.critical("I am a critical message") diff --git a/samples-python/logbook/main.py b/samples-python/logbook/main.py index 49ed66091..113f65101 100644 --- a/samples-python/logbook/main.py +++ b/samples-python/logbook/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import logbook.app diff --git a/samples-python/logbook/requirements.txt b/samples-python/logbook/requirements.txt index 151465818..e2d643157 100644 --- a/samples-python/logbook/requirements.txt +++ b/samples-python/logbook/requirements.txt @@ -1 +1 @@ -systemd \ No newline at end of file +cysystemd \ No newline at end of file diff --git a/samples-python/logbook/setup.py b/samples-python/logbook/setup.py index 99667bdd0..bbfc951ce 100644 --- a/samples-python/logbook/setup.py +++ b/samples-python/logbook/setup.py @@ -1,12 +1,15 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name = 'sdk-py-logbook', - version='2.3.0', + version='2.4.0', description = 'Logbook sample written in Python for ctrlX', author = 'SDK Team', packages = ['logbook'], - install_requires=['systemd'], + install_requires=['cysystemd'], scripts = ['main.py'], - license = 'Copyright (c) 2021 Bosch Rexroth AG, Licensed under MIT License' + license = 'MIT License' ) diff --git a/samples-python/logbook/snap/snapcraft.yaml b/samples-python/logbook/snap/snapcraft.yaml index a93d32e78..c755af260 100644 --- a/samples-python/logbook/snap/snapcraft.yaml +++ b/samples-python/logbook/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-logbook -version: 2.3.0 +version: 2.4.0 summary: Logbook sample written in Python for ctrlX title: sdk-py-logbook description: | This sample shows how to log with different loglevels -base: core20 +base: core22 confinement: strict grade: stable @@ -23,6 +23,9 @@ parts: logbook: plugin: python source: . + stage-packages: + - libsystemd-dev + plugs: datalayer: diff --git a/samples-python/webserver/.vscode/tasks.json b/samples-python/webserver/.vscode/tasks.json index 6fe5bc49b..1234c0ab8 100644 --- a/samples-python/webserver/.vscode/tasks.json +++ b/samples-python/webserver/.vscode/tasks.json @@ -22,7 +22,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -35,11 +35,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Network Adapter", + "label": "Build upload snap - ctrlX COREvirtual Network Adapter", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -48,11 +48,11 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { - "label": "Build upload snap - ctrlX CORE virtual Port Forwarding", + "label": "Build upload snap - ctrlX COREvirtual Port Forwarding", "type": "shell", "command": "../../scripts/build-upload-log-snap.sh", "args": [ @@ -61,7 +61,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -75,7 +75,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { @@ -109,7 +109,7 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, ], @@ -142,12 +142,8 @@ }, { "id": "SSLPort", - "type": "pickString", + "type": "promptString", "description": "HTTPS (SSL) port number", - "options": [ - "443", - "8443" - ], "default": "443" }, { @@ -158,7 +154,7 @@ "y", "n" ], - "default": "n" + "default": "y" }, { "id": "SSLUser", @@ -195,12 +191,8 @@ }, { "id": "SSHPort", - "type": "pickString", + "type": "promptString", "description": "SSH port number", - "options": [ - "22", - "8022" - ], "default": "22" }, { diff --git a/samples-python/webserver/LICENSE b/samples-python/webserver/LICENSE deleted file mode 100644 index 57874ee50..000000000 --- a/samples-python/webserver/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2021 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/samples-python/webserver/README.md b/samples-python/webserver/README.md index 0e6da08ea..191268963 100644 --- a/samples-python/webserver/README.md +++ b/samples-python/webserver/README.md @@ -2,18 +2,18 @@ ## Introduction -This python app deploys a simple webserver including Data Layer connection and user permissions with web interface accessible from ctrlX webpage. +This python app deploys a simple webserver including ctrlX Data Layer connection and user permissions with web interface accessible from ctrlX webpage. ## Function Description -The app runs a simple webserver with reverse proxy and Data Layer access, setup user permissions through package-manifest and token authentification. +The app runs a simple webserver with reverse proxy and ctrlX Data Layer access, setup user permissions through package-manifest and token authentification. -Once the installation of the snap was finished, you can access to the provided webpage through the sidebar or overview menu of ctrlX CORE webpage. +Once the installation of the snap was finished, you can access to the provided webpage through the sidebar or overview menu of the ctrlX CORE webpage. ![ctrlX Integration](docs/images/ctrlx_integration.png) -The Python-Webpage allows you to read and write at the Data Layer (depends on permissions of the current user) and shows permissions of the current user. +The Python-Webpage allows you to read and write at the ctrlX Data Layer (depends on permissions of the current user) and shows permissions of the current user. ![Python Webserver](docs/images/python_webserver.png) @@ -30,8 +30,8 @@ The app has these modules: * __main.py__ connects to the ctrlX Data Layer and starts the web server. In snap environment an Unix socket connection is established otherwise a TCP/IP connection. * __app/__ -* __datalayer.py__ handles the Data Layer node data access. -* __ctrlx_datalayer_helper.py__ handles the Data Layer client connection. +* __datalayer.py__ handles the ctrlX Data Layer node data access. +* __ctrlx_datalayer_helper.py__ handles the ctrlX Data Layer client connection. * __web/__ * __unix_socket_server.py *)__ Web server class (wrapper) to use unix sockets instead of TCP/IP @@ -47,24 +47,5 @@ ___ ## License -MIT License - -Copyright (c) 2020-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-python/webserver/app/ctrlx_datalayer_helper.py b/samples-python/webserver/app/ctrlx_datalayer_helper.py index db4f6e01e..0377a58c1 100644 --- a/samples-python/webserver/app/ctrlx_datalayer_helper.py +++ b/samples-python/webserver/app/ctrlx_datalayer_helper.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2021-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os @@ -30,8 +12,8 @@ Feel free to use it in your projects and to change it if necessary. -For ease of use, the default values for IP address, user, password and SSL port are chosen to match the settings of a -newly created ctrlX CORE device: +For ease of use, the default values for IP address, user, password and SSL port are choosen to match the settings of a +newly created ctrlX CORE: ip="192.168.1.1" user="boschrexroth" @@ -41,17 +23,17 @@ If these values do not suit your use case, explicitly pass the parameters that require different values. Here some examples: -1. ctrlX CORE or ctrlX CORE virtual with another IP address, user and password: +1. ctrlX CORE or ctrlX COREvirtual with another IP address, user and password: client, client_connection = get_client(system, ip="192.168.1.100", user="admin", password="-$_U/{X$aG}Z3/e<") -2. ctrlX CORE virtual with port forwarding running on the same host as the app build environment (QEMU VM): +2. ctrlX COREvirtual with port forwarding running on the same host as the app build environment (QEMU VM): client, client_connection = get_client(system, ip="10.0.2.2", ssl_port=8443) Remarks: 10.0.2.2 is the IP address of the host from the point of view of the app build environment (QEMU VM). - 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX CORE virtual + 8443 is the host port which is forwarded to the SSL port (=433) of the ctrlX COREvirtual IMPORTANT: @@ -71,10 +53,10 @@ def get_connection_string( ssl_port=443): """ Combines a ctrlX Datalayer connection string. - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX CORE virtual. @returns connection_string The connection string: "ipc://" for running in snap environment, "tcp://..." for running in environment. """ @@ -84,7 +66,7 @@ def get_connection_string( # Client connection port 2069 resp. Provider connection port 2070 are obsolete connection_string = "tcp://"+user+":"+password+"@"+ip - if (ssl_port == 443): + if ssl_port == 443: return connection_string return connection_string+"?sslport=" + str(ssl_port) @@ -98,10 +80,10 @@ def get_client(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer client instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (client, connection_string) @return The ctrlxdatalayer.client.Client instance or None if failed @return The connection string or None if failed @@ -125,10 +107,10 @@ def get_provider(system: ctrlxdatalayer.system.System, """ Creates a ctrlX Datalayer provider instance. @param[in] system A ctrlxdatalayer.system.System instance - @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX CORE virtual with port forwarding. + @param[in] ip IP address of the ctrlX CORE. Use "10.0.2.2" to connect to a ctrlX COREvirtual with port forwarding. @param[in] user Name of the user. @param[in] password Password of the user. - @param[in] ssl_port Port number for a SSL connection. ctrlX CORE virtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX virtual. + @param[in] ssl_port Port number for a SSL connection. ctrlX COREvirtual with port forwarding: Use the host port (default 8443) forwarded to port 22 of the ctrlX COREvirtual. @returns tuple (provider, connection_string) @return , a ctrlxdatalayer.provider.Provider instance or None if failed, @return , a connection string or None if failed diff --git a/samples-python/webserver/app/datalayer.py b/samples-python/webserver/app/datalayer.py index a3eff2bcc..3c701e66a 100644 --- a/samples-python/webserver/app/datalayer.py +++ b/samples-python/webserver/app/datalayer.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT from comm.datalayer import Metadata @@ -28,13 +10,17 @@ from app.ctrlx_datalayer_helper import get_client + class DataLayer: + """DataLayer + """ def __init__(self, ip="192.168.1.1", user="boschrexroth", password="boschrexroth", ssl_port=443) -> None: - + """__init__ + """ self.system = ctrlxdatalayer.system.System("") self.client = None @@ -52,15 +38,34 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.client = None def start(self): + """ + start + """ self.system.start(False) def stop(self): + """ + stop + """ self.system.stop(False) def connect_client(self, ip="192.168.1.1", user="boschrexroth", password="boschrexroth", https_port=443): + """ + client connect + + Args: + ip (str, optional): device address. Defaults to "192.168.1.1". + user (str, optional): username. Defaults to "boschrexroth". + password (str, optional): password. Defaults to "boschrexroth". + https_port (int, optional): port. Defaults to 443. + + Returns: + client: client + connection_string: connection string + """ self.client, connection_string = get_client( self.system, ip, user, password, https_port) @@ -68,22 +73,48 @@ def connect_client(self, ip="192.168.1.1", return self.client, connection_string def read_node(self, address: str): + """ + read node + + Args: + address (str): address of the node + Returns: + see get_value + """ result, value = self.get_value(address) return result.name, value def write_node(self, address: str, value: str): + """ + write node + Args: + address (str): address of node + value (str): value + Returns: + Result: result + """ result = self.set_value(address, value) return result.name def get_value(self, address): + """ + get value + + Args: + address (_type_): address of the node + + Returns: + Result: result + Variant: data + """ print("Reading", address, flush=True) result, data = self.client.read_sync(address) if result != Result.OK: - print("ERROR Reading Data Layer failed with:", result, flush=True) + print("ERROR Reading ctrlX Data Layer failed with:", result, flush=True) return result, data with data: @@ -170,14 +201,22 @@ def get_value(self, address): return Result.UNSUPPORTED, None def getFlatbuffersAsJsonStr(self, addr: str, fbs_value: Variant): + """getFlatbuffersAsJsonStr + Args: + addr (str): address of the node + fbs_value (Variant): fbs value + + Returns: + Result: result + """ result, fbs_metadata = self.client.metadata_sync(addr) if result != Result.OK: return result, "" metadata_root = Metadata.Metadata.GetRootAsMetadata( fbs_metadata.get_flatbuffers()) - if metadata_root == None: + if metadata_root is None: return result, "" address_read_type = "" @@ -206,7 +245,15 @@ def getFlatbuffersAsJsonStr(self, addr: str, fbs_value: Variant): return Result.OK, jsonVariant.get_string() def set_value(self, address, value): + """set_value + Args: + address (_type_): address of node + value (_type_): value + + Returns: + Result: result + """ print("Checking VarianType of", address, flush=True) # Read first to check VariantType @@ -280,4 +327,3 @@ def set_value(self, address, value): print("ERROR Unsupported Variant Type:", variant_type, flush=True) return Result.UNSUPPORTED - diff --git a/samples-python/webserver/build-snap-amd64.sh b/samples-python/webserver/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-python/webserver/build-snap-amd64.sh +++ b/samples-python/webserver/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-python/webserver/build-snap-arm64.sh b/samples-python/webserver/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-python/webserver/build-snap-arm64.sh +++ b/samples-python/webserver/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-python/webserver/configs/package-assets/rexroth-python-webserver.package-manifest.json b/samples-python/webserver/configs/package-assets/rexroth-python-webserver.package-manifest.json index 46314e4ce..284f37623 100644 --- a/samples-python/webserver/configs/package-assets/rexroth-python-webserver.package-manifest.json +++ b/samples-python/webserver/configs/package-assets/rexroth-python-webserver.package-manifest.json @@ -1,11 +1,12 @@ { + "$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.schema.json", "version": "1.0.0", "id": "rexroth-python-webserver", "scopes-declaration": [ { "identifier": "rexroth-python-webserver.web", "name": "Python-Webserver", - "description": "Data Layer access permissions over webpage", + "description": "ctrlX Data Layer access permissions over webpage", "scopes": [ { "identifier": "rexroth-python-webserver.web.r", diff --git a/samples-python/webserver/main.py b/samples-python/webserver/main.py index 5e0fee5e6..ea1aba8c8 100644 --- a/samples-python/webserver/main.py +++ b/samples-python/webserver/main.py @@ -1,26 +1,8 @@ #!/usr/bin/env python3 -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2021 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os import sys @@ -36,13 +18,16 @@ httpServerPort = 12345 token = 'eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjAxNDg3NzQsImlhdCI6MTY2MDExOTk3NCwiaWQiOiIxMDAwIiwibmFtZSI6ImJvc2NocmV4cm90aCIsIm5vbmNlIjoiMGU0NTVhODMtMThlOC00YjY2LTllMWUtYTE0NWM2ZWIzZWQzIiwicGxjaGFuZGxlIjowLCJyZW1vdGVhdXRoIjoiIiwic2NvcGUiOlsicmV4cm90aC1kZXZpY2UuYWxsLnJ3eCJdfQ.VqCCRh2ga1Ujn5C_vBAf7dZHXNr6gY0Aqvrwu39_6L9d7fWBYXr-MmqdYxGB85fHBhs56MFrCacYjN5SbctqSyH1LTeXLKAdP4Etx8V7B2QB_5XZdVCLqIwYOAU8Gdzv' -def main(): +def main(): + """main + """ web.request_handler.data_layer = app.datalayer.DataLayer() web.request_handler.data_layer.start() - client, connection_string = web.request_handler.data_layer.connect_client(ip="10.0.2.2", https_port=8443) - if client == None: + client, connection_string = web.request_handler.data_layer.connect_client( + ip="10.0.2.2", https_port=8443) + if client is None: print("ERROR Could not connect", connection_string, flush=True) return @@ -57,14 +42,16 @@ def main(): def thread_start(): - + """thread_start + """ # If running with a snap (on a ctrlX) start UNIX socket # If running as app in an app builder envorinemtn start a TCP server run_webserver_unixsock() if 'SNAP' in os.environ else run_webserver_tcp() def run_webserver_tcp(): - + """run_webserver_tcp + """ with http.server.HTTPServer(('', httpServerPort), web.request_handler.RequestHandler) as http_server: print('TCP/IP server started - listening on 0.0.0.0:', httpServerPort) @@ -82,7 +69,8 @@ def run_webserver_tcp(): def run_webserver_unixsock(): - + """run_webserver_unixsock + """ sock_dir = os.getenv('SNAP_DATA') + '/package-run/sdk-py-webserver/' if not os.path.exists(sock_dir): os.makedirs(sock_dir) diff --git a/samples-python/webserver/requirements.txt b/samples-python/webserver/requirements.txt index 445a41335..e7542c1e1 100644 --- a/samples-python/webserver/requirements.txt +++ b/samples-python/webserver/requirements.txt @@ -2,4 +2,4 @@ PyJWT autopep8 ctrlx-datalayer ctrlx-fbs -systemd \ No newline at end of file +cysystemd \ No newline at end of file diff --git a/samples-python/webserver/setup.py b/samples-python/webserver/setup.py index 2d84a67a1..f929429f8 100644 --- a/samples-python/webserver/setup.py +++ b/samples-python/webserver/setup.py @@ -1,11 +1,14 @@ +# SPDX-FileCopyrightText: Bosch Rexroth AG +# +# SPDX-License-Identifier: MIT from setuptools import setup setup(name='sdk-py-webserver', version='2.3.0', description='Webserver Sample written in Python for ctrlX', author='SDK Team', - install_requires=['systemd','PyJWT', 'ctrlx-datalayer', 'ctrlx-fbs'], + install_requires=['cysystemd','PyJWT', 'ctrlx-datalayer', 'ctrlx-fbs'], scripts=['main.py'], packages=['app', 'web'], - license='Copyright (c) 2020-2022 Bosch Rexroth AG, Licensed under MIT License' + license='MIT License' ) diff --git a/samples-python/webserver/snap/snapcraft.yaml b/samples-python/webserver/snap/snapcraft.yaml index c4ee85ad4..baa007763 100644 --- a/samples-python/webserver/snap/snapcraft.yaml +++ b/samples-python/webserver/snap/snapcraft.yaml @@ -1,10 +1,10 @@ name: sdk-py-webserver -version: 2.4.0 +version: 2.5.0 summary: Webserver Sample written in Python for ctrlX title: sdk-py-webserver description: | This sample shows how to create a webserver app in ctrlX -base: core20 +base: core22 confinement: strict grade: stable @@ -30,6 +30,7 @@ parts: stage-packages: - libzmq5 - ctrlx-datalayer + - libsystemd-dev configs: plugin: dump diff --git a/samples-python/webserver/web/request_handler.py b/samples-python/webserver/web/request_handler.py index 5ad0fc1fa..8e39a960a 100644 --- a/samples-python/webserver/web/request_handler.py +++ b/samples-python/webserver/web/request_handler.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import os import traceback @@ -30,15 +12,23 @@ from urllib.parse import unquote, parse_qs, urlparse from json import dumps, loads -import app.datalayer +import app.datalayer + +data_layer: app.datalayer.DataLayer -data_layer : app.datalayer.DataLayer class RequestHandler(http.server.BaseHTTPRequestHandler): + """RequestHandler + + Args: + http (BaseHTTPRequestHandler): request handler + + """ # Form parameters saved server side # "datalayer/subscriptions/settings" - readPath = "datalayer/subscriptions/settings" # "framework/metrics/system/cpu-utilisation-percent" + # "framework/metrics/system/cpu-utilisation-percent" + readPath = "datalayer/subscriptions/settings" readValue = "" readResult = "" writePath = "sdk-py-provider-alldata/dynamic/int64" @@ -46,9 +36,20 @@ class RequestHandler(http.server.BaseHTTPRequestHandler): writeResult = "" def do_HEAD(self): + """do_HEAD + """ return def get_www_file_path(self, relative_path): + """def get_www_file_path(self, relative_path): + + + Args: + relative_path (string): relative path + + Returns: + str: result path + """ # relative_path: 'www/xxx' or '/python-webserver/stylesheet.css' if len(relative_path) <= 0: @@ -67,12 +68,20 @@ def get_www_file_path(self, relative_path): return result_path def send_response_and_header(self, response, content_type): + """send_response_and_header + + Args: + response (Response): Response + content_type (str): content type + """ self.send_response(response) self.send_header('Content-type', content_type) self.end_headers() def send_file_response(self, content_type, rel_path=""): + """send_file_response + """ path = self.get_www_file_path(rel_path) try: @@ -85,7 +94,11 @@ def send_file_response(self, content_type, rel_path=""): self.send_response_and_header(404, content_type) def send_html_file_response(self, rel_path=""): + """send_html_file_response + Args: + rel_path (str, optional): path. Defaults to "". + """ path = self.get_www_file_path(rel_path) content_type = 'text/html' @@ -99,6 +112,8 @@ def send_html_file_response(self, rel_path=""): self.send_response_and_header(404, content_type) def do_GET(self): + """do_GET + """ # GET Requests from client print("GET", self.path, flush=True) @@ -191,7 +206,8 @@ def do_GET(self): self.send_response(404) def do_POST(self): - + """do_POST + """ # Get the size of data content_length = int(self.headers['Content-Length']) content = self.rfile.read(content_length).decode("utf-8") @@ -207,7 +223,7 @@ def do_POST(self): if 'node' in data: RequestHandler.readPath = data['node'][0] - # Data Layer access + # ctrlX Data Layer access RequestHandler.readResult, RequestHandler.readValue = data_layer.read_node( RequestHandler.readPath) @@ -221,7 +237,7 @@ def do_POST(self): RequestHandler.writePath = data['node'][0] RequestHandler.writeValue = data['value'][0] - # Data Layer access + # ctrlX Data Layer access RequestHandler.writeResult = data_layer.write_node( RequestHandler.writePath, RequestHandler.writeValue) diff --git a/samples-python/webserver/web/unix_socket_server.py b/samples-python/webserver/web/unix_socket_server.py index a6017796e..84785e6ac 100644 --- a/samples-python/webserver/web/unix_socket_server.py +++ b/samples-python/webserver/web/unix_socket_server.py @@ -1,25 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - +# SPDX-License-Identifier: MIT # Because http.server lib is designed for tcp, we need to write our own class to use unix sockets @@ -28,7 +9,17 @@ class UnixSocketServer(UnixStreamServer): + """UnixSocketServer + + Args: + UnixStreamServer (UnixStreamServer): socket server + """ def get_request(self): + """get_request + + Returns: + Request: request + """ request, _ = super().get_request() return (request, ["local", 0]) diff --git a/samples-python/webserver/web/web_token.py b/samples-python/webserver/web/web_token.py index 41c2c11cc..2d7aa76ad 100644 --- a/samples-python/webserver/web/web_token.py +++ b/samples-python/webserver/web/web_token.py @@ -1,24 +1,6 @@ -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2020-2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT import jwt import logging @@ -27,7 +9,13 @@ def check_permissions(token: str, scopes_list): + """def check_permissions(token: str, scopes_list): + + Args: + token (str): token + scopes_list (list): scope list + """ try: token_decoded = jwt.decode(token, options={"verify_signature": False}) @@ -38,7 +26,7 @@ def check_permissions(token: str, scopes_list): scopes_token = token_decoded['scope'] scopes_validated_json = {} for scope in scopes_list: - scopes_validated_json[str(scope)]= scope in scopes_token + scopes_validated_json[str(scope)] = scope in scopes_token return scopes_validated_json diff --git a/samples-python/webserver/www/index.html b/samples-python/webserver/www/index.html index d16555e7a..f6ad987ce 100644 --- a/samples-python/webserver/www/index.html +++ b/samples-python/webserver/www/index.html @@ -13,7 +13,7 @@

PYTHON WEBSERVER SAMPLE

-

Read Data Layer Node

+

Read ctrlX Data Layer Node

Node:

Value: $(Server.readValue)

@@ -21,7 +21,7 @@

PYTHON WEBSERVER SAMPLE

-

Write Data Layer Node

+

Write ctrlX Data Layer Node

Node:

Value:

diff --git a/samples-sh/tpm2.consumer/README.md b/samples-sh/tpm2.consumer/README.md index 877c5c2a7..df7e52b0a 100644 --- a/samples-sh/tpm2.consumer/README.md +++ b/samples-sh/tpm2.consumer/README.md @@ -47,24 +47,5 @@ ___ ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-sh/tpm2.consumer/snap/snapcraft.yaml b/samples-sh/tpm2.consumer/snap/snapcraft.yaml index 61d203116..8e5166386 100644 --- a/samples-sh/tpm2.consumer/snap/snapcraft.yaml +++ b/samples-sh/tpm2.consumer/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: rexroth-tpm2-webserver -base: core20 +base: core22 version: '0.0.1' summary: A snap containing a tpm2 based openssl server description: | diff --git a/samples-sh/ulimit-snap/README.md b/samples-sh/ulimit-snap/README.md index ea2e8a650..0b529f3e0 100644 --- a/samples-sh/ulimit-snap/README.md +++ b/samples-sh/ulimit-snap/README.md @@ -46,24 +46,5 @@ apps: ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-sh/ulimit-snap/build-snap.sh b/samples-sh/ulimit-snap/build-snap.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-sh/ulimit-snap/build-snap.sh +++ b/samples-sh/ulimit-snap/build-snap.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-sh/ulimit-snap/snap/snapcraft.yaml b/samples-sh/ulimit-snap/snap/snapcraft.yaml index 98a1408ed..49df0c1c5 100644 --- a/samples-sh/ulimit-snap/snap/snapcraft.yaml +++ b/samples-sh/ulimit-snap/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: ulimit-n-16384 -base: core20 +base: core22 version: '1.0.0' summary: Ulimit demo snap description: | diff --git a/samples-snap/README.md b/samples-snap/README.md index af42b72aa..7b19dbd55 100644 --- a/samples-snap/README.md +++ b/samples-snap/README.md @@ -3,4 +3,5 @@ ## Find out the supported samples * [Generate Manifest](generate-manifest/README.md) -* [Monitor Health](monitor-health/README.md) \ No newline at end of file +* [Monitor Health](monitor-health/README.md) +* [Storage extension](storage-extension/README.md) \ No newline at end of file diff --git a/samples-snap/generate-manifest/README.md b/samples-snap/generate-manifest/README.md index 8eb09e02d..e3333fe6d 100644 --- a/samples-snap/generate-manifest/README.md +++ b/samples-snap/generate-manifest/README.md @@ -2,7 +2,7 @@ ## Goal -For a few use cases, it might be necessary to generate a package-manifest depending on the device or on the setup in is installed. This is possible during installation by using snap hook mechanism. This how-to describes how this can be resolved. +For a few use cases, it might be necessary to generate a package-manifest depending on the ctrlX CORE or on the setup in is installed. This is possible during installation by using snap hook mechanism. This how-to describes how this can be resolved. The snap build in this examples takes two random words and uses them to generate a menu entry in the ctrlX CORE sidebar. It will look like this: @@ -246,6 +246,6 @@ Therefore declaring all interfaces specific for each app and hook should be the ## Build and run -Now build the snap using "snapcraft" and install it on your device, on every reinstall, it will change the name of the menu entry. +Now build the snap using "snapcraft" and install it on your ctrlX CORE, on every reinstall, it will change the name of the menu entry. Thats it. diff --git a/samples-snap/generate-manifest/build-snap-amd64.sh b/samples-snap/generate-manifest/build-snap-amd64.sh index 1a4af2189..17b0914db 100644 --- a/samples-snap/generate-manifest/build-snap-amd64.sh +++ b/samples-snap/generate-manifest/build-snap-amd64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=amd64 --enable-experimental-target-arch diff --git a/samples-snap/generate-manifest/build-snap-arm64.sh b/samples-snap/generate-manifest/build-snap-arm64.sh index 9d6d8e6bc..a9d4aec2b 100644 --- a/samples-snap/generate-manifest/build-snap-arm64.sh +++ b/samples-snap/generate-manifest/build-snap-arm64.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +set -e snapcraft clean --destructive-mode snapcraft --destructive-mode --target-arch=arm64 --enable-experimental-target-arch diff --git a/samples-snap/generate-manifest/snap/snapcraft.yaml b/samples-snap/generate-manifest/snap/snapcraft.yaml index 5a68172b4..dad17969c 100644 --- a/samples-snap/generate-manifest/snap/snapcraft.yaml +++ b/samples-snap/generate-manifest/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: changing-world -base: core20 +base: core22 version: '1.0.0' summary: Simple snap with random menu entry description: | diff --git a/samples-snap/monitor-health/README.md b/samples-snap/monitor-health/README.md index abcc5cae1..27113fead 100644 --- a/samples-snap/monitor-health/README.md +++ b/samples-snap/monitor-health/README.md @@ -53,24 +53,5 @@ If you've found an error in these sample, please [file an issue](https://github. ## License -MIT License - -Copyright (c) 2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/samples-snap/monitor-health/build-snap-amd64.sh b/samples-snap/monitor-health/build-snap-amd64.sh index e3f627cf7..1ba73fc5a 100644 --- a/samples-snap/monitor-health/build-snap-amd64.sh +++ b/samples-snap/monitor-health/build-snap-amd64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_ARCH=amd64 # Clean all snap part assets diff --git a/samples-snap/monitor-health/build-snap-arm64.sh b/samples-snap/monitor-health/build-snap-arm64.sh index 103dfccb8..4b1ed5ae6 100644 --- a/samples-snap/monitor-health/build-snap-arm64.sh +++ b/samples-snap/monitor-health/build-snap-arm64.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e TARGET_ARCH=arm64 # Clean all snap part assets diff --git a/samples-snap/monitor-health/health/check-health b/samples-snap/monitor-health/health/check-health index df76f930e..74e2b09f5 100644 --- a/samples-snap/monitor-health/health/check-health +++ b/samples-snap/monitor-health/health/check-health @@ -1,27 +1,8 @@ #!/bin/bash -# MIT License +# SPDX-FileCopyrightText: Bosch Rexroth AG # -# Copyright (c) 2022 Bosch Rexroth AG -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - +# SPDX-License-Identifier: MIT # This check-health script periodically checks our app (service) for it's service status. # If the app not running or periodically restarted because of an crash, the health status will be reported to 'error', else 'okay'. diff --git a/samples-snap/monitor-health/snap/snapcraft.yaml b/samples-snap/monitor-health/snap/snapcraft.yaml index 9578a863b..7ef5d77fc 100644 --- a/samples-snap/monitor-health/snap/snapcraft.yaml +++ b/samples-snap/monitor-health/snap/snapcraft.yaml @@ -11,7 +11,7 @@ confinement: strict #confinement: devmode #icon: assets/icons/ICONHERE.png grade: stable # must be 'stable' to release into candidate/stable channels -base: core20 +base: core22 type: app apps: diff --git a/samples-snap/storage-extension/README.md b/samples-snap/storage-extension/README.md new file mode 100644 index 000000000..580c0353a --- /dev/null +++ b/samples-snap/storage-extension/README.md @@ -0,0 +1,13 @@ +# Example Snap to use a storage extension + +## Introduction + +Storage extension is a feature to extend the internal storage by an external media like sd card or usb stick. +Storage extension was introduced with DeviceAdmin 1.18. + +This storage is encrypted and bond to one ctrlX CORE, so it cannot be used to transfer data from one ctrlX CORE to another one. + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/samples-snap/storage-extension/backup/snapshots.yaml b/samples-snap/storage-extension/backup/snapshots.yaml new file mode 100644 index 000000000..d03cfbd4f --- /dev/null +++ b/samples-snap/storage-extension/backup/snapshots.yaml @@ -0,0 +1,3 @@ +exclude: + # Exclude storage-extension partition + - $SNAP_COMMON/storage-extension/* \ No newline at end of file diff --git a/samples-snap/storage-extension/snap/hooks/remove b/samples-snap/storage-extension/snap/hooks/remove new file mode 100644 index 000000000..bc56f9b04 --- /dev/null +++ b/samples-snap/storage-extension/snap/hooks/remove @@ -0,0 +1 @@ +snapctl umount $SNAP_COMMON/storage-extension/$SNAP_NAME diff --git a/samples-snap/storage-extension/snap/snapcraft.yaml b/samples-snap/storage-extension/snap/snapcraft.yaml new file mode 100644 index 000000000..9527f1620 --- /dev/null +++ b/samples-snap/storage-extension/snap/snapcraft.yaml @@ -0,0 +1,42 @@ +name: storage-extension-sample +title: Storage extenstion sample app +base: core22 +version: 0.0.1 +summary: Storage extension sample +description: | + Storage extension sample +grade: stable # must be 'stable' to release into candidate/stable channels +confinement: strict # use 'strict' once you have the right plugs and slots +architectures: + - all + +parts: + sources: + plugin: dump + source: wrapper + backup: + plugin: nil + source: backup + override-build: | + snapcraftctl build + mkdir -p $SNAPCRAFT_PART_INSTALL/meta + cp $SNAPCRAFT_PART_SRC/snapshots.yaml $SNAPCRAFT_PART_INSTALL/meta +plugs: + storage-extension-mnt: + interface: mount-control + mount: + - what: /writable/system-data/var/run/mnt/storage-extension/${SNAPCRAFT_PROJECT_NAME} + where: $SNAP_COMMON/storage-extension/${SNAPCRAFT_PROJECT_NAME} + options: + - rw + - bind + +apps: + sample: + command: bin/sample + daemon: simple + restart-condition: always + restart-delay: 5s + plugs: + - storage-extension-mnt + - mount-observe diff --git a/samples-snap/storage-extension/wrapper/bin/sample b/samples-snap/storage-extension/wrapper/bin/sample new file mode 100644 index 000000000..ea5dbc28d --- /dev/null +++ b/samples-snap/storage-extension/wrapper/bin/sample @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +mount | grep /dev/mapper/storage-extension +if [ $? -ne 0 ]; then + echo No storage extension found + exit 1 +fi +STORAGE_EXTENSION=$SNAP_COMMON/storage-extension/$SNAP_NAME +snapctl mount -o rw,bind /writable/system-data/var/run/mnt/storage-extension/$SNAP_NAME $STORAGE_EXTENSION + +while true; do + date +%Y-%m-%d-%H-%M-%S>>$STORAGE_EXTENSION/test-file.log + sleep 5 +done diff --git a/doc/samples.md b/samples.md similarity index 86% rename from doc/samples.md rename to samples.md index 052e7e8ef..5b4d194b1 100644 --- a/doc/samples.md +++ b/samples.md @@ -1,95 +1,96 @@ - -## Sample Projects - -Applications (snaps) for ctrlX CORE targets can be written in several programming language or even as shell scripts. - -For creating your own applications, the ctrlX AUTOMATION SDK offers sample projects that can be used as source of code snippets as templates. The sample projects are saved in sub folders according to their programming language or their type. - -Here an overview of the sample project types and their subfolders. - -!!! important - Run the install script listet in column three once before you are working with one or more sample projects. - These scripts are located in __/home/boschrexroth/scripts__. See also [install-scripts](install-scripts.md). - -| Sample Project Type | Link to Projects | Install Script -| :------------------ | :------------------------------------------------------ | :------------------------ | -| __C/C++__ | [samples-cpp/README.md](samples-cpp/README.md) | -| __Go__ | [samples-go/README.md](samples-go/README.md) | ~/scripts/install-go.sh -| __Python__ | [samples-python/README.md](samples-python/README.md) | -| __.NET__ | [samples-net/README.md](samples-net/README.md) | ~/scripts/install-dotnet-sdk.sh -| __Node.js__ | [samples-node/README.md](samples-node/README.md) | ~/scripts/install-nodejs-npm.sh -| __Shell scripting__ | [samples-sh/README.md](samples-sh/README.md) | -| __Snap__ | [samples-snap/README.md](samples-snap/README.md) | -| __IEC 61131-3__ | [samples-iec61131/README.md](samples-iec61131/README.md)| - - -## Building Snaps - -!!! important - All project folders are containing these scripts to build snaps: - -* __build-snap-amd64.sh__: Build an amd64 snap for a ctrlX CORE virtual. -* __build-snap-arm64.sh__: Build an arm64 (aarch64) snap for a ctrlX CORE. - -You can call these scripts from the command line: - - ./build-snap-amd64.sh - ./build-snap-arm64.sh - - or from Visual Studio Code: - - * Select main menu item Terminal --> Run Build Task - * Select `build snap amd64` for building a snap for a ctrlX CORE virtual - * Select `build snap arm64` for building a snap for a ctrlX CORE. - -At the end of the build process the snap file should be available in the root folder of your project. - -See below for further Run Build Task items. - -## Installing a Snap Manually - -Right click the snap file in the Visual Studio Code EXPLORER and select 'Download'. Visual Studio Code stores it in your home directory on your host computer. For Windows 10 this is %USERPROFILE%, in Linux this is: ~/ - -Start a Web browser, login into your ctrlX CORE: - -* Select Settings - Apps -* Switch to Service Mode -* Click Install from file -* Select the downloaded file -* Switch to Operation Mode - -## Building and Installing a Snap Automated by Script - -Using the bash script __build-upload-log-snap.sh__ in the ctrlX AUTOMATION SDK folder scripts/ -You can create a snap file, upload it, install it on a ctrlX CORE and view the log output. - -The script can be started either from the command line or with the additional Run Build Task items of the Visual Studio Code IDE. - -### Starting Script from the Command Line - -Change into a sample project folder (e.g. samples-cpp/datalayer.client) and enter - - ../../scripts/build-upload-log-snap.sh -help - -All parameters and their default values are listed. - -E.g. to build and install a snap for a ctrlX CORE virtual with Network Adapter enter - - ../../scripts/build-upload-log-snap.sh -NA - -But we recommend calling this script from Visual Studio Code. See next chapter. - -### Starting Script as Visual Studio Build Task - -Additional to the two Build Tasks mentioned above there are further tasks: - -* __Build upload snap - ctrlX CORE virtual Network Adapter__ -* __Build upload snap - ctrlX CORE virtual Port Forwarding__ -* __Build upload log snap - ctrlX CORE 192.168.1.1__ -* __Build upload snap__ - -The first three tasks are calling the script with the parameter set needed for the according destination. There is sno need to select further parameters. - -If you are choosing the last item each parameter is prompted. - -Feel free to add more tasks or adapt the existing ones. + +## Sample Projects + +Applications (snaps) for ctrlX CORE targets can be written in several programming language or even as shell scripts. + +For creating your own applications, the ctrlX AUTOMATION SDK offers sample projects that can be used as source of code snippets as templates. The sample projects are saved in sub folders according to their programming language or their type. + +Here an overview of the sample project types and their subfolders. + +!!! important + Run the install script listet in column three once before you are working with one or more sample projects. + These scripts are located in __/home/boschrexroth/scripts__. See also [install-scripts](install-scripts.md). + +| Sample Project Type | Link to Projects | Install Script +| :------------------ | :------------------------------------------------------ | :------------------------ | +| __C/C++__ | [samples-cpp/README.md](samples-cpp/README.md) | +| __Go__ | [samples-go/README.md](samples-go/README.md) | ~/scripts/install-go.sh +| __Python__ | [samples-python/README.md](samples-python/README.md) | +| __.NET__ | [samples-net/README.md](samples-net/README.md) | ~/scripts/install-dotnet-sdk.sh +| __ANGULAR__ | [samples-angular/README.md](samples-angular/README.md) | +| __Node.js__ | [samples-node/README.md](samples-node/README.md) | ~/scripts/install-nodejs-npm.sh +| __Shell scripting__ | [samples-sh/README.md](samples-sh/README.md) | +| __Snap__ | [samples-snap/README.md](samples-snap/README.md) | +| __IEC 61131-3__ | [samples-iec61131/README.md](samples-iec61131/README.md)| + + +## Building Snaps + +!!! important + All project folders are containing these scripts to build snaps: + +* __build-snap-amd64.sh__: Build an amd64 snap for a ctrlX COREvirtual. +* __build-snap-arm64.sh__: Build an arm64 (aarch64) snap for a ctrlX CORE. + +You can call these scripts from the command line: + + ./build-snap-amd64.sh + ./build-snap-arm64.sh + + or from Visual Studio Code: + + * Select main menu item Terminal --> Run Build Task + * Select `build snap amd64` for building a snap for a ctrlX COREvirtual + * Select `build snap arm64` for building a snap for a ctrlX CORE. + +At the end of the build process the snap file should be available in the root folder of your project. + +See below for further Run Build Task items. + +## Installing a Snap Manually + +Right click the snap file in the Visual Studio Code EXPLORER and select 'Download'. Visual Studio Code stores it in your home directory on your host computer. For Windows 10 this is %USERPROFILE%, in Linux this is: ~/ + +Start a Web browser, login into your ctrlX CORE: + +* Select Settings - Apps +* Switch to Service Mode +* Click Install from file +* Select the downloaded file +* Switch to Operation Mode + +## Building and Installing a Snap Automated by Script + +Using the bash script __build-upload-log-snap.sh__ in the ctrlX AUTOMATION SDK folder scripts/ +You can create a snap file, upload it, install it on a ctrlX CORE and view the log output. + +The script can be started either from the command line or with the additional Run Build Task items of the Visual Studio Code IDE. + +### Starting Script from the Command Line + +Change into a sample project folder (e.g. samples-cpp/datalayer.client) and enter + + ../../scripts/build-upload-log-snap.sh -help + +All parameters and their default values are listed. + +E.g. to build and install a snap for a ctrlX COREvirtual with Network Adapter enter + + ../../scripts/build-upload-log-snap.sh -NA + +But we recommend calling this script from Visual Studio Code. See next chapter. + +### Starting Script as Visual Studio Build Task + +Additional to the two Build Tasks mentioned above there are further tasks: + +* __Build upload snap - ctrlX COREvirtual Network Adapter__ +* __Build upload snap - ctrlX COREvirtual Port Forwarding__ +* __Build upload log snap - ctrlX CORE 192.168.1.1__ +* __Build upload snap__ + +The first three tasks are calling the script with the parameter set needed for the according destination. There is sno need to select further parameters. + +If you are choosing the last item each parameter is prompted. + +Feel free to add more tasks or adapt the existing ones. diff --git a/scripts/build-upload-log-snap.sh b/scripts/build-upload-log-snap.sh index b77b30309..69e815730 100644 --- a/scripts/build-upload-log-snap.sh +++ b/scripts/build-upload-log-snap.sh @@ -1,24 +1,32 @@ #!/bin/bash -SECONDS_TO_WAIT_AFTER_SHOW_ARGUMENTS=2 +ARCH=arm64 + +ADDR=192.168.1.1 +SSL_PORT=443 +SSH_PORT=22 + +ASK=y + +SECONDS_TO_WAIT_AFTER_SHOW_ARGUMENTS=5 SECONDS_TO_WAIT_AFTER_UPLOAD=30 +SECONDS_TO_WAIT_AFTER_UNINSTALL=30 BUILD=y - UPLOAD=y -ADDR=192.168.1.1 +UNINSTALL=n +BUNDLE="" -SSL_PORT=443 SSL_USR=boschrexroth SSL_PWD=boschrexroth -SVC=n +SERVICE=y +OPERATING=y -ARCH=arm64 +SSH_USR=rexroot +SSH_PWD=rexroot LOGS=y -SSH_PORT=22 -SSH_USR=rexroot # Scanning parameter list @@ -50,6 +58,19 @@ for arg in "$@"; do UPLOAD=${!argNext} fi + + if grep -q "uninst" <<<${arg} + then + UNINSTALL=${!argNext} + fi + + if [[ "-bundle" =~ ^$arg ]] + then + echo ********************************* + BUNDLE=${!argNext} + echo BUNDLE $BUNDLE + fi + if grep -q "ip" <<<${arg} then ADDR=${!argNext} @@ -75,9 +96,14 @@ for arg in "$@"; do SSL_PWD=${!argNext} fi - if grep -q "svc" <<<${arg} + if grep -q "serv" <<<${arg} then - SVC=${!argNext} + SERVICE=${!argNext} + fi + + if grep -q "oper" <<<${arg} + then + OPERATING=${!argNext} fi if grep -q "arch" <<<${arg} @@ -85,7 +111,7 @@ for arg in "$@"; do ARCH=${!argNext} fi - if grep -q "logs" <<<${arg} + if grep -q "log" <<<${arg} then LOGS=${!argNext} fi @@ -121,20 +147,28 @@ for arg in "$@"; do echo " n Skip snap build" echo " " echo "-upload Upload snap" - echo " y Default: Servive State, Upload, Operation State" + echo " y Default: Upload" echo " n Skip upload" echo " " + echo "-bundle Snap is a bundle" + echo " y Check" + echo " n Default: Skip check" + echo " " + echo "-uninstall Uninstall snap" + echo " y Uninstall" + echo " n Default: Skip uninstall" + echo " " echo "-logs Show snap logs" - echo " y Start remote: sudo snap logs -f ... " + echo " y Default: sudo snap logs -f ... " echo " n No logs" echo " " echo "-addr IP address or name of the destination ctrlX CORE" echo " 192.168.1.1 Default: ctrlX CORE" - echo " 10.0.2.2 ctrlX CORE virtual with port forwarding" + echo " 10.0.2.2 ctrlX COREvirtual with port forwarding" echo " " echo "-ssl-port Port number for HTTPS (SSL) connection" echo " 443 Default: ctrlX CORE" - echo " 8443 ctrlX CORE virtual with port forwarding" + echo " 8443 ctrlX COREvirtual with port forwarding" echo " " echo "-ssl-usr User name for HTTPS (SSL) connection" echo " boschrexroth default value" @@ -142,26 +176,30 @@ for arg in "$@"; do echo "-ssl-pwd Password for HTTPS (SSL) connection" echo " boschrexroth Default value" echo " " - echo "-svc Switch scheduler to state Service" - echo " n Do not swtich" - echo " y state=SERVICE -> install snap -> state=OPERATING" + echo "-service Switch scheduler to state Service" + echo " n Default: Do not switch" + echo " y Switch to SERVICE" + echo " " + echo "-operating Switch scheduler to state Operating" + echo " n Default: Do not switch" + echo " y Switch to OPERATING" echo " " echo "-arch CPU architecture" - echo " arm64 Default: CORE M3/4" - echo " amd64 ctrlX CORE virtual, OS" + echo " arm64 Default: CORE X3" + echo " amd64 ctrlX COREvirtual, OS" echo " " echo "-ssh-port Port number for HTTPS (SSL) connection" echo " 22 Default: ctrlX CORE" - echo " 8022 ctrlX CORE virtual with port forwarding" + echo " 8022 ctrlX COREvirtual with port forwarding" echo " " echo "-ssh-usr User name for SSH connection" echo " rexroot Default value" echo " " echo " " - echo "-ctrlx-virt-PF Use settings for ctrlX CORE virtual with Port Forwarding" + echo "-ctrlx-virt-PF Use settings for ctrlX COREvirtual with Port Forwarding" echo " 10.0.2.2, 8443, amd64, 8022" echo " " - echo "-ctrlx-virt-NA Use settings for ctrlX CORE virtual with Network Adapter" + echo "-ctrlx-virt-NA Use settings for ctrlX COREvirtual with Network Adapter" echo " 192.168.1.1, 443, amd64, 22" echo " " @@ -169,18 +207,22 @@ for arg in "$@"; do fi done -echo -build = ${BUILD} +echo -arch ${ARCH} +echo -addr ${ADDR} +echo -ssl-port ${SSL_PORT} +echo -ssl-usr ${SSL_USR} +echo -ssl-pwd ${SSL_PWD} +echo -ssh-port ${SSH_PORT} +echo " " +echo -build ${BUILD} +echo -upload ${UPLOAD} +echo -bundle ${BUNDLE} +echo -uninstall ${UNINSTALL} echo " " -echo -upload = ${UPLOAD} -echo -addr = ${ADDR} -echo -arch = ${ARCH} -echo -svc = ${SVC} -echo -ssl-port = ${SSL_PORT} -echo -ssl-usr = ${SSL_USR} -echo -ssl-pwd = ${SSL_PWD} +echo -service ${SERVICE} +echo -operating ${OPERATING} echo " " -echo -logs = ${LOGS} -echo -ssh-port = ${SSH_PORT} +echo -logs ${LOGS} echo " " echo " " echo "Settings OK? Waiting" ${SECONDS_TO_WAIT_AFTER_SHOW_ARGUMENTS} "s ..." @@ -194,23 +236,97 @@ then echo " " source build-snap-${ARCH}.sh fi - -if grep -q "y" <<<${UPLOAD} + +echo " " +echo ----------------------------------------------------------------- +echo Requesting new Bearer Token +echo " " + +res=$(curl --insecure --no-progress-meter --request POST https://${ADDR}:${SSL_PORT}/identity-manager/api/v1/auth/token --header 'Content-Type: application/json' --data-raw '{"name":"'${SSL_USR}'","password":"'${SSL_PWD}'"}') +# https://stackoverflow.com/questions/9733338/shell-script-remove-first-and-last-quote-from-a-variable +# Remove first and last quote (") from a variable +TOKEN=$(echo ${res} | jq .access_token | xargs) + +echo Bearer ${TOKEN} +echo " " + +if grep -q "y" <<<${SERVICE} then - echo " " echo ----------------------------------------------------------------- - echo Requesting new Bearer Token + echo Switching Scheduler to state SERVICE + echo " " + + RESPONSE=$(curl -X 'PUT' \ + https://${ADDR}:${SSL_PORT}/automation/api/v1/scheduler/admin/state?format=json \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + -d '{"state":"SERVICE"}' \ + --insecure --no-progress-meter --silent --show-error) + + if grep -q "SERVICE" <<<${RESPONSE} + then + echo OK + else + echo WARNING Switching Scheduler to state SERVICE failed + read -t ${SECONDS_TO_WAIT_AFTER_UPLOAD} -p "Wait or press ENTER to continue" + fi + echo " " +fi - res=$(curl --insecure --no-progress-meter --request POST https://${ADDR}:${SSL_PORT}/identity-manager/api/v1/auth/token --header 'Content-Type: application/json' --data-raw '{"name":"'${SSL_USR}'","password":"'${SSL_PWD}'"}') - # https://stackoverflow.com/questions/9733338/shell-script-remove-first-and-last-quote-from-a-variable - # Remove first and last quote (") from a variable - TOKEN=$(echo ${res} | jq .access_token | xargs) +if grep -q "y" <<<${UNINSTALL} +then - echo Bearer ${TOKEN} echo " " + echo ----------------------------------------------------------------- + echo Uninstalling ${ARCH} snaps + + # Read list of installed snaps + ALL_INSTALLED_SNAPS=$(curl -X 'GET' \ + https://${ADDR}:${SSL_PORT}/package-manager/api/v1/packages \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + --insecure --no-progress-meter) + + # Loop over all found snaps + for f in $(find . -name "*_${ARCH}.snap"); + do + + # Get snap name without arch and version info + SNAP=$(basename $f) + SNAP=${SNAP%_*} + SNAP=${SNAP%_*} + + if grep -q $SNAP <<<${ALL_INSTALLED_SNAPS} + then + + echo " " + echo Uninstalling $SNAP -------------------------- + echo " " + + curl -X POST \ + https://${ADDR}:${SSL_PORT}/package-manager/api/v1/tasks \ + -H 'accept: */*' \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + -d '{ "action": "uninstall", "parameters": { "id": "'${SNAP}'" } }' \ + --insecure --no-progress-meter --silent --show-error + + echo "Waiting ${SECONDS_TO_WAIT_AFTER_UNINSTALL}s after uninstallation ..." + read -t ${SECONDS_TO_WAIT_AFTER_UNINSTALL} -p "Wait or press ENTER to continue" + echo " " + + else + echo NOT installed: $SNAP + fi + done; +fi +if grep -q "y" <<<${UPLOAD} +then echo " " echo ----------------------------------------------------------------- @@ -223,115 +339,184 @@ then -H "Authorization: Bearer ${TOKEN}" \ -H 'Content-Type: application/json' \ -d '{ "allowUnknownApps": true }' \ - --insecure --no-progress-meter + --insecure --no-progress-meter --silent --show-error - if grep -q "y" <<<${SVC} - then - echo " " - echo ----------------------------------------------------------------- - echo Switching Scheduler to state SERVICE - echo " " + echo " " + echo ----------------------------------------------------------------- + echo Uploading and installing ${ARCH} snaps - curl -X 'PUT' \ - https://${ADDR}:${SSL_PORT}/automation/api/v1/scheduler/admin/state?format=json \ - -H 'accept: application/json' \ - -H "Authorization: Bearer ${TOKEN}" \ - -H 'Content-Type: application/json' \ - -d '{"state":"SERVICE"}' \ - --insecure --no-progress-meter - fi + for f in $(find . -name "*_${ARCH}.snap"); + do + SNAP=$(basename $f) + SNAP=${SNAP%_*} + SNAP=${SNAP%_*} + + echo " " + echo Uploading ... + echo " file" $f + echo " snap" ${SNAP} + echo " " + curl -X POST https://${ADDR}:${SSL_PORT}/package-manager/api/v1/packages \ + -H "accept: */*" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: multipart/form-data" \ + -F "file=@${f}" \ + -F update=true \ + --insecure --no-progress-meter --silent --show-error + + echo "Waiting ${SECONDS_TO_WAIT_AFTER_UPLOAD}s after installation ..." + sleep ${SECONDS_TO_WAIT_AFTER_UPLOAD} + done; echo " " echo ----------------------------------------------------------------- - echo Uploading and installing ${ARCH} snaps + echo Checking if ${ARCH} snaps are installed + + # Read list of installed snaps + ALL_INSTALLED_SNAPS=$(curl -X 'GET' \ + https://${ADDR}:${SSL_PORT}/package-manager/api/v1/packages \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + --insecure --no-progress-meter) - for f in $(find . -maxdepth 1 -name "*_${ARCH}.snap"); + for f in $(find . -name "*_${ARCH}.snap"); do - echo " " - echo $f - echo " " - curl -X POST https://${ADDR}:${SSL_PORT}/package-manager/api/v1/packages \ - -H "accept: */*" \ - -H "Authorization: Bearer ${TOKEN}" \ - -H "Content-Type: multipart/form-data" \ - -F "file=@${f}" \ - -F update=true \ - --insecure --no-progress-meter + SNAP=$(basename $f) + SNAP=${SNAP%_*} + SNAP=${SNAP%_*} + + if grep -q ${SNAP} <<<${ALL_INSTALLED_SNAPS} + then + echo INFO Is installed ${SNAP} + else + echo ERROR Is NOT installed ${SNAP} + fi done; +fi - echo "Waiting ${SECONDS_TO_WAIT_AFTER_UPLOAD}s after installation ..." - read -t ${SECONDS_TO_WAIT_AFTER_UPLOAD} -p "Wait or press ENTER to continue" +if grep -q "y" <<<${OPERATING} +then - if grep -q "y" <<<${SVC} - then + for i in $(seq 1 5); + do echo " " echo ----------------------------------------------------------------- echo Switching Scheduler to state OPERATING echo " " - RESPONSE=Error - while grep -q "Error" <<<${RESPONSE} - do - - RESPONSE=$(curl -X 'PUT' \ - https://${ADDR}:${SSL_PORT}/automation/api/v1/scheduler/admin/state?format=json \ - -H 'accept: application/json' \ - -H "Authorization: Bearer ${TOKEN}" \ - -H 'Content-Type: application/json' \ - -d '{"state":"OPERATING"}' \ - --insecure --no-progress-meter) - - if grep -q "Error" <<<${RESPONSE} - then - echo " " - echo WARNING Switching Scheduler to state OPERATING failed - echo "We are repeating in ${SECONDS_TO_WAIT_AFTER_UPLOAD}s ..." - read -t ${SECONDS_TO_WAIT_AFTER_UPLOAD} -p "Wait or press ENTER to continue" - fi - done - - fi - - echo " " - echo ----------------------------------------------------------------- - echo Deleting Bearer Token - echo " " - curl \ - --insecure --no-progress-meter \ - --request DELETE https://${ADDR}:${SSL_PORT}/identity-manager/api/v1/auth/token \ - -H 'accept: */*' -H "Authorization: Bearer ${TOKEN}" + # Two steps are needed + # 1. Start rexroth-automationcore.control (scheduler) + NOT_USED_RESPONSE=$(curl -X 'PUT' \ + https://${ADDR}:${SSL_PORT}/automation/api/v1/scheduler/admin/state?format=json \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + -d '{"action":"start","parameters":{"service":"rexroth-automationcore.control","enable":"true"}}' \ + --insecure --no-progress-meter --silent) + # 2. Switch scheduler to OPERATING + RESPONSE=$(curl -X 'PUT' \ + https://${ADDR}:${SSL_PORT}/automation/api/v1/scheduler/admin/state?format=json \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + -d '{"state":"OPERATING"}' \ + --insecure --no-progress-meter --silent --show-error) + + if grep -q "Error" <<<${RESPONSE} + then + echo " " + echo WARNING Switching Scheduler to state OPERATING failed + echo "We are repeating in ${SECONDS_TO_WAIT_AFTER_UPLOAD}s ..." + read -t ${SECONDS_TO_WAIT_AFTER_UPLOAD} -p "Wait or press ENTER to continue" + echo " " + else + echo OK + break + fi + done + fi -SNAP_FILE=$(ls *${ARCH}.snap) -SNAP_VERSION=${SNAP_FILE%_*} -SNAP=${SNAP_VERSION%_*} +# Not empty +if [ -n "$BUNDLE" ] +then -echo Searching ${SNAP} in snap list... + # No logs + LOGS=n + + echo " " + echo ----------------------------------------------------------------- + echo Checking bundle $BUNDLE ... + echo " " + BUNDLES=$(curl -X 'GET' \ + https://${ADDR}:${SSL_PORT}/automation/api/v2/nodes/framework/bundles?type=browse \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${TOKEN}" \ + --insecure --no-progress-meter) -SNAP_LIST=$(ssh -o StrictHostKeyChecking=no -p ${SSH_PORT} ${SSH_USR}@${ADDR} snap list) -echo " " + echo " " + echo $BUNDLES + echo " " -if grep -q "${SNAP}" <<<${SNAP_LIST} -then - echo "Our snap is installed" -else - echo "Our snap is NOT installed!" - read -t ${SECONDS_TO_WAIT_AFTER_UPLOAD} -p "Press Ctrl-C to exit" + if grep -q $BUNDLE <<<"$BUNDLES"; then + echo "INFO Is registered: $BUNDLE" + + STATE=$(curl -X 'GET' \ + https://${ADDR}:${SSL_PORT}/automation/api/v2/nodes/framework/bundles/$BUNDLE \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${TOKEN}" \ + --insecure --no-progress-meter) + + echo $STATE + echo " " + echo " name" $(echo $STATE | jq .value.name) + echo " version" $(echo $STATE | jq .value.version) + echo " components" $(echo $STATE | jq .value.components) + echo " state" $(echo $STATE | jq .value.state) + echo " active" $(echo $STATE | jq .value.active) + echo " installed" $(echo $STATE | jq .value.installed) + + else + echo "ERROR Is NOT registered: $BUNDLE" + fi fi echo " " +echo ----------------------------------------------------------------- +echo Deleting Bearer Token +echo " " +curl \ + --insecure --no-progress-meter \ + --request DELETE https://${ADDR}:${SSL_PORT}/identity-manager/api/v1/auth/token \ + -H 'accept: */*' -H "Authorization: Bearer ${TOKEN}" if grep -q "y" <<<${LOGS} then echo " " echo ----------------------------------------------------------------- - echo Viewing logs + echo Activate SSH access echo " " - ssh -o StrictHostKeyChecking=no -p ${SSH_PORT} ${SSH_USR}@${ADDR} sudo snap logs -f ${SNAP} -fi - + curl -X 'PUT' \ + https://${ADDR}:${SSL_PORT}/ssh/api/v1/status \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + -d '{"state": "activated"}' \ + --insecure --no-progress-meter --silent --show-error + + echo " " + + ssh-keygen -f "/home/boschrexroth/.ssh/known_hosts" -R "[${ADDR}]:${SSH_PORT}" 2>&1 1>/dev/null + + echo " " + echo ----------------------------------------------------------------- + echo Viewing logs + echo " " + sshpass -p ${SSH_PWD} ssh -o StrictHostKeyChecking=no -p ${SSH_PORT} ${SSH_USR}@${ADDR} sudo snap logs -f ${SNAP} +fi \ No newline at end of file diff --git a/scripts/build_flatbuffers.sh b/scripts/build_flatbuffers.sh index 5a417befa..22a54e927 100644 --- a/scripts/build_flatbuffers.sh +++ b/scripts/build_flatbuffers.sh @@ -1,5 +1,5 @@ #!/bin/bash -flatc=$(dirname $0)/../bin/oss.flatbuffers/ubuntu20-gcc-x64/release/flatc +flatc=$(dirname $0)/../bin/oss.flatbuffers/ubuntu22-gcc-x64/release/flatc # flatc=$0/../bin/oss.flatbuffers/win-msvc-x64/release/flatc.exe lang=$1 fbs=$2 diff --git a/scripts/environment/.gitignore b/scripts/environment/.gitignore index 4f1241d1f..b296dfff5 100644 --- a/scripts/environment/.gitignore +++ b/scripts/environment/.gitignore @@ -1,9 +1,10 @@ -*-generated +*generated* *64.img *.qcow2 QEMU_EFI.fd -*.tar.* -*copy -*copy.* --pure.* +*copy* wget-log* +*.bak +*.zip +cloud-config-* +scripts/cloud-config/* diff --git a/scripts/environment/README-internal.md b/scripts/environment/README-internal.md index 782288724..406b3e4b6 100644 --- a/scripts/environment/README-internal.md +++ b/scripts/environment/README-internal.md @@ -2,83 +2,68 @@ __Important__: -* The host operating system were the App Builder Environments are running must be Windows 64Bit. +* The host operating system were the App Build Environments are running must be __Windows amd64.__ -* The user-image-files (see below) can only be build on a Linux system (e.g. an App Builder Environment). +* The user-image-files (see below) can only be build on a Linux system (e.g. within an App Build Environment). ## Concept -__cloud-config-amd64__ and __cloud-config-aarch64__ are so called cloud-config files. These files are compiled into user-data-image files. One for proxy usage, the other for none-proxy usage. +Four different types of App Build Environments are supported: -With the script __user-data-img-build-all.sh__ all user-data-image files are build. +1. amd64 architecture with proxy +2. amd64 architecture with NO proxy +3. aarch64 architecture with proxy +4. aarch64 architecture with NO proxy -Remark: The user-data-image files for aarch64 are kept for future usage. +An App Build Environment is a Ubuntu Server operating system installed with the help of the build-in cloud-init service. For more information see [cloud-init](https://cloud-init.io/). -__Important: The user-data-image files for amd64 are used by ctrlX WORKS.__ +The configuration is provided by a so called cloud-config file. -For more information see [cloud-init](https://cloud-init.io/) +For informations on the content of cloud-config files see [Cloud config examples](https://cloudinit.readthedocs.io/en/latest/topics/examples. +html). -## Files -### cloud-config Files +For all types of App Build Environments one single configuration file is used: __cloud-config__. -Cloud-config files are containing settings (user/password, proxy,...) and a list of packages to be installed on the App Builder Environment: +Type specific lines within this file are marked by these patterns: -* cloud-config-amd64 For amd64 VMs -* cloud-config-aarch64 For aarch64 VMs (reserved) +* #amd64-ONLY: Only relevant for amd64 architecture +* #aarch64-ONLY: Only relevant for aarch64 architecture +* #proxy-ONLY: Only if a proxy server is used +* insert-????-here: Indicates a text passage where during the build process a special text is inserted -For informations on the content of cloud-config files see [Cloud config examples](https://cloudinit.readthedocs.io/en/latest/topics/examples.html). +## Building User Data Image Files -### User Image Files +During the build process the type specific configuration file is generated, compiled (by the tool cloud-localds) and provided in a so called user-data-image file: -cloud-config file are compiled into image files: +* builder/user-data-amd64-proxy.img amd64 VM with proxy usage +* builder/user-data-amd64-noproxy.img amd64 VM without proxy usage +* user-data-aarch64-proxy.img aarch64 VM with proxy usage +* user-data-aarch64-noproxy.img aarch64 VM without proxy usage -* ubuntu-20.04-server-cloudimg-amd64-user-data-proxy.img amd64 VM with proxy usage -* ubuntu-20.04-server-cloudimg-amd64-user-data-noproxy.img amd64 VM without proxy usage -* ubuntu-20.04-server-cloudimg-aarch64-user-data-proxy.img aarch64 VM with proxy usage -* ubuntu-20.04-server-cloudimg-aarch64-user-data-noproxy.img aarch64 VM without proxy usage +__Important:__ -### Linux Scripts +The user-data-image files for amd64 are stored in the sub folder `builder`. This folder contains also other files needed by ctrlX WORKS to create and start App Build Enviroments. -* user-data-img-build.sh, user-data-img-build-all.sh are used to compile the cloud-config files into user-data-image files. +Hint: The user-data-image files for aarch64 are kept for future usage. -### Windows Batch Files +### Build Scripts -* __scp_id_rsa.bat__ copies the id_rsa and id_rsa.pub file from the Windows host to the App Builder Environment guest operating system so that entering password on login is obsolete. +* __build-0-user-data-img.sh__ is the build over all script. __Start this script to run the whole build process.__ +* build-1-cloud-configs.sh generates the architecture specific config files: cloud-config-aarch64-generated, cloud-config-amd64-generated +* build-2-user-data-img-all.sh initiates the build off all user data images files calling calls build-9-user-data-img.sh +* calls build-9-user-data-img.sh: Creates a single regarding the provided architecture and proxy settings -* __ssh-keygen-copy-id.bat__ enables login without password by adding .ssh\id_rsa.pub of the host to ~/.authorized_keys of the QM VM. +__replace-text.py__ is as simple text search and replace Python script which is able to handle special characters in both search and replace pattern. -* __shrink-qcow2.bat__ shrinks the qcow2 snapshot file. +### Scripts for the App Build Environment -!!! important - This action takes some time, do not interrupt. +Bash scripts e.g. to install programing language packages are stored in the folder scripts/. +This folder and its files are packed into the zip archive scripts.zip. This file again is gzipped and inserted as base64 encoded text into the cloud-config file. -* wget.bat calls PowerShell to download files. - -### Folder install-scripts - -Contains shell scripts packed into the cloud-config files. +At the end of the first boot this zip archive is unpacked and installed into the folder /home/boschrexroth/scripts. ## License -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/scripts/environment/README.md b/scripts/environment/README.md deleted file mode 100644 index cb653c071..000000000 --- a/scripts/environment/README.md +++ /dev/null @@ -1,68 +0,0 @@ -# ctrlX App Build Environment - -## Indroduction - -This folder contains bat and image files to build and launch an App Builder Environment. - -This is a [QEMU](https://wiki.ubuntu.com/ARM64/QEMU) virtual machines running an Ubuntu Server operating system. - -__Important__: The host operating system must be Windows 64Bit (amd64). - -Installation and configuration of the Ubuntu Server guest operating system are automatically done on first boot by the Ubuntu Cloud-Init Technology. -For this purpose, a so-called user image file is specified when the VM is started. -This file contains the compiled information of a cloud-config file which is processed by the cloud-init service. - -For more informations see [cloud-init](https://cloud-init.io/) - -## Starting and Building the App Builder Environment - -* start.bat is created and called by ctrlX WORKS. Here the required parameters are passed. -* start.bat calls launch.bat -* launch.bat calls build.bat. This script downloads the Ubuntu Server image and creates a qemu snapshotfile .qcow2 -* The Ubuntu Server image file will kept unchanged, all changes are stored into the snapshot file. -* Furthermore a user-data image file is provided. This file contains the cloud-config informations used during first boot to preinstall the operating system. - - -## Windows Helper Batchs - -### ssh-keygen-copy-id.bat - -Enables login without password by adding .ssh\id_rsa.pub of the host to ~/.authorized_keys of the QM VM. - -!!! important - We recommend to use this script instead of always signing in with the password. - -### shrink-qcow2.bat - -Shrinks the qcow2 snapshot file. - -!!! important - This action takes some time, do not interrupt. - -### wget.bat - -Calls PowerShell to download files. - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/scripts/environment/build-0-user-data-img.sh b/scripts/environment/build-0-user-data-img.sh new file mode 100644 index 000000000..8627a6a0d --- /dev/null +++ b/scripts/environment/build-0-user-data-img.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +source build-1-cloud-configs.sh + +source build-2-user-data-img-all.sh \ No newline at end of file diff --git a/scripts/environment/build-1-cloud-configs.sh b/scripts/environment/build-1-cloud-configs.sh new file mode 100644 index 000000000..019a67a69 --- /dev/null +++ b/scripts/environment/build-1-cloud-configs.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# Pack all files under scripts/ into a zip archive and insert this file +# into the cloud-config files as gzip base64 encoded text. + +# scripts.zip handling ---------------------------------------------------- +echo "___________________________________________________________" +rm scripts.zip +mkdir -p scripts/cloud-config/ && cp cloud-config scripts/cloud-config/ + +echo "Creating scripts.zip ..." + +# Add all files into one zip archive +zip -q -r scripts.zip scripts/ + +# Create search and replace text -------------------------------------------- +SEARCH_ZIP=insert-scripts.zip-here +SEARCH_SH=insert-check-cloud-init-log.sh-here + +# Cloud-init function write_files supports gzip format as base64 encoded text, so these steps are necessary: +# 1. Convert zip archive into gzip format. +# 2. Convert the gzip (binary) into base64 encoded text. +REPLACE_ZIP=$(gzip -c scripts.zip | base64 --wrap=0) +REPLACE_SH=$(base64 --wrap=0 check-cloud-init-log.sh) + +# amd64 handling ----------------------------------------------------------------- +ARCH=amd64 +ARCH_REMOVE=aarch64 +# Remove these lines +grep -v "#${ARCH_REMOVE}-ONLY" cloud-config >cloud-config-${ARCH}-generated +# Insert base64 encoded content +python3 replace-text.py cloud-config-${ARCH}-generated $SEARCH_ZIP $REPLACE_ZIP +python3 replace-text.py cloud-config-${ARCH}-generated $SEARCH_SH $REPLACE_SH +# Remove flags +python3 replace-text.py cloud-config-${ARCH}-generated "#${ARCH}-ONLY" " " + +# aarch64 (arm64) handling ----------------------------------------------------------------- +ARCH=aarch64 +ARCH_REMOVE=amd64 +# Remove these lines +grep -v "#${ARCH_REMOVE}-ONLY" cloud-config >cloud-config-${ARCH}-generated +# Insert base64 encoded content +python3 replace-text.py cloud-config-${ARCH}-generated $SEARCH_ZIP $REPLACE_ZIP +python3 replace-text.py cloud-config-${ARCH}-generated $SEARCH_SH $REPLACE_SH + +# Remove flags +python3 replace-text.py cloud-config-${ARCH}-generated "#${ARCH}-ONLY" " " diff --git a/scripts/environment/build-2-user-data-img-all.sh b/scripts/environment/build-2-user-data-img-all.sh new file mode 100644 index 000000000..76ca71c66 --- /dev/null +++ b/scripts/environment/build-2-user-data-img-all.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +source ./build-9-user-data-img.sh amd64 proxy +source ./build-9-user-data-img.sh amd64 noproxy +mv user-data-amd64-* builder/ + +source ./build-9-user-data-img.sh aarch64 proxy +source ./build-9-user-data-img.sh aarch64 noproxy diff --git a/scripts/environment/user-data-img-build.sh b/scripts/environment/build-9-user-data-img.sh similarity index 88% rename from scripts/environment/user-data-img-build.sh rename to scripts/environment/build-9-user-data-img.sh index 4109c4808..8326f57e3 100644 --- a/scripts/environment/user-data-img-build.sh +++ b/scripts/environment/build-9-user-data-img.sh @@ -3,7 +3,7 @@ # This script ... # - Installs the cloud-image-utils package if it's not installed # - Removes optionally proxy usage lines from a cloud-config file -# - Calls cloud-localds to compile a cloud-config file into a user data img file (ubuntu-20.04-server-cloudimg-aaa-user-data-ppp.img) +# - Calls cloud-localds to compile a cloud-config file into a user data img file (ubuntu-xx.yy-server-cloudimg-aaa-user-data-ppp.img) # were aaa is the CPU architecture 'amd64' or 'aarch64'and ppp 'proxy' or 'noproxy' # Usage: build-user-data-img.sh aaa ppp info help @@ -50,12 +50,11 @@ do done # Operating system ------------------------------------------------------------ -OS=ubuntu-20.04-server +OS=ubuntu-22.04-server # Ubuntu cloud image name ----------------------------------------------------- # The Ubunt version name U=${OS}-cloudimg -# Combined with architecture e.g. ubuntu-20.04-server-cloudimg-aarch64 UA=${U}-${ARCH} # Name of the Ubuntu cloud image file to be downloaded @@ -67,20 +66,19 @@ else fi # Architecture independent snapshot from cloud image -# e.g. ubuntu-20.04-server-cloudimg-snapshot.qcow2 -QCOW2=${UA}-snapshot-${PROXY}.qcow2 +QCOW2=${UA}-${PROXY}.qcow2 # cloud-config ---------------------------------------------------------------- -CC=cloud-config-amd64 +CC=cloud-config-amd64-generated if grep -q "ar" <<<${ARCH} then - CC=cloud-config-aarch64 + CC=cloud-config-aarch64-generated fi -CCG=${CC}-${PROXY}-generated +CCG=${CC}-${PROXY} # User data image created from cloud-config ----------------------------------- -UDIMG=${UA}-user-data-${PROXY}.img +UDIMG=user-data-${ARCH}-${PROXY}.img # Function(s) ################################################################# @@ -122,9 +120,12 @@ install_pkg cloud-image-utils if grep -q "no" <<<${PROXY} then - grep -v "#Remove-if-noproxy" $CC >$CCG + # Remove these lines + grep -v "#proxy-ONLY" $CC >$CCG else cp $CC $CCG + python3 replace-text.py $CCG "#proxy-ONLY" " " + fi # Create user-data-image diff --git a/scripts/environment/build.bat b/scripts/environment/build.bat deleted file mode 100644 index 1cfd75ba7..000000000 --- a/scripts/environment/build.bat +++ /dev/null @@ -1,58 +0,0 @@ -@echo off - -rem Parameters -rem CPU Architecture: amd64 (default), aarch64 -rem Use proxy usage: proxy (default), noproxy - -REM Remove 'REM' in the next two lines if you are using Px.exe as proxy server -REM set https_proxy=localhost:3128 -REM set http_proxy=localhost:3128 - -set OS=ubuntu-20.04-server - -set ARCH=amd64 -set PROXY=proxy - -set AR=ar -set NO=no - -rem https://stackoverflow.com/questions/7005951/batch-file-find-if-substring-is-in-string-not-in-a-file -for %%x in (%*) do ( - echo %%x - echo %%x | FINDSTR /C:%AR% >nul && ( set ARCH=aarch64) - echo %%x | FINDSTR /C:%NO% >nul && ( set PROXY=noproxy) -) - -:: Check cloud image file --------------------------------------------------- -set U=%OS%-cloudimg -set UA=%U%-%ARCH% -set IMG=%UA%.img -set QCOW2=%UA%-snapshot-%PROXY%.qcow2 -set UDIMG=%UA%-user-data-%PROXY%.img - -IF "%ARCH%" == "aarch64" ( -set IMG=%U%-arm64.img -) -if not exist %IMG% ( - call wget.bat https://cloud-images.ubuntu.com/releases/focal/release/%IMG% %IMG% -) - -if not exist %IMG% ( - echo ERROR: File '%IMG%' is missing - echo INFO: Download this file from 'https://cloud-images.ubuntu.com/releases/focal/release' and copy it into this directory - exit /B 1 -) - -:: Create snapshot file -------------------------------------------------------- -if not exist %QCOW2% ( - qemu-img create -b %IMG% -f qcow2 %QCOW2% -F qcow2 1T -) - -:: Check user data image file ------------------------------------------------- -if not exist %UDIMG% ( - echo ERROR: File '%UDIMG%' is missing - echo INFO: Copy this file from your SDK zip archive into this directory - exit /B 1 -) - -exit /B 0 diff --git a/scripts/environment/builder/README.md b/scripts/environment/builder/README.md new file mode 100644 index 000000000..1fbf9d92b --- /dev/null +++ b/scripts/environment/builder/README.md @@ -0,0 +1,111 @@ +# ctrlX App Build Environment Ubuntu 22.04 + +## Introduction + +This folder contains bat and image files to launch an App Build Environment with ctrlX WORKS under Windows operating system. +An App Build Environment is a Ubuntu Server guest operating running within a [QEMU](https://www.qemu.org/) virtual machine. + +The installation and configuration of the Ubuntu Server guest operating system is automatically done +on first boot by the build-in Ubuntu Cloud-Init Technology. For this purpose, a so-called user image file is specified when the App Build Environment is started. +This file contains the compiled information of a cloud-config file which is processed by the cloud-init service. + +For more informations see [cloud-init](https://cloud-init.io/) + +## Creating an App Build Environment Instance + +An instance of an App Build Environment is created by ctrlX WORKS. + +ctrlX WORKS copies a set of files into the specific destination directory. Depending on the option __Use HTTP and HTTPS proxy on localhost:3128__ a user-data-image file is used with or without proxy server information. + +## Working with an App Build Environment + +### Starting an App Build Environment for the first time + +An new created App Build Environment instance can be launched by clicking the '>' icon in ctrlX WORKS. + +Each time ctrlX WORKS generates the batch file start.bat. +Here the Windows environment variable PATH is extended so that the ctrlX WORKS internal QEMU installation will be used. Then launch.bat is called. + +launch.bat downloads the Ubuntu Server image, creates a snapshot file (.qcow2) and launches the QEMU executable. The image file remains unchanged, all changes are saved in the snapshot file. + +During startup the App Build Environment will be configured by the Ubuntu Cloud-Init Technology. Therefor the cloud-config file contained in the user-data-image file is used. + +In this initialization phase login is not possible. + +When this phase is finished, the guest operating system will automatically shut down and has to be restarted. + +### Restarting an App Build Environment + +The restart is initiated by clicking the '>' icon on the ctrlX WORKS UI. + +start.bat is called and the App Build Environment will start directly into the run phase. + +Logging in - directly or via SSH - is enabled. + +### Logging in + +We recommend to login in via SSH - using a RSA public / private key pair. + +A SSH session can be started by clicking the SSH link in ctrlX WORKS. Then open.bat will be created and called. + +### Shutdown + +The shutdown of the App Build Enviroment can triggered externally by clicking the stop icon in ctrlX WORKS. Then stop.bat is called, the guest operating system will shutdown and the App Build Environment will stop. + +### Deleting an App Build Environment + +Stop the App Build Enviroment and click the waste bin icon in ctrlX WORKS. + +### Working with Snapshots + +An App Build Enviroment always works with a base file and a snapshot file. The base file is never changed, all changes are stored into the snapshot file. + +When a new App Build Enviroment was created the ubuntu server image file (e.g. ubuntu-22.04-server-cloudimg-amd64.img) is the base file. + +`ubuntu-22.04-server-cloudimg-amd64.qcow2` is always the snap shot file. + +#### Creating a new Snapshot + +Creating a new snapshot file makes sense if you want to save a certain status of your App Build Environment. + +To do this just call: + + snapshot.bat + +The bat file converts the actual snapshot file into a base file `ubuntu-22.04-server-cloudimg-amd64-0.qcow2` and creates a new snapshot file `ubuntu-22.04-server-cloudimg-amd64.qcow2` will be created. + +This can be done several times, for each repetition the number in the base file name will be increased: 0, 1, 2, etc. + +#### Restoring a Snapshot + +You can restore an older snapshot manually: + +* Delete the actual snapshot file (or move to another direcory): `ubuntu-22.04-server-cloudimg-amd64.qcow2` +* Rename the base file you want to use into `ubuntu-22.04-server-cloudimg-amd64.qcow2` + +#### Increase the Virtual Size of the Snapshot File + +Per default a snapshot file has the virtual size of 32GB. +In case you want to increase this just call: + + increase-virtual-size.bat + +The virtual size is increased by 10GB. + +You can repeat this procudure if needed. + +## Windows Helper File wget.bat + +This batch file is used to download the Ubuntu Server image. Internally is uses the Windows PowerShell. + +!!! important + If using PowerShell is not possible this bat file can alternatively use Wget for Windows - see further instructions in [wget.bat](wget.bat). + +## Hints + +For the full set of files to run App Build Enviroments see the SDK folder [scripts/evironment](https://github.com/boschrexroth/ctrlx-automation-sdk/tree/main/scripts/environment) + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT diff --git a/scripts/environment/builder/increase-virtual-size.bat b/scripts/environment/builder/increase-virtual-size.bat new file mode 100644 index 000000000..69fdcd8bb --- /dev/null +++ b/scripts/environment/builder/increase-virtual-size.bat @@ -0,0 +1,28 @@ +@echo off + +setlocal +SET PATH=c:\Program Files\Rexroth\ctrlX WORKS\qemu;%PATH% +SET QCOW2=ubuntu-22.04-server-cloudimg-amd64.qcow2 + +CALL :SUB_INFO + +echo . +echo Increasing 'virtual size' by +10GB +echo . +timeout /t 20 + +qemu-img resize %QCOW2% +10G + +CALL :SUB_INFO + +timeout /t 20 + +goto EOF + +:SUB_INFO +echo --------------------------------------------------------- +qemu-img info %QCOW2% +echo --------------------------------------------------------- +EXIT /B + +:EOF diff --git a/scripts/environment/launch.bat b/scripts/environment/builder/launch.bat similarity index 60% rename from scripts/environment/launch.bat rename to scripts/environment/builder/launch.bat index 657f444f3..d7cc09cd6 100644 --- a/scripts/environment/launch.bat +++ b/scripts/environment/builder/launch.bat @@ -29,7 +29,54 @@ if exist *.qcow2 (set ACTIVITY= ) TITLE %NAME% %ACTIVITY% %CD% %ARCH% %PFW% -call build.bat %ARCH% %PROXY% +REM Desired Ubuntu version +set VERSION=22.04 + +set OS=ubuntu-%VERSION%-server + +set ARCH=amd64 +set PROXY=proxy + +set AR=ar +set NO=no + +rem https://stackoverflow.com/questions/7005951/batch-file-find-if-substring-is-in-string-not-in-a-file +for %%x in (%*) do ( + echo %%x + echo %%x | FINDSTR /C:%AR% >nul && ( set ARCH=aarch64) + echo %%x | FINDSTR /C:%NO% >nul && ( set PROXY=noproxy) +) + +:: Check cloud image file --------------------------------------------------- +set U=%OS%-cloudimg +set IMG=%U%-%ARCH%.img +set QCOW2=%U%-%ARCH%.qcow2 +set UDIMG=user-data-%ARCH%-%PROXY%.img + +IF "%ARCH%" == "aarch64" ( +set IMG=%U%-arm64.img +) +if not exist %IMG% ( + call wget.bat https://cloud-images.ubuntu.com/releases/%VERSION%/release/%IMG% %IMG% +) + +if not exist %IMG% ( + echo ERROR: File '%IMG%' is missing + echo INFO: Download this file from 'https://cloud-images.ubuntu.com/releases/%VERSION%/release' and copy it into this directory + exit /B 1 +) + +:: Create snapshot file -------------------------------------------------------- +if not exist %QCOW2% ( + qemu-img create -b %IMG% -f qcow2 %QCOW2% -F qcow2 32G +) + +:: Check user data image file ------------------------------------------------- +if not exist %UDIMG% ( + echo ERROR: File '%UDIMG%' is missing + echo INFO: Copy this file from your SDK zip archive into this directory + exit /B 1 +) REM wget.exe changes the title TITLE %NAME% %ACTIVITY% %CD% %ARCH% %PFW% diff --git a/scripts/environment/builder/snapshot.bat b/scripts/environment/builder/snapshot.bat new file mode 100644 index 000000000..74a562065 --- /dev/null +++ b/scripts/environment/builder/snapshot.bat @@ -0,0 +1,26 @@ +@echo off + +REM Moves the actual overlay file to a new backing file +REM and creates a new overlay file. + +setlocal +SET PATH=c:\Program Files\Rexroth\ctrlX WORKS\qemu;%PATH% +SET QCOW2=ubuntu-22.04-server-cloudimg-amd64.qcow2 + +REM Find filename for the new snapshot file +for /l %%x in (1, 1, 100) do ( + if not exist ubuntu-22.04-server-cloudimg-amd64-%%x.qcow2 ( + SET SNAPSHOT=ubuntu-22.04-server-cloudimg-amd64-%%x.qcow2 + goto SNAPSHOT_CREATE) +) + +:SNAPSHOT_CREATE +echo New snapshot %SNAPSHOT% +timeout 10 + + +REM The actual overlay file will become the backing file +move %QCOW2% %SNAPSHOT% + +REM Create a new overlay file +qemu-img create -F qcow2 -b %SNAPSHOT% -f qcow2 %QCOW2% diff --git a/scripts/environment/ubuntu-20.04-server-cloudimg-amd64-user-data-noproxy.img b/scripts/environment/builder/user-data-amd64-noproxy.img similarity index 96% rename from scripts/environment/ubuntu-20.04-server-cloudimg-amd64-user-data-noproxy.img rename to scripts/environment/builder/user-data-amd64-noproxy.img index cbccfea74..dcae68ddc 100644 Binary files a/scripts/environment/ubuntu-20.04-server-cloudimg-amd64-user-data-noproxy.img and b/scripts/environment/builder/user-data-amd64-noproxy.img differ diff --git a/scripts/environment/ubuntu-20.04-server-cloudimg-aarch64-user-data-proxy.img b/scripts/environment/builder/user-data-amd64-proxy.img similarity index 96% rename from scripts/environment/ubuntu-20.04-server-cloudimg-aarch64-user-data-proxy.img rename to scripts/environment/builder/user-data-amd64-proxy.img index a1f7c1053..6cf47d492 100644 Binary files a/scripts/environment/ubuntu-20.04-server-cloudimg-aarch64-user-data-proxy.img and b/scripts/environment/builder/user-data-amd64-proxy.img differ diff --git a/scripts/environment/builder/wget.bat b/scripts/environment/builder/wget.bat new file mode 100644 index 000000000..405e11b95 --- /dev/null +++ b/scripts/environment/builder/wget.bat @@ -0,0 +1,18 @@ +REM +REM Helper script to download an img file. +REM + +rmdir /S /Q img 2>nul +mkdir img + +echo Downloading %1 ... +Powershell.exe -command "(New-Object System.Net.WebClient).DownloadFile('%1','img\%2')" + +REM If using Powershell.exe is not possible: +REM - Download Wget for Windows e.g. from here: https://gnuwin32.sourceforge.net/packages/wget.htm +REM - Install it - do not forget adding the storage location to the PATH environment variable. +REM - Disable the line calling Powershell.exe with am REM or delete it. +REM - Enable following line by removing 'REM ' +REM wget.exe %1 -O img\%2 + +move img\%2 . \ No newline at end of file diff --git a/scripts/environment/check-cloud-init-log.sh b/scripts/environment/check-cloud-init-log.sh new file mode 100644 index 000000000..d26420ea6 --- /dev/null +++ b/scripts/environment/check-cloud-init-log.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +FILE=/var/log/cloud-init-output.log + +# Do not use $0 because '...bash...' is returned at login +SCRIPT_NAME=check-cloud-init-log.sh + +# Add/remove search patterns here +PATTERNS=( + "Could not connect" + "Unable to connect" + "Failed to fetch" + "failed to download" + "Unable to locate" + "is not available, but is referred to by another package" + "util.py[WARNING]:" +) + +echo " " +echo "=======================================================================" +echo "Searching for errors and warnings reported during initialization phase." +echo "=======================================================================" +echo " " + +read -t 5 -p "Hit ENTER to continue - cancel with Ctrl-C " + +# Search patterns +for PATTERN in "${PATTERNS[@]}"; do + ERRORS_WARNINGS=${ERRORS_WARNINGS}$(sudo grep -i "${PATTERN}" ${FILE}) +done + +# Calculate the length +ERRORS_WARNINGS_LEN=${#ERRORS_WARNINGS} + +if (( ERRORS_WARNINGS_LEN == 0)); then + echo " " + echo "--------------------------------------------------------------------------- " + echo " No errors/warnings were found." + echo "--------------------------------------------------------------------------- " + echo " " + + read -t 5 -p "Remove this check script from ~/.bashrc? Y/n" INPUT + + if grep -q "n" <<<${INPUT} + then + return 0 + fi + + # Remove line with containing the call of this script + sed -i /${SCRIPT_NAME}/d ~/.bashrc + + # Add enabled call + echo "# source /home/boschrexroth/${SCRIPT_NAME}" >>/home/boschrexroth/.bashrc + + return 0 +fi + +echo " " +echo "Errors/warnings ----------------------------------------------------------------" +echo " " + +for PATTERN in "${PATTERNS[@]}"; do + sudo grep -i "${PATTERN}" ${FILE} +done + +echo " " +echo "--------------------------------------------------------------------------------" +echo " " +echo " Errors/warnings that occurred during the initialization phase were found," +echo " we strongly recommend to discard this App Build Environment." +echo " " +echo " Before creating a new App Build Environment, please check these preconditions:" +echo " - Is there enough disk memory available on your host system? At least 50GB." +echo " - Is a working internet connection available?" +echo " - Is the Ubuntu APT repository mirror available?" +echo " - If a proxy is needed:" +echo " Is the proxy server on the host operating system running and available under port 3128?" +echo "--------------------------------------------------------------------------------" +echo " " + +return 1 + diff --git a/scripts/environment/cloud-config b/scripts/environment/cloud-config new file mode 100644 index 000000000..ff76f8318 --- /dev/null +++ b/scripts/environment/cloud-config @@ -0,0 +1,94 @@ +#cloud-config +hostname: app-build-env #amd64-ONLY +hostname: app-build-env-arm64 #aarch64-ONLY +chpasswd: { expire: False } +ssh_pwauth: True + +write_files: + - encoding: b64 + content: insert-check-cloud-init-log.sh-here + path: /tmp/cloud-config/check-cloud-init-log.sh + permissions: '0775' + + - encoding: gzip + content: !!binary | + insert-scripts.zip-here + path: /tmp/cloud-config/scripts.zip + permissions: '0554' + +# Proxy settings for apt #proxy-ONLY +apt: #proxy-ONLY + http_proxy: http://10.0.2.2:3128/ #proxy-ONLY + https_proxy: http://10.0.2.2:3128/ #proxy-ONLY + +package_update: true +package_upgrade: true + +# Install neccessary packages, will automatically set package_update: true, package_upgrade: true +packages: + - zip + - unzip + - p7zip-full + - git + - cifs-utils + - apt-transport-https + - build-essential + - crossbuild-essential-arm64 #amd64-ONLY + - gcc + - gdb-multiarch #amd64-ONLY + - gdb #aarch64-ONLY + - whois + - python3-pip + - virtualenv + - cmake + - net-tools + - pkg-config + - jq + - sshpass + - libsystemd-dev + - libzmq3-dev + - libssl-dev + +# Run commands on first boot +runcmd: + # Proxy settings for wget #proxy-ONLY + - echo "http_proxy = http://10.0.2.2:3128/" >> /etc/wgetrc #proxy-ONLY + - echo "https_proxy = http://10.0.2.2:3128/" >> /etc/wgetrc #proxy-ONLY + - echo "use_proxy = on" >> /etc/wgetrc #proxy-ONLY + + # Proxy settings for environment #proxy-ONLY + - echo "http_proxy=\"http://10.0.2.2:3128\"" >> /etc/environment #proxy-ONLY + - echo "https_proxy=\"http://10.0.2.2:3128\"" >> /etc/environment #proxy-ONLY + - echo "HTTP_PROXY=\"http://10.0.2.2:3128\"" >> /etc/environment #proxy-ONLY + - echo "HTTPS_PROXY=\"http://10.0.2.2:3128\"" >> /etc/environment #proxy-ONLY + - echo "no_proxy=localhost,127.0.0.1,10.0.2.2,.local" >> /etc/environment #proxy-ONLY + + # https://wiki.ubuntu.com/MultiarchSpec #amd64-ONLY + - dpkg --add-architecture arm64 #amd64-ONLY + - echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy main restricted universe" >> /etc/apt/sources.list.d/multiarch-libs.list #amd64-ONLY + - echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy-updates main restricted universe" >> /etc/apt/sources.list.d/multiarch-libs.list #amd64-ONLY + + # Qualify architecture #amd64-ONLY + - sed -i 's/deb http:/deb [arch=amd64] http:/g' /etc/apt/sources.list #amd64-ONLY + + # We create the user boschrexroth here in the very latest step of the initialization phase + # to avoid a too early login. + # Create user boschrexroth with password boschrexroth, home directory and sudo rights + - useradd -m -p $(openssl passwd -1 boschrexroth) -s /bin/bash -G sudo boschrexroth + # Enable sudo commands via SSH + - echo "boschrexroth ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/boschrexroth + + # Now move all written files to /home/boschrexroth/ and change their owner and group + - mv /tmp/cloud-config/* /home/boschrexroth/ + - unzip -d /home/boschrexroth/ /home/boschrexroth/scripts.zip && rm /home/boschrexroth/scripts.zip + - mkdir -p /home/boschrexroth/scripts/cloud-config/ + - cp /var/log/cloud-init*.log /home/boschrexroth/scripts/cloud-config/ + - chmod 664 /home/boschrexroth/scripts/cloud-config/*.log + - chown -R boschrexroth:boschrexroth /home/boschrexroth/* + - echo "source /home/boschrexroth/check-cloud-init-log.sh" >>/home/boschrexroth/.bashrc + +power_state: + mode: poweroff + message: ======================== Installation Finished ======================== + timeout: 30 + condition: True \ No newline at end of file diff --git a/scripts/environment/cloud-config-aarch64 b/scripts/environment/cloud-config-aarch64 deleted file mode 100644 index 304bfff12..000000000 --- a/scripts/environment/cloud-config-aarch64 +++ /dev/null @@ -1,218 +0,0 @@ -#cloud-config -hostname: app-builder-aarch64 -chpasswd: { expire: False } -ssh_pwauth: True - -write_files: - - content: | - #!/usr/bin/env bash - sudo snap install snapcraft --classic - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-snapcraft.sh - permissions: '0755' - - # Insert content of install-nodejs-npm.sh here - - content: | - #!/usr/bin/env bash - sudo snap install snapcraft --classic - - sudo snap install node --classic - npm config set prefix ${HOME}/npm - echo proxy=http://10.0.2.2:3128/ >> ~/.npmrc - echo https-proxy=https://10.0.2.2:3128/ >> ~/.npmrc - node --version - npm --version - - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-nodejs-npm.sh - permissions: '0755' - - # Insert content of install-go.sh here - - content: | - #!/usr/bin/env bash - sudo snap install snapcraft --classic - - sudo snap install go --classic - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-go.sh - permissions: '0755' - - # install-sdk.sh - - content: | - #!/usr/bin/env bash - - echo " " - echo "============================================" - echo Installing ctrlX AUTOMATION SDK from github - echo "============================================" - read -t 2 - - ZIP_ARCHIVE=ctrlx-automation-sdk-*.zip - if compgen -G ${ZIP_ARCHIVE} > /dev/null; then - read -p "${ZIP_ARCHIVE} exists, delete, exit or continue d/e/c?" USERS_INPUT - - if grep -q "d" <<<${USERS_INPUT}; then - rm ${ZIP_ARCHIVE} - fi - - - if grep -q "e" <<<${USERS_INPUT}; then - exit 1 - fi - fi - - LATEST=$(curl -s https://api.github.com/repos/boschrexroth/ctrlx-automation-sdk/releases/latest) - - if grep -q "limit exceeded" <<<${LATEST}; then - echo " " - echo ERROR - echo " " - echo ${LATEST} - echo " " - echo "Hint:" - echo This error happens often because a proxy server is used. - echo In this case github registered a hugh number of requests from the same machine. - echo " " - echo Workaround: - echo "- Download the zip archive from here https://github.com/boschrexroth/ctrlx-automation-sdk/releases" - echo "- Copy it into this directory." - echo "- Restart this script." - echo " " - read -p "Continue or exit c/e?" USERS_INPUT - if grep -q "e" <<<${USERS_INPUT}; then - exit 1 - fi - echo " " - else - # .assets[0].browser_download_url --> ctrlx-...zip - # .assets[1].browser_download_url --> ctrlx-...deb - sudo apt-get install jq -y - DOWNLOAD_URL=$(echo $LATEST | jq -r .assets[0].browser_download_url) - wget $DOWNLOAD_URL - fi - - if compgen -G ${ZIP_ARCHIVE} > /dev/null; then - unzip -XK $(ls ctrlx-automation-sdk-*.zip) - chmod a+x ctrlx-automation-sdk/bin/oss.flatbuffers*/ubuntu20-gcc-*/release/flatc - chmod a+x ctrlx-automation-sdk/bin/framework/ubuntu20-gcc-*/rexroth-automation-frame - chmod a+w -R ctrlx-automation-sdk/include - sudo chown -R boschrexroth:boschrexroth ctrlx-automation-sdk/fbs/comm/ethercat/master/ - sudo chown -R boschrexroth:boschrexroth ctrlx-automation-sdk/bfbs/comm/ethercat/master/ - sudo chmod 777 -R ctrlx-automation-sdk/fbs/comm/ethercat/master/ - sudo chmod 777 -R ctrlx-automation-sdk/bfbs/comm/ethercat/master/ - find ctrlx-automation-sdk/ -name '*.sh' -exec chmod +x {} \; - - cd ctrlx-automation-sdk/deb/ - source ~/install-ctrlx-datalayer-deb.sh - - else - echo "ERROR ${ZIP_ARCHIVE} does not exist" - fi - - echo " " - echo "============================================" - echo Installing snapcraft snap - echo "============================================" - - sudo snap install snapcraft --classic - source ~/install-deb.sh - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-sdk.sh - permissions: '0755' - - # install-ctrlx-datalayer-deb.sh - - content: | - #!/usr/bin/env bash - - DEP_PACKAGE=*.deb - - echo " " - echo "============================================" - echo Installing ${DEP_PACKAGE} - echo "============================================" - read -t 2 - - if compgen -G ${DEP_PACKAGE} > /dev/null; then - # Exists - # Install package containing required component dpkg-scanpackages - sudo apt-get install dpkg-dev - - # Install debian package locally so that 'apt-get install' will find it (for building sample project snaps) - dpkg-scanpackages -m . > Packages - - # Create full path - FULL_PATH=$(pwd) - # Add package to sources list - sudo sh -c "echo 'deb [trusted=yes] file:${FULL_PATH} ./' > /etc/apt/sources.list.d/ctrlx-automation.list" - # Use newest sources list - sudo apt update - - # Install newest ctrlx-datalayer package - sudo apt-get install -y ctrlx-datalayer - else - echo "ERROR ${DEP_PACKAGE} not found!" - fi - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-ctrlx-datalayer-deb.sh - permissions: '0755' - -# Proxy settings for apt #Remove-if-noproxy -apt: #Remove-if-noproxy - http_proxy: http://10.0.2.2:3128/ #Remove-if-noproxy - https_proxy: http://10.0.2.2:3128/ #Remove-if-noproxy - -package_update: true -package_upgrade: true - -# Install neccessary packages, will automatically set package_update: true, package_upgrade: true -packages: - - zip - - unzip - - p7zip-full - - git - - cifs-utils - - apt-transport-https - - build-essential - - gcc - - gdb - - whois - - python3-pip - - virtualenv - - cmake - - net-tools - - pkg-config - - libzmq3-dev - - libsystemd-dev - - libssl-dev - -# Run commands on first boot -runcmd: - # Proxy settings for wget #Remove-if-noproxy - - echo "http_proxy = http://10.0.2.2:3128/" >> /etc/wgetrc #Remove-if-noproxy - - echo "https_proxy = http://10.0.2.2:3128/" >> /etc/wgetrc #Remove-if-noproxy - - echo "use_proxy = on >> /etc/wgetrc" #Remove-if-noproxy - - # Proxy settings for environment #Remove-if-noproxy - - echo "http_proxy=\"http://10.0.2.2:3128\"" >> /etc/environment #Remove-if-noproxy - - echo "https_proxy=\"http://10.0.2.2:3128\"" >> /etc/environment #Remove-if-noproxy - - echo "HTTP_PROXY=\"http://10.0.2.2:3128\"" >> /etc/environment #Remove-if-noproxy - - echo "HTTPS_PROXY=\"http://10.0.2.2:3128\"" >> /etc/environment #Remove-if-noproxy - - echo "no_proxy=localhost,127.0.0.1,10.0.2.2,.local" >> /etc/environment #Remove-if-noproxy - - # We create the user boschrexroth here in the very latest step of the initialization phase - # to avoid a too early login. - # Create user boschrexroth with password boschrexroth, home directory and sudo rights - - useradd -m -p $(openssl passwd -1 boschrexroth) -s /bin/bash -G sudo boschrexroth - # Enable sudo commands via SSH - - echo "boschrexroth ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/boschrexroth - - # Now move install scripts to /home/boschrexroth and change owner and group - - mv /tmp/cloud-config/install-*.sh /home/boschrexroth - - chown boschrexroth:boschrexroth /home/boschrexroth/install-*.sh - - # Necessary because snapcraft cannot be installed directly after init phase -power_state: - mode: poweroff - message: ======================== Installation Finished ======================== - timeout: 30 - condition: True diff --git a/scripts/environment/cloud-config-amd64 b/scripts/environment/cloud-config-amd64 deleted file mode 100644 index 7e67933b2..000000000 --- a/scripts/environment/cloud-config-amd64 +++ /dev/null @@ -1,274 +0,0 @@ -#cloud-config -hostname: app-builder-amd64 -chpasswd: { expire: False } -ssh_pwauth: True - -write_files: - # install-snapcraft.sh - - content: | - #!/usr/bin/env bash - sudo snap install snapcraft --classic - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-snapcraft.sh - permissions: '0755' - - # install-dotnet-sdk - - content: | - #!/usr/bin/env bash - sudo snap install snapcraft --classic - - # Install as snap - #sudo snap install dotnet-sdk --classic - #sudo snap alias dotnet-sdk.dotnet dotnet - #sh -c 'echo "export DOTNET_ROOT=/snap/dotnet-sdk/current" >> /home/boschrexroth/.bashrc' - #export DOTNET_ROOT=/snap/dotnet-sdk/current - #sudo ln -sv /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet - - # Install as Debian Package - wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb - sudo dpkg -i packages-microsoft-prod.deb - rm packages-microsoft-prod.deb - sudo apt-get update - sudo apt-get install -y apt-transport-https - sudo apt-get update - sudo apt-get install -y dotnet-sdk-6.0 - dotnet --version - - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-dotnet-sdk.sh - permissions: '0755' - - # install-nodejs-npm.sh - - content: | - #!/usr/bin/env bash - sudo snap install snapcraft --classic - - sudo snap install node --classic - npm config set prefix ${HOME}/npm - echo proxy=http://10.0.2.2:3128/ >> ~/.npmrc - echo https-proxy=http://10.0.2.2:3128/ >> ~/.npmrc - node --version - npm --version - - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-nodejs-npm.sh - permissions: '0755' - - # install-go.sh - - content: | - #!/usr/bin/env bash - sudo snap install snapcraft --classic - - sudo snap install go --classic - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-go.sh - permissions: '0755' - - # install-sdk.sh - - content: | - #!/usr/bin/env bash - - echo " " - echo "============================================" - echo Installing ctrlX AUTOMATION SDK from github - echo "============================================" - read -t 2 - - ZIP_ARCHIVE=ctrlx-automation-sdk-*.zip - if compgen -G ${ZIP_ARCHIVE} > /dev/null; then - read -p "${ZIP_ARCHIVE} exists, delete, exit or continue d/e/c?" USERS_INPUT - - if grep -q "d" <<<${USERS_INPUT}; then - rm ${ZIP_ARCHIVE} - fi - - - if grep -q "e" <<<${USERS_INPUT}; then - exit 1 - fi - fi - - LATEST=$(curl -s https://api.github.com/repos/boschrexroth/ctrlx-automation-sdk/releases/latest) - - if grep -q "limit exceeded" <<<${LATEST}; then - echo " " - echo ERROR - echo " " - echo ${LATEST} - echo " " - echo "Hint:" - echo This error happens often because a proxy server is used. - echo In this case github registered a hugh number of requests from the same machine. - echo " " - echo Workaround: - echo "- Download the zip archive from here https://github.com/boschrexroth/ctrlx-automation-sdk/releases" - echo "- Copy it into this directory." - echo "- Restart this script." - echo " " - read -p "Continue or exit c/e?" USERS_INPUT - if grep -q "e" <<<${USERS_INPUT}; then - exit 1 - fi - echo " " - else - # .assets[0].browser_download_url --> ctrlx-...zip - # .assets[1].browser_download_url --> ctrlx-...deb - sudo apt-get install jq -y - DOWNLOAD_URL=$(echo $LATEST | jq -r .assets[0].browser_download_url) - wget $DOWNLOAD_URL - fi - - if compgen -G ${ZIP_ARCHIVE} > /dev/null; then - unzip -XK $(ls ctrlx-automation-sdk-*.zip) - chmod a+x ctrlx-automation-sdk/bin/oss.flatbuffers*/ubuntu20-gcc-*/release/flatc - chmod a+x ctrlx-automation-sdk/bin/framework/ubuntu20-gcc-*/rexroth-automation-frame - chmod a+w -R ctrlx-automation-sdk/include - sudo chown -R boschrexroth:boschrexroth ctrlx-automation-sdk/fbs/comm/ethercat/master/ - sudo chown -R boschrexroth:boschrexroth ctrlx-automation-sdk/bfbs/comm/ethercat/master/ - sudo chmod 777 -R ctrlx-automation-sdk/fbs/comm/ethercat/master/ - sudo chmod 777 -R ctrlx-automation-sdk/bfbs/comm/ethercat/master/ - find ctrlx-automation-sdk/ -name '*.sh' -exec chmod +x {} \; - - cd ctrlx-automation-sdk/deb/ - source ~/install-ctrlx-datalayer-deb.sh - - else - echo "ERROR ${ZIP_ARCHIVE} does not exist" - fi - - echo " " - echo "============================================" - echo Installing snapcraft snap - echo "============================================" - - sudo snap install snapcraft --classic - source ~/install-deb.sh - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-sdk.sh - permissions: '0755' - - # install-deb.sh - - content: | - #!/usr/bin/env bash - - echo " " - echo "============================================" - echo Installing required libraries - echo "============================================" - read -t 2 - - sudo apt-get -y update - sudo apt-get -y upgrade - sudo apt-get -y install libsystemd-dev:arm64 - sudo apt-get -y install libsystemd-dev:amd64 - sudo apt-get -y install libssl-dev:amd64 - sudo apt-get -y install libssl-dev:arm64 - sudo apt-get -y install libzmq3-dev:amd64 - sudo apt-get -y install libzmq3-dev:arm64 - - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-deb.sh - permissions: '0755' - - # install-ctrlx-datalayer-deb.sh - - content: | - #!/usr/bin/env bash - - DEP_PACKAGE=*.deb - - echo " " - echo "============================================" - echo Installing ${DEP_PACKAGE} - echo "============================================" - read -t 2 - - if compgen -G ${DEP_PACKAGE} > /dev/null; then - # Exists - # Install package containing required component dpkg-scanpackages - sudo apt-get install dpkg-dev - - # Install debian package locally so that 'apt-get install' will find it (for building sample project snaps) - dpkg-scanpackages -m . > Packages - - # Create full path - FULL_PATH=$(pwd) - # Add package to sources list - sudo sh -c "echo 'deb [trusted=yes] file:${FULL_PATH} ./' > /etc/apt/sources.list.d/ctrlx-automation.list" - # Use newest sources list - sudo apt update - - # Install newest ctrlx-datalayer package - sudo apt-get install -y ctrlx-datalayer - else - echo "ERROR ${DEP_PACKAGE} not found!" - fi - # Create in /tmp because /home/boschrexroth doesn't exists at this moment - path: /tmp/cloud-config/install-ctrlx-datalayer-deb.sh - permissions: '0755' - -# Proxy settings for apt #Remove-if-noproxy -apt: #Remove-if-noproxy - http_proxy: http://10.0.2.2:3128/ #Remove-if-noproxy - https_proxy: http://10.0.2.2:3128/ #Remove-if-noproxy - -package_update: true -package_upgrade: true - -# Install neccessary packages, will automatically set package_update: true, package_upgrade: true -packages: - - zip - - unzip - - p7zip-full - - git - - cifs-utils - - apt-transport-https - - build-essential - - crossbuild-essential-arm64 - - gcc - - gdb-multiarch - - whois - - python3-pip - - virtualenv - - cmake - - net-tools - - pkg-config - -# Run commands on first boot -runcmd: - # Proxy settings for wget #Remove-if-noproxy - - echo "http_proxy = http://10.0.2.2:3128/" >> /etc/wgetrc #Remove-if-noproxy - - echo "https_proxy = http://10.0.2.2:3128/" >> /etc/wgetrc #Remove-if-noproxy - - echo "use_proxy = on" >> /etc/wgetrc #Remove-if-noproxy - - # Proxy settings for environment #Remove-if-noproxy - - echo "http_proxy=\"http://10.0.2.2:3128\"" >> /etc/environment #Remove-if-noproxy - - echo "https_proxy=\"http://10.0.2.2:3128\"" >> /etc/environment #Remove-if-noproxy - - echo "HTTP_PROXY=\"http://10.0.2.2:3128\"" >> /etc/environment #Remove-if-noproxy - - echo "HTTPS_PROXY=\"http://10.0.2.2:3128\"" >> /etc/environment #Remove-if-noproxy - - echo "no_proxy=localhost,127.0.0.1,10.0.2.2,.local" >> /etc/environment #Remove-if-noproxy - - # https://wiki.ubuntu.com/MultiarchSpec - - dpkg --add-architecture arm64 - - echo "deb [arch=arm64] http://ports.ubuntu.com/ focal main restricted universe" >> /etc/apt/sources.list.d/multiarch-libs.list - - echo "deb [arch=arm64] http://ports.ubuntu.com/ focal-updates main restricted universe" >> /etc/apt/sources.list.d/multiarch-libs.list - # Qualify architecture - - sed -i 's/deb http:/deb [arch=amd64] http:/g' /etc/apt/sources.list - - # We create the user boschrexroth here in the very latest step of the initialization phase - # to avoid a too early login. - # Create user boschrexroth with password boschrexroth, home directory and sudo rights - - useradd -m -p $(openssl passwd -1 boschrexroth) -s /bin/bash -G sudo boschrexroth - # Enable sudo commands via SSH - - echo "boschrexroth ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/boschrexroth - - # Now move install scripts to /home/boschrexroth and change owner and group - - mv /tmp/cloud-config/install-*.sh /home/boschrexroth - - chown boschrexroth:boschrexroth /home/boschrexroth/install-*.sh - -# Necessary because snapcraft cannot be installed directly after init phase -power_state: - mode: poweroff - message: ======================== Installation Finished ======================== - timeout: 30 - condition: True - diff --git a/scripts/environment/install-qemu.sh b/scripts/environment/install-qemu.sh new file mode 100644 index 000000000..470a57ca9 --- /dev/null +++ b/scripts/environment/install-qemu.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +sudo apt update && upgrade + +# QEMU needs the virtualization daemon libvirt +sudo apt install -y libvirt-daemon +sudo systemctl enable libvirtd +sudo systemctl start libvirtd + +sudo apt install -y qemu-kvm +sudo apt install -y qemu-system-aarch64 diff --git a/scripts/environment/install-scripts/README.md b/scripts/environment/install-scripts/README.md deleted file mode 100644 index 585865f0a..000000000 --- a/scripts/environment/install-scripts/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Installation Sripts - -## Usage -__Important:__ - -These scripts should be used to install software in the VM. - -Some of them are used directly in the cloud-config-files so that they are available under /home/boschrexroth/ directory of the VM. - -## License - -MIT License - -Copyright (c) 2021-2022 Bosch Rexroth AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/scripts/environment/install-scripts/install-ctrlx-datalayer-deb.sh b/scripts/environment/install-scripts/install-ctrlx-datalayer-deb.sh deleted file mode 100644 index 8fa75cb5f..000000000 --- a/scripts/environment/install-scripts/install-ctrlx-datalayer-deb.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -DEP_PACKAGE=*.deb - -echo " " -echo "============================================" -echo Installing ${DEP_PACKAGE} -echo "============================================" -read -t 2 - -if compgen -G ${DEP_PACKAGE} > /dev/null; then - # Exists - # Install package containing required component dpkg-scanpackages - sudo apt-get install dpkg-dev - - # Install debian package locally so that 'apt-get install' will find it (for building sample project snaps) - dpkg-scanpackages -m . > Packages - - # Create full path - FULL_PATH=$(pwd) - # Add package to sources list - sudo sh -c "echo 'deb [trusted=yes] file:${FULL_PATH} ./' > /etc/apt/sources.list.d/ctrlx-automation.list" - # Use newest sources list - sudo apt update - - # Install newest ctrlx-datalayer package - sudo apt-get install -y ctrlx-datalayer -else - echo "ERROR ${DEP_PACKAGE} not found!" -fi diff --git a/scripts/environment/install-scripts/install-deb.sh b/scripts/environment/install-scripts/install-deb.sh deleted file mode 100644 index 6ba1c904c..000000000 --- a/scripts/environment/install-scripts/install-deb.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -echo " " -echo "============================================" -echo Installing required libraries -echo "============================================" -read -t 2 - -sudo apt-get -y update -sudo apt-get -y upgrade -sudo apt-get -y install libsystemd-dev:arm64 -sudo apt-get -y install libsystemd-dev:amd64 -sudo apt-get -y install libssl-dev:amd64 -sudo apt-get -y install libssl-dev:arm64 -sudo apt-get -y install libzmq3-dev:amd64 -sudo apt-get -y install libzmq3-dev:arm64 diff --git a/scripts/environment/install-scripts/install-nodejs-npm-from-binary-archive.sh b/scripts/environment/install-scripts/install-nodejs-npm-from-binary-archive.sh deleted file mode 100644 index b53ec82cd..000000000 --- a/scripts/environment/install-scripts/install-nodejs-npm-from-binary-archive.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash - -# Installs node.js and npm on the virtual machine - -# Uninstall an install snap -sudo snap remove node - -# TODO: Check/change the version -VERSION=v16.13.2 - -ARCH=`uname -p` -ARCH_OK=no - -if grep -q "x86_64" <<<${ARCH}; then - ARCH=x64 - ARCH_OK=yes -fi - -if grep -q "aarch64" <<<${ARCH}; then - ARCH=arm64 - ARCH_OK=yes -fi - -if grep -q "no" <<<${ARCH_OK}; then - echo ERROR: Unknown processor type $ARCH - exit 1 -fi - -DISTRO=linux-${ARCH} -NODE=node-${VERSION}-${DISTRO} -ARCHIVE=${NODE}.tar.xz -EXPORT_CMD=export' 'PATH=/usr/local/lib/nodejs/${NODE}/bin -PROFILE=~/.profile -NODEJS_DIR=/usr/local/lib/nodejs -URL=https://nodejs.org/dist/${VERSION}/${ARCHIVE} - -if [ ! -f ${ARCHIVE} ]; then - echo Downloading $URL - read -p "OK? Waiting 10s ..." -t 10 - - wget $URL - EXIT_CODE=$? - if [ ! $EXIT_CODE -eq 0 ] - then - echo ERROR: Downloading $URL failed with exit code $EXIT_CODE - exit $EXIT_CODE - fi -fi - -echo Installing content of $ARCHIVE to $NODEJS_DIR -read -p "OK? Waiting 10s ..." -t 10 - -sudo rm -rf $NODEJS_DIR -sudo mkdir -p $NODEJS_DIR -sudo tar -xJvf ${ARCHIVE} -C $NODEJS_DIR - -if [ ! -f $PROFILE ]; then - echo Creating ${PROFILE} - echo '# Created by install-nodejs-npm.sh' >${PROFILE} -fi - -if ! grep -q $NODE $PROFILE -then - # Add two line feeds - echo Appending $EXPORT_CMD:'$PATH' to $PROFILE - read -p "OK? Waiting 10s ..." -t 10 - sed -i -z 's/$/\n\n/g' $PROFILE - echo $EXPORT_CMD:'$PATH' >>${PROFILE} - cat $PROFILE - . ~/.profile - echo $PATH changed: $PATH -fi - -echo -echo Done: ${NODEJS_DIR}/${NODE}/ installed -node --version -echo \ No newline at end of file diff --git a/scripts/environment/install-scripts/install-sdk.sh b/scripts/environment/install-scripts/install-sdk.sh deleted file mode 100644 index bb9550eb3..000000000 --- a/scripts/environment/install-scripts/install-sdk.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash - -echo " " -echo "============================================" -echo Installing ctrlX AUTOMATION SDK from github -echo "============================================" -read -t 2 - -ZIP_ARCHIVE=ctrlx-automation-sdk-*.zip -if compgen -G ${ZIP_ARCHIVE} > /dev/null; then - read -p "${ZIP_ARCHIVE} exists, delete, exit or continue d/e/c?" USERS_INPUT - - if grep -q "d" <<<${USERS_INPUT}; then - rm ${ZIP_ARCHIVE} - fi - - - if grep -q "e" <<<${USERS_INPUT}; then - exit 1 - fi -fi - -LATEST=$(curl -s https://api.github.com/repos/boschrexroth/ctrlx-automation-sdk/releases/latest) - -if grep -q "limit exceeded" <<<${LATEST}; then - echo " " - echo ERROR - echo " " - echo ${LATEST} - echo " " - echo "Hint:" - echo This error happens often because a proxy server is used. - echo In this case github registered a hugh number of requests from the same machine. - echo " " - echo Workaround: - echo "- Download the zip archive from here https://github.com/boschrexroth/ctrlx-automation-sdk/releases" - echo "- Copy it into this directory." - echo "- Restart this script." - echo " " - read -p "Continue or exit c/e?" USERS_INPUT - if grep -q "e" <<<${USERS_INPUT}; then - exit 1 - fi - echo " " -else - # .assets[0].browser_download_url --> ctrlx-...zip - # .assets[1].browser_download_url --> ctrlx-...deb - sudo apt-get install jq -y - DOWNLOAD_URL=$(echo $LATEST | jq -r .assets[0].browser_download_url) - wget $DOWNLOAD_URL -fi - -if compgen -G ${ZIP_ARCHIVE} > /dev/null; then - unzip -XK $(ls ctrlx-automation-sdk-*.zip) - chmod a+x ctrlx-automation-sdk/bin/oss.flatbuffers*/ubuntu20-gcc-*/release/flatc - chmod a+x ctrlx-automation-sdk/bin/framework/ubuntu20-gcc-*/rexroth-automation-frame - chmod a+w -R ctrlx-automation-sdk/include - sudo chown -R boschrexroth:boschrexroth ctrlx-automation-sdk/fbs/comm/ethercat/master/ - sudo chown -R boschrexroth:boschrexroth ctrlx-automation-sdk/bfbs/comm/ethercat/master/ - sudo chmod 777 -R ctrlx-automation-sdk/fbs/comm/ethercat/master/ - sudo chmod 777 -R ctrlx-automation-sdk/bfbs/comm/ethercat/master/ - find ctrlx-automation-sdk/ -name '*.sh' -exec chmod +x {} \; - - cd ctrlx-automation-sdk/deb/ - source ~/install-ctrlx-datalayer-deb.sh - -else - echo "ERROR ${ZIP_ARCHIVE} does not exist" -fi - -echo " " -echo "============================================" -echo Installing snapcraft snap -echo "============================================" - -sudo snap install snapcraft --classic -source ~/install-deb.sh - - - diff --git a/scripts/environment/launch-aarch64-noproxy.sh b/scripts/environment/launch-aarch64-noproxy.sh new file mode 100644 index 000000000..5c8278cc5 --- /dev/null +++ b/scripts/environment/launch-aarch64-noproxy.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +source ./launch.sh aarch64 noproxy \ No newline at end of file diff --git a/scripts/environment/launch-aarch64-proxy.sh b/scripts/environment/launch-aarch64-proxy.sh new file mode 100644 index 000000000..d5a91dc81 --- /dev/null +++ b/scripts/environment/launch-aarch64-proxy.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +source ./launch.sh aarch64 proxy \ No newline at end of file diff --git a/scripts/environment/launch-amd64-noproxy.sh b/scripts/environment/launch-amd64-noproxy.sh new file mode 100644 index 000000000..5a345972b --- /dev/null +++ b/scripts/environment/launch-amd64-noproxy.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +source ./launch.sh amd64 noproxy \ No newline at end of file diff --git a/scripts/environment/launch-amd64-proxy.sh b/scripts/environment/launch-amd64-proxy.sh new file mode 100644 index 000000000..d3a96242f --- /dev/null +++ b/scripts/environment/launch-amd64-proxy.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +source ./launch.sh amd64 proxy \ No newline at end of file diff --git a/scripts/environment/launch.sh b/scripts/environment/launch.sh new file mode 100644 index 000000000..283908f92 --- /dev/null +++ b/scripts/environment/launch.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash + +# $1 Guest System CPU Architecture : amd64 (default), aarch64 +# $2 Proxy usage: proxy (default), no-proxy + +# Set variables ######################################################## +ARCH=amd64 +PROXY=proxy + +# Scan parameter list +for PARAM in "$@" +do + if grep -q "ar" <<<${PARAM}; then + ARCH=aarch64 + fi + + if grep -q "no" <<<${PARAM}; then + PROXY=noproxy + fi + +done + +# Operating system ------------------------------------------------------------ +VERSION=22.04 + +OS=ubuntu-${VERSION}-server + +# Ubuntu cloud image name ----------------------------------------------------- +U=${OS}-cloudimg +UA=${U}-${ARCH} + +# Name of the Ubuntu cloud image file to be downloaded +if grep -q "ar" <<<${ARCH} +then + IMG=${U}-arm64.img +else + IMG=${U}-amd64.img +fi + +# Architecture independent snapshot from cloud image +QCOW2=${UA}-${PROXY}.qcow2 + +# User data image created from cloud-config ----------------------------------- +UDIMG=user-data-${ARCH}-${PROXY}.img + +# aarch64 only: Download QEMU_EFI.fd ########################################## +if grep -q "ar" <<<${ARCH} +then + if [ ! -f QEMU_EFI.fd ]; then + wget --no-check-certificate -q --show-progress https://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/QEMU_EFI.fd + fi +fi + +# Download Ubuntu cloud image file ########################################## +if [ ! -f $IMG ]; then + rm -rf img 2>/dev/null + mkdir img + wget -q --show-progress https://cloud-images.ubuntu.com/releases/${VERSION}/release/$IMG -O img/$IMG + mv -f img/$IMG . +fi + +# Create snapshot file ###################################################### +if [ ! -f $QCOW2 ]; then + qemu-img create -f qcow2 -b $IMG -F qcow2 $QCOW2 32G +fi + +# EMULATED aarch64 Guest System: -cpu cortex-a57 +if grep -q "ar" <<<${ARCH} +then + qemu-system-aarch64 \ + -M virt \ + -cpu cortex-a57 \ + -accel kvm \ + -accel xen \ + -accel tcg \ + -smp 4 \ + -m 4G \ + -bios QEMU_EFI.fd \ + -netdev user,id=eth0,hostfwd=tcp::10022-:22 \ + -device virtio-net-pci,netdev=eth0,mac=DE-AD-BE-00-00-01 \ + -drive file="$QCOW2",format=qcow2 \ + -drive file="$UDIMG",format=raw \ + -display none \ + -nographic \ + ; + + exit $? +fi + +# amd64 Guest System +if grep -q "am" <<<${ARCH} +then + qemu-system-x86_64 \ + -machine q35,accel=kvm:xen:tcg \ + -smp 4 \ + -m 4G \ + -netdev user,id=eth0,hostfwd=tcp::10022-:22 \ + -device virtio-net-pci,netdev=eth0,mac=DE-AD-BE-00-00-01 \ + -drive file="$QCOW2",format=qcow2 \ + -drive file="$UDIMG",format=raw \ + -display none \ + -nographic \ + ; + + exit $? +fi + +echo "Wrong CPU Architecture specified:" $ARCH +exit 1 diff --git a/scripts/environment/replace-text.py b/scripts/environment/replace-text.py new file mode 100644 index 000000000..42e461b83 --- /dev/null +++ b/scripts/environment/replace-text.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +# Helper script to search and replace arbitrary strings (including special characters) + +import sys + +filename = sys.argv[1] +search = sys.argv[2] +replace = sys.argv[3] + +print ("___________________________________________________________") +print ("Filename:",filename) +print ("Searching:", search) +print ("Replacing:", replace[:10], " ...") + +f = open(filename, 'r') +data = f.read() +f.close() + +data = data.replace(search, replace) + +f = open(filename, 'w') +f.write(data) +f.close() + diff --git a/scripts/environment/scripts/README.md b/scripts/environment/scripts/README.md new file mode 100644 index 000000000..c05cdb426 --- /dev/null +++ b/scripts/environment/scripts/README.md @@ -0,0 +1,27 @@ +# Sub folder 'scripts' + +This folder contains scripts to install the ctrlX AUTOMATION SDK and programming language dependend packages to develop apps. + +## Script Files + +* __install-sdk.sh__ downloads ctrlX AUTOMATION SDK from github and installs it. Calls internally install-snapcraft.sh and uses download-sdk.sh +* __install-go.sh__ downloads and installs required packages to develop snaps with go +* __install-dotnet-sdk.sh__ downloads and installs required packages to develop snaps with dotnet +* __install-nodejs-npm.sh__ downloads and installs required packages to develop snaps with Node.js +* __install-snapcraft.sh__ installs snapcraft to build snaps +* __install-ctrlx-datalayer-deb.sh__ installs the content of the package ctrlx-datalayer.deb which is used for ctrlX Data Layer connections and registers the folder from which the script is called as local source. +* __install-cpp-aarch64-libs.sh__ downloads and installs required aarch64 libraries for cross build - __for cpp projects only.__ +* __install-ctrlx-os-dev-tools.sh__ downloads and installs required packages to build a ctrlX OS image +* download-sdk.sh Helper script to download the ctrlX AUTOMATION SDK zip archive + +## Sub folder 'cloud-config' + +This folder contains the origin cloud-config file. The information provided here can be used to setup a custom specific build environment. + +__Important__: Settings/packages for amd64 based environments only are marked with '#amd64-ONLY', for arm64 (aarch64) based only with '#aarch64-ONLY'. + + +## License + +SPDX-FileCopyrightText: Bosch Rexroth AG +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/scripts/environment/scripts/download-sdk.sh b/scripts/environment/scripts/download-sdk.sh new file mode 100644 index 000000000..c26b05829 --- /dev/null +++ b/scripts/environment/scripts/download-sdk.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +echo " " +echo Downloading ctrlX AUTOMATION SDK from github +echo " " + +LATEST=$(curl -s https://api.github.com/repos/boschrexroth/ctrlx-automation-sdk/releases/latest) + +if grep -q "limit exceeded" <<<${LATEST}; then + # Providing a dummy user/token can avoid the limit exceeded problem + LATEST=$(curl -s -u xx:yy https://api.github.com/repos/boschrexroth/ctrlx-automation-sdk/releases/latest) +fi + +if grep -q "limit exceeded" <<<${LATEST}; then + echo " " + echo ERROR + echo " " + echo ${LATEST} + echo " " + echo "Hint:" + echo "This error can happen on an unauthenticated request and if a proxy server is used." + echo "In this case, github has registered too many requests from the same machine." + echo " " + echo "To avoid this please provide your github username and an access token." + echo "See - https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token" + echo " " + echo "Enter your github user and token - or ctrl-c to exit" + read -p "github user: " GITHUB_USER + read -s -p "github token: " GITHUB_TOKEN + echo " " + LATEST=$(curl -s -u ${GITHUB_USER}:${GITHUB_TOKEN} https://api.github.com/repos/boschrexroth/ctrlx-automation-sdk/releases/latest) + echo " " +fi + +if grep -q "limit exceeded" <<<${LATEST}; then + echo " " + echo ERROR + echo " " + echo ${LATEST} + echo " " + echo "Recommended workaround:" + echo "- Download the zip archive manually from here https://github.com/boschrexroth/ctrlx-automation-sdk/releases" + echo "- Restart install-sdk.sh" + echo " " + exit 1 +fi + +# .assets[0].browser_download_url --> ctrlx-...zip +# .assets[1].browser_download_url --> ctrlx-...deb +DOWNLOAD_URL=$(echo $LATEST | jq -r .assets[0].browser_download_url) +wget $DOWNLOAD_URL diff --git a/scripts/environment/scripts/install-cpp-aarch64-libs.sh b/scripts/environment/scripts/install-cpp-aarch64-libs.sh new file mode 100644 index 000000000..649386f44 --- /dev/null +++ b/scripts/environment/scripts/install-cpp-aarch64-libs.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# AMD64 only: If not installed the required arm64 libraries are installed. + +ARCH=$(uname -m) +if grep -q "aarch64" <<<${ARCH} +then + exit 0 +fi + +sudo apt-get -y update + +sudo apt-get -y install libsystemd-dev:arm64 +sudo apt-get -y install libssl-dev:arm64 +sudo apt-get -y install libzmq3-dev:arm64 + + diff --git a/scripts/environment/scripts/install-ctrlx-datalayer-deb.sh b/scripts/environment/scripts/install-ctrlx-datalayer-deb.sh new file mode 100644 index 000000000..42f4726bd --- /dev/null +++ b/scripts/environment/scripts/install-ctrlx-datalayer-deb.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +DEP_PACKAGE=*.deb +DEP_DIR=/etc/apt/ctrlx-datalayer + +echo " " +echo "==================================================================================" +echo Installing ${DEP_PACKAGE} into ${DEP_DIR} +echo "==================================================================================" +echo " " + +if compgen -G ${DEP_PACKAGE} > /dev/null; then + # Exists + # Install package containing required component dpkg-scanpackages + sudo apt install -y dpkg-dev + + # Install debian package as source locally + sudo dpkg-scanpackages -m . > Packages + + sudo mkdir -p ${DEP_DIR} + sudo cp ${DEP_PACKAGE} ${DEP_DIR} + sudo mv Packages ${DEP_DIR} + + # Add package to sources list + sudo sh -c "echo 'deb [trusted=yes] file:${DEP_DIR} ./' > /etc/apt/sources.list.d/ctrlx-automation.list" + + # Use newest sources list + sudo apt update + + # Install newest ctrlx-datalayer package + sudo apt-get install -y ctrlx-datalayer +else + echo "ERROR ${DEP_PACKAGE} not found!" +fi diff --git a/scripts/environment/scripts/install-ctrlx-os-dev-tools.sh b/scripts/environment/scripts/install-ctrlx-os-dev-tools.sh new file mode 100644 index 000000000..38df94886 --- /dev/null +++ b/scripts/environment/scripts/install-ctrlx-os-dev-tools.sh @@ -0,0 +1,19 @@ +echo " " +echo "============================================" +echo Adding required apt sources +echo "============================================" +echo " " + +sudo add-apt-repository -y ppa:snappy-dev/image + +source ~/scripts/install-snapcraft.sh + +source ~/scripts/install-go.sh + +echo " " +echo "============================================" +echo Installing ubuntu-image snap +echo "============================================" +echo " " + +sudo snap install ubuntu-image --classic diff --git a/scripts/environment/scripts/install-dotnet-sdk.sh b/scripts/environment/scripts/install-dotnet-sdk.sh new file mode 100644 index 000000000..f085e7911 --- /dev/null +++ b/scripts/environment/scripts/install-dotnet-sdk.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +echo " " +echo "============================================" +echo Installing dotnet-sdk +echo "============================================" +echo " " + +# Install as snap +#sudo snap install dotnet-sdk --classic +#sudo snap alias dotnet-sdk.dotnet dotnet +#sh -c 'echo "export DOTNET_ROOT=/snap/dotnet-sdk/current" >> /home/boschrexroth/.bashrc' +#export DOTNET_ROOT=/snap/dotnet-sdk/current +#sudo ln -sv /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet + +# Install as Debian Package +wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb +sudo dpkg -i packages-microsoft-prod.deb +rm packages-microsoft-prod.deb +sudo apt-get update +sudo apt-get install -y dotnet-sdk-6.0 +dotnet --version + +source ~/scripts/install-snapcraft.sh diff --git a/scripts/environment/scripts/install-go.sh b/scripts/environment/scripts/install-go.sh new file mode 100644 index 000000000..7d71c3eeb --- /dev/null +++ b/scripts/environment/scripts/install-go.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +echo " " +echo "============================================" +echo Installing go +echo "============================================" +echo " " + +sudo snap install go --classic \ No newline at end of file diff --git a/scripts/environment/scripts/install-nodejs-npm.sh b/scripts/environment/scripts/install-nodejs-npm.sh new file mode 100644 index 000000000..6e9db5d64 --- /dev/null +++ b/scripts/environment/scripts/install-nodejs-npm.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +echo " " +echo "============================================" +echo Installing node.js and npm +echo "============================================" +echo " " + +sudo snap install node --classic +npm config set prefix ${HOME}/npm +echo proxy=http://10.0.2.2:3128/ >> ~/.npmrc +echo https-proxy=http://10.0.2.2:3128/ >> ~/.npmrc +node --version +npm --version + +source ~/scripts/install-snapcraft.sh diff --git a/scripts/environment/scripts/install-sdk.sh b/scripts/environment/scripts/install-sdk.sh new file mode 100644 index 000000000..34d9bbe0b --- /dev/null +++ b/scripts/environment/scripts/install-sdk.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +echo " " +echo "============================================" +echo Installing ctrlX AUTOMATION SDK +echo "============================================" +echo " " + +ZIP_ARCHIVE=ctrlx-automation-sdk-*.zip +if compgen -G ${ZIP_ARCHIVE} > /dev/null; then + read -p "${ZIP_ARCHIVE} exists! Delete, exit or continue: d e c? " USERS_INPUT + + if grep -q "e" <<<${USERS_INPUT}; then + exit 1 + fi + + if grep -q "d" <<<${USERS_INPUT}; then + rm ${ZIP_ARCHIVE} + fi +fi + +if compgen -G ${ZIP_ARCHIVE} > /dev/null; then + # OK it exists + echo " " +else + source ~/scripts/download-sdk.sh +fi + +if compgen -G ${ZIP_ARCHIVE} > /dev/null; then + + unzip -XK $(ls ctrlx-automation-sdk-*.zip) + chmod a+x ctrlx-automation-sdk/bin/oss.flatbuffers*/ubuntu22-gcc-*/release/flatc + chmod a+x ctrlx-automation-sdk/bin/framework/ubuntu22-gcc-*/rexroth-automation-frame + chmod a+w -R ctrlx-automation-sdk/include + + find ctrlx-automation-sdk/ -name '*.sh' -exec chmod +x {} \; + + cd ctrlx-automation-sdk/deb/ + source ~/scripts/install-ctrlx-datalayer-deb.sh + +else + echo "ERROR ${ZIP_ARCHIVE} does not exist" +fi + +source ~/scripts/install-snapcraft.sh + diff --git a/scripts/environment/scripts/install-snapcraft.sh b/scripts/environment/scripts/install-snapcraft.sh new file mode 100644 index 000000000..8de9b9f13 --- /dev/null +++ b/scripts/environment/scripts/install-snapcraft.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +echo " " +echo "============================================" +echo Installing snapcraft +echo "============================================" +echo " " + +sudo snap install snapcraft --channel=6.x/stable --classic + diff --git a/scripts/environment/shrink-qcow2.bat b/scripts/environment/shrink-qcow2.bat index d7bd52f4f..5dd74e414 100644 --- a/scripts/environment/shrink-qcow2.bat +++ b/scripts/environment/shrink-qcow2.bat @@ -1,7 +1,7 @@ @echo off echo. -echo App Builder Enviromment file: +echo App Build Enviromment file: dir /B ubuntu*.qcow2 echo. echo ----------------------------------------------------------------- diff --git a/scripts/environment/snapshot.sh b/scripts/environment/snapshot.sh new file mode 100644 index 000000000..5f36ccc0c --- /dev/null +++ b/scripts/environment/snapshot.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Moves the actual overlay file to a new backing file +# and creates a new overlay file. + +VERSION=22.04 + +# amd64|arm64 +ARCH=amd64 + +#proxy|noproxy +PROXY=noproxy + +QCOW2=ubuntu-${VERSION}-server-cloudimg-${ARCH}-${PROXY}.qcow2 + +for i in $(seq 1 100); +do + SNAPSHOT=ubuntu-${VERSION}-server-cloudimg-${ARCH}-${PROXY}-$i.qcow2 + if [ ! -f ${SNAPSHOT} ] + then + # File does not exist + break + fi +done + +echo mv ${QCOW2} ${SNAPSHOT} + +# The actual overlay file will become the backing file +mv ${QCOW2} ${SNAPSHOT} + +# Create a new overlay file +qemu-img create -F qcow2 -b ${SNAPSHOT} -f qcow2 ${QCOW2} diff --git a/scripts/environment/ssh-keygen-copy-id.bat b/scripts/environment/ssh-keygen-copy-id.bat index b77c284d4..6bf555d41 100644 --- a/scripts/environment/ssh-keygen-copy-id.bat +++ b/scripts/environment/ssh-keygen-copy-id.bat @@ -1,25 +1,37 @@ @echo off -REM -REM Helper script to setup a (new) ssh connection. -REM IMPORTANT: -REM This script can be used if ssh.exe denies a connection to a 'known host' with another foot print. -REM +echo ======================================================================= +echo Helper script to add the users public key on the host operating system +echo located in %USERPROFILE%\.ssh\id_rsa.pub +echo to /home/boschrexroth/.ssh/authorized_keys of the App Build Environment +echo ======================================================================= + + +REM IP address of the host machine is fix 127.0.0.1 set HOST=127.0.0.1 -set /p HOST=Host (%HOST%): set SSHPORT=10022 -set /p SSHPORT=SSHPORT (%SSHPORT%): +set /p SSHPORT=Enter forwarded SSH port (%SSHPORT%): +REM The user name within an App Build environment is fix boschrexroth set USER=boschrexroth -set /p USER=User (%USER%): -REM Delete an existing entry in .ssh\known_hosts according Host and Port -ssh-keygen.exe -R [%HOST%]:%SSHPORT% +REM Delete an existing entry in %USERPROFILE%\.ssh\known_hosts +REM regarding the SSH connection to the App Build Enviroment +ssh-keygen.exe -R [%HOST%]:%SSHPORT% 2> nul + +echo Appending %USERPROFILE%\.ssh\id_rsa.pub to /home/boschrexroth/.ssh/authorized_keys on t -REM Append content of .ssh\id_rsa.pub to .ssh/authorized_keys on the destination system -REM Hint: Delete duplicate lines in .ssh/authorized_keys ssh -o "StrictHostKeyChecking no" -p %SSHPORT% %USER%@%HOST% mkdir -p ~/.ssh/ type %USERPROFILE%\.ssh\id_rsa.pub | ssh -o "StrictHostKeyChecking no" -p %SSHPORT% %USER%@%HOST% "cat >> ~/.ssh/authorized_keys" +ssh -o "StrictHostKeyChecking no" -p %SSHPORT% %USER%@%HOST% "chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys" + +REM Removing duplicate entries from /home/boschrexroth/.ssh/authorized_keys +ssh -o "StrictHostKeyChecking no" -p %SSHPORT% %USER%@%HOST% "sort ~/.ssh/authorized_keys | uniq > ~/.ssh/authorized_keys.uniq" +ssh -o "StrictHostKeyChecking no" -p %SSHPORT% %USER%@%HOST% "mv ~/.ssh/authorized_keys{.uniq,}" + +echo Content of /home/boschrexroth/.ssh/authorized_keys ---------------------------------------------------------------- +ssh -o "StrictHostKeyChecking no" -p %SSHPORT% %USER%@%HOST% "cat ~/.ssh/authorized_keys" +echo -------------------------------------------------------------------------------------------------- pause \ No newline at end of file diff --git a/scripts/environment/ubuntu-20.04-server-cloudimg-aarch64-user-data-noproxy.img b/scripts/environment/user-data-aarch64-noproxy.img similarity index 96% rename from scripts/environment/ubuntu-20.04-server-cloudimg-aarch64-user-data-noproxy.img rename to scripts/environment/user-data-aarch64-noproxy.img index 18674582e..64454786a 100644 Binary files a/scripts/environment/ubuntu-20.04-server-cloudimg-aarch64-user-data-noproxy.img and b/scripts/environment/user-data-aarch64-noproxy.img differ diff --git a/scripts/environment/ubuntu-20.04-server-cloudimg-amd64-user-data-proxy.img b/scripts/environment/user-data-aarch64-proxy.img similarity index 96% rename from scripts/environment/ubuntu-20.04-server-cloudimg-amd64-user-data-proxy.img rename to scripts/environment/user-data-aarch64-proxy.img index 936237178..0b9f82881 100644 Binary files a/scripts/environment/ubuntu-20.04-server-cloudimg-amd64-user-data-proxy.img and b/scripts/environment/user-data-aarch64-proxy.img differ diff --git a/scripts/environment/user-data-img-build-all.sh b/scripts/environment/user-data-img-build-all.sh deleted file mode 100644 index b51fec371..000000000 --- a/scripts/environment/user-data-img-build-all.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -source ./user-data-img-build.sh amd64 proxy -source ./user-data-img-build.sh amd64 noproxy -source ./user-data-img-build.sh aarch64 proxy -source ./user-data-img-build.sh aarch64 noproxy diff --git a/scripts/environment/wget.bat b/scripts/environment/wget.bat deleted file mode 100644 index 09c10eb11..000000000 --- a/scripts/environment/wget.bat +++ /dev/null @@ -1,11 +0,0 @@ -REM -REM Helper script to download an img file. -REM - -rmdir /S /Q img 2>nul -mkdir img - -echo Downloading %1 ... -Powershell.exe -command "(New-Object System.Net.WebClient).DownloadFile('%1','img\%2')" - -move img\%2 . \ No newline at end of file diff --git a/scripts/install-sdk-from-github.sh b/scripts/install-sdk-from-github.sh index d1e538c65..dae7b8430 100644 --- a/scripts/install-sdk-from-github.sh +++ b/scripts/install-sdk-from-github.sh @@ -108,8 +108,8 @@ echo " " cd ${MY_DIR}/${DEST_DIR} -chmod a+x bin/oss.flatbuffers*/ubuntu20-gcc-*/release/flatc -chmod a+x bin/framework/ubuntu20-gcc-*/rexroth-automation-frame +chmod a+x bin/oss.flatbuffers*/ubuntu22-gcc-*/release/flatc +chmod a+x bin/framework/ubuntu22-gcc-*/rexroth-automation-frame chmod a+w -R include sudo chown -R boschrexroth:boschrexroth fbs/comm/ethercat/master/ sudo chown -R boschrexroth:boschrexroth bfbs/comm/ethercat/master/ @@ -146,10 +146,6 @@ else echo "ERROR ${DEP_PACKAGE} not found!" fi -echo " " -echo "------------------------------------------------------" -echo "Installing snapcraft..." -echo " " - -sudo snap install snapcraft --classic +REM Installing snapcraft +~/scripts/install-snapcraft.sh"