diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-05-30 15:51:08 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-05-30 15:51:08 +0200 |
commit | b231e9d808f40aef0895787ea09624787b10addd (patch) | |
tree | 6ee2a4550e1c4a6384dd22e9967464b7766dc9cc /client | |
parent | d1f5291f82f5e13db756adc919883e310cc537de (diff) |
more client i2c shuffling
Diffstat (limited to 'client')
-rw-r--r-- | client/CMakeLists.txt | 2 | ||||
-rw-r--r-- | client/cmd.cpp | 3 | ||||
-rw-r--r-- | client/i2c.cpp | 37 | ||||
-rw-r--r-- | client/i2c.h | 8 | ||||
-rw-r--r-- | client/sock.cpp | 31 | ||||
-rw-r--r-- | client/sock.h | 3 |
6 files changed, 48 insertions, 36 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 50d3cd7..cb891a6 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -20,11 +20,11 @@ add_executable(pbc cmd.cpp parse.cpp xxd.c + i2c.cpp ) target_link_libraries(pbc i2ctcp - puzbus mpack readline # this is such a common library that I did not bother adding it as a submodule ) diff --git a/client/cmd.cpp b/client/cmd.cpp index e3c9eb9..5ac2ff3 100644 --- a/client/cmd.cpp +++ b/client/cmd.cpp @@ -4,10 +4,9 @@ #include <string.h> #include "cmd.h" -#include "i2ctcpv1.h" #include "pb/types.h" #include "rl.h" -#include "sock.h" +#include "i2c.h" #include "parse.h" #include "pb/bus.h" diff --git a/client/i2c.cpp b/client/i2c.cpp new file mode 100644 index 0000000..fd29e1e --- /dev/null +++ b/client/i2c.cpp @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "i2ctcpv1.h" +#include "sock.h" +#include "xxd.h" + +bool i2c_dump_send = false; +bool i2c_dump_recv = true; + +void i2c_send(uint16_t addr, const char * data, size_t data_size) { + i2ctcp_msg_t msg = { + .addr = addr, + .data = (char *) data, + .length = data_size, + }; + + char* packed; + size_t size; + if (!i2ctcp_write(&msg, &packed, &size)) return; + + sock->send(packed, size); + if (i2c_dump_send) { + printf("[%s] addr(0x%02x) data(0x%02lx):\n", __FUNCTION__, addr, data_size); + xxd(data, data_size); + } + + free(packed); +} + +void i2c_recv(uint16_t addr, const char * data, size_t data_size) { + if (i2c_dump_recv) { + printf("[%s] addr(0x%02x) data(0x%02lx):\n", __FUNCTION__, addr, data_size); + xxd(data, data_size); + } +} + diff --git a/client/i2c.h b/client/i2c.h new file mode 100644 index 0000000..f9f58f9 --- /dev/null +++ b/client/i2c.h @@ -0,0 +1,8 @@ +#pragma once + +#include <stdint.h> +#include <stddef.h> + +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); + diff --git a/client/sock.cpp b/client/sock.cpp index f5bd564..638bf9d 100644 --- a/client/sock.cpp +++ b/client/sock.cpp @@ -7,13 +7,12 @@ #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> - #include <thread> #include "i2ctcpv1.h" #include "sock.h" #include "rl.h" -#include "xxd.h" +#include "i2c.h" using std::logic_error; using std::thread; @@ -106,31 +105,3 @@ void PBSocket::sock_task() { sock_close(); } -bool i2c_dump_send = false; -bool i2c_dump_recv = true; - -void i2c_send(uint16_t addr, const char * data, size_t data_size) { - i2ctcp_msg_t msg = { - .addr = addr, - .data = (char *) data, - .length = data_size, - }; - - char* packed; - size_t size; - if (!i2ctcp_write(&msg, &packed, &size)) return; - - sock->send(packed, size); - if (i2c_dump_send) { - printf("[i2c send] data(0x%02lx):\n", data_size); - xxd(data, data_size); - } -} - -void i2c_recv(uint16_t addr, const char * data, size_t data_size) { - if (i2c_dump_recv) { - printf("[i2c recv] data(0x%02lx):\n", data_size); - xxd(data, data_size); - } -} - diff --git a/client/sock.h b/client/sock.h index 42eba3b..0dee09e 100644 --- a/client/sock.h +++ b/client/sock.h @@ -29,6 +29,3 @@ private: extern PBSocket* sock; -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); - |