stream world data from pxl8d to pxl8
This commit is contained in:
parent
39ee0fefb7
commit
a71a9840b2
55 changed files with 5290 additions and 2131 deletions
139
pxl8d/src/log.rs
Normal file
139
pxl8d/src/log.rs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
use crate::protocol::{pxl8_log, pxl8_log_init};
|
||||
use core::ffi::c_char;
|
||||
|
||||
static mut G_LOG: pxl8_log = pxl8_log {
|
||||
handler: None,
|
||||
level: crate::protocol::pxl8_log_level::PXL8_LOG_LEVEL_DEBUG,
|
||||
};
|
||||
|
||||
pub fn init() {
|
||||
unsafe {
|
||||
pxl8_log_init(&raw mut G_LOG);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pxl8_debug {
|
||||
($($arg:tt)*) => {{
|
||||
use ::core::fmt::Write;
|
||||
let mut buf = $crate::log::LogBuffer::new();
|
||||
let _ = ::core::write!(&mut buf, $($arg)*);
|
||||
buf.push(0);
|
||||
unsafe {
|
||||
$crate::protocol::pxl8_log_write_debug(
|
||||
concat!(file!(), "\0").as_ptr() as *const ::core::ffi::c_char,
|
||||
line!() as ::core::ffi::c_int,
|
||||
c"%s".as_ptr() as *const ::core::ffi::c_char,
|
||||
buf.as_ptr(),
|
||||
);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pxl8_error {
|
||||
($($arg:tt)*) => {{
|
||||
use ::core::fmt::Write;
|
||||
let mut buf = $crate::log::LogBuffer::new();
|
||||
let _ = ::core::write!(&mut buf, $($arg)*);
|
||||
buf.push(0);
|
||||
unsafe {
|
||||
$crate::protocol::pxl8_log_write_error(
|
||||
concat!(file!(), "\0").as_ptr() as *const ::core::ffi::c_char,
|
||||
line!() as ::core::ffi::c_int,
|
||||
c"%s".as_ptr() as *const ::core::ffi::c_char,
|
||||
buf.as_ptr(),
|
||||
);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pxl8_info {
|
||||
($($arg:tt)*) => {{
|
||||
use ::core::fmt::Write;
|
||||
let mut buf = $crate::log::LogBuffer::new();
|
||||
let _ = ::core::write!(&mut buf, $($arg)*);
|
||||
buf.push(0);
|
||||
unsafe {
|
||||
$crate::protocol::pxl8_log_write_info(
|
||||
c"%s".as_ptr() as *const ::core::ffi::c_char,
|
||||
buf.as_ptr(),
|
||||
);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pxl8_trace {
|
||||
($($arg:tt)*) => {{
|
||||
use ::core::fmt::Write;
|
||||
let mut buf = $crate::log::LogBuffer::new();
|
||||
let _ = ::core::write!(&mut buf, $($arg)*);
|
||||
buf.push(0);
|
||||
unsafe {
|
||||
$crate::protocol::pxl8_log_write_trace(
|
||||
concat!(file!(), "\0").as_ptr() as *const ::core::ffi::c_char,
|
||||
line!() as ::core::ffi::c_int,
|
||||
c"%s".as_ptr() as *const ::core::ffi::c_char,
|
||||
buf.as_ptr(),
|
||||
);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pxl8_warn {
|
||||
($($arg:tt)*) => {{
|
||||
use ::core::fmt::Write;
|
||||
let mut buf = $crate::log::LogBuffer::new();
|
||||
let _ = ::core::write!(&mut buf, $($arg)*);
|
||||
buf.push(0);
|
||||
unsafe {
|
||||
$crate::protocol::pxl8_log_write_warn(
|
||||
concat!(file!(), "\0").as_ptr() as *const ::core::ffi::c_char,
|
||||
line!() as ::core::ffi::c_int,
|
||||
c"%s".as_ptr() as *const ::core::ffi::c_char,
|
||||
buf.as_ptr(),
|
||||
);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
pub struct LogBuffer {
|
||||
buf: [u8; 1024],
|
||||
pos: usize,
|
||||
}
|
||||
|
||||
impl LogBuffer {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
buf: [0; 1024],
|
||||
pos: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_ptr(&self) -> *const c_char {
|
||||
self.buf.as_ptr() as *const c_char
|
||||
}
|
||||
|
||||
pub fn push(&mut self, b: u8) {
|
||||
if self.pos < self.buf.len() {
|
||||
self.buf[self.pos] = b;
|
||||
self.pos += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Write for LogBuffer {
|
||||
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
||||
for b in s.bytes() {
|
||||
if self.pos >= self.buf.len() - 1 {
|
||||
break;
|
||||
}
|
||||
self.buf[self.pos] = b;
|
||||
self.pos += 1;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue