parent
584ca15338
commit
2d48a5fb90
27
.editorconfig
Normal file
27
.editorconfig
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copyright 2025 Enactic, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
# https://editorconfig.org/
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
insert_final_newline = true
|
||||||
|
spelling_language = en
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.sh]
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
@ -39,4 +39,22 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: meson-fmt
|
- id: meson-fmt
|
||||||
alias: python
|
alias: python
|
||||||
args: ['--inplace']
|
args: ["--inplace"]
|
||||||
|
exclude: ".editorconfig$"
|
||||||
|
- repo: https://github.com/koalaman/shellcheck-precommit
|
||||||
|
rev: v0.10.0
|
||||||
|
hooks:
|
||||||
|
- id: shellcheck
|
||||||
|
alias: shell
|
||||||
|
- repo: https://github.com/scop/pre-commit-shfmt
|
||||||
|
# v3.11.0-1 or later requires pre-commit 3.2.0 or later but Ubuntu
|
||||||
|
# 22.04 ships pre-commit 2.17.0. We can update this rev after
|
||||||
|
# Ubuntu 22.04 reached EOL (June 2027).
|
||||||
|
rev: v3.10.0-1
|
||||||
|
hooks:
|
||||||
|
- id: shfmt
|
||||||
|
alias: shell
|
||||||
|
args:
|
||||||
|
# The default args is "--write --simplify" but we don't use
|
||||||
|
# "--simplify". Because it's conflicted will ShellCheck.
|
||||||
|
- "--write"
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
#
|
#
|
||||||
# Build script for OpenArm Python bindings
|
# Build script for OpenArm Python bindings
|
||||||
|
|
||||||
set -e
|
set -eu
|
||||||
|
|
||||||
# Get script directory
|
# Get script directory
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
@ -36,11 +36,13 @@ fi
|
|||||||
# Build the C++ library first if needed
|
# Build the C++ library first if needed
|
||||||
if [ ! -d "$PROJECT_ROOT/build" ]; then
|
if [ ! -d "$PROJECT_ROOT/build" ]; then
|
||||||
echo "Building C++ library..."
|
echo "Building C++ library..."
|
||||||
mkdir -p "$PROJECT_ROOT/build"
|
cmake \
|
||||||
cd "$PROJECT_ROOT/build"
|
-S "$PROJECT_ROOT" \
|
||||||
cmake ..
|
-B "$PROJECT_ROOT/build" \
|
||||||
make -j$(nproc)
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
cd "$SCRIPT_DIR"
|
-GNinja
|
||||||
|
cmake --build "$PROJECT_ROOT/build"
|
||||||
|
cmake --install "$PROJECT_ROOT/build"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install in development mode
|
# Install in development mode
|
||||||
|
|||||||
@ -14,6 +14,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
# Simple CAN Interface Setup Script
|
# Simple CAN Interface Setup Script
|
||||||
# Usage: script/configure_socketcan.sh <interface> [options]
|
# Usage: script/configure_socketcan.sh <interface> [options]
|
||||||
|
|
||||||
@ -52,32 +54,32 @@ shift
|
|||||||
# Parse options
|
# Parse options
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-fd)
|
-fd)
|
||||||
FD_MODE=true
|
FD_MODE=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-b)
|
-b)
|
||||||
BITRATE="$2"
|
BITRATE="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-d)
|
-d)
|
||||||
DBITRATE="$2"
|
DBITRATE="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-h)
|
-h)
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Error: Unknown option '$1'"
|
echo "Error: Unknown option '$1'"
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check if interface exists
|
# Check if interface exists
|
||||||
if ! ip link show $CAN_IF &>/dev/null; then
|
if ! ip link show "$CAN_IF" &>/dev/null; then
|
||||||
echo "Error: CAN interface '$CAN_IF' not found"
|
echo "Error: CAN interface '$CAN_IF' not found"
|
||||||
echo "Available interfaces:"
|
echo "Available interfaces:"
|
||||||
ip link show | grep -E "can[0-9]" | cut -d: -f2 | tr -d ' ' || echo " No CAN interfaces found"
|
ip link show | grep -E "can[0-9]" | cut -d: -f2 | tr -d ' ' || echo " No CAN interfaces found"
|
||||||
@ -87,26 +89,26 @@ fi
|
|||||||
# Configure CAN interface
|
# Configure CAN interface
|
||||||
echo "Configuring $CAN_IF..."
|
echo "Configuring $CAN_IF..."
|
||||||
|
|
||||||
if ! sudo ip link set $CAN_IF down; then
|
if ! sudo ip link set "$CAN_IF" down; then
|
||||||
echo "Error: Failed to bring down $CAN_IF"
|
echo "Error: Failed to bring down $CAN_IF"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$FD_MODE" = true ]; then
|
if [ "$FD_MODE" = true ]; then
|
||||||
if ! sudo ip link set $CAN_IF type can bitrate $BITRATE dbitrate $DBITRATE fd on; then
|
if ! sudo ip link set "$CAN_IF" type can bitrate "$BITRATE" dbitrate "$DBITRATE" fd on; then
|
||||||
echo "Error: Failed to configure CAN FD mode"
|
echo "Error: Failed to configure CAN FD mode"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$CAN_IF is now set to CAN FD mode (${BITRATE} bps / ${DBITRATE} bps)"
|
echo "$CAN_IF is now set to CAN FD mode (${BITRATE} bps / ${DBITRATE} bps)"
|
||||||
else
|
else
|
||||||
if ! sudo ip link set $CAN_IF type can bitrate $BITRATE; then
|
if ! sudo ip link set "$CAN_IF" type can bitrate "$BITRATE"; then
|
||||||
echo "Error: Failed to configure CAN 2.0 mode"
|
echo "Error: Failed to configure CAN 2.0 mode"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$CAN_IF is now set to CAN 2.0 mode (${BITRATE} bps)"
|
echo "$CAN_IF is now set to CAN 2.0 mode (${BITRATE} bps)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! sudo ip link set $CAN_IF up; then
|
if ! sudo ip link set "$CAN_IF" up; then
|
||||||
echo "Error: Failed to bring up $CAN_IF"
|
echo "Error: Failed to bring up $CAN_IF"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
# CAN Interface Script
|
# CAN Interface Script
|
||||||
# Usage: scripts/set_zero.sh <CAN_IF> [CAN_ID] [-all]
|
# Usage: scripts/set_zero.sh <CAN_IF> [CAN_ID] [-all]
|
||||||
@ -42,7 +43,8 @@ check_can_interface() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if interface is up
|
# Check if interface is up
|
||||||
local state=$(ip link show "$interface" | grep -o "state [A-Z]*" | cut -d' ' -f2)
|
local state
|
||||||
|
state=$(ip link show "$interface" | grep -o "state [A-Z]*" | cut -d' ' -f2)
|
||||||
if [ "$state" != "UP" ]; then
|
if [ "$state" != "UP" ]; then
|
||||||
echo "Error: CAN interface $interface is not UP (current state: $state)"
|
echo "Error: CAN interface $interface is not UP (current state: $state)"
|
||||||
return 1
|
return 1
|
||||||
@ -52,14 +54,16 @@ check_can_interface() {
|
|||||||
|
|
||||||
# Try to get baudrate information
|
# Try to get baudrate information
|
||||||
if command -v ethtool &>/dev/null; then
|
if command -v ethtool &>/dev/null; then
|
||||||
local baudrate=$(ethtool "$interface" 2>/dev/null | grep -i speed | cut -d: -f2 | tr -d ' ')
|
local baudrate
|
||||||
|
baudrate=$(ethtool "$interface" 2>/dev/null | grep -i speed | cut -d: -f2 | tr -d ' ')
|
||||||
if [ -n "$baudrate" ]; then
|
if [ -n "$baudrate" ]; then
|
||||||
echo "Baudrate: $baudrate"
|
echo "Baudrate: $baudrate"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Alternative method using ip command
|
# Alternative method using ip command
|
||||||
local bitrate=$(ip -details link show "$interface" 2>/dev/null | grep -o "bitrate [0-9]*" | cut -d' ' -f2)
|
local bitrate
|
||||||
|
bitrate=$(ip -details link show "$interface" 2>/dev/null | grep -o "bitrate [0-9]*" | cut -d' ' -f2)
|
||||||
if [ -n "$bitrate" ]; then
|
if [ -n "$bitrate" ]; then
|
||||||
echo "Bitrate: ${bitrate} bps"
|
echo "Bitrate: ${bitrate} bps"
|
||||||
fi
|
fi
|
||||||
@ -146,7 +150,8 @@ main() {
|
|||||||
echo "Sending set zero messages to all motor with CAN IDs from 001 to 008"
|
echo "Sending set zero messages to all motor with CAN IDs from 001 to 008"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
for i in {1..8}; do
|
for i in {1..8}; do
|
||||||
local padded_id=$(printf "%03d" $i)
|
local padded_id
|
||||||
|
padded_id=$(printf "%03d" "$i")
|
||||||
send_can_messages "$padded_id" "$CAN_IF"
|
send_can_messages "$padded_id" "$CAN_IF"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
@ -157,4 +162,4 @@ main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run main function with all arguments
|
# Run main function with all arguments
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user