aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/i2c.cpp21
-rw-r--r--client/rl.cpp31
-rw-r--r--client/rl.h5
-rw-r--r--client/sock.cpp2
4 files changed, 28 insertions, 31 deletions
diff --git a/client/i2c.cpp b/client/i2c.cpp
index 3655191..c8b2dc8 100644
--- a/client/i2c.cpp
+++ b/client/i2c.cpp
@@ -2,14 +2,13 @@
#include <stdlib.h>
#include "i2ctcpv1.h"
+#include "rl.h"
#include "sock.h"
#include "xxd.h"
#include "pb.h"
#include "pb-types.h"
-// #include "pb/mod/main.h"
-
bool i2c_dump_send = true;
bool i2c_dump_recv = true;
@@ -33,26 +32,12 @@ void i2c_send(uint16_t addr, const char * data, size_t data_size) {
free(packed);
}
-static void i2c_handle_cmd_read(uint16_t, const char *, size_t);
-
void i2c_recv(const char * data, size_t data_size) {
if (i2c_dump_recv) {
+ _rl_printf_start();
printf("[%s] data(0x%02lx):\n", __FUNCTION__, data_size);
xxd(data, data_size);
+ _rl_printf_stop();
}
}
-// static void i2c_handle_cmd_read(uint16_t i2c_addr, const char * buf, size_t sz) {
-// if (sz < 2) return; // require data address + 1 byte of data
-// pb_cmd_read_t * cmd = (pb_cmd_read_t *) buf;
-// sz--; // sz now represents size of cmd->data
-//
-// if (i2c_addr == BUSADDR_MAIN && cmd->address == 0x01) {
-// if (sz % 2 != 0) return; // invalid data
-// for (size_t offset = 0; offset < sz; offset += sizeof(pb_mod_main_mod_t)) {
-// pb_mod_main_mod_t * mod = (pb_mod_main_mod_t *) (cmd->data + offset);
-// printf("module at addr 0x%02x with state %d\n", mod->addr, mod->state);
-// }
-// }
-// }
-
diff --git a/client/rl.cpp b/client/rl.cpp
index 2e74e5f..493f753 100644
--- a/client/rl.cpp
+++ b/client/rl.cpp
@@ -10,24 +10,22 @@
#include "cmd.h"
#include "parse.h"
-void rl_printf(const char *fmt, ...) {
+static char* saved_line;
+static int saved_point, saved_end;
+
+void _rl_printf_start() {
// save line
- char* saved_line = rl_copy_text(0, rl_end);
- int saved_point = rl_point;
- int saved_end = rl_end;
+ saved_line = rl_copy_text(0, rl_end);
+ saved_point = rl_point;
+ saved_end = rl_end;
// clear line
rl_save_prompt();
rl_replace_line("", 0);
rl_redisplay();
+}
- // printf
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-
- // restore line
+void _rl_printf_stop() {
rl_restore_prompt();
rl_replace_line(saved_line, 0);
rl_point = saved_point;
@@ -37,6 +35,17 @@ void rl_printf(const char *fmt, ...) {
free(saved_line);
}
+void rl_printf(const char *fmt, ...) {
+ _rl_printf_start();
+
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+
+ _rl_printf_stop();
+}
+
static void cli_cmd(char* cmd) {
cmd += strspn(cmd, IFS); // skip leading whitespace
char* line = consume_token(cmd, IFS);
diff --git a/client/rl.h b/client/rl.h
index d2f8612..4a5b2c1 100644
--- a/client/rl.h
+++ b/client/rl.h
@@ -27,6 +27,11 @@ int cli_main();
* completes.
*/
void rl_printf(const char * fmt, ...);
+//! Store line for printing without disrupting readline prompt
+void _rl_printf_start();
+//! Restore line stored by \c _rl_printf_start()
+void _rl_printf_stop();
+
/**
* \brief Get the index of the word currently under the cursor
*
diff --git a/client/sock.cpp b/client/sock.cpp
index e33a3dc..c292d6a 100644
--- a/client/sock.cpp
+++ b/client/sock.cpp
@@ -79,8 +79,6 @@ void PBSocket::sock_task() {
char buf[80];
ssize_t bytes = read(_fd, buf, sizeof(buf));
- rl_printf("%.*s", bytes, buf);
- continue;
if (bytes == -1) {
rl_printf("error: %s (%d)\n", strerror(errno), errno);
break;