aboutsummaryrefslogtreecommitdiff
path: root/client/cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'client/cmd.cpp')
-rw-r--r--client/cmd.cpp60
1 files changed, 24 insertions, 36 deletions
diff --git a/client/cmd.cpp b/client/cmd.cpp
index e365a59..539e42d 100644
--- a/client/cmd.cpp
+++ b/client/cmd.cpp
@@ -4,42 +4,37 @@
#include <string.h>
#include "cmd.h"
-#include "pb-types.h"
+#include "i2c.h"
+#include "parse.h"
#include "pb-buf.h"
#include "pb-send.h"
+#include "pb-types.h"
#include "rl.h"
-#include "i2c.h"
-#include "parse.h"
-char* consume_token(char* input, const char* ifs) {
+char * consume_token(char * input, const char * ifs) {
strtok(input, ifs);
return strtok(NULL, "\0");
}
-void cmd_exit(char*) {
- exit(EXIT_SUCCESS);
-}
+void cmd_exit(char *) { exit(EXIT_SUCCESS); }
-void cmd_test(char*) {
- const char* data = "Hello world!";
+void cmd_test(char *) {
+ const char * data = "Hello world!";
i2c_send(0x39, data, strlen(data));
}
-void cmd_help(char*) {
+void cmd_help(char *) {
printf("List of available commands:\n");
for (size_t i = 0; i < cmds_length; i++) {
cmd_t cmd = cmds[i];
printf(" %-*s", 10, cmd.name);
- if (cmd.info != NULL)
- printf(" %s", cmd.info);
+ if (cmd.info != NULL) printf(" %s", cmd.info);
printf("\n");
}
- printf(
- "\n"
- "See man pbc(1) for more info about specific commands\n"
- "Hint: you can use the TAB key to autocomplete commands\n"
- );
+ printf("\n"
+ "See man pbc(1) for more info about specific commands\n"
+ "Hint: you can use the TAB key to autocomplete commands\n");
}
void cmd_send(char * addr_str) {
@@ -48,30 +43,31 @@ void cmd_send(char * addr_str) {
return;
}
- char* data_str = consume_token(addr_str, IFS);
+ char * data_str = consume_token(addr_str, IFS);
if (data_str == NULL) {
printf("error: no data\n");
return;
}
- char* end;
+ char * end;
uint16_t addr = strtol(addr_str, &end, 0);
if (addr_str + strlen(addr_str) != end) {
printf("address format error\n");
return;
}
- char* data;
+ char * data;
size_t data_size;
int err = strtodata(data_str, &data, &data_size);
if (err <= 0) {
- printf("data format error at index %d:\n%s\n%*s^\n",
- -err, data_str, -err, "");
+ printf("data format error at index %d:\n%s\n%*s^\n", -err, data_str,
+ -err, "");
return;
}
- printf("sending char data[%lu = 0x%02lx] to 0x%02x\n", data_size, data_size, addr);
+ printf("sending char data[%lu = 0x%02lx] to 0x%02x\n", data_size, data_size,
+ addr);
i2c_send(addr, data, data_size);
free(data);
@@ -82,7 +78,7 @@ static void cmd_set_state(char * line, pb_global_state_t state) {
printf("error: no address\n");
return;
}
-
+
i2c_addr_t addr = strtol(line, NULL, 0);
pb_buf_t buf = pb_send_state_set(state);
@@ -90,22 +86,14 @@ static void cmd_set_state(char * line, pb_global_state_t state) {
pb_buf_free(&buf);
}
-void cmd_reset(char * line) {
- cmd_set_state(line, PB_GS_IDLE);
-}
+void cmd_reset(char * line) { cmd_set_state(line, PB_GS_IDLE); }
-void cmd_skip(char * line) {
- cmd_set_state(line, PB_GS_SOLVED);
-}
+void cmd_skip(char * line) { cmd_set_state(line, PB_GS_SOLVED); }
extern bool i2c_dump_send;
extern bool i2c_dump_recv;
const char * dump_modes[] = {
- "none",
- "send",
- "recv",
- "both",
- NULL,
+ "none", "send", "recv", "both", NULL,
};
void cmd_dump(char * mode) {
consume_token(mode, IFS);
@@ -121,7 +109,7 @@ void cmd_dump(char * mode) {
printf("mode \"%s\" unknown\n", mode);
}
-char** cmd_dump_complete(const char * text, int begin, int end) {
+char ** cmd_dump_complete(const char * text, int begin, int end) {
int word = rl_word(rl_line_buffer, begin);
if (word == 1) return rl_complete_list(text, dump_modes);
return NULL;