Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/improve release scripts #18

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

cd $SCRIPT_DIR

# Create a virtual environment
python3 -m venv $SCRIPT_DIR/.venv

# Activate the virtual environment
source $SCRIPT_DIR/.venv/bin/activate

# Check the presence of the 'cargo set-version' command
if ! command -v cargo-set-version &> /dev/null
then
echo "cargo-set-version could not be found"
echo "Please install the cargo-edit crate, and try again."
exit 1
fi

# Updates the versions of
# - jcan/Cargo.toml
# - jcan-python/Cargo.toml
# By default we run a dry-run.
# To actually update the versions, use the --no-dry-run flag
if [[ "$1" == "--no-dry-run" ]];
then
cargo set-version --package jcan --bump patch
cargo set-version --package jcan_python --bump patch
else
cargo set-version --dry-run --package jcan --bump patch
cargo set-version --dry-run --package jcan_python --bump patch
fi

# Ask if you'd like to update the git tag
CURRENTVERSION=$(cargo pkgid jcan | cut -d# -f2)
# Pre-pend 'v' to the version
CURRENTVERSION="v$CURRENTVERSION"

TAGVERSION=$(git tag -l | tail -n1)
# Show the old and new version, ask if you'd like to update the git tag
echo "Current version: $CURRENTVERSION"
echo "Tag version: $TAGVERSION"
read -p "Update git tag to current version? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
# Update the git tag, with a message
git tag -a $CURRENTVERSION -m "v$CURRENTVERSION"
fi


30 changes: 30 additions & 0 deletions devsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,35 @@ then
fi
fi

# Install the crates cargo-edit, cargo-get
if ! command -v cargo set-version &> /dev/null
then
echo "cargo-edit could not be found"
# Prompt with y/N to install cargo-edit
read -p "Install cargo-edit? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
cargo install cargo-edit
else
echo "cargo-edit not installed, exiting"
exit 1
fi
fi

if ! command -v cargo get &> /dev/null
then
echo "cargo-get could not be found"
# Prompt with y/N to install cargo-get
read -p "Install cargo-get? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
cargo install cargo-get
else
echo "cargo-get not installed, exiting"
exit 1
fi
fi


22 changes: 20 additions & 2 deletions examples/cpp_receive_callbacks/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
#include <stdio.h>
#include <vector>
#include "jcan/jcan.h"

#include <unistd.h>
using namespace org::jcan;

/*
C++-14 example of using the jcan library with callbacks.
*/

uint32_t frame_counter = 0;

// Example of handling a frame within a class object
class MyFrameHandler {
public:
void on_frame(Frame frame) {
printf("MFH Received frame: %s\n", frame.to_string().c_str());
frame_counter++;
}
};

void on_frame(Frame frame) {
printf("Received frame: %s\n", frame.to_string().c_str());
frame_counter++;
}

// main function which opens a JBus, and prints incoming frames
Expand All @@ -27,7 +31,7 @@ int main(int argc, char **argv) {
std::unique_ptr<Bus> bus = new_bus();

// Set ID filter using a vector of allowed IDs
std::vector<uint32_t> allowed_ids = {0x100, 0x123, 0x456, 0x789};
std::vector<uint32_t> allowed_ids = {0x100, 0x123, 0x456, 0x789, 0x1A3, 0x1A5};
bus->set_id_filter(allowed_ids);

// Instantiate a frame handler object
Expand All @@ -37,16 +41,30 @@ int main(int argc, char **argv) {
bus->add_callback(0x123, &on_frame);
bus->add_callback(0x456, &on_frame);
bus->add_callback(0x789, &on_frame);
bus->add_callback(0x1A3, &on_frame);
bus->add_callback(0x1A5, &on_frame);

// Add a callback function to a class object
bus->add_callback_to(0x100, &frame_handler, &MyFrameHandler::on_frame);

// Open the bus
// Default 8-tx, 512-frame rx queues
bus->open("vcan0");
// Smaller internal queues
// bus->open("vcan0", 64, 64);

// Run forever
while (1) {
// Send a frame every 1 second
Frame frameToSend = new_frame(0x200, {1,2,3,4,5,6,7,8});
printf("Sending: %s...\n",frameToSend.to_string().c_str());
bus->send(frameToSend);
sleep(5);
// Clear our frame spin counter
frame_counter = 0;
printf("Spinning...\n");
bus->spin();
printf("Spun %d frames\n", frame_counter);
}

return 0;
Expand Down
3 changes: 2 additions & 1 deletion examples/cpp_send_receive/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int main(int argc, char **argv) {
// The format used below, of the form 'base_id + part of ID we don't care about',
// is a nice simple way to use this feature.
bus->set_id_filter_mask(0x1A0,0xFF0);
printf("Filter set to 0x1A0 : 0xFF0\n");

// Open the bus
bus->open("vcan0");
Expand All @@ -37,7 +38,7 @@ int main(int argc, char **argv) {
printf("Sending: %s...\n",frameToSend.to_string().c_str());
bus->send(frameToSend);

printf("Waiting for frame...\n");
printf("Waiting for frame matching filter...\n");
Frame frameReceived = bus->receive();
printf("Received: %s\n", frameReceived.to_string().c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions jcan-python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jcan_python"
version = "0.1.8"
version = "0.1.9"
edition = "2021"
publish = false

Expand All @@ -10,7 +10,6 @@ path = "src/lib.rs"
crate-type = ["cdylib","rlib"]

[dependencies]
anyhow = "1.0"
jcan = { version = "*", path = "../jcan" }
pyo3 = { version = "0.17.3", features = ["abi3-py38", "extension-module", "generate-import-lib"] }

Expand Down
2 changes: 1 addition & 1 deletion jcan-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
requires = ["setuptools", "wheel", "setuptools-rust", "toml"]

18 changes: 17 additions & 1 deletion jcan-python/setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
from setuptools import setup, find_namespace_packages
from setuptools_rust import Binding, RustExtension
from pathlib import Path
import toml

# The version of the python package will always match the version
# of the jcan-python cargo package.
# To do this, we read the version from the jcan-python/Cargo.toml file.
def get_version() -> str:
version = {}
# the Cargo.toml and setup.py file are in the same directory,
# so we can use the __file__ variable to get the path to the Cargo.toml file.
cargo_toml_path = Path(__file__).parent / "Cargo.toml"
# Open the toml file and retrieve the [package].version value.
with open(cargo_toml_path, "r") as f:
cargo_toml = toml.load(f)
version = cargo_toml["package"]["version"]

return version

setup(
name="jcan",
version="0.1.8",
version=get_version(),
packages=["jcan"],
zip_safe=False,
rust_extensions=[
Expand Down
4 changes: 2 additions & 2 deletions jcan-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl PyJBus {
}

// Implement the open method for the PyJBus
// Add pyo3 default arguments of 256 for tx_queue_len and rx_queue_len
#[args(tx_queue_len = 256, rx_queue_len = 256)]
// Add pyo3 default arguments of 8 for tx_queue_len and 512 rx_queue_len
#[args(tx_queue_len = 2, rx_queue_len = 256)]
fn open(&mut self, interface: String, tx_queue_len: u16, rx_queue_len: u16) -> PyResult<()> {
self.bus.open(interface, tx_queue_len, rx_queue_len).map_err(|e| {
PyOSError::new_err(format!("{}", e))
Expand Down
15 changes: 2 additions & 13 deletions jcan/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jcan"
version = "0.1.8"
version = "0.1.9"
edition = "2021"
publish = false
links = "jcan"
Expand All @@ -11,24 +11,13 @@ path = "src/lib.rs"
crate-type = ["staticlib", "rlib"]

[dependencies]
anyhow = "1.0"
bitflags = "1.3"
byte_conv = "0.1.1"
clap = {version = "3.2.8", features = ["derive"]}
ctrlc = "3.2.2"
embedded-can = "0.4"
hex = "0.4"
itertools = "0.10"
libc = "0.2"
nb = "1.0"
neli = { version = "0.6", optional = false }
nix = "0.26"
serial_test = "0.9"
socketcan = { git = "https://github.com/socketcan-rs/socketcan-rs", version = "2.0.0-pre.0" }
cxx = "1.0"
log = "0.4.17"
env_logger = "0.10.0"

[build-dependencies]
cxx-build = "1.0"
cc = "1.0.78"

2 changes: 1 addition & 1 deletion jcan/src/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace org::jcan

void Bus::open(const char *name) {
// Default queue lengths
this->jBus->open(name, 256, 256);
this->jBus->open(name, 2, 256);
}

void Bus::open(const char *name, uint16_t tx_queue_len, uint16_t rx_queue_len) {
Expand Down
Loading