-
-
Notifications
You must be signed in to change notification settings - Fork 0
Contributing
Thank you for considering contributing to Zigbee Analyzer! This document provides guidelines for contributing to the project.
- [Code of Conduct](#code-of-conduct)
- [Getting Started](#getting-started)
- [Development Setup](#development-setup)
- [Contribution Workflow](#contribution-workflow)
- [Code Style](#code-style)
- [Testing](#testing)
- [Documentation](#documentation)
- [Pull Request Process](#pull-request-process)
We are committed to providing a welcoming and inclusive environment for all contributors regardless of experience level, gender identity, sexual orientation, disability, ethnicity, religion, or other personal characteristics.
Expected Behavior
- Use welcoming and inclusive language
- Be respectful of differing viewpoints and experiences
- Accept constructive criticism gracefully
- Focus on what is best for the community
- Show empathy towards other community members
- Harassment, trolling, or discriminatory comments
- Personal or political attacks
- Public or private harassment
- Publishing others' private information without permission
- Other conduct which could reasonably be considered inappropriate
- Bug Reports: Found a bug? Let us know!
- Feature Requests: Have an idea? Share it!
- Code: Fix bugs, add features, improve performance
- Documentation: Improve docs, add examples, fix typos
- Hardware Support: Add drivers for new devices
- Testing: Test on different platforms and hardware
- Design: Improve UI/UX
Look for issues labeled good first issue or help wanted:
- Simple bug fixes
- Documentation improvements
- Test additions
- Minor feature implementations
# Rust (1.70 or newer)
rustup update stable
# Development tools
rustup component add rustfmt clippy
# Optional: cargo-watch for auto-rebuild
cargo install cargo-watch# Fork the repository on GitHub, then clone your fork
git clone https://github.com/YOUR_USERNAME/zigbee-analyzer.git
cd zigbee-analyzer
# Add upstream remote
git remote add upstream https://github.com/wofl/zigbee-analyzer.git
# Build all crates
cargo build
# Run tests
cargo test --all
# Run linter
cargo clippy --all-targets --all-features# Create a feature branch
git checkout -b feature/my-awesome-feature
# Make changes, commit often
git add .
git commit -m "Add feature X"
# Keep your branch up to date
git fetch upstream
git rebase upstream/main
# Push to your fork
git push origin feature/my-awesome-featureWe follow the official Rust style guide. Use rustfmt to format code:
# Format all code
cargo fmt --all
# Check formatting without changing files
cargo fmt --all -- --checkTypes and Traits:
// PascalCase
struct RawPacket { }
trait ZigbeeCapture { }
enum FrameType { }Functions and Variables:
// snake_case
fn capture_packet() { }
let frame_count = 0;Constants:
// SCREAMING_SNAKE_CASE
const MAX_PACKET_SIZE: usize = 127;
const SOF: u8 = 0xFE;Public APIs must have doc comments:
/// Captures a single packet from the device.
///
/// This function blocks until a packet is received or a timeout occurs.
///
/// # Errors
///
/// Returns `HalError::Timeout` if no packet is received within the
/// configured timeout period.
///
/// # Examples
///
/// ```
/// let packet = driver.capture_packet().await?;
/// println!("RSSI: {} dBm", packet.rssi);
/// ```
pub async fn capture_packet(&mut self) -> HalResult<RawPacket> {
// ...
}Use Result types:
// Good
fn parse_frame(data: &[u8]) -> Result<Frame, ParseError> {
// ...
}
// Bad
fn parse_frame(data: &[u8]) -> Frame {
// ...panics on error
}Provide context in errors:
// Good
Err(HalError::CommunicationError(format!(
"Failed to write command 0x{:02x}: {}", cmd, e
)))
// Less good
Err(HalError::CommunicationError(e.to_string()))Explain the "why", not the "what":
// Good
// Wait 100ms for device to reset, per datasheet section 4.2
tokio::time::sleep(Duration::from_millis(100)).await;
// Less good
// Sleep for 100 milliseconds
tokio::time::sleep(Duration::from_millis(100)).await;All new code should include tests:
- Unit tests for individual functions
- Integration tests for module interactions
- Documentation tests in doc comments
-
Hardware tests (when applicable, marked with
#[ignore])
Unit tests:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_frame_parsing() {
let data = vec![0x41, 0x88, 0x01, 0xCD, 0xAB];
let frame = parse_mac_frame(&data).unwrap();
assert_eq!(frame.frame_type, FrameType::Data);
assert_eq!(frame.sequence, 0x01);
}
#[test]
fn test_checksum_calculation() {
let data = vec![0x01, 0x02, 0x03];
assert_eq!(calculate_fcs(&data), 0x00);
}
}Async tests:
#[tokio::test]
async fn test_packet_capture() {
let mut driver = MockDriver::new();
let packet = driver.capture_packet().await.unwrap();
assert!(!packet.data.is_empty());
}Hardware tests (opt-in):
#[tokio::test]
#[ignore] // Only run with --ignored flag
async fn test_real_hardware() {
let mut driver = CC2531::new().unwrap();
driver.initialize().await.unwrap();
// ...
}# All tests
cargo test --all
# Specific crate
cargo test -p zigbee-core
# With output
cargo test -- --nocapture
# Hardware tests (requires real hardware)
cargo test --all -- --ignored --test-threads=1
# Coverage (requires tarpaulin)
cargo tarpaulin --all --out HtmlFor performance-critical code, add benchmarks:
#[bench]
fn bench_packet_parsing(b: &mut Bencher) {
let data = generate_test_packet();
b.iter(|| {
parse_mac_frame(&data)
});
}Run benchmarks:
cargo bench --allEach crate should have a README.md with:
- Brief description
- Usage examples
- Key features
- Dependencies
All public APIs must have documentation:
/// Brief one-line summary.
///
/// More detailed explanation of what this does,
/// how it works, and when to use it.
///
/// # Arguments
///
/// * `channel` - Channel number (11-26)
///
/// # Returns
///
/// Returns `Ok(())` on success.
///
/// # Errors
///
/// * `HalError::InvalidChannel` - If channel is out of range
/// * `HalError::CommunicationError` - If device communication fails
///
/// # Examples
///
/// ```
/// # use zigbee_hal::traits::ZigbeeCapture;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let mut driver = CC2531::new()?;
/// driver.set_channel(15).await?;
/// # Ok(())
/// # }
/// ```
pub async fn set_channel(&mut self, channel: u8) -> HalResult<()>When adding major features, update the wiki:
- Architecture changes → Update Architecture
- New hardware → Update Hardware Support
- New examples → Add to Examples
Checklist:
- Code compiles without warnings
- All tests pass (
cargo test --all) - Code is formatted (
cargo fmt --all) - No clippy warnings (
cargo clippy --all-targets) - Documentation is updated
- CHANGELOG.md is updated (if applicable)
- Commit messages are descriptive
-
Push your branch:
git push origin feature/my-awesome-feature
-
Open PR on GitHub:
- Go to your fork on GitHub
- Click "New Pull Request"
- Select your branch
- Fill out the PR template
-
PR Title Format:
[Type] Brief description Types: - feat: New feature - fix: Bug fix - docs: Documentation only - style: Code style (formatting, etc.) - refactor: Code refactoring - test: Adding tests - chore: Maintenance tasks -
PR Description Template:
## Description Brief description of changes ## Motivation Why is this change needed? ## Changes - Change 1 - Change 2 ## Testing How was this tested? ## Screenshots (if applicable) ## Checklist - [ ] Tests pass - [ ] Code is formatted - [ ] Documentation updated
-
Automated checks run on all PRs:
- Compilation
- Tests
- Linting
- Coverage
-
Code review:
- At least one maintainer reviews
- Address feedback promptly
- Update PR as needed
-
Merge:
- Once approved, maintainer will merge
- Squash commits for clean history
- Delete feature branch after merge
See Driver Development for detailed guide.
Quick checklist:
- Implement
ZigbeeCapturetrait - Add to
DriverRegistry - Write tests (unit + integration)
- Document in Hardware Support
- Provide example usage
- Include photos/links if possible
- Create an issue first (if not already exists)
-
Reference issue in commits:
Fix #123: Description - Add regression test to prevent recurrence
- Test on affected platforms
- Discuss first in an issue or discussion
- Start small - iterative improvements
- Maintain backward compatibility when possible
- Document thoroughly
- Add examples showing new feature
(For maintainers)
We follow [Semantic Versioning](https://semver.org/):
- Major (1.0.0): Breaking changes
- Minor (0.1.0): New features, backward compatible
- Patch (0.0.1): Bug fixes
- Update version in all
Cargo.tomlfiles - Update
CHANGELOG.md - Run full test suite
- Update documentation
- Create git tag
- Publish to crates.io
- Create GitHub release
- GitHub Issues: Bug reports, feature requests
- GitHub Discussions: Questions, ideas, general discussion
- Pull Requests: Code review, implementation discussion
- Issues: We aim to respond within 48 hours
- Pull Requests: Initial review within 72 hours
- Critical bugs: Priority response
Contributors are recognized in:
-
CONTRIBUTORS.mdfile - Release notes
- Project README
Thank you for contributing to Zigbee Analyzer!
- [Rust Style Guide](https://doc.rust-lang.org/1.0.0/style/)
- [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/)
- [Conventional Commits](https://www.conventionalcommits.org/)
- [Semantic Versioning](https://semver.org/)
If you have questions about contributing:
- Check existing issues and discussions
- Open a new discussion
- Reach out to maintainers
We're here to help! 🎉