forked from PX4/PX4-Autopilot
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# ########################################################################### | ||
# | ||
# Copyright (c) 2024 Technology Innovation Institute. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in | ||
# the documentation and/or other materials provided with the | ||
# distribution. | ||
# 3. Neither the name PX4 nor the names of its contributors may be | ||
# used to endorse or promote products derived from this software | ||
# without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# ############################################################################ | ||
|
||
px4_add_rust_module( | ||
MODULE modules__rust_module_test | ||
MAIN rust_module_test | ||
RUST_LIB lib__rust_module_test | ||
RUST_MOD | ||
rust_mod | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
menuconfig MODULES_RUST_MODULE_TEST | ||
bool "rust_module_test" | ||
default y | ||
---help--- | ||
Enable rust module test | ||
|
||
menuconfig USER_RUST_MODULE_TEST | ||
bool "rust module test in user" | ||
default y | ||
depends on BOARD_PROTECTED && MODULES_RUST_MODULE_TEST | ||
---help--- | ||
Put rust module test in userspace memory |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "rust_mod" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["staticlib"] | ||
|
||
[dependencies] | ||
log = "0.4" | ||
px4_nuttx = { path = "../../../lib/rust_px4_nuttx" } | ||
px4_nuttx_macros = { path = "../../../lib/rust_px4_nuttx/px4_nuttx_macros" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate px4_nuttx; | ||
extern crate px4_nuttx_macros; | ||
|
||
use log::info; | ||
use px4_nuttx::px4_module_main; | ||
use px4_nuttx::nuttx::net::UdpSocket; | ||
use px4_nuttx::nuttx::time::hrt_time; | ||
use px4_nuttx::alloc::vec::Vec; | ||
|
||
#[px4_module_main] | ||
pub fn run(_args: &[&str]) -> Result<(), ()> { | ||
info!("Hello from Rust module test!"); | ||
let mut count = 0; | ||
for arg in _args { | ||
info!(" arg[{}]: {}", count, arg); | ||
count += 1; | ||
} | ||
|
||
// Test vector | ||
let mut v1: Vec<u8> = Vec::new(); | ||
for i in 0..10 { | ||
v1.push(i+3); | ||
} | ||
info!("This is new vector: {:?}", v1); | ||
|
||
// Test hrt_timer | ||
info!("System timer: {}", hrt_time()); | ||
|
||
// Test udp socket | ||
let socket = UdpSocket::bind("192.168.200.101:12222").unwrap(); | ||
info!("Created socket binded to 0.0.0.0:12222"); | ||
socket.send_to(b"Hello from Rust!\n", "192.168.200.100:12223").unwrap(); | ||
info!("Sent message to 192.168.200.100:12223"); | ||
|
||
Ok(()) | ||
} | ||
|