summaryrefslogtreecommitdiff
path: root/client/commands.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-06-02 12:12:47 +0200
committerlonkaars <loek@pipeframe.xyz>2022-06-02 12:12:47 +0200
commitb12d6b2ecee0be03122a4bdba8ebbc91112fae3f (patch)
tree1bcc95eb0c26ffd1fbf23fab79f9ea80f26425b8 /client/commands.c
parent139651d45a72d57c5147e2854647d95cb87c9e4e (diff)
dirc working
Diffstat (limited to 'client/commands.c')
-rw-r--r--client/commands.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/client/commands.c b/client/commands.c
index 1ab79fb..62867dd 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -14,26 +14,41 @@ void w2_send_bin(w2_s_bin *data) {
}
}
-w2_s_bin *w2_send_info() {
- size_t msg_size = sizeof(w2_s_cmd_info_rx);
- w2_s_cmd_info_rx *msg = malloc(msg_size);
- msg->opcode = W2_CMD_INFO | W2_CMDDIR_RX;
- w2_s_bin *msg_bin = w2_bin_s_alloc(msg_size, (uint8_t *)msg);
+void w2_send_info() {
+ W2_CREATE_MSG_BIN(w2_s_cmd_info_rx, msg, msg_bin);
+ msg->opcode = W2_CMD_INFO | W2_CMDDIR_RX;
+
w2_send_bin(msg_bin);
- free(msg);
free(msg_bin);
}
-w2_s_bin *w2_send_ping() {
- g_w2_state.ping_id = (uint8_t)rand();
- size_t msg_size = sizeof(w2_s_cmd_ping_rx);
- w2_s_cmd_ping_rx *msg = malloc(msg_size);
- msg->opcode = W2_CMD_PING | W2_CMDDIR_RX;
- msg->id = g_w2_state.ping_id;
- w2_s_bin *msg_bin = w2_bin_s_alloc(msg_size, (uint8_t *)msg);
+void w2_send_ping() {
+ g_w2_state.ping_id = (uint8_t)rand();
+ W2_CREATE_MSG_BIN(w2_s_cmd_ping_rx, msg, msg_bin);
+ msg->opcode = W2_CMD_PING | W2_CMDDIR_RX;
+ msg->id = g_w2_state.ping_id;
+
w2_send_bin(msg_bin);
- free(msg);
free(msg_bin);
w2_timer_start(W2_TIMER_PING);
}
+
+void w2_send_mode(w2_e_mode mode) {
+ W2_CREATE_MSG_BIN(w2_s_cmd_mode_rx, msg, msg_bin);
+ msg->opcode = W2_CMD_MODE | W2_CMDDIR_RX;
+ msg->mode = mode;
+
+ w2_send_bin(msg_bin);
+ free(msg_bin);
+}
+
+void w2_send_dirc(int left, int right) {
+ W2_CREATE_MSG_BIN(w2_s_cmd_dirc_rx, msg, msg_bin);
+ msg->opcode = W2_CMD_DIRC | W2_CMDDIR_RX;
+ msg->left = w2_bin_hton16((uint16_t)left);
+ msg->right = w2_bin_hton16((uint16_t)right);
+
+ w2_send_bin(msg_bin);
+ free(msg_bin);
+}