diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 86491abb4f89ee44b04a66ce5b067977ca36d809..8de106b4de00bb69bb53379c6d2a61f8f0fb561f 100755 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,7 +13,7 @@ "label": "CLEAN", "type": "shell", "windows": { - "command": "sh sbs -c" + "command": "./sbs -c" }, "linux": { "command": "./sbs -c" @@ -35,7 +35,7 @@ "label": "BUILD current-entrypoint", "type": "shell", "windows": { - "command": "sh sbs -v -n -b ${fileBasenameNoExtension}" + "command": "./sbs -d -b ${fileBasenameNoExtension}" }, "linux": { "command": "./sbs -v -b ${fileBasenameNoExtension}" @@ -46,7 +46,7 @@ "label": "RUN current-entrypoint", "type": "shell", "windows": { - "command": "ST-LINK_CLI.exe -P bin/${fileBasenameNoExtension}/${fileBasenameNoExtension}.bin 0x8000000 -V -Rst" + "command": "ST-LINK_CLI.exe -P build/${fileBasenameNoExtension}.bin 0x8000000 -V -Rst" }, "linux": { "command": "st-flash write bin/${fileBasenameNoExtension}/${fileBasenameNoExtension}.bin 0x8000000" @@ -57,10 +57,10 @@ "label": "BUILD+RUN current-entrypoint", "type": "shell", "windows": { - "command": "ST-LINK_CLI.exe -P bin/${fileBasenameNoExtension}/${fileBasenameNoExtension}.bin 0x8000000 -V -Rst" + "command": "ST-LINK_CLI.exe -P build/${fileBasenameNoExtension}.bin 0x8000000 -V -Rst" }, "linux": { - "command": "sleep 1;st-flash write bin/${fileBasenameNoExtension}/${fileBasenameNoExtension}.bin 0x8000000" + "command": "sleep 1;st-flash write build/${fileBasenameNoExtension}.bin 0x8000000" }, "problemMatcher": [], "dependsOn": [ @@ -106,6 +106,17 @@ "options": { "cwd": "/opt/arm-miosix-eabi/bin" } + }, + { + "label": "Open PuTTY 'skyward' session", + "type": "shell", + "windows": { + "command": "putty.exe -load skyward &" + }, + "linux": { + "command": "putty.exe -load skyward &" + }, + "problemMatcher": [] } ] } \ No newline at end of file diff --git a/sbs b/sbs index 0de8717932d03b2c5a2e1b38f1830a9c07f30c94..dee9fd248df9a0b65657eb647f0910c7f616d51c 100755 --- a/sbs +++ b/sbs @@ -39,50 +39,111 @@ print_banner() { EOF } -show_found_deps() { - printf "Found Ccache: "; [ $ccache_found ] && echo "yes" || echo "no" - printf "Found Ninja: "; [ $ninja_found ] && echo "yes" || echo "no" +find_deps() { + command -v ccache &> /dev/null && config_ccache=true + command -v ninja &> /dev/null && config_ninja=true +} + +print_found_deps() { + printf "Found Ccache: "; [ "$config_ccache" = true ] && echo "yes" || echo "no" + printf "Found Ninja: "; [ "$config_ninja" = true ] && echo "yes" || echo "no" echo } configure() { - show_found_deps - config_ccache= && [ $ccache_found ] && config_ccache="-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" - config_toolchain="-DCMAKE_TOOLCHAIN_FILE=$sbs_base/libs/miosix-kernel/miosix/_tools/toolchain.cmake" - config_ninja= && [ $ninja_found ] && config_ninja="-GNinja" - cmake \ - -B"$build_dir" \ - $config_ccache \ - $config_toolchain \ - $config_ninja \ - $config_buildtype \ - $config_verbose \ - "$source_dir" + print_found_deps + + defs="-DCMAKE_TOOLCHAIN_FILE=$sbs_base/libs/miosix-kernel/miosix/_tools/toolchain.cmake" + [ "$config_ccache" = true ] && defs="$defs -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" + [ "$config_debug" = true ] && defs="$defs -DCMAKE_BUILD_TYPE=Debug" || defs="$defs -DCMAKE_BUILD_TYPE=Release" + [ "$config_verbose" = true ] && defs="$defs -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" + [ "$config_ninja" = true ] && gen="-GNinja" || gen="-GUnix Makefiles" + + if cmake -B"$build_dir" $defs "$gen" "$source_dir"; then + [ "$config_debug" = true ] && touch "$build_dir/$DEBUG_FILENAME" || rm -f "$build_dir/$DEBUG_FILENAME" + [ "$config_verbose" = true ] && touch "$build_dir/$VERBOSE_FILENAME" || rm -f "$build_dir/$VERBOSE_FILENAME" + fi } -clean() { [ -d "$build_dir" ] && cmake --build "$build_dir" $build_jobs --target clean; rm -rf "$build_dir"; } +check_configured() { + to_reconfigure=false + + if [ ! -d "$build_dir" ]; then + to_reconfigure=true + elif [ ! -f "$build_dir/$CMAKE_FILENAME" ]; then + rm -rf "$build_dir" + to_reconfigure=true + else + [ -f "$build_dir/$DEBUG_FILENAME" ] && found_debug=true || found_debug=false + [ -f "$build_dir/$VERBOSE_FILENAME" ] && found_verbose=true || found_verbose=false + if [ "$config_debug" != "$found_debug" ] \ + || [ "$config_verbose" != "$found_verbose" ]; then + to_reconfigure=true + fi + fi + + [ "$to_reconfigure" = true ] && configure && echo || true +} -build_all() { check_configured && cmake --build "$build_dir" $build_jobs; } +build() { + if check_configured; then + cmake --build "$build_dir" $(get_jobs_opt) --target "$1" + fi +} -build() { check_configured && cmake --build "$build_dir" $build_jobs --target "$1"; } +clean() { + if [ -f "$build_dir/$CMAKE_FILENAME" ]; then + cmake --build "$build_dir" $(get_jobs_opt) --target clean && echo + fi + echo "Removing build folder..." + rm -rf "$build_dir" +} -flash() { build "$1" && [ -f "$build_dir/$1.bin" ] && echo && st-flash --reset write "$build_dir/$1.bin" 0x08000000; } +flash() { + if build "$1"; then + echo + if [ -f "$build_dir/$1.bin" ]; then + st-flash --reset write "$build_dir/$1.bin" 0x08000000 + else + echo "Error: target '$1' is not flashable" + fi + fi +} -lint() { "$sbs_base/scripts/linter.sh" "$source_dir/src/shared"; } +list() { + if check_configured; then + echo "[1/1] All SBS targets available:" + cmake --build "$build_dir" $(get_jobs_opt) --target help | grep -o '^[^/]*\.bin' | cut -f 1 -d '.' + fi +} -list() { check_configured && echo "[1/1] All SBS targets available:" \ - && cmake --build "$build_dir" $build_jobs --target help | grep -o '^[^/]*\.bin' | cut -f 1 -d '.'; } +boards() { + build help-boards +} -boards() { check_configured && cmake --build "$build_dir" $build_jobs --target help-boards; } +build_all() { + build all +} -check_configured() { ([ "$to_reconfigure" = true ] || [ ! -d "$build_dir" ] || [ ! -f "$build_dir/CMakeCache.txt" ] && rm -rf "$build_dir") \ - && configure && echo || true; } +set_debug() { + config_debug=true +} -set_debug() { config_buildtype="-DCMAKE_BUILD_TYPE=Debug" && to_reconfigure=true; } +set_verbose() { + config_verbose=true +} -set_verbose() { config_verbose="-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" && to_reconfigure=true; } +set_jobs() { + build_jobs="$1" +} -set_jobs() { build_jobs="-j $1"; } +get_jobs_opt() { + [ ! -z "$build_jobs" ] && echo "-j $build_jobs" || echo +} + +lint() { + "$sbs_base/scripts/linter.sh" "$source_dir/src/shared" +} usage() { cat <<EOF @@ -98,24 +159,30 @@ OPTIONS: -j JOBS, --jobs JOBS Build in parallel using the given number of jobs -d, --debug Enable debug -v, --verbose Print a verbose output - -n, --lint Run the linter -l, --list List all targets available -r, --boards List all boards available + -n, --lint Run the linter EOF } +CMAKE_FILENAME="CMakeCache.txt" +DEBUG_FILENAME=".sbs_debug" +VERBOSE_FILENAME=".sbs_verbose" + print_banner sbs_base="$(cd -- "$(dirname "$0")" > /dev/null 2>&1; pwd -P)" source_dir="$PWD" build_dir="$source_dir/build" -config_buildtype="-DCMAKE_BUILD_TYPE=Release" -config_verbose= -build_jobs= + to_reconfigure=false +config_ccache=false +config_debug=false +config_verbose=false +config_ninja=false +build_jobs= -ccache_found="$(command -v ccache)" -ninja_found="$(command -v ninja)" +find_deps for arg in "$@"; do shift @@ -127,14 +194,14 @@ for arg in "$@"; do --jobs) set -- "$@" "-j";; --debug) set -- "$@" "-d";; --verbose) set -- "$@" "-v";; - --lint) set -- "$@" "-n";; --list) set -- "$@" "-l";; --boards) set -- "$@" "-r";; + --lint) set -- "$@" "-n";; *) set -- "$@" "$arg" esac done -while getopts hcb:f:j:dvnlr opt; do +while getopts hcb:f:j:dvlrn opt; do case "$opt" in h) usage; exit 0;; c) clean; exit $?;; @@ -143,9 +210,9 @@ while getopts hcb:f:j:dvnlr opt; do j) set_jobs "$OPTARG";; d) set_debug;; v) set_verbose;; - n) lint; exit $?;; l) list; exit $?;; r) boards; exit $?;; + n) lint; exit $?;; ?) usage; exit 2;; esac done diff --git a/src/shared/sensors/MBLoadCell/MBLoadCell.cpp b/src/shared/sensors/MBLoadCell/MBLoadCell.cpp index 78861834209574b70ba24447181aed4b8e9f3bb5..8bf6207b54efc0a2908f26e3507eadb6eb3d5e91 100644 --- a/src/shared/sensors/MBLoadCell/MBLoadCell.cpp +++ b/src/shared/sensors/MBLoadCell/MBLoadCell.cpp @@ -27,7 +27,6 @@ using ctrlPin1 = miosix::Gpio<GPIOC_BASE, 1>; ///< control R/W pin 1 using ctrlPin2 = miosix::Gpio<GPIOC_BASE, 2>; ///< control R/W pin 2 -using out1 = miosix::Gpio<GPIOC_BASE, 8>; ///< out1 for the first setpoint1 namespace Boardcore { @@ -57,10 +56,11 @@ bool MBLoadCell::init() } { + // disabling interrupts in order to set with no problems the control + // pins miosix::FastInterruptDisableLock dLock; ctrlPin1::mode(miosix::Mode::OUTPUT); ctrlPin2::mode(miosix::Mode::OUTPUT); - out1::mode(miosix::Mode::INPUT); } return true; @@ -233,7 +233,7 @@ MBLoadCellSettings MBLoadCell::getSettings() { return settings; } void MBLoadCell::resetMaxMinWeights() { - TRACE("TIMESTAMP: %.3f [s], EX MAX: %.2f [Kg], EX MIN: %.2f [Kg]\n", + TRACE("### TIMESTAMP: %.3f [s], EX MAX: %.2f [Kg], EX MIN: %.2f [Kg] ###\n", (double)TimestampTimer::getTimestamp() / 1000000, max_weight.data, min_weight.data); @@ -265,6 +265,7 @@ void MBLoadCell::generateRequest(DataAsciiRequest &req, void MBLoadCell::transmitASCII(std::string buf) { + // setting both the control pins to high in order to transmit ctrlPin1::high(); ctrlPin2::high(); serial->sendString(buf); @@ -275,6 +276,7 @@ std::string MBLoadCell::receiveASCII() { char buf[64]; + // setting both the control pins to low in order to receive ctrlPin1::low(); ctrlPin2::low(); int len = serial->recvString(buf, 64); @@ -286,6 +288,7 @@ std::string MBLoadCell::receiveASCII() template <typename T> void MBLoadCell::receive(T *buf) { + // setting both the control pins to low in order to receive ctrlPin1::low(); ctrlPin2::low(); serial->recvData(buf); diff --git a/src/shared/sensors/MBLoadCell/MBLoadCell.h b/src/shared/sensors/MBLoadCell/MBLoadCell.h index 5a97f87cd9b509c7970c680991bcd51210f4cd20..d2bb87f8681a5cccdbaa983a25c4728ac21d1169 100644 --- a/src/shared/sensors/MBLoadCell/MBLoadCell.h +++ b/src/shared/sensors/MBLoadCell/MBLoadCell.h @@ -67,6 +67,11 @@ public: */ bool init() override; + /** + * @brief self test function simply overridden in order to have a concrete + * class, simply returns true + * @return true + */ bool selfTest() override; /** diff --git a/src/shared/sensors/MBLoadCell/MBLoadCellData.h b/src/shared/sensors/MBLoadCell/MBLoadCellData.h index e3f46b33f6a90eb19b3f7845a849b1a7f49aefa3..c43988276ef76de5e8b5f3b3ff2c16696a274ddb 100644 --- a/src/shared/sensors/MBLoadCell/MBLoadCellData.h +++ b/src/shared/sensors/MBLoadCell/MBLoadCellData.h @@ -51,7 +51,6 @@ enum LoadCellValuesEnum NET_WEIGHT, PEAK_WEIGHT, RESET_TARE, - DECIMALS_READING, COMMUTE_TO_NET, COMMUTE_TO_GROSS }; @@ -61,13 +60,12 @@ enum LoadCellValuesEnum */ typedef std::map<const LoadCellValuesEnum, std::string> LoadCellValues; static LoadCellValues loadCellValues = { - {SET_SETPOINT_1, "A"}, {SET_SETPOINT_2, "B"}, - {SET_SETPOINT_3, "C"}, {GET_SETPOINT_1, "a"}, - {GET_SETPOINT_2, "b"}, {GET_SETPOINT_3, "c"}, - {GROSS_WEIGHT, "t"}, {NET_WEIGHT, "n"}, - {PEAK_WEIGHT, "p"}, {RESET_TARE, "z"}, - {DECIMALS_READING, "D"}, {COMMUTE_TO_NET, "NET"}, - {COMMUTE_TO_GROSS, "GROSS"}}; + {SET_SETPOINT_1, "A"}, {SET_SETPOINT_2, "B"}, + {SET_SETPOINT_3, "C"}, {GET_SETPOINT_1, "a"}, + {GET_SETPOINT_2, "b"}, {GET_SETPOINT_3, "c"}, + {GROSS_WEIGHT, "t"}, {NET_WEIGHT, "n"}, + {PEAK_WEIGHT, "p"}, {RESET_TARE, "z"}, + {COMMUTE_TO_NET, "NET"}, {COMMUTE_TO_GROSS, "GROSS"}}; /** * @brief structure of the errors in the ASCII requests @@ -233,4 +231,4 @@ struct DataAsciiRequest } }; -} // namespace Boardcore \ No newline at end of file +} // namespace Boardcore \ No newline at end of file