diff --git a/Makefile b/Makefile index ed6551f..266011e 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,10 @@ MK_DIR=mkdir -p CPP_SRCS= \ src/main.cpp -CC=g++ +#TOOLCHAIN=armv7a-unknown-linux-gnueabihf +TOOLCHAIN= +CC=$(TOOLCHAIN)-g++ +SIZE=$(TOOLCHAIN)-size CFLAGS=-Og -Wall -fdata-sections -ffunction-sections -g3 -DDEBUG INCLUDES=\ diff --git a/README.md b/README.md new file mode 100644 index 0000000..8fe476b --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Raspberry Pi Serial Bus Manager + +Pinout - we're using uart2, aka ttyAMA1 + +| TX | RX | CTS | RTS | +| --- | --- | --- | --- | +| GPIO0/PIN 27 | GPIO1/PIN 28 | GPIO2/PIN 3 | GPIO3/PIN 5 | diff --git a/bin/sbm b/bin/sbm new file mode 100644 index 0000000..696cae7 Binary files /dev/null and b/bin/sbm differ diff --git a/build/main.o b/build/main.o new file mode 100644 index 0000000..70b8b9e Binary files /dev/null and b/build/main.o differ diff --git a/src/main.cpp b/src/main.cpp index 6f0ca32..1c7541c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,63 @@ +#include +#include +#include #include +#include +#include +#include -int main(int argc, char** argv) +/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */ +#include + +int main() { - std::cout << "Hello" << std::endl; - std::cout << "Hello" << std::endl; + 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; + + if (ioctl(fd, TIOCSRS485, &rs485conf) < 0) + { + /* Error handling. See errno. */ + } + + /* 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. */ + } }