Compare commits
4 commits
389ced492c
...
e7426bdabe
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e7426bdabe | ||
![]() |
e5825819e6 | ||
![]() |
01b3169020 | ||
![]() |
c9d2479f5e |
56
Cargo.lock
generated
56
Cargo.lock
generated
|
@ -58,20 +58,20 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-wincon"
|
name = "anstyle-wincon"
|
||||||
version = "3.0.7"
|
version = "3.0.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
|
checksum = "6680de5231bd6ee4c6191b8a1325daa282b415391ec9d3a37bd34f2060dc73fa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"once_cell",
|
"once_cell_polyfill",
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.9.0"
|
version = "2.9.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitvec"
|
name = "bitvec"
|
||||||
|
@ -125,9 +125,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.21"
|
version = "1.2.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8691782945451c1c383942c4874dbe63814f61cb57ef773cda2972682b7bb3c0"
|
checksum = "16595d3be041c03b09d08d0858631facccee9221e579704070e6e9e4915d3bc7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jobserver",
|
"jobserver",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -142,18 +142,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.37"
|
version = "4.5.38"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
|
checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.37"
|
version = "4.5.38"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2"
|
checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
|
@ -213,9 +213,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "errno"
|
name = "errno"
|
||||||
version = "0.3.11"
|
version = "0.3.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e"
|
checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
|
@ -245,9 +245,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
|
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -291,9 +291,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jiff"
|
name = "jiff"
|
||||||
version = "0.2.13"
|
version = "0.2.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f02000660d30638906021176af16b17498bd0d12813dbfe7b276d8bc7f3c0806"
|
checksum = "a194df1107f33c79f4f93d02c80798520551949d59dfad22b6157048a88cca93"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jiff-static",
|
"jiff-static",
|
||||||
"log",
|
"log",
|
||||||
|
@ -304,9 +304,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jiff-static"
|
name = "jiff-static"
|
||||||
version = "0.2.13"
|
version = "0.2.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f3c30758ddd7188629c6713fc45d1188af4f44c90582311d0c8d8c9907f60c48"
|
checksum = "6c6e1db7ed32c6c71b759497fae34bf7933636f75a251b9e736555da426f6442"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -362,6 +362,12 @@ version = "1.21.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.32"
|
version = "0.3.32"
|
||||||
|
@ -514,7 +520,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servicepoint"
|
name = "servicepoint"
|
||||||
version = "0.14.1"
|
version = "0.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91a33bff7f9db5008748b23ca0c906c276fe00694390b681f004a55968a42cfe"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"bzip2",
|
"bzip2",
|
||||||
|
@ -566,9 +574,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.19.1"
|
version = "3.20.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf"
|
checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
|
@ -740,9 +748,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winnow"
|
name = "winnow"
|
||||||
version = "0.7.9"
|
version = "0.7.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d9fb597c990f03753e08d3c29efbfcf2019a003b4bf4ba19225c158e1549f0f3"
|
checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
|
@ -18,7 +18,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
cbindgen = "0.28.0"
|
cbindgen = "0.28.0"
|
||||||
|
|
||||||
[dependencies.servicepoint]
|
[dependencies.servicepoint]
|
||||||
version = "0.14.1"
|
version = "0.15.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.env_logger]
|
[dependencies.env_logger]
|
||||||
|
|
|
@ -14,23 +14,11 @@ CCFLAGS += -Wall -Wextra -pedantic -fwhole-program -fPIE -pie
|
||||||
|
|
||||||
STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag
|
STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag
|
||||||
|
|
||||||
ifeq ($(CFG_MUSL), 1)
|
|
||||||
TARGET ?= x86_64-unknown-linux-musl
|
|
||||||
CC ?= musl-gcc
|
|
||||||
CCFLAGS += -static -lservicepoint_binding_c
|
|
||||||
RUSTFLAGS += --crate-type=staticlib -Ctarget-feature=-crt-static
|
|
||||||
else
|
|
||||||
TARGET ?= x86_64-unknown-linux-gnu
|
|
||||||
CC ?= gcc
|
|
||||||
#CCFLAGS += -shared
|
|
||||||
CCFLAGS += -Wl,-Bstatic -lservicepoint_binding_c -Wl,-Bdynamic
|
|
||||||
endif
|
|
||||||
|
|
||||||
#ifeq ($(CFG_PROFILE), size-optimized)
|
#ifeq ($(CFG_PROFILE), size-optimized)
|
||||||
# CCFLAGS += -nodefaultlibs -lc
|
# CCFLAGS += -nodefaultlibs -lc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE)
|
STATIC_LINK_LIBS := -lservicepoint_binding_c
|
||||||
|
|
||||||
ifeq ($(CFG_PROFILE), size-optimized)
|
ifeq ($(CFG_PROFILE), size-optimized)
|
||||||
CARGO_PROFILE := size-optimized
|
CARGO_PROFILE := size-optimized
|
||||||
|
@ -53,16 +41,34 @@ ifeq ($(CFG_PROFILE), size-optimized)
|
||||||
-C link-arg=-z,norelro \
|
-C link-arg=-z,norelro \
|
||||||
-C panic=abort
|
-C panic=abort
|
||||||
#-C link-arg=--hash-style=gnu
|
#-C link-arg=--hash-style=gnu
|
||||||
else ifeq ($(CFG_PROFILE), release)
|
|
||||||
CARGO_PROFILE := release
|
|
||||||
CCFLAGS += -O2
|
|
||||||
else ifeq ($(CFG_PROFILE), debug)
|
|
||||||
CCFLAGS += -Og
|
|
||||||
CARGO_PROFILE := dev
|
|
||||||
else
|
else
|
||||||
CFG_PROFILE := $(error "PROFILE has to be set to one of: debug, release, size-optimized")
|
FEATURES := $(FEATURES),all_compressions
|
||||||
|
STATIC_LINK_LIBS += -llzma
|
||||||
|
ifeq ($(CFG_PROFILE), release)
|
||||||
|
CARGO_PROFILE := release
|
||||||
|
CCFLAGS += -O2
|
||||||
|
else ifeq ($(CFG_PROFILE), debug)
|
||||||
|
CCFLAGS += -Og
|
||||||
|
CARGO_PROFILE := dev
|
||||||
|
else
|
||||||
|
CFG_PROFILE := $(error "PROFILE has to be set to one of: debug, release, size-optimized")
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
ifeq ($(CFG_MUSL), 1)
|
||||||
|
TARGET ?= x86_64-unknown-linux-musl
|
||||||
|
CC ?= musl-gcc
|
||||||
|
CCFLAGS += -static $(STATIC_LINK_LIBS)
|
||||||
|
RUSTFLAGS += --crate-type=staticlib -Ctarget-feature=-crt-static
|
||||||
|
else
|
||||||
|
TARGET ?= x86_64-unknown-linux-gnu
|
||||||
|
CC ?= gcc
|
||||||
|
#CCFLAGS += -shared
|
||||||
|
CCFLAGS += -Wl,-Bstatic $(STATIC_LINK_LIBS) -Wl,-Bdynamic
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \
|
CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \
|
||||||
--profile=$(CARGO_PROFILE) \
|
--profile=$(CARGO_PROFILE) \
|
||||||
--no-default-features \
|
--no-default-features \
|
||||||
|
@ -78,6 +84,8 @@ ifeq ($(LTO), 1)
|
||||||
CCFLAGS += -flto
|
CCFLAGS += -flto
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE)
|
||||||
|
|
||||||
_c_src := $(wildcard ./src/*.c)
|
_c_src := $(wildcard ./src/*.c)
|
||||||
_programs := $(basename $(notdir $(_c_src)))
|
_programs := $(basename $(notdir $(_c_src)))
|
||||||
_bins := $(addprefix out/, $(_programs))
|
_bins := $(addprefix out/, $(_programs))
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "servicepoint.h"
|
#include "servicepoint.h"
|
||||||
|
|
||||||
#define DEFAULT_LISTEN_IP "127.0.0.1"
|
#define DEFAULT_LISTEN_IP "127.0.0.1"
|
||||||
|
@ -48,6 +49,7 @@ int main(int argc, char **argv) {
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
ssize_t num_bytes = recv(udp_socket, (void *) buffer, sizeof(buffer), 0);
|
ssize_t num_bytes = recv(udp_socket, (void *) buffer, sizeof(buffer), 0);
|
||||||
if (num_bytes == -1)
|
if (num_bytes == -1)
|
||||||
|
@ -63,14 +65,140 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Header *header = sp_packet_get_header(packet);
|
struct Header *header = sp_packet_get_header(packet);
|
||||||
|
|
||||||
ByteSlice payload = sp_packet_get_payload(packet);
|
ByteSlice payload = sp_packet_get_payload(packet);
|
||||||
printf("Received packet: cc=%d, a=%d, b=%d, c=%d, d=%d, payload=%p (len %zu)\n",
|
printf("Received packet: cc=%d, a=%d, b=%d, c=%d, d=%d, payload=%p (len %zu)\n",
|
||||||
header->command_code, header->a, header->b, header->c, header->d,
|
header->command_code, header->a, header->b, header->c, header->d,
|
||||||
payload.start, payload.length);
|
payload.start, payload.length);
|
||||||
|
|
||||||
done = header->command_code == COMMAND_CODE_HARD_RESET;
|
struct Command command = sp_cmd_generic_try_from_packet(packet);
|
||||||
sp_packet_free(packet);
|
switch (command.tag) {
|
||||||
|
case COMMAND_TAG_INVALID: {
|
||||||
|
printf("-> this is an invalid command\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_HARD_RESET: {
|
||||||
|
printf("-> HardReset command - exiting\n");
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_BITMAP: {
|
||||||
|
BitmapCommand *bitmapCommand = command.data.bitmap;
|
||||||
|
|
||||||
|
CompressionCode compression = sp_cmd_bitmap_get_compression(bitmapCommand);
|
||||||
|
|
||||||
|
size_t x, y;
|
||||||
|
sp_cmd_bitmap_get_origin(bitmapCommand, &x, &y);
|
||||||
|
|
||||||
|
Bitmap *bitmap = sp_cmd_bitmap_get(bitmapCommand);
|
||||||
|
size_t w = sp_bitmap_width(bitmap);
|
||||||
|
size_t h = sp_bitmap_height(bitmap);
|
||||||
|
|
||||||
|
printf("-> BitmapCommand with params: x=%zu, y=%zu, w=%zu, h=%zu, compression=%hu\n",
|
||||||
|
x, y, w, h, compression);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_BRIGHTNESS_GRID: {
|
||||||
|
BrightnessGridCommand *gridCommand = command.data.brightness_grid;
|
||||||
|
|
||||||
|
size_t x, y;
|
||||||
|
sp_cmd_brightness_grid_get_origin(gridCommand, &x, &y);
|
||||||
|
|
||||||
|
BrightnessGrid *grid = sp_cmd_brightness_grid_get(gridCommand);
|
||||||
|
size_t w = sp_brightness_grid_width(grid);
|
||||||
|
size_t h = sp_brightness_grid_height(grid);
|
||||||
|
|
||||||
|
printf("-> BrightnessGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||||
|
x, y, w, h);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_CHAR_GRID: {
|
||||||
|
CharGridCommand *gridCommand = command.data.char_grid;
|
||||||
|
|
||||||
|
size_t x, y;
|
||||||
|
sp_cmd_char_grid_get_origin(gridCommand, &x, &y);
|
||||||
|
|
||||||
|
CharGrid *grid = sp_cmd_char_grid_get(gridCommand);
|
||||||
|
size_t w = sp_char_grid_width(grid);
|
||||||
|
size_t h = sp_char_grid_height(grid);
|
||||||
|
|
||||||
|
printf("-> CharGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||||
|
x, y, w, h);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_CP437_GRID: {
|
||||||
|
Cp437GridCommand *gridCommand = command.data.cp437_grid;
|
||||||
|
|
||||||
|
size_t x, y;
|
||||||
|
sp_cmd_cp437_grid_get_origin(gridCommand, &x, &y);
|
||||||
|
|
||||||
|
Cp437Grid *grid = sp_cmd_cp437_grid_get(gridCommand);
|
||||||
|
size_t w = sp_cp437_grid_width(grid);
|
||||||
|
size_t h = sp_cp437_grid_height(grid);
|
||||||
|
|
||||||
|
printf("-> Cp437GridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||||
|
x, y, w, h);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_BIT_VEC: {
|
||||||
|
BitVecCommand *bitvecCommand = command.data.bitvec;
|
||||||
|
|
||||||
|
size_t offset = sp_cmd_bitvec_get_offset(bitvecCommand);
|
||||||
|
CompressionCode compression = sp_cmd_bitvec_get_compression(bitvecCommand);
|
||||||
|
|
||||||
|
BinaryOperation operation = sp_cmd_bitvec_get_operation(bitvecCommand);
|
||||||
|
char *operationText;
|
||||||
|
switch (operation) {
|
||||||
|
case BINARY_OPERATION_AND:
|
||||||
|
operationText = "and";
|
||||||
|
break;
|
||||||
|
case BINARY_OPERATION_OR:
|
||||||
|
operationText = "or";
|
||||||
|
break;
|
||||||
|
case BINARY_OPERATION_XOR:
|
||||||
|
operationText = "xor";
|
||||||
|
break;
|
||||||
|
case BINARY_OPERATION_OVERWRITE:
|
||||||
|
operationText ="overwrite";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
operationText ="unknown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
BitVec *bitvec = sp_cmd_bitvec_get(bitvecCommand);
|
||||||
|
size_t len = sp_bitvec_len(bitvec);
|
||||||
|
|
||||||
|
printf("-> BitVecCommand with params: offset=%zu, length=%zu, compression=%hu, operation=%s\n",
|
||||||
|
offset, len, compression, operationText);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_CLEAR: {
|
||||||
|
printf("-> ClearCommand\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_BITMAP_LEGACY: {
|
||||||
|
printf("-> BitmapLinearLegacy\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_FADE_OUT:{
|
||||||
|
printf("-> FadeOutCommand\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COMMAND_TAG_GLOBAL_BRIGHTNESS: {
|
||||||
|
Brightness brightness = sp_cmd_brightness_global_get(command.data.global_brightness);
|
||||||
|
printf("-> GlobalBrightnessCommand with params: brightness=%hu\n", brightness);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
printf("-> unknown command tag %d\n", command.tag);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sp_cmd_generic_free(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(udp_socket);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1739357830,
|
"lastModified": 1747862697,
|
||||||
"narHash": "sha256-9xim3nJJUFbVbJCz48UP4fGRStVW5nv4VdbimbKxJ3I=",
|
"narHash": "sha256-U4HaNZ1W26cbOVm0Eb5OdGSnfQVWQKbLSPrSSa78KC0=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "0ff09db9d034a04acd4e8908820ba0b410d7a33a",
|
"rev": "2baa12ff69913392faf0ace833bc54bba297ea95",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -159,23 +159,28 @@ typedef uint8_t CommandTag;
|
||||||
*
|
*
|
||||||
* # Examples
|
* # Examples
|
||||||
*
|
*
|
||||||
|
* create command without payload compression
|
||||||
* ```rust
|
* ```rust
|
||||||
* # use servicepoint::*;
|
* # use servicepoint::*;
|
||||||
* // create command without payload compression
|
|
||||||
* # let pixels = Bitmap::max_sized();
|
* # let pixels = Bitmap::max_sized();
|
||||||
* _ = BitmapCommand {
|
* _ = BitmapCommand {
|
||||||
* origin: Origin::ZERO,
|
* origin: Origin::ZERO,
|
||||||
* bitmap: pixels,
|
* bitmap: pixels,
|
||||||
* compression: CompressionCode::Uncompressed
|
* compression: CompressionCode::Uncompressed
|
||||||
* };
|
* };
|
||||||
|
* ```
|
||||||
*
|
*
|
||||||
* // create command with payload compressed with lzma and appropriate header flags
|
* create command with payload compressed with lzma and appropriate header flags
|
||||||
|
* ```rust
|
||||||
|
* # use servicepoint::*;
|
||||||
* # let pixels = Bitmap::max_sized();
|
* # let pixels = Bitmap::max_sized();
|
||||||
|
* # #[cfg(feature = "compression_lzma")] {
|
||||||
* _ = BitmapCommand {
|
* _ = BitmapCommand {
|
||||||
* origin: Origin::ZERO,
|
* origin: Origin::ZERO,
|
||||||
* bitmap: pixels,
|
* bitmap: pixels,
|
||||||
* compression: CompressionCode::Lzma
|
* compression: CompressionCode::Lzma
|
||||||
* };
|
* };
|
||||||
|
* # }
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
enum CompressionCode
|
enum CompressionCode
|
||||||
|
@ -279,7 +284,6 @@ typedef struct BitmapCommand BitmapCommand;
|
||||||
* # use servicepoint::*;
|
* # use servicepoint::*;
|
||||||
* # let connection = FakeConnection;
|
* # let connection = FakeConnection;
|
||||||
* // this sends a packet that does nothing
|
* // this sends a packet that does nothing
|
||||||
* # #[allow(deprecated)]
|
|
||||||
* connection.send_command(BitmapLegacyCommand).unwrap();
|
* connection.send_command(BitmapLegacyCommand).unwrap();
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
@ -332,8 +336,10 @@ typedef struct ClearCommand ClearCommand;
|
||||||
* # use servicepoint::*;
|
* # use servicepoint::*;
|
||||||
* # let connection = FakeConnection;
|
* # let connection = FakeConnection;
|
||||||
* let grid = CharGrid::from("Hello,\nWorld!");
|
* let grid = CharGrid::from("Hello,\nWorld!");
|
||||||
|
* # #[cfg(feature = "cp437")] {
|
||||||
* let grid = Cp437Grid::from(&grid);
|
* let grid = Cp437Grid::from(&grid);
|
||||||
* connection.send_command(Cp437GridCommand{ origin: Origin::ZERO, grid }).expect("send failed");
|
* connection.send_command(Cp437GridCommand{ origin: Origin::ZERO, grid }).expect("send failed");
|
||||||
|
* # }
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* ```rust
|
* ```rust
|
||||||
|
@ -627,6 +633,10 @@ typedef struct Header {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this function at the beginning of main to enable rust logging controlled by the
|
||||||
|
* `RUST_LOG` environment variable. See [env_logger](https://docs.rs/env_logger/latest/env_logger/).
|
||||||
|
*/
|
||||||
void init_env_logger(void);
|
void init_env_logger(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1317,7 +1327,7 @@ struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(struc
|
||||||
|
|
||||||
void sp_cmd_brightness_global_free(struct BitmapCommand */*notnull*/ command);
|
void sp_cmd_brightness_global_free(struct BitmapCommand */*notnull*/ command);
|
||||||
|
|
||||||
Brightness *sp_cmd_brightness_global_get(struct GlobalBrightnessCommand */*notnull*/ command);
|
Brightness sp_cmd_brightness_global_get(struct GlobalBrightnessCommand */*notnull*/ command);
|
||||||
|
|
||||||
struct Packet */*notnull*/ sp_cmd_brightness_global_into_packet(struct GlobalBrightnessCommand */*notnull*/ command);
|
struct Packet */*notnull*/ sp_cmd_brightness_global_into_packet(struct GlobalBrightnessCommand */*notnull*/ command);
|
||||||
|
|
||||||
|
@ -1564,6 +1574,8 @@ struct Command sp_cmd_generic_clone(struct Command command);
|
||||||
/**
|
/**
|
||||||
* Deallocates an [SPCommand].
|
* Deallocates an [SPCommand].
|
||||||
*
|
*
|
||||||
|
* Commands with an invalid `tag` do not have to be freed as the `data` pointer should be null.
|
||||||
|
*
|
||||||
* # Examples
|
* # Examples
|
||||||
*
|
*
|
||||||
* ```C
|
* ```C
|
||||||
|
@ -1588,7 +1600,7 @@ struct Packet *sp_cmd_generic_into_packet(struct Command command);
|
||||||
*
|
*
|
||||||
* Returns: pointer to new [SPCommand] instance or NULL if parsing failed.
|
* Returns: pointer to new [SPCommand] instance or NULL if parsing failed.
|
||||||
*/
|
*/
|
||||||
struct Command *sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet);
|
struct Command sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deallocates a [HardResetCommand].
|
* Deallocates a [HardResetCommand].
|
||||||
|
|
|
@ -74,10 +74,10 @@ impl SPCommand {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_cmd_generic_try_from_packet(
|
pub unsafe extern "C" fn sp_cmd_generic_try_from_packet(
|
||||||
packet: NonNull<Packet>,
|
packet: NonNull<Packet>,
|
||||||
) -> *mut SPCommand {
|
) -> SPCommand {
|
||||||
let packet = *unsafe { Box::from_raw(packet.as_ptr()) };
|
let packet = *unsafe { Box::from_raw(packet.as_ptr()) };
|
||||||
heap_move_ok(servicepoint::TypedCommand::try_from(packet).map(|value| {
|
servicepoint::TypedCommand::try_from(packet)
|
||||||
match value {
|
.map(|value| match value {
|
||||||
TypedCommand::Clear(clear) => SPCommand {
|
TypedCommand::Clear(clear) => SPCommand {
|
||||||
tag: CommandTag::Clear,
|
tag: CommandTag::Clear,
|
||||||
data: CommandUnion {
|
data: CommandUnion {
|
||||||
|
@ -139,8 +139,11 @@ pub unsafe extern "C" fn sp_cmd_generic_try_from_packet(
|
||||||
bitmap_legacy: heap_move_nonnull(bitmap_legacy),
|
bitmap_legacy: heap_move_nonnull(bitmap_legacy),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
}))
|
.unwrap_or_else(move |_| SPCommand {
|
||||||
|
tag: CommandTag::Invalid,
|
||||||
|
data: CommandUnion { null: null_mut() },
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clones an [SPCommand] instance.
|
/// Clones an [SPCommand] instance.
|
||||||
|
@ -219,6 +222,8 @@ pub unsafe extern "C" fn sp_cmd_generic_clone(command: SPCommand) -> SPCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deallocates an [SPCommand].
|
/// Deallocates an [SPCommand].
|
||||||
|
///
|
||||||
|
/// Commands with an invalid `tag` do not have to be freed as the `data` pointer should be null.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
|
|
@ -52,6 +52,6 @@ pub unsafe extern "C" fn sp_cmd_brightness_global_set(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_cmd_brightness_global_get(
|
pub unsafe extern "C" fn sp_cmd_brightness_global_get(
|
||||||
mut command: NonNull<GlobalBrightnessCommand>,
|
mut command: NonNull<GlobalBrightnessCommand>,
|
||||||
) -> *mut Brightness {
|
) -> Brightness {
|
||||||
unsafe { &mut command.as_mut().brightness }
|
unsafe { command.as_mut().brightness }
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,9 @@ pub struct UdpSocket;
|
||||||
pub struct DisplayBitVec;
|
pub struct DisplayBitVec;
|
||||||
|
|
||||||
#[cfg(feature = "env_logger")]
|
#[cfg(feature = "env_logger")]
|
||||||
pub mod feature_env_logger {
|
mod feature_env_logger {
|
||||||
|
/// Call this function at the beginning of main to enable rust logging controlled by the
|
||||||
|
/// `RUST_LOG` environment variable. See [env_logger](https://docs.rs/env_logger/latest/env_logger/).
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn init_env_logger() {
|
pub unsafe extern "C" fn init_env_logger() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
Loading…
Reference in a new issue