Compare commits
No commits in common. "main" and "forgejo-pipeline" have entirely different histories.
main
...
forgejo-pi
2
.github/workflows/rust.yml
vendored
2
.github/workflows/rust.yml
vendored
|
@ -24,7 +24,7 @@ jobs:
|
||||||
- name: Update repos
|
- name: Update repos
|
||||||
run: sudo apt-get update -qq
|
run: sudo apt-get update -qq
|
||||||
- name: Install rust toolchain
|
- name: Install rust toolchain
|
||||||
run: sudo apt-get install -qy cargo-1.80 rust-1.80-clippy
|
run: sudo apt-get install -qy cargo rust-clippy
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: sudo apt-get install -qy liblzma-dev libfontconfig1-dev
|
run: sudo apt-get install -qy liblzma-dev libfontconfig1-dev
|
||||||
|
|
||||||
|
|
681
Cargo.lock
generated
681
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
25
Cargo.toml
25
Cargo.toml
|
@ -1,16 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
name = "servicepoint-simulator"
|
name = "servicepoint-simulator"
|
||||||
version = "0.2.4"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = true
|
publish = false
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
keywords = ["cccb", "cccb-servicepoint", "cli"]
|
|
||||||
description = "A simulator for the Service Point display."
|
|
||||||
homepage = "https://git.berlin.ccc.de/servicepoint/servicepoint-simulator"
|
|
||||||
repository = "https://git.berlin.ccc.de/servicepoint/servicepoint-simulator.git"
|
|
||||||
readme = "README.md"
|
|
||||||
rust-version = "1.80.0"
|
|
||||||
resolver = "2"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# basics
|
# basics
|
||||||
|
@ -19,21 +12,15 @@ env_logger = "0.11"
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
|
|
||||||
|
# package parsing
|
||||||
|
servicepoint = { version = "0.13.0", features = ["all_compressions"] }
|
||||||
|
|
||||||
# font rendering
|
# font rendering
|
||||||
font-kit = "0.14.2"
|
font-kit = "0.14.2"
|
||||||
# I should not need this as a direct dependency, but then I cannot spell the types needed to use font-kit...
|
# I should not need this as a direct dependency, but then I cannot spell the types needed to use font-kit...
|
||||||
pathfinder_geometry = "0.5.1"
|
pathfinder_geometry = "0.5.1"
|
||||||
|
|
||||||
# for opening a window
|
# for opening a window
|
||||||
winit = "0.30"
|
winit = "0.30.8"
|
||||||
# for drawing pixels onto the surface of the window
|
# for drawing pixels onto the surface of the window
|
||||||
softbuffer = "0.4.6"
|
softbuffer = "0.4.6"
|
||||||
|
|
||||||
[dependencies.servicepoint]
|
|
||||||
version = "0.16.0"
|
|
||||||
features = ["all_compressions"]
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = true # Enable link-time optimization
|
|
||||||
codegen-units = 1 # Reduce number of codegen units to increase optimizations
|
|
||||||
strip = true # Strip symbols from binary
|
|
||||||
|
|
62
README.md
62
README.md
|
@ -1,40 +1,25 @@
|
||||||
# servicepoint-simulator
|
# servicepoint-simulator
|
||||||
|
|
||||||
[](https://git.berlin.ccc.de/servicepoint/servicepoint-simulator/releases)
|
An emulator for the CCCB airport display.
|
||||||
[](https://crates.io/crates/servicepoint-simulator)
|
|
||||||
[](https://crates.io/crates/servicepoint-simulator)
|
|
||||||
[](./LICENSE)
|
|
||||||
[](https://git.berlin.ccc.de/servicepoint/servicepoint-simulator)
|
|
||||||
|
|
||||||
A simulator for the CCCB service point display.
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
In CCCB, there is a big LED matrix screen you can send images to via UDP.
|
In CCCB, there is a big LED matrix screen you can send images to via UDP.
|
||||||
This crate contains an application that can receive packages in the same binary format and display the contents to the
|
This project aims to build a working an application that can receive packages in the same binary format and display the contents to the user.
|
||||||
user.
|
|
||||||
|
|
||||||
Use cases:
|
Use cases:
|
||||||
|
- getting error messages for invalid packages
|
||||||
- getting error messages for invalid packages (instead of nothing happening on the display)
|
|
||||||
- test your project when outside CCCB
|
- test your project when outside CCCB
|
||||||
- test your project while other people are using the display
|
- test your project while other people are using the display
|
||||||
|
|
||||||
Uses the [servicepoint](https://github.com/cccb/servicepoint) library for reading the packets.
|
Uses the [servicepoint](https://github.com/cccb/servicepoint) library for reading the packets.
|
||||||
The screenshot above shows the output of two example projects running in parallel (game_of_life and random_brightness).
|
The screenshot above shows the output of two example projects running in parallel (game_of_life and random_brightness).
|
||||||
|
|
||||||
This repository moved
|
|
||||||
to [git.berlin.ccc.de/servicepoint/servicepoint-simulator](https://git.berlin.ccc.de/servicepoint/servicepoint-simulator/).
|
|
||||||
The [GitHub repository](https://github.com/kaesaecracker/servicepoint-simulator) will remain as a mirror.
|
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
With cargo installed: `cargo install servicepoint-simulator`
|
|
||||||
|
|
||||||
With nix flakes: `nix run github:kaesaecracker/servicepoint-simulator`
|
With nix flakes: `nix run github:kaesaecracker/servicepoint-simulator`
|
||||||
|
|
||||||
You can also check out this repository and use `cargo run --release`.
|
Without nix: check out this repository and use `cargo run --release`.
|
||||||
Make sure to run a release build, because a debug build _way_ slower.
|
|
||||||
|
|
||||||
## Command line arguments
|
## Command line arguments
|
||||||
|
|
||||||
|
@ -42,41 +27,23 @@ Make sure to run a release build, because a debug build _way_ slower.
|
||||||
Usage: servicepoint-simulator [OPTIONS]
|
Usage: servicepoint-simulator [OPTIONS]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--bind <BIND>
|
--bind <BIND> address and port to bind to [default: 0.0.0.0:2342]
|
||||||
address and port to bind to [default: 0.0.0.0:2342]
|
-f, --font <FONT> The name of the font family to use. This defaults to the system monospace font.
|
||||||
-f, --font <FONT>
|
-s, --spacers add spacers between tile rows to simulate gaps in real display
|
||||||
The name of the font family to use. This defaults to the system monospace font.
|
-r, --red Use the red color channel
|
||||||
-s, --spacers
|
-g, --green Use the green color channel
|
||||||
add spacers between tile rows to simulate gaps in real display
|
-b, --blue Use the blue color channel
|
||||||
-r, --red
|
-v, --verbose Set default log level lower. You can also change this via the RUST_LOG environment variable.
|
||||||
Use the red color channel
|
-h, --help Print help
|
||||||
-g, --green
|
|
||||||
Use the green color channel
|
|
||||||
-b, --blue
|
|
||||||
Use the blue color channel
|
|
||||||
-v, --verbose
|
|
||||||
Set default log level lower. You can also change this via the RUST_LOG environment variable.
|
|
||||||
--experimental-null-char-handling
|
|
||||||
When receiving a null byte as a char in the CharGridCommand, do not overwrite any pixels instead of clearing all pixels.
|
|
||||||
-h, --help
|
|
||||||
Print help
|
|
||||||
```
|
```
|
||||||
|
|
||||||
See [env_logger](https://docs.rs/env_logger/latest/env_logger/) to configure logging.
|
See [env_logger](https://docs.rs/env_logger/latest/env_logger/) to configure logging.
|
||||||
|
|
||||||
Because this program renders to an RGB pixel buffer, you can enjoy the following additional features not available on
|
Because this program renders to an RGB pixel buffer, you can enjoy the following additional features not available on the real display:
|
||||||
the real display:
|
|
||||||
|
|
||||||
- enable or disable the empty space between tile rows (`./servicepoint-simulator --spacers` to enable)
|
- enable or disable the empty space between tile rows (`./servicepoint-simulator --spacers` to enable)
|
||||||
- render pixels in red, green, blue or a combination of the three (`./servicepoint-simulator -rgb` for white pixels)
|
- render pixels in red, green, blue or a combination of the three (`./servicepoint-simulator -rgb` for white pixels)
|
||||||
|
|
||||||
## Known differences
|
|
||||||
|
|
||||||
- The font used for displaying UTF-8 text is your default system monospace font, rendered to 8x8 pixels
|
|
||||||
- The brightness levels will look linear in the simulator
|
|
||||||
- Some commands will be executed in part on the real display and then produce an error (in a console you cannot see)
|
|
||||||
while the simulator refuses to execute the whole command
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Contributions are accepted in any form (issues, documentation, feature requests, code, reviews, ...).
|
Contributions are accepted in any form (issues, documentation, feature requests, code, reviews, ...).
|
||||||
|
@ -85,7 +52,6 @@ All creatures welcome.
|
||||||
|
|
||||||
## Legal stuff
|
## Legal stuff
|
||||||
|
|
||||||
The included font is https://int10h.org/oldschool-pc-fonts/fontlist/font?ibm_bios (included in the download
|
The included font is https://int10h.org/oldschool-pc-fonts/fontlist/font?ibm_bios (included in the download from https://int10h.org/oldschool-pc-fonts/download/). The font is CC BY-SA 4.0.
|
||||||
from https://int10h.org/oldschool-pc-fonts/download/). The font is CC BY-SA 4.0.
|
|
||||||
|
|
||||||
For everything else see the LICENSE file.
|
For everything else see the LICENSE file.
|
||||||
|
|
14
flake.lock
14
flake.lock
|
@ -7,11 +7,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1752249768,
|
"lastModified": 1736429655,
|
||||||
"narHash": "sha256-wKqMvhTqMgTKM/CdTH/ihq9eLZM95qpU0FG7cvTBFJg=",
|
"narHash": "sha256-BwMekRuVlSB9C0QgwKMICiJ5EVbLGjfe4qyueyNQyGI=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "naersk",
|
"repo": "naersk",
|
||||||
"rev": "35aa63738857c40f98ecb04db52887d664836e74",
|
"rev": "0621e47bd95542b8e1ce2ee2d65d6a1f887a13ce",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -37,16 +37,16 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1752162966,
|
"lastModified": 1736200483,
|
||||||
"narHash": "sha256-3MxxkU8ZXMHXcbFz7UE4M6qnIPTYGcE/7EMqlZNnVDE=",
|
"narHash": "sha256-JO+lFN2HsCwSLMUWXHeOad6QUxOuwe9UOAF/iSl1J4I=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "10e687235226880ed5e9f33f1ffa71fe60f2638a",
|
"rev": "3f0a8ac25fb674611b98089ca3a5dd6480175751",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"ref": "nixos-25.05",
|
"ref": "nixos-24.11",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
description = "Flake for servicepoint-simulator";
|
description = "Flake for servicepoint-simulator";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
|
||||||
nix-filter.url = "github:numtide/nix-filter";
|
nix-filter.url = "github:numtide/nix-filter";
|
||||||
naersk = {
|
naersk = {
|
||||||
url = "github:nix-community/naersk";
|
url = "github:nix-community/naersk";
|
||||||
|
@ -75,7 +75,6 @@
|
||||||
NIX_LD_LIBRARY_PATH = LD_LIBRARY_PATH;
|
NIX_LD_LIBRARY_PATH = LD_LIBRARY_PATH;
|
||||||
NIX_LD = pkgs.stdenv.cc.bintools.dynamicLinker;
|
NIX_LD = pkgs.stdenv.cc.bintools.dynamicLinker;
|
||||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
RUST_BACKTRACE = "1";
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -22,11 +22,6 @@ pub struct Cli {
|
||||||
help = "Set default log level lower. You can also change this via the RUST_LOG environment variable."
|
help = "Set default log level lower. You can also change this via the RUST_LOG environment variable."
|
||||||
)]
|
)]
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
#[arg(
|
|
||||||
long,
|
|
||||||
help = "When receiving a null byte as a char in the CharGridCommand, do not overwrite any pixels instead of clearing all pixels."
|
|
||||||
)]
|
|
||||||
pub experimental_null_char_handling: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
|
|
@ -1,28 +1,20 @@
|
||||||
use crate::{
|
use crate::command_executor::ExecutionResult::{Failure, Shutdown, Success};
|
||||||
command_executor::ExecutionResult::{Failure, Shutdown, Success},
|
use crate::cp437_font::Cp437Font;
|
||||||
cp437_font::Cp437Font,
|
use crate::font_renderer::FontRenderer8x8;
|
||||||
font_renderer::FontRenderer8x8,
|
|
||||||
};
|
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
BinaryOperation, BitVecCommand, Bitmap, BitmapCommand, BrightnessGrid,
|
BitVec, Bitmap, BrightnessGrid, CharGrid, Command, Cp437Grid, Grid, Offset,
|
||||||
BrightnessGridCommand, CharGridCommand, ClearCommand, CompressionCode,
|
Origin, Tiles, PIXEL_COUNT, PIXEL_WIDTH, TILE_SIZE,
|
||||||
Cp437GridCommand, FadeOutCommand, GlobalBrightnessCommand, Grid, GridMut,
|
|
||||||
HardResetCommand, Origin, TypedCommand, PIXEL_COUNT, PIXEL_WIDTH,
|
|
||||||
TILE_SIZE,
|
|
||||||
};
|
|
||||||
use std::{
|
|
||||||
ops::{BitAnd, BitOr, BitXor},
|
|
||||||
sync::RwLock,
|
|
||||||
};
|
};
|
||||||
|
use std::ops::{BitAnd, BitOr, BitXor};
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CommandExecutionContext<'t> {
|
pub struct CommandExecutor<'t> {
|
||||||
display: &'t RwLock<Bitmap>,
|
display: &'t RwLock<Bitmap>,
|
||||||
luma: &'t RwLock<BrightnessGrid>,
|
luma: &'t RwLock<BrightnessGrid>,
|
||||||
cp437_font: Cp437Font,
|
cp437_font: Cp437Font,
|
||||||
font_renderer: FontRenderer8x8,
|
font_renderer: FontRenderer8x8,
|
||||||
experimental_null_char_handling: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
@ -32,36 +24,201 @@ pub enum ExecutionResult {
|
||||||
Shutdown,
|
Shutdown,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CommandExecute {
|
impl<'t> CommandExecutor<'t> {
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult;
|
pub fn new(
|
||||||
}
|
display: &'t RwLock<Bitmap>,
|
||||||
|
luma: &'t RwLock<BrightnessGrid>,
|
||||||
|
font_renderer: FontRenderer8x8,
|
||||||
|
) -> Self {
|
||||||
|
CommandExecutor {
|
||||||
|
display,
|
||||||
|
luma,
|
||||||
|
font_renderer,
|
||||||
|
cp437_font: Cp437Font::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl CommandExecute for ClearCommand {
|
pub(crate) fn execute(&self, command: Command) -> ExecutionResult {
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult {
|
debug!("received {command:?}");
|
||||||
info!("clearing display");
|
match command {
|
||||||
context.display.write().unwrap().fill(false);
|
Command::Clear => {
|
||||||
|
info!("clearing display");
|
||||||
|
self.display.write().unwrap().fill(false);
|
||||||
|
Success
|
||||||
|
}
|
||||||
|
Command::HardReset => {
|
||||||
|
warn!("display shutting down");
|
||||||
|
Shutdown
|
||||||
|
}
|
||||||
|
Command::BitmapLinearWin(Origin { x, y, .. }, pixels, _) => {
|
||||||
|
self.print_pixel_grid(x, y, &pixels)
|
||||||
|
}
|
||||||
|
Command::Cp437Data(origin, grid) => {
|
||||||
|
self.print_cp437_data(origin, &grid)
|
||||||
|
}
|
||||||
|
#[allow(deprecated)]
|
||||||
|
Command::BitmapLegacy => {
|
||||||
|
warn!("ignoring deprecated command {:?}", command);
|
||||||
|
Failure
|
||||||
|
}
|
||||||
|
Command::BitmapLinearAnd(offset, vec, _) => {
|
||||||
|
self.execute_bitmap_linear(offset, vec, BitAnd::bitand)
|
||||||
|
}
|
||||||
|
Command::BitmapLinearOr(offset, vec, _) => {
|
||||||
|
self.execute_bitmap_linear(offset, vec, BitOr::bitor)
|
||||||
|
}
|
||||||
|
Command::BitmapLinearXor(offset, vec, _) => {
|
||||||
|
self.execute_bitmap_linear(offset, vec, BitXor::bitxor)
|
||||||
|
}
|
||||||
|
Command::BitmapLinear(offset, vec, _) => {
|
||||||
|
self.execute_bitmap_linear(offset, vec, move |_, new| new)
|
||||||
|
}
|
||||||
|
Command::CharBrightness(origin, grid) => {
|
||||||
|
self.execute_char_brightness(origin, grid)
|
||||||
|
}
|
||||||
|
Command::Brightness(brightness) => {
|
||||||
|
self.luma.write().unwrap().fill(brightness);
|
||||||
|
Success
|
||||||
|
}
|
||||||
|
Command::FadeOut => {
|
||||||
|
error!("command not implemented: {command:?}");
|
||||||
|
Success
|
||||||
|
}
|
||||||
|
Command::Utf8Data(origin, grid) => {
|
||||||
|
self.print_utf8_data(origin, &grid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute_char_brightness(
|
||||||
|
&self,
|
||||||
|
origin: Origin<Tiles>,
|
||||||
|
grid: BrightnessGrid,
|
||||||
|
) -> ExecutionResult {
|
||||||
|
let mut luma = self.luma.write().unwrap();
|
||||||
|
for inner_y in 0..grid.height() {
|
||||||
|
for inner_x in 0..grid.width() {
|
||||||
|
let brightness = grid.get(inner_x, inner_y);
|
||||||
|
luma.set(origin.x + inner_x, origin.y + inner_y, brightness);
|
||||||
|
}
|
||||||
|
}
|
||||||
Success
|
Success
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandExecute for BitmapCommand {
|
fn execute_bitmap_linear<Op>(
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult {
|
&self,
|
||||||
let Self {
|
offset: Offset,
|
||||||
origin:
|
vec: BitVec,
|
||||||
Origin {
|
op: Op,
|
||||||
x: offset_x,
|
) -> ExecutionResult
|
||||||
y: offset_y,
|
where
|
||||||
..
|
Op: Fn(bool, bool) -> bool,
|
||||||
},
|
{
|
||||||
bitmap: pixels,
|
if !Self::check_bitmap_valid(offset as u16, vec.len()) {
|
||||||
..
|
return Failure;
|
||||||
} = self;
|
}
|
||||||
|
let mut display = self.display.write().unwrap();
|
||||||
|
for bitmap_index in 0..vec.len() {
|
||||||
|
let (x, y) = Self::get_coordinates_for_index(offset, bitmap_index);
|
||||||
|
let old_value = display.get(x, y);
|
||||||
|
display.set(x, y, op(old_value, vec[bitmap_index]));
|
||||||
|
}
|
||||||
|
Success
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_bitmap_valid(offset: u16, payload_len: usize) -> bool {
|
||||||
|
if offset as usize + payload_len > PIXEL_COUNT {
|
||||||
|
error!(
|
||||||
|
"bitmap with offset {offset} is too big ({payload_len} bytes)"
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_cp437_data(
|
||||||
|
&self,
|
||||||
|
origin: Origin<Tiles>,
|
||||||
|
grid: &Cp437Grid,
|
||||||
|
) -> ExecutionResult {
|
||||||
|
let font = &self.cp437_font;
|
||||||
|
let Origin { x, y, .. } = origin;
|
||||||
|
for char_y in 0usize..grid.height() {
|
||||||
|
for char_x in 0usize..grid.width() {
|
||||||
|
let char_code = grid.get(char_x, char_y);
|
||||||
|
trace!(
|
||||||
|
"drawing char_code {char_code:#04x} (if this was UTF-8, it would be {})",
|
||||||
|
char::from(char_code)
|
||||||
|
);
|
||||||
|
|
||||||
|
let tile_x = char_x + x;
|
||||||
|
let tile_y = char_y + y;
|
||||||
|
|
||||||
|
match self.print_pixel_grid(
|
||||||
|
tile_x * TILE_SIZE,
|
||||||
|
tile_y * TILE_SIZE,
|
||||||
|
&font[char_code],
|
||||||
|
) {
|
||||||
|
Success => {}
|
||||||
|
Failure => {
|
||||||
|
error!(
|
||||||
|
"stopping drawing text because char draw failed"
|
||||||
|
);
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
Shutdown => return Shutdown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Success
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_utf8_data(
|
||||||
|
&self,
|
||||||
|
origin: Origin<Tiles>,
|
||||||
|
grid: &CharGrid,
|
||||||
|
) -> ExecutionResult {
|
||||||
|
let mut display = self.display.write().unwrap();
|
||||||
|
|
||||||
|
let Origin { x, y, .. } = origin;
|
||||||
|
for char_y in 0usize..grid.height() {
|
||||||
|
for char_x in 0usize..grid.width() {
|
||||||
|
let char = grid.get(char_x, char_y);
|
||||||
|
trace!("drawing {char}");
|
||||||
|
|
||||||
|
let tile_x = char_x + x;
|
||||||
|
let tile_y = char_y + y;
|
||||||
|
|
||||||
|
if let Err(e) = self.font_renderer.render(
|
||||||
|
char,
|
||||||
|
&mut display,
|
||||||
|
Origin::new(tile_x * TILE_SIZE, tile_y * TILE_SIZE),
|
||||||
|
) {
|
||||||
|
error!(
|
||||||
|
"stopping drawing text because char draw failed: {e}"
|
||||||
|
);
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Success
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_pixel_grid(
|
||||||
|
&self,
|
||||||
|
offset_x: usize,
|
||||||
|
offset_y: usize,
|
||||||
|
pixels: &Bitmap,
|
||||||
|
) -> ExecutionResult {
|
||||||
debug!(
|
debug!(
|
||||||
"printing {}x{} grid at {offset_x} {offset_y}",
|
"printing {}x{} grid at {offset_x} {offset_y}",
|
||||||
pixels.width(),
|
pixels.width(),
|
||||||
pixels.height()
|
pixels.height()
|
||||||
);
|
);
|
||||||
let mut display = context.display.write().unwrap();
|
let mut display = self.display.write().unwrap();
|
||||||
for inner_y in 0..pixels.height() {
|
for inner_y in 0..pixels.height() {
|
||||||
for inner_x in 0..pixels.width() {
|
for inner_x in 0..pixels.width() {
|
||||||
let is_set = pixels.get(inner_x, inner_y);
|
let is_set = pixels.get(inner_x, inner_y);
|
||||||
|
@ -79,202 +236,12 @@ impl CommandExecute for BitmapCommand {
|
||||||
|
|
||||||
Success
|
Success
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandExecute for HardResetCommand {
|
fn get_coordinates_for_index(
|
||||||
fn execute(&self, _: &CommandExecutionContext) -> ExecutionResult {
|
offset: usize,
|
||||||
warn!("display shutting down");
|
index: usize,
|
||||||
Shutdown
|
) -> (usize, usize) {
|
||||||
}
|
let pixel_index = offset + index;
|
||||||
}
|
(pixel_index % PIXEL_WIDTH, pixel_index / PIXEL_WIDTH)
|
||||||
|
|
||||||
impl CommandExecute for BitVecCommand {
|
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult {
|
|
||||||
let BitVecCommand {
|
|
||||||
offset,
|
|
||||||
bitvec,
|
|
||||||
operation,
|
|
||||||
..
|
|
||||||
} = self;
|
|
||||||
fn overwrite(_: bool, new: bool) -> bool {
|
|
||||||
new
|
|
||||||
}
|
|
||||||
let operation = match operation {
|
|
||||||
BinaryOperation::Overwrite => overwrite,
|
|
||||||
BinaryOperation::And => BitAnd::bitand,
|
|
||||||
BinaryOperation::Or => BitOr::bitor,
|
|
||||||
BinaryOperation::Xor => BitXor::bitxor,
|
|
||||||
};
|
|
||||||
|
|
||||||
if self.offset + bitvec.len() > PIXEL_COUNT {
|
|
||||||
error!(
|
|
||||||
"bitmap with offset {offset} is too big ({} bytes)",
|
|
||||||
bitvec.len()
|
|
||||||
);
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut display = context.display.write().unwrap();
|
|
||||||
for bitmap_index in 0..bitvec.len() {
|
|
||||||
let pixel_index = offset + bitmap_index;
|
|
||||||
let (x, y) = (pixel_index % PIXEL_WIDTH, pixel_index / PIXEL_WIDTH);
|
|
||||||
let old_value = display.get(x, y);
|
|
||||||
display.set(x, y, operation(old_value, bitvec[bitmap_index]));
|
|
||||||
}
|
|
||||||
Success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandExecute for Cp437GridCommand {
|
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult {
|
|
||||||
let Cp437GridCommand { origin, grid } = self;
|
|
||||||
let Origin { x, y, .. } = origin;
|
|
||||||
for char_y in 0usize..grid.height() {
|
|
||||||
for char_x in 0usize..grid.width() {
|
|
||||||
let char_code = grid.get(char_x, char_y);
|
|
||||||
trace!(
|
|
||||||
"drawing char_code {char_code:#04x} (if this was UTF-8, it would be {})",
|
|
||||||
char::from(char_code)
|
|
||||||
);
|
|
||||||
|
|
||||||
let tile_x = char_x + x;
|
|
||||||
let tile_y = char_y + y;
|
|
||||||
|
|
||||||
let execute_result = BitmapCommand {
|
|
||||||
origin: Origin::new(tile_x * TILE_SIZE, tile_y * TILE_SIZE),
|
|
||||||
bitmap: context.cp437_font[char_code].clone(),
|
|
||||||
compression: CompressionCode::default(),
|
|
||||||
}
|
|
||||||
.execute(context);
|
|
||||||
match execute_result {
|
|
||||||
Success => {}
|
|
||||||
Failure => {
|
|
||||||
error!(
|
|
||||||
"stopping drawing text because char draw failed"
|
|
||||||
);
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
Shutdown => return Shutdown,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl CommandExecute for servicepoint::BitmapLegacyCommand {
|
|
||||||
fn execute(&self, _: &CommandExecutionContext) -> ExecutionResult {
|
|
||||||
warn!("ignoring deprecated command {:?}", self);
|
|
||||||
Failure
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandExecute for BrightnessGridCommand {
|
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult {
|
|
||||||
let BrightnessGridCommand { origin, grid } = self;
|
|
||||||
let mut luma = context.luma.write().unwrap();
|
|
||||||
for inner_y in 0..grid.height() {
|
|
||||||
for inner_x in 0..grid.width() {
|
|
||||||
let brightness = grid.get(inner_x, inner_y);
|
|
||||||
luma.set(origin.x + inner_x, origin.y + inner_y, brightness);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandExecute for CharGridCommand {
|
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult {
|
|
||||||
let CharGridCommand { origin, grid } = self;
|
|
||||||
let mut display = context.display.write().unwrap();
|
|
||||||
|
|
||||||
let Origin { x, y, .. } = origin;
|
|
||||||
for char_y in 0usize..grid.height() {
|
|
||||||
for char_x in 0usize..grid.width() {
|
|
||||||
let char = grid.get(char_x, char_y);
|
|
||||||
let mut bitmap_window = {
|
|
||||||
let pixel_x = (char_x + x) * TILE_SIZE;
|
|
||||||
let pixel_y = (char_y + y) * TILE_SIZE;
|
|
||||||
display
|
|
||||||
.window_mut(
|
|
||||||
pixel_x..pixel_x + TILE_SIZE,
|
|
||||||
pixel_y..pixel_y + TILE_SIZE,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
if char == '\0' {
|
|
||||||
if context.experimental_null_char_handling {
|
|
||||||
trace!("skipping {char:?}");
|
|
||||||
} else {
|
|
||||||
bitmap_window.fill(false);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
trace!("drawing {char}");
|
|
||||||
if let Err(e) =
|
|
||||||
context.font_renderer.render(char, &mut bitmap_window)
|
|
||||||
{
|
|
||||||
error!(
|
|
||||||
"stopping drawing text because char draw failed: {e}"
|
|
||||||
);
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandExecute for GlobalBrightnessCommand {
|
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult {
|
|
||||||
context.luma.write().unwrap().fill(self.brightness);
|
|
||||||
Success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandExecute for FadeOutCommand {
|
|
||||||
fn execute(&self, _: &CommandExecutionContext) -> ExecutionResult {
|
|
||||||
error!("command not implemented: {self:?}");
|
|
||||||
Success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandExecute for TypedCommand {
|
|
||||||
fn execute(&self, context: &CommandExecutionContext) -> ExecutionResult {
|
|
||||||
match self {
|
|
||||||
TypedCommand::Clear(command) => command.execute(context),
|
|
||||||
TypedCommand::HardReset(command) => command.execute(context),
|
|
||||||
TypedCommand::Bitmap(command) => command.execute(context),
|
|
||||||
TypedCommand::Cp437Grid(command) => command.execute(context),
|
|
||||||
#[allow(deprecated)]
|
|
||||||
TypedCommand::BitmapLegacy(command) => command.execute(context),
|
|
||||||
TypedCommand::BitVec(command) => command.execute(context),
|
|
||||||
TypedCommand::BrightnessGrid(command) => command.execute(context),
|
|
||||||
TypedCommand::Brightness(command) => command.execute(context),
|
|
||||||
TypedCommand::FadeOut(command) => command.execute(context),
|
|
||||||
TypedCommand::CharGrid(command) => command.execute(context),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'t> CommandExecutionContext<'t> {
|
|
||||||
pub fn new(
|
|
||||||
display: &'t RwLock<Bitmap>,
|
|
||||||
luma: &'t RwLock<BrightnessGrid>,
|
|
||||||
font_renderer: FontRenderer8x8,
|
|
||||||
experimental_null_char_handling: bool,
|
|
||||||
) -> Self {
|
|
||||||
CommandExecutionContext {
|
|
||||||
display,
|
|
||||||
luma,
|
|
||||||
font_renderer,
|
|
||||||
cp437_font: Cp437Font::default(),
|
|
||||||
experimental_null_char_handling,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,8 @@ impl Cp437Font {
|
||||||
|
|
||||||
impl Default for Cp437Font {
|
impl Default for Cp437Font {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let mut bitmaps = core::array::from_fn(|_| {
|
let mut bitmaps =
|
||||||
Bitmap::new(TILE_SIZE, TILE_SIZE).unwrap()
|
core::array::from_fn(|_| Bitmap::new(TILE_SIZE, TILE_SIZE));
|
||||||
});
|
|
||||||
|
|
||||||
for (char_code, bitmap) in bitmaps.iter_mut().enumerate() {
|
for (char_code, bitmap) in bitmaps.iter_mut().enumerate() {
|
||||||
let bits = CP437_FONT_LINEAR[char_code];
|
let bits = CP437_FONT_LINEAR[char_code];
|
||||||
|
|
|
@ -12,11 +12,8 @@ use pathfinder_geometry::{
|
||||||
transform2d::Transform2F,
|
transform2d::Transform2F,
|
||||||
vector::{vec2f, vec2i},
|
vector::{vec2f, vec2i},
|
||||||
};
|
};
|
||||||
use servicepoint::{Bitmap, GridMut, WindowMut, TILE_SIZE};
|
use servicepoint::{Bitmap, Grid, Origin, Pixels, TILE_SIZE};
|
||||||
use std::{
|
use std::sync::{Mutex, MutexGuard};
|
||||||
collections::HashMap,
|
|
||||||
sync::{Mutex, MutexGuard},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct SendFont(Font);
|
struct SendFont(Font);
|
||||||
|
@ -35,7 +32,6 @@ pub struct FontRenderer8x8 {
|
||||||
font: SendFont,
|
font: SendFont,
|
||||||
canvas: Mutex<Canvas>,
|
canvas: Mutex<Canvas>,
|
||||||
fallback_char: Option<u32>,
|
fallback_char: Option<u32>,
|
||||||
cache: Mutex<HashMap<char, Bitmap>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
@ -60,7 +56,6 @@ impl FontRenderer8x8 {
|
||||||
font: SendFont(font),
|
font: SendFont(font),
|
||||||
fallback_char,
|
fallback_char,
|
||||||
canvas: Mutex::new(canvas),
|
canvas: Mutex::new(canvas),
|
||||||
cache: Mutex::new(HashMap::new()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,13 +74,9 @@ impl FontRenderer8x8 {
|
||||||
pub fn render(
|
pub fn render(
|
||||||
&self,
|
&self,
|
||||||
char: char,
|
char: char,
|
||||||
target: &mut WindowMut<bool, Bitmap>,
|
bitmap: &mut Bitmap,
|
||||||
|
offset: Origin<Pixels>,
|
||||||
) -> Result<(), RenderError> {
|
) -> Result<(), RenderError> {
|
||||||
let cache = &mut *self.cache.lock().unwrap();
|
|
||||||
if let Some(drawn_char) = cache.get(&char) {
|
|
||||||
target.deref_assign(drawn_char);
|
|
||||||
}
|
|
||||||
|
|
||||||
let glyph_id = self.get_glyph(char)?;
|
let glyph_id = self.get_glyph(char)?;
|
||||||
|
|
||||||
let mut canvas = self.canvas.lock().unwrap();
|
let mut canvas = self.canvas.lock().unwrap();
|
||||||
|
@ -100,21 +91,20 @@ impl FontRenderer8x8 {
|
||||||
RasterizationOptions::Bilevel,
|
RasterizationOptions::Bilevel,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut bitmap = Bitmap::new(TILE_SIZE, TILE_SIZE).unwrap();
|
Self::copy_to_bitmap(canvas, bitmap, offset)
|
||||||
Self::copy_to_bitmap(canvas, &mut bitmap)?;
|
|
||||||
target.deref_assign(&bitmap);
|
|
||||||
cache.insert(char, bitmap);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_to_bitmap(
|
fn copy_to_bitmap(
|
||||||
canvas: MutexGuard<Canvas>,
|
canvas: MutexGuard<Canvas>,
|
||||||
bitmap: &mut Bitmap,
|
bitmap: &mut Bitmap,
|
||||||
|
offset: Origin<Pixels>,
|
||||||
) -> Result<(), RenderError> {
|
) -> Result<(), RenderError> {
|
||||||
for y in 0..TILE_SIZE {
|
for y in 0..TILE_SIZE {
|
||||||
for x in 0..TILE_SIZE {
|
for x in 0..TILE_SIZE {
|
||||||
let canvas_val = canvas.pixels[x + y * TILE_SIZE] != 0;
|
let canvas_val = canvas.pixels[x + y * TILE_SIZE] != 0;
|
||||||
if !bitmap.set_optional(x, y, canvas_val) {
|
let bitmap_x = (offset.x + x) as isize;
|
||||||
|
let bitmap_y = (offset.y + y) as isize;
|
||||||
|
if !bitmap.set_optional(bitmap_x, bitmap_y, canvas_val) {
|
||||||
return Err(OutOfBounds(x, y));
|
return Err(OutOfBounds(x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
use std::{sync::mpsc::Sender, sync::RwLock};
|
||||||
|
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use servicepoint::*;
|
use servicepoint::*;
|
||||||
use std::{sync::mpsc::Sender, sync::RwLock};
|
|
||||||
use winit::{
|
use winit::{
|
||||||
application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent,
|
application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent,
|
||||||
event_loop::ActiveEventLoop, keyboard::KeyCode::KeyC, window::WindowId,
|
event_loop::ActiveEventLoop, keyboard::KeyCode::KeyC, window::WindowId,
|
||||||
|
@ -24,7 +25,6 @@ const PIXEL_HEIGHT_WITH_SPACERS: usize =
|
||||||
PIXEL_HEIGHT + NUM_SPACERS * SPACER_HEIGHT;
|
PIXEL_HEIGHT + NUM_SPACERS * SPACER_HEIGHT;
|
||||||
|
|
||||||
const OFF_COLOR: u32 = u32::from_ne_bytes([0u8, 0, 0, 0]);
|
const OFF_COLOR: u32 = u32::from_ne_bytes([0u8, 0, 0, 0]);
|
||||||
const SPACER_COLOR: u32 = u32::from_ne_bytes([100u8, 100, 100, 0]);
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum AppEvents {
|
pub enum AppEvents {
|
||||||
|
@ -62,7 +62,7 @@ impl<'t> Gui<'t> {
|
||||||
if self.options.spacers && tile_y != 0 {
|
if self.options.spacers && tile_y != 0 {
|
||||||
// cannot just frame.skip(PIXEL_WIDTH as usize * SPACER_HEIGHT as usize) because of typing
|
// cannot just frame.skip(PIXEL_WIDTH as usize * SPACER_HEIGHT as usize) because of typing
|
||||||
for _ in 0..PIXEL_WIDTH * SPACER_HEIGHT {
|
for _ in 0..PIXEL_WIDTH * SPACER_HEIGHT {
|
||||||
*frame.next().unwrap() = SPACER_COLOR;
|
frame.next().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::font_renderer::FontRenderer8x8;
|
use crate::font_renderer::FontRenderer8x8;
|
||||||
use crate::udp_server::UdpServer;
|
use crate::udp_server::UdpServer;
|
||||||
use crate::{command_executor::CommandExecutionContext, gui::Gui};
|
use crate::{command_executor::CommandExecutor, gui::Gui};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cli::Cli;
|
use cli::Cli;
|
||||||
use log::{info, LevelFilter};
|
use log::{info, LevelFilter};
|
||||||
|
@ -32,23 +32,18 @@ fn main() {
|
||||||
.expect("could not create event loop");
|
.expect("could not create event loop");
|
||||||
event_loop.set_control_flow(ControlFlow::Wait);
|
event_loop.set_control_flow(ControlFlow::Wait);
|
||||||
|
|
||||||
let display = RwLock::new(Bitmap::max_sized());
|
let display = RwLock::new(Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT));
|
||||||
let luma = RwLock::new(BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT));
|
let luma = RwLock::new(BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT));
|
||||||
let (stop_udp_tx, stop_udp_rx) = mpsc::channel();
|
let (stop_udp_tx, stop_udp_rx) = mpsc::channel();
|
||||||
let font_renderer = cli
|
let font_renderer = cli
|
||||||
.font
|
.font
|
||||||
.map(FontRenderer8x8::from_name)
|
.map(FontRenderer8x8::from_name)
|
||||||
.unwrap_or_else(FontRenderer8x8::default);
|
.unwrap_or_else(FontRenderer8x8::default);
|
||||||
let context = CommandExecutionContext::new(
|
let command_executor = CommandExecutor::new(&display, &luma, font_renderer);
|
||||||
&display,
|
|
||||||
&luma,
|
|
||||||
font_renderer,
|
|
||||||
cli.experimental_null_char_handling,
|
|
||||||
);
|
|
||||||
let mut udp_server = UdpServer::new(
|
let mut udp_server = UdpServer::new(
|
||||||
cli.bind,
|
cli.bind,
|
||||||
stop_udp_rx,
|
stop_udp_rx,
|
||||||
context,
|
command_executor,
|
||||||
event_loop.create_proxy(),
|
event_loop.create_proxy(),
|
||||||
);
|
);
|
||||||
let mut gui = Gui::new(&display, &luma, stop_udp_tx, cli.gui);
|
let mut gui = Gui::new(&display, &luma, stop_udp_tx, cli.gui);
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
use crate::command_executor::CommandExecute;
|
use crate::command_executor::{CommandExecutor, ExecutionResult};
|
||||||
use crate::{
|
use crate::gui::AppEvents;
|
||||||
command_executor::{CommandExecutionContext, ExecutionResult},
|
use log::{error, warn};
|
||||||
gui::AppEvents,
|
use servicepoint::Command;
|
||||||
};
|
use std::io::ErrorKind;
|
||||||
use log::{debug, error, warn};
|
use std::net::UdpSocket;
|
||||||
use servicepoint::TypedCommand;
|
use std::sync::mpsc::Receiver;
|
||||||
use std::{
|
use std::time::Duration;
|
||||||
io::ErrorKind, net::UdpSocket, sync::mpsc::Receiver, time::Duration,
|
|
||||||
};
|
|
||||||
use winit::event_loop::EventLoopProxy;
|
use winit::event_loop::EventLoopProxy;
|
||||||
|
|
||||||
const BUF_SIZE: usize = 8985 * 2;
|
const BUF_SIZE: usize = 8985;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UdpServer<'t> {
|
pub struct UdpServer<'t> {
|
||||||
socket: UdpSocket,
|
socket: UdpSocket,
|
||||||
stop_rx: Receiver<()>,
|
stop_rx: Receiver<()>,
|
||||||
command_executor: CommandExecutionContext<'t>,
|
command_executor: CommandExecutor<'t>,
|
||||||
app_events: EventLoopProxy<AppEvents>,
|
app_events: EventLoopProxy<AppEvents>,
|
||||||
buf: [u8; BUF_SIZE],
|
buf: [u8; BUF_SIZE],
|
||||||
}
|
}
|
||||||
|
@ -25,7 +23,7 @@ impl<'t> UdpServer<'t> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
bind: String,
|
bind: String,
|
||||||
stop_rx: Receiver<()>,
|
stop_rx: Receiver<()>,
|
||||||
command_executor: CommandExecutionContext<'t>,
|
command_executor: CommandExecutor<'t>,
|
||||||
app_events: EventLoopProxy<AppEvents>,
|
app_events: EventLoopProxy<AppEvents>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let socket = UdpSocket::bind(bind).expect("could not bind socket");
|
let socket = UdpSocket::bind(bind).expect("could not bind socket");
|
||||||
|
@ -47,8 +45,7 @@ impl<'t> UdpServer<'t> {
|
||||||
if let Some(cmd) = self.receive_into_buf().and_then(|amount| {
|
if let Some(cmd) = self.receive_into_buf().and_then(|amount| {
|
||||||
Self::command_from_slice(&self.buf[..amount])
|
Self::command_from_slice(&self.buf[..amount])
|
||||||
}) {
|
}) {
|
||||||
debug!("received {cmd:?}");
|
match self.command_executor.execute(cmd) {
|
||||||
match cmd.execute(&self.command_executor) {
|
|
||||||
ExecutionResult::Success => {
|
ExecutionResult::Success => {
|
||||||
self.app_events
|
self.app_events
|
||||||
.send_event(AppEvents::UdpPacketHandled)
|
.send_event(AppEvents::UdpPacketHandled)
|
||||||
|
@ -68,13 +65,13 @@ impl<'t> UdpServer<'t> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn command_from_slice(slice: &[u8]) -> Option<TypedCommand> {
|
fn command_from_slice(slice: &[u8]) -> Option<Command> {
|
||||||
let packet = servicepoint::Packet::try_from(slice)
|
let packet = servicepoint::Packet::try_from(slice)
|
||||||
.inspect_err(|_| {
|
.inspect_err(|_| {
|
||||||
warn!("could not load packet with length {}", slice.len())
|
warn!("could not load packet with length {}", slice.len())
|
||||||
})
|
})
|
||||||
.ok()?;
|
.ok()?;
|
||||||
TypedCommand::try_from(packet)
|
Command::try_from(packet)
|
||||||
.inspect_err(move |err| {
|
.inspect_err(move |err| {
|
||||||
warn!("could not read command for packet: {:?}", err)
|
warn!("could not read command for packet: {:?}", err)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue