diff options
Diffstat (limited to 'main/sock.c')
-rw-r--r-- | main/sock.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/main/sock.c b/main/sock.c index 6a5ff72..5d75e8f 100644 --- a/main/sock.c +++ b/main/sock.c @@ -9,7 +9,10 @@ #include "config.h" #include "i2ctcpv1.h" #include "sock.h" +#include "i2c.h" +#include <hardware/i2c.h> +extern uint8_t found[MAX_SLAVES]; struct netconn* current_connection = NULL; i2ctcp_msg_t recv_msg; @@ -35,31 +38,30 @@ void i2c_send(uint16_t addr, const char * data, size_t data_size) { } void i2c_recv(uint16_t addr, const char * data, size_t data_size) { - printf("address: 0x%02x\n", addr); - printf("data: \"%.*s\"\n", data_size, data); - - // send message back - char reply[] = "Test message back!"; - i2c_send(0x69, reply, strlen(reply)); - // TODO: this function should forward the recieved message onto the puzzle // bus instead of printing/replying + + printf("Addr: %lu, Data: %c, Data_size: %lu\n", addr, data[0], data_size); + i2c_write_blocking(i2c0, addr, data, data_size, false); } void recv_handler(struct netconn* conn, struct netbuf* buf) { - i2ctcp_read_reset(&recv_msg); + // i2ctcp_read_reset(&recv_msg); do { char* data; uint16_t len; netbuf_data(buf, (void**)&data, &len); + + printf("now scanning the bus!!!!\n"); + scan_bus(found); // continue early if more data is needed to complete message - if (!i2ctcp_read(&recv_msg, data, len)) continue; + // if (i2ctcp_read(&recv_msg, data, len) > 0) continue; // forward received message to puzzle bus - i2c_recv(recv_msg.addr, recv_msg.data, recv_msg.length); - free(recv_msg.data); + // i2c_recv(recv_msg.addr, recv_msg.data, recv_msg.length); + // free(recv_msg.data); } while (netbuf_next(buf) >= 0); netbuf_delete(buf); |