From c71970782fb6c3c6c48def31aa833d92ea94aa62 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 3 Feb 2019 20:37:47 -0500 Subject: [PATCH] simualtor I/O refactoring - better names and removing duplication --- simulator/main.c | 2 +- simulator/simulator/framework.cpp | 12 ++++++++++-- simulator/simulator/framework.h | 2 +- simulator/simulator/global.h | 9 +-------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/simulator/main.c b/simulator/main.c index bdc9319238..8a0a3be676 100644 --- a/simulator/main.c +++ b/simulator/main.c @@ -31,7 +31,7 @@ void printToConsole(char *p) { cputs(p); } -SerialAdapter_t serialAdapterInstance; +BaseChannel serialAdapterInstance; /* * Console print server done using synchronous messages. This makes the access diff --git a/simulator/simulator/framework.cpp b/simulator/simulator/framework.cpp index 37c5c65098..11a2d726e1 100644 --- a/simulator/simulator/framework.cpp +++ b/simulator/simulator/framework.cpp @@ -68,8 +68,16 @@ static msg_t wt_get(void *ip) { return CONSOLE_PORT->vmt->get(CONSOLE_PORT); } -static const struct BaseChannelVMT vmt = { wt_writes, wt_reads, wt_put, wt_get, wt_putt, wt_gett, wt_writet, wt_readt }; +/** + * These implementation print same content on console screen and send data over the underlying CONSOLE_PORT + * this is useful to see what's going on. + * See #wt_get() as a typical implementation + */ +static const struct BaseChannelVMT vmt = { + wt_writes, wt_reads, wt_put, wt_get, + wt_putt, wt_gett, wt_writet, wt_readt, +}; -void initTestStream(SerialAdapter_t *ts) { +void initTestStream(BaseChannel *ts) { ts->vmt = &vmt; } diff --git a/simulator/simulator/framework.h b/simulator/simulator/framework.h index e6f1a8d123..dc5d42c520 100644 --- a/simulator/simulator/framework.h +++ b/simulator/simulator/framework.h @@ -12,7 +12,7 @@ extern "C" { #endif /* __cplusplus */ -void initTestStream(SerialAdapter_t *ts); +void initTestStream(BaseChannel *ts); #ifdef __cplusplus } diff --git a/simulator/simulator/global.h b/simulator/simulator/global.h index 4b4be7434a..7d9e265739 100644 --- a/simulator/simulator/global.h +++ b/simulator/simulator/global.h @@ -55,14 +55,7 @@ // project-wide default thread stack size #define UTILITY_THREAD_STACK_SIZE 1384 -/** - * - */ -typedef struct { - const struct BaseChannelVMT *vmt; -} SerialAdapter_t; - -extern SerialAdapter_t serialAdapterInstance; +extern BaseChannel serialAdapterInstance; #ifdef __cplusplus extern "C"