diff --git a/.cache/clangd/index/main.cpp.6C7D4E708A9CF215.idx b/.cache/clangd/index/main.cpp.6C7D4E708A9CF215.idx new file mode 100644 index 0000000..a421d40 Binary files /dev/null and b/.cache/clangd/index/main.cpp.6C7D4E708A9CF215.idx differ diff --git a/.cache/clangd/index/p_idp.cpp.AB5BD6002393B24B.idx b/.cache/clangd/index/p_idp.cpp.AB5BD6002393B24B.idx new file mode 100644 index 0000000..e6e3532 Binary files /dev/null and b/.cache/clangd/index/p_idp.cpp.AB5BD6002393B24B.idx differ diff --git a/.cache/clangd/index/p_idp.h.7E99EF71390B444D.idx b/.cache/clangd/index/p_idp.h.7E99EF71390B444D.idx new file mode 100644 index 0000000..ba0ec33 Binary files /dev/null and b/.cache/clangd/index/p_idp.h.7E99EF71390B444D.idx differ diff --git a/.cache/clangd/index/p_serial_bus.cpp.ABEC82C874071671.idx b/.cache/clangd/index/p_serial_bus.cpp.ABEC82C874071671.idx new file mode 100644 index 0000000..5d7fed7 Binary files /dev/null and b/.cache/clangd/index/p_serial_bus.cpp.ABEC82C874071671.idx differ diff --git a/.cache/clangd/index/p_serial_bus.h.48DDA2AACC6854FD.idx b/.cache/clangd/index/p_serial_bus.h.48DDA2AACC6854FD.idx new file mode 100644 index 0000000..0a096e8 Binary files /dev/null and b/.cache/clangd/index/p_serial_bus.h.48DDA2AACC6854FD.idx differ diff --git a/.cache/clangd/index/p_serial_packet.cpp.45B1DE7F1E66FFCC.idx b/.cache/clangd/index/p_serial_packet.cpp.45B1DE7F1E66FFCC.idx new file mode 100644 index 0000000..d3121cf Binary files /dev/null and b/.cache/clangd/index/p_serial_packet.cpp.45B1DE7F1E66FFCC.idx differ diff --git a/.cache/clangd/index/p_serial_packet.h.38E83F6A61EFB6BA.idx b/.cache/clangd/index/p_serial_packet.h.38E83F6A61EFB6BA.idx new file mode 100644 index 0000000..281bb7c Binary files /dev/null and b/.cache/clangd/index/p_serial_packet.h.38E83F6A61EFB6BA.idx differ diff --git a/Makefile b/Makefile index 266011e..2b5f668 100644 --- a/Makefile +++ b/Makefile @@ -3,17 +3,20 @@ BUILD_DIR=build MK_DIR=mkdir -p CPP_SRCS= \ - src/main.cpp + src/main.cpp \ + src/p_serial_bus.cpp \ + src/p_serial_packet.cpp \ + src/p_idp.cpp #TOOLCHAIN=armv7a-unknown-linux-gnueabihf TOOLCHAIN= CC=$(TOOLCHAIN)-g++ SIZE=$(TOOLCHAIN)-size -CFLAGS=-Og -Wall -fdata-sections -ffunction-sections -g3 -DDEBUG - INCLUDES=\ - cfg\ - inc + -Icfg\ + -Iinc +CFLAGS=-Og -Wall -fdata-sections -ffunction-sections -g3 -DDEBUG $(INCLUDES) -lzmq + all: bin/$(TARGET) OBJS=$(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SRCS:.cpp=.o))) @@ -23,7 +26,7 @@ $(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR) $(CC) -c $(CFLAGS) $< -o $@ bin/$(TARGET): $(OBJS) Makefile - $(CC) $(OBJS) -o $@ + $(CC) $(OBJS) -o $@ -lzmq size $@ $(BUILD_DIR): diff --git a/bin/sbm b/bin/sbm index 696cae7..e56d88d 100644 Binary files a/bin/sbm and b/bin/sbm differ diff --git a/build/main.o b/build/main.o index 70b8b9e..cf9d595 100644 Binary files a/build/main.o and b/build/main.o differ diff --git a/build/p_idp.o b/build/p_idp.o new file mode 100644 index 0000000..5ee1a23 Binary files /dev/null and b/build/p_idp.o differ diff --git a/build/p_serial_bus.o b/build/p_serial_bus.o new file mode 100644 index 0000000..9653e60 Binary files /dev/null and b/build/p_serial_bus.o differ diff --git a/build/p_serial_packet.o b/build/p_serial_packet.o new file mode 100644 index 0000000..af4f1c3 Binary files /dev/null and b/build/p_serial_packet.o differ diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000..2494ee2 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,78 @@ +[ + { + "arguments": [ + "g++", + "-c", + "-Og", + "-Wall", + "-fdata-sections", + "-ffunction-sections", + "-g3", + "-DDEBUG", + "-Icfg", + "-Iinc", + "-o", + "build/p_idp.o", + "src/p_idp.cpp" + ], + "directory": "/storage/Shared/Projects/Penguinator/pi_serial_bus_manager", + "file": "src/p_idp.cpp" + }, + { + "arguments": [ + "g++", + "-c", + "-Og", + "-Wall", + "-fdata-sections", + "-ffunction-sections", + "-g3", + "-DDEBUG", + "-Icfg", + "-Iinc", + "-o", + "build/p_serial_bus.o", + "src/p_serial_bus.cpp" + ], + "directory": "/storage/Shared/Projects/Penguinator/pi_serial_bus_manager", + "file": "src/p_serial_bus.cpp" + }, + { + "arguments": [ + "g++", + "-c", + "-Og", + "-Wall", + "-fdata-sections", + "-ffunction-sections", + "-g3", + "-DDEBUG", + "-Icfg", + "-Iinc", + "-o", + "build/p_serial_packet.o", + "src/p_serial_packet.cpp" + ], + "directory": "/storage/Shared/Projects/Penguinator/pi_serial_bus_manager", + "file": "src/p_serial_packet.cpp" + }, + { + "arguments": [ + "g++", + "-c", + "-Og", + "-Wall", + "-fdata-sections", + "-ffunction-sections", + "-g3", + "-DDEBUG", + "-Icfg", + "-Iinc", + "-o", + "build/main.o", + "src/main.cpp" + ], + "directory": "/storage/Shared/Projects/Penguinator/pi_serial_bus_manager", + "file": "src/main.cpp" + } +] \ No newline at end of file diff --git a/inc/p_idp.h b/inc/p_idp.h new file mode 100644 index 0000000..4926e69 --- /dev/null +++ b/inc/p_idp.h @@ -0,0 +1,6 @@ +#ifndef __P_IDP_H__ +#define __P_IDP_H__ + +#include +#include +#endif diff --git a/inc/p_serial_bus.h b/inc/p_serial_bus.h index edeb0c7..41e6b41 100644 --- a/inc/p_serial_bus.h +++ b/inc/p_serial_bus.h @@ -1,7 +1,17 @@ #ifndef __P_SERIAL_BUS_H__ #define __P_SERIAL_BUS_H__ -void p_sbus_init(void); +class ps_bus +{ +public: + ps_bus(const char* dev); + ~ps_bus(); + + void ps_bus_start(); + +private: + int dev_fd; +}; void p_sbus_start(void); diff --git a/src/main.cpp b/src/main.cpp index 1c7541c..7a01d38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,63 +1,34 @@ -#include -#include -#include +#include "p_serial_bus.h" #include -#include +#include #include -#include +#include +#include -/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */ -#include +#define SERIAL_DEV ("/dev/ttyAMA1") +#define ZMQ_IPC_ADDR ("ipc:///penguinator/pubsub") -int main() +void sigint_handler(int param) { - uint8_t send_buffer[14] = {0x7E, 0x01, 0x02, 8, 0x01, 0x02, 0x03, - 0x7D, 0x5E, 0x05, 0x06, 0x07, 0x08, 0xFF}; - - /* Open your specific device (e.g., /dev/mydevice): */ - int fd = open("/dev/ttyAMA1", O_RDWR); - if (fd < 0) - { - /* Error handling. See errno. */ - fprintf(stderr, "Failed... error:%s", strerror(errno)); - } - - struct serial_rs485 rs485conf; - - /* Enable RS485 mode: */ - rs485conf.flags |= SER_RS485_ENABLED; - - /* Set logical level for RTS pin equal to 1 when sending: */ - rs485conf.flags |= SER_RS485_RTS_ON_SEND; - /* or, set logical level for RTS pin equal to 0 when sending: */ - rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND); - - /* Set logical level for RTS pin equal to 1 after sending: */ - rs485conf.flags |= SER_RS485_RTS_AFTER_SEND; - /* or, set logical level for RTS pin equal to 0 after sending: */ - rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND); - - // /* Set rts delay before send, if needed: */ - // rs485conf.delay_rts_before_send = ...; - - // /* Set rts delay after send, if needed: */ - // rs485conf.delay_rts_after_send = ...; - - /* Set this flag if you want to receive data even while sending data */ - // rs485conf.flags |= SER_RS485_RX_DURING_TX; + std::cout << "Exiting..." << std::endl; + exit(1); +} - if (ioctl(fd, TIOCSRS485, &rs485conf) < 0) +int main() +{ + signal(SIGINT, sigint_handler); + ps_bus sbus(SERIAL_DEV); + zmq::context_t ctx; + zmq::socket_t sub(ctx, ZMQ_SUB); + sub.connect(ZMQ_IPC_ADDR); + sub.setsockopt(ZMQ_SUBSCRIBE, "", 0); + + for (;;) { - /* Error handling. See errno. */ + zmq::message_t msg; + sub.recv(&msg, 0); + std::cout << msg << std::endl; } - /* Use read() and write() syscalls here... */ - ssize_t rc = 0; - write(fd, send_buffer, 14); - - /* Close the device when finished: */ - if (close(fd) < 0) - { - /* Error handling. See errno. */ - } + return 0; } diff --git a/src/p_idp.cpp b/src/p_idp.cpp new file mode 100644 index 0000000..4de809c --- /dev/null +++ b/src/p_idp.cpp @@ -0,0 +1 @@ +#include "p_idp.h" diff --git a/src/p_serial_bus.cpp b/src/p_serial_bus.cpp index e69de29..85f7e8f 100644 --- a/src/p_serial_bus.cpp +++ b/src/p_serial_bus.cpp @@ -0,0 +1,64 @@ +#include "p_serial_bus.h" +#include +#include +#include +#include +#include +#include +#include + +/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */ +#include + +ps_bus::ps_bus(const char* dev) +{ + /* Open your specific device (e.g., /dev/mydevice): */ + int fd = open(dev, O_RDWR); + if (fd < 0) + { + /* Error handling. See errno. */ + fprintf(stderr, "Creation of the bus failed... error: %s", + strerror(errno)); + } + + struct serial_rs485 rs485conf; + + /* Enable RS485 mode: */ + rs485conf.flags |= SER_RS485_ENABLED; + + /* Set logical level for RTS pin equal to 1 when sending: */ + rs485conf.flags |= SER_RS485_RTS_ON_SEND; + /* or, set logical level for RTS pin equal to 0 when sending: */ + rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND); + + /* Set logical level for RTS pin equal to 1 after sending: */ + rs485conf.flags |= SER_RS485_RTS_AFTER_SEND; + /* or, set logical level for RTS pin equal to 0 after sending: */ + rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND); + + // /* Set rts delay before send, if needed: */ + // rs485conf.delay_rts_before_send = ...; + + // /* Set rts delay after send, if needed: */ + // rs485conf.delay_rts_after_send = ...; + + /* Set this flag if you want to receive data even while sending data */ + // rs485conf.flags |= SER_RS485_RX_DURING_TX; + + if (ioctl(fd, TIOCSRS485, &rs485conf) < 0) + { + /* Error handling. See errno. */ + } +} + +ps_bus::~ps_bus() +{ + /* Close the device when finished: */ + if (close(dev_fd) < 0) + { + /* Error handling. See errno. */ + } +} + +void ps_bus::ps_bus_start() +{} diff --git a/src/p_serial_packet.cpp b/src/p_serial_packet.cpp index 314709f..efd1fdf 100644 --- a/src/p_serial_packet.cpp +++ b/src/p_serial_packet.cpp @@ -1,19 +1,40 @@ #include "p_serial_packet.h" -ps_packet::ps_packet() +ps_packet::ps_packet(uint8_t* data) {} ps_packet::~ps_packet() {} // takes members and prepares the buffer for transmission -bool ps_packet::encode(uint8_t* buffer) -{} +bool ps_packet::encode() +{ + bool ret = true; + do + { + + } while (0); + return ret; +} bool ps_packet::decode() -{} +{ + bool ret = true; + do + { + + } while (0); + return ret; +} bool ps_packet::validate() -{} +{ + bool ret = true; + do + { + + } while (0); + return ret; +} void ps_packet::calc_checksum() {}