Skip to content

Commit

Permalink
[PZACXX-20] Fixed BPS example
Browse files Browse the repository at this point in the history
  • Loading branch information
wardru committed Oct 2, 2023
1 parent 354e95f commit 05619c1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PzaCxx(ConanFile):
}
default_options = {
"shared": True,
"build_examples": False
"build_examples": True
}
generators = "CMakeDeps", "CMakeToolchain", "virtualrunenv"
exports_sources = "CMakeLists.txt", "source/*", "version.h.in", "CHANGELOG.md", "test/*", "cmake/*", "examples/*", "LICENSE"
Expand Down
55 changes: 24 additions & 31 deletions examples/bps.cxx
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
#include <pza/core/client.hxx>
#include <pza/core/core.hxx>
#include <pza/devices/bps.hxx>

int main(void)
int main(int argc, char** argv)
{
pza::core::set_log_level(pza::core::log_level::trace);
if (argc != 5) {
std::cerr << "Usage: " << argv[0] << " <address> <port> <group> <BPS name>" << std::endl;
return -1;
}

const char *address = argv[1];
int port = std::stoi(argv[2]);
const char *group = argv[3];
const char *bps_name = argv[4];

pza::core::set_log_level(pza::core::log_level::debug);

pza::client::ptr cli = std::make_shared<pza::client>("localhost", 1883);
pza::client::ptr cli = std::make_shared<pza::client>(address, port);

if (cli->connect() == -1) {
if (cli->connect() == -1)
return -1;
}

pza::bps::ptr bps = std::make_shared<pza::bps>("default", "MY BPS 1");
pza::bps::ptr bps = std::make_shared<pza::bps>(group, bps_name);

if (cli->register_device(bps) == -1)
return -1;

for (size_t i = 0; i < 1; i++) {
for (size_t i = 0; i < bps->get_num_channels(); i++) {
auto bps_channel = bps->channel[i];

// spdlog::info("Channel {}:", i);
// bps_channel->ctrl.set_voltage(-7.3);
// bps_channel->ctrl.set_current(1.0);
// bps_channel->ctrl.set_enable(false);
// spdlog::info(" Voltage: {}", bps_channel->voltmeter.get_measure());
// spdlog::info(" Current: {}", bps_channel->ampermeter.get_measure());
// spdlog::info(" Enabled: {}", bps_channel->ctrl.get_enable());
// bps_channel->ctrl.set_enable(true);
// bps_channel->ctrl.set_voltage(3.3);
// bps_channel->ctrl.set_current(5.0);
// spdlog::info(" Voltage: {}", bps_channel->voltmeter.get_measure());
// spdlog::info(" Current: {}", bps_channel->ampermeter.get_measure());
// spdlog::info(" Enabled: {}", bps_channel->ctrl.get_enable());

//bps_channel->voltmeter.set_measure_polling_cycle(2);
//bps_channel->ampermeter.set_measure_polling_cycle(2);
//bps_channel->ctrl.set_enable_polling_cycle(2);
spdlog::info("Channel {}:", i);
bps_channel->ctrl.set_voltage(-7.3);
bps_channel->ctrl.set_current(1.0);
bps_channel->ctrl.set_enable(false);
spdlog::info(" Voltage: {}", bps_channel->voltmeter.get_measure());
spdlog::info(" Current: {}", bps_channel->ampermeter.get_measure());
spdlog::info(" Enabled: {}", bps_channel->ctrl.get_enable());
}

spdlog::info("\n\nOK\n\n");

cli->disconnect();

return 0;
return cli->disconnect();
}
17 changes: 13 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ LIB_MODE="Shared"
BUILD_MODE="Debug"
PROJECT_ROOT_DIR="$(dirname "$(realpath "$0")")/.."
CONAN_PROFILES_DIR="$PROJECT_ROOT_DIR/conan_profiles"
EXAMPLES="ON"

TEMP=$(getopt -o t:l:b:h --long target:,lib:,build:,help -n "$0" -- "$@")
TEMP=$(getopt -o t:l:b:h --long target:,lib:,build:,help,no-examples -n "$0" -- "$@")
if [ $? != 0 ]; then
echo "Error processing arguments." >&2
exit 1
Expand All @@ -28,6 +29,10 @@ while true; do
BUILD_MODE="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}"
shift 2
;;
--no-examples)
EXAMPLES="OFF"
shift
;;
-h|--help)
echo "Usage: $0 [-t <target>] [-l <lib>] [-b <build>] [-h]"
echo " -t --target Target platform (Windows or Linux). Default is Linux"
Expand Down Expand Up @@ -63,7 +68,7 @@ fi
if [ "$LIB_MODE" == "Static" ]; then
BUILD_DIR="${BUILD_DIR}_static"
elif [ "$LIB_MODE" == "Shared" ]; then
pass
continue
else
echo "Library mode not supported: $LIB_MODE"
exit 1
Expand All @@ -85,5 +90,9 @@ if [ ! -d "$FULL_BUILD_DIR" ]; then
fi

cd $FULL_BUILD_DIR
cmake -DCMAKE_TOOLCHAIN_FILE=./$BUILD_MODE/generators/pzacxx_toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILD_MODE ..
cmake --build . --config $BUILD_MODE --parallel ${nproc}
cmake \
-DCMAKE_TOOLCHAIN_FILE=./$BUILD_MODE/generators/pzacxx_toolchain.cmake \
-DCMAKE_BUILD_TYPE=$BUILD_MODE \
-DBUILD_EXAMPLES=$EXAMPLES \
..
cmake --build . --config $BUILD_MODE --parallel ${nproc}
2 changes: 1 addition & 1 deletion scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ conan install \
--profile:b $FULL_PROFILE_BUILD \
--profile:h $FULL_PROFILE_HOST \
--install-folder=$FULL_BUILD_DIR \
$PROJECT_ROOT_DIR
$PROJECT_ROOT_DIR

0 comments on commit 05619c1

Please sign in to comment.