aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-18 20:11:44 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-18 20:11:44 +0200
commit1152ec32b6086c153dc41da59c9c451aa4465995 (patch)
treede696dc61a4566a75b4df1df907cb1a2da25bd82 /client
parentcddfbb715d6f4f9d022d383ab8737b6af57a1d6f (diff)
WIP send/receive w/ msgpack
Diffstat (limited to 'client')
-rw-r--r--client/CMakeLists.txt10
l---------client/lib1
-rw-r--r--client/main.cpp61
3 files changed, 54 insertions, 18 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index 9e433b1..bcef4c0 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -4,11 +4,17 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
-include(../proto/include.cmake)
-
project(puzzlebox_client C CXX)
+include(../proto/include.cmake)
+
add_executable(main
main.cpp
)
+target_link_libraries(main
+ puzbus
+ mpack
+ )
+
+
diff --git a/client/lib b/client/lib
new file mode 120000
index 0000000..dc598c5
--- /dev/null
+++ b/client/lib
@@ -0,0 +1 @@
+../lib \ No newline at end of file
diff --git a/client/main.cpp b/client/main.cpp
index 7a05049..30d7045 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -1,25 +1,54 @@
#include <cstdio>
-#include <string>
-
-#include "puzbusv1.pb.h"
-
-int main() {
- GOOGLE_PROTOBUF_VERIFY_VERSION;
-
- puzbus::I2CMsg test_msg;
+#include <cstdlib>
+#include <cstring>
+#include <unistd.h>
+
+#include "puzbusv1.h"
+
+int send_message() {
+ const char* data = "Test message data!";
+ struct pb_msg output = {
+ .addr = 0x39,
+ .data = (char*) data,
+ .length = strlen(data),
+ };
+
+ char* packed;
+ size_t size;
+ if (!pb_write(&output, &packed, &size)) {
+ printf("error writing!\n");
+ return 1;
+ }
- test_msg.set_address(0x39);
- test_msg.set_data("Test message data!");
+ fwrite(packed, sizeof(packed[0]), size, stdout);
+ fflush(stdout);
- std::string output;
- test_msg.SerializeToString(&output);
+ return 0;
+}
- printf("output[%lu]:\n", output.size());
- for (size_t i = 0; i < output.size(); i++) {
- printf("%02x ", output[i]);
+int read_message() {
+ freopen(NULL, "rb", stdin); // allow binary on stdin
+ struct pb_msg input;
+
+ char buf[8]; // extremely small buffer to test chunked message parsing
+ size_t bytes = 0;
+ while ((bytes = fread(buf, sizeof(buf[0]), sizeof(buf), stdin)) > 0) {
+ if (!pb_read(&input, buf, bytes)) continue;
+
+ printf("address: 0x%02x\n", input.addr);
+ printf("data: \"%.*s\"\n", input.length, input.data);
+ free(input.data);
+ return 0;
}
- printf("\n");
+ return 1;
+}
+
+int main() {
+ if (!isatty(fileno(stdout))) return send_message();
+ if (!isatty(fileno(stdin))) return read_message();
+
+ printf("please pipe some data in or out to use this program\n");
return 0;
}