add move fn to dsl, rename SPCommand to GenericCommand, remove DisplayBitVec command

This commit is contained in:
Vinzenz Schroeter 2025-06-23 20:26:07 +02:00
parent e434130784
commit 323ba6128e
13 changed files with 335 additions and 356 deletions

View file

@ -15,8 +15,8 @@ void handle_error(const char *msg) {
exit(EXIT_FAILURE);
}
bool log_command(struct Command command) {
switch (command.tag) {
bool log_command(struct GenericCommand *command) {
switch (command->tag) {
case COMMAND_TAG_INVALID: {
printf("-> this is an invalid command\n");
break;
@ -26,7 +26,7 @@ bool log_command(struct Command command) {
return true;
}
case COMMAND_TAG_BITMAP: {
BitmapCommand *bitmapCommand = command.data.bitmap;
BitmapCommand *bitmapCommand = command->data.bitmap;
CompressionCode compression = sp_bitmapcommand_get_compression(bitmapCommand);
@ -42,7 +42,7 @@ bool log_command(struct Command command) {
break;
}
case COMMAND_TAG_BRIGHTNESS_GRID: {
BrightnessGridCommand *gridCommand = command.data.brightness_grid;
BrightnessGridCommand *gridCommand = command->data.brightness_grid;
size_t x, y;
sp_brightnessgridcommand_get_origin(gridCommand, &x, &y);
@ -56,7 +56,7 @@ bool log_command(struct Command command) {
break;
}
case COMMAND_TAG_CHAR_GRID: {
CharGridCommand *gridCommand = command.data.char_grid;
CharGridCommand *gridCommand = command->data.char_grid;
size_t x, y;
sp_chargridcommand_get_origin(gridCommand, &x, &y);
@ -70,7 +70,7 @@ bool log_command(struct Command command) {
break;
}
case COMMAND_TAG_CP437_GRID: {
Cp437GridCommand *gridCommand = command.data.cp437_grid;
Cp437GridCommand *gridCommand = command->data.cp437_grid;
size_t x, y;
sp_cp437gridcommand_get_origin(gridCommand, &x, &y);
@ -84,7 +84,7 @@ bool log_command(struct Command command) {
break;
}
case COMMAND_TAG_BIT_VEC: {
BitVecCommand *bitvecCommand = command.data.bit_vec;
BitVecCommand *bitvecCommand = command->data.bit_vec;
size_t offset = sp_bitveccommand_get_offset(bitvecCommand);
CompressionCode compression = sp_bitveccommand_get_compression(bitvecCommand);
@ -109,7 +109,7 @@ bool log_command(struct Command command) {
break;
}
BitVec *bitvec = sp_bitveccommand_get_bitvec_mut(bitvecCommand);
DisplayBitVec *bitvec = sp_bitveccommand_get_bitvec_mut(bitvecCommand);
size_t len = sp_displaybitvec_len(bitvec);
printf("-> BitVecCommand with params: offset=%zu, length=%zu, compression=%hu, operation=%s\n",
@ -129,12 +129,12 @@ bool log_command(struct Command command) {
break;
}
case COMMAND_TAG_GLOBAL_BRIGHTNESS: {
Brightness brightness = sp_globalbrightnesscommand_get_brightness(command.data.global_brightness);
Brightness brightness = sp_globalbrightnesscommand_get_brightness(command->data.global_brightness);
printf("-> GlobalBrightnessCommand with params: brightness=%hu\n", brightness);
break;
}
default: {
printf("-> unknown command tag %d\n", command.tag);
printf("-> unknown command tag %d\n", command->tag);
break;
}
}
@ -198,10 +198,10 @@ int main(int argc, char **argv) {
header->command_code, header->a, header->b, header->c, header->d,
payload.start, payload.length);
struct Command command = sp_cmd_generic_try_from_packet(packet);
struct GenericCommand *command = sp_genericcommand_try_from_packet(packet);
done = log_command(command);
sp_cmd_generic_free(command);
sp_genericcommand_free(command);
}
close(udp_socket);

View file

@ -9,14 +9,14 @@ int main(void) {
sp_bitveccommand_free(bvcmd);
uint8_t *data = calloc(1024, 1);
struct Command generic = {
struct GenericCommand generic = {
.tag = COMMAND_TAG_BRIGHTNESS_GRID,
.data = {.null = data},
};
sock_init();
sp_udpsocket_send_command(sock, generic);
sp_udpsocket_send_command(sock, &generic);
return 0;
}

View file

@ -13,7 +13,7 @@ int main() {
sp_bitmap_set(enabled_pixels, x, y, false);
}
BitVec *bitvec = sp_bitmap_into_bitvec(sp_bitmap_clone(enabled_pixels));
DisplayBitVec *bitvec = sp_bitmap_into_bitvec(sp_bitmap_clone(enabled_pixels));
BitVecCommand *command = sp_bitveccommand_new(bitvec, 0, BINARY_OPERATION_AND, COMPRESSION_CODE_LZMA);
Packet *packet = sp_bitveccommand_try_into_packet(command);
if (packet == NULL) {