baudot: add line wrapping

This commit is contained in:
informatic 2024-07-20 11:54:07 +02:00
parent 7fb2f24269
commit 333b851a93
No known key found for this signature in database
3 changed files with 34 additions and 2 deletions

View file

@ -166,6 +166,16 @@ size_t baudot_to_unicode(baudot_context_t *ctx, uint8_t *input, uint8_t input_le
{
unsigned int mapped = baudot_map[c | (ctx->figures << 5)];
ESP_LOGD(TAG, "%02x -> %08x", c, mapped);
if (mapped == '\r')
{
ctx->column = 0;
}
else if (mapped != '\0' && c != '\n')
{
ctx->column += 1;
}
if (mapped < 256)
{
output[out_pos++] = mapped;
@ -295,9 +305,30 @@ size_t unicode_to_baudot(baudot_context_t *ctx, uint8_t *input, uint8_t input_le
ctx->tx_figures = !ctx->tx_figures;
ESP_LOGD(TAG, "figures switch: %d", ctx->tx_figures);
}
ESP_LOGD(TAG, "emitting: %d", x & 0b11111);
output[out_pos++] = x & 0b11111;
found = 1;
if (c == '\r')
{
ctx->column = 0;
}
else if (c != '\0' && c != '\n')
{
ctx->column += 1;
}
if (ctx->column >= 69)
{
// emit newline
output[out_pos++] = 0x1b;
ctx->tx_figures = 1;
output[out_pos++] = 0x08;
output[out_pos++] = 0x02;
ctx->column = 0;
}
break;
}
}

View file

@ -9,6 +9,7 @@ typedef struct
uint8_t tx_figures;
uint8_t unicode_len;
uint32_t unicode_codepoint;
uint8_t column;
} baudot_context_t;
size_t baudot_to_unicode(baudot_context_t *ctx, uint8_t *input, uint8_t input_len, uint8_t *output, uint8_t output_len);

View file

@ -147,7 +147,7 @@ static void tcp_server_task(network_ctx_t *ctx)
else if (read_buffer_len > 0)
{
ESP_LOGI(TAG, "Sending %d bytes to TTY", read_buffer_len);
uint8_t tx_baudot_data[64] = {0};
uint8_t tx_baudot_data[100] = {0};
size_t tx_baudot_data_len = unicode_to_baudot(&unicode_ctx, read_buffer, read_buffer_len, tx_baudot_data, sizeof(tx_baudot_data));
if (tx_baudot_data_len > 0)
{
@ -156,7 +156,7 @@ static void tcp_server_task(network_ctx_t *ctx)
ESP_LOGI(TAG, "TCP->TTY: %02x", tx_baudot_data[i]);
}
xStreamBufferSend(ctx->tx_buffer, &tx_baudot_data, tx_baudot_data_len, pdMS_TO_TICKS(1000));
xStreamBufferSend(ctx->tx_buffer, &tx_baudot_data, tx_baudot_data_len, pdMS_TO_TICKS(60000));
}
}
}