mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +01:00
stdio_telnet: port to new interface
This commit is contained in:
parent
c1b6c813ae
commit
b575e2d35b
@ -26,55 +26,6 @@
|
||||
#include "board.h"
|
||||
#include "kernel_defines.h"
|
||||
#include "net/telnet.h"
|
||||
#if IS_USED(MODULE_PERIPH_UART)
|
||||
#include "stdio_uart.h"
|
||||
#include "periph/uart.h"
|
||||
#endif
|
||||
#ifdef CPU_NATIVE
|
||||
#include "native_internal.h"
|
||||
#endif
|
||||
#include "stdio_base.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
static inline void _init_fallback(void)
|
||||
{
|
||||
#if defined(STDIO_UART_DEV) && IS_USED(MODULE_PERIPH_UART)
|
||||
uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, NULL, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int _write_fallback(const void* buffer, size_t len)
|
||||
{
|
||||
#if defined(CPU_NATIVE)
|
||||
real_write(STDOUT_FILENO, buffer, len);
|
||||
#elif defined(STDIO_UART_DEV) && IS_USED(MODULE_PERIPH_UART)
|
||||
uart_write(STDIO_UART_DEV, buffer, len);
|
||||
#else
|
||||
(void)buffer;
|
||||
#endif
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void stdio_init(void)
|
||||
{
|
||||
_init_fallback();
|
||||
}
|
||||
|
||||
ssize_t stdio_read(void* buffer, size_t count)
|
||||
{
|
||||
return telnet_server_read(buffer, count);
|
||||
}
|
||||
|
||||
ssize_t stdio_write(const void* buffer, size_t len)
|
||||
{
|
||||
int res = telnet_server_write(buffer, len);
|
||||
|
||||
/* write to UART if no client is connected */
|
||||
if (res == -ENOTCONN) {
|
||||
return _write_fallback(buffer, len);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
STDIO_PROVIDER(STDIO_TELNET, NULL, telnet_server_disconnect, telnet_server_write)
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <fcntl.h>
|
||||
#include "net/sock/tcp.h"
|
||||
#include "net/telnet.h"
|
||||
#include "stdio_base.h"
|
||||
#include "pipe.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
@ -106,16 +107,21 @@ static void _connected(void)
|
||||
telnet_cb_pre_connected(client);
|
||||
|
||||
connected = true;
|
||||
mutex_unlock(&connected_mutex);
|
||||
if (!IS_USED(MODULE_STDIO_TELNET)) {
|
||||
mutex_unlock(&connected_mutex);
|
||||
}
|
||||
|
||||
telnet_cb_connected(client);
|
||||
}
|
||||
|
||||
static void _disconnect(void)
|
||||
{
|
||||
mutex_trylock(&connected_mutex);
|
||||
if (!IS_USED(MODULE_STDIO_TELNET)) {
|
||||
mutex_trylock(&connected_mutex);
|
||||
}
|
||||
connected = false;
|
||||
|
||||
DEBUG("telnet disconnect\n");
|
||||
telnet_cb_disconneced();
|
||||
}
|
||||
|
||||
@ -252,7 +258,12 @@ static void *telnet_thread(void *arg)
|
||||
continue;
|
||||
}
|
||||
write:
|
||||
pipe_write(&_stdin_pipe, &c, 1);
|
||||
if (IS_USED(MODULE_STDIO_TELNET)) {
|
||||
isrpipe_write_one(&stdin_isrpipe, c);
|
||||
}
|
||||
else {
|
||||
pipe_write(&_stdin_pipe, &c, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
disco:
|
||||
@ -276,6 +287,7 @@ int telnet_server_write(const void* buffer, size_t len)
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
#ifndef MODULE_STDIO_TELNET
|
||||
int telnet_server_read(void* buffer, size_t count)
|
||||
{
|
||||
/* block until a connection is established */
|
||||
@ -286,6 +298,7 @@ int telnet_server_read(void* buffer, size_t count)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
void telnet_server_disconnect(void)
|
||||
{
|
||||
@ -304,9 +317,11 @@ int telnet_server_start(void)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* init RX ringbuffer */
|
||||
ringbuffer_init(&_stdin_ringbuffer, _stdin_pipe_buf, sizeof(_stdin_pipe_buf));
|
||||
pipe_init(&_stdin_pipe, &_stdin_ringbuffer, NULL);
|
||||
if (!IS_USED(MODULE_STDIO_TELNET)) {
|
||||
/* init RX ringbuffer */
|
||||
ringbuffer_init(&_stdin_ringbuffer, _stdin_pipe_buf, sizeof(_stdin_pipe_buf));
|
||||
pipe_init(&_stdin_pipe, &_stdin_ringbuffer, NULL);
|
||||
}
|
||||
|
||||
/* initiate telnet server */
|
||||
thread_create(telnet_stack, sizeof(telnet_stack),
|
||||
|
Loading…
Reference in New Issue
Block a user