diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-25 12:09:15 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-25 12:09:15 +0200 |
commit | 18e5d93da8fdf6dd97c9e2d090ae2648d85cb851 (patch) | |
tree | ec4935b8682ab878ecbe0c41afa96cacf9b5f53c | |
parent | 208dee5a3cf9eea84c5e26ef5cfe3abdd2e2a2f8 (diff) |
fix client show all messages
-rw-r--r-- | client/i2c.cpp | 18 | ||||
-rw-r--r-- | lib/pbdrv/drv/arduino/mod.cpp | 2 | ||||
-rw-r--r-- | lib/pbdrv/drv/rp2040/mod.c | 14 | ||||
-rw-r--r-- | lib/pbdrv/pb-mod.c | 11 | ||||
-rw-r--r-- | lib/pbdrv/pb-mod.h | 4 | ||||
-rw-r--r-- | main/sock.c | 16 |
6 files changed, 31 insertions, 34 deletions
diff --git a/client/i2c.cpp b/client/i2c.cpp index 2a5e67a..c8b2dc8 100644 --- a/client/i2c.cpp +++ b/client/i2c.cpp @@ -9,8 +9,6 @@ #include "pb.h" #include "pb-types.h" -// #include "pb/mod/main.h" - bool i2c_dump_send = true; bool i2c_dump_recv = true; @@ -34,8 +32,6 @@ 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(); @@ -45,17 +41,3 @@ void i2c_recv(const char * data, size_t data_size) { } } -// 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/lib/pbdrv/drv/arduino/mod.cpp b/lib/pbdrv/drv/arduino/mod.cpp index c381077..581b80a 100644 --- a/lib/pbdrv/drv/arduino/mod.cpp +++ b/lib/pbdrv/drv/arduino/mod.cpp @@ -48,6 +48,8 @@ static void pb_setup() { * RP2040. */ __weak void pb_i2c_send(i2c_addr_t addr, const uint8_t * buf, size_t sz) { + if (pb_hook_i2c_send(addr, buf, sz)) return; + vTaskDelay(10 / portTICK_PERIOD_MS); // prevent bus collisions Wire.beginTransmission((int) addr); Wire.write(buf, sz); diff --git a/lib/pbdrv/drv/rp2040/mod.c b/lib/pbdrv/drv/rp2040/mod.c index bc20927..bca38d0 100644 --- a/lib/pbdrv/drv/rp2040/mod.c +++ b/lib/pbdrv/drv/rp2040/mod.c @@ -1,10 +1,8 @@ -#include "pb.h" - -#include "pb.h" -#include "pb-types.h" -#include "pb-mod.h" -#include "pb-send.h" -#include "pb-buf.h" +#include "../../pb.h" +#include "../../pb-types.h" +#include "../../pb-mod.h" +#include "../../pb-send.h" +#include "../../pb-buf.h" #include <hardware/i2c.h> #include <hardware/gpio.h> @@ -43,7 +41,7 @@ void pb_setup() { } __weak void pb_i2c_send(i2c_addr_t addr, const uint8_t * buf, size_t sz) { - pb_hook_i2c_send(addr, buf, sz); + if (pb_hook_i2c_send(addr, buf, sz)) return; // false to write stop condition to i2c bus i2c_write_timeout_us(PB_I2C_M, addr, buf, sz, false, PB_TIMEOUT_US); diff --git a/lib/pbdrv/pb-mod.c b/lib/pbdrv/pb-mod.c index 6b23b04..0342391 100644 --- a/lib/pbdrv/pb-mod.c +++ b/lib/pbdrv/pb-mod.c @@ -18,9 +18,8 @@ __weak void pb_hook_mod_state_write(pb_global_state_t state) { _global_state = state; } -__weak void pb_hook_i2c_recv(const uint8_t * data, size_t sz) { } __weak void pb_i2c_recv(const uint8_t * data, size_t sz) { - pb_hook_i2c_recv(data, sz); + if (pb_hook_i2c_recv(data, sz)) return; pb_buf_t buf = { .data = (char *) data, @@ -35,5 +34,11 @@ __weak void pb_i2c_recv(const uint8_t * data, size_t sz) { pb_msg_free(msg); } -__weak void pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * data, size_t sz) { } +__weak bool pb_hook_i2c_recv(const uint8_t * data, size_t sz) { + return false; +} + +__weak bool pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * data, size_t sz) { + return false; +} diff --git a/lib/pbdrv/pb-mod.h b/lib/pbdrv/pb-mod.h index e7b7832..7069b32 100644 --- a/lib/pbdrv/pb-mod.h +++ b/lib/pbdrv/pb-mod.h @@ -101,8 +101,8 @@ void pb_hook_mod_state_write(pb_global_state_t state); * \{ */ -void pb_hook_i2c_recv(const uint8_t * buf, size_t sz); -void pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz); +bool pb_hook_i2c_recv(const uint8_t * buf, size_t sz); +bool pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz); /// \} diff --git a/main/sock.c b/main/sock.c index 07db6af..c97ad04 100644 --- a/main/sock.c +++ b/main/sock.c @@ -14,7 +14,7 @@ struct netconn* current_connection = NULL; i2ctcp_msg_t recv_msg; -void pb_hook_i2c_send(i2c_addr_t addr, const uint8_t * data, size_t data_size) { +static void sock_dump_msg(i2c_addr_t addr, const uint8_t * data, size_t data_size) { if (current_connection == NULL) return; i2ctcp_msg_t send_msg = { @@ -35,7 +35,17 @@ void pb_hook_i2c_send(i2c_addr_t addr, const uint8_t * data, size_t data_size) { free(buf); } -static void i2c_recv_fwd(i2c_addr_t addr, const uint8_t * data, size_t data_size) { +bool pb_hook_i2c_send(i2c_addr_t addr, const uint8_t * data, size_t data_size) { + sock_dump_msg(addr, data, data_size); + return addr == PB_MOD_ADDR; // stop processing message if it is sent to myself +} + +bool pb_hook_i2c_recv(const uint8_t * data, size_t data_size) { + sock_dump_msg(0x00, data, data_size); + return false; +} + +static void sock_fwd_msg(i2c_addr_t addr, const uint8_t * data, size_t data_size) { if (addr == PB_MOD_ADDR) { // addressed to me = act as recieved pb_i2c_recv(data, data_size); @@ -57,7 +67,7 @@ void recv_handler(struct netconn* conn, struct netbuf* buf) { if (i2ctcp_read(&recv_msg, data, len) != 0) continue; // forward received message to puzzle bus - i2c_recv_fwd(recv_msg.addr, (uint8_t *) recv_msg.data, recv_msg.length); + sock_fwd_msg(recv_msg.addr, (uint8_t *) recv_msg.data, recv_msg.length); free(recv_msg.data); } while (netbuf_next(buf) >= 0); |