i can get stuff over zmq now

stable
Penguin 2 years ago
parent 9b3e884aba
commit 55403fad86

@ -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):

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -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"
}
]

@ -0,0 +1,6 @@
#ifndef __P_IDP_H__
#define __P_IDP_H__
#include <iostream>
#include <zmq.hpp>
#endif

@ -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);

@ -1,63 +1,34 @@
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include "p_serial_bus.h"
#include <iostream>
#include <linux/serial.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <zmq.hpp>
/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */
#include <sys/ioctl.h>
#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;
}

@ -0,0 +1 @@
#include "p_idp.h"

@ -0,0 +1,64 @@
#include "p_serial_bus.h"
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include <iostream>
#include <linux/serial.h>
#include <stdio.h>
#include <unistd.h>
/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */
#include <sys/ioctl.h>
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()
{}

@ -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()
{}

Loading…
Cancel
Save